diff --git a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JVMCompilerArguments.java b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JVMCompilerArguments.java index 28cba71d8e2..7dab0271d40 100644 --- a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JVMCompilerArguments.java +++ b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JVMCompilerArguments.java @@ -51,9 +51,6 @@ public class K2JVMCompilerArguments extends CommonCompilerArguments { @Argument(value = "-no-reflect", description = "Don't include Kotlin reflection implementation into classpath") public boolean noReflect; - @Argument(value = "-module", valueDescription = "", description = "Path to the module file to compile") - public String module; - @Argument(value = "-script", description = "Evaluate the script file") public boolean script; @@ -111,6 +108,9 @@ public class K2JVMCompilerArguments extends CommonCompilerArguments { @Argument(value = "-Xreport-perf", description = "Report detailed performance statistics") public boolean reportPerf; + @Argument(value = "-Xbuild-file", deprecatedName = "-module", valueDescription = "", description = "Path to the .xml build file to compile") + public String buildFile; + @Argument(value = "-Xmultifile-parts-inherit", description = "Compile multifile classes as a hierarchy of parts and facade") public boolean inheritMultifileParts; diff --git a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/parseCommandLineArguments.kt b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/parseCommandLineArguments.kt index 309e035ec85..374c9dedc1b 100644 --- a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/parseCommandLineArguments.kt +++ b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/parseCommandLineArguments.kt @@ -23,6 +23,7 @@ import java.util.* annotation class Argument( val value: String, val shortName: String = "", + val deprecatedName: String = "", val delimiter: String = ",", val valueDescription: String = "", val description: String @@ -44,7 +45,10 @@ data class ArgumentParseErrors( // Non-boolean arguments which have been passed multiple times, possibly with different values. // The key in the map is the name of the argument, the value is the last passed value. - val duplicateArguments: MutableMap = LinkedHashMap(), + val duplicateArguments: MutableMap = mutableMapOf(), + + // Arguments where [Argument.deprecatedName] was used; the key is the deprecated name, the value is the new name ([Argument.value]) + val deprecatedArguments: MutableMap = mutableMapOf(), var argumentWithoutValue: String? = null ) @@ -62,6 +66,23 @@ fun parseCommandLineArguments(args: Array, val visitedArgs = mutableSetOf() var freeArgsStarted = false + fun ArgumentField.matches(arg: String): Boolean { + if (argument.deprecatedName.takeUnless(String::isEmpty) == arg) { + errors.deprecatedArguments[argument.deprecatedName] = argument.value + return true + } + + if (argument.value == arg) { + if (argument.isAdvanced && field.type != Boolean::class.java) { + errors.extraArgumentsPassedInObsoleteForm.add(arg) + } + return true + } + + return argument.shortName.takeUnless(String::isEmpty) == arg || + (argument.isAdvanced && arg.startsWith(argument.value + "=")) + } + var i = 0 loop@ while (i < args.size) { val arg = args[i++] @@ -75,12 +96,7 @@ fun parseCommandLineArguments(args: Array, continue } - val argumentField = fields.firstOrNull { (_, argument) -> - argument.value == arg || - argument.shortName.takeUnless(String::isEmpty) == arg || - (argument.isAdvanced && arg.startsWith(argument.value + "=")) - } - + val argumentField = fields.firstOrNull { it.matches(arg) } if (argumentField == null) { when { arg.startsWith(ADVANCED_ARGUMENT_PREFIX) -> errors.unknownExtraFlags.add(arg) @@ -96,17 +112,12 @@ fun parseCommandLineArguments(args: Array, argument.isAdvanced && arg.startsWith(argument.value + "=") -> { arg.substring(argument.value.length + 1) } + i == args.size -> { + errors.argumentWithoutValue = arg + break@loop + } else -> { - if (i == args.size) { - errors.argumentWithoutValue = arg - break@loop - } - else { - if (argument.isAdvanced) { - errors.extraArgumentsPassedInObsoleteForm.add(arg) - } - args[i++] - } + args[i++] } } diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/common/CLITool.kt b/compiler/cli/src/org/jetbrains/kotlin/cli/common/CLITool.kt index 394fdfce355..7e964e92695 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/common/CLITool.kt +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/common/CLITool.kt @@ -22,6 +22,8 @@ import org.jetbrains.kotlin.cli.common.arguments.CommonToolArguments import org.jetbrains.kotlin.cli.common.arguments.parseCommandLineArguments import org.jetbrains.kotlin.cli.common.arguments.validateArguments import org.jetbrains.kotlin.cli.common.messages.* +import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity.INFO +import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity.STRONG_WARNING import org.jetbrains.kotlin.cli.jvm.K2JVMCompiler import org.jetbrains.kotlin.cli.jvm.compiler.CompileEnvironmentException import org.jetbrains.kotlin.config.KotlinCompilerVersion @@ -106,32 +108,24 @@ abstract class CLITool { private fun reportArgumentParseProblems(collector: MessageCollector, errors: ArgumentParseErrors) { for (flag in errors.unknownExtraFlags) { - collector.report( - CompilerMessageSeverity.STRONG_WARNING, - "Flag is not supported by this version of the compiler: " + flag, null) + collector.report(STRONG_WARNING, "Flag is not supported by this version of the compiler: $flag") } for (argument in errors.extraArgumentsPassedInObsoleteForm) { - collector.report( - CompilerMessageSeverity.STRONG_WARNING, - "Advanced option value is passed in an obsolete form. Please use the '=' character " + - "to specify the value: " + argument + "=...", null) + collector.report(STRONG_WARNING, "Advanced option value is passed in an obsolete form. Please use the '=' character " + + "to specify the value: $argument=...") } for ((key, value) in errors.duplicateArguments) { - collector.report( - CompilerMessageSeverity.STRONG_WARNING, - "Argument $key is passed multiple times. Only the last value will be used: $value", null) + collector.report(STRONG_WARNING, "Argument $key is passed multiple times. Only the last value will be used: $value") + } + for ((deprecatedName, newName) in errors.deprecatedArguments) { + collector.report(STRONG_WARNING, "Argument $deprecatedName is deprecated. Please use $newName instead") } } - protected fun printVersionIfNeeded(messageCollector: MessageCollector, arguments: A) { - if (!arguments.version) return - + private fun printVersionIfNeeded(messageCollector: MessageCollector, arguments: A) { if (arguments.version) { val jreVersion = System.getProperty("java.runtime.version") - messageCollector.report(CompilerMessageSeverity.INFO, - "${executableScriptFileName()} ${KotlinCompilerVersion.VERSION} (JRE $jreVersion)", - null - ) + messageCollector.report(INFO, "${executableScriptFileName()} ${KotlinCompilerVersion.VERSION} (JRE $jreVersion)") } } diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/K2JVMCompiler.kt b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/K2JVMCompiler.kt index bd942984163..29fc09939db 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/K2JVMCompiler.kt +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/K2JVMCompiler.kt @@ -91,7 +91,7 @@ class K2JVMCompiler : CLICompiler() { return INTERNAL_ERROR } - if (!arguments.script && arguments.module == null) { + if (!arguments.script && arguments.buildFile == null) { for (arg in arguments.freeArgs) { val file = File(arg) if (file.extension == JavaFileType.DEFAULT_EXTENSION) { @@ -114,7 +114,7 @@ class K2JVMCompiler : CLICompiler() { configuration.put(CommonConfigurationKeys.MODULE_NAME, arguments.moduleName ?: JvmAbi.DEFAULT_MODULE_NAME) - if (arguments.module == null && arguments.freeArgs.isEmpty() && !arguments.version) { + if (arguments.buildFile == null && arguments.freeArgs.isEmpty() && !arguments.version) { if (arguments.script) { messageCollector.report(ERROR, "Specify script source path to evaluate") return COMPILATION_ERROR @@ -150,18 +150,18 @@ class K2JVMCompiler : CLICompiler() { try { val destination = arguments.destination - if (arguments.module != null) { + if (arguments.buildFile != null) { val sanitizedCollector = FilteringMessageCollector(messageCollector, VERBOSE::contains) - val moduleScript = CompileEnvironmentUtil.loadModuleDescriptions(arguments.module, sanitizedCollector) + val moduleScript = CompileEnvironmentUtil.loadModuleDescriptions(arguments.buildFile, sanitizedCollector) if (destination != null) { messageCollector.report( STRONG_WARNING, - "The '-d' option with a directory destination is ignored because '-module' is specified" + "The '-d' option with a directory destination is ignored because '-Xbuild-file' is specified" ) } - val moduleFile = File(arguments.module) + val moduleFile = File(arguments.buildFile) val directory = moduleFile.absoluteFile.parentFile KotlinToJVMBytecodeCompiler.configureSourceRoots(configuration, moduleScript.modules, directory) diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/CompileEnvironmentUtil.java b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/CompileEnvironmentUtil.java index d63f31eba10..83ee3250f2a 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/CompileEnvironmentUtil.java +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/CompileEnvironmentUtil.java @@ -168,12 +168,11 @@ public class CompileEnvironmentUtil { if (vFile == null) { String message = "Source file or directory not found: " + sourceRootPath; - File moduleFilePath = configuration.get(JVMConfigurationKeys.MODULE_XML_FILE); - if (moduleFilePath != null && Logger.isInitialized()) { - String moduleFileContent = FileUtil.loadFile(moduleFilePath); + File buildFilePath = configuration.get(JVMConfigurationKeys.MODULE_XML_FILE); + if (buildFilePath != null && Logger.isInitialized()) { LOG.warn(message + - "\n\nmodule file path: " + moduleFilePath + - "\ncontent:\n" + moduleFileContent); + "\n\nbuild file path: " + buildFilePath + + "\ncontent:\n" + FileUtil.loadFile(buildFilePath)); } reportError.invoke(message); diff --git a/compiler/daemon/src/org/jetbrains/kotlin/daemon/CompileServiceImpl.kt b/compiler/daemon/src/org/jetbrains/kotlin/daemon/CompileServiceImpl.kt index c7762650b59..103c6ba9a69 100644 --- a/compiler/daemon/src/org/jetbrains/kotlin/daemon/CompileServiceImpl.kt +++ b/compiler/daemon/src/org/jetbrains/kotlin/daemon/CompileServiceImpl.kt @@ -398,15 +398,15 @@ class CompileServiceImpl( val reporter = RemoteICReporter(servicesFacade, compilationResults, incrementalCompilationOptions) val annotationFileUpdater = if (servicesFacade.hasAnnotationsFileUpdater()) RemoteAnnotationsFileUpdater(servicesFacade) else null - val moduleFile = k2jvmArgs.module?.let(::File) - assert(moduleFile?.exists() ?: false) { "Module does not exist ${k2jvmArgs.module}" } + val moduleFile = k2jvmArgs.buildFile?.let(::File) + assert(moduleFile?.exists() ?: false) { "Module does not exist ${k2jvmArgs.buildFile}" } // todo: pass javaSourceRoots and allKotlinFiles using IncrementalCompilationOptions val parsedModule = run { val bytesOut = ByteArrayOutputStream() val printStream = PrintStream(bytesOut) val mc = PrintingMessageCollector(printStream, MessageRenderer.PLAIN_FULL_PATHS, false) - val parsedModule = ModuleXmlParser.parseModuleScript(k2jvmArgs.module, mc) + val parsedModule = ModuleXmlParser.parseModuleScript(k2jvmArgs.buildFile, mc) if (mc.hasErrors()) { daemonMessageReporter.report(ReportSeverity.ERROR, bytesOut.toString("UTF8")) } diff --git a/compiler/incremental-compilation-impl/src/org/jetbrains/kotlin/incremental/IncrementalJvmCompilerRunner.kt b/compiler/incremental-compilation-impl/src/org/jetbrains/kotlin/incremental/IncrementalJvmCompilerRunner.kt index 79d051183c9..ead150f6f0b 100644 --- a/compiler/incremental-compilation-impl/src/org/jetbrains/kotlin/incremental/IncrementalJvmCompilerRunner.kt +++ b/compiler/incremental-compilation-impl/src/org/jetbrains/kotlin/incremental/IncrementalJvmCompilerRunner.kt @@ -424,7 +424,7 @@ class IncrementalJvmCompilerRunner( friendDirs = listOf()) val destination = args.destination args.destination = null - args.module = moduleFile.absolutePath + args.buildFile = moduleFile.absolutePath args.reportOutputFiles = true val outputItemCollector = OutputItemsCollectorImpl() @Suppress("NAME_SHADOWING") diff --git a/compiler/testData/cli/jvm/duplicateSourcesInModule.args b/compiler/testData/cli/jvm/duplicateSourcesInModule.args index 7f8f50de34c..34c6114677b 100644 --- a/compiler/testData/cli/jvm/duplicateSourcesInModule.args +++ b/compiler/testData/cli/jvm/duplicateSourcesInModule.args @@ -1,2 +1 @@ --module -$TESTDATA_DIR$/duplicateSourcesInModule.xml +-Xbuild-file=$TESTDATA_DIR$/duplicateSourcesInModule.xml diff --git a/compiler/testData/cli/jvm/extraHelp.out b/compiler/testData/cli/jvm/extraHelp.out index b9003a52934..b8470e00468 100644 --- a/compiler/testData/cli/jvm/extraHelp.out +++ b/compiler/testData/cli/jvm/extraHelp.out @@ -7,6 +7,7 @@ where advanced options include: -Xno-param-assertions Don't generate not-null assertions on parameters of methods accessible from Java -Xno-optimize Disable optimizations -Xreport-perf Report detailed performance statistics + -Xbuild-file= Path to the .xml build file to compile -Xmultifile-parts-inherit Compile multifile classes as a hierarchy of parts and facade -Xskip-runtime-version-check Allow Kotlin runtime libraries of incompatible versions in the classpath -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) @@ -32,4 +33,4 @@ where advanced options include: Enable coroutines or report warnings or errors on declarations and use sites of 'suspend' modifier Advanced options are non-standard and may be changed or removed without any notice. -OK \ No newline at end of file +OK diff --git a/compiler/testData/cli/jvm/help.out b/compiler/testData/cli/jvm/help.out index 1c3859c8b0c..5326807c57a 100644 --- a/compiler/testData/cli/jvm/help.out +++ b/compiler/testData/cli/jvm/help.out @@ -7,7 +7,6 @@ where possible options include: -no-jdk Don't include Java runtime into classpath -no-stdlib Don't include Kotlin runtime into classpath -no-reflect Don't include Kotlin reflection implementation into classpath - -module Path to the module file to compile -script Evaluate the script file -script-templates Script definition template classes @@ -24,4 +23,4 @@ where possible options include: -version Display compiler version -verbose Enable verbose logging output -nowarn Generate no warnings -OK \ No newline at end of file +OK diff --git a/compiler/testData/cli/jvm/nonexistentPathInModule.args b/compiler/testData/cli/jvm/nonexistentPathInModule.args index bf3db449d6b..ad2f350c9a2 100644 --- a/compiler/testData/cli/jvm/nonexistentPathInModule.args +++ b/compiler/testData/cli/jvm/nonexistentPathInModule.args @@ -1,2 +1 @@ --module -$TESTDATA_DIR$/nonexistentPathInModule.xml +-Xbuild-file=$TESTDATA_DIR$/nonexistentPathInModule.xml diff --git a/compiler/tests-common/org/jetbrains/kotlin/test/MockLibraryUtil.kt b/compiler/tests-common/org/jetbrains/kotlin/test/MockLibraryUtil.kt index bc9b803f0db..307abeed096 100644 --- a/compiler/tests-common/org/jetbrains/kotlin/test/MockLibraryUtil.kt +++ b/compiler/tests-common/org/jetbrains/kotlin/test/MockLibraryUtil.kt @@ -193,8 +193,8 @@ object MockLibraryUtil { runJsCompiler(listOf("-meta-info", "-output", outputFile.absolutePath, sourcesPath)) } - fun compileKotlinModule(modulePath: String) { - runJvmCompiler(listOf("-no-stdlib", "-module", modulePath)) + fun compileKotlinModule(buildFilePath: String) { + runJvmCompiler(listOf("-no-stdlib", "-Xbuild-file", buildFilePath)) } private val compiler2JVMClass: Class<*> diff --git a/idea/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/GradleFacetImportTest.kt b/idea/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/GradleFacetImportTest.kt index 3a0b712600e..e0a8fc01642 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/GradleFacetImportTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/GradleFacetImportTest.kt @@ -716,7 +716,7 @@ class GradleFacetImportTest : GradleImportingTestCase() { with (facetSettings) { Assert.assertEquals( - listOf("-module", "module with spaces"), + listOf("-Xbuild-file=module with spaces"), compilerSettings!!.additionalArgumentsAsList ) } diff --git a/jps-plugin/src/org/jetbrains/kotlin/compilerRunner/JpsKotlinCompilerRunner.kt b/jps-plugin/src/org/jetbrains/kotlin/compilerRunner/JpsKotlinCompilerRunner.kt index 32fe18f2bff..b3f71c05b45 100644 --- a/jps-plugin/src/org/jetbrains/kotlin/compilerRunner/JpsKotlinCompilerRunner.kt +++ b/jps-plugin/src/org/jetbrains/kotlin/compilerRunner/JpsKotlinCompilerRunner.kt @@ -205,7 +205,7 @@ class JpsKotlinCompilerRunner : KotlinCompilerRunner() { private fun setupK2JvmArguments(moduleFile: File, settings: K2JVMCompilerArguments) { with(settings) { - module = moduleFile.absolutePath + buildFile = moduleFile.absolutePath destination = null noStdlib = true noReflect = true diff --git a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/compilerRunner/GradleKotlinCompilerRunner.kt b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/compilerRunner/GradleKotlinCompilerRunner.kt index 44a2381cf1b..bfe70ccfceb 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/compilerRunner/GradleKotlinCompilerRunner.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/compilerRunner/GradleKotlinCompilerRunner.kt @@ -88,7 +88,7 @@ internal class GradleCompilerRunner(private val project: Project) : KotlinCompil args: K2JVMCompilerArguments, environment: GradleCompilerEnvironment ): ExitCode { - val moduleFile = makeModuleFile( + val buildFile = makeModuleFile( args.moduleName, isTest = false, outputDir = args.destinationAsFile, @@ -96,22 +96,22 @@ internal class GradleCompilerRunner(private val project: Project) : KotlinCompil javaSourceRoots = javaSourceRoots, classpath = args.classpathAsList, friendDirs = args.friendPaths?.map(::File) ?: emptyList()) - args.module = moduleFile.absolutePath + args.buildFile = buildFile.absolutePath if (environment !is GradleIncrementalCompilerEnvironment) { args.destination = null } - var deleteModuleFile = true + var deleteBuildFile = true try { val res = runCompiler(K2JVM_COMPILER, args, environment) - deleteModuleFile = (res == ExitCode.OK || System.getProperty("kotlin.compiler.leave.module.file.on.error") == null) + deleteBuildFile = (res == ExitCode.OK || System.getProperty("kotlin.compiler.leave.module.file.on.error") == null) return res } finally { - if (deleteModuleFile) { - moduleFile.delete() + if (deleteBuildFile) { + buildFile.delete() } } }