Skip to content

Commit

Permalink
chore: solve foss source sets and dependencies statically 🍒 (#3083)
Browse files Browse the repository at this point in the history
Co-authored-by: Vitor Hugo Schwaab <[email protected]>
  • Loading branch information
github-actions[bot] and vitorhugods committed Jun 7, 2024
1 parent 61eacdc commit 8bc646b
Showing 1 changed file with 22 additions and 28 deletions.
50 changes: 22 additions & 28 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,9 @@ 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

private fun getFlavorsSettings(): NormalizedFlavorSettings =
try {
Expand All @@ -76,21 +74,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 @@ -193,15 +187,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 8bc646b

Please sign in to comment.