-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Gradle, native] Disable platform libraries generation by default
Since there are a lot of changes around klibs in 1.4-M2, it was decided to postpone enabling user-side platform libraries generation by default. This patch switches the default distribution type to prebuilt. It also slightly refactors the code allowing user to choose the distribution type. Now, there are only two distribution types available: - prebuilt - the default type, contains prebuilt platform libs. A distribution archive has the "-prebuilt-" classifier. - light - doesn't contain platform libs in an archive and generates them at the user side. The archive has no classifier to avoid changes in the K/N build logic and TC configurations. The same types are also available for 1.3 but with sightly different convention: - prebuilt - the default type, contains prebuilt platform libs. A distribution archive has no classifier. - light - aka "restricted" distribution, doesn't contain platform libs for Apple platforms. The archive has the "-restricted-" suffix. Doesn't have a facility to build the libraries at the user side. Issue #KT-38174 Fixed
- Loading branch information
Showing
6 changed files
with
159 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
...main/kotlin/org/jetbrains/kotlin/gradle/targets/native/internal/NativeDistributionType.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. | ||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. | ||
*/ | ||
|
||
package org.jetbrains.kotlin.gradle.targets.native.internal | ||
|
||
import org.gradle.api.Project | ||
import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider | ||
import org.jetbrains.kotlin.gradle.plugin.mpp.isAtLeast | ||
import org.jetbrains.kotlin.gradle.targets.native.internal.NativeDistributionType.* | ||
import org.jetbrains.kotlin.gradle.utils.SingleWarningPerBuild | ||
import org.jetbrains.kotlin.konan.CompilerVersion | ||
import org.jetbrains.kotlin.konan.target.HostManager | ||
|
||
internal enum class NativeDistributionType(val suffix: String?, val mustGeneratePlatformLibs: Boolean) { | ||
LIGHT(null, true), | ||
PREBUILT("prebuilt", false), | ||
|
||
// Distribution types for 1.3: | ||
LIGHT_1_3("restricted", false), // aka "restricted" distribution without platform libs for Apple targets. | ||
PREBUILT_1_3(null, false) | ||
} | ||
|
||
internal class NativeDistributionTypeProvider(private val project: Project) { | ||
private val propertiesProvider = PropertiesProvider(project) | ||
|
||
private fun warning(message: String) = SingleWarningPerBuild.show(project, "Warning: $message") | ||
|
||
private fun chooseDistributionType( | ||
prebuiltType: NativeDistributionType, | ||
lightType: NativeDistributionType, | ||
defaultType: NativeDistributionType | ||
): NativeDistributionType { | ||
val requestedByUser = propertiesProvider.nativeDistributionType?.toLowerCase() | ||
val deprecatedRestricted = propertiesProvider.nativeDeprecatedRestricted | ||
|
||
// A case when a deprecated property (kotlin.native.restrictedDistribution) is used to choose the restricted distribution. | ||
// Effectively the restricted distribution from 1.3 and the light distribution from 1.4 are the same, | ||
// so we allow user to specify kotlin.native.restrictedDistribution in both 1.3 and 1.4 | ||
if (requestedByUser == null && deprecatedRestricted != null) { | ||
return if (deprecatedRestricted) { | ||
lightType | ||
} else { | ||
defaultType | ||
} | ||
} | ||
|
||
// A normal path: no deprecated properties, only kotlin.native.distribution.type. | ||
return when (requestedByUser) { | ||
null -> defaultType | ||
"prebuilt" -> prebuiltType | ||
"light" -> lightType | ||
else -> { | ||
warning("Unknown Kotlin/Native distribution type: $requestedByUser. Available values: prebuilt, light") | ||
defaultType | ||
} | ||
} | ||
} | ||
|
||
fun getDistributionType(version: CompilerVersion): NativeDistributionType { | ||
if (propertiesProvider.nativeDeprecatedRestricted != null) { | ||
warning("Project property 'kotlin.native.restrictedDistribution' is deprecated. Please use 'kotlin.native.distribution.type=light' instead") | ||
} | ||
|
||
return if (version.isAtLeast(1, 4, 0)) { | ||
chooseDistributionType(prebuiltType = PREBUILT, lightType = LIGHT, defaultType = PREBUILT) | ||
} else { | ||
// In 1.3, the distribution type can be chosen for Mac hosts only. | ||
if (!HostManager.hostIsMac) { | ||
return PREBUILT_1_3 | ||
} | ||
chooseDistributionType(prebuiltType = PREBUILT_1_3, lightType = LIGHT_1_3, defaultType = PREBUILT_1_3) | ||
} | ||
} | ||
} |