Skip to content

Commit a68903b

Browse files
committed
Merge remote-tracking branch 'origin/main' into vpinst-with-type
2 parents 1749b91 + db98e29 commit a68903b

File tree

1,162 files changed

+42104
-32171
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,162 files changed

+42104
-32171
lines changed

.ci/compute_projects.py

Lines changed: 226 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,226 @@
1+
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
2+
# See https://llvm.org/LICENSE.txt for license information.
3+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4+
"""Computes the list of projects that need to be tested from a diff.
5+
6+
Does some things, spits out a list of projects.
7+
"""
8+
9+
from collections.abc import Set
10+
import pathlib
11+
import platform
12+
import sys
13+
14+
# This mapping lists out the dependencies for each project. These should be
15+
# direct dependencies. The code will handle transitive dependencies. Some
16+
# projects might have optional dependencies depending upon how they are built.
17+
# The dependencies listed here should be the dependencies required for the
18+
# configuration built/tested in the premerge CI.
19+
PROJECT_DEPENDENCIES = {
20+
"llvm": set(),
21+
"clang": {"llvm"},
22+
"bolt": {"clang", "lld", "llvm"},
23+
"clang-tools-extra": {"clang", "llvm"},
24+
"compiler-rt": {"clang", "lld"},
25+
"libc": {"clang", "lld"},
26+
"openmp": {"clang", "lld"},
27+
"flang": {"llvm", "clang"},
28+
"lldb": {"llvm", "clang"},
29+
"libclc": {"llvm", "clang"},
30+
"lld": {"llvm"},
31+
"mlir": {"llvm"},
32+
"polly": {"llvm"},
33+
}
34+
35+
# This mapping describes the additional projects that should be tested when a
36+
# specific project is touched. We enumerate them specifically rather than
37+
# just invert the dependencies list to give more control over what exactly is
38+
# tested.
39+
DEPENDENTS_TO_TEST = {
40+
"llvm": {
41+
"bolt",
42+
"clang",
43+
"clang-tools-extra",
44+
"lld",
45+
"lldb",
46+
"mlir",
47+
"polly",
48+
"flang",
49+
},
50+
"lld": {"bolt", "cross-project-tests"},
51+
# TODO(issues/132795): LLDB should be enabled on clang changes.
52+
"clang": {"clang-tools-extra", "compiler-rt", "cross-project-tests"},
53+
"clang-tools-extra": {"libc"},
54+
"mlir": {"flang"},
55+
}
56+
57+
DEPENDENT_RUNTIMES_TO_TEST = {"clang": {"libcxx", "libcxxabi", "libunwind"}}
58+
59+
EXCLUDE_LINUX = {
60+
"cross-project-tests", # TODO(issues/132796): Tests are failing.
61+
"openmp", # https://github.com/google/llvm-premerge-checks/issues/410
62+
}
63+
64+
EXCLUDE_WINDOWS = {
65+
"cross-project-tests", # TODO(issues/132797): Tests are failing.
66+
"compiler-rt", # TODO(issues/132798): Tests take excessive time.
67+
"openmp", # TODO(issues/132799): Does not detect perl installation.
68+
"libc", # No Windows Support.
69+
"lldb", # TODO(issues/132800): Needs environment setup.
70+
"bolt", # No Windows Support.
71+
}
72+
73+
# These are projects that we should test if the project itself is changed but
74+
# where testing is not yet stable enough for it to be enabled on changes to
75+
# dependencies.
76+
EXCLUDE_DEPENDENTS_WINDOWS = {
77+
"flang", # TODO(issues/132803): Flang is not stable.
78+
}
79+
80+
EXCLUDE_MAC = {
81+
"bolt",
82+
"compiler-rt",
83+
"cross-project-tests",
84+
"flang",
85+
"libc",
86+
"libcxx",
87+
"libcxxabi",
88+
"libunwind",
89+
"lldb",
90+
"openmp",
91+
"polly",
92+
}
93+
94+
PROJECT_CHECK_TARGETS = {
95+
"clang-tools-extra": "check-clang-tools",
96+
"compiler-rt": "check-compiler-rt",
97+
"cross-project-tests": "check-cross-project",
98+
"libcxx": "check-cxx",
99+
"libcxxabi": "check-cxxabi",
100+
"libunwind": "check-unwind",
101+
"lldb": "check-lldb",
102+
"llvm": "check-llvm",
103+
"clang": "check-clang",
104+
"bolt": "check-bolt",
105+
"lld": "check-lld",
106+
"flang": "check-flang",
107+
"libc": "check-libc",
108+
"lld": "check-lld",
109+
"lldb": "check-lldb",
110+
"mlir": "check-mlir",
111+
"openmp": "check-openmp",
112+
"polly": "check-polly",
113+
}
114+
115+
RUNTIMES = {"libcxx", "libcxxabi", "libunwind"}
116+
117+
118+
def _add_dependencies(projects: Set[str]) -> Set[str]:
119+
projects_with_dependents = set(projects)
120+
current_projects_count = 0
121+
while current_projects_count != len(projects_with_dependents):
122+
current_projects_count = len(projects_with_dependents)
123+
for project in list(projects_with_dependents):
124+
if project not in PROJECT_DEPENDENCIES:
125+
continue
126+
projects_with_dependents.update(PROJECT_DEPENDENCIES[project])
127+
return projects_with_dependents
128+
129+
130+
def _compute_projects_to_test(modified_projects: Set[str], platform: str) -> Set[str]:
131+
projects_to_test = set()
132+
for modified_project in modified_projects:
133+
# Skip all projects where we cannot run tests.
134+
if modified_project not in PROJECT_CHECK_TARGETS:
135+
continue
136+
if modified_project in RUNTIMES:
137+
continue
138+
projects_to_test.add(modified_project)
139+
if modified_project not in DEPENDENTS_TO_TEST:
140+
continue
141+
for dependent_project in DEPENDENTS_TO_TEST[modified_project]:
142+
if (
143+
platform == "Windows"
144+
and dependent_project in EXCLUDE_DEPENDENTS_WINDOWS
145+
):
146+
continue
147+
projects_to_test.add(dependent_project)
148+
if platform == "Linux":
149+
for to_exclude in EXCLUDE_LINUX:
150+
if to_exclude in projects_to_test:
151+
projects_to_test.remove(to_exclude)
152+
elif platform == "Windows":
153+
for to_exclude in EXCLUDE_WINDOWS:
154+
if to_exclude in projects_to_test:
155+
projects_to_test.remove(to_exclude)
156+
elif platform == "Darwin":
157+
for to_exclude in EXCLUDE_MAC:
158+
if to_exclude in projects_to_test:
159+
projects_to_test.remove(to_exclude)
160+
else:
161+
raise ValueError("Unexpected platform.")
162+
return projects_to_test
163+
164+
165+
def _compute_projects_to_build(projects_to_test: Set[str]) -> Set[str]:
166+
return _add_dependencies(projects_to_test)
167+
168+
169+
def _compute_project_check_targets(projects_to_test: Set[str]) -> Set[str]:
170+
check_targets = set()
171+
for project_to_test in projects_to_test:
172+
if project_to_test not in PROJECT_CHECK_TARGETS:
173+
continue
174+
check_targets.add(PROJECT_CHECK_TARGETS[project_to_test])
175+
return check_targets
176+
177+
178+
def _compute_runtimes_to_test(projects_to_test: Set[str]) -> Set[str]:
179+
runtimes_to_test = set()
180+
for project_to_test in projects_to_test:
181+
if project_to_test not in DEPENDENT_RUNTIMES_TO_TEST:
182+
continue
183+
runtimes_to_test.update(DEPENDENT_RUNTIMES_TO_TEST[project_to_test])
184+
return runtimes_to_test
185+
186+
187+
def _compute_runtime_check_targets(runtimes_to_test: Set[str]) -> Set[str]:
188+
check_targets = set()
189+
for runtime_to_test in runtimes_to_test:
190+
check_targets.add(PROJECT_CHECK_TARGETS[runtime_to_test])
191+
return check_targets
192+
193+
194+
def _get_modified_projects(modified_files: list[str]) -> Set[str]:
195+
modified_projects = set()
196+
for modified_file in modified_files:
197+
modified_projects.add(pathlib.Path(modified_file).parts[0])
198+
return modified_projects
199+
200+
201+
def get_env_variables(modified_files: list[str], platform: str) -> Set[str]:
202+
modified_projects = _get_modified_projects(modified_files)
203+
projects_to_test = _compute_projects_to_test(modified_projects, platform)
204+
projects_to_build = _compute_projects_to_build(projects_to_test)
205+
projects_check_targets = _compute_project_check_targets(projects_to_test)
206+
runtimes_to_test = _compute_runtimes_to_test(projects_to_test)
207+
runtimes_check_targets = _compute_runtime_check_targets(runtimes_to_test)
208+
# We use a semicolon to separate the projects/runtimes as they get passed
209+
# to the CMake invocation and thus we need to use the CMake list separator
210+
# (;). We use spaces to separate the check targets as they end up getting
211+
# passed to ninja.
212+
return {
213+
"projects_to_build": ";".join(sorted(projects_to_build)),
214+
"project_check_targets": " ".join(sorted(projects_check_targets)),
215+
"runtimes_to_build": ";".join(sorted(runtimes_to_test)),
216+
"runtimes_check_targets": " ".join(sorted(runtimes_check_targets)),
217+
}
218+
219+
220+
if __name__ == "__main__":
221+
current_platform = platform.system()
222+
if len(sys.argv) == 2:
223+
current_platform = sys.argv[1]
224+
env_variables = get_env_variables(sys.stdin.readlines(), current_platform)
225+
for env_variable in env_variables:
226+
print(f"{env_variable}='{env_variables[env_variable]}'")

0 commit comments

Comments
 (0)