build: update F-Droid config

This commit is contained in:
Akash Yadav
2023-12-31 17:13:53 +05:30
parent 7c962905e4
commit ab301ddd28
7 changed files with 141 additions and 140 deletions
+6
View File
@@ -77,3 +77,9 @@ services:
REPOSITORY_OWNER: "AndroidIDEOfficial"
REPOSITORY_NAME: "AndroidIDE"
AUTHENTICATION_TOKEN: "{{#environmentVariable}}GH_TOKEN{{/environmentVariable}}"
git:
remotes:
origin:
user: '{{#environmentVariable}}GH_TOKEN{{/environmentVariable}}'
password: ''
@@ -0,0 +1,62 @@
import org.gradle.api.Project
import java.io.File
/*
* This file is part of AndroidIDE.
*
* AndroidIDE is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* AndroidIDE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with AndroidIDE. If not, see <https://www.gnu.org/licenses/>.
*/
/**
* @author Akash Yadav
*/
object FDroidConfig {
var hasRead: Boolean = false
private set
var isFDroidBuild: Boolean = false
private set
var fDroidVersionName: String? = null
private set
var fDroidVersionCode: Int? = null
private set
const val PROP_FDROID_BUILD = "ide.build.fdroid"
const val PROP_FDROID_BUILD_VERSION = "ide.build.fdroid.version"
const val PROP_FDROID_BUILD_VERCODE = "ide.build.fdroid.vercode"
fun load(project: Project) {
val propsFile = File(project.rootDir, "fdroid.properties")
if (!propsFile.exists() || !propsFile.isFile) {
hasRead = true
isFDroidBuild = false
return
}
val properties = propsFile.let { props ->
java.util.Properties().also {
it.load(props.reader())
}
}
hasRead = true
isFDroidBuild = properties.getProperty(PROP_FDROID_BUILD, null).toBoolean()
fDroidVersionName = properties.getProperty(PROP_FDROID_BUILD_VERSION, null)
fDroidVersionCode = properties.getProperty(PROP_FDROID_BUILD_VERCODE, null)?.toInt()
}
}
@@ -38,7 +38,12 @@ private var shouldPrintVersionName = true
* Whether this build is being executed in the F-Droid build server.
*/
val Project.isFDroidBuild: Boolean
get() = hasProperty(PROP_IDE_BUILD_FDROID) && property(PROP_IDE_BUILD_FDROID) == "true"
get() {
if (!FDroidConfig.hasRead) {
FDroidConfig.load(this)
}
return FDroidConfig.isFDroidBuild
}
val Project.simpleVersionName: String
get() {
@@ -78,19 +78,12 @@ fun Project.configureAndroidModule(
"\"${abi}\"")
}
// Do not configure flavorDimensions here when building with F-Droid
// flavor dimensions for F-Droid builds are configured in <root>/scripts/setup_fdroid_build.sh
//
// IMPORTANT: When changing the configuration here, make sure to update the following file:
// - <root>/scripts/setup_fdroid_build.sh
if (!isFDroidBuild) {
productFlavors {
flavorsAbis.forEach { (abi, verCodeIncrement) ->
val flavor = create(abi)
flavor.versionNameSuffix = "-${abi}"
flavor.versionCode = 100 * projectVersionCode + verCodeIncrement
}
productFlavors {
val fdroidSuffix = if (isFDroidBuild) "-fdroid" else ""
flavorsAbis.forEach { (abi, verCodeIncrement) ->
val flavor = create(abi)
flavor.versionNameSuffix = "-${abi}${fdroidSuffix}"
flavor.versionCode = 100 * projectVersionCode + verCodeIncrement
}
}
} else {
+7 -4
View File
@@ -18,12 +18,11 @@
@file:Suppress("UnstableApiUsage")
import com.itsaky.androidide.plugins.AndroidIDEPlugin
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import com.itsaky.androidide.plugins.conf.configureAndroidModule
import com.itsaky.androidide.plugins.conf.configureJavaModule
import com.itsaky.androidide.plugins.conf.configureMavenPublish
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
@Suppress("DSL_SCOPE_VIOLATION")
plugins {
id("build-logic.root-project")
alias(libs.plugins.android.application) apply false
@@ -49,8 +48,12 @@ subprojects {
project.group = BuildConfig.packageName
project.version = rootProject.version
plugins.withId("com.android.application") { configureAndroidModule(libs.androidx.lib.desugaring.get()) }
plugins.withId("com.android.library") { configureAndroidModule(libs.androidx.lib.desugaring.get()) }
plugins.withId("com.android.application") {
configureAndroidModule(libs.androidx.lib.desugaring.get())
}
plugins.withId("com.android.library") {
configureAndroidModule(libs.androidx.lib.desugaring.get())
}
plugins.withId("java-library") { configureJavaModule() }
plugins.withId("com.vanniktech.maven.publish.base") { configureMavenPublish() }
-109
View File
@@ -1,109 +0,0 @@
#!/bin/bash
#
# This file is part of AndroidIDE.
#
# AndroidIDE is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# AndroidIDE is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with AndroidIDE. If not, see <https://www.gnu.org/licenses/>.
#
set -eu
# Arguments are positional
# 1 - version name
# 2 - version code
versionName="$1" # Format: $major.$minor.$patch-$type-$abi e.g. 2.7.0-beta-arm64
versionCode="$2" # Format: $major$minor$patch e.g. 270
# Android defaultConfig
DEFCONFIG_REPLACE_BEGIN="FDROID_PREBUILD_DEFCONFIG_REPLACE_BEGIN"
DEFCONFIG_REPLACE_END="FDROID_PREBUILD_DEFCONFIG_REPLACE_END"
# settings.gradle
SETTINGS_GRADLE_REPLACE_BEGIN="FDROID_PREBUILD_SETTINGS_REPLACE_BEGIN"
SETTINGS_GRADLE_REPLACE_END="FDROID_PREBUILD_SETTINGS_REPLACE_END"
# Android productFlavors
FLAVORS_INSERT="FDROID_PREBUILD_FLAVORS_INSERT"
# File to update
build_gradle="build.gradle.kts"
gradle_props="../fdroid.properties"
settings_gradle="../settings.gradle.kts"
flavorDef="productFlavors {\n"
i=1
for arch in arm64-v8a armeabi-v7a x86_64; do
flavorDef+="create(\"$arch\") { \n"
flavorDef+=" versionNameSuffix = \"-fdroid\" \n"
flavorDef+=" versionCode = 100 * $versionCode + $i \n"
flavorDef+="}\n"
i=$((i + 1))
done
flavorDef+="}"
# settings.gradle
settingsDef=$(
cat <<-END
val propsFile = File(rootDir, "fdroid.properties")
if (!propsFile.exists() || !propsFile.isFile) {
throw GradleException("fdroid.properties file does not exist or is not a file")
}
val properties = propsFile.let { props ->
java.util.Properties().also {
it.load(props.reader())
}
}
val isFDroidBuild = properties.getProperty("ide.build.fdroid", "true").toBoolean()
val fdroidVersionName = requireNotNull(properties.getProperty("ide.build.fdroid.version", null)) {
"'ide.build.fdroid' is 'true' but no 'ide.build.fdroid.version' is defined!"
}
gradle.rootProject { project.setProperty("version", fdroidVersionName) }
END
)
# Replace properties in defaultConfig with constants
sed -i "/\/\/ @@$DEFCONFIG_REPLACE_BEGIN@@/,/\/\/ @@$DEFCONFIG_REPLACE_END@@/c\
applicationId = \"com.itsaky.androidide\" \n \
versionName = \"$versionName\" \n \
versionCode = $versionCode \n" $build_gradle
# Add product flavors
sed -i "/\/\/ @@$FLAVORS_INSERT@@/c\
$flavorDef" $build_gradle
# Remove the Nyx plugin from settings.gradle
awk -v begin="$SETTINGS_GRADLE_REPLACE_BEGIN" -v end="$SETTINGS_GRADLE_REPLACE_END" -v replacement="$settingsDef" '
$0 ~ ("// @@" begin "@@") {
printing = 1;
print replacement;
next;
}
printing && $0 ~ ("// @@" end "@@") {
printing = 0;
next;
}
!printing
' $settings_gradle >temp_settings.gradle && mv temp_settings.gradle $settings_gradle
# Write Gradle properties
echo "ide.build.fdroid=true" >"$gradle_props"
echo "ide.build.fdroid.version=${versionName}" >>"$gradle_props"
echo "ide.build.fdroid.vercode=${versionCode}" >>"$gradle_props"
+54 -13
View File
@@ -11,23 +11,24 @@ pluginManagement {
}
}
// DO NOT REMOVE THESE COMMENTS!
// @@FDROID_PREBUILD_SETTINGS_REPLACE_BEGIN@@
plugins {
id("com.mooltiverse.oss.nyx") version "2.5.1"
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("com.mooltiverse.oss.nyx:gradle:2.5.1")
}
}
// DO NOT REPLACE WITH IMPORT!!
extensions.configure<com.mooltiverse.oss.nyx.gradle.NyxExtension> {
git {
remotes.register("origin") {
user.set("{{#environmentVariable}}GH_TOKEN{{/environmentVariable}}")
password.set("")
}
FDroidConfig.load(rootDir)
if (FDroidConfig.hasRead && FDroidConfig.isFDroidBuild) {
gradle.rootProject { project.setProperty("version", FDroidConfig.fDroidVersionName!!) }
} else {
apply {
plugin("com.mooltiverse.oss.nyx")
}
configurationFile.set(".nyx.yml")
}
// @@FDROID_PREBUILD_SETTINGS_REPLACE_END@@
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
@@ -108,3 +109,43 @@ include(
":testing:tooling",
":testing:unit",
)
object FDroidConfig {
var hasRead: Boolean = false
private set
var isFDroidBuild: Boolean = false
private set
var fDroidVersionName: String? = null
private set
var fDroidVersionCode: Int? = null
private set
const val PROP_FDROID_BUILD = "ide.build.fdroid"
const val PROP_FDROID_BUILD_VERSION = "ide.build.fdroid.version"
const val PROP_FDROID_BUILD_VERCODE = "ide.build.fdroid.vercode"
fun load(rootDir: File) {
val propsFile = File(rootDir, "fdroid.properties")
if (!propsFile.exists() || !propsFile.isFile) {
hasRead = true
isFDroidBuild = false
return
}
val properties = propsFile.let { props ->
java.util.Properties().also {
it.load(props.reader())
}
}
hasRead = true
isFDroidBuild = properties.getProperty(PROP_FDROID_BUILD, null).toBoolean()
fDroidVersionName = properties.getProperty(PROP_FDROID_BUILD_VERSION, null)
fDroidVersionCode = properties.getProperty(PROP_FDROID_BUILD_VERCODE, null)?.toInt()
}
}