Filter some characters out of module names passed to Kotlin from Gradle
This addresses the cases when a module name contains a slash (e.g. when the Gradle project name was set this way to point Gradle to the directory), which led to Kotlin module file being placed under a subdirectory of META-INF and thus undiscoverable for the compiler and reflect. Additionally, this fix removes characters \n, \r, \t whose presence in a module name caused compilation failures. Issue #KT-20608 Fixed
This commit is contained in:
+14
@@ -771,4 +771,18 @@ class KotlinGradleIT : BaseGradleIT() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testModuleNameFiltering() = with(Project("typeAlias")) { // Use a Project with a top-level typealias
|
||||
setupWorkingDir()
|
||||
|
||||
gradleBuildScript().appendText("\n" + """archivesBaseName = 'a/really\\tricky\n\rmodule\tname'""")
|
||||
build("classes") {
|
||||
assertSuccessful()
|
||||
|
||||
val metaInfDir = File(projectDir, kotlinClassesDir() + "META-INF")
|
||||
assertNotNull(metaInfDir.listFiles().singleOrNull { it.name.endsWith(".kotlin_module") })
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+6
-1
@@ -164,7 +164,7 @@ abstract class AbstractKotlinCompile<T : CommonCompilerArguments>() : AbstractKo
|
||||
val baseName = project.convention.findPlugin(BasePluginConvention::class.java)?.archivesBaseName
|
||||
?: project.name
|
||||
val suffix = if (sourceSetName == "main") "" else "_$sourceSetName"
|
||||
return "$baseName$suffix"
|
||||
return filterModuleName("${baseName}_$suffix")
|
||||
}
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
@@ -538,6 +538,11 @@ open class Kotlin2JsCompile() : AbstractKotlinCompile<K2JSCompilerArguments>(),
|
||||
}
|
||||
}
|
||||
|
||||
private val invalidModuleNameCharactersRegex = """[\\/\r\n\t]""".toRegex()
|
||||
|
||||
private fun filterModuleName(moduleName: String): String =
|
||||
moduleName.replace(invalidModuleNameCharactersRegex, "_")
|
||||
|
||||
private fun Task.getGradleVersion(): ParsedGradleVersion? {
|
||||
val gradleVersion = project.gradle.gradleVersion
|
||||
val result = ParsedGradleVersion.parse(gradleVersion)
|
||||
|
||||
Reference in New Issue
Block a user