Search in sources :

Example 1 with GenerationBatch

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);
    }
}
Also used : ProcessingContext(com.google.devtools.j2objc.pipeline.ProcessingContext) TranslationProcessor(com.google.devtools.j2objc.pipeline.TranslationProcessor) InputFilePreprocessor(com.google.devtools.j2objc.pipeline.InputFilePreprocessor) IOException(java.io.IOException) File(java.io.File) GenerationBatch(com.google.devtools.j2objc.pipeline.GenerationBatch) ProGuardUsageParser(com.google.devtools.j2objc.util.ProGuardUsageParser) Parser(com.google.devtools.j2objc.util.Parser)

Example 2 with GenerationBatch

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());
}
Also used : RegularInputFile(com.google.devtools.j2objc.file.RegularInputFile) InputFilePreprocessor(com.google.devtools.j2objc.pipeline.InputFilePreprocessor) GenerationBatch(com.google.devtools.j2objc.pipeline.GenerationBatch)

Aggregations

GenerationBatch (com.google.devtools.j2objc.pipeline.GenerationBatch)2 InputFilePreprocessor (com.google.devtools.j2objc.pipeline.InputFilePreprocessor)2 RegularInputFile (com.google.devtools.j2objc.file.RegularInputFile)1 ProcessingContext (com.google.devtools.j2objc.pipeline.ProcessingContext)1 TranslationProcessor (com.google.devtools.j2objc.pipeline.TranslationProcessor)1 Parser (com.google.devtools.j2objc.util.Parser)1 ProGuardUsageParser (com.google.devtools.j2objc.util.ProGuardUsageParser)1 File (java.io.File)1 IOException (java.io.IOException)1