From e06066528f00d59d04d37b9bbcc81cb8bd94a631 Mon Sep 17 00:00:00 2001 From: voczi Date: Sun, 13 Oct 2024 13:00:53 +0200 Subject: [PATCH 1/2] Add FSRS version to BuildConfig --- build_rust/src/main.rs | 1 + rsdroid/build.gradle | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/build_rust/src/main.rs b/build_rust/src/main.rs index 3fca0498e..0d3c0fe56 100644 --- a/build_rust/src/main.rs +++ b/build_rust/src/main.rs @@ -143,6 +143,7 @@ fn build_android_jni() -> Result<()> { let (is_release, _release_dir) = check_release(false); Command::run("cargo install cargo-ndk@3.5.4")?; + Command::run("cargo install jaq@1.6.0")?; let mut command = Command::new("cargo"); command diff --git a/rsdroid/build.gradle b/rsdroid/build.gradle index 999de539b..0687b027a 100644 --- a/rsdroid/build.gradle +++ b/rsdroid/build.gradle @@ -2,6 +2,7 @@ import com.android.build.gradle.tasks.BundleAar import com.vanniktech.maven.publish.SonatypeHost import org.jetbrains.kotlin.gradle.tasks.KotlinCompile import java.util.zip.ZipFile +import org.gradle.internal.os.OperatingSystem apply plugin: 'com.android.library' // required for aar generation to link to from AnkiDroid apply plugin: "kotlin-android" @@ -22,6 +23,31 @@ def getAnkiCommitHash = { -> return commit } +def getFsrsVersion = { -> + def pkgStdout = new ByteArrayOutputStream() + exec { + commandLine "cargo", "metadata", "--format-version=1", "--manifest-path=" + new File("${project.rootDir}", "anki/Cargo.toml") + standardOutput = pkgStdout + } + + def verArgs = OperatingSystem.current() == OperatingSystem.WINDOWS ? + ".packages[] | select(.name==\\\"fsrs\\\") | .version" : + ".packages[] | select(.name==\"fsrs\") | .version" + def verStdout = new ByteArrayOutputStream() + def verStdin = new ByteArrayInputStream(pkgStdout.toByteArray()) + exec { + // use "jaq" cargo module installed during rust build: self-contained + cross-platform + // if we use `jq` we are dependent on local system utility installation status + commandLine "jaq", verArgs + standardInput = verStdin + standardOutput = verStdout + } + + def version = verStdout.toString().trim().replace("\"", "") + println("FSRS version: ${version}") + return version +} + def getAnkiDesktopVersion() { Properties properties = new Properties() properties.load(project.rootProject.file('gradle.properties').newDataInputStream()) @@ -61,6 +87,7 @@ android { buildConfigField "String", "ANKI_COMMIT_HASH", "\"${getAnkiCommitHash()}\"" buildConfigField "String", "ANKI_DESKTOP_VERSION", "\"${getAnkiDesktopVersion()}\"" + buildConfigField "String", "FSRS_VERSION", "\"${getFsrsVersion()}\"" buildConfigField "String", "BACKEND_GIT_COMMIT_HASH", "\"${getBackendGitCommitHash()}\"" buildConfigField "long", "BACKEND_BUILD_TIME", System.currentTimeMillis().toString() From 274c10652b42c53170a6baac48f521f47a6f6335 Mon Sep 17 00:00:00 2001 From: voczi Date: Mon, 14 Oct 2024 09:40:48 +0200 Subject: [PATCH 2/2] Make sure Cargo.lock is not touched --- rsdroid/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rsdroid/build.gradle b/rsdroid/build.gradle index 0687b027a..2022dc68d 100644 --- a/rsdroid/build.gradle +++ b/rsdroid/build.gradle @@ -26,7 +26,7 @@ def getAnkiCommitHash = { -> def getFsrsVersion = { -> def pkgStdout = new ByteArrayOutputStream() exec { - commandLine "cargo", "metadata", "--format-version=1", "--manifest-path=" + new File("${project.rootDir}", "anki/Cargo.toml") + commandLine "cargo", "metadata", "--locked", "--format-version=1", "--manifest-path=" + new File("${project.rootDir}", "anki/Cargo.toml") standardOutput = pkgStdout }