[CLI] Replace K2 -Xmodule by -Xfragments and -Xfragment-sources

KT-56210
This commit is contained in:
Sebastian Sellmair
2023-02-21 15:12:21 +01:00
committed by Space Team
parent 8e5b19fe96
commit 21bf497830
30 changed files with 157 additions and 92 deletions
@@ -717,12 +717,18 @@ abstract class CommonCompilerArguments : CommonToolArguments() {
}
@Argument(
value = "-Xmodule",
valueDescription = "<module name>;<source file[,source file...]>",
description = "Describes module with specific sources. Usage of this arguments requires to specify module for each source file from free args",
delimiter = ""
value = "-Xfragments",
valueDescription = "<fragment name>",
description = "Declares all known fragments of a multiplatform compilation"
)
var modulesDescription: Array<String>? = null
var fragments: Array<String>? = null
@Argument(
value = "-Xfragment-sources",
valueDescription = "<fragment name>;<path>",
description = "Adds sources to a specific fragment of a multiplatform compilation",
)
var fragmentSources: Array<String>? = null
set(value) {
checkFrozen()
field = value
@@ -732,7 +738,6 @@ abstract class CommonCompilerArguments : CommonToolArguments() {
value = "-Xdepends-on",
valueDescription = "<fromModuleName>:<onModuleName>",
description = "Declares that <fromModuleName> depends on <onModuleName> with dependsOn relation",
delimiter = ""
)
var dependsOnDependencies: Array<String>? = null
set(value) {
@@ -130,7 +130,8 @@ private fun <A : CommonToolArguments> MessageCollector.reportUnsafeInternalArgum
}
private fun CompilerConfiguration.buildHmppModuleStructure(arguments: CommonCompilerArguments): HmppCliModuleStructure? {
val rawModules = arguments.modulesDescription
val rawFragments = arguments.fragments
val rawFragmentSources = arguments.fragmentSources
val rawDependencies = arguments.dependsOnDependencies
val messageCollector = getNotNull(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY)
@@ -143,33 +144,41 @@ private fun CompilerConfiguration.buildHmppModuleStructure(arguments: CommonComp
messageCollector.report(CompilerMessageSeverity.WARNING, message)
}
if (rawModules == null) {
if (rawFragments == null) {
if (rawDependencies != null) {
reportError("-Xdepends-on flag can not be used without -Xmodule")
reportError("-Xdepends-on flag can not be used without -Xfragments")
}
return null
}
if (!languageVersionSettings.languageVersion.usesK2) {
reportWarning("-Xmodule flag is not supported for language version < 2.0")
reportWarning("-Xfragments flag is not supported for language version < 2.0")
return null
}
var modules = rawModules.mapNotNull { arg ->
val split = arg.split(";")
val name = split.first()
when (split.size) {
1 -> reportWarning("Incorrect syntax for -Xmodule argument. Module $name has no sources")
2 -> {} // OK
else -> {
reportError("Incorrect syntax for -Xmodule argument. `<module name>;<source file[,source file...]>` expected but got `$arg`")
return@mapNotNull null
val sourcesByFragmentName: Map<String, Set<String>> = rawFragments.associateWith { mutableSetOf<String>() }.apply {
rawFragmentSources.orEmpty().forEach { rawFragmentSourceArg ->
val split = rawFragmentSourceArg.split(";")
if (split.size != 2) {
reportError(
"Incorrect syntax for -Xfragment-sources argument. " +
"`<module name>;<source file>` expected but got `$rawFragmentSourceArg`"
)
return@forEach
}
val fragmentName = split[0]
val fragmentSource = split[1]
getOrElse(fragmentName) {
reportError("fragment `$fragmentName` of source file $fragmentSource is not specified in -Xfragments")
return@forEach
}.add(fragmentSource)
}
val sources = split.getOrNull(1)?.split(",")?.toSet().orEmpty()
HmppCliModule(name, sources)
}
var modules = sourcesByFragmentName.map { (fragmentName, sources) -> HmppCliModule(fragmentName, sources) }
var wasError = false
// check sources mapping
for (i in modules.indices) {
@@ -185,7 +194,10 @@ private fun CompilerConfiguration.buildHmppModuleStructure(arguments: CommonComp
append("Files ")
append(commonFiles.joinToString(", ") { "'$it'" })
}
append(" can be a part of only one module, but is listed as a source for both `${m1.name}` and `${m2.name}`, please check you -Xmodule options.")
append(
" can be a part of only one module, but is listed as a source for both `${m1.name}` and `${m2.name}`, " +
"please check you -Xfragment-sources options."
)
}
reportError(message)
wasError = true
@@ -233,7 +245,7 @@ private fun CompilerConfiguration.buildHmppModuleStructure(arguments: CommonComp
fun findModule(name: String): HmppCliModule? {
return moduleByName[name].also { module ->
if (module == null) {
reportError("Module `$name` not found in -Xmodule arguments")
reportError("Module `$name` not found in -Xfragments arguments")
}
}
}
+3 -2
View File
@@ -83,6 +83,9 @@ where advanced options include:
Use 'warning' level to issue warnings instead of errors.
-Xextended-compiler-checks Enable additional compiler checks that might provide verbose diagnostic information for certain errors.
Warning: this mode is not backward-compatible and might cause compilation errors in previously compiled code.
-Xfragment-sources=<fragment name>;<path>
Adds sources to a specific fragment of a multiplatform compilation
-Xfragments=<fragment name> Declares all known fragments of a multiplatform compilation
-Xenable-incremental-compilation
Enable incremental compilation
-Xinference-compatibility Enable compatibility changes for generic type inference algorithm
@@ -91,8 +94,6 @@ where advanced options include:
-Xlegacy-smart-cast-after-try Allow var smart casts despite assignment in try block
-Xlist-phases List backend phases
-Xmetadata-version Change metadata version of the generated binary files
-Xmodule=<module name>;<source file[,source file...]>
Describes module with specific sources. Usage of this arguments requires to specify module for each source file from free args
-Xmulti-platform Enable experimental language support for multi-platform projects
-Xnew-inference Enable new experimental generic type inference algorithm
-Xno-check-actual Do not check presence of 'actual' modifier in multi-platform projects
+4 -3
View File
@@ -8,8 +8,9 @@ fir-hmpp
-language-version
2.0
-XXLanguage\:+MultiPlatformProjects
-Xmodule=a;$TESTDATA_DIR$/../jvm/hmpp/src/a.kt
-Xmodule=b;$TESTDATA_DIR$/../jvm/hmpp/src/b.kt
-Xmodule=c;$TESTDATA_DIR$/../jvm/hmpp/src/c.kt
-Xfragments=a,b,c
-Xfragment-sources=a;$TESTDATA_DIR$/../jvm/hmpp/src/a.kt
-Xfragment-sources=b;$TESTDATA_DIR$/../jvm/hmpp/src/b.kt
-Xfragment-sources=c;$TESTDATA_DIR$/../jvm/hmpp/src/c.kt
-Xdepends-on=b\:a
-Xdepends-on=c\:b
+3 -2
View File
@@ -189,6 +189,9 @@ where advanced options include:
Use 'warning' level to issue warnings instead of errors.
-Xextended-compiler-checks Enable additional compiler checks that might provide verbose diagnostic information for certain errors.
Warning: this mode is not backward-compatible and might cause compilation errors in previously compiled code.
-Xfragment-sources=<fragment name>;<path>
Adds sources to a specific fragment of a multiplatform compilation
-Xfragments=<fragment name> Declares all known fragments of a multiplatform compilation
-Xenable-incremental-compilation
Enable incremental compilation
-Xinference-compatibility Enable compatibility changes for generic type inference algorithm
@@ -197,8 +200,6 @@ where advanced options include:
-Xlegacy-smart-cast-after-try Allow var smart casts despite assignment in try block
-Xlist-phases List backend phases
-Xmetadata-version Change metadata version of the generated binary files
-Xmodule=<module name>;<source file[,source file...]>
Describes module with specific sources. Usage of this arguments requires to specify module for each source file from free args
-Xmulti-platform Enable experimental language support for multi-platform projects
-Xnew-inference Enable new experimental generic type inference algorithm
-Xno-check-actual Do not check presence of 'actual' modifier in multi-platform projects
+4 -3
View File
@@ -6,9 +6,10 @@ $TEMP_DIR$
-language-version
2.0
-XXLanguage\:+MultiPlatformProjects
-Xmodule=a;$TESTDATA_DIR$/src/a.kt
-Xmodule=b;$TESTDATA_DIR$/src/b.kt
-Xmodule=c;$TESTDATA_DIR$/src/c.kt
-Xfragments=a,b,c
-Xfragment-sources=a;$TESTDATA_DIR$/src/a.kt
-Xfragment-sources=b;$TESTDATA_DIR$/src/b.kt
-Xfragment-sources=c;$TESTDATA_DIR$/src/c.kt
-Xdepends-on=b\:a
-Xdepends-on=c\:b
-Xdepends-on=a\:c
+2 -1
View File
@@ -4,5 +4,6 @@ $TEMP_DIR$
-language-version
2.0
-XXLanguage\:+MultiPlatformProjects
-Xmodule=a;$TESTDATA_DIR$/src/a.kt
-Xfragments=a
-Xfragment-sources=a;$TESTDATA_DIR$/src/a.kt
-Xdepends-on=b\:a
@@ -8,5 +8,5 @@ as no stability/compatibility guarantees are given on
compiler or generated code. Use it at your own risk!
warning: language version 2.0 is experimental, there are no backwards compatibility guarantees for new language and library features
error: there are multiple modules with same name(s): a, a
error: -Xdepends-on flag can not be used without -Xfragments
COMPILATION_ERROR
+1 -1
View File
@@ -8,5 +8,5 @@ as no stability/compatibility guarantees are given on
compiler or generated code. Use it at your own risk!
warning: language version 2.0 is experimental, there are no backwards compatibility guarantees for new language and library features
error: -Xdepends-on flag can not be used without -Xmodule
error: -Xdepends-on flag can not be used without -Xfragments
COMPILATION_ERROR
@@ -5,4 +5,4 @@ $TEMP_DIR$
-language-version
2.0
-XXLanguage\:+MultiPlatformProjects
-Xmodule=a;a.kt;b.kt
-Xfragments=a,a
@@ -8,7 +8,6 @@ as no stability/compatibility guarantees are given on
compiler or generated code. Use it at your own risk!
warning: language version 2.0 is experimental, there are no backwards compatibility guarantees for new language and library features
error: incorrect syntax for -Xmodule argument. `<module name>;<source file[,source file...]>` expected but got `a;a.kt;b.kt`
error: source '$TESTDATA_DIR$/src/a.kt' does not belong to any module
error: source '$TESTDATA_DIR$/src/b.kt' does not belong to any module
COMPILATION_ERROR
-10
View File
@@ -1,10 +0,0 @@
$TESTDATA_DIR$/src/a.kt
$TESTDATA_DIR$/src/b.kt
-d
$TEMP_DIR$
-language-version
2.0
-XXLanguage\:+MultiPlatformProjects
-Xmodule=a;$TESTDATA_DIR$/src/a.kt
-Xmodule=b;$TESTDATA_DIR$/src/b.kt
-Xmodule=a;$TESTDATA_DIR$/src/c.kt
@@ -5,4 +5,5 @@ $TEMP_DIR$
-language-version
2.0
-XXLanguage\:+MultiPlatformProjects
-Xmodule=a;$TESTDATA_DIR$/src/a.kt
-Xfragments=a,b,c
-Xfragment-sources=a;a.kt;
@@ -0,0 +1,14 @@
warning: ATTENTION!
This build uses unsafe internal compiler arguments:
-XXLanguage:+MultiPlatformProjects
This mode is not recommended for production use,
as no stability/compatibility guarantees are given on
compiler or generated code. Use it at your own risk!
warning: language version 2.0 is experimental, there are no backwards compatibility guarantees for new language and library features
error: incorrect syntax for -Xfragment-sources argument. `<module name>;<source file>` expected but got `a;a.kt;`
error: source '$TESTDATA_DIR$/src/a.kt' does not belong to any module
error: source '$TESTDATA_DIR$/src/b.kt' does not belong to any module
COMPILATION_ERROR
@@ -4,5 +4,4 @@ $TEMP_DIR$
-language-version
2.0
-XXLanguage\:+MultiPlatformProjects
-Xmodule=a
-Xmodule=b;
-Xfragments=a,b
+1 -2
View File
@@ -6,6 +6,5 @@ $TEMP_DIR$
-language-version
1.9
-XXLanguage\:+MultiPlatformProjects
-Xmodule=a;$TESTDATA_DIR$/src/a.kt
-Xmodule=b;$TESTDATA_DIR$/src/b.kt,$TESTDATA_DIR$/src/c.kt
-Xfragments=a,b,c
-Xcommon-sources=$TESTDATA_DIR$/src/a.kt,$TESTDATA_DIR$/src/b.kt
+1 -1
View File
@@ -7,5 +7,5 @@ This mode is not recommended for production use,
as no stability/compatibility guarantees are given on
compiler or generated code. Use it at your own risk!
warning: -Xmodule flag is not supported for language version < 2.0
warning: -Xfragments flag is not supported for language version < 2.0
OK
@@ -5,6 +5,6 @@ $TEMP_DIR$
-language-version
2.0
-XXLanguage\:+MultiPlatformProjects
-Xmodule=a;$TESTDATA_DIR$/src/a.kt
-Xmodule=b;$TESTDATA_DIR$/src/b.kt
-Xfragments=a,b
-Xfragment-sources=a;$TESTDATA_DIR$/src/a.kt,b;$TESTDATA_DIR$/src/b.kt
-Xdepends-on=c\:a
@@ -8,5 +8,5 @@ as no stability/compatibility guarantees are given on
compiler or generated code. Use it at your own risk!
warning: language version 2.0 is experimental, there are no backwards compatibility guarantees for new language and library features
error: module `c` not found in -Xmodule arguments
error: module `c` not found in -Xfragments arguments
COMPILATION_ERROR
@@ -0,0 +1,11 @@
$TESTDATA_DIR$/src/a.kt
$TESTDATA_DIR$/src/b.kt
-d
$TEMP_DIR$
-language-version
2.0
-XXLanguage\:+MultiPlatformProjects
-Xfragments=a,b
-Xfragment-sources=a;$TESTDATA_DIR$/src/a.kt
-Xfragment-sources=b;$TESTDATA_DIR$/src/a.kt
-Xfragment-sources=b;$TESTDATA_DIR$/src/b.kt
@@ -8,6 +8,5 @@ as no stability/compatibility guarantees are given on
compiler or generated code. Use it at your own risk!
warning: language version 2.0 is experimental, there are no backwards compatibility guarantees for new language and library features
error: file '$TESTDATA_DIR$/src/a.kt' can be a part of only one module, but is listed as a source for both `a` and `b`, please check you -Xmodule options.
error: source '$TESTDATA_DIR$/src/b.kt' does not belong to any module
error: file '$TESTDATA_DIR$/src/a.kt' can be a part of only one module, but is listed as a source for both `a` and `b`, please check you -Xfragment-sources options.
COMPILATION_ERROR
@@ -5,5 +5,5 @@ $TEMP_DIR$
-language-version
2.0
-XXLanguage\:+MultiPlatformProjects
-Xmodule=a;$TESTDATA_DIR$/src/a.kt
-Xmodule=b;$TESTDATA_DIR$/src/a.kt
-Xfragments=a,b
-Xfragment-sources=a;$TESTDATA_DIR$/src/a.kt
+6 -3
View File
@@ -6,8 +6,11 @@ $TEMP_DIR$
-language-version
2.0
-XXLanguage\:+MultiPlatformProjects
-Xmodule=a;$TESTDATA_DIR$/src/a.kt
-Xmodule=b;$TESTDATA_DIR$/src/b.kt
-Xmodule=c;$TESTDATA_DIR$/src/c.kt
-Xfragments=a
-Xfragments=b
-Xfragments=c
-Xfragment-sources=a;$TESTDATA_DIR$/src/a.kt
-Xfragment-sources=b;$TESTDATA_DIR$/src/b.kt
-Xfragment-sources=c;$TESTDATA_DIR$/src/c.kt
-Xdepends-on=b\:a
-Xdepends-on=c\:b
@@ -0,0 +1,11 @@
$TESTDATA_DIR$/src/a.kt
$TESTDATA_DIR$/src/b.kt
$TESTDATA_DIR$/src/c.kt
-d
$TEMP_DIR$
-language-version
2.0
-XXLanguage\:+MultiPlatformProjects
-Xfragments=a,b,c
-Xfragment-sources=a;$TESTDATA_DIR$/src/a.kt,b;$TESTDATA_DIR$/src/b.kt,c;$TESTDATA_DIR$/src/c.kt
-Xdepends-on=b\:a,c\:b
@@ -0,0 +1,11 @@
warning: ATTENTION!
This build uses unsafe internal compiler arguments:
-XXLanguage:+MultiPlatformProjects
This mode is not recommended for production use,
as no stability/compatibility guarantees are given on
compiler or generated code. Use it at your own risk!
warning: language version 2.0 is experimental, there are no backwards compatibility guarantees for new language and library features
OK
+4 -3
View File
@@ -6,8 +6,9 @@ $TEMP_DIR$
-language-version
2.0
-XXLanguage\:+MultiPlatformProjects
-Xmodule=a;$TESTDATA_DIR$/../jvm/hmpp/src/a.kt
-Xmodule=b;$TESTDATA_DIR$/../jvm/hmpp/src/b.kt
-Xmodule=c;$TESTDATA_DIR$/../jvm/hmpp/src/c.kt
-Xfragments=a,b,c
-Xfragment-sources=a;$TESTDATA_DIR$/../jvm/hmpp/src/a.kt
-Xfragment-sources=b;$TESTDATA_DIR$/../jvm/hmpp/src/b.kt
-Xfragment-sources=c;$TESTDATA_DIR$/../jvm/hmpp/src/c.kt
-Xdepends-on=b\:a
-Xdepends-on=c\:b
@@ -127,14 +127,24 @@ public class CliTestGenerated extends AbstractCliTest {
runTest("compiler/testData/cli/jvm/hmpp/dependsOnSingleModule.args");
}
@TestMetadata("dependsOnWithoutModules.args")
public void testDependsOnWithoutModules() throws Exception {
runTest("compiler/testData/cli/jvm/hmpp/dependsOnWithoutModules.args");
@TestMetadata("dependsOnWithoutFragments.args")
public void testDependsOnWithoutFragments() throws Exception {
runTest("compiler/testData/cli/jvm/hmpp/dependsOnWithoutFragments.args");
}
@TestMetadata("duplicatedModules.args")
public void testDuplicatedModules() throws Exception {
runTest("compiler/testData/cli/jvm/hmpp/duplicatedModules.args");
@TestMetadata("duplicatedFragments.args")
public void testDuplicatedFragments() throws Exception {
runTest("compiler/testData/cli/jvm/hmpp/duplicatedFragments.args");
}
@TestMetadata("fragmentSourcesIncorrectSyntax.args")
public void testFragmentSourcesIncorrectSyntax() throws Exception {
runTest("compiler/testData/cli/jvm/hmpp/fragmentSourcesIncorrectSyntax.args");
}
@TestMetadata("fragmentWithoutSources.args")
public void testFragmentWithoutSources() throws Exception {
runTest("compiler/testData/cli/jvm/hmpp/fragmentWithoutSources.args");
}
@TestMetadata("lowLanguageVersion.args")
@@ -142,35 +152,30 @@ public class CliTestGenerated extends AbstractCliTest {
runTest("compiler/testData/cli/jvm/hmpp/lowLanguageVersion.args");
}
@TestMetadata("missingModule.args")
public void testMissingModule() throws Exception {
runTest("compiler/testData/cli/jvm/hmpp/missingModule.args");
@TestMetadata("missingFragment.args")
public void testMissingFragment() throws Exception {
runTest("compiler/testData/cli/jvm/hmpp/missingFragment.args");
}
@TestMetadata("moduleIncorrectSyntax.args")
public void testModuleIncorrectSyntax() throws Exception {
runTest("compiler/testData/cli/jvm/hmpp/moduleIncorrectSyntax.args");
@TestMetadata("sameSourceInDifferentFragments.args")
public void testSameSourceInDifferentFragments() throws Exception {
runTest("compiler/testData/cli/jvm/hmpp/sameSourceInDifferentFragments.args");
}
@TestMetadata("moduleWithoutSources.args")
public void testModuleWithoutSources() throws Exception {
runTest("compiler/testData/cli/jvm/hmpp/moduleWithoutSources.args");
}
@TestMetadata("sameSourceInDifferentModules.args")
public void testSameSourceInDifferentModules() throws Exception {
runTest("compiler/testData/cli/jvm/hmpp/sameSourceInDifferentModules.args");
}
@TestMetadata("sourceNotInAnyModule.args")
public void testSourceNotInAnyModule() throws Exception {
runTest("compiler/testData/cli/jvm/hmpp/sourceNotInAnyModule.args");
@TestMetadata("sourceNotInAnyFragment.args")
public void testSourceNotInAnyFragment() throws Exception {
runTest("compiler/testData/cli/jvm/hmpp/sourceNotInAnyFragment.args");
}
@TestMetadata("successfulCompilation.args")
public void testSuccessfulCompilation() throws Exception {
runTest("compiler/testData/cli/jvm/hmpp/successfulCompilation.args");
}
@TestMetadata("successfulCompilation2.args")
public void testSuccessfulCompilation2() throws Exception {
runTest("compiler/testData/cli/jvm/hmpp/successfulCompilation2.args");
}
}
@TestMetadata("compiler/testData/cli/jvm")