zip_manifest_creator: fix rlocation on Windows Apparently `rlocation` is not defined in the environment of regular sh_binary rules, only in tests. So this commit adds an implementation for it. See https://github.com/bazelbuild/bazel/issues/3264 Change-Id: I70ecb91cef5e1b66679e6ba04823831183da5cd9 PiperOrigin-RevId: 161775438
diff --git a/tools/android/zip_manifest_creator.sh b/tools/android/zip_manifest_creator.sh index d28b261..4507572 100755 --- a/tools/android/zip_manifest_creator.sh +++ b/tools/android/zip_manifest_creator.sh
@@ -36,6 +36,19 @@ IS_WINDOWS=true esac +if "$IS_WINDOWS" && ! type rlocation &> /dev/null; then + function rlocation() { + # Use 'sed' instead of 'awk', so if the absolute path ($2) has spaces, it + # will be printed completely. + local result="$(grep "$1" "${RUNFILES_MANIFEST_FILE}" | head -1)" + # If the entry has a space, it is a mapping from a runfiles-path to absolute + # path, otherwise it resolves to itself. + echo "$result" | grep -q " " \ + && echo "$result" | sed 's/^[^ ]* //' \ + || echo "$result" + } +fi + # For @bazel_tools//tools/android:zip_manifest_creator in BUILD.tools, zipper is here: # Windows (in MANIFEST): <repository_name>/tools/zip/zipper/zipper.exe # Linux/MacOS (symlink): ${RUNFILES}/<repository_name>/tools/zip/zipper/zipper @@ -57,9 +70,9 @@ if [ ! -x "$ZIPPER" ]; then echo >&2 "ERROR: $(basename $0): could not find zipper executable. Additional info:" echo >&2 " \$0=($0)" - echo >&2 " \$RUNFILES=($RUNFILES)" - echo >&2 " \$RUNFILES_MANIFEST_FILE=($RUNFILES_MANIFEST_FILE)" - echo >&2 " \$IS_WINDOWS=($IS_WINDOWS)" + echo >&2 " RUNFILES=($RUNFILES)" + echo >&2 " RUNFILES_MANIFEST_FILE=($RUNFILES_MANIFEST_FILE)" + echo >&2 " IS_WINDOWS=($IS_WINDOWS)" if "$IS_WINDOWS"; then echo >&2 " grep=($(grep zipper "$RUNFILES_MANIFEST_FILE"))" else