Skip to content

Commit 2a387fe

Browse files
author
Andres Wearden
committed
[llvm-profdata][llvm-cov] Add options to merge coverage by object filename and show per-architecture coverage; added llvm-lit tests for these features
1 parent e4e7a7e commit 2a387fe

File tree

25,473 files changed

+1717515
-856020
lines changed

Some content is hidden

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

25,473 files changed

+1717515
-856020
lines changed

.ci/compute_projects.py

Lines changed: 151 additions & 58 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,15 +50,43 @@
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

60-
DEPENDENT_RUNTIMES_TO_TEST = {"clang": {"libcxx", "libcxxabi", "libunwind"}}
72+
# This mapping describes runtimes that should be enabled for a specific project,
73+
# but not necessarily run for testing. The only case of this currently is lldb
74+
# which needs some runtimes enabled for tests.
75+
DEPENDENT_RUNTIMES_TO_BUILD = {"lldb": {"libcxx", "libcxxabi", "libunwind"}}
76+
77+
# This mapping describes runtimes that should be tested when the key project is
78+
# touched.
79+
DEPENDENT_RUNTIMES_TO_TEST = {
80+
"clang": {"compiler-rt"},
81+
"clang-tools-extra": {"libc"},
82+
"libc": {"libc"},
83+
".ci": {"compiler-rt", "libc"},
84+
}
85+
DEPENDENT_RUNTIMES_TO_TEST_NEEDS_RECONFIG = {
86+
"llvm": {"libcxx", "libcxxabi", "libunwind"},
87+
"clang": {"libcxx", "libcxxabi", "libunwind"},
88+
".ci": {"libcxx", "libcxxabi", "libunwind"},
89+
}
6190

6291
EXCLUDE_LINUX = {
6392
"cross-project-tests", # TODO(issues/132796): Tests are failing.
@@ -86,9 +115,6 @@
86115
"cross-project-tests",
87116
"flang",
88117
"libc",
89-
"libcxx",
90-
"libcxxabi",
91-
"libunwind",
92118
"lldb",
93119
"openmp",
94120
"polly",
@@ -104,6 +130,7 @@
104130
"lldb": "check-lldb",
105131
"llvm": "check-llvm",
106132
"clang": "check-clang",
133+
"CIR": "check-clang-cir",
107134
"bolt": "check-bolt",
108135
"lld": "check-lld",
109136
"flang": "check-flang",
@@ -115,21 +142,52 @@
115142
"polly": "check-polly",
116143
}
117144

118-
RUNTIMES = {"libcxx", "libcxxabi", "libunwind"}
145+
RUNTIMES = {"libcxx", "libcxxabi", "libunwind", "compiler-rt", "libc"}
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+
(".github", "workflows", "premerge.yaml"): ".ci",
158+
("third-party",): ".ci",
159+
}
160+
161+
# Projects that should not run any tests. These need to be metaprojects.
162+
SKIP_PROJECTS = ["docs", "gn"]
119163

120164

121-
def _add_dependencies(projects: Set[str]) -> Set[str]:
165+
def _add_dependencies(projects: Set[str], runtimes: Set[str]) -> Set[str]:
122166
projects_with_dependents = set(projects)
123167
current_projects_count = 0
124168
while current_projects_count != len(projects_with_dependents):
125169
current_projects_count = len(projects_with_dependents)
126170
for project in list(projects_with_dependents):
127-
if project not in PROJECT_DEPENDENCIES:
128-
continue
129-
projects_with_dependents.update(PROJECT_DEPENDENCIES[project])
171+
if project in PROJECT_DEPENDENCIES:
172+
projects_with_dependents.update(PROJECT_DEPENDENCIES[project])
173+
for runtime in runtimes:
174+
if runtime in PROJECT_DEPENDENCIES:
175+
projects_with_dependents.update(PROJECT_DEPENDENCIES[runtime])
130176
return projects_with_dependents
131177

132178

