Auto-commit after successful build: update app gameplay/UI, improve build setup
Changed files:\nCrossCompileGitForAndroid.sh SetupBuildEnvironment.sh app/build.gradle.kts app/src/main/assets/native-git/arm64-v8a/git app/src/main/java/com/kawomi/githugandroid/GitRuntime.kt
This commit is contained in:
BIN
app/src/main/assets/native-git/arm64-v8a/git
Executable file
BIN
app/src/main/assets/native-git/arm64-v8a/git
Executable file
Binary file not shown.
@@ -1,21 +1,23 @@
|
||||
package com.kawomi.githugandroid
|
||||
|
||||
import android.os.Build
|
||||
import android.content.Context
|
||||
import java.io.File
|
||||
|
||||
class GitRepositoryRuntime(private val context: Context) {
|
||||
private val sandboxesRoot = File(context.filesDir, "githug-sandboxes")
|
||||
private val extractedGitDir = File(context.filesDir, "native-git/bin")
|
||||
|
||||
fun startupBanner(): String {
|
||||
return if (nativeGitBinary() != null) {
|
||||
return if (ensureNativeGitBinary() != null) {
|
||||
"Welcome to GitHug Android. Native Git prototype ready."
|
||||
} else {
|
||||
"Welcome to GitHug Android. Native Git prototype scaffolded; using in-memory fallback until a bundled Git binary is available."
|
||||
"Welcome to GitHug Android. Native Git binary not bundled for this ABI yet; using in-memory fallback."
|
||||
}
|
||||
}
|
||||
|
||||
fun prepareLevel(level: Level): RepoState {
|
||||
val nativeGit = nativeGitBinary()
|
||||
val nativeGit = ensureNativeGitBinary()
|
||||
if (nativeGit == null) {
|
||||
return level.setup()
|
||||
}
|
||||
@@ -50,7 +52,7 @@ class GitRepositoryRuntime(private val context: Context) {
|
||||
}
|
||||
|
||||
fun execute(level: Level, currentRepo: RepoState, command: String): Pair<RepoState, List<String>> {
|
||||
val nativeGit = nativeGitBinary()
|
||||
val nativeGit = ensureNativeGitBinary()
|
||||
if (nativeGit == null) {
|
||||
return GitSandboxEngine.execute(currentRepo, command)
|
||||
}
|
||||
@@ -76,7 +78,8 @@ class GitRepositoryRuntime(private val context: Context) {
|
||||
return buildList {
|
||||
addAll(GitSandboxEngine.commandReferenceLines())
|
||||
add("Native Git prototype:")
|
||||
add(" bundled binary path: files/native-git/bin/git")
|
||||
add(" extracted binary path: files/native-git/bin/git")
|
||||
add(" selected ABI: ${Build.SUPPORTED_ABIS.firstOrNull() ?: "unknown"}")
|
||||
add(" helper commands: ls, pwd, cat, touch, mkdir, rm, echo")
|
||||
}
|
||||
}
|
||||
@@ -129,7 +132,7 @@ class GitRepositoryRuntime(private val context: Context) {
|
||||
|
||||
private fun inspectSandbox(level: Level): RepoState {
|
||||
val sandbox = sandboxDir(level)
|
||||
val nativeGit = nativeGitBinary()
|
||||
val nativeGit = ensureNativeGitBinary()
|
||||
val filesOnDisk = sandbox.listFiles()
|
||||
?.filter { it.isFile && it.name != ".git" }
|
||||
.orEmpty()
|
||||
@@ -177,12 +180,27 @@ class GitRepositoryRuntime(private val context: Context) {
|
||||
)
|
||||
}
|
||||
|
||||
private fun nativeGitBinary(): File? {
|
||||
val candidates = listOf(
|
||||
File(context.filesDir, "native-git/bin/git"),
|
||||
File(context.filesDir, "git/bin/git"),
|
||||
)
|
||||
return candidates.firstOrNull { it.exists() && it.canExecute() }
|
||||
private fun ensureNativeGitBinary(): File? {
|
||||
val extracted = File(extractedGitDir, "git")
|
||||
if (extracted.exists() && extracted.canExecute()) {
|
||||
return extracted
|
||||
}
|
||||
|
||||
val abi = Build.SUPPORTED_ABIS.firstOrNull() ?: return null
|
||||
val assetPath = "native-git/$abi/git"
|
||||
|
||||
return try {
|
||||
extractedGitDir.mkdirs()
|
||||
context.assets.open(assetPath).use { input ->
|
||||
extracted.outputStream().use { output ->
|
||||
input.copyTo(output)
|
||||
}
|
||||
}
|
||||
extracted.setExecutable(true)
|
||||
extracted.takeIf { it.canExecute() }
|
||||
} catch (_: Exception) {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
private fun sandboxDir(level: Level): File = File(sandboxesRoot, level.id)
|
||||
|
||||
Reference in New Issue
Block a user