Skip to content

Commit

Permalink
Consolidate to only use AndroidXExtension.type to control publishing
Browse files Browse the repository at this point in the history
Removing all uses of AndroidXExtension.publish replacing it with appropriate AndroidXExtension.type within build.gradle files

Also refactor LibraryTypes by a single class `ConfigurableLibray` to make it simpler to add new types, reducing code dups

BUG: 327630926
TESTED: Ran ./gradlew bOS --dry-run and it was the same as HEAD

Change-Id: I0f65a086a1c47e537864ce1fdca8975cbb2da581
  • Loading branch information
omarismail94 committed Dec 19, 2024
1 parent d99a1f6 commit a293b97
Show file tree
Hide file tree
Showing 90 changed files with 439 additions and 304 deletions.
6 changes: 6 additions & 0 deletions appcompat/appcompat-benchmark/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
* limitations under the License.
*/

import androidx.build.LibraryType

plugins {
id("AndroidXPlugin")
id("com.android.library")
Expand All @@ -34,3 +36,7 @@ dependencies {
android {
namespace = "androidx.appcompat.benchmark"
}

androidx {
type = LibraryType.BENCHMARK
}
4 changes: 2 additions & 2 deletions benchmark/benchmark-darwin-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* modifying its settings.
*/
import androidx.build.PlatformIdentifier
import androidx.build.Publish
import androidx.build.LibraryType
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
import org.jetbrains.kotlin.gradle.plugin.mpp.BitcodeEmbeddingMode

Expand Down Expand Up @@ -54,7 +54,7 @@ androidXMultiplatform {

androidx {
name = "Benchmarks - Darwin Core"
type = LibraryType.SNAPSHOT_ONLY_LIBRARY
inceptionYear = "2022"
description = "AndroidX Benchmarks - Darwin Core"
publish = Publish.SNAPSHOT_ONLY
}
2 changes: 1 addition & 1 deletion benchmark/benchmark-darwin-gradle-plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ gradlePlugin {

androidx {
name = "Benchmarks - Darwin Gradle Plugin"
type = LibraryType.GRADLE_PLUGIN
type = LibraryType.INTERNAL_GRADLE_PLUGIN
inceptionYear = "2022"
description = "AndroidX Benchmarks - Darwin Gradle Plugin"
}
4 changes: 2 additions & 2 deletions benchmark/benchmark-darwin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* modifying its settings.
*/
import androidx.build.PlatformIdentifier
import androidx.build.Publish
import androidx.build.LibraryType
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
import org.jetbrains.kotlin.gradle.plugin.mpp.BitcodeEmbeddingMode
import org.jetbrains.kotlin.gradle.plugin.mpp.apple.XCFrameworkConfig
Expand Down Expand Up @@ -87,5 +87,5 @@ androidx {
name = "Benchmarks - Darwin"
inceptionYear = "2022"
description = "AndroidX Benchmarks - Darwin"
publish = Publish.SNAPSHOT_ONLY
type = LibraryType.SNAPSHOT_ONLY_LIBRARY
}
2 changes: 1 addition & 1 deletion benchmark/benchmark/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,5 @@ android {
}

androidx {
type = LibraryType.INTERNAL_TEST_LIBRARY
type = LibraryType.BENCHMARK
}
6 changes: 6 additions & 0 deletions benchmark/integration-tests/dry-run-benchmark/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
* limitations under the License.
*/

import androidx.build.LibraryType

plugins {
id("AndroidXPlugin")
id("com.android.library")
Expand All @@ -32,3 +34,7 @@ dependencies {
android {
namespace = "androidx.benchmark.integration.dryrun.benchmark"
}

androidx {
type = LibraryType.BENCHMARK
}
6 changes: 6 additions & 0 deletions benchmark/integration-tests/startup-benchmark/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
* limitations under the License.
*/

import androidx.build.LibraryType

plugins {
id("AndroidXPlugin")
id("com.android.library")
Expand All @@ -32,3 +34,7 @@ dependencies {
android {
namespace = "androidx.benchmark.integration.startup.benchmark"
}

androidx {
type = LibraryType.BENCHMARK
}
1 change: 0 additions & 1 deletion bluetooth/integration-tests/testapp/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* Please use that script when creating a new project, rather than copying an existing project and
* modifying its settings.
*/
import androidx.build.Publish

/*
* Copyright 2022 The Android Open Source Project
Expand Down
4 changes: 1 addition & 3 deletions buildSrc-tests/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import androidx.build.LibraryType
import androidx.build.KotlinTarget
import androidx.build.Publish

plugins {
id("AndroidXPlugin")
Expand Down Expand Up @@ -90,8 +89,7 @@ tasks.withType(Test).configureEach {
}

androidx {
type = LibraryType.GRADLE_PLUGIN
publish = Publish.NONE
type = LibraryType.INTERNAL_GRADLE_PLUGIN
kotlinTarget = KotlinTarget.KOTLIN_1_9
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
* modifying its settings.
*/
import androidx.build.LibraryType
import androidx.build.Publish

plugins {
id("AndroidXPlugin")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1062,8 +1062,7 @@ constructor(private val componentFactory: SoftwareComponentFactory) : Plugin<Pro
val isProbablyPublished =
androidXExtension.type == LibraryType.PUBLISHED_LIBRARY ||
androidXExtension.type ==
LibraryType.PUBLISHED_LIBRARY_ONLY_USED_BY_KOTLIN_CONSUMERS ||
androidXExtension.type == LibraryType.UNSET
LibraryType.PUBLISHED_LIBRARY_ONLY_USED_BY_KOTLIN_CONSUMERS
if (mavenGroup != null && isProbablyPublished && androidXExtension.shouldPublish()) {
validateProjectMavenGroup(mavenGroup.group)
validateProjectMavenName(androidXExtension.name.get(), mavenGroup.group)
Expand Down Expand Up @@ -1310,7 +1309,7 @@ constructor(private val componentFactory: SoftwareComponentFactory) : Plugin<Pro
) {
if (buildFeatures.isIsolatedProjectsEnabled()) return
afterEvaluate {
if (androidXExtension.type !in listOf(LibraryType.UNSET, LibraryType.SAMPLES)) {
if (androidXExtension.type.requiresDependencyVerification()) {
val verifyDependencyVersionsTask = project.createVerifyDependencyVersionsTask()
if (verifyDependencyVersionsTask != null) {
taskConfigurator(verifyDependencyVersionsTask)
Expand Down Expand Up @@ -1635,10 +1634,6 @@ fun Project.validateProjectParser(androidXExtension: AndroidXExtension) {
"$errorPrefix Incorrectly computed libraryType = ${parsed.libraryType} " +
"instead of ${androidXExtension.type}"
}
check(androidXExtension.publish == parsed.publish) {
"$errorPrefix Incorrectly computed publish = ${parsed.publish} " +
"instead of ${androidXExtension.publish}"
}
check(androidXExtension.shouldPublish() == parsed.shouldPublish()) {
"$errorPrefix Incorrectly computed shouldPublish() = ${parsed.shouldPublish()} " +
"instead of ${androidXExtension.shouldPublish()}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,10 @@ private fun Project.configureLint(lint: Lint, isLibrary: Boolean) {
val lintChecksProject = findLintProject(":lint-checks") ?: return
project.dependencies.add("lintChecks", lintChecksProject)

if (extension.type == LibraryType.GRADLE_PLUGIN) {
if (
extension.type == LibraryType.GRADLE_PLUGIN ||
extension.type == LibraryType.INTERNAL_GRADLE_PLUGIN
) {
project.rootProject.findProject(":lint:lint-gradle")?.let {
project.dependencies.add("lintChecks", it)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,22 +294,15 @@ abstract class AndroidXExtension(

private var extraLicenses: MutableCollection<License> = ArrayList()

// Should only be used to override LibraryType.publish, if a library isn't ready to publish yet
var publish: Publish = Publish.UNSET

fun shouldPublish(): Boolean =
if (publish != Publish.UNSET) {
publish.shouldPublish()
} else if (type != LibraryType.UNSET) {
if (type != LibraryType.UNSET) {
type.publish.shouldPublish()
} else {
false
}

fun shouldRelease(): Boolean =
if (publish != Publish.UNSET) {
publish.shouldRelease()
} else if (type != LibraryType.UNSET) {
if (type != LibraryType.UNSET) {
type.publish.shouldRelease()
} else {
false
Expand All @@ -323,7 +316,7 @@ abstract class AndroidXExtension(
}
}

fun isPublishConfigured(): Boolean = (publish != Publish.UNSET || type.publish != Publish.UNSET)
fun isPublishConfigured(): Boolean = type.publish != Publish.UNSET

fun shouldPublishSbom(): Boolean {
if (isIsolatedProjectsEnabled()) return false
Expand Down
Loading

0 comments on commit a293b97

Please sign in to comment.