Gradle: Import production output path for JavaScript modules
This commit is contained in:
+4
-3
@@ -209,7 +209,8 @@ private fun configureFacetByGradleModule(
|
|||||||
|
|
||||||
with(kotlinFacet.configuration.settings) {
|
with(kotlinFacet.configuration.settings) {
|
||||||
implementedModuleName = (sourceSetNode ?: moduleNode).implementedModuleName
|
implementedModuleName = (sourceSetNode ?: moduleNode).implementedModuleName
|
||||||
testOutputPath = getExplicitTestOutputPath(moduleNode, platformKind)
|
productionOutputPath = getExplicitOutputPath(moduleNode, platformKind, "main")
|
||||||
|
testOutputPath = getExplicitOutputPath(moduleNode, platformKind, "test")
|
||||||
}
|
}
|
||||||
|
|
||||||
kotlinFacet.noVersionAutoAdvance()
|
kotlinFacet.noVersionAutoAdvance()
|
||||||
@@ -217,9 +218,9 @@ private fun configureFacetByGradleModule(
|
|||||||
return kotlinFacet
|
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
|
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
|
return K2JSCompilerArguments().apply { parseCommandLineArguments(k2jsArgumentList, this) }.outputFile
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+51
@@ -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
|
@Test
|
||||||
fun testJsTestOutputFileInProjectWithAndroid() {
|
fun testJsTestOutputFileInProjectWithAndroid() {
|
||||||
createProjectSubFile(
|
createProjectSubFile(
|
||||||
|
|||||||
@@ -194,6 +194,7 @@ class KotlinFacetSettings {
|
|||||||
|
|
||||||
var implementedModuleName: String? = null
|
var implementedModuleName: String? = null
|
||||||
|
|
||||||
|
var productionOutputPath: String? = null
|
||||||
var testOutputPath: String? = null
|
var testOutputPath: String? = null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -110,6 +110,9 @@ private fun readV2AndLaterConfig(element: Element): KotlinFacetSettings {
|
|||||||
XmlSerializer.deserializeInto(compilerArguments!!, it)
|
XmlSerializer.deserializeInto(compilerArguments!!, it)
|
||||||
compilerArguments!!.detectVersionAutoAdvance()
|
compilerArguments!!.detectVersionAutoAdvance()
|
||||||
}
|
}
|
||||||
|
productionOutputPath = element.getChild("productionOutputPath")?.let {
|
||||||
|
PathUtil.toSystemDependentName((it.content.firstOrNull() as? Text)?.textTrim)
|
||||||
|
} ?: (compilerArguments as? K2JSCompilerArguments)?.outputFile
|
||||||
testOutputPath = element.getChild("testOutputPath")?.let {
|
testOutputPath = element.getChild("testOutputPath")?.let {
|
||||||
PathUtil.toSystemDependentName((it.content.firstOrNull() as? Text)?.textTrim)
|
PathUtil.toSystemDependentName((it.content.firstOrNull() as? Text)?.textTrim)
|
||||||
} ?: (compilerArguments as? K2JSCompilerArguments)?.outputFile
|
} ?: (compilerArguments as? K2JSCompilerArguments)?.outputFile
|
||||||
@@ -237,6 +240,11 @@ private fun KotlinFacetSettings.writeLatestConfig(element: Element) {
|
|||||||
implementedModuleName?.let {
|
implementedModuleName?.let {
|
||||||
element.addContent(Element("implements").apply { addContent(it) })
|
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 {
|
testOutputPath?.let {
|
||||||
if (it != (compilerArguments as? K2JSCompilerArguments)?.outputFile) {
|
if (it != (compilerArguments as? K2JSCompilerArguments)?.outputFile) {
|
||||||
element.addContent(Element("testOutputPath").apply { addContent(PathUtil.toSystemIndependentName(it)) })
|
element.addContent(Element("testOutputPath").apply { addContent(PathUtil.toSystemIndependentName(it)) })
|
||||||
|
|||||||
@@ -38,6 +38,17 @@ val Module.jsTestOutputFilePath: String?
|
|||||||
return JpsPathUtil.urlToPath("$outputDir/${name}_test.js")
|
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)) {
|
fun Module.jsOrJsImpl() = when (TargetPlatformDetector.getPlatform(this)) {
|
||||||
is TargetPlatform.Common -> implementingModules.firstOrNull { TargetPlatformDetector.getPlatform(it) is JsPlatform }
|
is TargetPlatform.Common -> implementingModules.firstOrNull { TargetPlatformDetector.getPlatform(it) is JsPlatform }
|
||||||
is JsPlatform -> this
|
is JsPlatform -> this
|
||||||
|
|||||||
Reference in New Issue
Block a user