mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 20:20:10 +01:00
This removes the need to install any specific version of Python or figure out how to configure it by instead asking users to install `uv` and letting it manage Python. Among other advantages, `uv` is designed to be fast enough to embed directly into our scripts. We were already using this in `bench_runner.py` so that the script could import non standard library dependencies. Moving to it for the rest of our Python unifies the approach and will also enable dependencies whenever needed. I've left `github_tools` alone as it has special handling with its own Bazel setup. I've updated the contributing tools to explain the approach here.
65 lines
1.8 KiB
Python
Executable File
65 lines
1.8 KiB
Python
Executable File
#!/usr/bin/env -S uv run --script
|
|
|
|
# /// script
|
|
# requires-python = ">=3.11"
|
|
# ///
|
|
|
|
|
|
"""Detects and prevents dependencies on LLVM's googletest.
|
|
|
|
Carbon uses googletest directly, and it's a significantly more recent version
|
|
than is provided by LLVM. Using both versions in the same binary leads to
|
|
problems, so this detects dependencies.
|
|
|
|
We also have some dependency checking at //bazel/check_deps. This is a separate
|
|
script because check_deps relies on being able to validate specific binaries
|
|
which change infrequently, whereas this effectively monitors all cc_test rules,
|
|
the set of which is expected to be altered more often.
|
|
"""
|
|
|
|
__copyright__ = """
|
|
Part of the Carbon Language project, under the Apache License v2.0 with LLVM
|
|
Exceptions. See /LICENSE for license information.
|
|
SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
"""
|
|
|
|
import subprocess
|
|
|
|
import scripts_utils
|
|
|
|
_MESSAGE = """\
|
|
Dependencies on @llvm-project//llvm:gtest are forbidden, but a dependency path
|
|
was detected:
|
|
|
|
%s
|
|
Carbon uses GoogleTest through @googletest, which is a different
|
|
version than LLVM uses at @llvm-project//llvm:gtest. As a consequence,
|
|
dependencies on @llvm-project//llvm:gtest must be avoided.
|
|
"""
|
|
|
|
|
|
def main() -> None:
|
|
scripts_utils.chdir_repo_root()
|
|
args = [
|
|
scripts_utils.locate_bazel(),
|
|
"query",
|
|
"somepath("
|
|
# tree_sitter is excluded here because it causes the query to failure on
|
|
# `@platforms`.
|
|
+ "//... except //utils/tree_sitter/..., "
|
|
+ "@llvm-project//third-party/unittest:gtest)",
|
|
]
|
|
p = subprocess.run(
|
|
args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, encoding="utf-8"
|
|
)
|
|
if p.returncode != 0:
|
|
print(p.stderr)
|
|
exit(f"bazel query returned {p.returncode}")
|
|
if p.stdout:
|
|
exit(_MESSAGE % p.stdout)
|
|
print("Done!")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|