use of com.google.devtools.j2objc.pipeline.GenerationBatch in project j2objc by google.
the class J2ObjC method run.
/**
* Runs the entire J2ObjC pipeline.
* @param fileArgs the files to process, same format as command-line args to {@link #main}.
*/
public static void run(List<String> fileArgs, Options options) {
File preProcessorTempDir = null;
File strippedSourcesDir = null;
Parser parser = null;
try {
List<ProcessingContext> inputs = Lists.newArrayList();
GenerationBatch batch = new GenerationBatch(options);
batch.processFileArgs(fileArgs);
inputs.addAll(batch.getInputs());
if (ErrorUtil.errorCount() > 0) {
return;
}
parser = createParser(options);
Parser.ProcessingResult processingResult = parser.processAnnotations(fileArgs, inputs);
List<ProcessingContext> generatedInputs = processingResult.getGeneratedSources();
// Ensure all generatedInputs are at end of input list.
inputs.addAll(generatedInputs);
preProcessorTempDir = processingResult.getSourceOutputDirectory();
if (ErrorUtil.errorCount() > 0) {
return;
}
if (preProcessorTempDir != null) {
parser.addSourcepathEntry(preProcessorTempDir.getAbsolutePath());
}
InputFilePreprocessor inputFilePreprocessor = new InputFilePreprocessor(parser);
inputFilePreprocessor.processInputs(inputs);
if (ErrorUtil.errorCount() > 0) {
return;
}
strippedSourcesDir = inputFilePreprocessor.getStrippedSourcesDir();
if (strippedSourcesDir != null) {
parser.prependSourcepathEntry(strippedSourcesDir.getPath());
}
options.getHeaderMap().loadMappings();
TranslationProcessor translationProcessor = new TranslationProcessor(parser, loadDeadCodeMap());
translationProcessor.processInputs(inputs);
translationProcessor.processBuildClosureDependencies();
if (ErrorUtil.errorCount() > 0) {
return;
}
translationProcessor.postProcess();
options.getHeaderMap().printMappings();
} finally {
if (parser != null) {
try {
parser.close();
} catch (IOException e) {
ErrorUtil.error(e.getMessage());
}
}
Set<String> tempDirs = options.fileUtil().getTempDirs();
for (String dir : tempDirs) {
FileUtil.deleteTempDir(new File(dir));
}
FileUtil.deleteTempDir(preProcessorTempDir);
FileUtil.deleteTempDir(strippedSourcesDir);
}
}
use of com.google.devtools.j2objc.pipeline.GenerationBatch in project j2objc by google.
the class GenerationTest method preprocessFiles.
protected void preprocessFiles(String... fileNames) {
GenerationBatch batch = new GenerationBatch(options);
for (String fileName : fileNames) {
batch.addSource(new RegularInputFile(tempDir.getPath() + File.separatorChar + fileName, fileName));
}
new InputFilePreprocessor(parser).processInputs(batch.getInputs());
}
Aggregations