Ejemplo n.º 1
0
  private static void doCompile(
      @NotNull MessageCollector messageCollector,
      @NotNull OutputSink sink,
      @NotNull Module module,
      @NotNull CompilerEnvironment environment,
      VirtualFile[] files) {
    List<File> srcFiles =
        ContainerUtil.map(
            files,
            new Function<VirtualFile, File>() {
              @Override
              public File fun(VirtualFile file) {
                return new File(file.getPath());
              }
            });
    List<String> libraryFiles = getLibraryFiles(module);
    File outDir = environment.getOutput();
    File outFile = new File(outDir, module.getName() + ".js");

    OutputItemsCollectorImpl outputItemsCollector = new OutputItemsCollectorImpl();

    Project project = module.getProject();
    CommonCompilerArguments commonArguments =
        KotlinCommonCompilerArgumentsHolder.getInstance(project).getSettings();
    K2JSCompilerArguments k2jsArguments =
        Kotlin2JsCompilerArgumentsHolder.getInstance(project).getSettings();
    CompilerSettings compilerSettings = KotlinCompilerSettings.getInstance(project).getSettings();

    KotlinCompilerRunner.runK2JsCompiler(
        commonArguments,
        k2jsArguments,
        compilerSettings,
        messageCollector,
        environment,
        outputItemsCollector,
        srcFiles,
        libraryFiles,
        outFile);

    TranslatingCompilerUtils.reportOutputs(sink, environment.getOutput(), outputItemsCollector);
  }
Ejemplo n.º 2
0
  @Override
  public void compile(
      CompileContext context, Chunk<Module> moduleChunk, VirtualFile[] files, OutputSink sink) {
    if (files.length == 0) {
      return;
    }

    Module module = getModule(context, moduleChunk);
    if (module == null) {
      return;
    }

    MessageCollector messageCollector = new MessageCollectorAdapter(context);

    CompilerEnvironment environment =
        TranslatingCompilerUtils.getEnvironmentFor(context, module, /*tests = */ false);
    if (!environment.success()) {
      environment.reportErrorsTo(messageCollector);
      return;
    }

    doCompile(messageCollector, sink, module, environment, files);
  }