11load ("@bazel_binaries//:defs.bzl" , "bazel_binaries" )
22load ("@rules_bazel_integration_test//bazel_integration_test:defs.bzl" , "bazel_integration_test" , "bazel_integration_tests" )
33load ("@rules_shell//shell:sh_binary.bzl" , "sh_binary" )
4+ load ("@rules_shell//shell:sh_test.bzl" , "sh_test" )
5+
6+ def package_workspace_impl (ctx ):
7+ out_dir = ctx .actions .declare_directory (ctx .label .name )
8+
9+ commands = []
10+ pkg_root = ctx .label .package
11+ print (pkg_root )
12+ for f in ctx .files .srcs :
13+ f_path = f .short_path
14+ #if f.short_path.startswith(pkg_root + "/"):
15+ # f_path = f_path[len(pkg_root) + 1:]
16+ dest_path = out_dir .path + "/" + f_path
17+ dest_parent = dest_path .rsplit ("/" , 1 )[0 ]
18+
19+ commands .append (
20+ "mkdir -p \" {dest_parent}\" && cp \" {src}\" \" {dest}\" " .format (
21+ dest_parent = dest_parent ,
22+ src = f .path ,
23+ dest = dest_path ,
24+ )
25+ )
26+
27+ ctx .actions .run_shell (
28+ inputs = ctx .files .srcs ,
29+ outputs = [out_dir ],
30+ command = " && " .join (commands ),
31+ progress_message = "Creating workspace '{}'" .format (ctx .label .name )
32+ )
33+ return DefaultInfo (files = depset ([out_dir ]))
34+
35+ package_workspace = rule (
36+ implementation = package_workspace_impl ,
37+ attrs = {
38+ "srcs" : attr .label_list (allow_files = True ),
39+ }
40+ )
441
542def gen_workspace (
643 name ,
@@ -20,16 +57,35 @@ def gen_workspace(
2057 )
2158 build_files .append (build_file )
2259
23- native .filegroup (
60+ #native.filegroup(
61+ # name = name,
62+ # srcs = workspace_files + build_files + ["//:all_files_for_testing"],
63+ # testonly = True,
64+ #)
65+ package_workspace (
2466 name = name ,
25- srcs = workspace_files + build_files ,
67+ srcs = workspace_files + build_files + [ "//:all_files_for_testing" ] ,
2668 testonly = True ,
2769 )
2870
71+ def common_prefix (files ):
72+ if not files :
73+ return ""
74+ walking = files [0 ]
75+ others = files [1 :]
76+
77+ for idx , c in enumerate (walking .elems ()):
78+ for other in others :
79+ if other [idx ] != c :
80+ return walking [:idx ]
81+ return walking
82+
83+
2984def rules_cc_integration_test (
3085 name ,
3186 test_script ,
3287 workspace ,
88+ workspace_name ,
3389 deps = [],
3490 tags = []):
3591 test_binary = name + "_test_runner"
@@ -50,39 +106,82 @@ def rules_cc_integration_test(
50106 testonly = True ,
51107 )
52108
53- bazel_integration_tests (
54- name = name ,
55- test_runner = test_binary ,
56- bazel_binaries = bazel_binaries ,
57- bazel_versions = bazel_binaries .versions .all ,
58- env = {"TEST_RUNNER" : "$(location %s)" % test_script },
59- data = [
60- test_script ,
61- ],
62- workspace_path = Label (workspace ).name ,
63- workspace_files = [workspace , "//:all_files_for_testing" ],
64- tags = tags + ["manual" ],
65- )
109+ # bazel_integration_tests(
110+ # name = name,
111+ # test_runner = test_binary,
112+ # bazel_binaries = bazel_binaries,
113+ # bazel_versions = bazel_binaries.versions.all,
114+ # env = {"TEST_RUNNER": "$(location %s)" % test_script},
115+ # data = [
116+ # test_script,
117+ # ],
118+ # workspace_path = Label(workspace).name,
119+ # workspace_files = [workspace, "//:all_files_for_testing"],
120+ # tags = tags + ["manual"],
121+ # )
122+
123+ # selected_bazel = name + "_bazel_selected"
124+ # native.alias(
125+ # name = selected_bazel,
126+ # actual = select({
127+ # "//tests/integration:bazel_7": "@build_bazel_bazel_7_x//:bazel_binary",
128+ # "//tests/integration:bazel_8": "@build_bazel_bazel_8_x//:bazel_binary",
129+ # "//tests/integration:bazel_9": "@build_bazel_bazel_9_x//:bazel_binary",
130+ # "//tests/integration:bazel_latest": "@build_bazel_bazel_last_green//:bazel_binary",
131+ # "//conditions:default": "@build_bazel_bazel_last_green//:bazel_binary",
132+ # }),
133+ # )
134+
135+ # bazel_integration_test(
136+ # name = name,
137+ # test_runner = test_binary,
138+ # bazel_binary = selected_bazel,
139+ # env = {"TEST_RUNNER": "$(location %s)" % test_script},
140+ # data = [test_script],
141+ # workspace_path = Label(workspace).name,
142+ # workspace_files = [workspace, "//:all_files_for_testing"],
143+ # tags = tags,
144+ # )
66145
67146 selected_bazel = name + "_bazel_selected"
68147 native .alias (
69148 name = selected_bazel ,
70149 actual = select ({
71- "//tests/integration:bazel_7" : "@build_bazel_bazel_7_x//:bazel_binary" ,
72- "//tests/integration:bazel_8" : "@build_bazel_bazel_8_x//:bazel_binary" ,
73- "//tests/integration:bazel_9" : "@build_bazel_bazel_9_x//:bazel_binary" ,
74- "//tests/integration:bazel_latest" : "@build_bazel_bazel_last_green//:bazel_binary" ,
75- "//conditions:default" : "@build_bazel_bazel_last_green//:bazel_binary" ,
76- }),
150+ "//tests/integration:bazel_7" : "@bazel_7//file" ,
151+ "//tests/integration:bazel_8" : "@bazel_8//file" ,
152+ "//tests/integration:bazel_9" : "@bazel_9//file" ,
153+ "//conditions:default" : "@local_bazel//:bazel_bin" ,
154+ })
77155 )
78156
79- bazel_integration_test (
157+ #workspace_dir = name + "_workspace"
158+ #package_workspace(
159+ # name = workspace_dir,
160+ # srcs = [workspace],
161+ # testonly = True,
162+ #)
163+
164+ sh_test (
80165 name = name ,
81- test_runner = test_binary ,
82- bazel_binary = selected_bazel ,
83- env = {"TEST_RUNNER" : "$(location %s)" % test_script },
84- data = [test_script ],
85- workspace_path = Label (workspace ).name ,
86- workspace_files = [workspace , "//:all_files_for_testing" ],
87- tags = tags ,
166+ srcs = [
167+ "//tests/integration:test_launcher.sh" ,
168+ ],
169+ data = [
170+ selected_bazel ,
171+ test_script ,
172+ "//tests/integration:test_utils" ,
173+ "@rules_shell//shell/runfiles" ,
174+ Label (workspace ),
175+ Label (workspace_name ),
176+ ],
177+ env = {
178+ "TEST_RUNNER" : "$(location %s)" % test_script ,
179+ "BAZEL_BINARY" : "$(location %s)" % selected_bazel ,
180+ "WORKSPACE_DIR" : "$(location %s)" % Label (workspace ),
181+ "WORKSPACE_PATH" : "$(location %s)" % Label (workspace_name ),
182+ },
183+ deps = [
184+ "//tests/integration:test_utils" ,
185+ "@rules_shell//shell/runfiles" ,
186+ ],
88187 )
0 commit comments