Supply temporary directory to genrule() invoked java_binary()
JVMs on UNIX systems typically hardcode to use /tmp as the default
temporary area, unless system property java.io.tmpdir is set on
the command line. Pass the genrule's TMP location to the binary
as a system property so it can be used automatically.
diff --git a/src/com/facebook/buck/rules/Genrule.java b/src/com/facebook/buck/rules/Genrule.java
index 34f39c8..e29ad9a 100644
--- a/src/com/facebook/buck/rules/Genrule.java
+++ b/src/com/facebook/buck/rules/Genrule.java
@@ -332,10 +332,18 @@
buildTarget, cmd, getType().getDisplayName(), getFullyQualifiedName());
}
BinaryBuildRule binaryBuildRule = (BinaryBuildRule)matchingRule;
+ String bincmd;
+ if (binaryBuildRule instanceof JavaBinaryRule) {
+ List<String> jvmArgs = Lists.newArrayListWithCapacity(4);
+ jvmArgs.add(String.format("-Djava.io.tmpdir=%s", tmpDirectory));
+ bincmd = ((JavaBinaryRule)binaryBuildRule).getExecutableCommand(jvmArgs);
+ } else {
+ bincmd = binaryBuildRule.getExecutableCommand();
+ }
// Note that matcher.group(1) is the non-backslash character that did not escape the dollar
// sign, so we make sure that it does not get lost during the regex replacement.
- String replacement = matcher.group(1) + binaryBuildRule.getExecutableCommand();
+ String replacement = matcher.group(1) + bincmd;
matcher.appendReplacement(buffer, replacement);
}
matcher.appendTail(buffer);
diff --git a/src/com/facebook/buck/rules/JavaBinaryRule.java b/src/com/facebook/buck/rules/JavaBinaryRule.java
index c41632a..940adec 100644
--- a/src/com/facebook/buck/rules/JavaBinaryRule.java
+++ b/src/com/facebook/buck/rules/JavaBinaryRule.java
@@ -35,6 +35,7 @@
import com.google.common.collect.Iterables;
import java.io.IOException;
+import java.util.Collections;
import java.util.List;
import java.util.Map;
@@ -156,15 +157,23 @@
@Override
public String getExecutableCommand() {
+ return getExecutableCommand(Collections.<String>emptyList());
+ }
+
+ public String getExecutableCommand(List<String> jvmArgs) {
Preconditions.checkState(mainClass != null,
"Must specify a main class for %s in order to to run it.",
getBuildTarget().getFullyQualifiedName());
-
- return String.format("java -classpath %s %s",
+ StringBuilder cmd = new StringBuilder();
+ cmd.append("java");
+ if (!jvmArgs.isEmpty()) {
+ cmd.append(' ').append(Joiner.on(' ').join(jvmArgs));
+ }
+ return cmd.append(String.format(" -classpath %s %s",
Joiner.on(':').join(Iterables.transform(
getTransitiveClasspathEntries().values(),
Functions.RELATIVE_TO_ABSOLUTE_PATH)),
- mainClass);
+ mainClass)).toString();
}
public static class Builder extends AbstractBuildRuleBuilder {