From 7b5a9e26a42c0977f24ad68137e3ada13a066da7 Mon Sep 17 00:00:00 2001 From: Fabian Meumertzheim Date: Thu, 16 Jan 2025 08:48:02 +0100 Subject: [PATCH] Allow `buildozer` target to be aliased Co-authored-by: Spencer Putt --- .bcr/presubmit.yml | 3 ++- .github/workflows/test.yml | 1 + BUILD.bazel | 8 +++++--- buildozer.sh | 5 +++-- tests/bcr/BUILD.bazel | 5 +++++ 5 files changed, 16 insertions(+), 6 deletions(-) diff --git a/.bcr/presubmit.yml b/.bcr/presubmit.yml index 46c3929..defde52 100644 --- a/.bcr/presubmit.yml +++ b/.bcr/presubmit.yml @@ -17,7 +17,8 @@ bcr_test_module: # Workaround for https://github.com/bazelbuild/bazel/issues/3268 - echo bazel-bcr/>> .bazelignore run_targets: - - //:run_buildozer + - //:buildozer_alias # Run the alias with no args. + - //:run_buildozer # Will modify a test target. build_targets: - //... test_targets: diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 17eb3d3..b3e24d0 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -34,5 +34,6 @@ jobs: USE_BAZEL_VERSION: ${{ matrix.bazel }} working-directory: tests/bcr run: | + bazel run //:buildozer_alias bazel run //:run_buildozer bazel test //... diff --git a/BUILD.bazel b/BUILD.bazel index 0c25f2d..14b4674 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -1,15 +1,17 @@ +# A buildozer binary that will run in the root repository's workspace directory +# when executed with `bazel run`. +# Can be aliased or used as a data dependency of other targets executed via +# `bazel run`. sh_binary( name = "buildozer", srcs = ["buildozer.sh"], data = [ "@buildozer_binary//:buildozer.exe", ], - env = { - "BUILDOZER_RLOCATIONPATH": "$(rlocationpath @buildozer_binary//:buildozer.exe)", - }, deps = [ "@bazel_tools//tools/bash/runfiles", ], + visibility = ["//visibility:public"], ) exports_files(["buildozer.bzl"]) diff --git a/buildozer.sh b/buildozer.sh index 5070e3c..6b8bd5d 100755 --- a/buildozer.sh +++ b/buildozer.sh @@ -20,9 +20,10 @@ source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \ { echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -e # --- end runfiles.bash initialization v3 --- -buildozer_path=$(rlocation $BUILDOZER_RLOCATIONPATH) +buildozer_rlocationpath=buildozer_binary/buildozer.exe +buildozer_path=$(rlocation $buildozer_rlocationpath) if [[ ! -f "$buildozer_path" ]]; then - echo "buildozer.exe not found at runfiles path $BUILDOZER_RLOCATIONPATH and resolved path $buildozer_path." + echo "buildozer.exe not found at runfiles path $buildozer_rlocationpath and resolved path $buildozer_path." exit 1 fi diff --git a/tests/bcr/BUILD.bazel b/tests/bcr/BUILD.bazel index cd46c4f..a64368b 100644 --- a/tests/bcr/BUILD.bazel +++ b/tests/bcr/BUILD.bazel @@ -5,3 +5,8 @@ sh_binary( }, srcs = ["run_buildozer.sh"], ) + +alias( + name = "buildozer_alias", + actual = "@buildozer", +)