Skip to content

Commit 20a67bb

Browse files
[𝘀𝗽𝗿] initial version
Created using spr 1.3.4
2 parents dfa665f + 050bd37 commit 20a67bb

File tree

5 files changed

+379
-279
lines changed

5 files changed

+379
-279
lines changed

.ci/compute-projects.sh

Lines changed: 0 additions & 194 deletions
This file was deleted.

.ci/compute_projects.py

Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
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+
PROJECT_DEPENDENCIES = {
15+
"llvm": set(),
16+
"clang": {"llvm"},
17+
"bolt": {"clang", "lld", "llvm"},
18+
"clang-tools-extra": {"clang", "llvm"},
19+
"compiler-rt": {"clang", "lld"},
20+
"libc": {"clang", "lld"},
21+
"openmp": {"clang", "lld"},
22+
"flang": {"llvm", "clang"},
23+
"lldb": {"llvm", "clang"},
24+
"libclc": {"llvm", "clang"},
25+
"lld": {"llvm"},
26+
"mlir": {"llvm"},
27+
"polly": {"llvm"},
28+
}
29+
30+
DEPENDENTS_TO_TEST = {
31+
"llvm": {"bolt", "clang", "clang-tools-extra", "lld", "lldb", "mlir", "polly"},
32+
"lld": {"bolt", "cross-project-tests"},
33+
"clang": {"clang-tools-extra", "compiler-rt", "cross-project-tests"},
34+
"clang-tools-extra": {"libc"},
35+
"mlir": {"flang"},
36+
}
37+
38+
DEPENDENT_RUNTIMES_TO_TEST = {"clang": {"libcxx", "libcxxabi", "libunwind"}}
39+
40+
EXCLUDE_LINUX = {
41+
"cross-project-tests", # Tests are failing.
42+
"openmp", # https://github.com/google/llvm-premerge-checks/issues/410
43+
}
44+
45+
EXCLUDE_WINDOWS = {
46+
"cross-project-tests", # Tests are failing.
47+
"compiler-rt", # Tests are taking too long.
48+
"openmp", # Does not detect perl installation.
49+
"libc", # No Windows Support.
50+
"lldb", # Custom environment requirements.
51+
"bolt", # No Windows Support.
52+
}
53+
54+
EXCLUDE_MAC = {
55+
"bolt",
56+
"compiler-rt",
57+
"cross-project-tests",
58+
"flang",
59+
"libc",
60+
"libcxx",
61+
"libcxxabi",
62+
"libunwind",
63+
"lldb",
64+
"openmp",
65+
"polly",
66+
}
67+
68+
PROJECT_CHECK_TARGETS = {
69+
"clang-tools-extra": "check-clang-tools",
70+
"compiler-rt": "check-compiler-rt",
71+
"cross-project-tests": "check-cross-project",
72+
"libcxx": "check-cxx",
73+
"libcxxabi": "check-cxxabi",
74+
"libunwind": "check-unwind",
75+
"lldb": "check-lldb",
76+
"llvm": "check-llvm",
77+
"clang": "check-clang",
78+
"bolt": "check-bolt",
79+
"lld": "check-lld",
80+
"flang": "check-flang",
81+
"libc": "check-libc",
82+
"lld": "check-lld",
83+
"lldb": "check-lldb",
84+
"mlir": "check-mlir",
85+
"openmp": "check-openmp",
86+
"polly": "check-polly",
87+
}
88+
89+
90+
def _add_dependencies(projects: Set[str]) -> Set[str]:
91+
projects_with_dependents = set(projects)
92+
current_projects_count = 0
93+
while current_projects_count != len(projects_with_dependents):
94+
current_projects_count = len(projects_with_dependents)
95+
for project in list(projects_with_dependents):
96+
if project not in PROJECT_DEPENDENCIES:
97+
continue
98+
projects_with_dependents.update(PROJECT_DEPENDENCIES[project])
99+
return projects_with_dependents
100+
101+
102+
def _compute_projects_to_test(modified_projects: Set[str], platform: str) -> Set[str]:
103+
projects_to_test = set()
104+
for modified_project in modified_projects:
105+
# Skip all projects where we cannot run tests.
106+
if modified_project not in PROJECT_CHECK_TARGETS:
107+
continue
108+
projects_to_test.add(modified_project)
109+
if modified_project not in DEPENDENTS_TO_TEST:
110+
continue
111+
projects_to_test.update(DEPENDENTS_TO_TEST[modified_project])
112+
if platform == "Linux":
113+
for to_exclude in EXCLUDE_LINUX:
114+
if to_exclude in projects_to_test:
115+
projects_to_test.remove(to_exclude)
116+
elif platform == "Windows":
117+
for to_exclude in EXCLUDE_WINDOWS:
118+
if to_exclude in projects_to_test:
119+
projects_to_test.remove(to_exclude)
120+
elif platform == "Darwin":
121+
for to_exclude in EXCLUDE_MAC:
122+
if to_exclude in projects_to_test:
123+
projects_to_test.remove(to_exclude)
124+
else:
125+
raise ValueError("Unexpected platform.")
126+
return projects_to_test
127+
128+
129+
def _compute_projects_to_build(projects_to_test: Set[str]) -> Set[str]:
130+
return _add_dependencies(projects_to_test)
131+
132+
133+
def _compute_project_check_targets(projects_to_test: Set[str]) -> Set[str]:
134+
check_targets = set()
135+
for project_to_test in projects_to_test:
136+
if project_to_test not in PROJECT_CHECK_TARGETS:
137+
continue
138+
check_targets.add(PROJECT_CHECK_TARGETS[project_to_test])
139+
return check_targets
140+
141+
142+
def _compute_runtimes_to_test(projects_to_test: Set[str]) -> Set[str]:
143+
runtimes_to_test = set()
144+
for project_to_test in projects_to_test:
145+
if project_to_test not in DEPENDENT_RUNTIMES_TO_TEST:
146+
continue
147+
runtimes_to_test.update(DEPENDENT_RUNTIMES_TO_TEST[project_to_test])
148+
return runtimes_to_test
149+
150+
151+
def _compute_runtime_check_targets(runtimes_to_test: Set[str]) -> Set[str]:
152+
check_targets = set()
153+
for runtime_to_test in runtimes_to_test:
154+
check_targets.add(PROJECT_CHECK_TARGETS[runtime_to_test])
155+
return check_targets
156+
157+
158+
def _get_modified_projects(modified_files: list[str]) -> Set[str]:
159+
modified_projects = set()
160+
for modified_file in modified_files:
161+
modified_projects.add(pathlib.Path(modified_file).parts[0])
162+
return modified_projects
163+
164+
165+
def get_env_variables(modified_files: list[str], platform: str) -> Set[str]:
166+
modified_projects = _get_modified_projects(modified_files)
167+
projects_to_test = _compute_projects_to_test(modified_projects, platform)
168+
projects_to_build = _compute_projects_to_build(projects_to_test)
169+
projects_check_targets = _compute_project_check_targets(projects_to_test)
170+
runtimes_to_test = _compute_runtimes_to_test(projects_to_test)
171+
runtimes_check_targets = _compute_runtime_check_targets(runtimes_to_test)
172+
return {
173+
"projects_to_build": ";".join(sorted(projects_to_build)),
174+
"project_check_targets": " ".join(sorted(projects_check_targets)),
175+
"runtimes_to_build": ";".join(sorted(runtimes_to_test)),
176+
"runtimes_check_targets": " ".join(sorted(runtimes_check_targets)),
177+
}
178+
179+
180+
if __name__ == "__main__":
181+
current_platform = platform.system()
182+
if len(sys.argv) == 2:
183+
current_platform = sys.argv[1]
184+
env_variables = get_env_variables(sys.stdin.readlines(), current_platform)
185+
for env_variable in env_variables:
186+
print(f"{env_variable}=\"{env_variables[env_variable]}\"")

0 commit comments

Comments
 (0)