[Gradle] Propagate offline mode to Native platform libs generator
^KT-49247
This commit is contained in:
committed by
Space
parent
a28884b1c3
commit
fa951f8f9c
+63
-5
@@ -18,9 +18,9 @@ import org.jetbrains.kotlin.konan.target.HostManager
|
|||||||
import org.jetbrains.kotlin.konan.target.KonanTarget
|
import org.jetbrains.kotlin.konan.target.KonanTarget
|
||||||
import org.jetbrains.kotlin.konan.target.presetName
|
import org.jetbrains.kotlin.konan.target.presetName
|
||||||
import org.jetbrains.kotlin.konan.util.DependencyDirectories
|
import org.jetbrains.kotlin.konan.util.DependencyDirectories
|
||||||
import org.junit.Assume
|
import org.junit.*
|
||||||
import org.junit.BeforeClass
|
import org.junit.rules.TemporaryFolder
|
||||||
import org.junit.Test
|
import kotlin.test.assertFalse
|
||||||
import kotlin.test.assertTrue
|
import kotlin.test.assertTrue
|
||||||
|
|
||||||
class NativePlatformLibsIT : BaseGradleIT() {
|
class NativePlatformLibsIT : BaseGradleIT() {
|
||||||
@@ -33,6 +33,16 @@ class NativePlatformLibsIT : BaseGradleIT() {
|
|||||||
// We temporary disable it for windows until a proper fix is found.
|
// We temporary disable it for windows until a proper fix is found.
|
||||||
Assume.assumeFalse(HostManager.hostIsMingw)
|
Assume.assumeFalse(HostManager.hostIsMingw)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@field:ClassRule
|
||||||
|
@JvmField
|
||||||
|
val tempDir = TemporaryFolder()
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
@AfterClass
|
||||||
|
fun deleteTempDir() {
|
||||||
|
tempDir.delete()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override val defaultGradleVersion: GradleVersionRequired
|
override val defaultGradleVersion: GradleVersionRequired
|
||||||
@@ -81,8 +91,11 @@ class NativePlatformLibsIT : BaseGradleIT() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun Project.buildWithLightDist(vararg tasks: String, check: CompiledProject.() -> Unit) =
|
private fun Project.buildWithLightDist(
|
||||||
build(*tasks, "-Pkotlin.native.distribution.type=light", check = check)
|
vararg tasks: String,
|
||||||
|
options: BuildOptions = defaultBuildOptions(),
|
||||||
|
check: CompiledProject.() -> Unit
|
||||||
|
) = build(*tasks, "-Pkotlin.native.distribution.type=light", options = options, check = check)
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testNoGenerationForOldCompiler() = with(platformLibrariesProject("linuxX64")) {
|
fun testNoGenerationForOldCompiler() = with(platformLibrariesProject("linuxX64")) {
|
||||||
@@ -279,4 +292,49 @@ class NativePlatformLibsIT : BaseGradleIT() {
|
|||||||
assertContains("Generate platform libraries for linux_x64")
|
assertContains("Generate platform libraries for linux_x64")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `check offline mode is propagated to the platform libs generator`() = with(platformLibrariesProject("linuxX64")) {
|
||||||
|
deleteInstalledCompilers()
|
||||||
|
|
||||||
|
// Install the compiler at the first time. Don't build to reduce execution time.
|
||||||
|
buildWithLightDist("tasks") {
|
||||||
|
assertSuccessful()
|
||||||
|
assertContains("Generate platform libraries for linux_x64")
|
||||||
|
}
|
||||||
|
|
||||||
|
deleteInstalledCompilers()
|
||||||
|
|
||||||
|
// Check that --offline works when all the dependencies are already downloaded:
|
||||||
|
val buildOptionsOffline = defaultBuildOptions()
|
||||||
|
.let { it.copy(freeCommandLineArgs = it.freeCommandLineArgs + "--offline") }
|
||||||
|
|
||||||
|
buildWithLightDist("tasks", options = buildOptionsOffline) {
|
||||||
|
assertSuccessful()
|
||||||
|
assertContains("Generate platform libraries for linux_x64")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check that --offline fails when there are no downloaded dependencies:
|
||||||
|
val customKonanDataDir = tempDir.newFolder("konanOffline")
|
||||||
|
val buildOptionsOfflineWithCustomKonanDataDir = buildOptionsOffline.copy(
|
||||||
|
customEnvironmentVariables = buildOptionsOffline.customEnvironmentVariables +
|
||||||
|
("KONAN_DATA_DIR" to customKonanDataDir.absolutePath)
|
||||||
|
)
|
||||||
|
|
||||||
|
buildWithLightDist("tasks", options = buildOptionsOfflineWithCustomKonanDataDir) {
|
||||||
|
assertFailed()
|
||||||
|
assertContains("Generate platform libraries for linux_x64")
|
||||||
|
}
|
||||||
|
|
||||||
|
// The build above have extracted the cached compiler to the custom KONAN_DATA_DIR; remove it:
|
||||||
|
assertTrue(customKonanDataDir.deleteRecursively())
|
||||||
|
|
||||||
|
// Check that the compiler is not extracted if it is not cached:
|
||||||
|
buildWithLightDist("tasks", "-Pkotlin.native.version=1.6.20-M1-9999", options = buildOptionsOfflineWithCustomKonanDataDir) {
|
||||||
|
assertFailed()
|
||||||
|
assertNotContains("Generate platform libraries for linux_x64")
|
||||||
|
}
|
||||||
|
|
||||||
|
assertFalse(customKonanDataDir.exists())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+7
@@ -196,4 +196,11 @@ internal class KotlinNativeLibraryGenerationRunner(project: Project) :
|
|||||||
AbstractKotlinNativeCInteropRunner("generatePlatformLibraries", project) {
|
AbstractKotlinNativeCInteropRunner("generatePlatformLibraries", project) {
|
||||||
// The library generator works for a long time so enabling C2 can improve performance.
|
// The library generator works for a long time so enabling C2 can improve performance.
|
||||||
override val disableC2: Boolean = false
|
override val disableC2: Boolean = false
|
||||||
|
|
||||||
|
override val defaultArguments: List<String>
|
||||||
|
get() = mutableListOf<String>().apply {
|
||||||
|
if (project.gradle.startParameter.isOffline) {
|
||||||
|
addAll(listOf("-Xoverride-konan-properties", "airplaneMode=true"))
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user