Support generation of relative path in JS source maps in JPS builder

See KT-20820
This commit is contained in:
Alexey Andreev
2017-10-20 15:03:04 +03:00
parent cb0482f53e
commit 2fbecfdd9c
4 changed files with 51 additions and 4 deletions
@@ -366,6 +366,18 @@ open class KotlinJpsBuildTest : AbstractKotlinJpsBuildTestCase() {
assertTrue("Source map for stdlib should be copied to $librarySourceMapFile", librarySourceMapFile.exists())
}
fun testKotlinJavaScriptProjectWithSourceMapRelativePaths() {
initProject(JS_STDLIB)
buildAllModules().assertSuccessful()
val sourceMapContent = File(getOutputDir(PROJECT_NAME), "$PROJECT_NAME.js.map").readText()
val expectedPath = "../../../src/pkg/test1.kt"
assertTrue("Source map file should contain relative path ($expectedPath)", sourceMapContent.contains("\"$expectedPath\""))
val librarySourceMapFile = File(getOutputDir(PROJECT_NAME), "lib/kotlin.js.map")
assertTrue("Source map for stdlib should be copied to $librarySourceMapFile", librarySourceMapFile.exists())
}
fun testKotlinJavaScriptProjectWithTwoModules() {
initProject(JS_STDLIB)
buildAllModules().assertSuccessful()
@@ -648,10 +648,21 @@ class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR) {
val compilerSettings = JpsKotlinCompilerSettings.getCompilerSettings(representativeModule)
val k2JsArguments = JpsKotlinCompilerSettings.getK2JsCompilerArguments(representativeModule)
val sourceRoots = representativeModule.contentRootsList.urls
.map { URI.create(it) }
.filter { it.scheme == "file" }
.map { File(it.path) }
// Compiler starts to produce path relative to base dirs in source maps if at least one statement is true:
// 1) base dirs are specified;
// 2) prefix is specified (i.e. non-empty)
// Otherwise compiler produces paths relative to source maps location.
// We don't have UI to configure base dirs, but we have UI to configure prefix.
// If prefix is not specified (empty) in UI, we want to produce paths relative to source maps location
val sourceRoots = if (k2JsArguments.sourceMapPrefix.isNullOrBlank()) {
emptyList()
}
else {
representativeModule.contentRootsList.urls
.map { URI.create(it) }
.filter { it.scheme == "file" }
.map { File(it.path) }
}
val friendPaths = KotlinBuilderModuleScriptGenerator.getProductionModulesWhichInternalsAreVisible(representativeTarget).mapNotNull {
val file = getOutputMetaFile(it, false)
@@ -0,0 +1,17 @@
<?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" />
</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>
@@ -0,0 +1,7 @@
package pkg
var log = ""
fun foo(x: String) {
log += "$x;"
}