예제 #1
0
 private TreeLogger makeCompileLogger(CompileDir compileDir, TreeLogger parent)
     throws UnableToCompleteException {
   try {
     PrintWriterTreeLogger fileLogger = new PrintWriterTreeLogger(compileDir.getLogFile());
     fileLogger.setMaxDetail(options.getLogLevel());
     return new CompositeTreeLogger(parent, fileLogger);
   } catch (IOException e) {
     parent.log(TreeLogger.ERROR, "unable to open log file: " + compileDir.getLogFile(), e);
     throw new UnableToCompleteException();
   }
 }
예제 #2
0
  /**
   * Prepares a stub compile directory. It will include all "public" resources and a nocache.js file
   * that invokes the compiler.
   */
  private void setUpCompileDir(CompileDir compileDir, ModuleDef module, TreeLogger compileLogger)
      throws UnableToCompleteException {
    try {
      String currentModuleName = module.getName();

      // Create the directory.
      File outputDir =
          new File(compileDir.getWarDir().getCanonicalPath() + "/" + currentModuleName);
      if (!outputDir.exists()) {
        if (!outputDir.mkdir()) {
          compileLogger.log(Type.WARN, "cannot create directory: " + outputDir);
        }
      }
      LauncherDir.writePublicResources(outputDir, module, compileLogger);

      // write no cache that will inject recompile.nocache.js
      String stub = LauncherDir.generateStubNocacheJs(module.getName(), options);
      File noCacheJs = new File(outputDir.getCanonicalPath(), module.getName() + ".nocache.js");
      Files.write(stub, noCacheJs, Charsets.UTF_8);

      // Create a "module_name.recompile.nocache.js" that calculates the permutation
      // and forces a recompile.
      String recompileNoCache = generateModuleRecompileJs(module, compileLogger);
      writeRecompileNoCacheJs(outputDir, currentModuleName, recompileNoCache, compileLogger);
    } catch (IOException e) {
      compileLogger.log(Type.ERROR, "Error creating stub compile directory.", e);
      UnableToCompleteException wrapped = new UnableToCompleteException();
      wrapped.initCause(e);
      throw wrapped;
    }
  }
예제 #3
0
 @Override
 public File getGenDir() {
   return compileDir.getGenDir();
 }
예제 #4
0
 @Override
 public File getExtraDir() {
   return compileDir.getExtraDir();
 }
예제 #5
0
 @Override
 public File getDeployDir() {
   return compileDir.getDeployDir();
 }
예제 #6
0
 @Override
 public File getWorkDir() {
   return compileDir.getWorkDir();
 }
예제 #7
0
  private boolean doCompile(TreeLogger compileLogger, CompileDir compileDir, Job job)
      throws UnableToCompleteException {

    job.onProgress("Loading modules");

    CompilerOptions loadOptions = new CompilerOptionsImpl(compileDir, inputModuleName, options);
    compilerContext = compilerContextBuilder.options(loadOptions).build();

    ModuleDef module = loadModule(compileLogger);
    if (!Compiler.maybeRestrictProperties(compileLogger, module, loadOptions.getProperties())) {
      return false;
    }

    // We need to generate the stub before restricting permutations
    String recompileJs = generateModuleRecompileJs(module, compileLogger);

    Map<String, String> bindingProperties =
        restrictPermutations(compileLogger, module, job.getBindingProperties());

    // Propagates module rename.
    String newModuleName = module.getName();
    outputModuleName.set(newModuleName);

    // Check if we can skip the compile altogether.
    InputSummary input = new InputSummary(bindingProperties, module);
    if (input.equals(lastBuildInput)) {
      compileLogger.log(Type.INFO, "skipped compile because no input files have changed");
      job.setCompileStrategy(CompileStrategy.SKIPPED);
      return true;
    }
    // Force a recompile if we don't succeed.
    lastBuildInput = null;

    job.onProgress("Compiling");
    // TODO: use speed tracer to get more compiler events?

    CompilerOptions runOptions = new CompilerOptionsImpl(compileDir, newModuleName, options);
    compilerContext = compilerContextBuilder.options(runOptions).build();

    MinimalRebuildCache minimalRebuildCache = new NullRebuildCache();
    if (options.isIncrementalCompileEnabled()) {
      // Returns a copy of the intended cache, which is safe to modify in this compile.
      minimalRebuildCache = minimalRebuildCacheManager.getCache(inputModuleName, bindingProperties);
    }
    job.setCompileStrategy(
        minimalRebuildCache.isPopulated() ? CompileStrategy.INCREMENTAL : CompileStrategy.FULL);

    boolean success = new Compiler(runOptions, minimalRebuildCache).run(compileLogger, module);
    if (success) {
      publishedCompileDir = compileDir;
      lastBuildInput = input;
      if (options.isIncrementalCompileEnabled()) {
        minimalRebuildCacheManager.putCache(
            inputModuleName, bindingProperties, minimalRebuildCache);
      }
      String moduleName = outputModuleName.get();
      writeRecompileNoCacheJs(
          new File(publishedCompileDir.getWarDir(), moduleName),
          moduleName,
          recompileJs,
          compileLogger);
      if (launcherDir != null) {
        launcherDir.update(module, compileDir, compileLogger);
      }
    }

    return success;
  }