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")
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")
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 = "<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")
public boolean inheritMultifileParts;
@@ -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<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
)
@@ -62,6 +66,23 @@ fun <A : CommonToolArguments> parseCommandLineArguments(args: Array<out String>,
val visitedArgs = mutableSetOf<String>()
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 <A : CommonToolArguments> parseCommandLineArguments(args: Array<out String>,
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 <A : CommonToolArguments> parseCommandLineArguments(args: Array<out String>,
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++]
}
}
@@ -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<A : CommonToolArguments> {
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 <A : CommonToolArguments> printVersionIfNeeded(messageCollector: MessageCollector, arguments: A) {
if (!arguments.version) return
private fun <A : CommonToolArguments> 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)")
}
}
@@ -91,7 +91,7 @@ class K2JVMCompiler : CLICompiler<K2JVMCompilerArguments>() {
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<K2JVMCompilerArguments>() {
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<K2JVMCompilerArguments>() {
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)
@@ -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);
@@ -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"))
}
@@ -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")
+1 -2
View File
@@ -1,2 +1 @@
-module
$TESTDATA_DIR$/duplicateSourcesInModule.xml
-Xbuild-file=$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-optimize Disable optimizations
-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
-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
OK
+1 -2
View File
@@ -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> Path to the module file to compile
-script Evaluate the script file
-script-templates <fully qualified class name[,]>
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
OK
+1 -2
View File
@@ -1,2 +1 @@
-module
$TESTDATA_DIR$/nonexistentPathInModule.xml
-Xbuild-file=$TESTDATA_DIR$/nonexistentPathInModule.xml
@@ -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<*>
@@ -716,7 +716,7 @@ class GradleFacetImportTest : GradleImportingTestCase() {
with (facetSettings) {
Assert.assertEquals(
listOf("-module", "module with spaces"),
listOf("-Xbuild-file=module with spaces"),
compilerSettings!!.additionalArgumentsAsList
)
}
@@ -205,7 +205,7 @@ class JpsKotlinCompilerRunner : KotlinCompilerRunner<JpsCompilerEnvironment>() {
private fun setupK2JvmArguments(moduleFile: File, settings: K2JVMCompilerArguments) {
with(settings) {
module = moduleFile.absolutePath
buildFile = moduleFile.absolutePath
destination = null
noStdlib = true
noReflect = true
@@ -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()
}
}
}