|
| 1 | +load("@bazel_binaries//:defs.bzl", "bazel_binaries") |
| 2 | +load("@rules_bazel_integration_test//bazel_integration_test:defs.bzl", "bazel_integration_test", "bazel_integration_tests") |
| 3 | +load("@rules_shell//shell:sh_binary.bzl", "sh_binary") |
| 4 | + |
| 5 | +def gen_workspace( |
| 6 | + name, |
| 7 | + workspace_files = []): |
| 8 | + build_file_standins = [f for f in workspace_files if f.endswith("BUILD.test")] |
| 9 | + if len(build_file_standins) == 0: |
| 10 | + fail("Could not find any BUILD.test files") |
| 11 | + build_files = [] |
| 12 | + for build_file_standin in build_file_standins: |
| 13 | + build_file = build_file_standin[:-len(".test")] |
| 14 | + native.genrule( |
| 15 | + name = build_file + "_gen", |
| 16 | + srcs = [build_file_standin], |
| 17 | + outs = [build_file], |
| 18 | + cmd = "cp $< $@", |
| 19 | + testonly = True, |
| 20 | + ) |
| 21 | + build_files.append(build_file) |
| 22 | + |
| 23 | + native.filegroup( |
| 24 | + name = name, |
| 25 | + srcs = workspace_files + build_files, |
| 26 | + testonly = True, |
| 27 | + ) |
| 28 | + |
| 29 | +def rules_cc_integration_test( |
| 30 | + name, |
| 31 | + test_script, |
| 32 | + workspace, |
| 33 | + deps = [], |
| 34 | + tags = []): |
| 35 | + test_binary = name + "_test_runner" |
| 36 | + sh_binary( |
| 37 | + name = test_binary, |
| 38 | + srcs = ["//tests/integration:test_launcher.sh"], |
| 39 | + data = deps + [ |
| 40 | + test_script, |
| 41 | + "//cc:all_files_for_testing", |
| 42 | + "//tests/integration:test_utils", |
| 43 | + "@rules_shell//shell/runfiles", |
| 44 | + "@rules_bazel_integration_test//tools:create_scratch_dir", |
| 45 | + ], |
| 46 | + deps = [ |
| 47 | + "//tests/integration:test_utils", |
| 48 | + "@rules_shell//shell/runfiles", |
| 49 | + ], |
| 50 | + testonly = True, |
| 51 | + ) |
| 52 | + |
| 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 | + ) |
| 66 | + |
| 67 | + selected_bazel = name + "_bazel_selected" |
| 68 | + native.alias( |
| 69 | + name = selected_bazel, |
| 70 | + 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 | + }), |
| 77 | + ) |
| 78 | + |
| 79 | + bazel_integration_test( |
| 80 | + 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, |
| 88 | + ) |
0 commit comments