179+
def _exclude_projects(current_projects: Set[str], platform: str) -> Set[str]:
180+
if platform == "Linux":
181+
to_exclude = EXCLUDE_LINUX
182+
elif platform == "Windows":
183+
to_exclude = EXCLUDE_WINDOWS
184+
elif platform == "Darwin":
185+
to_exclude = EXCLUDE_MAC
186+
else:
187+
raise ValueError(f"Unexpected platform: {platform}")
188+
return current_projects.difference(to_exclude)
189+
190+
133191
def _compute_projects_to_test(modified_projects: Set[str], platform: str) -> Set[str]:
134192
projects_to_test = set()
135193
for modified_project in modified_projects:
@@ -147,86 +205,121 @@ def _compute_projects_to_test(modified_projects: Set[str], platform: str) -> Set
147205
):
148206
continue
149207
projects_to_test.add(dependent_project)
150-
if platform == "Linux":
151-
for to_exclude in EXCLUDE_LINUX:
152-
if to_exclude in projects_to_test:
153-
projects_to_test.remove(to_exclude)
154-
elif platform == "Windows":
155-
for to_exclude in EXCLUDE_WINDOWS:
156-
if to_exclude in projects_to_test:
157-
projects_to_test.remove(to_exclude)
158-
elif platform == "Darwin":
159-
for to_exclude in EXCLUDE_MAC:
160-
if to_exclude in projects_to_test:
161-
projects_to_test.remove(to_exclude)
162-
else:
163-
raise ValueError("Unexpected platform.")
208+
projects_to_test = _exclude_projects(projects_to_test, platform)
164209
return projects_to_test
165210

166211

167-
def _compute_projects_to_build(projects_to_test: Set[str]) -> Set[str]:
168-
return _add_dependencies(projects_to_test)
212+
def _compute_projects_to_build(
213+
projects_to_test: Set[str], runtimes: Set[str]
214+
) -> Set[str]:
215+
return _add_dependencies(projects_to_test, runtimes)
169216

170217

171218
def _compute_project_check_targets(projects_to_test: Set[str]) -> Set[str]:
172219
check_targets = set()
173220
for project_to_test in projects_to_test:
174-
if project_to_test not in PROJECT_CHECK_TARGETS:
175-
continue
176-
check_targets.add(PROJECT_CHECK_TARGETS[project_to_test])
221+
if project_to_test in PROJECT_CHECK_TARGETS:
222+
check_targets.add(PROJECT_CHECK_TARGETS[project_to_test])
177223
return check_targets
178224

179225

180-
def _compute_runtimes_to_test(projects_to_test: Set[str]) -> Set[str]:
226+
def _compute_runtimes_to_test(modified_projects: Set[str], platform: str) -> Set[str]:
181227
runtimes_to_test = set()
182-
for project_to_test in projects_to_test:
183-
if project_to_test not in DEPENDENT_RUNTIMES_TO_TEST:
228+
for modified_project in modified_projects:
229+
if modified_project in DEPENDENT_RUNTIMES_TO_TEST:
230+
runtimes_to_test.update(DEPENDENT_RUNTIMES_TO_TEST[modified_project])
231+
return _exclude_projects(runtimes_to_test, platform)
232+
233+
234+
def _compute_runtimes_to_test_needs_reconfig(
235+
modified_projects: Set[str], platform: str
236+
) -> Set[str]:
237+
runtimes_to_test = set()
238+
for modified_project in modified_projects:
239+
if modified_project in DEPENDENT_RUNTIMES_TO_TEST_NEEDS_RECONFIG:
240+
runtimes_to_test.update(
241+
DEPENDENT_RUNTIMES_TO_TEST_NEEDS_RECONFIG[modified_project]
242+
)
243+
return _exclude_projects(runtimes_to_test, platform)
244+
245+
246+
def _compute_runtimes_to_build(
247+
runtimes_to_test: Set[str], modified_projects: Set[str], platform: str
248+
) -> Set[str]:
249+
runtimes_to_build = set(runtimes_to_test)
250+
for modified_project in modified_projects:
251+
if modified_project in DEPENDENT_RUNTIMES_TO_BUILD:
252+
runtimes_to_build.update(DEPENDENT_RUNTIMES_TO_BUILD[modified_project])
253+
return _exclude_projects(runtimes_to_build, platform)
254+
255+
256+
def _path_matches(matcher: tuple[str], file_path: tuple[str]) -> bool:
257+
if len(file_path) < len(matcher):
258+
return False
259+
for match_part, file_part in zip(matcher, file_path):
260+
if match_part == "*" or file_part == "*":
184261
continue
185-
runtimes_to_test.update(DEPENDENT_RUNTIMES_TO_TEST[project_to_test])
186-
return runtimes_to_test
262+
if match_part != file_part:
263+
return False
264+
return True
187265

