summaryrefslogtreecommitdiffstats
path: root/jack
diff options
context:
space:
mode:
authormikaelpeltier <mikaelpeltier@google.com>2014-06-30 16:42:32 +0200
committermikaelpeltier <mikaelpeltier@google.com>2014-07-08 17:11:53 +0200
commit71abc4edf7748d068adf8435268584ee32d525fa (patch)
treea9f62cc438551bfaaf46501bc26e0dd8330e3284 /jack
parent6e428383759c2f4efda91e55ef7a15fc9ad4013b (diff)
downloadtoolchain_jack-71abc4edf7748d068adf8435268584ee32d525fa.zip
toolchain_jack-71abc4edf7748d068adf8435268584ee32d525fa.tar.gz
toolchain_jack-71abc4edf7748d068adf8435268584ee32d525fa.tar.bz2
Replace compiler state file by a directory
- This directory will contains all data required by incremental compilation (one jack file per types, on dex file per types, the serialized compiler state). Change-Id: I427edf6371899fb43127c284ce48ad3f568e37cc
Diffstat (limited to 'jack')
-rw-r--r--jack/src/com/android/jack/experimental/incremental/CompilerState.java44
-rw-r--r--jack/src/com/android/jack/experimental/incremental/CompilerStateWriter.java2
-rw-r--r--jack/src/com/android/jack/experimental/incremental/JackIncremental.java39
-rw-r--r--jack/tests/com/android/jack/experimental/incremental/DependenciesTest009.java6
-rw-r--r--jack/tests/com/android/jack/experimental/incremental/IncrementalTestingEnvironment.java31
5 files changed, 79 insertions, 43 deletions
diff --git a/jack/src/com/android/jack/experimental/incremental/CompilerState.java b/jack/src/com/android/jack/experimental/incremental/CompilerState.java
index 40d24e5..2ef6094 100644
--- a/jack/src/com/android/jack/experimental/incremental/CompilerState.java
+++ b/jack/src/com/android/jack/experimental/incremental/CompilerState.java
@@ -21,6 +21,7 @@ import com.android.jack.util.TextUtils;
import com.android.sched.item.Description;
import com.android.sched.item.Name;
import com.android.sched.item.Tag;
+import com.android.sched.util.file.Directory;
import java.io.BufferedReader;
import java.io.File;
@@ -44,6 +45,9 @@ import javax.annotation.Nonnull;
*/
public final class CompilerState {
+ @Nonnull
+ private static final String COMPILER_STATE_FILENAME = "compilerState.ser";
+
/**
* This tag means that {@link CompilerState} is filled and could be write for later compilation.
*/
@@ -64,6 +68,18 @@ public final class CompilerState {
@Nonnull
private Map<String, Set<String>> javaFileToJackFile = new HashMap<String, Set<String>>();
+ @Nonnull
+ private final File compilerStateFile;
+
+ public CompilerState(@Nonnull Directory directory) {
+ compilerStateFile = new File(directory.getFile(), COMPILER_STATE_FILENAME);
+ }
+
+ @Nonnull
+ public File getCompilerStateFile() {
+ return compilerStateFile;
+ }
+
public void updateCompilerState(@Nonnull Set<String> filesToRecompile) {
for (String javaFileToRecompile : filesToRecompile) {
javaFileToJackFile.remove(javaFileToRecompile);
@@ -101,7 +117,12 @@ public final class CompilerState {
addUsage(codeFileToUsedFiles, filename, nameOfUsedFile);
}
- public void write(@Nonnull File compilerStateFile) throws JackIOException {
+ public boolean exists() {
+ return compilerStateFile.exists();
+ }
+
+ public void write(@Nonnull Directory directory) throws JackIOException {
+ File compilerStateFile = new File(directory.getFile(), COMPILER_STATE_FILENAME);
PrintStream ps = null;
try {
@@ -126,19 +147,18 @@ public final class CompilerState {
}
@Nonnull
- public static CompilerState read(@Nonnull File compilerStateFile) throws JackIOException {
- CompilerState csm = new CompilerState();
+ public void read() throws JackIOException {
BufferedReader br = null;
-
+ File csf = getCompilerStateFile();
try {
- br = new BufferedReader(new InputStreamReader(new FileInputStream(compilerStateFile)));
- csm.javaFileToJackFile = readMap(br);
- csm.codeFileToUsedFiles = readMap(br);
- csm.cstFileToUsedFiles = readMap(br);
- csm.structFileToUsedFiles = readMap(br);
+ br = new BufferedReader(new InputStreamReader(new FileInputStream(csf)));
+ javaFileToJackFile = readMap(br);
+ codeFileToUsedFiles = readMap(br);
+ cstFileToUsedFiles = readMap(br);
+ structFileToUsedFiles = readMap(br);
} catch (IOException e) {
throw new JackIOException(
- "Could not read compiler state file '" + compilerStateFile.getAbsolutePath() + "'", e);
+ "Could not read compiler state file '" + csf.getAbsolutePath() + "'", e);
} finally {
try {
if (br != null) {
@@ -146,11 +166,9 @@ public final class CompilerState {
}
} catch (IOException e) {
throw new JackIOException(
- "Could not read compiler state file '" + compilerStateFile.getAbsolutePath() + "'", e);
+ "Could not read compiler state file '" + csf.getAbsolutePath() + "'", e);
}
}
-
- return csm;
}
@Nonnull
diff --git a/jack/src/com/android/jack/experimental/incremental/CompilerStateWriter.java b/jack/src/com/android/jack/experimental/incremental/CompilerStateWriter.java
index 925df0e..e7994c9 100644
--- a/jack/src/com/android/jack/experimental/incremental/CompilerStateWriter.java
+++ b/jack/src/com/android/jack/experimental/incremental/CompilerStateWriter.java
@@ -39,6 +39,6 @@ public class CompilerStateWriter implements RunnableSchedulable<JSession>{
@Override
public void run(@Nonnull JSession program) throws JackUserException {
JackIncremental.getCompilerState().write(
- ThreadConfig.get(JackIncremental.COMPILER_STATE_OUTPUT));
+ ThreadConfig.get(JackIncremental.COMPILER_STATE_OUTPUT_DIR));
}
} \ No newline at end of file
diff --git a/jack/src/com/android/jack/experimental/incremental/JackIncremental.java b/jack/src/com/android/jack/experimental/incremental/JackIncremental.java
index 08eae2d..d9bce2f 100644
--- a/jack/src/com/android/jack/experimental/incremental/JackIncremental.java
+++ b/jack/src/com/android/jack/experimental/incremental/JackIncremental.java
@@ -31,13 +31,16 @@ import com.android.jack.frontend.FrontendCompilationException;
import com.android.jack.util.TextUtils;
import com.android.sched.util.RunnableHooks;
import com.android.sched.util.UnrecoverableException;
-import com.android.sched.util.codec.PathCodec;
+import com.android.sched.util.codec.DirectoryCodec;
import com.android.sched.util.config.ChainedException;
import com.android.sched.util.config.ConfigurationException;
import com.android.sched.util.config.HasKeyId;
import com.android.sched.util.config.ThreadConfig;
import com.android.sched.util.config.id.BooleanPropertyId;
import com.android.sched.util.config.id.PropertyId;
+import com.android.sched.util.file.Directory;
+import com.android.sched.util.file.FileOrDirectory.Existence;
+import com.android.sched.util.file.FileOrDirectory.Permission;
import com.android.sched.util.log.LoggerFactory;
import java.io.File;
@@ -67,8 +70,9 @@ public class JackIncremental extends CommandLine {
Boolean.FALSE);
@Nonnull
- public static final PropertyId<File> COMPILER_STATE_OUTPUT = PropertyId.create(
- "jack.experimental.compilerstate.output", "Compiler state output file", new PathCodec())
+ public static final PropertyId<Directory> COMPILER_STATE_OUTPUT_DIR = PropertyId.create(
+ "jack.experimental.compilerstate.output.dir", "Compiler state output folder",
+ new DirectoryCodec(Existence.MUST_EXIST, Permission.READ | Permission.WRITE))
.requiredIf(GENERATE_COMPILER_STATE.getValue().isTrue());
@CheckForNull
@@ -148,17 +152,19 @@ public class JackIncremental extends CommandLine {
}
ThreadConfig.setConfig(options.getConfig());
+ compilerState = new CompilerState(ThreadConfig.get(JackIncremental.COMPILER_STATE_OUTPUT_DIR));
+
if (isIncrementalCompilation(options)) {
logger.log(Level.INFO, "Incremental compilation");
List<String> javaFilesNames = getJavaFilesSpecifiedOnCommandLine(options);
- compilerState = CompilerState.read(ThreadConfig.get(JackIncremental.COMPILER_STATE_OUTPUT));
- Map<String, Set<String>> fileDependencies = compilerState.computeDependencies();
+ getCompilerState().read();
+
+ Map<String, Set<String>> fileDependencies = getCompilerState().computeDependencies();
printDependencyStat(fileDependencies);
- logger.log(Level.FINE, "Compiler state {0}", new Object[] {compilerState});
- logger.log(Level.FINE, "File dependencies {0}",
- new Object[] {dependenciesToString(fileDependencies)});
+ logger.log(Level.FINE, "Compiler state {0}", getCompilerState());
+ logger.log(Level.FINE, "File dependencies {0}", dependenciesToString(fileDependencies));
Set<String> filesToRecompile = getFilesToRecompile(fileDependencies, options, javaFilesNames);
@@ -172,8 +178,8 @@ public class JackIncremental extends CommandLine {
logger.log(Level.INFO, "Update compiler state");
getCompilerState().updateCompilerState(filesToRecompile);
- logger.log(Level.INFO, "Generate {0}", new Object[] {options.getOutputFile()});
- logger.log(Level.INFO, "Ecj options {0}", new Object[] {options.getEcjArguments()});
+ logger.log(Level.INFO, "Generate {0}", options.getOutputFile());
+ logger.log(Level.INFO, "Ecj options {0}", options.getEcjArguments());
Jack.run(options);
logger.log(Level.INFO, "Merge {0} with {1}",
@@ -183,7 +189,6 @@ public class JackIncremental extends CommandLine {
logger.log(Level.INFO, "No files to recompile");
}
} else {
- compilerState = new CompilerState();
Jack.run(options);
}
}
@@ -310,7 +315,7 @@ public class JackIncremental extends CommandLine {
while (previousFilesIt.hasNext()) {
String previousFileName = previousFilesIt.next();
if (!javaFileNames.contains(previousFileName)) {
- logger.log(Level.INFO, "{0} was deleted", new Object[] {previousFileName});
+ logger.log(Level.INFO, "{0} was deleted", previousFileName);
deletedFiles.addAll(fileDependencies.get(previousFileName));
deleteJackFilesFromJavaFiles(previousFileName);
previousFilesIt.remove();
@@ -322,8 +327,8 @@ public class JackIncremental extends CommandLine {
private static void deleteJackFilesFromJavaFiles(@Nonnull String javaFileName)
throws JackUserException {
- for (String jackFileToRemove :
- getCompilerState().getJacksFileNameFromJavaFileName(javaFileName)) {
+ for (String jackFileToRemove : getCompilerState()
+ .getJacksFileNameFromJavaFileName(javaFileName)) {
File jackFile = new File(jackFileToRemove);
if (jackFile.exists() && !jackFile.delete()) {
throw new JackIOException("Failed to delete file " + jackFileToRemove);
@@ -339,7 +344,7 @@ public class JackIncremental extends CommandLine {
for (String javaFileName : javaFileNames) {
if (!previousFiles.contains(javaFileName)) {
- logger.log(Level.INFO, "{0} was added", new Object[] {javaFileName});
+ logger.log(Level.INFO, "{0} was added", javaFileName);
addedFiles.add(javaFileName);
}
}
@@ -357,7 +362,7 @@ public class JackIncremental extends CommandLine {
File javaFile = new File(javaFileName);
if (javaFileNames.contains(javaFileName) &&
javaFile.lastModified() > options.getOutputFile().lastModified()) {
- logger.log(Level.INFO, "{0} was modified", new Object[] {javaFileName});
+ logger.log(Level.INFO, "{0} was modified", javaFileName);
modifiedFiles.add(javaFileName);
modifiedFiles.addAll(previousFileEntry.getValue());
deleteJackFilesFromJavaFiles(javaFileName);
@@ -407,7 +412,7 @@ public class JackIncremental extends CommandLine {
if (!options.getEcjArguments().isEmpty()
&& ThreadConfig.get(Options.GENERATE_DEX_FILE).booleanValue()
&& ThreadConfig.get(JackIncremental.GENERATE_COMPILER_STATE).booleanValue()
- && ThreadConfig.get(JackIncremental.COMPILER_STATE_OUTPUT).exists()) {
+ && getCompilerState().exists()) {
return true;
}
diff --git a/jack/tests/com/android/jack/experimental/incremental/DependenciesTest009.java b/jack/tests/com/android/jack/experimental/incremental/DependenciesTest009.java
index 02ea163..aec446f 100644
--- a/jack/tests/com/android/jack/experimental/incremental/DependenciesTest009.java
+++ b/jack/tests/com/android/jack/experimental/incremental/DependenciesTest009.java
@@ -57,7 +57,8 @@ public class DependenciesTest009 {
ite.incrementalBuildFromFolder();
- CompilerState csm = CompilerState.read(ite.getCompilerStateFile());
+ CompilerState csm = new CompilerState(ite.getCompilerStateDirectory());
+ csm.read();
Map<String, Set<String>> dependencies1 = csm.computeDependencies();
ite.addJavaFile("jack.incremental", "A.java", "package jack.incremental; \n"
@@ -65,8 +66,7 @@ public class DependenciesTest009 {
ite.incrementalBuildFromFolder();
- csm = CompilerState.read(ite.getCompilerStateFile());
- CompilerState.read(ite.getCompilerStateFile());
+ csm.read();
Map<String, Set<String>> dependencies2 = csm.computeDependencies();
assert dependencies1.equals(dependencies2);
diff --git a/jack/tests/com/android/jack/experimental/incremental/IncrementalTestingEnvironment.java b/jack/tests/com/android/jack/experimental/incremental/IncrementalTestingEnvironment.java
index ce7bc50..83d9742 100644
--- a/jack/tests/com/android/jack/experimental/incremental/IncrementalTestingEnvironment.java
+++ b/jack/tests/com/android/jack/experimental/incremental/IncrementalTestingEnvironment.java
@@ -21,6 +21,10 @@ import com.android.jack.TestTools;
import com.android.jack.backend.jayce.JayceFileImporter;
import com.android.jack.util.ExecuteFile;
import com.android.jack.util.NamingTools;
+import com.android.sched.util.file.Directory;
+import com.android.sched.util.file.FileOrDirectory.ChangePermission;
+import com.android.sched.util.file.FileOrDirectory.Existence;
+import com.android.sched.util.file.FileOrDirectory.Permission;
import java.io.ByteArrayOutputStream;
import java.io.File;
@@ -53,6 +57,9 @@ public class IncrementalTestingEnvironment extends TestTools {
PrintStream outRedirectStream = null;
@Nonnull
+ private final Directory compilerStateDir;
+
+ @Nonnull
private final File testingFolder;
@Nonnull
@@ -61,6 +68,9 @@ public class IncrementalTestingEnvironment extends TestTools {
@Nonnull
private final File dexFile;
+ @Nonnull
+ private final File jackFolder;
+
private final Map<String, Long> fileModificationDate = new HashMap<String, Long>();
@Nonnull
@@ -73,6 +83,11 @@ public class IncrementalTestingEnvironment extends TestTools {
throw new IOException("Failed to create folder " + this.sourceFolder.getAbsolutePath());
}
dexFile = new File(testingFolder, "result.dex");
+ compilerStateDir =
+ new Directory(testingFolder.getAbsolutePath() + File.separatorChar + "compilerState",
+ null, Existence.MAY_EXIST, Permission.READ | Permission.WRITE,
+ ChangePermission.NOCHANGE);
+ jackFolder = new File(compilerStateDir.getFile(), "jackFiles");
}
public void addJavaFile(@Nonnull String packageName, @Nonnull String fileName,
@@ -111,8 +126,8 @@ public class IncrementalTestingEnvironment extends TestTools {
}
@Nonnull
- public File getCompilerStateFile() {
- return new File(testingFolder, "compilerState.ser");
+ public Directory getCompilerStateDirectory() {
+ return compilerStateDir;
}
public void incrementalBuildFromFolder() throws Exception {
@@ -122,11 +137,10 @@ public class IncrementalTestingEnvironment extends TestTools {
Options options = TestTools.buildCommandLineArgs(testingFolder);
options.addProperty(Options.GENERATE_JACK_FILE.getName(), "true");
options.addProperty(Options.JACK_OUTPUT_CONTAINER_TYPE.getName(), "dir");
- options.addProperty(Options.JACK_FILE_OUTPUT_DIR.getName(), new File(testingFolder,
- "jackIncrementalOutput").getAbsolutePath());
+ options.addProperty(Options.JACK_FILE_OUTPUT_DIR.getName(), jackFolder.getAbsolutePath());
options.addProperty(JackIncremental.GENERATE_COMPILER_STATE.getName(), "true");
- options.addProperty(JackIncremental.COMPILER_STATE_OUTPUT.getName(), getCompilerStateFile()
- .getAbsolutePath());
+ options.addProperty(JackIncremental.COMPILER_STATE_OUTPUT_DIR.getName(), getCompilerStateDirectory()
+ .getFile().getAbsolutePath());
compileSourceToDex(options, sourceFolder,
TestTools.getClasspathAsString(TestTools.getDefaultBootclasspath()), dexFile);
@@ -162,7 +176,6 @@ public class IncrementalTestingEnvironment extends TestTools {
List<String> fqnOfRebuiltTypes = new ArrayList<String>();
List<File> jackFiles = new ArrayList<File>();
- File jackFolder = new File(testingFolder, "jackIncrementalOutput");
fillJackFiles(jackFolder, jackFiles);
for (File jackFile : jackFiles) {
@@ -184,7 +197,7 @@ public class IncrementalTestingEnvironment extends TestTools {
public void snapshotJackFilesModificationDate() {
List<File> jackFiles = new ArrayList<File>();
- fillJackFiles(new File(testingFolder, "jackIncrementalOutput"), jackFiles);
+ fillJackFiles(jackFolder, jackFiles);
for (File jackFile : jackFiles) {
fileModificationDate.put(jackFile.getAbsolutePath(), Long.valueOf(jackFile.lastModified()));
}
@@ -211,7 +224,7 @@ public class IncrementalTestingEnvironment extends TestTools {
@Nonnull
public List<File> getJackFiles() {
List<File> jackFiles = new ArrayList<File>();
- fillJackFiles(new File(testingFolder, "jackIncrementalOutput"), jackFiles);
+ fillJackFiles(jackFolder, jackFiles);
return (jackFiles);
}