diff --git a/test/apply_fixes/execution_logic.py b/test/apply_fixes/execution_logic.py index 4c226361..b4ecb1b5 100644 --- a/test/apply_fixes/execution_logic.py +++ b/test/apply_fixes/execution_logic.py @@ -17,48 +17,30 @@ TEST_CASES_DIR = Path("test/apply_fixes") TEST_WORKSPACES_DIR = TEST_CASES_DIR / "workspaces" -WORKSPACE_FILE_TEMPLATE = """ -local_repository( - name = "depend_on_what_you_use", - path = "{dwyu_path}", -) - -load("@depend_on_what_you_use//:setup_step_1.bzl", "setup_step_1") -setup_step_1() - -load("@depend_on_what_you_use//:setup_step_2.bzl", "setup_step_2") -setup_step_2() - -load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") -load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") +MODULE_FILE_TEMPLATE = """ +bazel_dep(name = "depend_on_what_you_use") +local_path_override(module_name = "depend_on_what_you_use", path = "{dwyu_path}") # -# One can use DWYU without the content below. Those are dependencies to enable testing. +# Setup dependencies for test orchestration # -http_archive( - name = "bazel_skylib", - sha256 = "9f38886a40548c6e96c106b752f242130ee11aaa068a56ba7e56f4511f33e4f2", - urls = ["https://github.com/bazelbuild/bazel-skylib/releases/download/1.6.1/bazel-skylib-1.6.1.tar.gz"], -) - -maybe( - http_archive, - name = "rules_python", - sha256 = "e85ae30de33625a63eca7fc40a94fea845e641888e52f32b6beea91e8b1b2793", - strip_prefix = "rules_python-0.27.1", - urls = ["https://github.com/bazelbuild/rules_python/releases/download/0.27.1/rules_python-0.27.1.tar.gz"], -) - -load("@rules_python//python:repositories.bzl", "python_register_toolchains") -python_register_toolchains( - name = "python", - python_version = "3.8", -) +bazel_dep(name = "bazel_skylib", version = "1.6.1") + +bazel_dep(name = "rules_python", version = "0.27.1") +python = use_extension("@rules_python//python/extensions:python.bzl", "python") +python.toolchain(python_version = "3.8") {extra_content} """ +BAZEL_RC_FILE = """ +common --nolegacy_external_runfiles +common --lockfile_mode=off +""" + +BAZEL_VERSION = "7.0.0" + def dwyu_path_as_string(dwyu_path: Path) -> str: """ @@ -71,16 +53,16 @@ def setup_test_workspace( origin_workspace: Path, test_sources: Path, extra_workspace_file_content: str, temporary_workspace: Path ) -> None: copytree(src=test_sources, dst=str(temporary_workspace), dirs_exist_ok=True) - with temporary_workspace.joinpath("WORKSPACE").open(mode="w", encoding="utf-8") as ws_file: + with temporary_workspace.joinpath("MODULE.bazel").open(mode="w", encoding="utf-8") as ws_file: ws_file.write( - WORKSPACE_FILE_TEMPLATE.format( + MODULE_FILE_TEMPLATE.format( dwyu_path=dwyu_path_as_string(origin_workspace), extra_content=extra_workspace_file_content ) ) with temporary_workspace.joinpath(".bazelversion").open(mode="w", encoding="utf-8") as ws_file: - ws_file.write("7.0.0") + ws_file.write(BAZEL_VERSION) with temporary_workspace.joinpath(".bazelrc").open(mode="w", encoding="utf-8") as ws_file: - ws_file.write("common --nolegacy_external_runfiles\ncommon --noenable_bzlmod") + ws_file.write(BAZEL_RC_FILE) def cleanup(test_workspace: Path) -> None: diff --git a/test/apply_fixes/missing_dependency/test_find_external_dependency.py b/test/apply_fixes/missing_dependency/test_find_external_dependency.py index d7b8eee3..a7a18d6a 100644 --- a/test/apply_fixes/missing_dependency/test_find_external_dependency.py +++ b/test/apply_fixes/missing_dependency/test_find_external_dependency.py @@ -9,7 +9,10 @@ def test_target(self) -> str: @property def extra_workspace_file_content(self) -> str: - return 'load("//:load_external_dep.bzl", "load_external_dep")\nload_external_dep()' + return """ +bazel_dep(name = "external_dep") +local_path_override(module_name = "external_dep", path = "external_dep") +""" def execute_test_logic(self) -> Result: self._create_reports() diff --git a/test/apply_fixes/missing_dependency/workspace/external_dep/MODULE.bazel b/test/apply_fixes/missing_dependency/workspace/external_dep/MODULE.bazel new file mode 100644 index 00000000..aa54fbba --- /dev/null +++ b/test/apply_fixes/missing_dependency/workspace/external_dep/MODULE.bazel @@ -0,0 +1 @@ +module(name = "external_dep") diff --git a/test/apply_fixes/missing_dependency/workspace/external_dep/WORKSPACE b/test/apply_fixes/missing_dependency/workspace/external_dep/WORKSPACE deleted file mode 100644 index e69de29b..00000000 diff --git a/test/apply_fixes/missing_dependency/workspace/load_external_dep.bzl b/test/apply_fixes/missing_dependency/workspace/load_external_dep.bzl deleted file mode 100644 index df0f26ef..00000000 --- a/test/apply_fixes/missing_dependency/workspace/load_external_dep.bzl +++ /dev/null @@ -1,6 +0,0 @@ -# buildifier: disable=unnamed-macro -def load_external_dep(): - native.local_repository( - name = "external_dep", - path = "external_dep", - )