diff --git a/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/bitcode/CompileToBitcodePlugin.kt b/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/bitcode/CompileToBitcodePlugin.kt index 2e7f1fa40c7..15c12af7331 100644 --- a/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/bitcode/CompileToBitcodePlugin.kt +++ b/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/bitcode/CompileToBitcodePlugin.kt @@ -10,10 +10,7 @@ import org.gradle.api.* import org.gradle.api.artifacts.Configuration import org.gradle.api.artifacts.ConfigurationVariant import org.gradle.api.attributes.Usage -import org.gradle.api.file.ConfigurableFileCollection -import org.gradle.api.file.ConfigurableFileTree -import org.gradle.api.file.DirectoryProperty -import org.gradle.api.file.RegularFileProperty +import org.gradle.api.file.* import org.gradle.api.provider.ListProperty import org.gradle.api.provider.Property import org.gradle.api.provider.Provider @@ -104,28 +101,28 @@ open class CompileToBitcodeExtension @Inject constructor(val project: Project) : this.factory = { target -> project.objects.newInstance(this, target) } - } - /** - * Outgoing configuration with `main` parts of all modules. - */ - val compileBitcodeMainElements = project.compileBitcodeElements(MAIN_SOURCE_SET_NAME) + /** + * Outgoing configuration with `main` parts of all modules. + */ + project.compileBitcodeElements(MAIN_SOURCE_SET_NAME) - /** - * Outgoing configuration with `testFixtures` parts of all modules. - */ - val compileBitcodeTestFixturesElements = project.compileBitcodeElements(TEST_FIXTURES_SOURCE_SET_NAME) { - outgoing { - capability(CppConsumerPlugin.testFixturesCapability(project)) + /** + * Outgoing configuration with `testFixtures` parts of all modules. + */ + project.compileBitcodeElements(TEST_FIXTURES_SOURCE_SET_NAME) { + outgoing { + capability(CppConsumerPlugin.testFixturesCapability(project)) + } } - } - /** - * Outgoing configuration with `test` parts of all modules. - */ - val compileBitcodeTestElements = project.compileBitcodeElements(TEST_SOURCE_SET_NAME) { - outgoing { - capability(CppConsumerPlugin.testCapability(project)) + /** + * Outgoing configuration with `test` parts of all modules. + */ + project.compileBitcodeElements(TEST_SOURCE_SET_NAME) { + outgoing { + capability(CppConsumerPlugin.testCapability(project)) + } } } @@ -198,12 +195,12 @@ open class CompileToBitcodeExtension @Inject constructor(val project: Project) : */ abstract val dependencies: ListProperty> - protected abstract val onlyIf: ListProperty> + protected abstract val onlyIf: ListProperty> /** * Builds this source set only if [spec] is satisfied. */ - fun onlyIf(spec: Spec) { + fun onlyIf(spec: Spec) { this.onlyIf.add(spec) } @@ -234,8 +231,10 @@ open class CompileToBitcodeExtension @Inject constructor(val project: Project) : dependsOn(nativeDependencies.llvmDependency) dependsOn(nativeDependencies.targetDependency(_target)) dependsOn(this@SourceSet.dependencies) + val specs = this@SourceSet.onlyIf + val target = target onlyIf { - this@SourceSet.onlyIf.get().all { it.isSatisfiedBy(this@SourceSet) } + specs.get().all { it.isSatisfiedBy(target) } } } compilationDatabase.target(_target) { @@ -268,8 +267,10 @@ open class CompileToBitcodeExtension @Inject constructor(val project: Project) : this.inputFiles.from(compileTask) this.outputFile.set(this@SourceSet.outputFile) this.arguments.set(module.linkerArgs) + val specs = this@SourceSet.onlyIf + val target = target onlyIf { - this@SourceSet.onlyIf.get().all { it.isSatisfiedBy(this@SourceSet) } + specs.get().all { it.isSatisfiedBy(target) } } } project.compileBitcodeElements(this@SourceSet.name).targetVariant(_target).artifact(this) @@ -363,40 +364,43 @@ open class CompileToBitcodeExtension @Inject constructor(val project: Project) : } } + private val project by owner::project + + init { + + /** + * Outgoing configuration with `main` part of this module. + */ + project.moduleCompileBitcodeElements(name, MAIN_SOURCE_SET_NAME) { + outgoing { + capability(CppConsumerPlugin.moduleCapability(project, this@Module.name)) + } + } + + /** + * Outgoing configuration with `testFixtures` part of this module. + */ + project.moduleCompileBitcodeElements(name, TEST_FIXTURES_SOURCE_SET_NAME) { + outgoing { + capability(CppConsumerPlugin.moduleTestFixturesCapability(project, this@Module.name)) + } + } + + /** + * Outgoing configuration with `test` part of this module. + */ + project.moduleCompileBitcodeElements(name, TEST_SOURCE_SET_NAME) { + outgoing { + capability(CppConsumerPlugin.moduleTestCapability(project, this@Module.name)) + } + } + } + val target by _target::target val sanitizer by _target::sanitizer override fun getName() = name - private val project by owner::project - - /** - * Outgoing configuration with `main` part of this module. - */ - val compileBitcodeMainElements = project.moduleCompileBitcodeElements(name, MAIN_SOURCE_SET_NAME) { - outgoing { - capability(CppConsumerPlugin.moduleCapability(project, this@Module.name)) - } - } - - /** - * Outgoing configuration with `testFixtures` part of this module. - */ - val compileBitcodeTestFixturesElements = project.moduleCompileBitcodeElements(name, TEST_FIXTURES_SOURCE_SET_NAME) { - outgoing { - capability(CppConsumerPlugin.moduleTestFixturesCapability(project, this@Module.name)) - } - } - - /** - * Outgoing configuration with `test` part of this module. - */ - val compileBitcodeTestElements = project.moduleCompileBitcodeElements(name, TEST_SOURCE_SET_NAME) { - outgoing { - capability(CppConsumerPlugin.moduleTestCapability(project, this@Module.name)) - } - } - /** * Directory where module sources are located. By default `src/`. */ @@ -432,12 +436,12 @@ open class CompileToBitcodeExtension @Inject constructor(val project: Project) : * Extra tqsk dependencies to be used for all [SourceSet]s. */ abstract val dependencies: ListProperty> - protected abstract val onlyIf: ListProperty> + protected abstract val onlyIf: ListProperty> /** * Builds this module only if [spec] is satisfied. */ - fun onlyIf(spec: Spec) { + fun onlyIf(spec: Spec) { this.onlyIf.add(spec) } @@ -453,8 +457,10 @@ open class CompileToBitcodeExtension @Inject constructor(val project: Project) : this.inputFiles.from(this@Module.srcRoot.dir("cpp")) this.headersDirs.setFrom(this@Module.headersDirs) dependencies.set(this@Module.dependencies) + val specs = this@Module.onlyIf + val target = target onlyIf { - this@Module.onlyIf.get().all { it.isSatisfiedBy(this@Module) } + specs.get().all { it.isSatisfiedBy(target) } } } } @@ -612,9 +618,9 @@ open class CompileToBitcodeExtension @Inject constructor(val project: Project) : tsanSuppressionsFile.set(project.layout.projectDirectory.file("tsan_suppressions.txt")) this.target.set(target) this.executionTimeout.set( - (project.findProperty("gtest_timeout") as? String)?.let { - Duration.parse("PT${it}") - } ?: Duration.ofMinutes(5)) + (project.findProperty("gtest_timeout") as? String)?.let { + Duration.parse("PT${it}") + } ?: Duration.ofMinutes(5)) usesService(runGTestSemaphore) } diff --git a/kotlin-native/runtime/build.gradle.kts b/kotlin-native/runtime/build.gradle.kts index bcd91a02242..8768d75e61d 100644 --- a/kotlin-native/runtime/build.gradle.kts +++ b/kotlin-native/runtime/build.gradle.kts @@ -90,7 +90,7 @@ bitcode { "-DMI_TSAN=1".takeIf { sanitizer == SanitizerKind.THREAD }, )) - onlyIf { target.supportsMimallocAllocator() } + onlyIf { it.supportsMimallocAllocator() } } module("libbacktrace") { @@ -142,7 +142,7 @@ bitcode { "-Wno-atomic-alignment" )) - onlyIf { target.supportsLibBacktrace() } + onlyIf { it.supportsLibBacktrace() } } module("compiler_interface") { @@ -251,7 +251,7 @@ bitcode { main {} } - onlyIf { target.supportsCoreSymbolication() } + onlyIf { it.supportsCoreSymbolication() } } module("source_info_libbacktrace") { @@ -261,7 +261,7 @@ bitcode { main {} } - onlyIf { target.supportsLibBacktrace() } + onlyIf { it.supportsLibBacktrace() } } module("objc") { @@ -488,7 +488,7 @@ bitcode { sourceSets { main {} } - onlyIf { target.family.isAppleFamily } + onlyIf { it.family.isAppleFamily } } } }