Skip to content

Commit ad1c841

Browse files
committed
Integration test for bazelbuild#1530
1 parent 1357b85 commit ad1c841

28 files changed

+322
-0
lines changed

.bazelrc

+5
Large diffs are not rendered by default.

BUILD.bazel

+32
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ bzl_library(
1111
visibility = ["//visibility:public"],
1212
)
1313

14+
bzl_library(
15+
name = "bazel_versions",
16+
srcs = ["bazel_versions.bzl"],
17+
visibility = ["//:__subpackages__"],
18+
)
19+
1420
# This setting may be changed from the command line to generate machine readable errors.
1521
error_format(
1622
name = "error_format",
@@ -101,3 +107,29 @@ capture_clippy_output(
101107
build_setting_default = False,
102108
visibility = ["//visibility:public"],
103109
)
110+
111+
filegroup(
112+
name = "all_files",
113+
srcs = [
114+
"BUILD.bazel",
115+
"WORKSPACE.bazel",
116+
"//rust:all_files",
117+
"//rust/platform:all_files",
118+
"//rust/platform/channel:all_files",
119+
"//rust/platform/cpu:all_files",
120+
"//rust/platform/os:all_files",
121+
"//rust/private:all_files",
122+
"//rust/private/dummy_cc_toolchain:all_files",
123+
"//rust/rust_analyzer:all_files",
124+
"//rust/settings:all_files",
125+
"//rust/toolchain:all_files",
126+
"//rust/toolchain/channel:all_files",
127+
"//util:all_files",
128+
"//util/dir_zipper:all_files",
129+
"//util/import:all_files",
130+
"//util/import/3rdparty:all_files",
131+
"//util/label:all_files",
132+
"//util/process_wrapper:all_files",
133+
],
134+
visibility = ["//:__subpackages__"],
135+
)

WORKSPACE.bazel

+13
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,19 @@ load("//test:deps.bzl", "rules_rust_test_deps")
4444

4545
rules_rust_test_deps()
4646

47+
load("@contrib_rules_bazel_integration_test//bazel_integration_test:deps.bzl", "bazel_integration_test_rules_dependencies")
48+
49+
bazel_integration_test_rules_dependencies()
50+
51+
load("@cgrindel_bazel_starlib//:deps.bzl", "bazel_starlib_dependencies")
52+
53+
bazel_starlib_dependencies()
54+
55+
load("//:bazel_versions.bzl", "SUPPORTED_BAZEL_VERSIONS")
56+
load("@contrib_rules_bazel_integration_test//bazel_integration_test:defs.bzl", "bazel_binaries")
57+
58+
bazel_binaries(versions = SUPPORTED_BAZEL_VERSIONS)
59+
4760
# --- end stardoc
4861

4962
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

bazel_versions.bzl

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
CURRENT_BAZEL_VERSION = "6.0.0"
2+
SUPPORTED_BAZEL_VERSIONS = [CURRENT_BAZEL_VERSION]

rust/BUILD.bazel

+6
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,9 @@ bzl_library(
2929
"//rust/settings:bzl_lib",
3030
],
3131
)
32+
33+
filegroup(
34+
name = "all_files",
35+
srcs = glob(["*"]),
36+
visibility = ["//:__subpackages__"],
37+
)

rust/platform/BUILD.bazel

+6
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,9 @@ bzl_library(
1717
srcs = glob(["**/*.bzl"]),
1818
visibility = ["//rust:__subpackages__"],
1919
)
20+
21+
filegroup(
22+
name = "all_files",
23+
srcs = glob(["*"]),
24+
visibility = ["//:__subpackages__"],
25+
)

rust/platform/channel/BUILD.bazel

+6
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,9 @@ constraint_value(
2020
name = "stable",
2121
constraint_setting = ":channel",
2222
)
23+
24+
filegroup(
25+
name = "all_files",
26+
srcs = glob(["*"]),
27+
visibility = ["//:__subpackages__"],
28+
)

rust/platform/cpu/BUILD.bazel

+6
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,9 @@ alias(
44
deprecation = "Use @platforms//cpu:wasm32 directly instead.",
55
visibility = ["//visibility:public"],
66
)
7+
8+
filegroup(
9+
name = "all_files",
10+
srcs = glob(["*"]),
11+
visibility = ["//:__subpackages__"],
12+
)

