Add support for relative JS source map paths in JPS
This commit is contained in:
@@ -298,6 +298,15 @@ class KotlinJpsBuildTest : AbstractKotlinJpsBuildTestCase() {
|
|||||||
checkWhen(touch("src/test1.kt"), null, k2jsOutput(PROJECT_NAME))
|
checkWhen(touch("src/test1.kt"), null, k2jsOutput(PROJECT_NAME))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun testKotlinJavaScriptProjectWithSourceMap() {
|
||||||
|
initProject(JS_STDLIB)
|
||||||
|
buildAllModules().assertSuccessful()
|
||||||
|
|
||||||
|
val sourceMapContent = File(getOutputDir(PROJECT_NAME), "$PROJECT_NAME.js.map").readText()
|
||||||
|
val expectedPath = "prefix-dir/pkg/test1.kt"
|
||||||
|
assertTrue("Source map file should contain relative path ($expectedPath)", sourceMapContent.contains("\"$expectedPath\""))
|
||||||
|
}
|
||||||
|
|
||||||
fun testKotlinJavaScriptProjectWithTwoModules() {
|
fun testKotlinJavaScriptProjectWithTwoModules() {
|
||||||
initProject(JS_STDLIB)
|
initProject(JS_STDLIB)
|
||||||
buildAllModules().assertSuccessful()
|
buildAllModules().assertSuccessful()
|
||||||
@@ -690,8 +699,7 @@ class KotlinJpsBuildTest : AbstractKotlinJpsBuildTestCase() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun contentOfOutputDir(moduleName: String): Set<String> {
|
private fun contentOfOutputDir(moduleName: String): Set<String> {
|
||||||
val outputDir = "out/production/$moduleName"
|
val baseDir = getOutputDir(moduleName)
|
||||||
val baseDir = File(workDir, outputDir)
|
|
||||||
val files = FileUtil.findFilesByMask(Pattern.compile(".*"), baseDir)
|
val files = FileUtil.findFilesByMask(Pattern.compile(".*"), baseDir)
|
||||||
val result = HashSet<String>()
|
val result = HashSet<String>()
|
||||||
for (file in files) {
|
for (file in files) {
|
||||||
@@ -702,6 +710,8 @@ class KotlinJpsBuildTest : AbstractKotlinJpsBuildTestCase() {
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun getOutputDir(moduleName: String): File = File(workDir, "out/production/$moduleName")
|
||||||
|
|
||||||
fun testReexportedDependency() {
|
fun testReexportedDependency() {
|
||||||
initProject()
|
initProject()
|
||||||
AbstractKotlinJpsBuildTestCase.addKotlinRuntimeDependency(JpsJavaDependencyScope.COMPILE, ContainerUtil.filter(myProject.modules, object : Condition<JpsModule> {
|
AbstractKotlinJpsBuildTestCase.addKotlinRuntimeDependency(JpsJavaDependencyScope.COMPILE, ContainerUtil.filter(myProject.modules, object : Condition<JpsModule> {
|
||||||
|
|||||||
@@ -20,7 +20,10 @@ import com.intellij.util.xmlb.XmlSerializerUtil
|
|||||||
import org.jetbrains.jps.api.GlobalOptions
|
import org.jetbrains.jps.api.GlobalOptions
|
||||||
import org.jetbrains.kotlin.cli.common.ExitCode
|
import org.jetbrains.kotlin.cli.common.ExitCode
|
||||||
import org.jetbrains.kotlin.cli.common.KOTLIN_COMPILER_ENVIRONMENT_KEEPALIVE_PROPERTY
|
import org.jetbrains.kotlin.cli.common.KOTLIN_COMPILER_ENVIRONMENT_KEEPALIVE_PROPERTY
|
||||||
import org.jetbrains.kotlin.cli.common.arguments.*
|
import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments
|
||||||
|
import org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments
|
||||||
|
import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments
|
||||||
|
import org.jetbrains.kotlin.cli.common.arguments.mergeBeans
|
||||||
import org.jetbrains.kotlin.config.CompilerSettings
|
import org.jetbrains.kotlin.config.CompilerSettings
|
||||||
import org.jetbrains.kotlin.config.additionalArgumentsAsList
|
import org.jetbrains.kotlin.config.additionalArgumentsAsList
|
||||||
import org.jetbrains.kotlin.daemon.client.CompileServiceSession
|
import org.jetbrains.kotlin.daemon.client.CompileServiceSession
|
||||||
@@ -81,6 +84,7 @@ class JpsKotlinCompilerRunner : KotlinCompilerRunner<JpsCompilerEnvironment>() {
|
|||||||
compilerSettings: CompilerSettings,
|
compilerSettings: CompilerSettings,
|
||||||
environment: JpsCompilerEnvironment,
|
environment: JpsCompilerEnvironment,
|
||||||
sourceFiles: Collection<File>,
|
sourceFiles: Collection<File>,
|
||||||
|
sourceRoots: Collection<File>,
|
||||||
libraries: List<String>,
|
libraries: List<String>,
|
||||||
friendModules: List<String>,
|
friendModules: List<String>,
|
||||||
outputFile: File
|
outputFile: File
|
||||||
@@ -92,6 +96,10 @@ class JpsKotlinCompilerRunner : KotlinCompilerRunner<JpsCompilerEnvironment>() {
|
|||||||
log.debug("K2JS: merged arguments: " + ArgumentUtils.convertArgumentsToStringList(arguments))
|
log.debug("K2JS: merged arguments: " + ArgumentUtils.convertArgumentsToStringList(arguments))
|
||||||
|
|
||||||
setupK2JsArguments(outputFile, sourceFiles, libraries, friendModules, arguments)
|
setupK2JsArguments(outputFile, sourceFiles, libraries, friendModules, arguments)
|
||||||
|
if (arguments.sourceMap) {
|
||||||
|
arguments.sourceMapSourceRoots = sourceRoots.joinToString(File.pathSeparator) { it.path }
|
||||||
|
}
|
||||||
|
|
||||||
log.debug("K2JS: arguments after setup" + ArgumentUtils.convertArgumentsToStringList(arguments))
|
log.debug("K2JS: arguments after setup" + ArgumentUtils.convertArgumentsToStringList(arguments))
|
||||||
|
|
||||||
withCompilerSettings(compilerSettings) {
|
withCompilerSettings(compilerSettings) {
|
||||||
|
|||||||
@@ -662,13 +662,16 @@ class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR) {
|
|||||||
val compilerSettings = JpsKotlinCompilerSettings.getCompilerSettings(representativeModule)
|
val compilerSettings = JpsKotlinCompilerSettings.getCompilerSettings(representativeModule)
|
||||||
val k2JsArguments = JpsKotlinCompilerSettings.getK2JsCompilerArguments(representativeModule)
|
val k2JsArguments = JpsKotlinCompilerSettings.getK2JsCompilerArguments(representativeModule)
|
||||||
|
|
||||||
|
val sourceRoots = KotlinSourceFileCollector.getRelevantSourceRoots(representativeTarget).map { it.file }
|
||||||
|
|
||||||
val friendPaths = KotlinBuilderModuleScriptGenerator.getProductionModulesWhichInternalsAreVisible(representativeTarget).mapNotNull {
|
val friendPaths = KotlinBuilderModuleScriptGenerator.getProductionModulesWhichInternalsAreVisible(representativeTarget).mapNotNull {
|
||||||
val file = getOutputMetaFile(it, false)
|
val file = getOutputMetaFile(it, false)
|
||||||
if (file.exists()) file.absolutePath.toString() else null
|
if (file.exists()) file.absolutePath.toString() else null
|
||||||
}
|
}
|
||||||
|
|
||||||
val compilerRunner = JpsKotlinCompilerRunner()
|
val compilerRunner = JpsKotlinCompilerRunner()
|
||||||
compilerRunner.runK2JsCompiler(commonArguments, k2JsArguments, compilerSettings, environment, sourceFiles, libraries, friendPaths, outputFile)
|
compilerRunner.runK2JsCompiler(commonArguments, k2JsArguments, compilerSettings, environment, sourceFiles, sourceRoots,
|
||||||
|
libraries, friendPaths, outputFile)
|
||||||
return environment.outputItemsCollector
|
return environment.outputItemsCollector
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -124,7 +124,7 @@ public class KotlinSourceFileCollector {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Iterable<JpsModuleSourceRoot> getRelevantSourceRoots(ModuleBuildTarget target) {
|
public static Iterable<JpsModuleSourceRoot> getRelevantSourceRoots(ModuleBuildTarget target) {
|
||||||
JavaSourceRootType sourceRootType = target.isTests() ? JavaSourceRootType.TEST_SOURCE : JavaSourceRootType.SOURCE;
|
JavaSourceRootType sourceRootType = target.isTests() ? JavaSourceRootType.TEST_SOURCE : JavaSourceRootType.SOURCE;
|
||||||
|
|
||||||
//noinspection unchecked
|
//noinspection unchecked
|
||||||
|
|||||||
+12
@@ -0,0 +1,12 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="JAVA_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||||
|
<exclude-output />
|
||||||
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="jdk" jdkName="IDEA_JDK" jdkType="JavaSDK" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
<orderEntry type="module" module-name="kotlinProject" />
|
||||||
|
</component>
|
||||||
|
</module>
|
||||||
+18
@@ -0,0 +1,18 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="CompilerConfiguration">
|
||||||
|
<option name="DEFAULT_COMPILER" value="Javac" />
|
||||||
|
</component>
|
||||||
|
<component name="Kotlin2JsCompilerArguments">
|
||||||
|
<option name="sourceMap" value="true" />
|
||||||
|
<option name="sourceMapPrefix" value="prefix-dir/" />
|
||||||
|
</component>
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/kotlinProject.iml" filepath="$PROJECT_DIR$/kotlinProject.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_6" assert-keyword="true" jdk-15="true" project-jdk-name="IDEA_JDK" project-jdk-type="JavaSDK">
|
||||||
|
<output url="file://$PROJECT_DIR$/out" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
+7
@@ -0,0 +1,7 @@
|
|||||||
|
package pkg
|
||||||
|
|
||||||
|
var log = ""
|
||||||
|
|
||||||
|
fun foo(x: String) {
|
||||||
|
log += "$x;"
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user