Rename -module argument to -Xbuild-file

To prevent confusion with Java 9 module-related arguments

 #KT-18754 Fixed
This commit is contained in:
Alexander Udalov
2017-06-23 20:59:01 +03:00
parent 6200d07808
commit 55468735df
15 changed files with 71 additions and 69 deletions
@@ -51,9 +51,6 @@ public class K2JVMCompilerArguments extends CommonCompilerArguments {
@Argument(value = "-no-reflect", description = "Don't include Kotlin reflection implementation into classpath") @Argument(value = "-no-reflect", description = "Don't include Kotlin reflection implementation into classpath")
public boolean noReflect; public boolean noReflect;
@Argument(value = "-module", valueDescription = "<path>", description = "Path to the module file to compile")
public String module;
@Argument(value = "-script", description = "Evaluate the script file") @Argument(value = "-script", description = "Evaluate the script file")
public boolean script; public boolean script;
@@ -111,6 +108,9 @@ public class K2JVMCompilerArguments extends CommonCompilerArguments {
@Argument(value = "-Xreport-perf", description = "Report detailed performance statistics") @Argument(value = "-Xreport-perf", description = "Report detailed performance statistics")
public boolean reportPerf; public boolean reportPerf;
@Argument(value = "-Xbuild-file", deprecatedName = "-module", valueDescription = "<path>", 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") @Argument(value = "-Xmultifile-parts-inherit", description = "Compile multifile classes as a hierarchy of parts and facade")
public boolean inheritMultifileParts; public boolean inheritMultifileParts;
@@ -23,6 +23,7 @@ import java.util.*
annotation class Argument( annotation class Argument(
val value: String, val value: String,
val shortName: String = "", val shortName: String = "",
val deprecatedName: String = "",
val delimiter: String = ",", val delimiter: String = ",",
val valueDescription: String = "", val valueDescription: String = "",
val description: String val description: String
@@ -44,7 +45,10 @@ data class ArgumentParseErrors(
// Non-boolean arguments which have been passed multiple times, possibly with different values. // 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. // The key in the map is the name of the argument, the value is the last passed value.
val duplicateArguments: MutableMap<String, String> = LinkedHashMap<String, String>(), val duplicateArguments: MutableMap<String, String> = mutableMapOf(),
// Arguments where [Argument.deprecatedName] was used; the key is the deprecated name, the value is the new name ([Argument.value])
val deprecatedArguments: MutableMap<String, String> = mutableMapOf(),
var argumentWithoutValue: String? = null var argumentWithoutValue: String? = null
) )
@@ -62,6 +66,23 @@ fun <A : CommonToolArguments> parseCommandLineArguments(args: Array<out String>,
val visitedArgs = mutableSetOf<String>() val visitedArgs = mutableSetOf<String>()
var freeArgsStarted = false 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 var i = 0
loop@ while (i < args.size) { loop@ while (i < args.size) {
val arg = args[i++] val arg = args[i++]
@@ -75,12 +96,7 @@ fun <A : CommonToolArguments> parseCommandLineArguments(args: Array<out String>,
continue continue
} }
val argumentField = fields.firstOrNull { (_, argument) -> val argumentField = fields.firstOrNull { it.matches(arg) }
argument.value == arg ||
argument.shortName.takeUnless(String::isEmpty) == arg ||
(argument.isAdvanced && arg.startsWith(argument.value + "="))
}
if (argumentField == null) { if (argumentField == null) {
when { when {
arg.startsWith(ADVANCED_ARGUMENT_PREFIX) -> errors.unknownExtraFlags.add(arg) arg.startsWith(ADVANCED_ARGUMENT_PREFIX) -> errors.unknownExtraFlags.add(arg)
@@ -96,17 +112,12 @@ fun <A : CommonToolArguments> parseCommandLineArguments(args: Array<out String>,
argument.isAdvanced && arg.startsWith(argument.value + "=") -> { argument.isAdvanced && arg.startsWith(argument.value + "=") -> {
arg.substring(argument.value.length + 1) arg.substring(argument.value.length + 1)
} }
i == args.size -> {
errors.argumentWithoutValue = arg
break@loop
}
else -> { else -> {
if (i == args.size) { args[i++]
errors.argumentWithoutValue = arg
break@loop
}
else {
if (argument.isAdvanced) {
errors.extraArgumentsPassedInObsoleteForm.add(arg)
}
args[i++]
}
} }
} }
@@ -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.parseCommandLineArguments
import org.jetbrains.kotlin.cli.common.arguments.validateArguments import org.jetbrains.kotlin.cli.common.arguments.validateArguments
import org.jetbrains.kotlin.cli.common.messages.* 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.K2JVMCompiler
import org.jetbrains.kotlin.cli.jvm.compiler.CompileEnvironmentException import org.jetbrains.kotlin.cli.jvm.compiler.CompileEnvironmentException
import org.jetbrains.kotlin.config.KotlinCompilerVersion import org.jetbrains.kotlin.config.KotlinCompilerVersion
@@ -106,32 +108,24 @@ abstract class CLITool<A : CommonToolArguments> {
private fun reportArgumentParseProblems(collector: MessageCollector, errors: ArgumentParseErrors) { private fun reportArgumentParseProblems(collector: MessageCollector, errors: ArgumentParseErrors) {
for (flag in errors.unknownExtraFlags) { for (flag in errors.unknownExtraFlags) {
collector.report( collector.report(STRONG_WARNING, "Flag is not supported by this version of the compiler: $flag")
CompilerMessageSeverity.STRONG_WARNING,
"Flag is not supported by this version of the compiler: " + flag, null)
} }
for (argument in errors.extraArgumentsPassedInObsoleteForm) { for (argument in errors.extraArgumentsPassedInObsoleteForm) {
collector.report( collector.report(STRONG_WARNING, "Advanced option value is passed in an obsolete form. Please use the '=' character " +
CompilerMessageSeverity.STRONG_WARNING, "to specify the value: $argument=...")
"Advanced option value is passed in an obsolete form. Please use the '=' character " +
"to specify the value: " + argument + "=...", null)
} }
for ((key, value) in errors.duplicateArguments) { for ((key, value) in errors.duplicateArguments) {
collector.report( collector.report(STRONG_WARNING, "Argument $key is passed multiple times. Only the last value will be used: $value")
CompilerMessageSeverity.STRONG_WARNING, }
"Argument $key is passed multiple times. Only the last value will be used: $value", null) for ((deprecatedName, newName) in errors.deprecatedArguments) {
collector.report(STRONG_WARNING, "Argument $deprecatedName is deprecated. Please use $newName instead")
} }
} }
protected fun <A : CommonToolArguments> printVersionIfNeeded(messageCollector: MessageCollector, arguments: A) { private fun <A : CommonToolArguments> printVersionIfNeeded(messageCollector: MessageCollector, arguments: A) {
if (!arguments.version) return
if (arguments.version) { if (arguments.version) {
val jreVersion = System.getProperty("java.runtime.version") val jreVersion = System.getProperty("java.runtime.version")
messageCollector.report(CompilerMessageSeverity.INFO, messageCollector.report(INFO, "${executableScriptFileName()} ${KotlinCompilerVersion.VERSION} (JRE $jreVersion)")
"${executableScriptFileName()} ${KotlinCompilerVersion.VERSION} (JRE $jreVersion)",
null
)
} }
} }
@@ -91,7 +91,7 @@ class K2JVMCompiler : CLICompiler<K2JVMCompilerArguments>() {
return INTERNAL_ERROR return INTERNAL_ERROR
} }
if (!arguments.script && arguments.module == null) { if (!arguments.script && arguments.buildFile == null) {
for (arg in arguments.freeArgs) { for (arg in arguments.freeArgs) {
val file = File(arg) val file = File(arg)
if (file.extension == JavaFileType.DEFAULT_EXTENSION) { if (file.extension == JavaFileType.DEFAULT_EXTENSION) {
@@ -114,7 +114,7 @@ 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.module == null && 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
@@ -150,18 +150,18 @@ class K2JVMCompiler : CLICompiler<K2JVMCompilerArguments>() {
try { try {
val destination = arguments.destination val destination = arguments.destination
if (arguments.module != null) { if (arguments.buildFile != null) {
val sanitizedCollector = FilteringMessageCollector(messageCollector, VERBOSE::contains) val sanitizedCollector = FilteringMessageCollector(messageCollector, VERBOSE::contains)
val moduleScript = CompileEnvironmentUtil.loadModuleDescriptions(arguments.module, sanitizedCollector) val moduleScript = CompileEnvironmentUtil.loadModuleDescriptions(arguments.buildFile, sanitizedCollector)
if (destination != null) { if (destination != null) {
messageCollector.report( messageCollector.report(
STRONG_WARNING, 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 val directory = moduleFile.absoluteFile.parentFile
KotlinToJVMBytecodeCompiler.configureSourceRoots(configuration, moduleScript.modules, directory) KotlinToJVMBytecodeCompiler.configureSourceRoots(configuration, moduleScript.modules, directory)
@@ -168,12 +168,11 @@ public class CompileEnvironmentUtil {
if (vFile == null) { if (vFile == null) {
String message = "Source file or directory not found: " + sourceRootPath; String message = "Source file or directory not found: " + sourceRootPath;
File moduleFilePath = configuration.get(JVMConfigurationKeys.MODULE_XML_FILE); File buildFilePath = configuration.get(JVMConfigurationKeys.MODULE_XML_FILE);
if (moduleFilePath != null && Logger.isInitialized()) { if (buildFilePath != null && Logger.isInitialized()) {
String moduleFileContent = FileUtil.loadFile(moduleFilePath);
LOG.warn(message + LOG.warn(message +
"\n\nmodule file path: " + moduleFilePath + "\n\nbuild file path: " + buildFilePath +
"\ncontent:\n" + moduleFileContent); "\ncontent:\n" + FileUtil.loadFile(buildFilePath));
} }
reportError.invoke(message); reportError.invoke(message);
@@ -398,15 +398,15 @@ class CompileServiceImpl(
val reporter = RemoteICReporter(servicesFacade, compilationResults, incrementalCompilationOptions) val reporter = RemoteICReporter(servicesFacade, compilationResults, incrementalCompilationOptions)
val annotationFileUpdater = if (servicesFacade.hasAnnotationsFileUpdater()) RemoteAnnotationsFileUpdater(servicesFacade) else null val annotationFileUpdater = if (servicesFacade.hasAnnotationsFileUpdater()) RemoteAnnotationsFileUpdater(servicesFacade) else null
val moduleFile = k2jvmArgs.module?.let(::File) val moduleFile = k2jvmArgs.buildFile?.let(::File)
assert(moduleFile?.exists() ?: false) { "Module does not exist ${k2jvmArgs.module}" } assert(moduleFile?.exists() ?: false) { "Module does not exist ${k2jvmArgs.buildFile}" }
// todo: pass javaSourceRoots and allKotlinFiles using IncrementalCompilationOptions // todo: pass javaSourceRoots and allKotlinFiles using IncrementalCompilationOptions
val parsedModule = run { val parsedModule = run {
val bytesOut = ByteArrayOutputStream() val bytesOut = ByteArrayOutputStream()
val printStream = PrintStream(bytesOut) val printStream = PrintStream(bytesOut)
val mc = PrintingMessageCollector(printStream, MessageRenderer.PLAIN_FULL_PATHS, false) 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()) { if (mc.hasErrors()) {
daemonMessageReporter.report(ReportSeverity.ERROR, bytesOut.toString("UTF8")) daemonMessageReporter.report(ReportSeverity.ERROR, bytesOut.toString("UTF8"))
} }
@@ -424,7 +424,7 @@ class IncrementalJvmCompilerRunner(
friendDirs = listOf()) friendDirs = listOf())
val destination = args.destination val destination = args.destination
args.destination = null args.destination = null
args.module = moduleFile.absolutePath args.buildFile = moduleFile.absolutePath
args.reportOutputFiles = true args.reportOutputFiles = true
val outputItemCollector = OutputItemsCollectorImpl() val outputItemCollector = OutputItemsCollectorImpl()
@Suppress("NAME_SHADOWING") @Suppress("NAME_SHADOWING")
+1 -2
View File
@@ -1,2 +1 @@
-module -Xbuild-file=$TESTDATA_DIR$/duplicateSourcesInModule.xml
$TESTDATA_DIR$/duplicateSourcesInModule.xml
+2 -1
View File
@@ -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-param-assertions Don't generate not-null assertions on parameters of methods accessible from Java
-Xno-optimize Disable optimizations -Xno-optimize Disable optimizations
-Xreport-perf Report detailed performance statistics -Xreport-perf Report detailed performance statistics
-Xbuild-file=<path> Path to the .xml build file to compile
-Xmultifile-parts-inherit Compile multifile classes as a hierarchy of parts and facade -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 -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) -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 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. Advanced options are non-standard and may be changed or removed without any notice.
OK OK
+1 -2
View File
@@ -7,7 +7,6 @@ where possible options include:
-no-jdk Don't include Java runtime into classpath -no-jdk Don't include Java runtime into classpath
-no-stdlib Don't include Kotlin runtime into classpath -no-stdlib Don't include Kotlin runtime into classpath
-no-reflect Don't include Kotlin reflection implementation into classpath -no-reflect Don't include Kotlin reflection implementation into classpath
-module <path> Path to the module file to compile
-script Evaluate the script file -script Evaluate the script file
-script-templates <fully qualified class name[,]> -script-templates <fully qualified class name[,]>
Script definition template classes Script definition template classes
@@ -24,4 +23,4 @@ where possible options include:
-version Display compiler version -version Display compiler version
-verbose Enable verbose logging output -verbose Enable verbose logging output
-nowarn Generate no warnings -nowarn Generate no warnings
OK OK
+1 -2
View File
@@ -1,2 +1 @@
-module -Xbuild-file=$TESTDATA_DIR$/nonexistentPathInModule.xml
$TESTDATA_DIR$/nonexistentPathInModule.xml
@@ -193,8 +193,8 @@ object MockLibraryUtil {
runJsCompiler(listOf("-meta-info", "-output", outputFile.absolutePath, sourcesPath)) runJsCompiler(listOf("-meta-info", "-output", outputFile.absolutePath, sourcesPath))
} }
fun compileKotlinModule(modulePath: String) { fun compileKotlinModule(buildFilePath: String) {
runJvmCompiler(listOf("-no-stdlib", "-module", modulePath)) runJvmCompiler(listOf("-no-stdlib", "-Xbuild-file", buildFilePath))
} }
private val compiler2JVMClass: Class<*> private val compiler2JVMClass: Class<*>
@@ -716,7 +716,7 @@ class GradleFacetImportTest : GradleImportingTestCase() {
with (facetSettings) { with (facetSettings) {
Assert.assertEquals( Assert.assertEquals(
listOf("-module", "module with spaces"), listOf("-Xbuild-file=module with spaces"),
compilerSettings!!.additionalArgumentsAsList compilerSettings!!.additionalArgumentsAsList
) )
} }
@@ -205,7 +205,7 @@ class JpsKotlinCompilerRunner : KotlinCompilerRunner<JpsCompilerEnvironment>() {
private fun setupK2JvmArguments(moduleFile: File, settings: K2JVMCompilerArguments) { private fun setupK2JvmArguments(moduleFile: File, settings: K2JVMCompilerArguments) {
with(settings) { with(settings) {
module = moduleFile.absolutePath buildFile = moduleFile.absolutePath
destination = null destination = null
noStdlib = true noStdlib = true
noReflect = true noReflect = true
@@ -88,7 +88,7 @@ internal class GradleCompilerRunner(private val project: Project) : KotlinCompil
args: K2JVMCompilerArguments, args: K2JVMCompilerArguments,
environment: GradleCompilerEnvironment environment: GradleCompilerEnvironment
): ExitCode { ): ExitCode {
val moduleFile = makeModuleFile( val buildFile = makeModuleFile(
args.moduleName, args.moduleName,
isTest = false, isTest = false,
outputDir = args.destinationAsFile, outputDir = args.destinationAsFile,
@@ -96,22 +96,22 @@ internal class GradleCompilerRunner(private val project: Project) : KotlinCompil
javaSourceRoots = javaSourceRoots, javaSourceRoots = javaSourceRoots,
classpath = args.classpathAsList, classpath = args.classpathAsList,
friendDirs = args.friendPaths?.map(::File) ?: emptyList()) friendDirs = args.friendPaths?.map(::File) ?: emptyList())
args.module = moduleFile.absolutePath args.buildFile = buildFile.absolutePath
if (environment !is GradleIncrementalCompilerEnvironment) { if (environment !is GradleIncrementalCompilerEnvironment) {
args.destination = null args.destination = null
} }
var deleteModuleFile = true var deleteBuildFile = true
try { try {
val res = runCompiler(K2JVM_COMPILER, args, environment) 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 return res
} }
finally { finally {
if (deleteModuleFile) { if (deleteBuildFile) {
moduleFile.delete() buildFile.delete()
} }
} }
} }