Skip to content

Commit

Permalink
Allow buildozer target to be aliased (#23)
Browse files Browse the repository at this point in the history
Closes #17

Co-authored-by: Spencer Putt <sputt@alumni.iu.edu>
fmeum and sputt authored Jan 25, 2025
1 parent a8e885a commit be01120
Showing 5 changed files with 16 additions and 6 deletions.
3 changes: 2 additions & 1 deletion .bcr/presubmit.yml
Original file line number Diff line number Diff line change
@@ -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:
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -35,5 +35,6 @@ jobs:
USE_BAZEL_VERSION: ${{ matrix.bazel }}
working-directory: tests/bcr
run: |
bazel run //:buildozer_alias
bazel run //:run_buildozer
bazel test //...
8 changes: 5 additions & 3 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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"])
5 changes: 3 additions & 2 deletions buildozer.sh
Original file line number Diff line number Diff line change
@@ -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

5 changes: 5 additions & 0 deletions tests/bcr/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -5,3 +5,8 @@ sh_binary(
},
srcs = ["run_buildozer.sh"],
)

alias(
name = "buildozer_alias",
actual = "@buildozer",
)

0 comments on commit be01120

Please sign in to comment.