do not write main if there's more than one main
This commit is contained in:
+17
-8
@@ -131,6 +131,22 @@ public class KotlinToJVMBytecodeCompiler {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
private static FqName findMainClass(@NotNull List<JetFile> files) {
|
||||||
|
FqName mainClass = null;
|
||||||
|
for (JetFile file : files) {
|
||||||
|
if (JetMainDetector.hasMain(file.getDeclarations())) {
|
||||||
|
if (mainClass != null) {
|
||||||
|
// more than one main
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
FqName fqName = JetPsiUtil.getFQName(file);
|
||||||
|
mainClass = fqName.child(Name.identifier(JvmAbi.PACKAGE_CLASS));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return mainClass;
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean compileBunchOfSources(
|
public static boolean compileBunchOfSources(
|
||||||
K2JVMCompileEnvironmentConfiguration configuration,
|
K2JVMCompileEnvironmentConfiguration configuration,
|
||||||
@Nullable File jar,
|
@Nullable File jar,
|
||||||
@@ -138,14 +154,7 @@ public class KotlinToJVMBytecodeCompiler {
|
|||||||
boolean script,
|
boolean script,
|
||||||
boolean includeRuntime
|
boolean includeRuntime
|
||||||
) {
|
) {
|
||||||
FqName mainClass = null;
|
FqName mainClass = findMainClass(configuration.getEnvironment().getSourceFiles());
|
||||||
for (JetFile file : configuration.getEnvironment().getSourceFiles()) {
|
|
||||||
if (JetMainDetector.hasMain(file.getDeclarations())) {
|
|
||||||
FqName fqName = JetPsiUtil.getFQName(file);
|
|
||||||
mainClass = fqName.child(Name.identifier(JvmAbi.PACKAGE_CLASS));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
GenerationState generationState = analyzeAndGenerate(configuration);
|
GenerationState generationState = analyzeAndGenerate(configuration);
|
||||||
if (generationState == null) {
|
if (generationState == null) {
|
||||||
|
|||||||
Reference in New Issue
Block a user