[Gradle] Propagate offline mode to Native cinterop
^KT-49247
This commit is contained in:
committed by
Space
parent
15a52f33ad
commit
a28884b1c3
+45
@@ -1158,6 +1158,51 @@ class GeneralNativeIT : BaseGradleIT() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `check offline mode is propagated to the cinterop`() = with(transformNativeTestProjectWithPluginDsl("native-cinterop")) {
|
||||||
|
val buildOptions = defaultBuildOptions()
|
||||||
|
val cinteropTask = ":projectLibrary:cinteropAnotherNumberHost"
|
||||||
|
|
||||||
|
build(cinteropTask, options = buildOptions) {
|
||||||
|
assertSuccessful()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check that --offline works when all the dependencies are already downloaded:
|
||||||
|
val buildOptionsOffline = buildOptions.copy(freeCommandLineArgs = buildOptions.freeCommandLineArgs + "--offline")
|
||||||
|
|
||||||
|
build("clean", cinteropTask, options = buildOptionsOffline) {
|
||||||
|
assertSuccessful()
|
||||||
|
withNativeCommandLineArguments(cinteropTask, toolName = "cinterop") {
|
||||||
|
assertTrue(it.containsSequentially("-Xoverride-konan-properties", "airplaneMode=true"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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)
|
||||||
|
)
|
||||||
|
|
||||||
|
build("clean", cinteropTask, options = buildOptionsOfflineWithCustomKonanDataDir) {
|
||||||
|
assertFailed()
|
||||||
|
}
|
||||||
|
|
||||||
|
checkNoDependenciesDownloaded(customKonanDataDir)
|
||||||
|
|
||||||
|
// Check that the compiler is not extracted if it is not cached:
|
||||||
|
assertTrue(customKonanDataDir.deleteRecursively())
|
||||||
|
build(
|
||||||
|
"clean", cinteropTask, "-Pkotlin.native.version=1.6.20-M1-9999",
|
||||||
|
options = buildOptionsOfflineWithCustomKonanDataDir
|
||||||
|
) {
|
||||||
|
assertFailed()
|
||||||
|
assertTasksNotExecuted(listOf(cinteropTask))
|
||||||
|
}
|
||||||
|
|
||||||
|
assertFalse(customKonanDataDir.exists())
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
fun List<String>.containsSequentially(vararg elements: String): Boolean {
|
fun List<String>.containsSequentially(vararg elements: String): Boolean {
|
||||||
check(elements.isNotEmpty())
|
check(elements.isNotEmpty())
|
||||||
|
|||||||
+7
@@ -146,6 +146,13 @@ internal class KotlinNativeCInteropRunner private constructor(project: Project)
|
|||||||
fun runWithContext(action: () -> Unit)
|
fun runWithContext(action: () -> Unit)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override val defaultArguments: List<String>
|
||||||
|
get() = mutableListOf<String>().apply {
|
||||||
|
if (project.gradle.startParameter.isOffline) {
|
||||||
|
addAll(listOf("-Xoverride-konan-properties", "airplaneMode=true"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
fun ExecutionContext.run(args: List<String>) {
|
fun ExecutionContext.run(args: List<String>) {
|
||||||
val runner = KotlinNativeCInteropRunner(project)
|
val runner = KotlinNativeCInteropRunner(project)
|
||||||
|
|||||||
Reference in New Issue
Block a user