Fix some warnings in kotlin-gradle-plugin

This commit is contained in:
Alexander Udalov
2021-02-19 19:18:06 +01:00
committed by TeamCityServer
parent 19a5c2f1c8
commit 37ccd82b6c
40 changed files with 110 additions and 111 deletions
@@ -28,7 +28,9 @@ tasks {
kotlinOptions.languageVersion = "1.3"
kotlinOptions.apiVersion = "1.3"
kotlinOptions.freeCompilerArgs += listOf(
"-Xskip-prerelease-check", "-Xsuppress-version-warnings"
"-Xskip-prerelease-check",
"-Xskip-runtime-version-check",
"-Xsuppress-version-warnings"
)
}
@@ -129,7 +129,9 @@ tasks {
kotlinOptions.languageVersion = "1.3"
kotlinOptions.apiVersion = "1.3"
kotlinOptions.freeCompilerArgs += listOf(
"-Xskip-prerelease-check", "-Xsuppress-version-warnings"
"-Xskip-prerelease-check",
"-Xskip-runtime-version-check",
"-Xsuppress-version-warnings"
)
}
@@ -79,9 +79,9 @@ internal fun <T : KotlinTarget> KotlinTargetsContainerWithPresets.configureOrCre
else -> {
throw InvalidUserCodeException(
"The target '$targetName' already exists, but it was not created with the '${targetPreset.name}' preset. " +
"To configure it, access it by name in `kotlin.targets`" +
" or use the preset function '${existingTarget.preset?.name}'."
.takeIf { existingTarget.preset != null } ?: "."
"To configure it, access it by name in `kotlin.targets`" +
(" or use the preset function '${existingTarget.preset?.name}'."
.takeIf { existingTarget.preset != null } ?: ".")
)
}
}
@@ -5,7 +5,10 @@
package org.jetbrains.kotlin.gradle.dsl
import org.gradle.api.*
import org.gradle.api.DomainObjectSet
import org.gradle.api.Named
import org.gradle.api.NamedDomainObjectSet
import org.gradle.api.Project
import org.gradle.api.plugins.ExtensionAware
import org.gradle.util.WrapUtil
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation
@@ -51,7 +54,7 @@ open class KotlinNativeBinaryContainer @Inject constructor(
"Binary $name has incorrect outputKind or build type.\n" +
"Expected: ${buildType.getName()} $classifier. Actual: ${binary.buildType.getName()} ${binary.outputKind.taskNameClassifier}."
}
return binary as T
return binary
}
private inline fun <reified T : NativeBinary> findBinary(
@@ -129,6 +129,7 @@ open class KotlinJsProjectExtension(project: Project) :
}
@Deprecated("Use js() instead", ReplaceWith("js()"))
@Suppress("DEPRECATION")
override var target: KotlinJsTargetDsl
get() {
if (_target == null) {
@@ -142,6 +143,7 @@ open class KotlinJsProjectExtension(project: Project) :
override lateinit var defaultJsCompilerType: KotlinJsCompilerType
@Suppress("DEPRECATION")
private fun jsInternal(
compiler: KotlinJsCompilerType? = null,
body: KotlinJsTargetDsl.() -> Unit
@@ -230,6 +232,7 @@ open class KotlinJsProjectExtension(project: Project) :
"Needed for IDE import using the MPP import mechanism",
level = DeprecationLevel.HIDDEN
)
@Suppress("DEPRECATION")
fun getTargets(): NamedDomainObjectContainer<KotlinTarget>? =
_target?.let { target ->
target.project.container(KotlinTarget::class.java)
@@ -96,6 +96,7 @@ private fun KotlinTargetContainerWithJsPresetFunctions.jsInternal(
}
reportJsCompilerMode(compilerOrDefault)
@Suppress("UNCHECKED_CAST")
return configureOrCreate(
targetName,
presets.getByName(
@@ -144,4 +145,4 @@ private fun getTargetName(name: String, compiler: KotlinJsCompilerType?): String
name,
if (compiler == KotlinJsCompilerType.BOTH) KotlinJsCompilerType.LEGACY.lowerName else null
)
}
}
@@ -5,12 +5,12 @@
package org.jetbrains.kotlin.gradle.incremental
import org.gradle.api.tasks.incremental.IncrementalTaskInputs
import org.jetbrains.kotlin.incremental.ChangedFiles
import java.io.File
import java.util.*
internal fun ChangedFiles(taskInputs: IncrementalTaskInputs): ChangedFiles {
internal fun ChangedFiles(
@Suppress("DEPRECATION") taskInputs: org.gradle.api.tasks.incremental.IncrementalTaskInputs
): ChangedFiles {
if (!taskInputs.isIncremental) return ChangedFiles.Unknown()
val modified = ArrayList<File>()
@@ -757,7 +757,7 @@ internal fun registerGeneratedJavaSource(kaptTask: TaskProvider<out KaptTask>, j
}
}
internal fun Configuration.getNamedDependencies(): List<Dependency> = allDependencies.filter { it.group != null && it.name != null }
internal fun Configuration.getNamedDependencies(): List<Dependency> = allDependencies.filter { it.group != null }
private val ANNOTATION_PROCESSOR = "annotationProcessor"
private val ANNOTATION_PROCESSOR_CAP = ANNOTATION_PROCESSOR.capitalize()
@@ -6,7 +6,6 @@
package org.jetbrains.kotlin.gradle.internal
import org.gradle.api.file.ConfigurableFileCollection
import org.gradle.api.file.DirectoryProperty
import org.gradle.api.model.ObjectFactory
import org.gradle.api.provider.Property
import org.gradle.api.tasks.*
@@ -84,10 +83,10 @@ abstract class KaptWithoutKotlincTask @Inject constructor(
for (option in options) {
result[option.key] = option.value
}
annotationProcessorOptionProviders.forEach {
(it as List<Any>).forEach {
(it as CommandLineArgumentProvider).asArguments().forEach {
result[it.removePrefix("-A")] = ""
annotationProcessorOptionProviders.forEach { providers ->
(providers as List<*>).forEach { provider ->
(provider as CommandLineArgumentProvider).asArguments().forEach { argument ->
result[argument.removePrefix("-A")] = ""
}
}
}
@@ -6,8 +6,8 @@
package org.jetbrains.kotlin.gradle.logging
import org.gradle.api.logging.Logger
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSourceLocation
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSourceLocation
import org.jetbrains.kotlin.cli.common.messages.GradleStyleMessageRenderer
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
import org.jetbrains.kotlin.compilerRunner.KotlinLogger
@@ -32,6 +32,7 @@ internal class GradlePrintingMessageCollector(
override fun report(severity: CompilerMessageSeverity, message: String, location: CompilerMessageSourceLocation?) {
val renderedMessage = messageRenderer.render(severity, message, location)
@Suppress("UNNECESSARY_NOT_NULL_ASSERTION")
when (severity) {
CompilerMessageSeverity.ERROR,
CompilerMessageSeverity.EXCEPTION -> {
@@ -56,4 +57,4 @@ internal class GradlePrintingMessageCollector(
}
}!! // !! is used to force compile-time exhaustiveness
}
}
}
@@ -65,6 +65,7 @@ open class KaptExtension {
private var apOptionsClosure: Closure<*>? = null
private var javacOptionsClosure: Closure<*>? = null
@Suppress("DEPRECATION")
open fun annotationProcessor(fqName: String) {
val oldProcessors = this.processors
this.processors = if (oldProcessors.isEmpty()) fqName else "$oldProcessors,$fqName"
@@ -701,9 +701,7 @@ internal open class KotlinAndroidPlugin(
}
companion object {
fun androidTargetHandler(
androidTarget: KotlinAndroidTarget
): AbstractAndroidProjectHandler {
fun androidTargetHandler(): AbstractAndroidProjectHandler {
val tasksProvider = AndroidTasksProvider()
if (androidPluginVersion != null) {
@@ -720,15 +718,14 @@ internal open class KotlinAndroidPlugin(
return Android25ProjectHandler(kotlinTools)
}
fun applyToTarget(
kotlinTarget: KotlinAndroidTarget
) {
androidTargetHandler(kotlinTarget).configureTarget(kotlinTarget)
fun applyToTarget(kotlinTarget: KotlinAndroidTarget) {
androidTargetHandler().configureTarget(kotlinTarget)
}
}
}
class KotlinConfigurationTools internal constructor(
@Suppress("EXPOSED_PROPERTY_TYPE_IN_CONSTRUCTOR")
val kotlinTasksProvider: KotlinTasksProvider
)
@@ -841,7 +838,7 @@ abstract class AbstractAndroidProjectHandler(private val kotlinConfigurationTool
project.addExtendsFromRelation(androidSourceSet.apiConfigurationName, apiConfigurationName)
} else {
// If any dependency is added to this configuration, report an error:
project.configurations.getByName(apiConfigurationName).dependencies.all { dependency ->
project.configurations.getByName(apiConfigurationName).dependencies.all {
throw InvalidUserCodeException(
"API dependencies are not allowed for Android source set ${androidSourceSet.name}. " +
"Please use an implementation dependency instead."
@@ -37,7 +37,7 @@ import org.jetbrains.kotlin.gradle.plugin.statistics.KotlinBuildStatsService
import org.jetbrains.kotlin.gradle.targets.js.KotlinJsCompilerAttribute
import org.jetbrains.kotlin.gradle.targets.js.KotlinJsPlugin
import org.jetbrains.kotlin.gradle.targets.js.npm.addNpmDependencyExtension
import org.jetbrains.kotlin.gradle.tasks.*
import org.jetbrains.kotlin.gradle.tasks.AbstractKotlinCompile
import org.jetbrains.kotlin.gradle.tasks.KOTLIN_COMPILER_EMBEDDABLE
import org.jetbrains.kotlin.gradle.tasks.KOTLIN_KLIB_COMMONIZER_EMBEDDABLE
import org.jetbrains.kotlin.gradle.tasks.KOTLIN_MODULE_GROUP
@@ -63,7 +63,7 @@ abstract class KotlinBasePluginWrapper : Plugin<Project> {
val kotlinPluginVersion = project.getKotlinPluginVersion()
val listenerRegistryHolder = BuildEventsListenerRegistryHolder.getInstance(project)
val statisticsReporter = KotlinBuildStatsService.getOrCreateInstance(project, listenerRegistryHolder)
val statisticsReporter = KotlinBuildStatsService.getOrCreateInstance(project)
statisticsReporter?.report(StringMetrics.KOTLIN_COMPILER_VERSION, kotlinPluginVersion)
checkGradleCompatibility()
@@ -16,7 +16,6 @@ import org.gradle.api.attributes.Usage
import org.gradle.api.attributes.Usage.USAGE_ATTRIBUTE
import org.gradle.api.file.FileCollection
import org.gradle.api.internal.artifacts.ArtifactAttributes
import org.gradle.api.internal.plugins.DslObject
import org.gradle.api.plugins.BasePlugin
import org.gradle.api.plugins.ExtensionAware
import org.gradle.api.plugins.JavaBasePlugin
@@ -272,7 +271,7 @@ abstract class AbstractKotlinTargetConfigurator<KotlinTargetType : KotlinTarget>
val target = compilation.target
val configurations = target.project.configurations
val pluginConfiguration = configurations.maybeCreate(compilation.pluginConfigurationName).apply {
configurations.maybeCreate(compilation.pluginConfigurationName).apply {
if (target.platformType == KotlinPlatformType.native) {
extendsFrom(configurations.getByName(NATIVE_COMPILER_PLUGIN_CLASSPATH_CONFIGURATION_NAME))
isTransitive = false
@@ -317,7 +316,7 @@ abstract class AbstractKotlinTargetConfigurator<KotlinTargetType : KotlinTarget>
description = "Compile only dependencies for $compilation."
}
val compileClasspathConfiguration = configurations.maybeCreate(compilation.compileDependencyConfigurationName).apply {
configurations.maybeCreate(compilation.compileDependencyConfigurationName).apply {
extendsFrom(compileOnlyConfiguration, implementationConfiguration)
usesPlatformOf(target)
isVisible = false
@@ -344,7 +343,7 @@ abstract class AbstractKotlinTargetConfigurator<KotlinTargetType : KotlinTarget>
description = "Runtime only dependencies for $compilation."
}
val runtimeClasspathConfiguration = configurations.maybeCreate(compilation.runtimeDependencyConfigurationName).apply {
configurations.maybeCreate(compilation.runtimeDependencyConfigurationName).apply {
extendsFrom(runtimeOnlyConfiguration, implementationConfiguration)
runtimeConfiguration?.let { extendsFrom(it) }
usesPlatformOf(target)
@@ -7,8 +7,10 @@ import org.gradle.api.tasks.compile.AbstractCompile
import org.gradle.api.tasks.compile.JavaCompile
import org.jetbrains.kotlin.gradle.dsl.KotlinCompile
import org.jetbrains.kotlin.gradle.logging.kotlinDebug
import org.jetbrains.kotlin.gradle.plugin.mpp.*
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.KotlinCompilationData
import org.jetbrains.kotlin.gradle.plugin.mpp.AbstractKotlinNativeCompilation
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJvmAndroidCompilation
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJvmCompilation
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinWithJavaCompilation
import org.jetbrains.kotlin.gradle.tasks.AbstractKotlinCompile
import org.jetbrains.kotlin.gradle.tasks.CompilerPluginOptions
import org.jetbrains.kotlin.gradle.tasks.KotlinNativeCompile
@@ -127,7 +129,7 @@ internal fun addCompilationSourcesToExternalCompileTask(compilation: KotlinCompi
internal class LegacyKotlinCompilerPluginSupportPlugin(
@Suppress("deprecation") // support for deprecated API
val oldPlugin: KotlinGradleSubplugin<AbstractCompile>
): KotlinCompilerPluginSupportPlugin {
) : KotlinCompilerPluginSupportPlugin {
override fun isApplicable(kotlinCompilation: KotlinCompilation<*>): Boolean =
oldPlugin.isApplicable(kotlinCompilation.target.project, kotlinCompilation.compileKotlinTaskProvider.get() as AbstractCompile)
@@ -136,10 +138,8 @@ internal class LegacyKotlinCompilerPluginSupportPlugin(
): Provider<List<SubpluginOption>> {
val project = kotlinCompilation.target.project
val androidProjectHandlerOrNull: AbstractAndroidProjectHandler? = if (kotlinCompilation is KotlinJvmAndroidCompilation)
KotlinAndroidPlugin.androidTargetHandler(
kotlinCompilation.target as KotlinAndroidTarget
) else null
val androidProjectHandlerOrNull: AbstractAndroidProjectHandler? =
if (kotlinCompilation is KotlinJvmAndroidCompilation) KotlinAndroidPlugin.androidTargetHandler() else null
val variantData = (kotlinCompilation as? KotlinJvmAndroidCompilation)?.androidVariant
@@ -391,7 +391,6 @@ private class ProjectMppDependencyMetadataExtractor(
is KotlinMultiplatformExtension -> projectExtension.targets.getByName(KotlinMultiplatformPlugin.METADATA_TARGET_NAME).compilations
.filter { it.name in visibleSourceSetNames }.associate { it.defaultSourceSet.name to it.output.classesDirs }
is KotlinPm20ProjectExtension -> {
require(moduleIdentifier != null)
val moduleId = moduleIdentifier
val module = projectExtension.modules.single { it.moduleIdentifier == moduleId }
val metadataCompilationRegistry = projectExtension.metadataCompilationRegistryByModuleId.getValue(moduleId)
@@ -82,7 +82,7 @@ sealed class SourceSetMetadataLayout(
fun byName(name: String): SourceSetMetadataLayout? = values.firstOrNull { it.name == name }
fun chooseForProducingProject(project: Project) =
fun chooseForProducingProject() =
/** A producing project will now only generate Granular source sets metadata as a KLIB */
KLIB
}
@@ -173,7 +173,7 @@ internal fun buildKotlinProjectStructureMetadata(project: Project): KotlinProjec
.filter { it in sourceSetsWithMetadataCompilations }.map { it.name }
.toSet(),
sourceSetBinaryLayout = sourceSetsWithMetadataCompilations.keys.associate { sourceSet ->
sourceSet.name to SourceSetMetadataLayout.chooseForProducingProject(project)
sourceSet.name to SourceSetMetadataLayout.chooseForProducingProject()
},
isPublishedAsRoot = true
)
@@ -285,7 +285,6 @@ private val NodeList.elements: Iterable<Element> get() = (0 until length).map {
internal fun parseKotlinSourceSetMetadataFromJson(string: String): KotlinProjectStructureMetadata? {
@Suppress("DEPRECATION") // The replacement doesn't compile against old dependencies such as AS 4.0
val json = JsonParser().parse(string).asJsonObject
val nodeNamed: JsonObject.(String) -> JsonObject? = { name -> get(name)?.asJsonObject }
val valueNamed: JsonObject.(String) -> String? = { name -> get(name)?.asString }
val multiObjects: JsonObject.(String?) -> Iterable<JsonObject> = { name -> get(name).asJsonArray.map { it.asJsonObject } }
val multiValues: JsonObject.(String?) -> Iterable<String> = { name -> get(name).asJsonArray.map { it.asString } }
@@ -139,7 +139,7 @@ abstract class AbstractKotlinTarget(
object : ComponentWithVariants, ComponentWithCoordinates, SoftwareComponentInternal {
override fun getCoordinates() = (kotlinVariant as? ComponentWithCoordinates)?.coordinates
override fun getVariants(): Set<out SoftwareComponent> =
override fun getVariants(): Set<SoftwareComponent> =
(kotlinVariant as? KotlinVariantWithMetadataVariant)?.variants.orEmpty()
override fun getName(): String = adhocVariant.name
@@ -151,7 +151,7 @@ private fun associateDependenciesWithActualModuleDependencies(
val dependencyProjectKotlinExtension = dependencyProject.multiplatformExtensionOrNull
?: return@associate noMapping
val resolved = resolvedDependencies[Triple(dependency.group, dependency.name, dependency.version)]
val resolved = resolvedDependencies[Triple(dependency.group!!, dependency.name, dependency.version!!)]
?: return@associate noMapping
val resolvedToConfiguration = resolved.configuration
@@ -185,7 +185,7 @@ private fun associateDependenciesWithActualModuleDependencies(
)
}
else -> {
val resolvedDependency = resolvedDependencies[Triple(dependency.group, dependency.name, dependency.version)]
val resolvedDependency = resolvedDependencies[Triple(dependency.group!!, dependency.name, dependency.version!!)]
?: return@associate noMapping
if (resolvedDependency.moduleArtifacts.isEmpty() && resolvedDependency.children.size == 1) {
@@ -146,7 +146,7 @@ open class KotlinPm20ProjectExtension(project: Project) : KotlinTopLevelExtensio
@PublishedApi
@JvmName("isAllowCommonizer")
internal fun isAllowCommonizerForIde(project: Project): Boolean = false
internal fun isAllowCommonizerForIde(@Suppress("UNUSED_PARAMETER") project: Project): Boolean = false
}
val KotlinGradleModule.jvm: KotlinJvmVariant
@@ -246,7 +246,7 @@ internal fun KotlinSourceSet.disambiguateName(simpleName: String): String {
}
private fun createDefaultSourceDirectorySet(project: Project, name: String?): SourceDirectorySet =
project.objects.sourceDirectorySet(name, name)
project.objects.sourceDirectorySet(name!!, name)
/**
* Like [resolveAllDependsOnSourceSets] but will include the receiver source set also!
@@ -102,7 +102,7 @@ class KotlinBuildStatHandler {
when (configurationName) {
"kapt" -> {
sessionLogger.report(BooleanMetrics.ENABLED_KAPT, true)
dependencies?.forEach { dependency ->
for (dependency in dependencies) {
when (dependency.group) {
"com.google.dagger" -> sessionLogger.report(BooleanMetrics.ENABLED_DAGGER, true)
"com.android.databinding" -> sessionLogger.report(BooleanMetrics.ENABLED_DATABINDING, true)
@@ -12,7 +12,6 @@ import org.gradle.api.invocation.Gradle
import org.gradle.api.logging.Logging
import org.gradle.initialization.BuildRequestMetaData
import org.gradle.invocation.DefaultGradle
import org.jetbrains.kotlin.gradle.plugin.BuildEventsListenerRegistryHolder
import org.jetbrains.kotlin.gradle.plugin.statistics.KotlinBuildStatHandler.Companion.runSafe
import org.jetbrains.kotlin.gradle.utils.isConfigurationCacheAvailable
import org.jetbrains.kotlin.statistics.BuildSessionLogger
@@ -85,7 +84,7 @@ internal abstract class KotlinBuildStatsService internal constructor() : BuildAd
*/
@JvmStatic
@Synchronized
internal fun getOrCreateInstance(project: Project, listenerRegistryHolder: BuildEventsListenerRegistryHolder): IStatisticsValuesConsumer? {
internal fun getOrCreateInstance(project: Project): IStatisticsValuesConsumer? {
return runSafe("${KotlinBuildStatsService::class.java}.getOrCreateInstance") {
val gradle = project.gradle
@@ -106,7 +105,7 @@ internal abstract class KotlinBuildStatsService internal constructor() : BuildAd
)
instance = JMXKotlinBuildStatsService(mbs, beanName)
} else {
val kotlinBuildStatProvider = project.provider{ KotlinBuildStatListener(beanName) }
project.provider { KotlinBuildStatListener(beanName) }
val newInstance = DefaultKotlinBuildStatsService(gradle, beanName)
instance = newInstance
@@ -115,7 +114,7 @@ internal abstract class KotlinBuildStatsService internal constructor() : BuildAd
}
if (!isConfigurationCacheAvailable(gradle)) {
gradle.addBuildListener(instance)
gradle.addBuildListener(instance!!)
}
}
instance
@@ -71,9 +71,7 @@ open class KotlinAndroidTarget(
}
}
val variantNames =
KotlinAndroidPlugin.androidTargetHandler(this)
.getLibraryVariantNames()
val variantNames = KotlinAndroidPlugin.androidTargetHandler().getLibraryVariantNames()
val missingVariants =
publishLibraryVariants?.minus(variantNames).orEmpty()
@@ -90,7 +88,7 @@ open class KotlinAndroidTarget(
override val kotlinComponents by lazy {
checkPublishLibraryVariantsExist()
KotlinAndroidPlugin.androidTargetHandler(this).doCreateComponents()
KotlinAndroidPlugin.androidTargetHandler().doCreateComponents()
}
private fun isVariantPublished(variant: BaseVariant): Boolean {
@@ -92,7 +92,7 @@ open class KotlinJsTargetPreset(
}
override fun createCompilationFactory(forTarget: KotlinJsTarget): KotlinJsCompilationFactory {
return KotlinJsCompilationFactory(project, forTarget, irPreset?.let { (forTarget as KotlinJsTarget).irTarget })
return KotlinJsCompilationFactory(project, forTarget, irPreset?.let { forTarget.irTarget })
}
companion object {
@@ -5,7 +5,6 @@
package org.jetbrains.kotlin.gradle.targets.js.dsl
@Experimental(level = Experimental.Level.WARNING)
// TODO: @RequiresOptIn(level = RequiresOptIn.Level.WARNING)
@RequiresOptIn(level = RequiresOptIn.Level.WARNING)
@Target(AnnotationTarget.FUNCTION)
annotation class ExperimentalDceDsl
@@ -5,7 +5,6 @@
package org.jetbrains.kotlin.gradle.targets.js.dsl
@Experimental(level = Experimental.Level.WARNING)
// TODO: @RequiresOptIn(level = RequiresOptIn.Level.WARNING)
@RequiresOptIn(level = RequiresOptIn.Level.WARNING)
@Target(AnnotationTarget.FUNCTION)
annotation class ExperimentalDistributionDsl
@@ -82,12 +82,12 @@ constructor(
private fun executableLegacyInternal(compilation: KotlinJsCompilation) = createBinaries(
compilation = compilation,
jsBinaryType = KotlinJsBinaryType.EXECUTABLE,
create = { compilation, name, type ->
create = { jsCompilation, name, type ->
object : JsBinary {
override val compilation: KotlinJsCompilation = compilation
override val compilation: KotlinJsCompilation = jsCompilation
override val name: String = name
override val mode: KotlinJsBinaryMode = type
override val distribution: Distribution = DefaultDistribution(compilation.target.project)
override val distribution: Distribution = DefaultDistribution(jsCompilation.target.project)
}
}
)
@@ -10,7 +10,6 @@ import org.gradle.api.file.FileTree
import org.gradle.api.file.RegularFileProperty
import org.gradle.api.model.ObjectFactory
import org.gradle.api.tasks.*
import org.gradle.api.tasks.incremental.IncrementalTaskInputs
import org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments
import org.jetbrains.kotlin.gradle.dsl.KotlinJsOptions
import org.jetbrains.kotlin.gradle.dsl.KotlinJsOptionsImpl
@@ -50,9 +49,8 @@ open class KotlinJsIrLink @Inject constructor(
)
}
override fun skipCondition(inputs: IncrementalTaskInputs): Boolean {
return !inputs.isIncremental && !entryModule.exists()
}
override fun skipCondition(): Boolean =
!entryModule.exists()
override fun getDestinationDir(): File {
return if (kotlinOptions.outputFile == null) {
@@ -84,4 +82,4 @@ open class KotlinJsIrLink @Inject constructor(
PRODUCE_JS +
"$ENTRY_IR_MODULE=${entryModule.canonicalPath}"
}
}
}
@@ -196,8 +196,6 @@ abstract class KotlinJsIrSubTarget(
protected open fun configureLibrary(compilation: KotlinJsIrCompilation) {
val project = compilation.target.project
val processResourcesTask = target.project.tasks.named(compilation.processResourcesTaskName)
val assembleTaskProvider = project.tasks.named(LifecycleBasePlugin.ASSEMBLE_TASK_NAME)
val npmProject = compilation.npmProject
@@ -58,15 +58,18 @@ open class NodeJsRootExtension(@Transient val rootProject: Project) : Configurat
val nodeJsSetupTaskProvider: TaskProvider<out NodeJsSetupTask>
get() = rootProject.tasks.withType(NodeJsSetupTask::class.java).named(NodeJsSetupTask.NAME)
@Suppress("UNNECESSARY_SAFE_CALL") // TODO: investigate this warning; fixing it breaks integration tests.
val npmInstallTaskProvider: TaskProvider<out KotlinNpmInstallTask>?
get() = rootProject?.tasks?.withType(KotlinNpmInstallTask::class.java)?.named(KotlinNpmInstallTask.NAME)
val packageJsonUmbrellaTaskProvider: TaskProvider<Task>
get() = rootProject.tasks.named(PACKAGE_JSON_UMBRELLA_TASK_NAME)
@Suppress("UNNECESSARY_SAFE_CALL") // TODO: investigate this warning; fixing it breaks integration tests.
val rootPackageJsonTaskProvider: TaskProvider<RootPackageJsonTask>?
get() = rootProject?.tasks?.withType(RootPackageJsonTask::class.java)?.named(RootPackageJsonTask.NAME)
@Suppress("UNNECESSARY_SAFE_CALL") // TODO: investigate this warning; fixing it breaks integration tests.
val npmCachesSetupTaskProvider: TaskProvider<out KotlinNpmCachesSetup>?
get() = rootProject?.tasks?.withType(KotlinNpmCachesSetup::class.java)?.named(KotlinNpmCachesSetup.NAME)
@@ -183,7 +183,7 @@ private abstract class NpmDependencyExtensionDelegate(
val generateExternals = generateExternalsIfPossible(*args)
return when (val arg1 = if (args.size > 1) args[1] else null) {
null -> invoke(
null -> @Suppress("DEPRECATION") invoke(
name = name
)
is String -> invoke(
@@ -249,6 +249,7 @@ private class DefaultNpmDependencyExtension(
defaultGenerateExternals
)
@Suppress("DEPRECATION")
override fun invoke(name: String): NpmDependency =
delegate.invoke(name)
@@ -284,6 +285,7 @@ private class DefaultDevNpmDependencyExtension(
null
)
@Suppress("DEPRECATION")
override fun invoke(name: String): NpmDependency =
delegate.invoke(name)
@@ -398,6 +400,7 @@ private class DefaultPeerNpmDependencyExtension(
npmDeclarationException(args)
}
@Suppress("DEPRECATION")
override fun invoke(name: String): NpmDependency =
delegate.invoke(name)
@@ -406,4 +409,4 @@ private class DefaultPeerNpmDependencyExtension(
override fun call(vararg args: Any?): NpmDependency =
delegate.call(*args)
}
}
@@ -20,8 +20,8 @@ class YarnSimple : YarnBasics() {
override fun resolveProject(resolvedNpmProject: KotlinCompilationNpmResolution) {
setup(resolvedNpmProject.project.rootProject)
val project = resolvedNpmProject.project
// val project = resolvedNpmProject.project
//
// PackageJsonUpToDateCheck(resolvedNpmProject.npmProject).updateIfNeeded {
// yarnExec(
// (project as ProjectInternal).services,
@@ -611,6 +611,7 @@ internal fun getPublishedPlatformCompilations(project: Project): Map<KotlinUsage
internal fun Project.filesWithUnpackedArchives(from: FileCollection, extensions: Set<String>): FileCollection =
project.files(project.provider {
from.mapNotNull {
@Suppress("IMPLICIT_CAST_TO_ANY")
if (it.extension in extensions) {
if (it.exists()) project.zipTree(it) else null
} else it
@@ -348,7 +348,7 @@ open class KotlinNativeTargetConfigurator<T : KotlinNativeTarget> : AbstractKotl
}
target.binaries.withType(AbstractNativeLibrary::class.java).all { framework ->
val exportConfiguration = project.configurations.maybeCreate(framework.exportConfigurationName).apply {
project.configurations.maybeCreate(framework.exportConfigurationName).apply {
isVisible = false
isTransitive = false
isCanBeConsumed = false
@@ -22,7 +22,6 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
import org.jetbrains.kotlin.gradle.plugin.whenEvaluated
import org.jetbrains.kotlin.gradle.targets.native.tasks.*
import org.jetbrains.kotlin.gradle.tasks.*
import org.jetbrains.kotlin.gradle.tasks.registerTask
import org.jetbrains.kotlin.gradle.utils.asValidTaskName
import org.jetbrains.kotlin.gradle.utils.lowerCamelCaseName
import org.jetbrains.kotlin.konan.target.Family
@@ -373,15 +372,14 @@ open class KotlinCocoapodsPlugin : Plugin<Project> {
}
cocoapodsExtension.pods.all { pod ->
val podSource = pod.source
val downloadPodTask = when (podSource) {
val downloadPodTask = when (val podSource = pod.source) {
is Git -> project.tasks.register(pod.toPodDownloadTaskName, PodDownloadGitTask::class.java) {
it.podName = project.provider { pod.name.asValidTaskName() }
it.podSource = project.provider { podSource as Git }
it.podSource = project.provider<Git> { podSource }
}
is Url -> project.tasks.register(pod.toPodDownloadTaskName, PodDownloadUrlTask::class.java) {
it.podName = project.provider { pod.name.asValidTaskName() }
it.podSource = project.provider { podSource as Url }
it.podSource = project.provider<Url> { podSource }
}
else -> return@all
}
@@ -54,12 +54,12 @@ fun parseKotlinNativeStackTrace(stackTrace: String): KotlinNativeStackTrace {
stackTrace.lines().forEach {
val srcLine = it.trim()
var bin: String? = null
var address: String? = null
var className: String? = null
var methodName: String? = null
var signature: String? = null
var offset: Int = -1
val bin: String?
val address: String?
val className: String?
val methodName: String?
val signature: String?
val offset: Int
var fileName: String? = null
var lineNumber: Int = -1
var columnNumber: Int = -1
@@ -102,14 +102,13 @@ fun parseKotlinNativeStackTrace(stackTrace: String): KotlinNativeStackTrace {
classAndMethod = classAndMethod.substringBeforeLast("(")
if ("." in classAndMethod) {
methodName = classAndMethod.substringAfterLast(".").trim()
methodName = classAndMethod.substringAfterLast(".").trim().takeUnless(String::isBlank)
className = classAndMethod.substringBeforeLast(".").trim()
} else {
methodName = classAndMethod.trim()
methodName = classAndMethod.trim().takeUnless(String::isBlank)
className = null
}
if (methodName.isBlank()) methodName = null
stack.add(
KotlinNativeStackTraceElement(
bin,
@@ -103,7 +103,7 @@ open class PodspecTask : DefaultTask() {
""".trimIndent()
}
val gradleCommand = "\$REPO_ROOT/${gradleWrapper!!.toRelativeString(project.projectDir)}"
val gradleCommand = "\$REPO_ROOT/${gradleWrapper.toRelativeString(project.projectDir)}"
val syncTask = "${project.path}:$SYNC_TASK_NAME"
val deploymentTargets = run {
@@ -112,7 +112,7 @@ private fun FileCollection.filterOutPublishableInteropLibs(project: Project): Fi
* for it (NO-SOURCE check). So we need to take this case into account
* and skip libraries that were not compiled. See also: GH-2617 (K/N repo).
*/
private fun Collection<File>.filterKlibsPassedToCompiler(project: Project) = filter {
private fun Collection<File>.filterKlibsPassedToCompiler(): List<File> = filter {
(it.extension == "klib" || it.isDirectory) && it.exists()
}
@@ -277,6 +277,7 @@ abstract class AbstractKotlinNativeCompile<T : KotlinCommonToolOptions, K : Kotl
@get:Input
@get:Optional
internal val konanTargetsForManifest: String by project.provider {
@Suppress("CAST_NEVER_SUCCEEDS") // TODO: this warning looks very suspicious, as if the code never works as intended.
(compilation as? KotlinSharedNativeCompilation)
?.konanTargets
?.joinToString(separator = " ") { it.visibleName }
@@ -309,7 +310,7 @@ abstract class AbstractKotlinNativeCompile<T : KotlinCommonToolOptions, K : Kotl
addArg("-o", outputFile.get().absolutePath)
// Libraries.
libraries.files.filterKlibsPassedToCompiler(project).forEach { library ->
libraries.files.filterKlibsPassedToCompiler().forEach { library ->
addArg("-l", library.absolutePath)
}
}
@@ -458,15 +459,15 @@ constructor(
addArg("-module-name", moduleName)
add("-Xshort-module-name=$shortModuleName")
val friends = friendModule.files
if (friends != null && friends.isNotEmpty()) {
addArg("-friend-modules", friends.map { it.absolutePath }.joinToString(File.pathSeparator))
if (friends.isNotEmpty()) {
addArg("-friend-modules", friends.joinToString(File.pathSeparator) { it.absolutePath })
}
}
override fun buildSourceArgs(): List<String> = mutableListOf<String>().apply {
addAll(getSource().map { it.absolutePath })
if (!commonSourcesTree.isEmpty) {
add("-Xcommon-sources=${commonSourcesTree.map { it.absolutePath }.joinToString(separator = ",")}")
add("-Xcommon-sources=${commonSourcesTree.joinToString(separator = ",") { it.absolutePath }}")
}
}
// endregion.
@@ -600,7 +601,7 @@ constructor(
linkerOpts.forEach {
addArg("-linker-option", it)
}
exportLibraries.files.filterKlibsPassedToCompiler(project).forEach {
exportLibraries.files.filterKlibsPassedToCompiler().forEach {
add("-Xexport-library=${it.absolutePath}")
}
addKey("-Xstatic-framework", isStaticFramework)
@@ -622,7 +623,7 @@ constructor(
@get:Internal
val apiFilesProvider = project.provider {
project.configurations.getByName(compilation.apiConfigurationName).files.filterKlibsPassedToCompiler(project)
project.configurations.getByName(compilation.apiConfigurationName).files.filterKlibsPassedToCompiler()
}
private fun validatedExportedLibraries() {
@@ -631,7 +632,7 @@ constructor(
val failed = mutableSetOf<Dependency>()
exportConfiguration.allDependencies.forEach {
val dependencyFiles = exportConfiguration.files(it).filterKlibsPassedToCompiler(project)
val dependencyFiles = exportConfiguration.files(it).filterKlibsPassedToCompiler()
if (!apiFiles.containsAll(dependencyFiles)) {
failed.add(it)
}
@@ -803,7 +804,7 @@ internal class CacheBuilder(val project: Project, val binary: NativeBinary, val
getAllDependencies(dependency)
.flatMap { it.moduleArtifacts }
.map { it.file }
.filterKlibsPassedToCompiler(project)
.filterKlibsPassedToCompiler()
.forEach {
args += "-l"
args += it.absolutePath
@@ -1017,7 +1018,7 @@ open class CInteropProcess @Inject constructor(@get:Internal val settings: Defau
addArg("-linker-option", it)
}
libraries.files.filterKlibsPassedToCompiler(project).forEach { library ->
libraries.files.filterKlibsPassedToCompiler().forEach { library ->
addArg("-library", library.absolutePath)
}
@@ -164,7 +164,6 @@ abstract class AbstractKotlinCompile<T : CommonCompilerArguments>() : AbstractKo
cacheOnlyIfEnabledForKotlin()
}
@get:Internal
private val layout = project.layout
// avoid creating directory in getter: this can lead to failure in parallel build
@@ -353,11 +352,9 @@ abstract class AbstractKotlinCompile<T : CommonCompilerArguments>() : AbstractKo
}
}
protected open fun skipCondition(inputs: IncrementalTaskInputs): Boolean {
return !inputs.isIncremental && getSourceRoots().kotlinSourceFiles.isEmpty()
}
protected open fun skipCondition(): Boolean =
getSourceRoots().kotlinSourceFiles.isEmpty()
@get:Internal
private val projectDir = project.rootProject.projectDir
private fun executeImpl(inputs: IncrementalTaskInputs) {
@@ -369,7 +366,7 @@ abstract class AbstractKotlinCompile<T : CommonCompilerArguments>() : AbstractKo
logger.kotlinDebug { "All kotlin sources: ${allKotlinSources.pathsAsStringRelativeTo(projectDir)}" }
if (skipCondition(inputs)) {
if (!inputs.isIncremental && skipCondition()) {
// Skip running only if non-incremental run. Otherwise, we may need to do some cleanup.
logger.kotlinDebug { "No Kotlin files found, skipping Kotlin compiler task" }
return
@@ -453,7 +450,7 @@ class KotlinJvmCompilerArgumentsProvider
compileClasspath = taskProvider.compileClasspath
destinationDir = taskProvider.destinationDir
kotlinOptions = listOfNotNull(
taskProvider.parentKotlinOptionsImpl as KotlinJvmOptionsImpl?,
taskProvider.parentKotlinOptionsImpl,
taskProvider.kotlinOptions as KotlinJvmOptionsImpl
)
}