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 committed Oct 13, 2024
1 parent d68710b commit cdb1b77
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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
26 changes: 26 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,30 @@ 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"),
"--frozen"
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 +86,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 cdb1b77

Please sign in to comment.