Added existsCompat and its usages for checking tasks' inputs.
#KT-54232 Ready for Review Merge-request: KT-MR-11705 Merged-by: Dmitrii Krasnov <Dmitrii.Krasnov@jetbrains.com>
This commit is contained in:
committed by
Space Team
parent
9c8b215bbb
commit
dbddac3e80
+25
-2
@@ -21,13 +21,16 @@ import org.jetbrains.kotlin.gradle.targets.js.yarn.YarnLockCopyTask.Companion.YA
|
||||
import org.jetbrains.kotlin.gradle.tasks.USING_JS_IR_BACKEND_MESSAGE
|
||||
import org.jetbrains.kotlin.gradle.testbase.*
|
||||
import org.jetbrains.kotlin.gradle.testbase.TestVersions.Gradle.G_7_6
|
||||
import org.jetbrains.kotlin.gradle.util.replaceText
|
||||
import org.junit.jupiter.api.DisplayName
|
||||
import org.junit.jupiter.api.condition.DisabledIf
|
||||
import java.nio.file.Files
|
||||
import java.util.zip.ZipFile
|
||||
import kotlin.io.path.*
|
||||
import kotlin.streams.toList
|
||||
import kotlin.test.*
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertFalse
|
||||
import kotlin.test.assertNotNull
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
@JsGradlePluginTests
|
||||
class Kotlin2JsIrGradlePluginIT : KGPBaseTest() {
|
||||
@@ -547,6 +550,26 @@ class Kotlin2JsIrGradlePluginIT : KGPBaseTest() {
|
||||
}
|
||||
}
|
||||
|
||||
@DisplayName("Not existed friend dependencies does not affect compileKotlinJs UTD")
|
||||
@GradleTest
|
||||
fun testFriendDependenciesDoesNotExist(gradleVersion: GradleVersion) {
|
||||
project("kotlin-js-with-friend-paths", gradleVersion) {
|
||||
build("assemble")
|
||||
|
||||
val oldFriendPaths = "friendPaths.from(project(\":lib\").buildDir.resolve(\"libs/lib.klib\"))"
|
||||
val appModuleGradleBuildKts = subProject("app").buildGradleKts
|
||||
assertFileInProjectContains(appModuleGradleBuildKts.absolutePathString(), oldFriendPaths)
|
||||
appModuleGradleBuildKts.replaceText(
|
||||
oldFriendPaths,
|
||||
"friendPaths.from(project(\":lib\").buildDir.resolve(\"libs/lib.klib\"), project(\":lib\").buildDir.resolve(\"libs/not_existed_lib.klib\"))"
|
||||
)
|
||||
|
||||
build("assemble") {
|
||||
assertTasksUpToDate(":app:compileKotlinJs")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@DisplayName("klib fingerprints")
|
||||
@GradleTest
|
||||
fun testKlibFingerprints(gradleVersion: GradleVersion) {
|
||||
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
plugins {
|
||||
kotlin("js")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(project(":lib"))
|
||||
}
|
||||
|
||||
kotlin {
|
||||
js {
|
||||
browser {}
|
||||
binaries.executable()
|
||||
}
|
||||
}
|
||||
|
||||
tasks.withType<org.jetbrains.kotlin.gradle.tasks.Kotlin2JsCompile>().configureEach {
|
||||
friendPaths.from(project(":lib").buildDir.resolve("libs/lib.klib"))
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
package com.example
|
||||
|
||||
import com.example.LibClass
|
||||
|
||||
fun main() {
|
||||
println(LibClass().helloFromFriend())
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
plugins {
|
||||
kotlin("js").apply(false)
|
||||
}
|
||||
|
||||
group = "com.example"
|
||||
version = "1.0"
|
||||
|
||||
allprojects {
|
||||
repositories {
|
||||
mavenLocal()
|
||||
mavenCentral()
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
plugins {
|
||||
kotlin("js")
|
||||
}
|
||||
|
||||
kotlin {
|
||||
js {
|
||||
useCommonJs()
|
||||
browser {
|
||||
}
|
||||
}
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
package com.example
|
||||
|
||||
internal class LibClass {
|
||||
fun helloFromFriend() = "Hello from -Xfriend-modules"
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
rootProject.name = "kotlin-js-with-friend-paths"
|
||||
|
||||
include("lib")
|
||||
include("app")
|
||||
+4
-1
@@ -19,6 +19,7 @@ import org.jetbrains.kotlin.gradle.plugin.diagnostics.UsesKotlinToolingDiagnosti
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.Framework
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.NativeBuildType
|
||||
import org.jetbrains.kotlin.gradle.tasks.*
|
||||
import org.jetbrains.kotlin.gradle.utils.existsCompat
|
||||
import org.jetbrains.kotlin.gradle.utils.lowerCamelCaseName
|
||||
import org.jetbrains.kotlin.konan.target.HostManager
|
||||
import org.jetbrains.kotlin.konan.target.KonanTarget
|
||||
@@ -181,7 +182,9 @@ internal constructor(
|
||||
@get:PathSensitive(PathSensitivity.ABSOLUTE)
|
||||
@get:SkipWhenEmpty
|
||||
val inputFrameworkFiles: Collection<File>
|
||||
get() = groupedFrameworkFiles.values.flatten().map { it.file }.filter { it.exists() }
|
||||
get() = groupedFrameworkFiles.values.flatten().map { it.file }.filter {
|
||||
it.existsCompat()
|
||||
}
|
||||
|
||||
/**
|
||||
* A parent directory for the XCFramework.
|
||||
|
||||
+2
-3
@@ -41,6 +41,7 @@ import org.jetbrains.kotlin.gradle.targets.js.ir.PRODUCE_UNZIPPED_KLIB
|
||||
import org.jetbrains.kotlin.gradle.targets.js.ir.PRODUCE_ZIPPED_KLIB
|
||||
import org.jetbrains.kotlin.gradle.tasks.internal.KotlinJsOptionsCompat
|
||||
import org.jetbrains.kotlin.gradle.utils.getFile
|
||||
import org.jetbrains.kotlin.gradle.utils.existsCompat
|
||||
import org.jetbrains.kotlin.gradle.utils.isParentOf
|
||||
import org.jetbrains.kotlin.gradle.utils.newInstance
|
||||
import org.jetbrains.kotlin.gradle.utils.toPathsArray
|
||||
@@ -220,9 +221,7 @@ abstract class Kotlin2JsCompile @Inject constructor(
|
||||
internal val friendDependencies: FileCollection = objectFactory
|
||||
.fileCollection()
|
||||
.from(friendPaths)
|
||||
.filter {
|
||||
it.exists() && libraryFilter(it)
|
||||
}
|
||||
.filter { libraryFilter(it) }
|
||||
|
||||
@get:Internal
|
||||
internal val sourceMapBaseDir: Property<Directory> = objectFactory
|
||||
|
||||
+16
@@ -129,3 +129,19 @@ internal fun Provider<RegularFile>.getFile(): File = get().asFile
|
||||
|
||||
@JvmName("getDirectoryAsFile") // avoids jvm signature clash
|
||||
internal fun Provider<Directory>.getFile(): File = get().asFile
|
||||
|
||||
|
||||
/**
|
||||
* Checks if the file exists, taking into account compatibility with different versions of Gradle.
|
||||
* It should be used instead of [File.exists] in checking UPD inputs. See KT-54232 for more info.
|
||||
*
|
||||
* @return `true` if the file exists, `false` otherwise.
|
||||
*
|
||||
* NOTE: You can remove this method and all its usages since the minimal supported version of gradle become 8.0
|
||||
*/
|
||||
internal fun File.existsCompat(): Boolean =
|
||||
if (isGradleVersionAtLeast(8, 0)) {
|
||||
true
|
||||
} else {
|
||||
exists()
|
||||
}
|
||||
Reference in New Issue
Block a user