Skip to content

Commit 807604f

Browse files
committed
rebase
Created using spr 1.3.6-beta.1
2 parents cd7d8bb + 10a230c commit 807604f

File tree

20,827 files changed

+1410269
-646739
lines changed

Some content is hidden

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

20,827 files changed

+1410269
-646739
lines changed

.ci/compute_projects.py

Lines changed: 150 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
PROJECT_DEPENDENCIES = {
2020
"llvm": set(),
2121
"clang": {"llvm"},
22+
"CIR": {"clang", "mlir"},
2223
"bolt": {"clang", "lld", "llvm"},
2324
"clang-tools-extra": {"clang", "llvm"},
2425
"compiler-rt": {"clang", "lld"},
@@ -49,12 +50,23 @@
4950
},
5051
"lld": {"bolt", "cross-project-tests"},
5152
# 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"},
53+
"clang": {"clang-tools-extra", "cross-project-tests"},
5454
"mlir": {"flang"},
5555
# Test everything if ci scripts are changed.
56-
# FIXME: Figure out what is missing and add here.
57-
".ci": {"llvm", "clang", "lld", "lldb"},
56+
".ci": {
57+
"llvm",
58+
"clang",
59+
"CIR",
60+
"lld",
61+
"lldb",
62+
"bolt",
63+
"clang-tools-extra",
64+
"mlir",
65+
"polly",
66+
"flang",
67+
"libclc",
68+
"openmp",
69+
},
5870
}
5971

6072
# This mapping describes runtimes that should be enabled for a specific project,
@@ -64,7 +76,18 @@
6476

6577
# This mapping describes runtimes that should be tested when the key project is
6678
# touched.
67-
DEPENDENT_RUNTIMES_TO_TEST = {"clang": {"libcxx", "libcxxabi", "libunwind"}}
79+
DEPENDENT_RUNTIMES_TO_TEST = {
80+
"clang": {"compiler-rt"},
81+
"clang-tools-extra": {"libc"},
82+
"libc": {"libc"},
83+
"compiler-rt": {"compiler-rt"},
84+
".ci": {"compiler-rt", "libc"},
85+
}
86+
DEPENDENT_RUNTIMES_TO_TEST_NEEDS_RECONFIG = {
87+
"llvm": {"libcxx", "libcxxabi", "libunwind"},
88+
"clang": {"libcxx", "libcxxabi", "libunwind"},
89+
".ci": {"libcxx", "libcxxabi", "libunwind"},
90+
}
6891

6992
EXCLUDE_LINUX = {
7093
"cross-project-tests", # TODO(issues/132796): Tests are failing.
@@ -78,6 +101,9 @@
78101
"libc", # No Windows Support.
79102
"lldb", # TODO(issues/132800): Needs environment setup.
80103
"bolt", # No Windows Support.
104+
"libcxx",
105+
"libcxxabi",
106+
"libunwind",
81107
}
82108

83109
# These are projects that we should test if the project itself is changed but
@@ -93,12 +119,12 @@
93119
"cross-project-tests",
94120
"flang",
95121
"libc",
96-
"libcxx",
97-
"libcxxabi",
98-
"libunwind",
99122
"lldb",
100123
"openmp",
101124
"polly",
125+
"libcxx",
126+
"libcxxabi",
127+
"libunwind",
102128
}
103129

104130
PROJECT_CHECK_TARGETS = {
@@ -111,6 +137,7 @@
111137
"lldb": "check-lldb",
112138
"llvm": "check-llvm",
113139
"clang": "check-clang",
140+
"CIR": "check-clang-cir",
114141
"bolt": "check-bolt",
115142
"lld": "check-lld",
116143
"flang": "check-flang",
@@ -122,21 +149,52 @@
122149
"polly": "check-polly",
123150
}
124151

125-
RUNTIMES = {"libcxx", "libcxxabi", "libunwind"}
152+
RUNTIMES = {"libcxx", "libcxxabi", "libunwind", "compiler-rt", "libc"}
126153

154+
# Meta projects are projects that need explicit handling but do not reside
155+
# in their own top level folder. To add a meta project, the start of the path
156+
# for the metaproject should be mapped to the name of the project below.
157+
# Multiple paths can map to the same metaproject.
158+
META_PROJECTS = {
159+
("clang", "lib", "CIR"): "CIR",
160+
("clang", "test", "CIR"): "CIR",
161+
("clang", "include", "clang", "CIR"): "CIR",
162+
("*", "docs"): "docs",
163+
("llvm", "utils", "gn"): "gn",
164+
(".github", "workflows", "premerge.yaml"): ".ci",
165+
("third-party",): ".ci",
166+
}
167+
168+
# Projects that should not run any tests. These need to be metaprojects.
169+
SKIP_PROJECTS = ["docs", "gn"]
127170

