Delete the temporary AndroidManifest.xml file after aapt finishes running.
Summary:
Apparently on Linux, deleteOnExit won't clean up tmp if the directory is non-empty.
diff --git a/src/com/facebook/buck/android/GenRDotJavaStep.java b/src/com/facebook/buck/android/GenRDotJavaStep.java
index 66311b4..5ce4796 100644
--- a/src/com/facebook/buck/android/GenRDotJavaStep.java
+++ b/src/com/facebook/buck/android/GenRDotJavaStep.java
@@ -35,7 +35,7 @@
public class GenRDotJavaStep extends ShellStep {
private final Set<String> resDirectories;
- private final String androidManifestPath;
+ private final File androidManifest;
private final String genDirectoryPath;
private final boolean isTempRDotJava;
private final ImmutableSet<String> extraLibraryPackages;
@@ -79,7 +79,7 @@
// android_resource() rule in the codebase. This may turn out to be helpful when running the
// Android linter because then the user will specify the min/max values of Android for a
// library.
- File androidManifest = new File(tmpDir, "AndroidManifest.xml");
+ this.androidManifest = new File(tmpDir, "AndroidManifest.xml");
try {
String xml = String.format(
"<manifest xmlns:android='http://schemas.android.com/apk/res/android' package='%s' />",
@@ -91,7 +91,6 @@
} catch (IOException e) {
Throwables.propagate(e);
}
- this.androidManifestPath = androidManifest.getAbsolutePath();
this.genDirectoryPath = Preconditions.checkNotNull(genDirectoryPath);
this.isTempRDotJava = isTempRDotJava;
@@ -125,7 +124,7 @@
}
// Add the remaining flags.
- builder.add("-M").add(androidManifestPath);
+ builder.add("-M").add(androidManifest.getAbsolutePath());
builder.add("-m").add("-J").add(genDirectoryPath);
builder.add("--auto-add-overlay");
builder.add("-I").add(androidPlatformTarget.getAndroidJar().getAbsolutePath());
@@ -134,6 +133,15 @@
}
@Override
+ protected void onProcessFinished(int exitCode) {
+ super.onProcessFinished(exitCode);
+
+ if (androidManifest.exists() && androidManifest.isFile()) {
+ androidManifest.delete();
+ }
+ }
+
+ @Override
public String getShortName() {
return String.format("aapt_package");
}
diff --git a/src/com/facebook/buck/shell/ShellStep.java b/src/com/facebook/buck/shell/ShellStep.java
index cc14e3b..b53ced2 100644
--- a/src/com/facebook/buck/shell/ShellStep.java
+++ b/src/com/facebook/buck/shell/ShellStep.java
@@ -99,16 +99,19 @@
}
Process process;
+ int exitCode;
try {
startTime = System.currentTimeMillis();
process = processBuilder.start();
+ exitCode = interactWithProcess(context, process);
} catch (IOException e) {
e.printStackTrace(context.getStdErr());
- return 1;
+ exitCode = 1;
}
- int exitCode = interactWithProcess(context, process);
endTime = System.currentTimeMillis();
+
+ onProcessFinished(exitCode);
return exitCode;
}
@@ -151,6 +154,14 @@
@VisibleForTesting
protected abstract ImmutableList<String> getShellCommandInternal(ExecutionContext context);
+ /**
+ * Callback function to be run after invoking the shell command.
+ * @param exitCode exit code from invoking the shell script.
+ */
+ protected void onProcessFinished(int exitCode) {
+ // Do nothing by default.
+ }
+
@Override
public final String getDescription(ExecutionContext context) {
// Get environment variables for this command as VAR1=val1 VAR2=val2... etc., with values