rust/platform/os/BUILD.bazel

+6
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,9 @@ alias(
33
actual = "@platforms//os:none",
44
visibility = ["//visibility:public"],
55
)
6+
7+
filegroup(
8+
name = "all_files",
9+
srcs = glob(["*"]),
10+
visibility = ["//:__subpackages__"],
11+
)

rust/private/BUILD.bazel

+6
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,9 @@ rust_analyzer_detect_sysroot(
1515
name = "rust_analyzer_detect_sysroot",
1616
visibility = ["//visibility:public"],
1717
)
18+
19+
filegroup(
20+
name = "all_files",
21+
srcs = glob(["*"]),
22+
visibility = ["//:__subpackages__"],
23+
)

rust/private/dummy_cc_toolchain/BUILD.bazel

+6
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,9 @@ filegroup(
3535
srcs = [],
3636
visibility = ["//:__subpackages__"],
3737
)
38+
39+
filegroup(
40+
name = "all_files",
41+
srcs = glob(["*"]),
42+
visibility = ["//:__subpackages__"],
43+
)

rust/rust_analyzer/BUILD.bazel

+6
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,9 @@ package(default_visibility = ["//visibility:public"])
33
toolchain_type(
44
name = "toolchain_type",
55
)
6+
7+
filegroup(
8+
name = "all_files",
9+
srcs = glob(["*"]),
10+
visibility = ["//:__subpackages__"],
11+
)

rust/settings/BUILD.bazel

+6
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,9 @@ bzl_library(
4848
name = "bzl_lib",
4949
srcs = glob(["**/*.bzl"]),
5050
)
51+
52+
filegroup(
53+
name = "all_files",
54+
srcs = glob(["*"]),
55+
visibility = ["//:__subpackages__"],
56+
)

rust/toolchain/BUILD.bazel

