Gradle: Import production output path for JavaScript modules

This commit is contained in:
Alexey Sedunov
2018-01-24 16:27:02 +03:00
parent 80887a84ca
commit 1f7fab837f
5 changed files with 75 additions and 3 deletions
@@ -209,7 +209,8 @@ private fun configureFacetByGradleModule(
with(kotlinFacet.configuration.settings) {
implementedModuleName = (sourceSetNode ?: moduleNode).implementedModuleName
testOutputPath = getExplicitTestOutputPath(moduleNode, platformKind)
productionOutputPath = getExplicitOutputPath(moduleNode, platformKind, "main")
testOutputPath = getExplicitOutputPath(moduleNode, platformKind, "test")
}
kotlinFacet.noVersionAutoAdvance()
@@ -217,9 +218,9 @@ private fun configureFacetByGradleModule(
return kotlinFacet
}
private fun getExplicitTestOutputPath(moduleNode: DataNode<ModuleData>, platformKind: TargetPlatformKind<*>?): String? {
private fun getExplicitOutputPath(moduleNode: DataNode<ModuleData>, platformKind: TargetPlatformKind<*>?, sourceSet: String): String? {
if (platformKind !is TargetPlatformKind.JavaScript) return null
val k2jsArgumentList = moduleNode.compilerArgumentsBySourceSet?.get("test")?.currentArguments ?: return null
val k2jsArgumentList = moduleNode.compilerArgumentsBySourceSet?.get(sourceSet)?.currentArguments ?: return null
return K2JSCompilerArguments().apply { parseCommandLineArguments(k2jsArgumentList, this) }.outputFile
}
@@ -533,6 +533,57 @@ class MultiplatformProjectImportingTest : GradleImportingTestCase() {
)
}
@Test
fun testJsProductionOutputFile() {
createProjectSubFile(
"settings.gradle",
"include ':project1', ':project2', ':project3'"
)
val kotlinVersion = "1.1.51"
createProjectSubFile("build.gradle", """
buildscript {
repositories {
jcenter()
maven { url 'https://maven.google.com' }
}
dependencies {
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion")
classpath 'com.android.tools.build:gradle:2.3.3'
}
}
project('project1') {
apply plugin: 'kotlin-platform-common'
}
project('project2') {
repositories {
mavenCentral()
}
apply plugin: 'kotlin-platform-js'
dependencies {
implement project(':project1')
}
}
""")
importProject()
TestCase.assertEquals(
projectPath + "/project2/build/classes/main/project2.js",
PathUtil.toSystemIndependentName(KotlinFacet.get (getModule("project2_main"))!!.configuration.settings.productionOutputPath)
)
TestCase.assertEquals(
projectPath + "/project2/build/classes/main/project2.js",
PathUtil.toSystemIndependentName(KotlinFacet.get (getModule("project2_test"))!!.configuration.settings.productionOutputPath)
)
}
@Test
fun testJsTestOutputFileInProjectWithAndroid() {
createProjectSubFile(
@@ -194,6 +194,7 @@ class KotlinFacetSettings {
var implementedModuleName: String? = null
var productionOutputPath: String? = null
var testOutputPath: String? = null
}
@@ -110,6 +110,9 @@ private fun readV2AndLaterConfig(element: Element): KotlinFacetSettings {
XmlSerializer.deserializeInto(compilerArguments!!, it)
compilerArguments!!.detectVersionAutoAdvance()
}
productionOutputPath = element.getChild("productionOutputPath")?.let {
PathUtil.toSystemDependentName((it.content.firstOrNull() as? Text)?.textTrim)
} ?: (compilerArguments as? K2JSCompilerArguments)?.outputFile
testOutputPath = element.getChild("testOutputPath")?.let {
PathUtil.toSystemDependentName((it.content.firstOrNull() as? Text)?.textTrim)
} ?: (compilerArguments as? K2JSCompilerArguments)?.outputFile
@@ -237,6 +240,11 @@ private fun KotlinFacetSettings.writeLatestConfig(element: Element) {
implementedModuleName?.let {
element.addContent(Element("implements").apply { addContent(it) })
}
productionOutputPath?.let {
if (it != (compilerArguments as? K2JSCompilerArguments)?.outputFile) {
element.addContent(Element("productionOutputPath").apply { addContent(PathUtil.toSystemIndependentName(it)) })
}
}
testOutputPath?.let {
if (it != (compilerArguments as? K2JSCompilerArguments)?.outputFile) {
element.addContent(Element("testOutputPath").apply { addContent(PathUtil.toSystemIndependentName(it)) })
@@ -38,6 +38,17 @@ val Module.jsTestOutputFilePath: String?
return JpsPathUtil.urlToPath("$outputDir/${name}_test.js")
}
val Module.jsProductionOutputFilePath: String?
get() {
if (!shouldUseJpsOutput) {
(KotlinFacet.get(this)?.configuration?.settings?.productionOutputPath)?.let { return it }
}
val compilerExtension = CompilerModuleExtension.getInstance(this)
val outputDir = compilerExtension?.compilerOutputUrl ?: return null
return JpsPathUtil.urlToPath("$outputDir/$name.js")
}
fun Module.jsOrJsImpl() = when (TargetPlatformDetector.getPlatform(this)) {
is TargetPlatform.Common -> implementingModules.firstOrNull { TargetPlatformDetector.getPlatform(it) is JsPlatform }
is JsPlatform -> this