Configure Java module path when compiler is invoked in -Xbuild-file mode
#KT-27626 Fixed
This commit is contained in:
@@ -94,17 +94,15 @@ class K2JVMCompiler : CLICompiler<K2JVMCompilerArguments>() {
|
|||||||
|
|
||||||
configuration.put(CommonConfigurationKeys.MODULE_NAME, arguments.moduleName ?: JvmAbi.DEFAULT_MODULE_NAME)
|
configuration.put(CommonConfigurationKeys.MODULE_NAME, arguments.moduleName ?: JvmAbi.DEFAULT_MODULE_NAME)
|
||||||
|
|
||||||
if (arguments.buildFile == null) {
|
configureContentRoots(paths, arguments, configuration)
|
||||||
configureContentRoots(paths, arguments, configuration)
|
|
||||||
|
|
||||||
if (arguments.freeArgs.isEmpty() && !arguments.version) {
|
if (arguments.buildFile == null && arguments.freeArgs.isEmpty() && !arguments.version) {
|
||||||
if (arguments.script) {
|
if (arguments.script) {
|
||||||
messageCollector.report(ERROR, "Specify script source path to evaluate")
|
messageCollector.report(ERROR, "Specify script source path to evaluate")
|
||||||
return COMPILATION_ERROR
|
return COMPILATION_ERROR
|
||||||
}
|
|
||||||
ReplFromTerminal.run(rootDisposable, configuration)
|
|
||||||
return ExitCode.OK
|
|
||||||
}
|
}
|
||||||
|
ReplFromTerminal.run(rootDisposable, configuration)
|
||||||
|
return ExitCode.OK
|
||||||
}
|
}
|
||||||
|
|
||||||
if (arguments.includeRuntime) {
|
if (arguments.includeRuntime) {
|
||||||
@@ -411,15 +409,20 @@ class K2JVMCompiler : CLICompiler<K2JVMCompilerArguments>() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun configureContentRoots(paths: KotlinPaths?, arguments: K2JVMCompilerArguments, configuration: CompilerConfiguration) {
|
private fun configureContentRoots(paths: KotlinPaths?, arguments: K2JVMCompilerArguments, configuration: CompilerConfiguration) {
|
||||||
|
for (modularRoot in arguments.javaModulePath?.split(File.pathSeparatorChar).orEmpty()) {
|
||||||
|
configuration.add(CLIConfigurationKeys.CONTENT_ROOTS, JvmModulePathRoot(File(modularRoot)))
|
||||||
|
}
|
||||||
|
|
||||||
|
if (arguments.buildFile != null) {
|
||||||
|
// In the .xml compilation mode, all content roots except module path will be loaded from the .xml build file.
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
val messageCollector = configuration.getNotNull(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY)
|
val messageCollector = configuration.getNotNull(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY)
|
||||||
for (path in arguments.classpath?.split(File.pathSeparatorChar).orEmpty()) {
|
for (path in arguments.classpath?.split(File.pathSeparatorChar).orEmpty()) {
|
||||||
configuration.add(CLIConfigurationKeys.CONTENT_ROOTS, JvmClasspathRoot(File(path)))
|
configuration.add(CLIConfigurationKeys.CONTENT_ROOTS, JvmClasspathRoot(File(path)))
|
||||||
}
|
}
|
||||||
|
|
||||||
for (modularRoot in arguments.javaModulePath?.split(File.pathSeparatorChar).orEmpty()) {
|
|
||||||
configuration.add(CLIConfigurationKeys.CONTENT_ROOTS, JvmModulePathRoot(File(modularRoot)))
|
|
||||||
}
|
|
||||||
|
|
||||||
val isModularJava = configuration.get(JVMConfigurationKeys.JDK_HOME).let { it != null && CoreJrtFileSystem.isModularJdk(it) }
|
val isModularJava = configuration.get(JVMConfigurationKeys.JDK_HOME).let { it != null && CoreJrtFileSystem.isModularJdk(it) }
|
||||||
fun addRoot(moduleName: String, libraryName: String, getLibrary: (KotlinPaths) -> File, noLibraryArgument: String) {
|
fun addRoot(moduleName: String, libraryName: String, getLibrary: (KotlinPaths) -> File, noLibraryArgument: String) {
|
||||||
val file = getLibraryFromHome(paths, getLibrary, libraryName, messageCollector, noLibraryArgument) ?: return
|
val file = getLibraryFromHome(paths, getLibrary, libraryName, messageCollector, noLibraryArgument) ?: return
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
<modules>
|
||||||
|
<module name="app" type="java-production" outputDir="$TEMP_DIR$/app">
|
||||||
|
<sources path="$TESTDATA_DIR$/usage/usage.kt"/>
|
||||||
|
<javaSourceRoots path="$TESTDATA_DIR$/usage"/>
|
||||||
|
</module>
|
||||||
|
</modules>
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
warning: the '-d' option with a directory destination is ignored because '-Xbuild-file' is specified
|
||||||
|
OK
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
module usage {
|
||||||
|
requires kotlin.stdlib;
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
class Test {
|
||||||
|
fun test() = KotlinVersion.CURRENT
|
||||||
|
}
|
||||||
@@ -204,7 +204,7 @@ public abstract class AbstractCliTest extends TestCaseWithTmpdir {
|
|||||||
String argWithTestPathsReplaced = replaceTestPaths(argWithColonsReplaced, testDataDir, tempDir);
|
String argWithTestPathsReplaced = replaceTestPaths(argWithColonsReplaced, testDataDir, tempDir);
|
||||||
|
|
||||||
if (arg.startsWith(BUILD_FILE_ARGUMENT_PREFIX)) {
|
if (arg.startsWith(BUILD_FILE_ARGUMENT_PREFIX)) {
|
||||||
return createTempFileWithPathsReplaced(argWithTestPathsReplaced, BUILD_FILE_ARGUMENT_PREFIX, ".xml", testDataDir, tempDir);
|
return replacePathsInBuildXml(argWithTestPathsReplaced, testDataDir, tempDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (arg.startsWith(ARGFILE_ARGUMENT)) {
|
if (arg.startsWith(ARGFILE_ARGUMENT)) {
|
||||||
@@ -214,6 +214,11 @@ public abstract class AbstractCliTest extends TestCaseWithTmpdir {
|
|||||||
return argWithTestPathsReplaced;
|
return argWithTestPathsReplaced;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public static String replacePathsInBuildXml(@NotNull String argument, @NotNull String testDataDir, @NotNull String tempDir) {
|
||||||
|
return createTempFileWithPathsReplaced(argument, BUILD_FILE_ARGUMENT_PREFIX, ".xml", testDataDir, tempDir);
|
||||||
|
}
|
||||||
|
|
||||||
// Create new temporary file with all test paths replaced and return the new argument value with the new file path
|
// Create new temporary file with all test paths replaced and return the new argument value with the new file path
|
||||||
@NotNull
|
@NotNull
|
||||||
private static String createTempFileWithPathsReplaced(
|
private static String createTempFileWithPathsReplaced(
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
package org.jetbrains.kotlin.jvm.compiler
|
package org.jetbrains.kotlin.jvm.compiler
|
||||||
|
|
||||||
import com.intellij.openapi.util.io.FileUtil
|
import com.intellij.openapi.util.io.FileUtil
|
||||||
|
import org.jetbrains.kotlin.cli.AbstractCliTest
|
||||||
import org.jetbrains.kotlin.codegen.forTestCompile.ForTestCompileRuntime
|
import org.jetbrains.kotlin.codegen.forTestCompile.ForTestCompileRuntime
|
||||||
import org.jetbrains.kotlin.test.KotlinTestUtils
|
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||||
import java.io.File
|
import java.io.File
|
||||||
@@ -30,6 +31,7 @@ class Java9ModulesIntegrationTest : AbstractKotlinCompilerIntegrationTest() {
|
|||||||
name: String,
|
name: String,
|
||||||
modulePath: List<File> = emptyList(),
|
modulePath: List<File> = emptyList(),
|
||||||
addModules: List<String> = emptyList(),
|
addModules: List<String> = emptyList(),
|
||||||
|
additionalKotlinArguments: List<String> = emptyList(),
|
||||||
manifest: Manifest? = null
|
manifest: Manifest? = null
|
||||||
): File {
|
): File {
|
||||||
val paths = (modulePath + ForTestCompileRuntime.runtimeJarForTests()).joinToString(separator = File.pathSeparator) { it.path }
|
val paths = (modulePath + ForTestCompileRuntime.runtimeJarForTests()).joinToString(separator = File.pathSeparator) { it.path }
|
||||||
@@ -42,6 +44,7 @@ class Java9ModulesIntegrationTest : AbstractKotlinCompilerIntegrationTest() {
|
|||||||
if (addModules.isNotEmpty()) {
|
if (addModules.isNotEmpty()) {
|
||||||
kotlinOptions += "-Xadd-modules=${addModules.joinToString()}"
|
kotlinOptions += "-Xadd-modules=${addModules.joinToString()}"
|
||||||
}
|
}
|
||||||
|
kotlinOptions += additionalKotlinArguments
|
||||||
|
|
||||||
return compileLibrary(
|
return compileLibrary(
|
||||||
name,
|
name,
|
||||||
@@ -237,4 +240,15 @@ class Java9ModulesIntegrationTest : AbstractKotlinCompilerIntegrationTest() {
|
|||||||
fun testDependencyOnReflect() {
|
fun testDependencyOnReflect() {
|
||||||
module("usage", listOf(ForTestCompileRuntime.reflectJarForTests()))
|
module("usage", listOf(ForTestCompileRuntime.reflectJarForTests()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun testWithBuildFile() {
|
||||||
|
// This test checks that module path is configured correctly when the compiler is invoked in the '-Xbuild-file' mode. Note that
|
||||||
|
// the "'-d' option is ignored" warning in this test is an artifact of the test infrastructure and is not a part of the test.
|
||||||
|
val buildFile = AbstractCliTest.replacePathsInBuildXml(
|
||||||
|
"-Xbuild-file=${File(testDataDirectory, "build.xml").path}",
|
||||||
|
testDataDirectory.absolutePath,
|
||||||
|
tmpdir.absolutePath
|
||||||
|
)
|
||||||
|
module("usage", additionalKotlinArguments = listOf("-no-stdlib", buildFile))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user