diff --git a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/CommonCompilerArguments.kt b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/CommonCompilerArguments.kt index da8881921f0..405985ccc6a 100644 --- a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/CommonCompilerArguments.kt +++ b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/CommonCompilerArguments.kt @@ -76,7 +76,7 @@ abstract class CommonCompilerArguments : CommonToolArguments() { ) var skipMetadataVersionCheck: Boolean by FreezableVar(false) - @Argument(value = "-Xallow-kotlin-package", description = "Allow compiling code in package 'kotlin'") + @Argument(value = "-Xallow-kotlin-package", description = "Allow compiling code in package 'kotlin' and allow not requiring kotlin.stdlib in module-info") var allowKotlinPackage: Boolean by FreezableVar(false) @Argument(value = "-Xreport-output-files", description = "Report source to output files mapping") diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/ClasspathRootsResolver.kt b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/ClasspathRootsResolver.kt index 757edcd7a90..7879a0dee8a 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/ClasspathRootsResolver.kt +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/ClasspathRootsResolver.kt @@ -19,7 +19,6 @@ package org.jetbrains.kotlin.cli.jvm.compiler import com.intellij.openapi.vfs.StandardFileSystems import com.intellij.openapi.vfs.VfsUtilCore import com.intellij.openapi.vfs.VirtualFile -import com.intellij.openapi.vfs.VirtualFileManager import com.intellij.psi.PsiJavaModule import com.intellij.psi.PsiManager import com.intellij.psi.impl.light.LightJavaModule @@ -51,7 +50,8 @@ internal class ClasspathRootsResolver( private val messageCollector: MessageCollector?, private val additionalModules: List, private val contentRootToVirtualFile: (JvmContentRoot) -> VirtualFile?, - private val javaModuleFinder: CliJavaModuleFinder + private val javaModuleFinder: CliJavaModuleFinder, + private val requireStdlibModule: Boolean ) { val javaModuleGraph = JavaModuleGraph(javaModuleFinder) @@ -179,14 +179,15 @@ internal class ClasspathRootsResolver( if (javaModuleFinder.allObservableModules.none()) return + val sourceModule = sourceModules.singleOrNull() val addAllModulePathToRoots = "ALL-MODULE-PATH" in additionalModules - if (addAllModulePathToRoots && sourceModules.isNotEmpty()) { + if (addAllModulePathToRoots && sourceModule != null) { report(ERROR, "-Xadd-modules=ALL-MODULE-PATH can only be used when compiling the unnamed module") return } val rootModules = when { - sourceModules.isNotEmpty() -> listOf(sourceModules.single().name) + additionalModules + sourceModule != null -> listOf(sourceModule.name) + additionalModules addAllModulePathToRoots -> modules.map(JavaModule::name) else -> computeDefaultRootModules() + additionalModules } @@ -217,6 +218,15 @@ internal class ClasspathRootsResolver( )) } } + + if (requireStdlibModule && sourceModule != null && "kotlin.stdlib" !in allDependencies) { + report( + ERROR, + "The Kotlin standard library is not found in the module graph. " + + "Please ensure you have the 'requires kotlin.stdlib' clause in your module definition", + sourceModule.moduleInfoFile + ) + } } // See http://openjdk.java.net/jeps/261 diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/KotlinCoreEnvironment.kt b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/KotlinCoreEnvironment.kt index 2089cc3eebb..03e71c8126b 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/KotlinCoreEnvironment.kt +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/KotlinCoreEnvironment.kt @@ -205,7 +205,8 @@ class KotlinCoreEnvironment private constructor( messageCollector, configuration.getList(JVMConfigurationKeys.ADDITIONAL_JAVA_MODULES), this::contentRootToVirtualFile, - javaModuleFinder + javaModuleFinder, + !configuration.getBoolean(CLIConfigurationKeys.ALLOW_KOTLIN_PACKAGE) ) val (initialRoots, javaModules) = diff --git a/compiler/testData/cli/js/jsExtraHelp.out b/compiler/testData/cli/js/jsExtraHelp.out index b85dba4ef8f..6ee7dc01c4b 100644 --- a/compiler/testData/cli/js/jsExtraHelp.out +++ b/compiler/testData/cli/js/jsExtraHelp.out @@ -3,7 +3,7 @@ where advanced options include: -Xfriend-modules= Paths to friend modules -Xfriend-modules-disabled Disable internal declaration export -Xtyped-arrays Translate primitive arrays to JS typed arrays - -Xallow-kotlin-package Allow compiling code in package 'kotlin' + -Xallow-kotlin-package Allow compiling code in package 'kotlin' and allow not requiring kotlin.stdlib in module-info -Xcoroutines={enable|warn|error} Enable coroutines or report warnings or errors on declarations and use sites of 'suspend' modifier -Xintellij-plugin-root= Path to the kotlin-compiler.jar or directory where IntelliJ configuration files can be found diff --git a/compiler/testData/cli/jvm/extraHelp.out b/compiler/testData/cli/jvm/extraHelp.out index cf9eb4bd6bf..2302f980146 100644 --- a/compiler/testData/cli/jvm/extraHelp.out +++ b/compiler/testData/cli/jvm/extraHelp.out @@ -23,7 +23,7 @@ where advanced options include: -Xskip-runtime-version-check Allow Kotlin runtime libraries of incompatible versions in the classpath -Xuse-javac Use javac for Java source and class files analysis -Xuse-old-class-files-reading Use old class files reading implementation (may slow down the build and should be used in case of problems with the new implementation) - -Xallow-kotlin-package Allow compiling code in package 'kotlin' + -Xallow-kotlin-package Allow compiling code in package 'kotlin' and allow not requiring kotlin.stdlib in module-info -Xcoroutines={enable|warn|error} Enable coroutines or report warnings or errors on declarations and use sites of 'suspend' modifier -Xintellij-plugin-root= Path to the kotlin-compiler.jar or directory where IntelliJ configuration files can be found