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
@@ -36,6 +36,19 @@ msys*|mingw*|cygwin*)
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 @@ fi
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
