[Gradle] Rename -Xdepends-on to -Xfragment-refines and use ':' for -Xfragment-sources instead of ';'

^KT-56210 Verification Pending
This commit is contained in:
Sebastian Sellmair
2023-02-27 12:23:24 +01:00
committed by Space Team
parent a692de871b
commit b90207edb9
24 changed files with 96 additions and 90 deletions
@@ -725,7 +725,7 @@ abstract class CommonCompilerArguments : CommonToolArguments() {
@Argument(
value = "-Xfragment-sources",
valueDescription = "<fragment name>;<path>",
valueDescription = "<fragment name>:<path>",
description = "Adds sources to a specific fragment of a multiplatform compilation",
)
var fragmentSources: Array<String>? = null
@@ -735,11 +735,11 @@ abstract class CommonCompilerArguments : CommonToolArguments() {
}
@Argument(
value = "-Xdepends-on",
value = "-Xfragment-refines",
valueDescription = "<fromModuleName>:<onModuleName>",
description = "Declares that <fromModuleName> depends on <onModuleName> with dependsOn relation",
description = "Declares that <fromModuleName> refines <onModuleName> with dependsOn/refines relation",
)
var dependsOnDependencies: Array<String>? = null
var fragmentRefines: Array<String>? = null
set(value) {
checkFrozen()
field = value
@@ -132,7 +132,7 @@ private fun <A : CommonToolArguments> MessageCollector.reportUnsafeInternalArgum
private fun CompilerConfiguration.buildHmppModuleStructure(arguments: CommonCompilerArguments): HmppCliModuleStructure? {
val rawFragments = arguments.fragments
val rawFragmentSources = arguments.fragmentSources
val rawDependencies = arguments.dependsOnDependencies
val rawFragmentRefines = arguments.fragmentRefines
val messageCollector = getNotNull(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY)
@@ -145,8 +145,8 @@ private fun CompilerConfiguration.buildHmppModuleStructure(arguments: CommonComp
}
if (rawFragments == null) {
if (rawDependencies != null) {
reportError("-Xdepends-on flag can not be used without -Xfragments")
if (rawFragmentRefines != null) {
reportError("-Xfragment-refines flag can not be used without -Xfragments")
}
return null
}
@@ -159,11 +159,11 @@ private fun CompilerConfiguration.buildHmppModuleStructure(arguments: CommonComp
val sourcesByFragmentName: Map<String, Set<String>> = rawFragments.associateWith { mutableSetOf<String>() }.apply {
rawFragmentSources.orEmpty().forEach { rawFragmentSourceArg ->
val split = rawFragmentSourceArg.split(";")
if (split.size != 2) {
val split = rawFragmentSourceArg.split(":", limit = 2)
if (split.size < 2) {
reportError(
"Incorrect syntax for -Xfragment-sources argument. " +
"`<module name>;<source file>` expected but got `$rawFragmentSourceArg`"
"`<module name>:<source file>` expected but got `$rawFragmentSourceArg`"
)
return@forEach
}
@@ -171,7 +171,10 @@ private fun CompilerConfiguration.buildHmppModuleStructure(arguments: CommonComp
val fragmentSource = split[1]
getOrElse(fragmentName) {
reportError("fragment `$fragmentName` of source file $fragmentSource is not specified in -Xfragments")
reportError(
"Passed $rawFragmentSourceArg, " +
"but fragment `$fragmentName` of source file $fragmentSource is not specified in -Xfragments"
)
return@forEach
}.add(fragmentSource)
}
@@ -218,8 +221,8 @@ private fun CompilerConfiguration.buildHmppModuleStructure(arguments: CommonComp
}
if (modules.size == 1) {
if (rawDependencies?.isNotEmpty() == true) {
reportError("-Xdepends-on flag is specified but there is only one module declared")
if (rawFragmentRefines?.isNotEmpty() == true) {
reportError("-Xfragment-refines flag is specified but there is only one module declared")
}
return HmppCliModuleStructure(modules, emptyMap())
}
@@ -233,10 +236,13 @@ private fun CompilerConfiguration.buildHmppModuleStructure(arguments: CommonComp
val moduleByName = modules.associateBy { it.name }
val dependenciesMap = rawDependencies.orEmpty().mapNotNull {
val split = it.split(":")
val dependenciesMap = rawFragmentRefines.orEmpty().mapNotNull { rawFragmentRefinesEdge ->
val split = rawFragmentRefinesEdge.split(":")
if (split.size != 2) {
reportError("Incorrect syntax for -Xdepends-on argument. Expected <fromModuleName>:<onModuleName> but got `$it`")
reportError(
"Incorrect syntax for -Xfragment-refines argument. " +
"Expected <fromModuleName>:<onModuleName> but got `$rawFragmentRefines`"
)
return@mapNotNull null
}
val moduleName1 = split[0]
@@ -245,7 +251,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 -Xfragments arguments")
reportError("`-Xfragment-refines=$rawFragmentRefinesEdge` Fragment `$name` not found in -Xfragments arguments")
}
}
}
+3 -3
View File
@@ -63,8 +63,6 @@ where advanced options include:
-Xcommon-sources=<path> Sources of the common module that need to be compiled together with this module in the multi-platform mode.
Should be a subset of sources passed as free arguments
-Xcontext-receivers Enable experimental context receivers
-Xdepends-on=<fromModuleName>:<onModuleName>
Declares that <fromModuleName> depends on <onModuleName> with dependsOn relation
-Xdisable-default-scripting-plugin
Do not enable scripting plugin by default
-Xdisable-phases Disable backend phases
@@ -83,7 +81,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>
-Xfragment-refines=<fromModuleName>:<onModuleName>
Declares that <fromModuleName> refines <onModuleName> with dependsOn/refines relation
-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
+5 -5
View File
@@ -9,8 +9,8 @@ fir-hmpp
2.0
-XXLanguage\:+MultiPlatformProjects
-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
-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
-Xfragment-refines=b\:a
-Xfragment-refines=c\:b
+3 -3
View File
@@ -169,8 +169,6 @@ where advanced options include:
-Xcommon-sources=<path> Sources of the common module that need to be compiled together with this module in the multi-platform mode.
Should be a subset of sources passed as free arguments
-Xcontext-receivers Enable experimental context receivers
-Xdepends-on=<fromModuleName>:<onModuleName>
Declares that <fromModuleName> depends on <onModuleName> with dependsOn relation
-Xdisable-default-scripting-plugin
Do not enable scripting plugin by default
-Xdisable-phases Disable backend phases
@@ -189,7 +187,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>
-Xfragment-refines=<fromModuleName>:<onModuleName>
Declares that <fromModuleName> refines <onModuleName> with dependsOn/refines relation
-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
+6 -6
View File
@@ -7,9 +7,9 @@ $TEMP_DIR$
2.0
-XXLanguage\:+MultiPlatformProjects
-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
-Xfragment-sources=a\:$TESTDATA_DIR$/src/a.kt
-Xfragment-sources=b\:$TESTDATA_DIR$/src/b.kt
-Xfragment-sources=c\:$TESTDATA_DIR$/src/c.kt
-Xfragment-refines=b\:a
-Xfragment-refines=c\:b
-Xfragment-refines=a\:c
@@ -8,7 +8,7 @@ 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: 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
+2 -2
View File
@@ -6,5 +6,5 @@ $TEMP_DIR$
2.0
-XXLanguage\:+MultiPlatformProjects
-Xfragments=a,b
-Xfragment-sources=a;$TESTDATA_DIR$/src/a.kt,b;$TESTDATA_DIR$/src/b.kt
-Xdepends-on=c\:a
-Xfragment-sources=a\:$TESTDATA_DIR$/src/a.kt,b\:$TESTDATA_DIR$/src/b.kt
-Xfragment-refines=c\:a
+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: module `c` not found in -Xfragments arguments
error: `-Xfragment-refines=c:a` Fragment `c` not found in -Xfragments arguments
COMPILATION_ERROR
@@ -5,5 +5,5 @@ $TEMP_DIR$
2.0
-XXLanguage\:+MultiPlatformProjects
-Xfragments=a
-Xfragment-sources=a;$TESTDATA_DIR$/src/a.kt
-Xdepends-on=b\:a
-Xfragment-sources=a\:$TESTDATA_DIR$/src/a.kt
-Xfragment-refines=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: -Xdepends-on flag is specified but there is only one module declared
error: -Xfragment-refines flag is specified but there is only one module declared
COMPILATION_ERROR
@@ -4,4 +4,4 @@ $TEMP_DIR$
-language-version
2.0
-XXLanguage\:+MultiPlatformProjects
-Xdepends-on=a\:b
-Xfragment-refines=a\:b
@@ -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 -Xfragments
error: -Xfragment-refines flag can not be used without -Xfragments
COMPILATION_ERROR
@@ -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 -Xfragments
error: -Xfragment-refines flag can not be used without -Xfragments
COMPILATION_ERROR
@@ -6,6 +6,6 @@ $TEMP_DIR$
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
-Xfragment-sources=a\:$TESTDATA_DIR$/src/a.kt
-Xfragment-sources=b\:$TESTDATA_DIR$/src/a.kt
-Xfragment-sources=b\:$TESTDATA_DIR$/src/b.kt
+1 -1
View File
@@ -6,4 +6,4 @@ $TEMP_DIR$
2.0
-XXLanguage\:+MultiPlatformProjects
-Xfragments=a,b
-Xfragment-sources=a;$TESTDATA_DIR$/src/a.kt
-Xfragment-sources=a\:$TESTDATA_DIR$/src/a.kt
+5 -5
View File
@@ -9,8 +9,8 @@ $TEMP_DIR$
-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
-Xfragment-sources=a\:$TESTDATA_DIR$/src/a.kt
-Xfragment-sources=b\:$TESTDATA_DIR$/src/b.kt
-Xfragment-sources=c\:$TESTDATA_DIR$/src/c.kt
-Xfragment-refines=b\:a
-Xfragment-refines=c\:b
+2 -2
View File
@@ -7,5 +7,5 @@ $TEMP_DIR$
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
-Xfragment-sources=a\:$TESTDATA_DIR$/src/a.kt,b\:$TESTDATA_DIR$/src/b.kt,c\:$TESTDATA_DIR$/src/c.kt
-Xfragment-refines=b\:a,c\:b
+5 -5
View File
@@ -7,8 +7,8 @@ $TEMP_DIR$
2.0
-XXLanguage\:+MultiPlatformProjects
-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
-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
-Xfragment-refines=b\:a
-Xfragment-refines=c\:b
@@ -122,16 +122,6 @@ public class CliTestGenerated extends AbstractCliTest {
runTest("compiler/testData/cli/jvm/hmpp/cycleInDependencies.args");
}
@TestMetadata("dependsOnSingleModule.args")
public void testDependsOnSingleModule() throws Exception {
runTest("compiler/testData/cli/jvm/hmpp/dependsOnSingleModule.args");
}
@TestMetadata("dependsOnWithoutFragments.args")
public void testDependsOnWithoutFragments() throws Exception {
runTest("compiler/testData/cli/jvm/hmpp/dependsOnWithoutFragments.args");
}
@TestMetadata("duplicatedFragments.args")
public void testDuplicatedFragments() throws Exception {
runTest("compiler/testData/cli/jvm/hmpp/duplicatedFragments.args");
@@ -157,6 +147,16 @@ public class CliTestGenerated extends AbstractCliTest {
runTest("compiler/testData/cli/jvm/hmpp/missingFragment.args");
}
@TestMetadata("refinesSingleModule.args")
public void testRefinesSingleModule() throws Exception {
runTest("compiler/testData/cli/jvm/hmpp/refinesSingleModule.args");
}
@TestMetadata("refinesWithoutFragments.args")
public void testRefinesWithoutFragments() throws Exception {
runTest("compiler/testData/cli/jvm/hmpp/refinesWithoutFragments.args");
}
@TestMetadata("sameSourceInDifferentFragments.args")
public void testSameSourceInDifferentFragments() throws Exception {
runTest("compiler/testData/cli/jvm/hmpp/sameSourceInDifferentFragments.args");
@@ -15,10 +15,10 @@ internal object KotlinCompilationK2MultiplatformConfigurator : KotlinCompilation
if (compileTask.name != compilation.compileKotlinTaskName) return@configureEach
if (compileTask !is K2CompileTask) return@configureEach
compileTask.multiplatformStructure.dependsOnEdges.set(compilation.project.provider {
compileTask.multiplatformStructure.refinesEdges.set(compilation.project.provider {
compilation.allKotlinSourceSets.flatMap { sourceSet ->
sourceSet.dependsOn.map { dependsOn ->
K2MultiplatformStructure.DependsOnEdge(sourceSet.name, dependsOn.name)
K2MultiplatformStructure.RefinesEdge(sourceSet.name, dependsOn.name)
}
}
})
@@ -88,7 +88,7 @@ internal fun buildKotlinNativeKlibCompilerArgs(
if (sharedCompilationData == null) {
add("-Xfragments=${k2MultiplatformCompilationData.fragmentsCompilerArgs.joinToString(",")}")
add("-Xfragment-sources=${k2MultiplatformCompilationData.fragmentSourcesCompilerArgs.joinToString(",")}")
add("-Xdepends-on=${k2MultiplatformCompilationData.dependsOnCompilerArgs.joinToString(",")}")
add("-Xfragment-refines=${k2MultiplatformCompilationData.fragmentRefinesCompilerArgs.joinToString(",")}")
}
}
@@ -20,7 +20,7 @@ import org.jetbrains.kotlin.gradle.dsl.usesK2
abstract class K2MultiplatformStructure {
@InternalKotlinGradlePluginApi
data class DependsOnEdge(
data class RefinesEdge(
@Input
val fromFragmentName: String,
@Input
@@ -41,7 +41,7 @@ abstract class K2MultiplatformStructure {
)
@get:Nested
abstract val dependsOnEdges: SetProperty<DependsOnEdge>
abstract val refinesEdges: SetProperty<RefinesEdge>
@get:Nested
abstract val fragments: ListProperty<Fragment>
@@ -52,18 +52,18 @@ internal val K2MultiplatformStructure.fragmentsCompilerArgs: Array<String>
internal val K2MultiplatformStructure.fragmentSourcesCompilerArgs: Array<String>
get() = fragments.get().flatMap { sourceSet ->
sourceSet.sources.files.map { sourceFile -> "${sourceSet.fragmentName};${sourceFile.absolutePath}" }
sourceSet.sources.files.map { sourceFile -> "${sourceSet.fragmentName}:${sourceFile.absolutePath}" }
}.toTypedArray()
internal val K2MultiplatformStructure.dependsOnCompilerArgs: Array<String>
get() = dependsOnEdges.get().map { edge ->
internal val K2MultiplatformStructure.fragmentRefinesCompilerArgs: Array<String>
get() = refinesEdges.get().map { edge ->
"${edge.fromFragmentName}:${edge.toFragmentName}"
}.toTypedArray()
internal fun CommonCompilerArguments.configureK2Multiplatform(multiplatformStructure: K2MultiplatformStructure) {
fragments = multiplatformStructure.fragmentsCompilerArgs
fragmentSources = multiplatformStructure.fragmentSourcesCompilerArgs
dependsOnDependencies = multiplatformStructure.dependsOnCompilerArgs
fragmentRefines = multiplatformStructure.fragmentRefinesCompilerArgs
}
internal fun CommonCompilerArguments.configureMultiplatform(
@@ -20,7 +20,7 @@ import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation
import org.jetbrains.kotlin.gradle.plugin.KotlinJsCompilerType.IR
import org.jetbrains.kotlin.gradle.tasks.K2CompileTask
import org.jetbrains.kotlin.gradle.tasks.K2MultiplatformStructure
import org.jetbrains.kotlin.gradle.tasks.K2MultiplatformStructure.DependsOnEdge
import org.jetbrains.kotlin.gradle.tasks.K2MultiplatformStructure.RefinesEdge
import org.jetbrains.kotlin.gradle.tasks.K2MultiplatformStructure.Fragment
import org.jetbrains.kotlin.gradle.tasks.KotlinNativeCompile
import org.jetbrains.kotlin.gradle.tasks.configureK2Multiplatform
@@ -43,7 +43,7 @@ class K2MultiplatformStructureTest {
@Test
fun `test - configureK2Multiplatform - then parse arguments`() {
val structure = project.objects.newInstance<K2MultiplatformStructure>()
structure.dependsOnEdges.set(listOf(DependsOnEdge("a", "b"), DependsOnEdge("b", "c")))
structure.refinesEdges.set(listOf(RefinesEdge("a", "b"), RefinesEdge("b", "c")))
structure.fragments.set(
listOf(
Fragment("a", project.files("a.kt")),
@@ -65,13 +65,13 @@ class K2MultiplatformStructureTest {
val fragmentSources = parsedArguments.fragmentSources ?: fail("Missing ${CommonCompilerArguments::fragmentSources.name}")
assertEquals(
listOf(
"a;${project.file("a.kt").absolutePath}",
"b;${project.file("b.kt").absolutePath}"
"a:${project.file("a.kt").absolutePath}",
"b:${project.file("b.kt").absolutePath}"
),
fragmentSources.toList()
)
val dependsOn = parsedArguments.dependsOnDependencies ?: fail("Missing ${CommonCompilerArguments::dependsOnDependencies.name}")
val dependsOn = parsedArguments.fragmentRefines ?: fail("Missing ${CommonCompilerArguments::fragmentRefines.name}")
assertEquals(listOf("a:b", "b:c"), dependsOn.toList())
}
@@ -116,11 +116,11 @@ class K2MultiplatformStructureTest {
/* check dependsOnEdges */
assertEquals(
setOf(
DependsOnEdge(defaultSourceSet.name, "commonMain"),
DependsOnEdge(defaultSourceSet.name, "intermediateMain"),
DependsOnEdge("intermediateMain", "commonMain")
RefinesEdge(defaultSourceSet.name, "commonMain"),
RefinesEdge(defaultSourceSet.name, "intermediateMain"),
RefinesEdge("intermediateMain", "commonMain")
),
compileTask.multiplatformStructure.dependsOnEdges.get().toSet()
compileTask.multiplatformStructure.refinesEdges.get().toSet()
)
/* check source files */
@@ -149,8 +149,8 @@ class K2MultiplatformStructureTest {
fail("Missing ${CommonCompilerArguments::fragmentSources.name} in K2 compilation")
}
if (args.dependsOnDependencies == null) {
fail("Missing ${CommonCompilerArguments::dependsOnDependencies.name} in K2 compilation")
if (args.fragmentRefines == null) {
fail("Missing ${CommonCompilerArguments::fragmentRefines.name} in K2 compilation")
}
}
}