genrule() should fail if any command fails.
Summary:
From https://github.com/facebook/buck/pull/16.
If a genrule is a complex sequence of shell commands the rule
should fail if any of the commands fails and its exit status was
not examined.
Fixes https://github.com/facebook/buck/issues/21
Test Plan: Sandcastle builds.
diff --git a/src/com/facebook/buck/shell/AbstractGenruleStep.java b/src/com/facebook/buck/shell/AbstractGenruleStep.java
index d35f47b..2d66a7b 100644
--- a/src/com/facebook/buck/shell/AbstractGenruleStep.java
+++ b/src/com/facebook/buck/shell/AbstractGenruleStep.java
@@ -103,7 +103,7 @@
protected ImmutableList<String> getShellCommandInternal(ExecutionContext context) {
// The priority sequence is
// "cmd.exe /c winCommand" (Windows Only)
- // "/bin/bash -c shCommand" (Non-windows Only)
+ // "/bin/bash -e -c shCommand" (Non-windows Only)
// "(/bin/bash -c) or (cmd.exe /c) cmd" (All platforms)
String command;
if (context.getPlatform() == Platform.WINDOWS) {
@@ -129,7 +129,7 @@
getFullyQualifiedName());
}
command = replaceMatches(context.getProjectFilesystem(), commandInUse);
- return ImmutableList.of("/bin/bash", "-c", command);
+ return ImmutableList.of("/bin/bash", "-e", "-c", command);
}
}
diff --git a/test/com/facebook/buck/android/ApkGenruleTest.java b/test/com/facebook/buck/android/ApkGenruleTest.java
index baa6e40..72c2b31 100644
--- a/test/com/facebook/buck/android/ApkGenruleTest.java
+++ b/test/com/facebook/buck/android/ApkGenruleTest.java
@@ -223,7 +223,7 @@
.put("OUT", expectedApkOutput).build(),
genruleCommand.getEnvironmentVariables(executionContext));
assertEquals(
- ImmutableList.of("/bin/bash", "-c", "python signer.py $APK key.properties > $OUT"),
+ ImmutableList.of("/bin/bash", "-e", "-c", "python signer.py $APK key.properties > $OUT"),
genruleCommand.getShellCommand(executionContext));
EasyMock.verify(parser);
diff --git a/test/com/facebook/buck/shell/GenruleTest.java b/test/com/facebook/buck/shell/GenruleTest.java
index 5a90327..2391fed 100644
--- a/test/com/facebook/buck/shell/GenruleTest.java
+++ b/test/com/facebook/buck/shell/GenruleTest.java
@@ -233,7 +233,7 @@
.build(),
genruleCommand.getEnvironmentVariables(executionContext));
assertEquals(
- ImmutableList.of("/bin/bash", "-c", "python convert_to_katana.py AndroidManifest.xml > $OUT"),
+ ImmutableList.of("/bin/bash", "-e", "-c", "python convert_to_katana.py AndroidManifest.xml > $OUT"),
genruleCommand.getShellCommand(executionContext));
}
@@ -511,7 +511,7 @@
.build(new BuildRuleResolver());
ImmutableList<String> command = rule.createGenruleStep().getShellCommand(linuxExecutionContext);
- assertEquals(ImmutableList.of("/bin/bash", "-c", bash), command);
+ assertEquals(ImmutableList.of("/bin/bash", "-e", "-c", bash), command);
command = rule.createGenruleStep().getShellCommand(windowsExecutionContext);
assertEquals(ImmutableList.of("cmd.exe", "/c", cmdExe), command);
@@ -523,7 +523,7 @@
.setOut("out.txt")
.build(new BuildRuleResolver());
command = rule.createGenruleStep().getShellCommand(linuxExecutionContext);
- assertEquals(ImmutableList.of("/bin/bash", "-c", cmd), command);
+ assertEquals(ImmutableList.of("/bin/bash", "-e", "-c", cmd), command);
command = rule.createGenruleStep().getShellCommand(windowsExecutionContext);
assertEquals(ImmutableList.of("cmd.exe", "/c", cmd), command);