diff --git a/compiler/cli/src/org/jetbrains/jet/cli/js/K2JSCompiler.java b/compiler/cli/src/org/jetbrains/jet/cli/js/K2JSCompiler.java index 44418e9fb9a..a8b71d9e984 100644 --- a/compiler/cli/src/org/jetbrains/jet/cli/js/K2JSCompiler.java +++ b/compiler/cli/src/org/jetbrains/jet/cli/js/K2JSCompiler.java @@ -65,21 +65,15 @@ public class K2JSCompiler extends CLICompiler sourceFiles; - @Override public boolean isHelp() { return help; @@ -84,10 +81,7 @@ public class K2JSCompilerArguments extends CompilerArguments { @Override public String getSrc() { - if (sourceFiles != null) { - return sourceFiles.toString(); - } - return srcdir; + throw new IllegalStateException(); } public MainCallParameters createMainCallParameters() { diff --git a/idea/src/org/jetbrains/jet/plugin/compiler/K2JSCompiler.java b/idea/src/org/jetbrains/jet/plugin/compiler/K2JSCompiler.java index 391e97e5908..bf4595c1f62 100644 --- a/idea/src/org/jetbrains/jet/plugin/compiler/K2JSCompiler.java +++ b/idea/src/org/jetbrains/jet/plugin/compiler/K2JSCompiler.java @@ -117,16 +117,9 @@ public final class K2JSCompiler implements TranslatingCompiler { @NotNull private static Integer doExec(@NotNull CompileContext context, @NotNull CompilerEnvironment environment, @NotNull PrintStream out, @NotNull Module module) throws Exception { - VirtualFile[] roots = ModuleRootManager.getInstance(module).getSourceRoots(); - if (roots.length != 1) { - context.addMessage(CompilerMessageCategory.ERROR, "K2JSCompiler does not support multiple module source roots.", null, -1, -1); - return -1; - } - VirtualFile outDir = context.getModuleOutputDirectory(module); String outFile = outDir == null ? null : outDir.getPath() + "/" + module.getName() + ".js"; - - String[] commandLineArgs = constructArguments(module, outFile, roots[0]); + String[] commandLineArgs = constructArguments(module, outFile); Object rc = invokeExecMethod(environment, out, context, commandLineArgs, "org.jetbrains.jet.cli.js.K2JSCompiler"); if (outDir != null && !ApplicationManager.getApplication().isUnitTestMode()) { @@ -136,15 +129,16 @@ public final class K2JSCompiler implements TranslatingCompiler { } @NotNull - private static String[] constructArguments(@NotNull Module module, @Nullable String outFile, @NotNull VirtualFile srcDir) { + private static String[] constructArguments(@NotNull Module module, @Nullable String outFile) { ArrayList args = Lists.newArrayList("-tags", "-verbose", "-version", "-mainCall", "mainWithArgs"); - addPathToSourcesDir(args, srcDir); + addPathToSourcesDir(module, args); addOutputPath(outFile, args); addLibLocationAndTarget(module, args); return ArrayUtil.toStringArray(args); } // we cannot use OrderEnumerator because it has critical bug — try https://gist.github.com/2953261, processor will never be called for module dependency + // we don't use context.getCompileScope().getAffectedModules() because we want to know about linkage type (well, we ignore scope right now, but in future...) private static void collectModuleDependencies(Module dependentModule, Set modules) { for (OrderEntry entry : ModuleRootManager.getInstance(dependentModule).getOrderEntries()) { if (entry instanceof ModuleOrderEntry) { @@ -165,6 +159,11 @@ public final class K2JSCompiler implements TranslatingCompiler { } } + private static VirtualFile[] getSourceFiles(@NotNull Module module) { + return CompilerManager.getInstance(module.getProject()).createModuleCompileScope(module, false) + .getFiles(JetFileType.INSTANCE, true); + } + private static void addLibLocationAndTarget(@NotNull Module module, @NotNull ArrayList args) { Pair libLocationAndTarget = JsModuleDetector.getLibLocationAndTargetForProject(module); @@ -176,9 +175,8 @@ public final class K2JSCompiler implements TranslatingCompiler { if (!modules.isEmpty()) { for (Module dependency : modules) { sb.append('@').append(dependency.getName()).append(','); - VirtualFile[] files = CompilerManager.getInstance(module.getProject()).createModuleCompileScope(dependency, false) - .getFiles(JetFileType.INSTANCE, true); - for (VirtualFile file : files) { + + for (VirtualFile file : getSourceFiles(dependency)) { sb.append(file.getPath()).append(','); } } @@ -206,10 +204,19 @@ public final class K2JSCompiler implements TranslatingCompiler { } } - private static void addPathToSourcesDir(@NotNull ArrayList args, @NotNull VirtualFile srcDir) { - String srcPath = srcDir.getPath(); - args.add("-srcdir"); - args.add(srcPath); + private static void addPathToSourcesDir(@NotNull Module module, @NotNull ArrayList args) { + args.add("-sourceFiles"); + + StringBuilder sb = StringBuilderSpinAllocator.alloc(); + try { + for (VirtualFile file : getSourceFiles(module)) { + sb.append(file.getPath()).append(','); + } + args.add(sb.substring(0, sb.length() - 1)); + } + finally { + StringBuilderSpinAllocator.dispose(sb); + } } private static void addOutputPath(@Nullable String outFile, @NotNull ArrayList args) { diff --git a/js/js.tests/test/org/jetbrains/k2js/test/semantics/StdLibTestSupport.java b/js/js.tests/test/org/jetbrains/k2js/test/semantics/StdLibTestSupport.java index 6c2f14ba2ad..1381212893f 100644 --- a/js/js.tests/test/org/jetbrains/k2js/test/semantics/StdLibTestSupport.java +++ b/js/js.tests/test/org/jetbrains/k2js/test/semantics/StdLibTestSupport.java @@ -79,7 +79,7 @@ abstract class StdLibTestSupport extends SingleFileTranslationTest { K2JSCompiler compiler = new K2JSCompiler(); K2JSCompilerArguments arguments = new K2JSCompilerArguments(); arguments.outputFile = getOutputFilePath(getTestName(false) + ".compiler.kt", version); - arguments.sourceFiles = files; + arguments.sourceFiles = files.toArray(new String[files.size()]); arguments.verbose = true; System.out.println("Compiling with version: " + version + " to: " + arguments.outputFile); ExitCode answer = compiler.exec(System.out, arguments);