|
144 | 144 |
|
145 | 145 | RUNTIMES = {"libcxx", "libcxxabi", "libunwind", "compiler-rt", "libc"}
|
146 | 146 |
|
| 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 | + |
147 | 162 |
|
148 | 163 | def _add_dependencies(projects: Set[str], runtimes: Set[str]) -> Set[str]:
|
149 | 164 | projects_with_dependents = set(projects)
|
@@ -236,29 +251,34 @@ def _compute_runtimes_to_build(
|
236 | 251 | return _exclude_projects(runtimes_to_build, platform)
|
237 | 252 |
|
238 | 253 |
|
| 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 | + |
239 | 278 | def _get_modified_projects(modified_files: list[str]) -> Set[str]:
|
240 | 279 | modified_projects = set()
|
241 | 280 | 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)) |
262 | 282 | return modified_projects
|
263 | 283 |
|
264 | 284 |
|
|
0 commit comments