mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-01 19:58:15 +00:00
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:
@@ -38,6 +38,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 }}
|
||||
|
||||
@@ -1 +1,5 @@
|
||||
ts/node_modules
|
||||
|
||||
# Test workspaces
|
||||
tests/bazel_repository_test_dir
|
||||
tests/ts/bazel_repository_test_dir
|
||||
|
||||
14
MODULE.bazel
14
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")
|
||||
|
||||
20
WORKSPACE
20
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"])
|
||||
|
||||
@@ -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",
|
||||
)
|
||||
|
||||
@@ -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 //...
|
||||
@@ -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"],
|
||||
)
|
||||
@@ -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",
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user