Fix --toolchain jack --mode device --benchmark

Bug: 27312904
Change-Id: I179c6d923667a8a9104ca7a2e3c113bd1541ef38
diff --git a/src/vogar/Driver.java b/src/vogar/Driver.java
index 1d8ea3c..ca17cf4 100644
--- a/src/vogar/Driver.java
+++ b/src/vogar/Driver.java
@@ -153,7 +153,7 @@
         boolean useLargeTimeout = expectation.getTags().contains("large");
         File jar;
         if (run.useJack) {
-            jar = run.hostDexJar(action);
+            jar = run.hostJack(action);
         } else {
             jar = run.hostJar(action);
         }
diff --git a/src/vogar/Run.java b/src/vogar/Run.java
index 75b98c2..633f78d 100644
--- a/src/vogar/Run.java
+++ b/src/vogar/Run.java
@@ -251,8 +251,8 @@
         return localFile(nameOrAction, nameOrAction + ".jar");
     }
 
-    public File hostDexJar(Object nameOrAction) {
-        return localFile(nameOrAction, nameOrAction + ".dex.jar");
+    public File hostJack(Object nameOrAction) {
+        return localFile(nameOrAction, nameOrAction + ".jack");
     }
 
     /**
diff --git a/src/vogar/android/DeviceRuntime.java b/src/vogar/android/DeviceRuntime.java
index 2fda2f5..cf60bbc 100644
--- a/src/vogar/android/DeviceRuntime.java
+++ b/src/vogar/android/DeviceRuntime.java
@@ -139,7 +139,7 @@
         Task dex;
         if (run.useJack) {
             dex = new JackDexTask(run, classpath, run.benchmark, name, classpathElement,
-                    null, localDex);
+                    action, localDex);
         } else {
             dex = new DexTask(run.androidSdk, classpath, run.benchmark, name, classpathElement,
                     action, localDex);
diff --git a/src/vogar/android/JackDexTask.java b/src/vogar/android/JackDexTask.java
index bc18283..f1d7d5a 100644
--- a/src/vogar/android/JackDexTask.java
+++ b/src/vogar/android/JackDexTask.java
@@ -39,7 +39,7 @@
     private final File localDex;
 
     public JackDexTask(Run run, Classpath classpath, boolean benchmark, String name,
-        File inputFile, Action action, File localDex) {
+            File inputFile, Action action, File localDex) {
         super("jackdex " + name);
         this.run = run;
         this.classpath = classpath;
@@ -59,53 +59,39 @@
         // for us.
         // 2) A .jar file containing .class files: We must ask Jack to convert it to a .dex.jar and
         // we have to handle resources.
-        // 3) A .dex.jar file produced by a prior compilation phase. We must copy it to the target
-        // location (if needed).
 
         // There are several things below that seem fishy and could be improved with a different
         // task workflow:
-        // 1) Being presented with a .dex.jar file suggests the workflow is broken (but is currently
-        // a necessary step while this step is done after compilation with jack where the
-        // alternative is compilation with javac).
-        // 2) Having to deal with multiple classpath entries for inclusion: if the purpose is
+        // 1) Having to deal with multiple classpath entries for inclusion: if the purpose is
         // to convert a .jack or .jar to a .dex.jar file we *may* not need supporting classes.
-        // 3) The resource inclusion behavior is almost certainly incorrect and may need a change in
+        // 2) The resource inclusion behavior is almost certainly incorrect and may need a change in
         // Jack if we persist with including the entire classpath (2).
 
-        if (inputFile.getName().endsWith(".dex.jar")) {
-            if (!inputFile.getCanonicalPath().equals(localDex.getCanonicalPath())) {
-                run.log.verbose("Copying " + inputFile + " to " + localDex);
-                new Command(run.log, "cp", inputFile.getPath(), localDex.getPath()).execute();
-            } else {
-                run.log.verbose("Skipping copy of " + inputFile);
-            }
-        } else {
-            Jack jack = Jack.getJackCommand(run.log).outputDexZip(localDex.getPath());
-            jack.sourceVersion(run.language.getJackArg());
+        Jack jack = Jack.getJackCommand(run.log).outputDexZip(localDex.getPath());
+        jack.sourceVersion(run.language.getJackArg());
 
-            // Jack imports resources from .jack files but not .jar files. We keep track of the .jar
-            // files so we can unpack them in reverse order (to maintain classpath ordering).
-            // Unfortunately, the inconsistency between .jack and .jar behavior makes it incorrect
-            // in some cases.
-            LinkedList<File> resourcesReverseClasspath = new LinkedList<>();
-            addClassPathEntryToJack(jack, resourcesReverseClasspath, inputFile);
-            if (benchmark && action != null) {
-                for (File classpathElement : classpath.getElements()) {
-                    addClassPathEntryToJack(jack, resourcesReverseClasspath, classpathElement);
-                }
+        // Jack imports resources from .jack files but not .jar files. We keep track of the .jar
+        // files so we can unpack them in reverse order (to maintain classpath ordering).
+        // Unfortunately, the inconsistency between .jack and .jar behavior makes it incorrect
+        // in some cases.
+        LinkedList<File> resourcesReverseClasspath = new LinkedList<>();
+        addClassPathEntryToJack(jack, resourcesReverseClasspath, inputFile);
+        if (benchmark && action != null) {
+            for (File classpathElement : classpath.getElements()) {
+                addClassPathEntryToJack(jack, resourcesReverseClasspath, classpathElement);
             }
-
-            if (!resourcesReverseClasspath.isEmpty()) {
-                File resourcesDir = run.localFile(localDex.getName() + "_resources");
-                run.mkdir.mkdirs(resourcesDir);
-                // Unpack each classpath entry into resourcesDir
-                for (File classpathEntry : resourcesReverseClasspath) {
-                    unpackJar(classpathEntry, resourcesDir);
-                }
-                jack.importResource(resourcesDir.getPath());
-            }
-            jack.invoke();
         }
+
+        if (!resourcesReverseClasspath.isEmpty()) {
+            File resourcesDir = run.localFile(localDex.getName() + "_resources");
+            run.mkdir.mkdirs(resourcesDir);
+            // Unpack each classpath entry into resourcesDir.
+            for (File classpathEntry : resourcesReverseClasspath) {
+                unpackJar(classpathEntry, resourcesDir);
+            }
+            jack.importResource(resourcesDir.getPath());
+        }
+        jack.invoke();
         return Result.SUCCESS;
     }
 
diff --git a/src/vogar/tasks/BuildActionTask.java b/src/vogar/tasks/BuildActionTask.java
index 082faaf..1f0b3ae 100644
--- a/src/vogar/tasks/BuildActionTask.java
+++ b/src/vogar/tasks/BuildActionTask.java
@@ -50,22 +50,22 @@
     private final Action action;
     private final Run run;
     private final Driver driver;
-    private final File jar;
+    private final File outputFile;
 
-    public BuildActionTask(Run run, Action action, Driver driver, File jar) {
+    public BuildActionTask(Run run, Action action, Driver driver, File outputFile) {
         super("build " + action.getName());
         this.run = run;
         this.action = action;
         this.driver = driver;
-        this.jar = jar;
+        this.outputFile = outputFile;
     }
 
     @Override protected Result execute() throws Exception {
         try {
             if (run.useJack) {
-                compileWithJack(action, jar);
+                compileWithJack(action, outputFile);
             } else {
-                compile(action, jar);
+                compile(action, outputFile);
             }
             return Result.SUCCESS;
         } catch (CommandFailedException e) {
@@ -124,8 +124,8 @@
     /**
      * Compile sources using the Jack compiler.
      */
-    private void compileWithJack(Action action, File jar) throws IOException {
-        // Create a folder for resources
+    private void compileWithJack(Action action, File jackFile) throws IOException {
+        // Create a folder for resources.
         File resourcesDir = run.localFile(action, "resources");
         run.mkdir.mkdirs(resourcesDir);
         createJarMetadataFiles(action, resourcesDir);
@@ -160,7 +160,7 @@
             }
         }
 
-        compiler.outputDexZip(jar.getPath())
+        compiler.outputJack(jackFile.getPath())
                 .importResource(resourcesDir.getPath())
                 .compile(sourceFiles);
     }