Got rid of creating JetCoreEnvironment which wont be used when compiling modules from module script.

This commit is contained in:
Evgeny Gerashchenko
2012-07-24 17:05:23 +04:00
parent 75ce5b3a1b
commit edb2e0e3b6
3 changed files with 16 additions and 11 deletions
@@ -57,6 +57,12 @@ public class BytecodeCompiler {
* @return compile environment instance
*/
private JetCoreEnvironment env(String stdlib, String[] classpath, String[] sourceRoots) {
CompilerConfiguration configuration = createConfiguration(stdlib, classpath, sourceRoots);
return new JetCoreEnvironment(CompileEnvironmentUtil.createMockDisposable(), configuration);
}
private CompilerConfiguration createConfiguration(String stdlib, String[] classpath, String[] sourceRoots) {
CompilerConfiguration configuration = new CompilerConfiguration();
configuration.add(CLASSPATH_KEY, PathUtil.findRtJar());
if ((stdlib != null) && (stdlib.trim().length() > 0)) {
@@ -83,8 +89,7 @@ public class BytecodeCompiler {
// lets register any compiler plugins
configuration.addAll(CLIConfigurationKeys.COMPILER_PLUGINS, getCompilerPlugins());
return new JetCoreEnvironment(CompileEnvironmentUtil.createMockDisposable(), configuration);
return configuration;
}
@@ -173,9 +178,9 @@ public class BytecodeCompiler {
for (Module m : modules) {
sourcesRoots.addAll(m.getSourceFiles());
}
JetCoreEnvironment env = env(stdlib, classpath, sourcesRoots.toArray(new String[0]));
CompilerConfiguration configuration = createConfiguration(stdlib, classpath, sourcesRoots.toArray(new String[0]));
File directory = new File(module).getParentFile();
boolean success = KotlinToJVMBytecodeCompiler.compileModules(env, modules, directory, new File(jar), null, includeRuntime);
boolean success = KotlinToJVMBytecodeCompiler.compileModules(configuration, modules, directory, new File(jar), null, includeRuntime);
if (!success) {
throw new CompileEnvironmentException(errorMessage(module, false));
}
@@ -93,7 +93,6 @@ public class K2JVMCompiler extends CLICompiler<K2JVMCompilerArguments> {
}
}
JetCoreEnvironment environment = JetCoreEnvironment.createCoreEnvironmentForJVM(rootDisposable, configuration);
boolean builtins = arguments.builtins;
configuration.put(JVMConfigurationKeys.SCRIPT_PARAMETERS, arguments.script
@@ -122,15 +121,17 @@ public class K2JVMCompiler extends CLICompiler<K2JVMCompilerArguments> {
List<Module> modules = CompileEnvironmentUtil.loadModuleScript(arguments.module, messageCollector);
messageCollector.setVerbose(oldVerbose);
File directory = new File(arguments.module).getParentFile();
noErrors = KotlinToJVMBytecodeCompiler.compileModules(environment, modules,
noErrors = KotlinToJVMBytecodeCompiler.compileModules(configuration, modules,
directory, jar, outputDir,
arguments.includeRuntime);
}
else if (arguments.script) {
List<String> scriptArgs = arguments.freeArgs.subList(1, arguments.freeArgs.size());
JetCoreEnvironment environment = JetCoreEnvironment.createCoreEnvironmentForJVM(rootDisposable, configuration);
noErrors = KotlinToJVMBytecodeCompiler.compileAndExecuteScript(environment, scriptArgs);
}
else {
JetCoreEnvironment environment = JetCoreEnvironment.createCoreEnvironmentForJVM(rootDisposable, configuration);
noErrors = KotlinToJVMBytecodeCompiler.compileBunchOfSources(environment, jar, outputDir, arguments.includeRuntime);
}
return noErrors ? OK : COMPILATION_ERROR;
@@ -73,13 +73,12 @@ public class KotlinToJVMBytecodeCompiler {
}
@Nullable
public static ClassFileFactory compileModule(JetCoreEnvironment environment, Module moduleBuilder, File directory) {
public static ClassFileFactory compileModule(CompilerConfiguration configuration, Module moduleBuilder, File directory) {
if (moduleBuilder.getSourceFiles().isEmpty()) {
throw new CompileEnvironmentException("No source files where defined");
}
// TODO creating environment copy each time - not good. original environment shouldn't be passed at all
CompilerConfiguration compilerConfiguration = environment.getConfiguration().copy();
CompilerConfiguration compilerConfiguration = configuration.copy();
for (String sourceFile : moduleBuilder.getSourceFiles()) {
File source = new File(sourceFile);
if (!source.isAbsolute()) {
@@ -121,7 +120,7 @@ public class KotlinToJVMBytecodeCompiler {
}
public static boolean compileModules(
JetCoreEnvironment environment,
CompilerConfiguration configuration,
@NotNull List<Module> modules,
@NotNull File directory,
@Nullable File jarPath,
@@ -129,7 +128,7 @@ public class KotlinToJVMBytecodeCompiler {
boolean jarRuntime) {
for (Module moduleBuilder : modules) {
ClassFileFactory moduleFactory = compileModule(environment, moduleBuilder, directory);
ClassFileFactory moduleFactory = compileModule(configuration, moduleBuilder, directory);
if (moduleFactory == null) {
return false;
}