Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add FSRS version to BuildConfig #427

Merged
merged 2 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build_rust/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ fn build_android_jni() -> Result<()> {
let (is_release, _release_dir) = check_release(false);

Command::run("cargo install [email protected]")?;
Command::run("cargo install [email protected]")?;
mikehardy marked this conversation as resolved.
Show resolved Hide resolved

let mut command = Command::new("cargo");
command
Expand Down
27 changes: 27 additions & 0 deletions rsdroid/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -22,6 +23,31 @@ def getAnkiCommitHash = { ->
return commit
}

def getFsrsVersion = { ->
def pkgStdout = new ByteArrayOutputStream()
exec {
commandLine "cargo", "metadata", "--locked", "--format-version=1", "--manifest-path=" + new File("${project.rootDir}", "anki/Cargo.toml")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

neat trick, wasn't aware of this one

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
david-allison marked this conversation as resolved.
Show resolved Hide resolved
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())
Expand Down Expand Up @@ -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()
Expand Down