Perform non-IC build when JS lib is changed
This commit is contained in:
+14
-1
@@ -16,12 +16,12 @@
|
||||
|
||||
package org.jetbrains.kotlin.incremental
|
||||
|
||||
import com.intellij.openapi.util.io.FileUtil
|
||||
import org.jetbrains.kotlin.build.GeneratedFile
|
||||
import org.jetbrains.kotlin.cli.common.ExitCode
|
||||
import org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments
|
||||
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
|
||||
import org.jetbrains.kotlin.cli.js.K2JSCompiler
|
||||
import org.jetbrains.kotlin.cli.jvm.K2JVMCompiler
|
||||
import org.jetbrains.kotlin.config.IncrementalCompilation
|
||||
import org.jetbrains.kotlin.config.Services
|
||||
import org.jetbrains.kotlin.incremental.components.LookupTracker
|
||||
@@ -83,6 +83,16 @@ class IncrementalJsCompilerRunner(
|
||||
override fun calculateSourcesToCompile(caches: IncrementalJsCachesManager, changedFiles: ChangedFiles.Known, args: K2JSCompilerArguments): CompilationMode {
|
||||
if (BuildInfo.read(lastBuildInfoFile) == null) return CompilationMode.Rebuild { "No information on previous build" }
|
||||
|
||||
val libs = (args.libraries ?: "").split(File.pathSeparator).mapTo(HashSet()) { File(it) }
|
||||
val libsDirs = libs.filter { it.isDirectory }
|
||||
|
||||
val changedLib = changedFiles.allAsSequence.find { it in libs }
|
||||
?: changedFiles.allAsSequence.find { changedFile ->
|
||||
libsDirs.any { libDir -> FileUtil.isAncestor(libDir, changedFile, true) }
|
||||
}
|
||||
|
||||
if (changedLib != null) return CompilationMode.Rebuild { "Library has been changed: $changedLib" }
|
||||
|
||||
return CompilationMode.Incremental(getDirtyFiles(changedFiles))
|
||||
}
|
||||
|
||||
@@ -133,4 +143,7 @@ class IncrementalJsCompilerRunner(
|
||||
args.freeArgs = freeArgsBackup
|
||||
}
|
||||
}
|
||||
|
||||
private val ChangedFiles.Known.allAsSequence: Sequence<File>
|
||||
get() = modified.asSequence() + removed.asSequence()
|
||||
}
|
||||
+6
@@ -404,6 +404,12 @@ abstract class BaseGradleIT {
|
||||
}
|
||||
}
|
||||
|
||||
val Project.allKotlinFiles: Iterable<File>
|
||||
get() = projectDir.allKotlinFiles()
|
||||
|
||||
fun Project.projectFile(name: String): File =
|
||||
projectDir.getFileByName(name)
|
||||
|
||||
fun CompiledProject.assertCompiledJavaSources(
|
||||
sources: Iterable<String>,
|
||||
weakTesting: Boolean = false
|
||||
|
||||
+12
-9
@@ -242,22 +242,25 @@ class Kotlin2JsGradlePluginIT : BaseGradleIT() {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testIncrementalCompilation() {
|
||||
val project = Project("kotlin2JsICProject", "4.0")
|
||||
project.build("build") {
|
||||
fun testIncrementalCompilation() = Project("kotlin2JsICProject", "4.0").run {
|
||||
build("build") {
|
||||
assertSuccessful()
|
||||
assertContains(USING_EXPERIMENTAL_JS_INCREMENTAL_COMPILATION_MESSAGE)
|
||||
assertCompiledKotlinSources(project.relativize(project.projectDir.allKotlinFiles()))
|
||||
assertCompiledKotlinSources(project.relativize(allKotlinFiles))
|
||||
}
|
||||
|
||||
val aKt = project.projectDir.getFileByName("A.kt").apply {
|
||||
modify { it.replace("val x: String", "val x: Int") }
|
||||
build("build") {
|
||||
assertSuccessful()
|
||||
assertCompiledKotlinSources(emptyList())
|
||||
}
|
||||
val useAKt = project.projectDir.getFileByName("useA.kt")
|
||||
project.build("build") {
|
||||
|
||||
projectFile("A.kt").modify {
|
||||
it.replace("val x = 0", "val x = \"a\"")
|
||||
}
|
||||
build("build") {
|
||||
assertSuccessful()
|
||||
assertContains(USING_EXPERIMENTAL_JS_INCREMENTAL_COMPILATION_MESSAGE)
|
||||
assertCompiledKotlinSources(project.relativize(aKt, useAKt))
|
||||
assertCompiledKotlinSources(project.relativize(allKotlinFiles - projectFile("DummyInLibMain.kt")))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
apply plugin: 'kotlin2js'
|
||||
|
||||
dependencies {
|
||||
compile "org.jetbrains.kotlin:kotlin-stdlib-js:$kotlin_version"
|
||||
compile project(":lib")
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
class DummyInAppMain
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
fun useAInAppMain(a: A) {
|
||||
println(a.x)
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
class DummyInAppTest
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
fun useAInAppTest(a: A) {
|
||||
println(a.x)
|
||||
}
|
||||
+5
-38
@@ -8,42 +8,9 @@ buildscript {
|
||||
}
|
||||
}
|
||||
|
||||
apply plugin: 'kotlin2js'
|
||||
|
||||
repositories {
|
||||
mavenLocal()
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile "org.jetbrains.kotlin:kotlin-stdlib-js:$kotlin_version"
|
||||
}
|
||||
|
||||
task jarSources(type: Jar) {
|
||||
from sourceSets.main.allSource
|
||||
classifier = 'source'
|
||||
}
|
||||
artifacts {
|
||||
compile jarSources
|
||||
}
|
||||
|
||||
def outDir = "${buildDir}/kotlin2js/main/"
|
||||
|
||||
compileKotlin2Js.kotlinOptions.outputFile = outDir + "test-library.js"
|
||||
|
||||
jar {
|
||||
from sourceSets.main.allSource
|
||||
include "**/*.kt"
|
||||
|
||||
from outDir
|
||||
include "**/*.js"
|
||||
|
||||
manifest {
|
||||
attributes(
|
||||
"Specification-Title": "Kotlin JavaScript Lib",
|
||||
"Kotlin-JS-Module-Name": "test-library"
|
||||
)
|
||||
subprojects {
|
||||
repositories {
|
||||
mavenLocal()
|
||||
mavenCentral()
|
||||
}
|
||||
}
|
||||
|
||||
jar.dependsOn(compileKotlin2Js)
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
apply plugin: 'kotlin2js'
|
||||
|
||||
dependencies {
|
||||
compile "org.jetbrains.kotlin:kotlin-stdlib-js:$kotlin_version"
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
class A {
|
||||
val x = 0
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
class DummyInLibMain
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
fun useAInLibMain(a: A) {
|
||||
println(a.x)
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
class DummyInLibTest
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
fun useAInLibTest(a: A) {
|
||||
println(a.x)
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
include ':app', ":lib"
|
||||
-19
@@ -1,19 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package foo
|
||||
|
||||
class A(val x: String)
|
||||
-19
@@ -1,19 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package foo
|
||||
|
||||
fun dummy() {}
|
||||
-19
@@ -1,19 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package foo
|
||||
|
||||
fun useA(a: A) = a.x
|
||||
Reference in New Issue
Block a user