Skip to content

Commit b5c8795

Browse files
[CI] Refactor compute_projects to Introduce Meta Projects
This patch introduces the concept of meta projects into the compute_projects script. Meta projects are projects like CIR and GoogleTest where they do not have their own top level project. This patch adds a little bit of extra code in exchange for making meta projects a first level concept that can be configured almost entirely by changing around the mappings at the top of the file. This patch also refactors the project skipping functionality to use meta projects. This (arguably) makes the CIR support a little bit cleaner and is necessary for some future improvements like running all the tests on Github workflow changes and running tests when third-party changes. Reviewers: Endilll, andykaylor, lnihlen, gburgessiv, dschuff, Keenuts, cmtice Reviewed By: andykaylor Pull Request: #150249
1 parent 690c3ee commit b5c8795

File tree

1 file changed

+40
-20
lines changed

1 file changed

+40
-20
lines changed

.ci/compute_projects.py

Lines changed: 40 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,21 @@
144144

145145
RUNTIMES = {"libcxx", "libcxxabi", "libunwind", "compiler-rt", "libc"}
146146

147+
# Meta projects are projects that need explicit handling but do not reside
148+
# in their own top level folder. To add a meta project, the start of the path
149+
# for the metaproject should be mapped to the name of the project below.
150+
# Multiple paths can map to the same metaproject.
151+
META_PROJECTS = {
152+
("clang", "lib", "CIR"): "CIR",
153+
("clang", "test", "CIR"): "CIR",
154+
("clang", "include", "clang", "CIR"): "CIR",
155+
("*", "docs"): "docs",
156+
("llvm", "utils", "gn"): "gn",
157+
}
158+
159+
# Projects that should not run any tests. These need to be metaprojects.
160+
SKIP_PROJECTS = ["docs", "gn"]
161+
147162

148163
def _add_dependencies(projects: Set[str], runtimes: Set[str]) -> Set[str]:
149164
projects_with_dependents = set(projects)
@@ -236,29 +251,34 @@ def _compute_runtimes_to_build(
236251
return _exclude_projects(runtimes_to_build, platform)
237252

238253

254+
def _path_matches(matcher: tuple[str], file_path: tuple[str]) -> bool:
255+
if len(file_path) < len(matcher):
256+
return False
257+
for match_part, file_part in zip(matcher, file_path):
258+
if match_part == "*" or file_part == "*":
259+
continue
260+
if match_part != file_part:
261+
return False
262+
return True
263+
264+
265+
def _get_modified_projects_for_file(modified_file: str) -> Set[str]:
266+
modified_projects = set()
267+
path_parts = pathlib.Path(modified_file).parts
268+
for meta_project_files in META_PROJECTS.keys():
269+
if _path_matches(meta_project_files, path_parts):
270+
meta_project = META_PROJECTS[meta_project_files]
271+
if meta_project in SKIP_PROJECTS:
272+
return set()
273+
modified_projects.add(meta_project)
274+
modified_projects.add(pathlib.Path(modified_file).parts[0])
275+
return modified_projects
276+
277+
239278
def _get_modified_projects(modified_files: list[str]) -> Set[str]:
240279
modified_projects = set()
241280
for modified_file in modified_files:
242-
path_parts = pathlib.Path(modified_file).parts
243-
# Exclude files in the docs directory. They do not impact an test
244-
# targets and there is a separate workflow used for ensuring the
245-
# documentation builds.
246-
if len(path_parts) > 2 and path_parts[1] == "docs":
247-
continue
248-
# Exclude files for the gn build. We do not test it within premerge
249-
# and changes occur often enough that they otherwise take up
250-
# capacity.
251-
if len(path_parts) > 3 and path_parts[:3] == ("llvm", "utils", "gn"):
252-
continue
253-
# If the file is in the clang/lib/CIR directory, add the CIR project.
254-
if len(path_parts) > 3 and (
255-
path_parts[:3] == ("clang", "lib", "CIR")
256-
or path_parts[:3] == ("clang", "test", "CIR")
257-
or path_parts[:4] == ("clang", "include", "clang", "CIR")
258-
):
259-
modified_projects.add("CIR")
260-
# Fall through to add clang.
261-
modified_projects.add(pathlib.Path(modified_file).parts[0])
281+
modified_projects.update(_get_modified_projects_for_file(modified_file))
262282
return modified_projects
263283

264284

0 commit comments

Comments
 (0)