[Gradle, K/N] Stop using enableEndorsedLibs Gradle flag, make it Error

#KT-54098 Fixed
This commit is contained in:
Alexander.Likhachev
2023-01-25 23:27:47 +01:00
committed by Space Team
parent 3b75658113
commit 67c4dc3cce
15 changed files with 66 additions and 79 deletions
@@ -13,9 +13,16 @@ kotlin {
hostOs.startsWith("Windows") -> mingwX64("csvParser") hostOs.startsWith("Windows") -> mingwX64("csvParser")
else -> throw GradleException("Host OS '$hostOs' is not supported in Kotlin/Native $project.") else -> throw GradleException("Host OS '$hostOs' is not supported in Kotlin/Native $project.")
} }
sourceSets {
commonMain {
dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-cli:0.3.5")
}
}
}
hostTarget.apply { hostTarget.apply {
compilations["main"].enableEndorsedLibs = true
binaries { binaries {
executable { executable {
entryPoint = "sample.csvparser.main" entryPoint = "sample.csvparser.main"
@@ -45,8 +45,14 @@ kotlin {
} }
} }
} }
}
compilations["main"].enableEndorsedLibs = true sourceSets {
commonMain {
dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-cli:0.3.5")
}
}
} }
// Enable experimental stdlib API used by the sample. // Enable experimental stdlib API used by the sample.
@@ -162,10 +162,13 @@ abstract class BenchmarkingPlugin: Plugin<Project> {
protected fun Project.configureNativeTarget(hostPreset: AbstractKotlinNativeTargetPreset<*>) { protected fun Project.configureNativeTarget(hostPreset: AbstractKotlinNativeTargetPreset<*>) {
kotlin.targetFromPreset(hostPreset, NATIVE_TARGET_NAME) { kotlin.targetFromPreset(hostPreset, NATIVE_TARGET_NAME) {
@Suppress("DEPRECATION") compilations.named("main").configure {
compilations.getByName("main").kotlinOptions.freeCompilerArgs = benchmark.compilerOpts + project.compilerArgs @Suppress("DEPRECATION")
@Suppress("DEPRECATION") // enableEndorsedLibs is scheduled to be removed in 1.9.0, see KT-54098 kotlinOptions.freeCompilerArgs = benchmark.compilerOpts + project.compilerArgs
compilations.getByName("main").enableEndorsedLibs = true dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-cli:0.3.5")
}
}
configureNativeOutput(this@configureNativeTarget) configureNativeOutput(this@configureNativeTarget)
} }
} }
@@ -139,23 +139,6 @@ class GeneralNativeIT : BaseGradleIT() {
} }
} }
@Test
fun testEndorsedLibsController() {
with(
transformNativeTestProjectWithPluginDsl("native-endorsed")
) {
build("build") {
assertSuccessful()
}
gradleBuildScript().modify {
it.replace("enableEndorsedLibs = true", "")
}
build("build") {
assertFailed()
}
}
}
@Test @Test
fun testCanProduceNativeLibraries() = with(transformNativeTestProjectWithPluginDsl("libraries", directoryPrefix = "native-binaries")) { fun testCanProduceNativeLibraries() = with(transformNativeTestProjectWithPluginDsl("libraries", directoryPrefix = "native-binaries")) {
val baseName = "native_library" val baseName = "native_library"
@@ -1,17 +0,0 @@
plugins {
id("org.jetbrains.kotlin.multiplatform").version("<pluginMarkerVersion>")
}
repositories {
mavenLocal()
mavenCentral()
}
kotlin {
<SingleNativeTarget>("host") {
compilations.all {
kotlinOptions.verbose = true
enableEndorsedLibs = true
}
}
}
@@ -1,9 +0,0 @@
import kotlinx.cli.*
fun main(args: Array<String>) {
val argParser = ArgParser("test")
val size by argParser.option(ArgType.Int, shortName = "s", description = "Required size of videoplayer window")
.delimiter(",")
val fileName by argParser.argument(ArgType.String, description = "File to play")
argParser.parse(args)
}
@@ -183,7 +183,10 @@ internal open class GradleKpmNativeFragmentMetadataCompilationDataImpl(
} }
@Suppress("DeprecatedCallableAddReplaceWith") @Suppress("DeprecatedCallableAddReplaceWith")
@Deprecated("Please declare explicit dependency on kotlinx-cli. This option is scheduled to be removed in 1.9.0") @Deprecated(
"Please declare explicit dependency on kotlinx-cli. This option has no longer effect since 1.9.0",
level = DeprecationLevel.ERROR
)
override val enableEndorsedLibs: Boolean override val enableEndorsedLibs: Boolean
get() = false get() = false
} }
@@ -17,10 +17,14 @@ internal class GradleKpmNativeVariantCompilationData(
override val konanTarget: KonanTarget override val konanTarget: KonanTarget
get() = variant.konanTarget get() = variant.konanTarget
@Suppress("DEPRECATION", "DeprecatedCallableAddReplaceWith")
@Deprecated("Please declare explicit dependency on kotlinx-cli. This option is scheduled to be removed in 1.9.0") @Suppress("DeprecatedCallableAddReplaceWith")
@Deprecated(
"Please declare explicit dependency on kotlinx-cli. This option has no longer effect since 1.9.0",
level = DeprecationLevel.ERROR
)
override val enableEndorsedLibs: Boolean override val enableEndorsedLibs: Boolean
get() = variant.enableEndorsedLibraries get() = false
override val project: Project override val project: Project
get() = variant.containingModule.project get() = variant.containingModule.project
@@ -48,6 +48,9 @@ abstract class GradleKpmNativeVariantInternal(
interface GradleKpmNativeCompilationData<T : KotlinCommonOptions> : GradleKpmCompilationData<T> { interface GradleKpmNativeCompilationData<T : KotlinCommonOptions> : GradleKpmCompilationData<T> {
val konanTarget: KonanTarget val konanTarget: KonanTarget
@Deprecated("Please declare explicit dependency on kotlinx-cli. This option is scheduled to be removed in 1.9.0") @Deprecated(
"Please declare explicit dependency on kotlinx-cli. This option has no longer effect since 1.9.0",
level = DeprecationLevel.ERROR
)
val enableEndorsedLibs: Boolean val enableEndorsedLibs: Boolean
} }
@@ -42,7 +42,11 @@ abstract class AbstractKotlinNativeCompilation internal constructor(
get() = project.nativeUseEmbeddableCompilerJar get() = project.nativeUseEmbeddableCompilerJar
// Endorsed library controller. // Endorsed library controller.
@Deprecated("Please declare explicit dependency on kotlinx-cli. This option is scheduled to be removed in 1.9.0") @Suppress("unused")
@Deprecated(
"Please declare explicit dependency on kotlinx-cli. This option has no longer effect since 1.9.0",
level = DeprecationLevel.ERROR
)
var enableEndorsedLibs: Boolean = false var enableEndorsedLibs: Boolean = false
} }
@@ -37,7 +37,6 @@ internal fun buildKotlinNativeKlibCompilerArgs(
libraries: List<File>, libraries: List<File>,
languageSettings: LanguageSettings, languageSettings: LanguageSettings,
enableEndorsedLibs: Boolean,
compilerOptions: KotlinCommonCompilerOptions, compilerOptions: KotlinCommonCompilerOptions,
compilerPlugins: List<CompilerPluginData>, compilerPlugins: List<CompilerPluginData>,
@@ -77,7 +76,7 @@ internal fun buildKotlinNativeKlibCompilerArgs(
} }
} }
addAll(buildKotlinNativeCompileCommonArgs(enableEndorsedLibs, languageSettings, compilerOptions, compilerPlugins)) addAll(buildKotlinNativeCompileCommonArgs(languageSettings, compilerOptions, compilerPlugins))
addAll(source.map { it.absolutePath }) addAll(source.map { it.absolutePath })
if (!commonSourcesTree.isEmpty) { if (!commonSourcesTree.isEmpty) {
@@ -94,7 +93,6 @@ internal fun buildKotlinNativeBinaryLinkerArgs(
libraries: List<File>, libraries: List<File>,
friendModules: List<File>, friendModules: List<File>,
enableEndorsedLibs: Boolean,
toolOptions: KotlinCommonCompilerToolOptions, toolOptions: KotlinCommonCompilerToolOptions,
compilerPlugins: List<CompilerPluginData>, compilerPlugins: List<CompilerPluginData>,
@@ -122,7 +120,7 @@ internal fun buildKotlinNativeBinaryLinkerArgs(
binaryOptions.forEach { (name, value) -> add("-Xbinary=$name=$value") } binaryOptions.forEach { (name, value) -> add("-Xbinary=$name=$value") }
addKey("-Xstatic-framework", isStaticFramework) addKey("-Xstatic-framework", isStaticFramework)
addAll(buildKotlinNativeCommonArgs(enableEndorsedLibs, toolOptions, compilerPlugins)) addAll(buildKotlinNativeCommonArgs(toolOptions, compilerPlugins))
exportLibraries.forEach { add("-Xexport-library=${it.absolutePath}") } exportLibraries.forEach { add("-Xexport-library=${it.absolutePath}") }
includeLibraries.forEach { add("-Xinclude=${it.absolutePath}") } includeLibraries.forEach { add("-Xinclude=${it.absolutePath}") }
@@ -150,13 +148,12 @@ private fun buildKotlinNativeMainArgs(
} }
internal fun buildKotlinNativeCompileCommonArgs( internal fun buildKotlinNativeCompileCommonArgs(
enableEndorsedLibs: Boolean,
languageSettings: LanguageSettings, languageSettings: LanguageSettings,
compilerOptions: KotlinCommonCompilerOptions, compilerOptions: KotlinCommonCompilerOptions,
compilerPlugins: List<CompilerPluginData> compilerPlugins: List<CompilerPluginData>
): List<String> = mutableListOf<String>().apply { ): List<String> = mutableListOf<String>().apply {
add("-Xmulti-platform") add("-Xmulti-platform")
addKey("-no-endorsed-libs", !enableEndorsedLibs) addKey("-no-endorsed-libs", true)
compilerPlugins.forEach { plugin -> compilerPlugins.forEach { plugin ->
plugin.files.map { it.canonicalPath }.sorted().forEach { add("-Xplugin=$it") } plugin.files.map { it.canonicalPath }.sorted().forEach { add("-Xplugin=$it") }
@@ -179,12 +176,11 @@ internal fun buildKotlinNativeCompileCommonArgs(
} }
internal fun buildKotlinNativeCommonArgs( internal fun buildKotlinNativeCommonArgs(
enableEndorsedLibs: Boolean,
toolOptions: KotlinCommonCompilerToolOptions, toolOptions: KotlinCommonCompilerToolOptions,
compilerPlugins: List<CompilerPluginData> compilerPlugins: List<CompilerPluginData>
): List<String> = mutableListOf<String>().apply { ): List<String> = mutableListOf<String>().apply {
add("-Xmulti-platform") add("-Xmulti-platform")
addKey("-no-endorsed-libs", !enableEndorsedLibs) addKey("-no-endorsed-libs", true)
compilerPlugins.forEach { plugin -> compilerPlugins.forEach { plugin ->
plugin.files.map { it.canonicalPath }.sorted().forEach { add("-Xplugin=$it") } plugin.files.map { it.canonicalPath }.sorted().forEach { add("-Xplugin=$it") }
@@ -263,10 +263,14 @@ constructor(
objectFactory.property(it.file(filename).asFile) objectFactory.property(it.file(filename).asFile)
} }
@Suppress("DEPRECATION", "DeprecatedCallableAddReplaceWith") @Suppress("unused", "DeprecatedCallableAddReplaceWith")
@Deprecated("Please declare explicit dependency on kotlinx-cli. This option is scheduled to be removed in 1.9.0") @Deprecated(
"Please declare explicit dependency on kotlinx-cli. This option has no longer effect since 1.9.0",
level = DeprecationLevel.ERROR
)
@get:Input @get:Input
val enableEndorsedLibs: Boolean by lazy { compilation.enableEndorsedLibs } val enableEndorsedLibs: Boolean
get() = false
@Internal @Internal
val compilerPluginOptions = CompilerPluginOptions() val compilerPluginOptions = CompilerPluginOptions()
@@ -313,8 +317,6 @@ constructor(
} }
} }
@Suppress("DEPRECATION") val enableEndorsedLibs = this.enableEndorsedLibs // TODO: remove before 1.9.0, see KT-54098
val buildArgs = buildKotlinNativeBinaryLinkerArgs( val buildArgs = buildKotlinNativeBinaryLinkerArgs(
output, output,
optimized, optimized,
@@ -323,7 +325,6 @@ constructor(
outputKind, outputKind,
libraries.files.filterKlibsPassedToCompiler(), libraries.files.filterKlibsPassedToCompiler(),
friendModule.files.toList(), friendModule.files.toList(),
enableEndorsedLibs,
toolOptions, toolOptions,
plugins, plugins,
processTests, processTests,
@@ -203,11 +203,14 @@ abstract class AbstractKotlinNativeCompile<
get() = languageSettings.progressiveMode get() = languageSettings.progressiveMode
// endregion. // endregion.
@Deprecated("Please declare explicit dependency on kotlinx-cli. This option is scheduled to be removed in 1.9.0") @Suppress("DeprecatedCallableAddReplaceWith")
@Deprecated(
"Please declare explicit dependency on kotlinx-cli. This option has no longer effect since 1.9.0",
level = DeprecationLevel.ERROR
)
@get:Input @get:Input
val enableEndorsedLibs: Boolean by project.provider { val enableEndorsedLibs: Boolean
compilation.tcsOrNull?.compilation?.run { this as? KotlinNativeCompilation }?.enableEndorsedLibs ?: false get() = false
}
@get:Input @get:Input
val kotlinNativeVersion: String val kotlinNativeVersion: String
@@ -425,7 +428,6 @@ internal constructor(
) )
return buildKotlinNativeCompileCommonArgs( return buildKotlinNativeCompileCommonArgs(
enableEndorsedLibs,
languageSettings, languageSettings,
compilerOptions, compilerOptions,
plugins plugins
@@ -467,7 +469,6 @@ internal constructor(
konanTarget, konanTarget,
libraries.files.filterKlibsPassedToCompiler(), libraries.files.filterKlibsPassedToCompiler(),
languageSettings, languageSettings,
enableEndorsedLibs,
compilerOptions, compilerOptions,
plugins, plugins,
moduleName, moduleName,
@@ -55,7 +55,10 @@ abstract class KotlinNativeLinkArtifactTask @Inject constructor(
@get:Input @get:Input
abstract val debuggable: Property<Boolean> abstract val debuggable: Property<Boolean>
@Deprecated("Please declare explicit dependency on kotlinx-cli. This option is scheduled to be removed in 1.9.0") @Deprecated(
"Please declare explicit dependency on kotlinx-cli. This option has no longer effect since 1.9.0",
level = DeprecationLevel.ERROR
)
@get:Input @get:Input
abstract val enableEndorsedLibs: Property<Boolean> abstract val enableEndorsedLibs: Property<Boolean>
@@ -156,7 +159,8 @@ abstract class KotlinNativeLinkArtifactTask @Inject constructor(
baseName.convention(project.name) baseName.convention(project.name)
debuggable.convention(true) debuggable.convention(true)
optimized.convention(false) optimized.convention(false)
enableEndorsedLibs.convention(false) @Suppress("DEPRECATION_ERROR")
enableEndorsedLibs.value(false).finalizeValue()
processTests.convention(false) processTests.convention(false)
staticFramework.convention(false) staticFramework.convention(false)
embedBitcode.convention(BitcodeEmbeddingMode.DISABLE) embedBitcode.convention(BitcodeEmbeddingMode.DISABLE)
@@ -183,7 +187,6 @@ abstract class KotlinNativeLinkArtifactTask @Inject constructor(
outputKind = outputKind, outputKind = outputKind,
libraries = libraries.klibs(), libraries = libraries.klibs(),
friendModules = emptyList(), //FriendModules aren't needed here because it's no test artifact friendModules = emptyList(), //FriendModules aren't needed here because it's no test artifact
enableEndorsedLibs = enableEndorsedLibs.get(), // TODO: remove before 1.9.0, see KT-54098
toolOptions = toolOptions, toolOptions = toolOptions,
compilerPlugins = emptyList(),//CompilerPlugins aren't needed here because it's no compilation but linking compilerPlugins = emptyList(),//CompilerPlugins aren't needed here because it's no compilation but linking
processTests = processTests.get(), processTests = processTests.get(),