Perform non-IC build when JS lib is changed

This commit is contained in:
Alexey Tsvetkov
2017-10-23 22:55:54 +03:00
parent be6474593d
commit e83f1b138b
19 changed files with 68 additions and 105 deletions
@@ -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()
}
@@ -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
@@ -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")))
}
}
}
@@ -0,0 +1,6 @@
apply plugin: 'kotlin2js'
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-js:$kotlin_version"
compile project(":lib")
}
@@ -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)
}
@@ -0,0 +1,5 @@
apply plugin: 'kotlin2js'
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-js:$kotlin_version"
}
@@ -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)
@@ -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() {}
@@ -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