-
Notifications
You must be signed in to change notification settings - Fork 458
Description
When following https://github.com/bazelbuild/buildtools/blob/master/buildifier/README.md#setup-and-usage-via-bazel on windows, the following output is observed:
$ bazel run //:buildifier
INFO: Analysed target //:buildifier (1 packages loaded).
INFO: Found 1 target...
Target //:buildifier up-to-date:
C:/users/kamik/_bazel_kamik/gq7cl633/execroot/angular_devkit/bazel-out/x64_windows-fastbuild/bin/buildifier.bash
INFO: Elapsed time: 2.531s, Critical Path: 0.01s
INFO: 0 processes.
INFO: Build completed successfully, 1 total action
INFO: Build completed successfully, 1 total action
C:/users/kamik/_bazel_kamik/gq7cl633/execroot/angular_devkit/bazel-out/x64_windows-fastbuild/bin/buildifier.bash: line 8: : command not found
(Note: --direct_run is not used because it shows a WARNING: Option 'direct_run' is deprecated message).
The buildifier.bash file is such:
#!/usr/bin/env bash
BUILDIFIER_SHORT_PATH='../com_github_bazelbuild_buildtools/buildifier/windows_amd64_stripped/buildifier.exe'
ARGS=('-mode=fix' '-v=false' '-showlog=false')
buildifier_short_path=$(readlink "$BUILDIFIER_SHORT_PATH")
cd "$BUILD_WORKSPACE_DIRECTORY"
"$buildifier_short_path" "${ARGS[@]}" $(find . -type f \( -name '*.bzl' -or -name 'BUILD.bazel' -or -name 'BUILD' -or -name 'WORKSPACE' \))
Debugging this generated file, I find two things:
$BUILDIFIER_SHORT_PATHevaluates to../com_github_bazelbuild_buildtools/buildifier/windows_amd64_stripped/buildifier.exe$buildifier_short_pathevaluates to an empty string.
Indeed the path listed by $BUILDIFIER_SHORT_PATH does not actually exist. That executable can be found at ../external/com_github_bazelbuild_buildtools/buildifier/windows_amd64_stripped/buildifier.exe instead though. This mapping in windows is expressed in the buildifier.bash.runfiles_manifest file.
Another problem is that the path listed is not a symlink on windows, as using the --verbose flag on readlink highlights:
readlink "./external/com_github_bazelbuild_buildtools/buildifier/windows_amd64_stripped/buildifier.exe" --verbose
readlink: ./external/com_github_bazelbuild_buildtools/buildifier/windows_amd64_stripped/buildifier.exe: Invalid argument
Using realpath instead of readlink helps here, but I am unsure of the effect on non-windows platforms.
I hacked a bit on a local copy by hardcoding the right path and using realpath and buildifier seemed to work on Windows then.
Related to #170