Skip to content

Commit

Permalink
Add FSRS version to BuildConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
voczi authored and mikehardy committed Oct 13, 2024
1 parent d68710b commit c749624
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
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]")?;

let mut command = Command::new("cargo");
command
Expand Down
25 changes: 25 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,29 @@ 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 {
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())
Expand Down Expand Up @@ -61,6 +85,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

0 comments on commit c749624

Please sign in to comment.