Skip to content

Commit

Permalink
Merge branch 'refactor-lockfile-script-task-dependencies-droid-1254'
Browse files Browse the repository at this point in the history
  • Loading branch information
albin-mullvad committed Aug 15, 2024
2 parents cb1df6a + faabc4e commit c48ea67
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 30 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/android-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions .github/workflows/android-audit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
33 changes: 15 additions & 18 deletions android/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -146,10 +147,6 @@ android {
)
}

tasks.withType<MergeSourceSetFolders> { dependsOn(getTasksByName("copyExtraAssets", true)) }

tasks.withType<LintModelWriterTask> { 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")
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -274,14 +275,16 @@ configure<org.owasp.dependencycheck.gradle.extension.DependencyCheckExtension> {
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")
}
Expand All @@ -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 {
Expand Down
21 changes: 19 additions & 2 deletions android/scripts/update-lockfile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -30,6 +41,12 @@ echo ""

echo "Removing old components..."
sed -i '/<components>/,/<\/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
3 changes: 2 additions & 1 deletion build-apk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ else
fi

$GRADLE_CMD --console plain clean
mkdir -p "app/build/extraAssets"
mkdir -p "app/build/extraJni"
popd

Expand Down Expand Up @@ -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[@]}"
Expand Down

0 comments on commit c48ea67

Please sign in to comment.