diff --git a/idea/idea-gradle/src/org/jetbrains/kotlin/idea/configuration/KotlinGradleSourceSetDataService.kt b/idea/idea-gradle/src/org/jetbrains/kotlin/idea/configuration/KotlinGradleSourceSetDataService.kt index fd534709b00..5aa22ce48c7 100644 --- a/idea/idea-gradle/src/org/jetbrains/kotlin/idea/configuration/KotlinGradleSourceSetDataService.kt +++ b/idea/idea-gradle/src/org/jetbrains/kotlin/idea/configuration/KotlinGradleSourceSetDataService.kt @@ -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, platformKind: TargetPlatformKind<*>?): String? { +private fun getExplicitOutputPath(moduleNode: DataNode, 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 } diff --git a/idea/idea-gradle/tests/org/jetbrains/kotlin/gradle/MultiplatformProjectImportingTest.kt b/idea/idea-gradle/tests/org/jetbrains/kotlin/gradle/MultiplatformProjectImportingTest.kt index 30df83a74bf..f2060b49715 100644 --- a/idea/idea-gradle/tests/org/jetbrains/kotlin/gradle/MultiplatformProjectImportingTest.kt +++ b/idea/idea-gradle/tests/org/jetbrains/kotlin/gradle/MultiplatformProjectImportingTest.kt @@ -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( diff --git a/idea/idea-jps-common/src/org/jetbrains/kotlin/config/KotlinFacetSettings.kt b/idea/idea-jps-common/src/org/jetbrains/kotlin/config/KotlinFacetSettings.kt index 7c71a715654..48c89ae5881 100644 --- a/idea/idea-jps-common/src/org/jetbrains/kotlin/config/KotlinFacetSettings.kt +++ b/idea/idea-jps-common/src/org/jetbrains/kotlin/config/KotlinFacetSettings.kt @@ -194,6 +194,7 @@ class KotlinFacetSettings { var implementedModuleName: String? = null + var productionOutputPath: String? = null var testOutputPath: String? = null } diff --git a/idea/idea-jps-common/src/org/jetbrains/kotlin/config/facetSerialization.kt b/idea/idea-jps-common/src/org/jetbrains/kotlin/config/facetSerialization.kt index fbb209aedd3..c37eab577f0 100644 --- a/idea/idea-jps-common/src/org/jetbrains/kotlin/config/facetSerialization.kt +++ b/idea/idea-jps-common/src/org/jetbrains/kotlin/config/facetSerialization.kt @@ -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)) }) diff --git a/idea/src/org/jetbrains/kotlin/idea/js/jsUtils.kt b/idea/src/org/jetbrains/kotlin/idea/js/jsUtils.kt index a5341d842ac..365a5967936 100644 --- a/idea/src/org/jetbrains/kotlin/idea/js/jsUtils.kt +++ b/idea/src/org/jetbrains/kotlin/idea/js/jsUtils.kt @@ -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