private Map<Module, List<VirtualFile>> buildModuleToFilesMap(
     final List<VirtualFile> filesToCompile) {
   if (myChunk.getNodes().size() == 1) {
     return Collections.singletonMap(
         myChunk.getNodes().iterator().next(), Collections.unmodifiableList(filesToCompile));
   }
   return CompilerUtil.buildModuleToFilesMap(myCompileContext, filesToCompile);
 }
 @Nullable
 private static Module getModule(
     @NotNull CompileContext context, @NotNull Chunk<Module> moduleChunk) {
   if (moduleChunk.getNodes().size() != 1) {
     context.addMessage(
         CompilerMessageCategory.ERROR,
         "K2JSCompiler does not support multiple modules.",
         null,
         -1,
         -1);
     return null;
   }
   return moduleChunk.getNodes().iterator().next();
 }
 private String getOutputPath(CompileContext context, Chunk<Module> moduleChunk) {
   if (moduleChunk.getNodes().isEmpty()) {
     context.addMessage(
         CompilerMessageCategory.WARNING,
         "No module defined, running application might not function properly.",
         null,
         -1,
         -1);
     return CompilerPathsManager.getInstance(project).getCompilerOutput().getPath() + "/go-bins";
   } else {
     // TODO This is a hack to keep GoMakefileCompiler compatible with the way Runner expects
     // binaries, we
     // use any module assuming the path is the same for all
     Module firstModule = moduleChunk.getNodes().iterator().next();
     return context.getModuleOutputDirectory(firstModule).getPath() + "/go-bins";
   }
 }
Exemple #4
0
  private void doCompile(
      CompileContext compileContext,
      Chunk<Module> moduleChunk,
      List<VirtualFile> files,
      Module module,
      boolean tests) {
    if (files.isEmpty()) return;

    VirtualFile mainOutput = compileContext.getModuleOutputDirectory(module);
    final VirtualFile outputDir =
        tests ? compileContext.getModuleOutputDirectoryForTests(module) : mainOutput;
    if (outputDir == null) {
      compileContext.addMessage(ERROR, "[Internal Error] No output directory", "", -1, -1);
      return;
    }

    File kotlinHome = PathUtil.getDefaultCompilerPath();
    if (kotlinHome == null) {
      compileContext.addMessage(
          ERROR, "Cannot find kotlinc home. Make sure plugin is properly installed", "", -1, -1);
      return;
    }

    ModuleChunk chunk =
        new ModuleChunk(
            (CompileContextEx) compileContext,
            moduleChunk,
            Collections.<Module, List<VirtualFile>>emptyMap());
    String moduleName = moduleChunk.getNodes().iterator().next().getName();

    // Filter the output we are writing to
    Set<VirtualFile> outputDirectoriesToFilter =
        Sets.newHashSet(compileContext.getModuleOutputDirectoryForTests(module));
    if (!tests) {
      outputDirectoriesToFilter.add(compileContext.getModuleOutputDirectory(module));
    }
    CharSequence script =
        generateModuleScript(
            moduleName, chunk, files, tests, mainOutput, outputDirectoriesToFilter);

    File scriptFile = new File(path(outputDir), "script.kts");
    try {
      FileUtil.writeToFile(scriptFile, script.toString());
    } catch (IOException e) {
      compileContext.addMessage(
          ERROR,
          "[Internal Error] Cannot write script to " + scriptFile.getAbsolutePath(),
          "",
          -1,
          -1);
      return;
    }

    if (RUN_OUT_OF_PROCESS) {
      runOutOfProcess(compileContext, outputDir, kotlinHome, scriptFile);
    } else {
      runInProcess(compileContext, outputDir, kotlinHome, scriptFile);
    }

    //        compileContext.addMessage(INFORMATION, "Generated module script:\n" +
    // script.toString(), "file://" + path(mainOutput), 0, 1);
  }