Skip to content
This repository was archived by the owner on Oct 18, 2024. It is now read-only.

Commit 9e75fe6

Browse files
committed
build: remove Nyx plugin when building for F-Droid
1 parent 83a33ac commit 9e75fe6

File tree

3 files changed

+72
-7
lines changed

3 files changed

+72
-7
lines changed

gradle.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,6 @@ android.jetifier.ignorelist=common-30.2.2.jar
2323

2424
# TODO : Migrate
2525
android.nonTransitiveRClass=false
26+
27+
# DO NOT REMOVE!!
28+
# @@FDROID_PREBUILD_PROPS_INSERT@@

scripts/setup_fdroid_build.sh

Lines changed: 61 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,20 @@ versionCode="$2"
2929
DEFCONFIG_REPLACE_BEGIN="FDROID_PREBUILD_DEFCONFIG_REPLACE_BEGIN"
3030
DEFCONFIG_REPLACE_END="FDROID_PREBUILD_DEFCONFIG_REPLACE_END"
3131

32+
# settings.gradle
33+
SETTINGS_GRADLE_REPLACE_BEGIN="FDROID_PREBUILD_SETTINGS_REPLACE_BEGIN"
34+
SETTINGS_GRADLE_REPLACE_END="FDROID_PREBUILD_SETTINGS_REPLACE_END"
35+
3236
# Android productFlavors
3337
FLAVORS_INSERT="FDROID_PREBUILD_FLAVORS_INSERT"
3438

39+
# Insert Gradle properties
40+
PROPS_INSERT="FDROID_PREBUILD_PROPS_INSERT"
41+
3542
# File to update
36-
target_file="build.gradle.kts"
43+
build_gradle="build.gradle.kts"
44+
gradle_props="../gradle.properties"
45+
settings_gradle="../settings.gradle.kts"
3746

3847
flavorDef="productFlavors {\n"
3948

@@ -48,12 +57,61 @@ done
4857

4958
flavorDef+="}"
5059

60+
# Gradle properties
61+
propsDef="ide.build.fdroid=true\n"
62+
propsDef+="ide.build.fdroid.version=${versionName}\n"
63+
propsDef+="ide.build.fdroid.vercode=${versionCode}\n"
64+
65+
66+
# settings.gradle
67+
settingsDef=$(cat <<- END
68+
val properties = File(rootDir, "gradle.properties").let { props ->
69+
java.util.Properties().also {
70+
it.load(props.reader())
71+
}
72+
}
73+
74+
val isFDroidBuild = properties.getProperty("ide.build.fdroid", "true").toBoolean()
75+
76+
val fdroidVersionName = requireNotNull(properties.getProperty("ide.build.fdroid.version", null)) {
77+
"'ide.build.fdroid' is 'true' but no 'ide.build.fdroid.version' is defined!"
78+
}
79+
80+
gradle.beforeProject {
81+
if (project.path == ":") {
82+
gradle.rootProject.version = "v" + fdroidVersionName
83+
}
84+
}
85+
END
86+
87+
)
88+
5189
# Replace properties in defaultConfig with constants
5290
sed -i "/\/\/ @@$DEFCONFIG_REPLACE_BEGIN@@/,/\/\/ @@$DEFCONFIG_REPLACE_END@@/c\
5391
applicationId = \"com.itsaky.androidide\" \n \
5492
versionName = \"$versionName\" \n \
55-
versionCode = $versionCode \n" $target_file
93+
versionCode = $versionCode \n" $build_gradle
5694

5795
# Add product flavors
5896
sed -i "/\/\/ @@$FLAVORS_INSERT@@/c\
59-
$flavorDef" $target_file
97+
$flavorDef" $build_gradle
98+
99+
# Remove the Nyx plugin from settings.gradle
100+
awk -v begin="$SETTINGS_GRADLE_REPLACE_BEGIN" -v end="$SETTINGS_GRADLE_REPLACE_END" -v replacement="$settingsDef" '
101+
$0 ~ ("// @@" begin "@@") {
102+
printing = 1;
103+
print replacement;
104+
next;
105+
}
106+
printing && $0 ~ ("// @@" end "@@") {
107+
printing = 0;
108+
next;
109+
}
110+
!printing
111+
' $settings_gradle > temp_settings.gradle && mv temp_settings.gradle $settings_gradle
112+
113+
114+
115+
# Insert Gradle properties
116+
sed -i "/# @@$PROPS_INSERT@@/c\
117+
$propsDef" $gradle_props

settings.gradle.kts

100755100644
Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
@file:Suppress("UnstableApiUsage")
22

3-
import com.mooltiverse.oss.nyx.gradle.NyxExtension
4-
53
enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS")
64

75
pluginManagement {
@@ -13,9 +11,14 @@ pluginManagement {
1311
}
1412
}
1513

16-
plugins { id("com.mooltiverse.oss.nyx") version "2.5.1" }
14+
// DO NOT REMOVE THESE COMMENTS!
15+
// @@FDROID_PREBUILD_SETTINGS_REPLACE_BEGIN@@
16+
plugins {
17+
id("com.mooltiverse.oss.nyx") version "2.5.1"
18+
}
1719

18-
extensions.configure<NyxExtension> {
20+
// DO NOT REPLACE WITH IMPORT!!
21+
extensions.configure<com.mooltiverse.oss.nyx.gradle.NyxExtension> {
1922
git {
2023
remotes.register("origin") {
2124
user.set("{{#environmentVariable}}GH_TOKEN{{/environmentVariable}}")
@@ -24,6 +27,7 @@ extensions.configure<NyxExtension> {
2427
}
2528
configurationFile.set(".nyx.yml")
2629
}
30+
// @@FDROID_PREBUILD_SETTINGS_REPLACE_END@@
2731

2832
dependencyResolutionManagement {
2933
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)

0 commit comments

Comments
 (0)