Test external modules explicitly in CI (#8507)

This setup is much simpler than calling Bazel from within Bazel
and making sure files and flags are set up correctly.

Co-authored-by: Derek Bailey <derekbailey@google.com>
This commit is contained in:
Marcel
2025-01-24 00:04:06 +01:00
committed by GitHub
parent 026c243dc5
commit 50be3cfe8c
8 changed files with 16 additions and 149 deletions

View File

@@ -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",
)

View File

@@ -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 //...

View File

@@ -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"],
)

View File

@@ -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",
)