Module script loading separated from module compilation
This commit is contained in:
@@ -128,7 +128,7 @@ public class BytecodeCompiler {
|
||||
|
||||
|
||||
/**
|
||||
* {@code CompileEnvironment#compileModuleScript} wrapper.
|
||||
* {@code CompileEnvironment#compileModules} wrapper.
|
||||
*
|
||||
* @param module compilation module file
|
||||
* @param jar compilation destination jar
|
||||
@@ -139,7 +139,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);
|
||||
boolean success = KotlinToJVMBytecodeCompiler.compileModuleScript(env, module, jar, null, includeRuntime);
|
||||
boolean success = KotlinToJVMBytecodeCompiler.compileModules(env, module, jar, null, includeRuntime);
|
||||
if ( ! success ) {
|
||||
throw new CompileEnvironmentException( errorMessage( module, false ));
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ import com.google.common.collect.Multimap;
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.sampullara.cli.Args;
|
||||
import jet.modules.Module;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.compiler.*;
|
||||
import org.jetbrains.jet.compiler.messages.CompilerMessageLocation;
|
||||
@@ -152,9 +153,10 @@ public class KotlinCompiler {
|
||||
|
||||
boolean noErrors;
|
||||
if (arguments.module != null) {
|
||||
noErrors = KotlinToJVMBytecodeCompiler.compileModuleScript(configuration,
|
||||
arguments.module, arguments.jar, arguments.outputDir,
|
||||
arguments.includeRuntime);
|
||||
List<Module> modules = CompileEnvironmentUtil.loadModuleScript(arguments.module, configuration.getMessageCollector());
|
||||
noErrors = KotlinToJVMBytecodeCompiler.compileModules(configuration, modules,
|
||||
arguments.module, arguments.jar, arguments.outputDir,
|
||||
arguments.includeRuntime);
|
||||
}
|
||||
else {
|
||||
// TODO ideally we'd unify to just having a single field that supports multiple files/dirs
|
||||
|
||||
@@ -78,10 +78,6 @@ public class CompileEnvironmentUtil {
|
||||
return null;
|
||||
}
|
||||
|
||||
//public static void ensureRuntime(@NotNull JetCoreEnvironment env) {
|
||||
// ensureJdkRuntime(env);
|
||||
//}
|
||||
|
||||
public static void ensureKotlinRuntime(JetCoreEnvironment env) {
|
||||
if (JavaPsiFacade.getInstance(env.getProject()).findClass("jet.JetObject", GlobalSearchScope.allScope(env.getProject())) == null) {
|
||||
// TODO: prepend
|
||||
@@ -151,16 +147,7 @@ public class CompileEnvironmentUtil {
|
||||
}
|
||||
}
|
||||
|
||||
//private CompileEnvironment copyEnvironment(boolean verbose) {
|
||||
// CompileEnvironment compileEnvironment = new CompileEnvironment(messageRenderer, verbose, compilerDependencies);
|
||||
// compileEnvironment.setIgnoreErrors(ignoreErrors);
|
||||
// compileEnvironment.setErrorStream(errorStream);
|
||||
// // copy across any compiler plugins
|
||||
// compileEnvironment.getEnvironment().getCompilerPlugins().addAll(environment.getCompilerPlugins());
|
||||
// return compileEnvironment;
|
||||
//}
|
||||
//
|
||||
public static List<Module> loadModuleScript(String moduleFile, MessageCollector messageCollector) {
|
||||
public static List<Module> loadModuleScript(String moduleScriptFile, MessageCollector messageCollector) {
|
||||
Disposable disposable = new Disposable() {
|
||||
@Override
|
||||
public void dispose() {
|
||||
@@ -170,7 +157,7 @@ public class CompileEnvironmentUtil {
|
||||
CompilerDependencies dependencies = CompilerDependencies.compilerDependenciesForProduction(CompilerSpecialMode.REGULAR);
|
||||
JetCoreEnvironment scriptEnvironment = new JetCoreEnvironment(disposable, dependencies);
|
||||
ensureRuntime(scriptEnvironment, dependencies);
|
||||
scriptEnvironment.addSources(moduleFile);
|
||||
scriptEnvironment.addSources(moduleScriptFile);
|
||||
|
||||
GenerationState generationState = KotlinToJVMBytecodeCompiler
|
||||
.analyzeAndGenerate(new CompileEnvironmentConfiguration(scriptEnvironment, dependencies, messageCollector), false);
|
||||
@@ -178,9 +165,17 @@ public class CompileEnvironmentUtil {
|
||||
return null;
|
||||
}
|
||||
|
||||
List<Module> modules = runDefineModules(dependencies, moduleFile, generationState.getFactory());
|
||||
List<Module> modules = runDefineModules(dependencies, moduleScriptFile, generationState.getFactory());
|
||||
|
||||
Disposer.dispose(disposable);
|
||||
|
||||
if (modules == null) {
|
||||
throw new CompileEnvironmentException("Module script " + moduleScriptFile + " compilation failed");
|
||||
}
|
||||
|
||||
if (modules.isEmpty()) {
|
||||
throw new CompileEnvironmentException("No modules where defined by " + moduleScriptFile);
|
||||
}
|
||||
return modules;
|
||||
}
|
||||
|
||||
|
||||
@@ -98,22 +98,15 @@ public class KotlinToJVMBytecodeCompiler {
|
||||
return generationState.getFactory();
|
||||
}
|
||||
|
||||
public static boolean compileModuleScript(
|
||||
public static boolean compileModules(
|
||||
CompileEnvironmentConfiguration configuration,
|
||||
|
||||
@NotNull List<Module> modules,
|
||||
|
||||
@NotNull String moduleScriptFile,
|
||||
@Nullable String jarPath,
|
||||
@Nullable String outputDir,
|
||||
boolean jarRuntime) {
|
||||
List<Module> modules = CompileEnvironmentUtil.loadModuleScript(moduleScriptFile, configuration.getMessageCollector());
|
||||
|
||||
if (modules == null) {
|
||||
throw new CompileEnvironmentException("Module script " + moduleScriptFile + " compilation failed");
|
||||
}
|
||||
|
||||
if (modules.isEmpty()) {
|
||||
throw new CompileEnvironmentException("No modules where defined by " + moduleScriptFile);
|
||||
}
|
||||
|
||||
final String directory = new File(moduleScriptFile).getParent();
|
||||
for (Module moduleBuilder : modules) {
|
||||
|
||||
Reference in New Issue
Block a user