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 module compilation module file
|
||||||
* @param jar compilation destination jar
|
* @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 ) {
|
public void moduleToJar ( @NotNull String module, @NotNull String jar, boolean includeRuntime, @Nullable String stdlib, @Nullable String[] classpath ) {
|
||||||
try {
|
try {
|
||||||
CompileEnvironmentConfiguration env = env(stdlib, classpath);
|
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 ) {
|
if ( ! success ) {
|
||||||
throw new CompileEnvironmentException( errorMessage( module, false ));
|
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.Disposable;
|
||||||
import com.intellij.openapi.util.Disposer;
|
import com.intellij.openapi.util.Disposer;
|
||||||
import com.sampullara.cli.Args;
|
import com.sampullara.cli.Args;
|
||||||
|
import jet.modules.Module;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.jet.compiler.*;
|
import org.jetbrains.jet.compiler.*;
|
||||||
import org.jetbrains.jet.compiler.messages.CompilerMessageLocation;
|
import org.jetbrains.jet.compiler.messages.CompilerMessageLocation;
|
||||||
@@ -152,9 +153,10 @@ public class KotlinCompiler {
|
|||||||
|
|
||||||
boolean noErrors;
|
boolean noErrors;
|
||||||
if (arguments.module != null) {
|
if (arguments.module != null) {
|
||||||
noErrors = KotlinToJVMBytecodeCompiler.compileModuleScript(configuration,
|
List<Module> modules = CompileEnvironmentUtil.loadModuleScript(arguments.module, configuration.getMessageCollector());
|
||||||
arguments.module, arguments.jar, arguments.outputDir,
|
noErrors = KotlinToJVMBytecodeCompiler.compileModules(configuration, modules,
|
||||||
arguments.includeRuntime);
|
arguments.module, arguments.jar, arguments.outputDir,
|
||||||
|
arguments.includeRuntime);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// TODO ideally we'd unify to just having a single field that supports multiple files/dirs
|
// 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;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
//public static void ensureRuntime(@NotNull JetCoreEnvironment env) {
|
|
||||||
// ensureJdkRuntime(env);
|
|
||||||
//}
|
|
||||||
|
|
||||||
public static void ensureKotlinRuntime(JetCoreEnvironment env) {
|
public static void ensureKotlinRuntime(JetCoreEnvironment env) {
|
||||||
if (JavaPsiFacade.getInstance(env.getProject()).findClass("jet.JetObject", GlobalSearchScope.allScope(env.getProject())) == null) {
|
if (JavaPsiFacade.getInstance(env.getProject()).findClass("jet.JetObject", GlobalSearchScope.allScope(env.getProject())) == null) {
|
||||||
// TODO: prepend
|
// TODO: prepend
|
||||||
@@ -151,16 +147,7 @@ public class CompileEnvironmentUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//private CompileEnvironment copyEnvironment(boolean verbose) {
|
public static List<Module> loadModuleScript(String moduleScriptFile, MessageCollector messageCollector) {
|
||||||
// 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) {
|
|
||||||
Disposable disposable = new Disposable() {
|
Disposable disposable = new Disposable() {
|
||||||
@Override
|
@Override
|
||||||
public void dispose() {
|
public void dispose() {
|
||||||
@@ -170,7 +157,7 @@ public class CompileEnvironmentUtil {
|
|||||||
CompilerDependencies dependencies = CompilerDependencies.compilerDependenciesForProduction(CompilerSpecialMode.REGULAR);
|
CompilerDependencies dependencies = CompilerDependencies.compilerDependenciesForProduction(CompilerSpecialMode.REGULAR);
|
||||||
JetCoreEnvironment scriptEnvironment = new JetCoreEnvironment(disposable, dependencies);
|
JetCoreEnvironment scriptEnvironment = new JetCoreEnvironment(disposable, dependencies);
|
||||||
ensureRuntime(scriptEnvironment, dependencies);
|
ensureRuntime(scriptEnvironment, dependencies);
|
||||||
scriptEnvironment.addSources(moduleFile);
|
scriptEnvironment.addSources(moduleScriptFile);
|
||||||
|
|
||||||
GenerationState generationState = KotlinToJVMBytecodeCompiler
|
GenerationState generationState = KotlinToJVMBytecodeCompiler
|
||||||
.analyzeAndGenerate(new CompileEnvironmentConfiguration(scriptEnvironment, dependencies, messageCollector), false);
|
.analyzeAndGenerate(new CompileEnvironmentConfiguration(scriptEnvironment, dependencies, messageCollector), false);
|
||||||
@@ -178,9 +165,17 @@ public class CompileEnvironmentUtil {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Module> modules = runDefineModules(dependencies, moduleFile, generationState.getFactory());
|
List<Module> modules = runDefineModules(dependencies, moduleScriptFile, generationState.getFactory());
|
||||||
|
|
||||||
Disposer.dispose(disposable);
|
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;
|
return modules;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -98,22 +98,15 @@ public class KotlinToJVMBytecodeCompiler {
|
|||||||
return generationState.getFactory();
|
return generationState.getFactory();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean compileModuleScript(
|
public static boolean compileModules(
|
||||||
CompileEnvironmentConfiguration configuration,
|
CompileEnvironmentConfiguration configuration,
|
||||||
|
|
||||||
|
@NotNull List<Module> modules,
|
||||||
|
|
||||||
@NotNull String moduleScriptFile,
|
@NotNull String moduleScriptFile,
|
||||||
@Nullable String jarPath,
|
@Nullable String jarPath,
|
||||||
@Nullable String outputDir,
|
@Nullable String outputDir,
|
||||||
boolean jarRuntime) {
|
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();
|
final String directory = new File(moduleScriptFile).getParent();
|
||||||
for (Module moduleBuilder : modules) {
|
for (Module moduleBuilder : modules) {
|
||||||
|
|||||||
Reference in New Issue
Block a user