+6
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,9 @@ toolchain_files(
4040
current_rust_toolchain(
4141
name = "current_rust_toolchain",
4242
)
43+
44+
filegroup(
45+
name = "all_files",
46+
srcs = glob(["*"]),
47+
visibility = ["//:__subpackages__"],
48+
)

rust/toolchain/channel/BUILD.bazel

+6
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,9 @@ config_setting(
2929
},
3030
visibility = ["//visibility:public"],
3131
)
32+
33+
filegroup(
34+
name = "all_files",
35+
srcs = glob(["*"]),
36+
visibility = ["//:__subpackages__"],
37+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
From ef519afd270781a41a54b485e5b54462790e2eb5 Mon Sep 17 00:00:00 2001
2+
From: John Firebaugh <john.firebaugh@gmail.com>
3+
Date: Fri, 23 Dec 2022 20:06:00 -0800
4+
Subject: [PATCH] Add support for WORKSPACE.bazel Fixes #97
5+
6+
---
7+
.../private/bazel_integration_test.bzl | 25 +++++++++++++++++--
8+
tools/find_child_workspace_packages.sh | 5 +---
9+
tools/shared_fns.sh | 2 +-
10+
tools/update_deleted_packages.sh | 9 +------
11+
4 files changed, 26 insertions(+), 15 deletions(-)
12+
13+
diff --git a/bazel_integration_test/private/bazel_integration_test.bzl b/bazel_integration_test/private/bazel_integration_test.bzl
14+
index fa1ceb3..5207bd7 100644
15+
--- a/bazel_integration_test/private/bazel_integration_test.bzl
16+
+++ b/bazel_integration_test/private/bazel_integration_test.bzl
17+
@@ -15,6 +15,27 @@ load(":integration_test_utils.bzl", "integration_test_utils")
18+
# CC: if Bazel use specific C-compiler it should be inherited by default
19+
_DEFAULT_ENV_INHERIT = ["SUDO_ASKPASS", "HOME", "CC"]
20+
21+
+def _select_workspace_file_impl(ctx):
22+
+ workspace_file = paths.join(ctx.attr.workspace_path, "WORKSPACE")
23+
+ workspace_bazel = paths.join(ctx.attr.workspace_path, "WORKSPACE.bazel")
24+
+ for file in ctx.attr.srcs.files.to_list():
25+
+ if file.path.endswith(workspace_file) or file.path.endswith(workspace_bazel):
26+
+ return [DefaultInfo(files = depset([file]))]
27+
+ fail("Can't find WORKSPACE or WORKSPACE.bazel in %s" % ctx.attr.workspace_path)
28+
+
29+
+select_workspace_file = rule(
30+
+ implementation = _select_workspace_file_impl,
31+
+ attrs = {
32+
+ "srcs": attr.label(
33+
+ allow_files = True,
34+
+ mandatory = True,
35+
+ ),
36+
+ "workspace_path": attr.string(
37+
+ mandatory = True,
38+
+ ),
39+
+ },
40+
+)
41+
+
42+
def bazel_integration_test(
43+
name,
44+
test_runner,
45+
@@ -115,10 +136,10 @@ def bazel_integration_test(
46+
# convey the actual workspace directory to the rule. The location of
47+
# the WORKSPACE file seems to be the best way to do this.
48+
bazel_wksp_file_name = name + "_bazel_workspace_file"
49+
- select_file(
50+
+ select_workspace_file(
51+
name = bazel_wksp_file_name,
52+
srcs = workspace_files_name,
53+
- subpath = paths.join(workspace_path, "WORKSPACE"),
54+
+ workspace_path = workspace_path,
55+
)
56+
57+
args.extend(["--workspace", "$(location :%s)" % (bazel_wksp_file_name)])
58+
diff --git a/tools/find_child_workspace_packages.sh b/tools/find_child_workspace_packages.sh
59+
index 46a0325..13c6478 100755
60+
--- a/tools/find_child_workspace_packages.sh
61+
+++ b/tools/find_child_workspace_packages.sh
62+
@@ -66,11 +66,8 @@ while (("$#")); do
63+
esac
64+
done
65+
66+
-if [[ -z "${workspace_root:-}" ]] && [[ -n "${BUILD_WORKING_DIRECTORY:-}" ]]; then
67+
- workspace_root="${BUILD_WORKING_DIRECTORY:-}"
68+
-fi
69+
if [[ -z "${workspace_root:-}" ]]; then
70+
- workspace_root="$(dirname "$(upsearch WORKSPACE)")"
71+
+ workspace_root="${BUILD_WORKSPACE_DIRECTORY}"
72+
fi
73+
if [[ ! -d "${workspace_root:-}" ]]; then
74+
fail "The workspace root was not found. ${workspace_root:-}"
75+
diff --git a/tools/shared_fns.sh b/tools/shared_fns.sh
76+
index 7c92bdf..d831f04 100644
77+
--- a/tools/shared_fns.sh
78+
+++ b/tools/shared_fns.sh
79+
@@ -4,5 +4,5 @@ find_workspace_dirs() {
80+
local path="${1}"
81+
# Make sure that the -print0 is the last primary for find. Otherwise, you
82+
# will get undesirable results.
83+
- find "${path}" -name "WORKSPACE" -print0 | xargs -0 -n 1 dirname
84+
+ find "${path}" -name "WORKSPACE" -o -name "WORKSPACE.bazel" -print0 | xargs -0 -n 1 dirname
85+
}
86+
diff --git a/tools/update_deleted_packages.sh b/tools/update_deleted_packages.sh
87+
index db73b1c..ec435c8 100755
88+
--- a/tools/update_deleted_packages.sh
89+
+++ b/tools/update_deleted_packages.sh
90+
@@ -71,15 +71,8 @@ while (("$#")); do
91+
done
92+
93+
94+
-# Try to search for the workspace root
95+
if [[ -z "${workspace_root:-}" ]]; then
96+
- # If the BUILD_WORKING_DIRECTORY exists, it will be the directory from which the command was run
97+
- if [[ -n "${BUILD_WORKING_DIRECTORY:-}" ]]; then
98+
- search_start_dir="${BUILD_WORKING_DIRECTORY}"
99+
- else
100+
- search_start_dir="${PWD}"
101+
- fi
102+
- workspace_root="$(dirname "$(upsearch --start_dir "${search_start_dir}" WORKSPACE)")"
103+
+ workspace_root="${BUILD_WORKSPACE_DIRECTORY}"
104+
fi
105+
if [[ ! -d "${workspace_root:-}" ]]; then
106+
exit_with_msg "The workspace root was not found. ${workspace_root:-}"
107+
--
108+
2.39.0
109+

test/deps.bzl

+11
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,14 @@ def rules_rust_test_deps():
3838
"https://github.com/rust-lang/libc/archive/0.2.20.zip",
3939
],
4040
)
41+
42+
http_archive(
43+
name = "contrib_rules_bazel_integration_test",
44+
patch_args = ["-p1"],
45+
patches = ["@//test:0001-Add-support-for-WORKSPACE.bazel.patch"],
46+
sha256 = "20d670bb614d311a2a0fc8af53760439214731c3d5be2d9b0a197dccc19583f5",
47+
strip_prefix = "rules_bazel_integration_test-0.9.0",
48+
urls = [
49+
"http://github.com/bazel-contrib/rules_bazel_integration_test/archive/v0.9.0.tar.gz",
50+
],
51+
)

test/integration/BUILD.bazel

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
load("//:bazel_versions.bzl", "CURRENT_BAZEL_VERSION")
2+
load(
3+
"@contrib_rules_bazel_integration_test//bazel_integration_test:defs.bzl",
4+
"bazel_integration_test",
5+
"bazel_integration_tests",
6+
"default_test_runner",
7+
"integration_test_utils",
8+
)
9+
10+
sh_binary(
11+
name = "issue1530_runner",
12+
srcs = ["issue1530.sh"],
13+
)
14+
15+
bazel_integration_test(
16+
name = "issue1530_test",
17+
bazel_version = CURRENT_BAZEL_VERSION,
18+
test_runner = ":issue1530_runner",
19+
workspace_files = integration_test_utils.glob_workspace_files("issue1530") + [
20+
"//:all_files",
21+
],
22+
workspace_path = "issue1530",
23+
)

test/integration/issue1530.sh

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
set -euo pipefail
2+
cd "$BIT_WORKSPACE_DIR"
3+
"$BIT_BAZEL_BINARY" build --execution_log_json_file=build-1.json //:panic
4+
"$BIT_BAZEL_BINARY" clean
5+
"$BIT_BAZEL_BINARY" build --execution_log_json_file=build-2.json //:panic
6+
diff -u -I walltime build-1.json build-2.json
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
load("@rules_rust//rust:defs.bzl", "rust_binary")
2+
3+
rust_binary(
4+
name = "panic",
5+
srcs = ["panic.rs"],
6+
edition = "2018",
7+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
local_repository(
2+
name = "rules_rust",
3+
path = "../../..",
4+
)
5+
6+
load("@rules_rust//rust:repositories.bzl", "rules_rust_dependencies", "rust_register_toolchains")
7+
8+
rules_rust_dependencies()
9+
rust_register_toolchains()

test/integration/issue1530/panic.rs

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fn main() {
2+
panic!("boom!")
3+
}

util/BUILD.bazel

+6
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,9 @@ filegroup(
99
srcs = ["collect_coverage.sh"],
1010
visibility = ["//visibility:public"],
1111
)
12+
13+
filegroup(
14+
name = "all_files",
15+
srcs = glob(["*"]),
16+
visibility = ["//:__subpackages__"],
17+
)

util/dir_zipper/BUILD.bazel

+6
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,9 @@ rust_binary(
66
edition = "2018",
77
visibility = ["//visibility:public"],
88
)
9+
10+
filegroup(
11+
name = "all_files",
12+
srcs = glob(["*"]),
13+
visibility = ["//:__subpackages__"],
14+
)

util/import/3rdparty/BUILD.bazel

+6
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,9 @@ bzl_library(
3838
],
3939
visibility = ["//util/import:__pkg__"],
4040
)
41+
42+
filegroup(
43+
name = "all_files",
44+
srcs = glob(["*"]),
45+
visibility = ["//:__subpackages__"],
46+
)

util/import/BUILD.bazel

+6
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,9 @@ cc_binary(
7777
name = "fake_import_macro_impl",
7878
srcs = ["fake_import_macro_impl.cc"],
7979
)
80+
81+
filegroup(
82+
name = "all_files",
83+
srcs = glob(["*"]),
84+
visibility = ["//:__subpackages__"],
85+
)

0 commit comments

Comments
 (0)