This directory contains tests meant to test the Fuchsia Bazel SDK. These currently require to be in a Fuchsia checkout.
The test suite can be run against three types of inputs:
A local IDK export directory.
This is currently how the Fuchsia IDK, generated by the Fuchsia build, are validated before uploading them to cloud storage.
A local Bazel SDK directory.
This is currently how the Fuchsia Bazel SDK, generated by the Fuchsia build, are validated before uploading them to cloud storage.
The content of the @fuchsia_sdk
repository in the Fuchsia in-tree platform build, which itself depends on the content of the @fuchsia_in_tree_idk
repository.
fx build
The simplest way to run the test suite is to use the following fx build
command from a Fuchsia checkout:
fx build bazel_sdk_tests
:
Setup the Fuchsia in-tree @fuchsia_sdk
repository and its dependencies, then run the test suite against it. This is useful during development of the Bazel rules themselves, or when modifying the content of the IDK/SDK.
Note that no tests are ever run against the @sdk_internal
repository of the in-tree Bazel workspace.
fx build //sdk:final_fuchsia_idk.validation
:
Build the Fuchsia IDK, then run the test suite against it.
NOTE: Building the Fuchsia IDK takes a long time, so this is usually only performed on dedicated CI builders (e.g. sdk-core-linux
).
NOTE: This target is called implicitly when building //sdk:final_fuchsia_idk
.
fx build //sdk:final_fuchsia_sdk_tests
:
Build the Fuchsia Bazel SDK, then run the test suite against it.
NOTE: Building the Fuchsia Bazel SDK takes a long time, so this is usually only performed on dedicated CI builders (e.g. sdk-bazel-linux
).
All these targets ensure that their pre-requisites are available, that builds are properly hermetic and also incrementally correct. However, they will run the full test suite every time (i.e. will not allow you to run an individual test).
Because Bazel caches test results, this can still be moderately fast during development.
scripts/bazel_test.py
Another way is to prepare your Fuchsia build, then invoking scripts/bazel_test.py
manually. You can use --test_target=<label>
to select an individual test target (instead of all of them), or even pass extra arguments using -- <extra_args>
.
The script ensures that the test workspace uses all vendored prebuilts and Bazel rules from the Fuchsia checkout, and never download anything from the network.
# Prepare the Fuchsia IDK (beware: this takes > 20minutes). fx build //sdk:final_fuchsia_idk.exported LOCAL_IDK="$(fx get-build-dir)/sdk/exported/fuchsia_idk" # Run the full test suite scripts/bazel_test.py \ --fuchsia_idk_directory="${LOCAL_IDK}" \ --target_cpu=x64 # Run a subset of test targets, and change test output. scripts/bazel_test.py \ --fuchsia_idk_directory="${LOCAL_IDK}" \ --target_cpu=x64 \ --test_target=:build_only_tests -- --test_output=streamed
@fuchsia_sdk
):Run against a minimal Fuchsia Bazel SDK:
# Generate the final Fuchsia in-tree SDK fx build //sdk:final_fuchsia_sdk_head_only LOCAL_SDK="$(fx get-build-dir)/obj/sdk/final_fuchsia_sdk_head_only" # Run the full test suite scripts/bazel_test.py --fuchsia_sdk_directory="${LOCAL_SDK}"
Alternatively, run against the full Fuchsia Bazel SDK:
# Generate the Fuchsia Bazel SDK (beware: this takes > 20minutes) fx build //sdk:final_fuchsia_sdk LOCAL_SDK="$(fx get-build-dir)/obj/sdk/final_fuchsia_sdk" # Run the full test suite scripts/bazel_test.py --fuchsia_sdk_directory="${LOCAL_SDK}"
@fuchsia_sdk
repository:Note that this is only needed by Fuchsia developers modifying the Bazel rules or the content of the in-tree IDK/SDK.
# Prepare the @fuchsia_sdk repository. Only needed once per `jiri update` fx build bazel_workspace fx bazel --query --config=quiet @fuchsia_sdk//:BUILD.bazel # Run the full test suite scripts/bazel_test.py --fuchsia-in-tree-sdk # Run a subset of test targets, and change test output. scripts/bazel_test.py \ --fuchsia-in-tree-sdk \ --test_target=:build_only_tests -- --test_output=streamed
Finally, it is possible to directly invoke bazel test
in this directory after some necessary preparation.
TODO: Fix Bazel 8.0 invocation.
This requires setting the LOCAL_FUCHSIA_IDK_DIRECTORY
environment variable when calling Bazel. For example, when using the Fuchsia IDK:
fx build //sdk:final_fuchsia_idk.exported IDK="$(fx get-build-dir)/sdk/exported/final_fuchsia_idk LOCAL_FUCHSIA_IDK_DIRECTORY="${IDK}" bazel test --config=fuchsia_x64 :tests
@fuchsia_sdk
repository:This is only mentioned here for completeness, as this is only useful for Fuchsia build developers when debugging changes to the in-tree Bazel workspace itself, even though using scripts/bazel_test.py
would be simpler to do the same.
This requires overriding two repositories, for reasons explained in //build/bazel/bazel_sdk/README.md
:
# Preparation steps is slightly different cd /work/fuchsia fx set minimal.x64 fx build bazel_workspace fx bazel --query --config=quiet @fuchsia_sdk//:BUILD.bazel OUTPUT_BASE="$(fx get-build-dir)/gen/build/bazel/output_base" FUCHSIA_SDK_REPO="${OUTPUT_BASE}/external/fuchsia_sdk" FUCHSIA_IN_TREE_IDK_REPO="${OUTPUT_BASE}/external/fuchsia_in_tree_idk" # Run the test suite bazel test \ --config=fuchsia_x64 \ --override_repository=fuchsia_sdk="${FUCHSIA_SDK_REPO}" \ --override_repository=fuchsia_in_tree_idk="${FUCHSIA_IN_TREE_IDK_REPO}" \ :tests