Skip to content

Commit

Permalink
fix: add Bazel option to force creating bazel-bin symlink (googleapis…
Browse files Browse the repository at this point in the history
…#5183)

Fixes googleapis#5185.

These `bazel-*` symlinks add a lot of toil for human users, and we are
thinking of disabling them in .bazelrc. Since this code depends on them
being created, let's have them enabled explicitly in the script.

`BAZEL_FLAGS` is not the right place for it, because this is not
something that is supposed to be configured, but rather something that
is supposed to be hardcoded.

---------

Co-authored-by: Jeff Ching <chingor@google.com>
Co-authored-by: Jeffrey Rennie <rennie@google.com>
Co-authored-by: Benjamin E. Coe <bencoe@google.com>
  • Loading branch information
4 people committed Nov 16, 2023
1 parent 7929595 commit d318c47
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions packages/bazel-bot/docker-image/generate-googleapis-gen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,12 @@ for (( idx=${#ungenerated_shas[@]}-1 ; idx>=0 ; idx-- )) ; do
targets="$BUILD_TARGETS"
fi
# Clean out all the source packages from the previous build.
rm -f $(find -L "$GOOGLEAPIS/bazel-bin" -name "*.tar.gz")

BAZEL_BIN=$(cd "$GOOGLEAPIS" && bazel info bazel-bin)
# The directory might not exist before the build, but its path is known
if test -d "$BAZEL_BIN"; then
rm -f $(find "$BAZEL_BIN" -name "*.tar.gz")
fi
# Confirm that bazel can fetch remote build dependencies before building
# with -k. Otherwise, we can't distinguish a build failure due to a bad proto
# vs. a build failure due to transient network issue.
Expand All @@ -108,7 +113,7 @@ for (( idx=${#ungenerated_shas[@]}-1 ; idx>=0 ; idx-- )) ; do
# Clear out the existing contents of googleapis-gen before we copy back into it,
# so that deleted APIs will be be removed.
rm -rf "$GOOGLEAPIS_GEN/external" "$GOOGLEAPIS_GEN/google" "$GOOGLEAPIS_GEN/grafeas"

# Untar the generated source files into googleapis-gen.
let target_count=0
failed_targets=()
Expand All @@ -119,7 +124,7 @@ for (( idx=${#ungenerated_shas[@]}-1 ; idx>=0 ; idx-- )) ; do
parent_dir=$(dirname $tar_gz)
target_dir="$GOOGLEAPIS_GEN/$parent_dir"
mkdir -p "$target_dir"
tar -xf "$GOOGLEAPIS/bazel-bin/$tar_gz" -C "$target_dir" || {
tar -xf "$BAZEL_BIN/$tar_gz" -C "$target_dir" || {
failed_targets+=($target)
# Restore the original source code because bazel failed to generate
# the new source code.
Expand Down

0 comments on commit d318c47

Please sign in to comment.