128-
def _add_dependencies(projects: Set[str]) -> Set[str]:
171+
172+
def _add_dependencies(projects: Set[str], runtimes: Set[str]) -> Set[str]:
129173
projects_with_dependents = set(projects)
130174
current_projects_count = 0
131175
while current_projects_count != len(projects_with_dependents):
132176
current_projects_count = len(projects_with_dependents)
133177
for project in list(projects_with_dependents):
134-
if project not in PROJECT_DEPENDENCIES:
135-
continue
136-
projects_with_dependents.update(PROJECT_DEPENDENCIES[project])
178+
if project in PROJECT_DEPENDENCIES:
179+
projects_with_dependents.update(PROJECT_DEPENDENCIES[project])
180+
for runtime in runtimes:
181+
if runtime in PROJECT_DEPENDENCIES:
182+
projects_with_dependents.update(PROJECT_DEPENDENCIES[runtime])
137183
return projects_with_dependents
138184

139185

186+
def _exclude_projects(current_projects: Set[str], platform: str) -> Set[str]:
187+
if platform == "Linux":
188+
to_exclude = EXCLUDE_LINUX
189+
elif platform == "Windows":
190+
to_exclude = EXCLUDE_WINDOWS
191+
elif platform == "Darwin":
192+
to_exclude = EXCLUDE_MAC
193+
else:
194+
raise ValueError(f"Unexpected platform: {platform}")
195+
return current_projects.difference(to_exclude)
196+
197+
140198
def _compute_projects_to_test(modified_projects: Set[str], platform: str) -> Set[str]:
141199
projects_to_test = set()
142200
for modified_project in modified_projects:
@@ -154,81 +212,108 @@ def _compute_projects_to_test(modified_projects: Set[str], platform: str) -> Set
154212
):
155213
continue
156214
projects_to_test.add(dependent_project)
157-
if platform == "Linux":
158-
for to_exclude in EXCLUDE_LINUX:
159-
if to_exclude in projects_to_test:
160-
projects_to_test.remove(to_exclude)
161-
elif platform == "Windows":
162-
for to_exclude in EXCLUDE_WINDOWS:
163-
if to_exclude in projects_to_test:
164-
projects_to_test.remove(to_exclude)
165-
elif platform == "Darwin":
166-
for to_exclude in EXCLUDE_MAC:
167-
if to_exclude in projects_to_test:
168-
projects_to_test.remove(to_exclude)
169-
else:
170-
raise ValueError("Unexpected platform.")
215+
projects_to_test = _exclude_projects(projects_to_test, platform)
171216
return projects_to_test
172217

173218

174-
def _compute_projects_to_build(projects_to_test: Set[str]) -> Set[str]:
175-
return _add_dependencies(projects_to_test)
219+
def _compute_projects_to_build(
220+
projects_to_test: Set[str], runtimes: Set[str]
221+
) -> Set[str]:
222+
return _add_dependencies(projects_to_test, runtimes)
176223

177224

178225
def _compute_project_check_targets(projects_to_test: Set[str]) -> Set[str]:
179226
check_targets = set()
180227
for project_to_test in projects_to_test:
181-
if project_to_test not in PROJECT_CHECK_TARGETS:
182-
continue
183-
check_targets.add(PROJECT_CHECK_TARGETS[project_to_test])
228+
if project_to_test in PROJECT_CHECK_TARGETS:
229+
check_targets.add(PROJECT_CHECK_TARGETS[project_to_test])
184230
return check_targets
185231

186232

187-
def _compute_runtimes_to_test(projects_to_test: Set[str]) -> Set[str]:
233+
def _compute_runtimes_to_test(modified_projects: Set[str], platform: str) -> Set[str]:
188234
runtimes_to_test = set()
189-
for project_to_test in projects_to_test:
190-
if project_to_test in DEPENDENT_RUNTIMES_TO_TEST:
191-
runtimes_to_test.update(DEPENDENT_RUNTIMES_TO_TEST[project_to_test])
192-
if project_to_test in DEPENDENT_RUNTIMES_TO_BUILD:
193-
runtimes_to_test.update(DEPENDENT_RUNTIMES_TO_BUILD[project_to_test])
194-
return runtimes_to_test
235+
for modified_project in modified_projects:
236+
if modified_project in DEPENDENT_RUNTIMES_TO_TEST:
237+
runtimes_to_test.update(DEPENDENT_RUNTIMES_TO_TEST[modified_project])
238+
return _exclude_projects(runtimes_to_test, platform)
195239

196240

