diff --git a/build-tools/core/src/org/jetbrains/jet/buildtools/core/BytecodeCompiler.java b/build-tools/core/src/org/jetbrains/jet/buildtools/core/BytecodeCompiler.java index 79611687b46..8127a45ad66 100644 --- a/build-tools/core/src/org/jetbrains/jet/buildtools/core/BytecodeCompiler.java +++ b/build-tools/core/src/org/jetbrains/jet/buildtools/core/BytecodeCompiler.java @@ -42,17 +42,18 @@ public class BytecodeCompiler { /** - * Creates new instance of {@link org.jetbrains.jet.cli.jvm.compiler.CompileEnvironmentConfiguration} instance using the arguments specified. + * Creates new instance of {@link org.jetbrains.jet.cli.jvm.compiler.K2JVMCompileEnvironmentConfiguration} instance using the arguments specified. * * @param stdlib path to "kotlin-runtime.jar", only used if not null and not empty * @param classpath compilation classpath, only used if not null and not empty * * @return compile environment instance */ - private CompileEnvironmentConfiguration env( String stdlib, String[] classpath ) { + private K2JVMCompileEnvironmentConfiguration env( String stdlib, String[] classpath ) { CompilerDependencies dependencies = CompilerDependencies.compilerDependenciesForProduction(CompilerSpecialMode.REGULAR); JetCoreEnvironment environment = new JetCoreEnvironment(CompileEnvironmentUtil.createMockDisposable(), dependencies); - CompileEnvironmentConfiguration env = new CompileEnvironmentConfiguration(environment, MessageCollector.PLAIN_TEXT_TO_SYSTEM_ERR); + K2JVMCompileEnvironmentConfiguration + env = new K2JVMCompileEnvironmentConfiguration(environment, MessageCollector.PLAIN_TEXT_TO_SYSTEM_ERR); if (( stdlib != null ) && ( stdlib.trim().length() > 0 )) { File file = new File(stdlib); @@ -140,7 +141,7 @@ public class BytecodeCompiler { */ public void moduleToJar ( @NotNull String module, @NotNull String jar, boolean includeRuntime, @Nullable String stdlib, @Nullable String[] classpath ) { try { - CompileEnvironmentConfiguration env = env(stdlib, classpath); + K2JVMCompileEnvironmentConfiguration env = env(stdlib, classpath); List modules = CompileEnvironmentUtil.loadModuleScript(module, env.getMessageCollector()); File directory = new File(module).getParentFile(); boolean success = KotlinToJVMBytecodeCompiler.compileModules(env, modules, directory, jar, null, includeRuntime); diff --git a/compiler/cli/src/org/jetbrains/jet/cli/common/ArgsUtil.java b/compiler/cli/src/org/jetbrains/jet/cli/common/ArgsUtil.java deleted file mode 100644 index 1de92e6ed16..00000000000 --- a/compiler/cli/src/org/jetbrains/jet/cli/common/ArgsUtil.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright 2010-2012 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.jet.cli.common; - -import com.sampullara.cli.Args; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.jet.cli.jvm.K2JVMCompilerArguments; - -import java.io.PrintStream; - -/** - * @author Pavel Talanov - */ -public final class ArgsUtil { - - private ArgsUtil() { - } - - public static void printUsage(@NotNull PrintStream target, @NotNull CompilerArguments exampleInstance) { - // We should say something like - // Args.usage(target, K2JVMCompilerArguments.class); - // but currently cli-parser we are using does not support that - // a corresponding patch has been sent to the authors - // For now, we are using this: - PrintStream oldErr = System.err; - System.setErr(target); - try { - // TODO: use proper argv0 - Args.usage(exampleInstance); - } - finally { - System.setErr(oldErr); - } - } -} diff --git a/compiler/cli/src/org/jetbrains/jet/cli/common/CLICompiler.java b/compiler/cli/src/org/jetbrains/jet/cli/common/CLICompiler.java index 1cb04464717..1d298647dd3 100644 --- a/compiler/cli/src/org/jetbrains/jet/cli/common/CLICompiler.java +++ b/compiler/cli/src/org/jetbrains/jet/cli/common/CLICompiler.java @@ -33,11 +33,11 @@ import static org.jetbrains.jet.cli.common.ExitCode.OK; /** * @author Pavel Talanov */ -public abstract class CLICompiler { +public abstract class CLICompiler { @NotNull public ExitCode exec(@NotNull PrintStream errStream, @NotNull String... args) { - CLArgs arguments = createArguments(); + A arguments = createArguments(); if (!parseArguments(errStream, arguments, args)) { return INTERNAL_ERROR; } @@ -47,7 +47,7 @@ public abstract class CLICompiler plugins = arguments.getCompilerPlugins(); configuration.getCompilerPlugins().addAll(plugins); } @NotNull - protected abstract CLArgs createArguments(); + protected abstract A createArguments(); /** * Executes the compiler on the parsed arguments */ @NotNull - public ExitCode exec(final PrintStream errStream, CLArgs arguments) { + public ExitCode exec(final PrintStream errStream, A arguments) { if (arguments.isHelp()) { usage(errStream); return OK; @@ -104,15 +118,15 @@ public abstract class CLICompiler { +public class K2JVMCompiler extends CLICompiler { public static void main(String... args) { doMain(new K2JVMCompiler(), args); @@ -89,8 +89,8 @@ public class K2JVMCompiler extends CLICompiler classpath = Splitter.on(File.pathSeparatorChar).split(arguments.classpath); + Iterable classpath = Splitter.on(File.pathSeparatorChar).split(arguments.classpath); CompileEnvironmentUtil.addToClasspath(configuration.getEnvironment(), Iterables.toArray(classpath, String.class)); } } diff --git a/compiler/cli/src/org/jetbrains/jet/cli/jvm/compiler/CompileEnvironmentUtil.java b/compiler/cli/src/org/jetbrains/jet/cli/jvm/compiler/CompileEnvironmentUtil.java index eb69be0cb15..448ffd76bbb 100644 --- a/compiler/cli/src/org/jetbrains/jet/cli/jvm/compiler/CompileEnvironmentUtil.java +++ b/compiler/cli/src/org/jetbrains/jet/cli/jvm/compiler/CompileEnvironmentUtil.java @@ -62,7 +62,7 @@ public class CompileEnvironmentUtil { @Nullable public static File getUnpackedRuntimePath() { - URL url = CompileEnvironmentConfiguration.class.getClassLoader().getResource("jet/JetObject.class"); + URL url = K2JVMCompileEnvironmentConfiguration.class.getClassLoader().getResource("jet/JetObject.class"); if (url != null && url.getProtocol().equals("file")) { return new File(url.getPath()).getParentFile().getParentFile(); } @@ -71,7 +71,7 @@ public class CompileEnvironmentUtil { @Nullable public static File getRuntimeJarPath() { - URL url = CompileEnvironmentConfiguration.class.getClassLoader().getResource("jet/JetObject.class"); + URL url = K2JVMCompileEnvironmentConfiguration.class.getClassLoader().getResource("jet/JetObject.class"); if (url != null && url.getProtocol().equals("jar")) { String path = url.getPath(); return new File(path.substring(path.indexOf(":") + 1, path.indexOf("!/"))); @@ -163,7 +163,7 @@ public class CompileEnvironmentUtil { scriptEnvironment.addSources(moduleScriptFile); GenerationState generationState = KotlinToJVMBytecodeCompiler - .analyzeAndGenerate(new CompileEnvironmentConfiguration(scriptEnvironment, messageCollector), false); + .analyzeAndGenerate(new K2JVMCompileEnvironmentConfiguration(scriptEnvironment, messageCollector), false); if (generationState == null) { return null; } @@ -195,7 +195,7 @@ public class CompileEnvironmentUtil { } } else { - loader = new GeneratedClassLoader(factory, CompileEnvironmentConfiguration.class.getClassLoader()); + loader = new GeneratedClassLoader(factory, K2JVMCompileEnvironmentConfiguration.class.getClassLoader()); } try { Class namespaceClass = loader.loadClass(JvmAbi.PACKAGE_CLASS); diff --git a/compiler/cli/src/org/jetbrains/jet/cli/jvm/compiler/CompileEnvironmentConfiguration.java b/compiler/cli/src/org/jetbrains/jet/cli/jvm/compiler/K2JVMCompileEnvironmentConfiguration.java similarity index 67% rename from compiler/cli/src/org/jetbrains/jet/cli/jvm/compiler/CompileEnvironmentConfiguration.java rename to compiler/cli/src/org/jetbrains/jet/cli/jvm/compiler/K2JVMCompileEnvironmentConfiguration.java index 1f14e72818c..97dc704fd99 100644 --- a/compiler/cli/src/org/jetbrains/jet/cli/jvm/compiler/CompileEnvironmentConfiguration.java +++ b/compiler/cli/src/org/jetbrains/jet/cli/jvm/compiler/K2JVMCompileEnvironmentConfiguration.java @@ -18,36 +18,27 @@ package org.jetbrains.jet.cli.jvm.compiler; import com.intellij.openapi.util.Disposer; import org.jetbrains.annotations.NotNull; -import org.jetbrains.jet.cli.common.CompileEnvironmentConfig; +import org.jetbrains.jet.cli.common.CompileEnvironmentConfiguration; import org.jetbrains.jet.cli.common.messages.MessageCollector; -import org.jetbrains.jet.lang.resolve.java.CompilerDependencies; /** * @author abreslav */ -public class CompileEnvironmentConfiguration extends CompileEnvironmentConfig { +public class K2JVMCompileEnvironmentConfiguration extends CompileEnvironmentConfiguration { private final JetCoreEnvironment environment; - private final CompilerDependencies compilerDependencies; /** * NOTE: It's very important to call dispose for every object of this class or there will be memory leaks. * * @see Disposer */ - public CompileEnvironmentConfiguration(@NotNull JetCoreEnvironment environment, - @NotNull CompilerDependencies compilerDependencies, + public K2JVMCompileEnvironmentConfiguration(@NotNull JetCoreEnvironment environment, @NotNull MessageCollector messageCollector) { super(messageCollector); - this.compilerDependencies = compilerDependencies; this.environment = environment; } public JetCoreEnvironment getEnvironment() { return environment; } - - @NotNull - public CompilerDependencies getCompilerDependencies() { - return compilerDependencies; - } } diff --git a/compiler/cli/src/org/jetbrains/jet/cli/jvm/compiler/KotlinToJVMBytecodeCompiler.java b/compiler/cli/src/org/jetbrains/jet/cli/jvm/compiler/KotlinToJVMBytecodeCompiler.java index 57082240c07..2605ad66056 100644 --- a/compiler/cli/src/org/jetbrains/jet/cli/jvm/compiler/KotlinToJVMBytecodeCompiler.java +++ b/compiler/cli/src/org/jetbrains/jet/cli/jvm/compiler/KotlinToJVMBytecodeCompiler.java @@ -59,7 +59,7 @@ public class KotlinToJVMBytecodeCompiler { @Nullable public static ClassFileFactory compileModule( - CompileEnvironmentConfiguration configuration, + K2JVMCompileEnvironmentConfiguration configuration, Module moduleBuilder, File directory ) { @@ -82,7 +82,7 @@ public class KotlinToJVMBytecodeCompiler { } public static boolean compileModules( - CompileEnvironmentConfiguration configuration, + K2JVMCompileEnvironmentConfiguration configuration, @NotNull List modules, @@ -118,7 +118,7 @@ public class KotlinToJVMBytecodeCompiler { } private static boolean compileBunchOfSources( - CompileEnvironmentConfiguration configuration, + K2JVMCompileEnvironmentConfiguration configuration, String jar, String outputDir, boolean includeRuntime @@ -163,7 +163,7 @@ public class KotlinToJVMBytecodeCompiler { } public static boolean compileBunchOfSources( - CompileEnvironmentConfiguration configuration, + K2JVMCompileEnvironmentConfiguration configuration, String sourceFileOrDir, String jar, String outputDir, boolean includeRuntime) { configuration.getEnvironment().addSources(sourceFileOrDir); @@ -172,7 +172,7 @@ public class KotlinToJVMBytecodeCompiler { } public static boolean compileBunchOfSourceDirectories( - CompileEnvironmentConfiguration configuration, + K2JVMCompileEnvironmentConfiguration configuration, List sources, String jar, String outputDir, boolean includeRuntime) { for (String source : sources) { @@ -184,7 +184,7 @@ public class KotlinToJVMBytecodeCompiler { @Nullable public static ClassLoader compileText( - CompileEnvironmentConfiguration configuration, + K2JVMCompileEnvironmentConfiguration configuration, String code) { configuration.getEnvironment() .addSources(new LightVirtualFile("script" + LocalTimeCounter.currentTime() + ".kt", JetLanguage.INSTANCE, code)); @@ -197,13 +197,13 @@ public class KotlinToJVMBytecodeCompiler { } @Nullable - public static GenerationState analyzeAndGenerate(CompileEnvironmentConfiguration configuration) { + public static GenerationState analyzeAndGenerate(K2JVMCompileEnvironmentConfiguration configuration) { return analyzeAndGenerate(configuration, configuration.getEnvironment().getCompilerDependencies().getCompilerSpecialMode().isStubs()); } @Nullable public static GenerationState analyzeAndGenerate( - CompileEnvironmentConfiguration configuration, + K2JVMCompileEnvironmentConfiguration configuration, boolean stubs ) { AnalyzeExhaust exhaust = analyze(configuration, stubs); @@ -219,7 +219,7 @@ public class KotlinToJVMBytecodeCompiler { @Nullable private static AnalyzeExhaust analyze( - final CompileEnvironmentConfiguration configuration, + final K2JVMCompileEnvironmentConfiguration configuration, boolean stubs) { final JetCoreEnvironment environment = configuration.getEnvironment(); AnalyzerWithCompilerReport analyzerWithCompilerReport = new AnalyzerWithCompilerReport(configuration.getMessageCollector()); @@ -243,7 +243,7 @@ public class KotlinToJVMBytecodeCompiler { @NotNull private static GenerationState generate( - final CompileEnvironmentConfiguration configuration, + final K2JVMCompileEnvironmentConfiguration configuration, AnalyzeExhaust exhaust, boolean stubs) { JetCoreEnvironment environment = configuration.getEnvironment(); diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/CompilerSpecialMode.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/CompilerSpecialMode.java index a92c9abb47f..032682e5bbc 100644 --- a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/CompilerSpecialMode.java +++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/CompilerSpecialMode.java @@ -24,6 +24,7 @@ public enum CompilerSpecialMode { BUILTINS, JDK_HEADERS, STDLIB, + JS ; public boolean includeJdkHeaders() { diff --git a/compiler/tests/org/jetbrains/jet/codegen/CompileTextTest.java b/compiler/tests/org/jetbrains/jet/codegen/CompileTextTest.java index 0159244370e..1ea4d434873 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/CompileTextTest.java +++ b/compiler/tests/org/jetbrains/jet/codegen/CompileTextTest.java @@ -16,7 +16,7 @@ package org.jetbrains.jet.codegen; -import org.jetbrains.jet.cli.jvm.compiler.CompileEnvironmentConfiguration; +import org.jetbrains.jet.cli.jvm.compiler.K2JVMCompileEnvironmentConfiguration; import org.jetbrains.jet.cli.jvm.compiler.KotlinToJVMBytecodeCompiler; import org.jetbrains.jet.cli.common.messages.MessageCollector; @@ -27,7 +27,7 @@ public class CompileTextTest extends CodegenTestCase { public void testMe() throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException { createEnvironmentWithMockJdk(); String text = "import org.jetbrains.jet.codegen.CompileTextTest; fun x() = CompileTextTest()"; - CompileEnvironmentConfiguration configuration = new CompileEnvironmentConfiguration( + K2JVMCompileEnvironmentConfiguration configuration = new K2JVMCompileEnvironmentConfiguration( myEnvironment, MessageCollector.PLAIN_TEXT_TO_SYSTEM_ERR); configuration.getEnvironment().addToClasspathFromClassLoader(getClass().getClassLoader()); ClassLoader classLoader = KotlinToJVMBytecodeCompiler.compileText(configuration, text); diff --git a/compiler/tests/org/jetbrains/jet/codegen/TestlibTest.java b/compiler/tests/org/jetbrains/jet/codegen/TestlibTest.java index ff0dc1a0498..2bac15daeb9 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/TestlibTest.java +++ b/compiler/tests/org/jetbrains/jet/codegen/TestlibTest.java @@ -22,7 +22,7 @@ import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; import org.jetbrains.jet.codegen.forTestCompile.ForTestCompileRuntime; -import org.jetbrains.jet.cli.jvm.compiler.CompileEnvironmentConfiguration; +import org.jetbrains.jet.cli.jvm.compiler.K2JVMCompileEnvironmentConfiguration; import org.jetbrains.jet.cli.jvm.compiler.KotlinToJVMBytecodeCompiler; import org.jetbrains.jet.cli.common.messages.MessageCollector; import org.jetbrains.jet.lang.descriptors.ClassDescriptor; @@ -87,7 +87,7 @@ public class TestlibTest extends CodegenTestCase { myEnvironment.addSources(localFileSystem.findFileByPath(JetParsingTest.getTestDataDir() + "/../../libraries/kunit/src")); GenerationState generationState = KotlinToJVMBytecodeCompiler - .analyzeAndGenerate(new CompileEnvironmentConfiguration(myEnvironment, MessageCollector.PLAIN_TEXT_TO_SYSTEM_ERR), false); + .analyzeAndGenerate(new K2JVMCompileEnvironmentConfiguration(myEnvironment, MessageCollector.PLAIN_TEXT_TO_SYSTEM_ERR), false); if (generationState == null) { throw new RuntimeException("There were compilation errors"); diff --git a/idea/src/org/jetbrains/jet/plugin/compiler/K2JSCompiler.java b/idea/src/org/jetbrains/jet/plugin/compiler/K2JSCompiler.java index 31e3888b344..d85b92f8fa4 100644 --- a/idea/src/org/jetbrains/jet/plugin/compiler/K2JSCompiler.java +++ b/idea/src/org/jetbrains/jet/plugin/compiler/K2JSCompiler.java @@ -22,6 +22,7 @@ import com.intellij.openapi.compiler.CompilerMessageCategory; import com.intellij.openapi.compiler.TranslatingCompiler; import com.intellij.openapi.module.Module; import com.intellij.openapi.project.Project; +import com.intellij.openapi.roots.ModuleRootManager; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.util.Chunk; import jet.Function1; @@ -62,7 +63,7 @@ public final class K2JSCompiler implements TranslatingCompiler { return; } - Module module = moduleChunk.getNodes().iterator().next(); + final Module module = moduleChunk.getNodes().iterator().next(); final CompilerEnvironment environment = CompilerEnvironment.getEnvironmentFor(context, module, /*tests = */ false); if (!environment.success()) { environment.reportErrorsTo(context); @@ -73,7 +74,7 @@ public final class K2JSCompiler implements TranslatingCompiler { outputCompilerMessagesAndHandleExitCode(context, collector, new Function1() { @Override public Integer invoke(PrintStream stream) { - return execInProcess(context, environment, stream); + return execInProcess(context, environment, stream, module); } }); sink.add(environment.getOutput().getPath(), collector.getOutputs(), collector.getSources().toArray(VirtualFile.EMPTY_ARRAY)); @@ -81,11 +82,15 @@ public final class K2JSCompiler implements TranslatingCompiler { @NotNull private static Integer execInProcess(@NotNull CompileContext context, - @NotNull CompilerEnvironment environment, @NotNull PrintStream out) { + @NotNull CompilerEnvironment environment, @NotNull PrintStream out, @NotNull Module module) { try { - String[] commandLineArgs = {"-tags", "-verbose", "-version"}; - Object rc = invokeExecMethod(environment, out, context, commandLineArgs, - "org.jetbrains.jet.cli.js.K2JSCompiler"); + VirtualFile[] roots = ModuleRootManager.getInstance(module).getSourceRoots(); + if (roots.length != 1) { + context.addMessage(CompilerMessageCategory.ERROR, "K2JSCompiler does not support module source roots.", null, -1, -1); + return -1; + } + String[] commandLineArgs = {"-tags", "-verbose", "-version", "-srcdir", roots[0].getPath()}; + Object rc = invokeExecMethod(environment, out, context, commandLineArgs, "org.jetbrains.jet.cli.js.K2JSCompiler"); return CompilerUtils.getReturnCodeFromObject(rc); } catch (Throwable e) { diff --git a/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/KDocCompiler.kt b/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/KDocCompiler.kt index c56df78d72e..0f4fd7badbf 100644 --- a/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/KDocCompiler.kt +++ b/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/KDocCompiler.kt @@ -5,7 +5,7 @@ import java.io.PrintStream import org.jetbrains.jet.cli.jvm.K2JVMCompilerArguments import org.jetbrains.jet.cli.jvm.K2JVMCompiler import org.jetbrains.jet.cli.common.CLICompiler -import org.jetbrains.jet.cli.jvm.compiler.CompileEnvironmentConfiguration +import org.jetbrains.jet.cli.jvm.compiler.K2JVMCompileEnvironmentConfiguration import org.jetbrains.kotlin.doc.highlighter.HtmlCompilerPlugin import org.jetbrains.jet.cli.common.ExitCode