Skip to content

Commit

Permalink
Windows: Make bazel run --script_path work on Windows
Browse files Browse the repository at this point in the history
--script_path should write a batch file instead of bash file on Windows.

Related: bazelbuild/bazel-watcher#144
(ibazel uses --script_path)

RELNOTES: None
PiperOrigin-RevId: 218828314
  • Loading branch information
meteorcloudy authored and Copybara-Service committed Oct 26, 2018
1 parent 79d5ac3 commit 4634c20
Showing 1 changed file with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
import com.google.devtools.build.lib.util.CommandFailureUtils;
import com.google.devtools.build.lib.util.ExitCode;
import com.google.devtools.build.lib.util.FileType;
import com.google.devtools.build.lib.util.OS;
import com.google.devtools.build.lib.util.OptionsUtils;
import com.google.devtools.build.lib.util.ShellEscaper;
import com.google.devtools.build.lib.util.io.OutErr;
Expand Down Expand Up @@ -523,11 +524,19 @@ private boolean writeScript(
String cmd) {
Path scriptPath = env.getWorkingDirectory().getRelative(scriptPathFrag);
try {
FileSystemUtils.writeContent(
scriptPath,
StandardCharsets.ISO_8859_1,
"#!" + shellExecutable.getPathString() + "\n" + cmd + " \"$@\"");
scriptPath.setExecutable(true);
if (OS.getCurrent() == OS.WINDOWS) {
FileSystemUtils.writeContent(
scriptPath,
StandardCharsets.ISO_8859_1,
"@echo off\n" + cmd + " %*");
scriptPath.setExecutable(true);
} else {
FileSystemUtils.writeContent(
scriptPath,
StandardCharsets.ISO_8859_1,
"#!" + shellExecutable.getPathString() + "\n" + cmd + " \"$@\"");
scriptPath.setExecutable(true);
}
} catch (IOException e) {
env.getReporter().handle(Event.error("Error writing run script:" + e.getMessage()));
return false;
Expand Down

0 comments on commit 4634c20

Please sign in to comment.