Skip to content

Commit

Permalink
Improves portability of buildifier_test (#1128)
Browse files Browse the repository at this point in the history
  • Loading branch information
jszumski authored Jan 27, 2023
1 parent d250c1a commit cf44629
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions buildifier/runner.bash.template
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,24 @@ buildifier_short_path=$(readlink "$BUILDIFIER_SHORT_PATH")
if [[ ! -z "${TEST_WORKSPACE+x}" && -z "${BUILD_WORKSPACE_DIRECTORY+x}" ]]; then
FIND_FILE_TYPE="l"
# If WORKSPACE was provided, then the script is being run under a test in no_sandbox mode
# cd to the directory containing the WORKSPACE file
if [[ ! -z "${WORKSPACE+x}" ]]; then
FIND_FILE_TYPE="f"
WORKSPACE_PATH="$(dirname "$(realpath ${WORKSPACE})")"

# resolve the WORKSPACE symlink
# use `realpath` if available and `readlink` otherwise (typically macOS)
if command -v realpath &> /dev/null; then
WORKSPACE_LINK="$(realpath ${WORKSPACE})"
elif command -v readlink &> /dev/null; then
WORKSPACE_LINK="$(readlink ${WORKSPACE})"
else
echo "Unable to resolve symlink (WORKSPACE: ${WORKSPACE})"
exit 1
fi

# Find the directory containing the WORKSPACE file
WORKSPACE_PATH="$(dirname "$WORKSPACE_LINK")"

# Change the working directory to the WORKSPACE parent
if ! cd "$WORKSPACE_PATH" ; then
echo "Unable to change to workspace (WORKSPACE_PATH: ${WORKSPACE_PATH})"
fi
Expand Down

0 comments on commit cf44629

Please sign in to comment.