197-
def _compute_runtime_check_targets(projects_to_test: Set[str]) -> Set[str]:
198-
check_targets = set()
199-
for project_to_test in projects_to_test:
200-
if project_to_test not in DEPENDENT_RUNTIMES_TO_TEST:
241+
def _compute_runtimes_to_test_needs_reconfig(
242+
modified_projects: Set[str], platform: str
243+
) -> Set[str]:
244+
runtimes_to_test = set()
245+
for modified_project in modified_projects:
246+
if modified_project in DEPENDENT_RUNTIMES_TO_TEST_NEEDS_RECONFIG:
247+
runtimes_to_test.update(
248+
DEPENDENT_RUNTIMES_TO_TEST_NEEDS_RECONFIG[modified_project]
249+
)
250+
return _exclude_projects(runtimes_to_test, platform)
251+
252+
253+
def _compute_runtimes_to_build(
254+
runtimes_to_test: Set[str], modified_projects: Set[str], platform: str
255+
) -> Set[str]:
256+
runtimes_to_build = set(runtimes_to_test)
257+
for modified_project in modified_projects:
258+
if modified_project in DEPENDENT_RUNTIMES_TO_BUILD:
259+
runtimes_to_build.update(DEPENDENT_RUNTIMES_TO_BUILD[modified_project])
260+
return _exclude_projects(runtimes_to_build, platform)
261+
262+
263+
def _path_matches(matcher: tuple[str], file_path: tuple[str]) -> bool:
264+
if len(file_path) < len(matcher):
265+
return False
266+
for match_part, file_part in zip(matcher, file_path):
267+
if match_part == "*" or file_part == "*":
201268
continue
202-
for runtime_to_test in DEPENDENT_RUNTIMES_TO_TEST[project_to_test]:
203-
check_targets.add(PROJECT_CHECK_TARGETS[runtime_to_test])
204-
return check_targets
269+
if match_part != file_part:
270+
return False
271+
return True
272+
273+
274+
def _get_modified_projects_for_file(modified_file: str) -> Set[str]:
275+
modified_projects = set()
276+
path_parts = pathlib.Path(modified_file).parts
277+
for meta_project_files in META_PROJECTS.keys():
278+
if _path_matches(meta_project_files, path_parts):
279+
meta_project = META_PROJECTS[meta_project_files]
280+
if meta_project in SKIP_PROJECTS:
281+
return set()
282+
modified_projects.add(meta_project)
283+
modified_projects.add(pathlib.Path(modified_file).parts[0])
284+
return modified_projects
205285

206286

207287
def _get_modified_projects(modified_files: list[str]) -> Set[str]:
208288
modified_projects = set()
209289
for modified_file in modified_files:
210-
path_parts = pathlib.Path(modified_file).parts
211-
# Exclude files in the docs directory. They do not impact an test
212-
# targets and there is a separate workflow used for ensuring the
213-
# documentation builds.
214-
if len(path_parts) > 2 and path_parts[1] == "docs":
215-
continue
216-
# Exclude files for the gn build. We do not test it within premerge
217-
# and changes occur often enough that they otherwise take up
218-
# capacity.
219-
if len(path_parts) > 3 and path_parts[:3] == ("llvm", "utils", "gn"):
220-
continue
221-
modified_projects.add(pathlib.Path(modified_file).parts[0])
290+
modified_projects.update(_get_modified_projects_for_file(modified_file))
222291
return modified_projects
223292

224293

225294
def get_env_variables(modified_files: list[str], platform: str) -> Set[str]:
226295
modified_projects = _get_modified_projects(modified_files)
227296
projects_to_test = _compute_projects_to_test(modified_projects, platform)
228-
projects_to_build = _compute_projects_to_build(projects_to_test)
297+
runtimes_to_test = _compute_runtimes_to_test(modified_projects, platform)
298+
runtimes_to_test_needs_reconfig = _compute_runtimes_to_test_needs_reconfig(
299+
modified_projects, platform
300+
)
301+
runtimes_to_build = _compute_runtimes_to_build(
302+
runtimes_to_test | runtimes_to_test_needs_reconfig, modified_projects, platform
303+
)
304+
projects_to_build = _compute_projects_to_build(projects_to_test, runtimes_to_build)
229305
projects_check_targets = _compute_project_check_targets(projects_to_test)
230-
runtimes_to_build = _compute_runtimes_to_test(projects_to_test)
231-
runtimes_check_targets = _compute_runtime_check_targets(projects_to_test)
306+
runtimes_check_targets = _compute_project_check_targets(runtimes_to_test)
307+
runtimes_check_targets_needs_reconfig = _compute_project_check_targets(
308+
runtimes_to_test_needs_reconfig
309+
)
310+
311+
# CIR is used as a pseudo-project in this script. It is built as part of the
312+
# clang build, but it requires an explicit option to enable. We set that
313+
# option here, and remove it from the projects_to_build list.
314+
enable_cir = "ON" if "CIR" in projects_to_build else "OFF"
315+
projects_to_build.discard("CIR")
316+
232317
# We use a semicolon to separate the projects/runtimes as they get passed
233318
# to the CMake invocation and thus we need to use the CMake list separator
234319
# (;). We use spaces to separate the check targets as they end up getting
@@ -238,6 +323,10 @@ def get_env_variables(modified_files: list[str], platform: str) -> Set[str]:
238323
"project_check_targets": " ".join(sorted(projects_check_targets)),
239324
"runtimes_to_build": ";".join(sorted(runtimes_to_build)),
240325
"runtimes_check_targets": " ".join(sorted(runtimes_check_targets)),
326+
"runtimes_check_targets_needs_reconfig": " ".join(
327+
sorted(runtimes_check_targets_needs_reconfig)
328+
),
329+
"enable_cir": enable_cir,
241330
}
242331

243332

0 commit comments

Comments
 (0)