[CLI] Don't register classpath roots twice

There are two ways how content roots are registered in compiler configuration
  in JVM CLI compiler:
1. Directly from arguments
2. From Module, which build from arguments

And there was a problem that both ways used at the same time in some
  circumstances (regular compilation without .xml module file) which
  caused duplication of all content roots.

Ideal solution for this problem is removal of Module usages at all,
  because it looks like redundant abstraction which just complicate
  things, but it's too scary to remove it, because it hove some none
  trivial usages inside compiler. So to fix problem with duplicated
  roots this commit just removes registration of roots from arguments
  if Module is used
This commit is contained in:
Dmitriy Novozhilov
2022-02-11 10:23:16 +03:00
committed by teamcity
parent 6d1fe3a962
commit faba9c4272
4 changed files with 18 additions and 15 deletions
@@ -74,13 +74,18 @@ class K2JVMCompiler : CLICompiler<K2JVMCompilerArguments>() {
val moduleName = arguments.moduleName ?: JvmProtoBufUtil.DEFAULT_MODULE_NAME
configuration.put(CommonConfigurationKeys.MODULE_NAME, moduleName)
configuration.configureExplicitContentRoots(arguments)
configuration.configureJavaModulesContentRoots(arguments)
configuration.configureStandardLibs(paths, arguments)
configuration.configureAdvancedJvmOptions(arguments)
configuration.configureKlibPaths(arguments)
if (arguments.buildFile == null && !arguments.version && !arguments.allowNoSourceFiles &&
(arguments.script || arguments.expression != null || arguments.freeArgs.isEmpty())) {
if (
arguments.buildFile == null &&
!arguments.version &&
!arguments.allowNoSourceFiles &&
(arguments.script || arguments.expression != null || arguments.freeArgs.isEmpty())
) {
configuration.configureContentRootsFromClassPath(arguments)
// script or repl
if (arguments.script && arguments.freeArgs.isEmpty()) {
@@ -131,7 +136,7 @@ class K2JVMCompiler : CLICompiler<K2JVMCompilerArguments>() {
if (arguments.javaPackagePrefix != null) {
strongWarning("The '-Xjava-package-prefix' option is ignored because '-Xbuild-file' is specified")
}
configuration.configureContentRootsFromClassPath(arguments)
val sanitizedCollector = FilteringMessageCollector(messageCollector, VERBOSE::contains)
configuration.put(JVMConfigurationKeys.MODULE_XML_FILE, buildFile)
CompileEnvironmentUtil.loadModuleChunk(buildFile, sanitizedCollector)
@@ -165,10 +165,10 @@ object KotlinToJVMBytecodeCompiler {
for (module in chunk) {
for (classpathRoot in module.getClasspathRoots()) {
configuration.add(
CLIConfigurationKeys.CONTENT_ROOTS,
if (isJava9Module) JvmModulePathRoot(File(classpathRoot)) else JvmClasspathRoot(File(classpathRoot))
)
if (isJava9Module) {
configuration.add(CLIConfigurationKeys.CONTENT_ROOTS, JvmModulePathRoot(File(classpathRoot)))
}
configuration.add(CLIConfigurationKeys.CONTENT_ROOTS, JvmClasspathRoot(File(classpathRoot)))
}
}
@@ -158,16 +158,13 @@ fun CompilerConfiguration.configureJdkHome(arguments: K2JVMCompilerArguments): B
return true
}
fun CompilerConfiguration.configureExplicitContentRoots(arguments: K2JVMCompilerArguments) {
fun CompilerConfiguration.configureJavaModulesContentRoots(arguments: K2JVMCompilerArguments) {
for (modularRoot in arguments.javaModulePath?.split(File.pathSeparatorChar).orEmpty()) {
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
}
fun CompilerConfiguration.configureContentRootsFromClassPath(arguments: K2JVMCompilerArguments) {
for (path in arguments.classpath?.split(File.pathSeparatorChar).orEmpty()) {
add(CLIConfigurationKeys.CONTENT_ROOTS, JvmClasspathRoot(File(path)))
}