Skip to content

Commit 050bd37

Browse files
[𝘀𝗽𝗿] changes to main this commit is based on
Created using spr 1.3.4 [skip ci]
1 parent dfa665f commit 050bd37

File tree

2 files changed

+352
-0
lines changed

2 files changed

+352
-0
lines changed

.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]}\"")

.ci/compute_projects_test.py

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
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+
"""Does some stuff."""
5+
6+
import unittest
7+
8+
import compute_projects
9+
10+
11+
class TestComputeProjects(unittest.TestCase):
12+
def test_llvm(self):
13+
env_variables = compute_projects.get_env_variables(
14+
["llvm/CMakeLists.txt"], "Linux"
15+
)
16+
self.assertEqual(
17+
env_variables["projects_to_build"],
18+
"bolt;clang;clang-tools-extra;lld;lldb;llvm;mlir;polly",
19+
)
20+
self.assertEqual(
21+
env_variables["project_check_targets"],
22+
"check-bolt check-clang check-clang-tools check-lld check-lldb check-llvm check-mlir check-polly",
23+
)
24+
self.assertEqual(
25+
env_variables["runtimes_to_build"], "libcxx;libcxxabi;libunwind"
26+
)
27+
self.assertEqual(
28+
env_variables["runtimes_check_targets"],
29+
"check-cxx check-cxxabi check-unwind",
30+
)
31+
32+
def test_llvm_windows(self):
33+
env_variables = compute_projects.get_env_variables(
34+
["llvm/CMakeLists.txt"], "Windows"
35+
)
36+
self.assertEqual(
37+
env_variables["projects_to_build"],
38+
"clang;clang-tools-extra;lld;llvm;mlir;polly",
39+
)
40+
self.assertEqual(
41+
env_variables["project_check_targets"],
42+
"check-clang check-clang-tools check-lld check-llvm check-mlir check-polly",
43+
)
44+
self.assertEqual(
45+
env_variables["runtimes_to_build"], "libcxx;libcxxabi;libunwind"
46+
)
47+
self.assertEqual(
48+
env_variables["runtimes_check_targets"],
49+
"check-cxx check-cxxabi check-unwind",
50+
)
51+
52+
def test_llvm_mac(self):
53+
env_variables = compute_projects.get_env_variables(
54+
["llvm/CMakeLists.txt"], "Darwin"
55+
)
56+
self.assertEqual(
57+
env_variables["projects_to_build"],
58+
"clang;clang-tools-extra;lld;llvm;mlir",
59+
)
60+
self.assertEqual(
61+
env_variables["project_check_targets"],
62+
"check-clang check-clang-tools check-lld check-llvm check-mlir",
63+
)
64+
self.assertEqual(
65+
env_variables["runtimes_to_build"], "libcxx;libcxxabi;libunwind"
66+
)
67+
self.assertEqual(
68+
env_variables["runtimes_check_targets"],
69+
"check-cxx check-cxxabi check-unwind",
70+
)
71+
72+
def test_clang(self):
73+
env_variables = compute_projects.get_env_variables(
74+
["clang/CMakeLists.txt"], "Linux"
75+
)
76+
self.assertEqual(
77+
env_variables["projects_to_build"],
78+
"clang;clang-tools-extra;compiler-rt;lld;llvm",
79+
)
80+
self.assertEqual(
81+
env_variables["project_check_targets"],
82+
"check-clang check-clang-tools check-compiler-rt",
83+
)
84+
self.assertEqual(
85+
env_variables["runtimes_to_build"], "libcxx;libcxxabi;libunwind"
86+
)
87+
self.assertEqual(
88+
env_variables["runtimes_check_targets"],
89+
"check-cxx check-cxxabi check-unwind",
90+
)
91+
92+
def test_clang_windows(self):
93+
env_variables = compute_projects.get_env_variables(
94+
["clang/CMakeLists.txt"], "Windows"
95+
)
96+
self.assertEqual(
97+
env_variables["projects_to_build"], "clang;clang-tools-extra;llvm"
98+
)
99+
self.assertEqual(
100+
env_variables["project_check_targets"], "check-clang check-clang-tools"
101+
)
102+
self.assertEqual(
103+
env_variables["runtimes_to_build"], "libcxx;libcxxabi;libunwind"
104+
)
105+
self.assertEqual(
106+
env_variables["runtimes_check_targets"],
107+
"check-cxx check-cxxabi check-unwind",
108+
)
109+
110+
def test_bolt(self):
111+
env_variables = compute_projects.get_env_variables(
112+
["bolt/CMakeLists.txt"], "Linux"
113+
)
114+
self.assertEqual(env_variables["projects_to_build"], "bolt;clang;lld;llvm")
115+
self.assertEqual(env_variables["project_check_targets"], "check-bolt")
116+
self.assertEqual(env_variables["runtimes_to_build"], "")
117+
self.assertEqual(env_variables["runtimes_check_targets"], "")
118+
119+
def test_lldb(self):
120+
env_variables = compute_projects.get_env_variables(
121+
["lldb/CMakeLists.txt"], "Linux"
122+
)
123+
self.assertEqual(env_variables["projects_to_build"], "clang;lldb;llvm")
124+
self.assertEqual(env_variables["project_check_targets"], "check-lldb")
125+
self.assertEqual(env_variables["runtimes_to_build"], "")
126+
self.assertEqual(env_variables["runtimes_check_targets"], "")
127+
128+
def test_mlir(self):
129+
env_variables = compute_projects.get_env_variables(
130+
["mlir/CMakeLists.txt"], "Linux"
131+
)
132+
self.assertEqual(env_variables["projects_to_build"], "clang;flang;llvm;mlir")
133+
self.assertEqual(
134+
env_variables["project_check_targets"], "check-flang check-mlir"
135+
)
136+
self.assertEqual(env_variables["runtimes_to_build"], "")
137+
self.assertEqual(env_variables["runtimes_check_targets"], "")
138+
139+
def test_flang(self):
140+
env_variables = compute_projects.get_env_variables(
141+
["flang/CMakeLists.txt"], "Linux"
142+
)
143+
self.assertEqual(env_variables["projects_to_build"], "clang;flang;llvm")
144+
self.assertEqual(env_variables["project_check_targets"], "check-flang")
145+
self.assertEqual(env_variables["runtimes_to_build"], "")
146+
self.assertEqual(env_variables["runtimes_check_targets"], "")
147+
148+
def test_invalid_subproject(self):
149+
env_variables = compute_projects.get_env_variables(
150+
[".ci/compute_projects.py"], "Linux"
151+
)
152+
self.assertEqual(env_variables["projects_to_build"], "")
153+
self.assertEqual(env_variables["project_check_targets"], "")
154+
self.assertEqual(env_variables["runtimes_to_build"], "")
155+
self.assertEqual(env_variables["runtimes_check_targets"], "")
156+
157+
def test_top_level_file(self):
158+
env_variables = compute_projects.get_env_variables(["README.md"], "Linux")
159+
self.assertEqual(env_variables["projects_to_build"], "")
160+
self.assertEqual(env_variables["project_check_targets"], "")
161+
self.assertEqual(env_variables["runtimes_to_build"], "")
162+
self.assertEqual(env_variables["runtimes_check_targets"], "")
163+
164+
165+
if __name__ == "__main__":
166+
unittest.main()

0 commit comments

Comments
 (0)