From 65ecb5c05ff3ec0a898bf6ec59b4268fff04311f Mon Sep 17 00:00:00 2001 From: maleo Date: Thu, 23 Jan 2025 21:54:17 +0000 Subject: [PATCH] Test external modules explicitly in CI This setup is much simpler than calling Bazel from within Bazel and making sure files and flags are set up correctly. --- .bazelci/presubmit.yml | 12 ++++ .bazelignore | 4 ++ MODULE.bazel | 14 ----- WORKSPACE | 20 ------- tests/BUILD.bazel | 6 -- tests/bazel_repository_test_template.sh | 29 ---------- tests/defs.bzl | 74 ------------------------- tests/ts/BUILD.bazel | 6 -- 8 files changed, 16 insertions(+), 149 deletions(-) delete mode 100755 tests/bazel_repository_test_template.sh delete mode 100644 tests/defs.bzl diff --git a/.bazelci/presubmit.yml b/.bazelci/presubmit.yml index 82332285085..ee3c38ee33f 100644 --- a/.bazelci/presubmit.yml +++ b/.bazelci/presubmit.yml @@ -36,6 +36,18 @@ tasks: - "//..." test_targets: - "//..." + test_module_cpp: + platform: ubuntu2204 + bazel: ${{ bazel }} + working_directory: tests/bazel_repository_test_dir + build_targets: + - "//..." + test_module_ts: + platform: ubuntu2204 + bazel: ${{ bazel }} + working_directory: tests/ts/bazel_repository_test_dir + test_targets: + - "//..." verify_macos: platform: macos bazel: ${{ bazel }} diff --git a/.bazelignore b/.bazelignore index accce227baa..874adf91565 100644 --- a/.bazelignore +++ b/.bazelignore @@ -1 +1,5 @@ ts/node_modules + +# Test workspaces +tests/bazel_repository_test_dir +tests/ts/bazel_repository_test_dir diff --git a/MODULE.bazel b/MODULE.bazel index 48931476567..caddfcb471c 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -71,17 +71,3 @@ use_repo(node, "nodejs_linux_amd64") rules_ts_ext = use_extension("@aspect_rules_ts//ts:extensions.bzl", "ext") rules_ts_ext.deps() use_repo(rules_ts_ext, "npm_typescript") - -bazel_dep( - name = "rules_bazel_integration_test", - version = "0.31.0", - dev_dependency = True, -) - -bazel_binaries = use_extension( - "@rules_bazel_integration_test//:extensions.bzl", - "bazel_binaries", - dev_dependency = True, -) -bazel_binaries.download(version = "6.5.0") -use_repo(bazel_binaries, "bazel_binaries", "bazel_binaries_bazelisk", "build_bazel_bazel_6_5_0") diff --git a/WORKSPACE b/WORKSPACE index 1cac3e97407..c483607cb0a 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -190,23 +190,3 @@ esbuild_register_toolchains( name = "esbuild", esbuild_version = LATEST_ESBUILD_VERSION, ) - -http_archive( - name = "rules_bazel_integration_test", - sha256 = "3e24bc0fba88177cd0ae87c1e37bf7de5d5af8e812f00817a58498b1a8368fca", - urls = [ - "https://github.com/bazel-contrib/rules_bazel_integration_test/releases/download/v0.31.0/rules_bazel_integration_test.v0.31.0.tar.gz", - ], -) - -load("@rules_bazel_integration_test//bazel_integration_test:deps.bzl", "bazel_integration_test_rules_dependencies") - -bazel_integration_test_rules_dependencies() - -load("@cgrindel_bazel_starlib//:deps.bzl", "bazel_starlib_dependencies") - -bazel_starlib_dependencies() - -load("@rules_bazel_integration_test//bazel_integration_test:defs.bzl", "bazel_binaries") - -bazel_binaries(versions = ["6.5.0"]) diff --git a/tests/BUILD.bazel b/tests/BUILD.bazel index 3717d43d283..ca673175802 100644 --- a/tests/BUILD.bazel +++ b/tests/BUILD.bazel @@ -1,7 +1,6 @@ load("@aspect_bazel_lib//lib:copy_to_bin.bzl", "copy_to_bin") load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test") load("//:build_defs.bzl", "DEFAULT_FLATC_ARGS", "flatbuffer_cc_library") -load(":defs.bzl", "flatbuffers_as_external_repo_test") package(default_visibility = ["//visibility:private"]) @@ -269,8 +268,3 @@ flatbuffer_cc_library( name = "alignment_test_cc_fbs", srcs = ["alignment_test.fbs"], ) - -flatbuffers_as_external_repo_test( - name = "bazel_repository_test", - directory = "bazel_repository_test_dir", -) diff --git a/tests/bazel_repository_test_template.sh b/tests/bazel_repository_test_template.sh deleted file mode 100755 index 43144e18674..00000000000 --- a/tests/bazel_repository_test_template.sh +++ /dev/null @@ -1,29 +0,0 @@ -#!/bin/bash - -# This test makes sure that a separate repository can import the flatbuffers -# repository and use it in their code. - -# --- begin runfiles.bash initialization v3 --- -# Copy-pasted from the Bazel Bash runfiles library v3. -set -uo pipefail; set +e; f=bazel_tools/tools/bash/runfiles/runfiles.bash -source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \ - source "$(grep -sm1 "^$f " "${RUNFILES_MANIFEST_FILE:-/dev/null}" | cut -f2- -d' ')" 2>/dev/null || \ - source "$0.runfiles/$f" 2>/dev/null || \ - source "$(grep -sm1 "^$f " "$0.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \ - source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \ - { echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -e -# --- end runfiles.bash initialization v3 --- - -BAZEL_BIN="$(rlocation {{BAZEL_PATH}})" -readonly BAZEL_BIN - -if [[ ! -x "${BAZEL_BIN}" ]]; then - echo "Failed to find the bazel binary." >&2 - exit 1 -fi - -export PATH="$(dirname "${BAZEL_BIN}"):${PATH}" - -cd {{REPOSITORY_DIR}} - -bazel test //... diff --git a/tests/defs.bzl b/tests/defs.bzl deleted file mode 100644 index 8ccbce26bc1..00000000000 --- a/tests/defs.bzl +++ /dev/null @@ -1,74 +0,0 @@ -"""Helper macros and rules for tests.""" - -load("@bazel_binaries//:defs.bzl", "bazel_binaries") -load("@bazel_skylib//lib:paths.bzl", "paths") -load("@bazel_skylib//rules:expand_template.bzl", "expand_template") - -def repo_name(label): - if hasattr(label, "repo_name"): # Added in Bazel 7.1 - return label.repo_name - else: - return "build_bazel_bazel_6_3_2" - -def rlocationpath(label): - """Returns the rlocationpath for a label - - Args: - label (Label): The label to determine the rlocationpath for - - Returns: - str: The rlocationpath for label - """ - path = "" - if repo_name(label): - path += repo_name(label) + "/" - if label.package: - path += label.package + "/" - path += label.name - return path - -def flatbuffers_as_external_repo_test(name, directory): - """Run all tests in a bazel workspace that imports flatbuffers as an external repository. - - Args: - name: The name of the test target. - directory: The directory in which the bazel workspace is located. This is the directory - that imports flatbuffers as an external repository. - """ - bazel_binary_label = Label(bazel_binaries.label(bazel_binaries.versions.current)) - expand_template( - name = name + "__template_expansion", - out = name + ".sh", - substitutions = { - "{{REPOSITORY_DIR}}": paths.join(native.package_name(), directory), - "{{BAZEL_PATH}}": rlocationpath(bazel_binary_label), - }, - template = "//tests:bazel_repository_test_template.sh", - ) - - native.sh_test( - name = name, - srcs = [":%s.sh" % name], - data = [ - "//:distribution", - bazel_binary_label, - ] + native.glob( - [ - directory + "/**/*", - ], - exclude = [ - directory + "/bazel-*/**", - ], - ), - tags = [ - # Since we have bazel downloading external repositories inside this - # test, we need to give it access to the internet. - "requires-network", - ], - # We only have x86_64 Linux bazel exposed so restrict the test to that. - target_compatible_with = [ - "@platforms//cpu:x86_64", - "@platforms//os:linux", - ], - deps = ["@bazel_tools//tools/bash/runfiles"], - ) diff --git a/tests/ts/BUILD.bazel b/tests/ts/BUILD.bazel index 4df03b4217a..cb5e6ad629b 100644 --- a/tests/ts/BUILD.bazel +++ b/tests/ts/BUILD.bazel @@ -1,7 +1,6 @@ load("@aspect_rules_js//js:defs.bzl", "js_test") load("@aspect_rules_js//npm:defs.bzl", "npm_link_package") load("//:typescript.bzl", "flatbuffer_ts_library") -load("//tests:defs.bzl", "flatbuffers_as_external_repo_test") package(default_visibility = ["//visibility:private"]) @@ -61,8 +60,3 @@ TEST_COMPLEX_ARRAYS_DATA = glob([ #("JavaScriptFlexBuffersTest", TBD_DATA) ("JavaScriptComplexArraysTest", TEST_COMPLEX_ARRAYS_DATA), )] - -flatbuffers_as_external_repo_test( - name = "bazel_repository_test", - directory = "bazel_repository_test_dir", -)