Skip to content

Commit

Permalink
chore: solve foss source sets and dependencies statically (#3082)
Browse files Browse the repository at this point in the history
  • Loading branch information
vitorhugods authored Jun 6, 2024
1 parent 9d2d278 commit 9fa0228
Showing 1 changed file with 23 additions and 28 deletions.
51 changes: 23 additions & 28 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,10 @@ repositories {
google()
}

fun isFossSourceSet(): Boolean {
return (Variants_gradle.Default.explicitBuildFlavor() ?: gradle.startParameter.taskRequests.toString())
.lowercase()
.contains("fdroid")
}
val nonFreeFlavors = setOf("prod", "internal", "staging", "beta", "dev")
val fossFlavors = setOf("fdroid")
val allFlavors = nonFreeFlavors + fossFlavors

android {
// Most of the configuration is done in the build-logic
// through the Wire Application convention plugin
Expand All @@ -64,21 +63,17 @@ android {
}
android.buildFeatures.buildConfig = true

val fdroidBuild = isFossSourceSet()

sourceSets {
// Add the "foss" sourceSets for the fdroid flavor
if (fdroidBuild) {
getByName("fdroid") {
java.srcDirs("src/foss/kotlin", "src/prod/kotlin")
res.srcDirs("src/prod/res")
println("Building with FOSS sourceSets")
}
// For all other flavors use the "nonfree" sourceSets
} else {
getByName("main") {
java.srcDirs("src/nonfree/kotlin")
println("Building with non-free sourceSets")
allFlavors.forEach { flavor ->
getByName(flavor) {
if (flavor in fossFlavors) {
java.srcDirs("src/foss/kotlin", "src/prod/kotlin")
res.srcDirs("src/prod/res")
println("Adding FOSS sourceSets to '$flavor' flavor")
} else {
java.srcDirs("src/nonfree/kotlin")
println("Adding non-free sourceSets to '$flavor' flavor")
}
}
}
}
Expand Down Expand Up @@ -181,15 +176,15 @@ dependencies {
implementation(libs.resaca.hilt)
implementation(libs.bundlizer.core)

var fdroidBuild = isFossSourceSet()

if (!fdroidBuild) {
// firebase
implementation(platform(libs.firebase.bom))
implementation(libs.firebase.fcm)
implementation(libs.googleGms.location)
} else {
println("Excluding FireBase for FDroid build")
allFlavors.forEach { flavor ->
if (flavor in nonFreeFlavors) {
println("Adding nonfree libraries to '$flavor' flavor")
add("${flavor}Implementation", platform(libs.firebase.bom))
add("${flavor}Implementation", libs.firebase.fcm)
add("${flavor}Implementation", libs.googleGms.location)
} else {
println("Skipping nonfree libraries for '$flavor' flavor")
}
}
implementation(libs.androidx.work)

Expand Down

0 comments on commit 9fa0228

Please sign in to comment.