188266

189-
def _compute_runtime_check_targets(runtimes_to_test: Set[str]) -> Set[str]:
190-
check_targets = set()
191-
for runtime_to_test in runtimes_to_test:
192-
check_targets.add(PROJECT_CHECK_TARGETS[runtime_to_test])
193-
return check_targets
267+
def _get_modified_projects_for_file(modified_file: str) -> Set[str]:
268+
modified_projects = set()
269+
path_parts = pathlib.Path(modified_file).parts
270+
for meta_project_files in META_PROJECTS.keys():
271+
if _path_matches(meta_project_files, path_parts):
272+
meta_project = META_PROJECTS[meta_project_files]
273+
if meta_project in SKIP_PROJECTS:
274+
return set()
275+
modified_projects.add(meta_project)
276+
modified_projects.add(pathlib.Path(modified_file).parts[0])
277+
return modified_projects
194278

195279

196280
def _get_modified_projects(modified_files: list[str]) -> Set[str]:
197281
modified_projects = set()
198282
for modified_file in modified_files:
199-
path_parts = pathlib.Path(modified_file).parts
200-
# Exclude files in the docs directory. They do not impact an test
201-
# targets and there is a separate workflow used for ensuring the
202-
# documentation builds.
203-
if len(path_parts) > 2 and path_parts[1] == "docs":
204-
continue
205-
# Exclude files for the gn build. We do not test it within premerge
206-
# and changes occur often enough that they otherwise take up
207-
# capacity.
208-
if len(path_parts) > 3 and path_parts[:3] == ("llvm", "utils", "gn"):
209-
continue
210-
modified_projects.add(pathlib.Path(modified_file).parts[0])
283+
modified_projects.update(_get_modified_projects_for_file(modified_file))
211284
return modified_projects
212285

213286

214287
def get_env_variables(modified_files: list[str], platform: str) -> Set[str]:
215288
modified_projects = _get_modified_projects(modified_files)
216289
projects_to_test = _compute_projects_to_test(modified_projects, platform)
217-
projects_to_build = _compute_projects_to_build(projects_to_test)
290+
runtimes_to_test = _compute_runtimes_to_test(modified_projects, platform)
291+
runtimes_to_test_needs_reconfig = _compute_runtimes_to_test_needs_reconfig(
292+
modified_projects, platform
293+
)
294+
runtimes_to_build = _compute_runtimes_to_build(
295+
runtimes_to_test | runtimes_to_test_needs_reconfig, modified_projects, platform
296+
)
297+
projects_to_build = _compute_projects_to_build(projects_to_test, runtimes_to_build)
218298
projects_check_targets = _compute_project_check_targets(projects_to_test)
219-
runtimes_to_test = _compute_runtimes_to_test(projects_to_test)
220-
runtimes_check_targets = _compute_runtime_check_targets(runtimes_to_test)
299+
runtimes_check_targets = _compute_project_check_targets(runtimes_to_test)
300+
runtimes_check_targets_needs_reconfig = _compute_project_check_targets(
301+
runtimes_to_test_needs_reconfig
302+
)
303+
304+
# CIR is used as a pseudo-project in this script. It is built as part of the
305+
# clang build, but it requires an explicit option to enable. We set that
306+
# option here, and remove it from the projects_to_build list.
307+
enable_cir = "ON" if "CIR" in projects_to_build else "OFF"
308+
projects_to_build.discard("CIR")
309+
221310
# We use a semicolon to separate the projects/runtimes as they get passed
222311
# to the CMake invocation and thus we need to use the CMake list separator
223312
# (;). We use spaces to separate the check targets as they end up getting
224313
# passed to ninja.
225314
return {
226315
"projects_to_build": ";".join(sorted(projects_to_build)),
227316
"project_check_targets": " ".join(sorted(projects_check_targets)),
228-
"runtimes_to_build": ";".join(sorted(runtimes_to_test)),
317+
"runtimes_to_build": ";".join(sorted(runtimes_to_build)),
229318
"runtimes_check_targets": " ".join(sorted(runtimes_check_targets)),
319+
"runtimes_check_targets_needs_reconfig": " ".join(
320+
sorted(runtimes_check_targets_needs_reconfig)
321+
),
322+
"enable_cir": enable_cir,
230323
}
231324

232325

0 commit comments

Comments
 (0)