Running Buildifier in Windows using Bazel
I'm trying to run Buildifier in Windows. I'm using Bazel instead of the Go package:
bazel run buildifier
I'm getting the following error:
FATAL: ExecuteProgram(C:\users\automation\_bazel_automation\iesztftu\execroot\test\bazel-out\x64_windows-fastbuild\bin\buildifier.bash) failed: ERROR: src/main/native/windows/process.cc(199): CreateProcessW("C:\users\automation\_bazel_automation\iesztftu\execroot\depo\bazel-out\x64_windows-fastbuild\bin\buildifier.bash"): %1 is not a valid Win32 application.
(error: 193)
It looks like a .bash file is trying to get executed in a Windows shell?
Did more research - I can confirm the problem is with running a .bash file in native Windows shell. A way around it is to use ----run_under='bash', which starts a Bash shell (I'm using MSYS2 as recommended by Bazel). But that won't work perfectly with the current bash template, because find for example is a command that exists in both Windows and MSYS2. The Windows find command is earlier on PATH (it's in Windows Folder and you can't control it). So the script fails because it's using the 'Wrong' find parameters (because it's running Windows find). I was able to run the script by stating the specific find folder in MSYS2 and fixing other quirks, but it's clear there's a need for a bat script for Windows.
When there is one, it's just a matter of using select based on the OS when selecting the template. I might be able to write the bat file, just let me know if the above works for you.
To me the issue looks related or the same like https://github.com/bazelbuild/buildtools/issues/346