Support building many modules "as one": merging all the paths etc
This is for a workaround implementation of support for mutually dependent modules
This commit is contained in:
@@ -0,0 +1,17 @@
|
|||||||
|
package org.jetbrains.jet.cli.jvm.compiler
|
||||||
|
|
||||||
|
import jet.modules.Module
|
||||||
|
|
||||||
|
class ChunkAsOneModule(private val chunk: ModuleChunk) : Module {
|
||||||
|
override fun getModuleName(): String = "chunk" + chunk.getModules().map { it.getModuleName() }.toString()
|
||||||
|
|
||||||
|
override fun getOutputDirectory(): String {
|
||||||
|
throw UnsupportedOperationException("Each module in a chunk has its own output directory")
|
||||||
|
}
|
||||||
|
override fun getSourceFiles(): List<String> = chunk.getModules().flatMap { it.getSourceFiles() }
|
||||||
|
|
||||||
|
override fun getClasspathRoots(): List<String> = chunk.getModules().flatMap { it.getClasspathRoots() }
|
||||||
|
|
||||||
|
override fun getAnnotationsRoots(): List<String> = chunk.getModules().flatMap { it.getAnnotationsRoots() }
|
||||||
|
|
||||||
|
}
|
||||||
+13
-5
@@ -63,17 +63,20 @@ import java.util.List;
|
|||||||
|
|
||||||
public class KotlinToJVMBytecodeCompiler {
|
public class KotlinToJVMBytecodeCompiler {
|
||||||
|
|
||||||
|
private static final boolean COMPILE_CHUNK_AS_ONE_MODULE = true;
|
||||||
|
|
||||||
private KotlinToJVMBytecodeCompiler() {
|
private KotlinToJVMBytecodeCompiler() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public static ClassFileFactory compileModule(CompilerConfiguration configuration, Module module, File directory) {
|
public static ClassFileFactory compileModule(CompilerConfiguration configuration, Module module, File directory) {
|
||||||
if (module.getSourceFiles().isEmpty()) {
|
List<String> sourceFiles = module.getSourceFiles();
|
||||||
|
if (sourceFiles.isEmpty()) {
|
||||||
throw new CompileEnvironmentException("No source files where defined in module " + module.getModuleName());
|
throw new CompileEnvironmentException("No source files where defined in module " + module.getModuleName());
|
||||||
}
|
}
|
||||||
|
|
||||||
CompilerConfiguration compilerConfiguration = configuration.copy();
|
CompilerConfiguration compilerConfiguration = configuration.copy();
|
||||||
for (String sourceFile : module.getSourceFiles()) {
|
for (String sourceFile : sourceFiles) {
|
||||||
File source = new File(sourceFile);
|
File source = new File(sourceFile);
|
||||||
if (!source.isAbsolute()) {
|
if (!source.isAbsolute()) {
|
||||||
source = new File(directory, sourceFile);
|
source = new File(directory, sourceFile);
|
||||||
@@ -126,12 +129,16 @@ public class KotlinToJVMBytecodeCompiler {
|
|||||||
|
|
||||||
public static boolean compileModules(
|
public static boolean compileModules(
|
||||||
CompilerConfiguration configuration,
|
CompilerConfiguration configuration,
|
||||||
@NotNull final ModuleChunk modules,
|
@NotNull final ModuleChunk chunk,
|
||||||
@NotNull File directory,
|
@NotNull File directory,
|
||||||
@Nullable File jarPath,
|
@Nullable File jarPath,
|
||||||
boolean jarRuntime
|
boolean jarRuntime
|
||||||
) {
|
) {
|
||||||
for (Module module : modules.getModules()) {
|
List<Module> modules = chunk.getModules();
|
||||||
|
if (COMPILE_CHUNK_AS_ONE_MODULE && modules.size() > 1) {
|
||||||
|
modules = Collections.<Module>singletonList(new ChunkAsOneModule(chunk));
|
||||||
|
}
|
||||||
|
for (Module module : modules) {
|
||||||
ClassFileFactory moduleFactory = compileModule(configuration, module, directory);
|
ClassFileFactory moduleFactory = compileModule(configuration, module, directory);
|
||||||
if (moduleFactory == null) {
|
if (moduleFactory == null) {
|
||||||
return false;
|
return false;
|
||||||
@@ -141,7 +148,8 @@ public class KotlinToJVMBytecodeCompiler {
|
|||||||
@Override
|
@Override
|
||||||
public File getOutputDirectory(@NotNull Collection<File> sourceFiles) {
|
public File getOutputDirectory(@NotNull Collection<File> sourceFiles) {
|
||||||
for (File sourceFile : sourceFiles) {
|
for (File sourceFile : sourceFiles) {
|
||||||
Module module = modules.findModuleBySourceFile(sourceFile);
|
// Note that here we track original modules:
|
||||||
|
Module module = chunk.findModuleBySourceFile(sourceFile);
|
||||||
if (module != null) {
|
if (module != null) {
|
||||||
return new File(module.getOutputDirectory());
|
return new File(module.getOutputDirectory());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
<orderEntry type="library" scope="PROVIDED" name="intellij-core" level="project" />
|
<orderEntry type="library" scope="PROVIDED" name="intellij-core" level="project" />
|
||||||
<orderEntry type="module" module-name="util.runtime" exported="" />
|
<orderEntry type="module" module-name="util.runtime" exported="" />
|
||||||
<orderEntry type="module" module-name="Kotlin" exported="" />
|
<orderEntry type="module" module-name="Kotlin" exported="" />
|
||||||
|
<orderEntry type="library" exported="" name="kotlin-runtime" level="project" />
|
||||||
</component>
|
</component>
|
||||||
</module>
|
</module>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user