Rename CompileEnvironmentConfiguration. Drop ArgsUtil class. Add CompilerSpecialMode.JS.
This commit is contained in:
@@ -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<Module> modules = CompileEnvironmentUtil.loadModuleScript(module, env.getMessageCollector());
|
||||
File directory = new File(module).getParentFile();
|
||||
boolean success = KotlinToJVMBytecodeCompiler.compileModules(env, modules, directory, jar, null, includeRuntime);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -33,11 +33,11 @@ import static org.jetbrains.jet.cli.common.ExitCode.OK;
|
||||
/**
|
||||
* @author Pavel Talanov
|
||||
*/
|
||||
public abstract class CLICompiler<CLArgs extends CompilerArguments, CEConf extends CompileEnvironmentConfig> {
|
||||
public abstract class CLICompiler<A extends CompilerArguments, C extends CompileEnvironmentConfiguration> {
|
||||
|
||||
@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<CLArgs extends CompilerArguments, CEConf exten
|
||||
/**
|
||||
* Returns true if the arguments can be parsed correctly
|
||||
*/
|
||||
protected boolean parseArguments(@NotNull PrintStream errStream, @NotNull CLArgs arguments, @NotNull String[] args) {
|
||||
protected boolean parseArguments(@NotNull PrintStream errStream, @NotNull A arguments, @NotNull String[] args) {
|
||||
try {
|
||||
Args.parse(arguments, args);
|
||||
return true;
|
||||
@@ -66,26 +66,40 @@ public abstract class CLICompiler<CLArgs extends CompilerArguments, CEConf exten
|
||||
* Allow derived classes to add additional command line arguments
|
||||
*/
|
||||
protected void usage(@NotNull PrintStream target) {
|
||||
ArgsUtil.printUsage(target, createArguments());
|
||||
// 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(createArguments());
|
||||
}
|
||||
finally {
|
||||
System.setErr(oldErr);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Strategy method to configure the environment, allowing compiler
|
||||
* based tools to customise their own plugins
|
||||
*/
|
||||
protected void configureEnvironment(@NotNull CEConf configuration, @NotNull CLArgs arguments) {
|
||||
//TODO: add parameter annotations when KT-1863 is resolved
|
||||
protected void configureEnvironment(C configuration, A arguments) {
|
||||
List<CompilerPlugin> 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<CLArgs extends CompilerArguments, CEConf exten
|
||||
|
||||
//TODO: can't declare parameters as not null due to KT-1863
|
||||
@NotNull
|
||||
protected abstract ExitCode doExecute(PrintStream stream, CLArgs arguments, MessageRenderer renderer);
|
||||
protected abstract ExitCode doExecute(PrintStream stream, A arguments, MessageRenderer renderer);
|
||||
|
||||
@NotNull
|
||||
private MessageRenderer getMessageRenderer(@NotNull CLArgs arguments) {
|
||||
private MessageRenderer getMessageRenderer(@NotNull A arguments) {
|
||||
return arguments.isTags() ? MessageRenderer.TAGS : MessageRenderer.PLAIN;
|
||||
}
|
||||
|
||||
protected void printVersionIfNeeded(@NotNull PrintStream errStream,
|
||||
@NotNull CLArgs arguments,
|
||||
@NotNull A arguments,
|
||||
@NotNull MessageRenderer messageRenderer) {
|
||||
if (arguments.isVersion()) {
|
||||
String versionMessage = messageRenderer.render(CompilerMessageSeverity.INFO,
|
||||
|
||||
+2
-2
@@ -26,7 +26,7 @@ import java.util.List;
|
||||
/**
|
||||
* @author Pavel Talanov
|
||||
*/
|
||||
public abstract class CompileEnvironmentConfig {
|
||||
public abstract class CompileEnvironmentConfiguration {
|
||||
|
||||
@NotNull
|
||||
private final MessageCollector messageCollector;
|
||||
@@ -38,7 +38,7 @@ public abstract class CompileEnvironmentConfig {
|
||||
*
|
||||
* @see Disposer
|
||||
*/
|
||||
public CompileEnvironmentConfig(@NotNull MessageCollector messageCollector) {
|
||||
public CompileEnvironmentConfiguration(@NotNull MessageCollector messageCollector) {
|
||||
this.messageCollector = messageCollector;
|
||||
}
|
||||
|
||||
@@ -18,13 +18,13 @@ package org.jetbrains.jet.cli.js;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* @author Pavel Talanov
|
||||
*/
|
||||
public class K2JSCompileEnvironmentConfiguration extends CompileEnvironmentConfig {
|
||||
public class K2JSCompileEnvironmentConfiguration extends CompileEnvironmentConfiguration {
|
||||
/**
|
||||
* NOTE: It's very important to call dispose for every object of this class or there will be memory leaks.
|
||||
*
|
||||
|
||||
@@ -25,7 +25,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.cli.common.CLICompiler;
|
||||
import org.jetbrains.jet.cli.common.ExitCode;
|
||||
import org.jetbrains.jet.cli.common.messages.*;
|
||||
import org.jetbrains.jet.cli.jvm.compiler.CompileEnvironmentConfiguration;
|
||||
import org.jetbrains.jet.cli.jvm.compiler.K2JVMCompileEnvironmentConfiguration;
|
||||
import org.jetbrains.jet.cli.jvm.compiler.CompileEnvironmentUtil;
|
||||
import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment;
|
||||
import org.jetbrains.jet.cli.jvm.compiler.KotlinToJVMBytecodeCompiler;
|
||||
@@ -45,7 +45,7 @@ import static org.jetbrains.jet.cli.common.ExitCode.*;
|
||||
* @author alex.tkachman
|
||||
*/
|
||||
@SuppressWarnings("UseOfSystemOutOrSystemErr")
|
||||
public class K2JVMCompiler extends CLICompiler<K2JVMCompilerArguments, CompileEnvironmentConfiguration> {
|
||||
public class K2JVMCompiler extends CLICompiler<K2JVMCompilerArguments, K2JVMCompileEnvironmentConfiguration> {
|
||||
|
||||
public static void main(String... args) {
|
||||
doMain(new K2JVMCompiler(), args);
|
||||
@@ -89,8 +89,8 @@ public class K2JVMCompiler extends CLICompiler<K2JVMCompilerArguments, CompileEn
|
||||
Disposable rootDisposable = CompileEnvironmentUtil.createMockDisposable();
|
||||
|
||||
JetCoreEnvironment environment = JetCoreEnvironment.getCoreEnvironmentForJVM(rootDisposable, dependencies);
|
||||
CompileEnvironmentConfiguration configuration =
|
||||
new CompileEnvironmentConfiguration(environment, dependencies, messageCollector);
|
||||
K2JVMCompileEnvironmentConfiguration configuration =
|
||||
new K2JVMCompileEnvironmentConfiguration(environment, messageCollector);
|
||||
|
||||
messageCollector.report(CompilerMessageSeverity.LOGGING, "Configuring the compilation environment",
|
||||
CompilerMessageLocation.NO_LOCATION);
|
||||
@@ -175,16 +175,16 @@ public class K2JVMCompiler extends CLICompiler<K2JVMCompilerArguments, CompileEn
|
||||
|
||||
|
||||
@Override
|
||||
protected void configureEnvironment(@NotNull CompileEnvironmentConfiguration configuration,
|
||||
@NotNull K2JVMCompilerArguments arguments) {
|
||||
protected void configureEnvironment(K2JVMCompileEnvironmentConfiguration configuration, K2JVMCompilerArguments arguments) {
|
||||
super.configureEnvironment(configuration, arguments);
|
||||
|
||||
if (configuration.getEnvironment().getCompilerDependencies().getRuntimeJar() != null) {
|
||||
CompileEnvironmentUtil.addToClasspath(configuration.getEnvironment(), configuration.getEnvironment().getCompilerDependencies().getRuntimeJar());
|
||||
CompileEnvironmentUtil.addToClasspath(configuration.getEnvironment(),
|
||||
configuration.getEnvironment().getCompilerDependencies().getRuntimeJar());
|
||||
}
|
||||
|
||||
if (arguments.classpath != null) {
|
||||
final Iterable<String> classpath = Splitter.on(File.pathSeparatorChar).split(arguments.classpath);
|
||||
Iterable<String> classpath = Splitter.on(File.pathSeparatorChar).split(arguments.classpath);
|
||||
CompileEnvironmentUtil.addToClasspath(configuration.getEnvironment(), Iterables.toArray(classpath, String.class));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
+3
-12
@@ -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;
|
||||
}
|
||||
}
|
||||
+10
-10
@@ -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<Module> 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<String> 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();
|
||||
|
||||
+1
@@ -24,6 +24,7 @@ public enum CompilerSpecialMode {
|
||||
BUILTINS,
|
||||
JDK_HEADERS,
|
||||
STDLIB,
|
||||
JS
|
||||
;
|
||||
|
||||
public boolean includeJdkHeaders() {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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<PrintStream, Integer>() {
|
||||
@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) {
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user