From faabc4e3ad1a7b77d7ed95da3e255c7d15582fac Mon Sep 17 00:00:00 2001 From: Albin Date: Thu, 15 Aug 2024 16:27:58 +0200 Subject: [PATCH] Refactor lockfile script and gradle tasks --- .github/workflows/android-app.yml | 10 ++++----- .github/workflows/android-audit.yml | 4 ---- android/app/build.gradle.kts | 33 +++++++++++++---------------- android/scripts/update-lockfile.sh | 21 ++++++++++++++++-- build-apk.sh | 3 ++- 5 files changed, 41 insertions(+), 30 deletions(-) diff --git a/.github/workflows/android-app.yml b/.github/workflows/android-app.yml index 48a8079369f7..22a9935ea307 100644 --- a/.github/workflows/android-app.yml +++ b/.github/workflows/android-app.yml @@ -114,7 +114,7 @@ jobs: uses: actions/cache@v4 id: cache-relay-list with: - path: build/relays.json + path: android/app/build/extraAssets/relays.json key: relay-list-${{ steps.get-date.outputs.date }} - name: Checkout repository @@ -128,14 +128,14 @@ jobs: env: RUSTFLAGS: --deny warnings run: | - mkdir -p build - cargo run --bin relay_list > build/relays.json + mkdir -p android/app/build/extraAssets + cargo run --bin relay_list > android/app/build/extraAssets/relays.json - name: Upload uses: actions/upload-artifact@v4 with: name: relay-list - path: build/relays.json + path: android/app/build/extraAssets/relays.json if-no-files-found: error retention-days: 7 @@ -313,7 +313,7 @@ jobs: - uses: actions/download-artifact@v4 with: name: relay-list - path: build + path: android/app/build/extraAssets/relays.json - name: Build app uses: burrunan/gradle-cache-action@v1 diff --git a/.github/workflows/android-audit.yml b/.github/workflows/android-audit.yml index e40111b46970..c0a0ca8f78b3 100644 --- a/.github/workflows/android-audit.yml +++ b/.github/workflows/android-audit.yml @@ -81,10 +81,6 @@ jobs: - name: Fix git dir run: git config --global --add safe.directory $(pwd) - # Needed until we improve the build system. - - name: Create dummy jni dir - run: mkdir -p android/app/build/extraJni - - name: Re-generate lockfile run: android/scripts/update-lockfile.sh diff --git a/android/app/build.gradle.kts b/android/app/build.gradle.kts index 3c01abf0803c..ecde2e9132bd 100644 --- a/android/app/build.gradle.kts +++ b/android/app/build.gradle.kts @@ -19,6 +19,7 @@ plugins { val repoRootPath = rootProject.projectDir.absoluteFile.parentFile.absolutePath val extraAssetsDirectory = "${project.buildDir}/extraAssets" +val relayListPath = "$extraAssetsDirectory/relays.json" val defaultChangelogAssetsDirectory = "$repoRootPath/android/src/main/play/release-notes/" val extraJniDirectory = "${project.buildDir}/extraJni" @@ -146,10 +147,6 @@ android { ) } - tasks.withType { dependsOn(getTasksByName("copyExtraAssets", true)) } - - tasks.withType { dependsOn(getTasksByName("copyExtraAssets", true)) } - // Suppressing since we don't seem have much of an option than using this api. The impact should // also be limited to tests. @Suppress("UnstableApiUsage") @@ -238,10 +235,14 @@ android { } createDistBundle.dependsOn("bundle$capitalizedVariantName") - } - project.tasks.assemble.dependsOn("ensureJniDirectoryExist") - project.tasks.assemble.dependsOn("ensureValidVersionCode") + // Ensure all relevant assemble tasks depend on our ensure tasks. + tasks.get("assemble$capitalizedVariantName").apply { + dependsOn(tasks.get("ensureRelayListExist")) + dependsOn(tasks.get("ensureJniDirectoryExist")) + dependsOn(tasks.get("ensureValidVersionCode")) + } + } } junitPlatform { @@ -274,14 +275,16 @@ configure { skipConfigurations = listOf("lintClassPath") } -tasks.register("copyExtraAssets", Copy::class) { - from("$repoRootPath/build") - include("relays.json") - into(extraAssetsDirectory) +tasks.register("ensureRelayListExist") { + doLast { + if (!file(relayListPath).exists()) { + throw GradleException("Missing relay list: $relayListPath") + } + } } tasks.register("ensureJniDirectoryExist") { - doFirst { + doLast { if (!file(extraJniDirectory).exists()) { throw GradleException("Missing JNI directory: $extraJniDirectory") } @@ -306,12 +309,6 @@ tasks.create("printVersion") { } } -afterEvaluate { - tasks.withType(com.android.build.gradle.internal.lint.AndroidLintAnalysisTask::class.java) { - mustRunAfter(tasks.getByName("copyExtraAssets")) - } -} - play { serviceAccountCredentials.set(file("play-api-key.json")) } dependencies { diff --git a/android/scripts/update-lockfile.sh b/android/scripts/update-lockfile.sh index d215da116bcf..83c8def349b7 100755 --- a/android/scripts/update-lockfile.sh +++ b/android/scripts/update-lockfile.sh @@ -11,7 +11,18 @@ GRADLE_OPTS="-Dorg.gradle.daemon=false" # We must provide a template for mktemp to work properly on macOS. GRADLE_USER_HOME=$(mktemp -d -t gradle-home-XXX) TEMP_GRADLE_PROJECT_CACHE_DIR=$(mktemp -d -t gradle-cache-XXX) -GRADLE_TASKS=("assemble" "compileDebugUnitTestKotlin" "assembleAndroidTest" "lint") +# Task list to discover all tasks and their dependencies since +# just running the suggested 'help' task isn't sufficient. +GRADLE_TASKS=( + "assemble" + "compileDebugUnitTestKotlin" + "assembleAndroidTest" + "lint" +) +EXCLUDED_GRADLE_TASKS=( + "-xensureRelayListExist" + "-xensureJniDirectoryExist" +) export GRADLE_OPTS export GRADLE_USER_HOME @@ -30,6 +41,12 @@ echo "" echo "Removing old components..." sed -i '//,/<\/components>/d' ../gradle/verification-metadata.xml +echo "" echo "Generating new components..." -../gradlew -q -p .. --project-cache-dir "$TEMP_GRADLE_PROJECT_CACHE_DIR" -M sha256 "${GRADLE_TASKS[@]}" +# Using a loop here since providing all tasks at once result in gradle task dependency issues. +for GRADLE_TASK in "${GRADLE_TASKS[@]}"; do + echo "Gradle task: $GRADLE_TASK" + ../gradlew -q -p .. --project-cache-dir "$TEMP_GRADLE_PROJECT_CACHE_DIR" -M sha256 "$GRADLE_TASK" "${EXCLUDED_GRADLE_TASKS[@]}" + echo "" +done diff --git a/build-apk.sh b/build-apk.sh index 517dd6f5d9e6..190e4e1f2ab2 100755 --- a/build-apk.sh +++ b/build-apk.sh @@ -73,6 +73,7 @@ else fi $GRADLE_CMD --console plain clean +mkdir -p "app/build/extraAssets" mkdir -p "app/build/extraJni" popd @@ -111,7 +112,7 @@ for ARCHITECTURE in ${ARCHITECTURES:-aarch64 armv7 x86_64 i686}; do done echo "Updating relays.json..." -cargo run --bin relay_list "${CARGO_ARGS[@]}" > build/relays.json +cargo run --bin relay_list "${CARGO_ARGS[@]}" > android/app/build/extraAssets/relays.json cd "$SCRIPT_DIR/android" $GRADLE_CMD --console plain "${GRADLE_TASKS[@]}"