mirror of
https://git.sr.ht/~eliasnaur/gio-cmd
synced 2026-07-08 10:55:33 +00:00
gogio: load Android assets from module root
This commit is contained in:
+18
-3
@@ -424,7 +424,8 @@ func exeAndroid(tmpDir string, tools *androidTools, bi *buildInfo, extraJars, pe
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := copyTree(filepath.Join(bi.pkgDir, "android", "res"), resDir); err != nil {
|
moduleRoot := moduleRootForDir(bi.pkgDir)
|
||||||
|
if err := copyTree(filepath.Join(moduleRoot, "android", "res"), resDir); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
resZip := filepath.Join(tmpDir, "resources.zip")
|
resZip := filepath.Join(tmpDir, "resources.zip")
|
||||||
@@ -452,8 +453,8 @@ func exeAndroid(tmpDir string, tools *androidTools, bi *buildInfo, extraJars, pe
|
|||||||
AppName: appName,
|
AppName: appName,
|
||||||
Schemes: bi.schemes,
|
Schemes: bi.schemes,
|
||||||
PackageQueries: bi.packageQueries,
|
PackageQueries: bi.packageQueries,
|
||||||
ManifestSnip: readOptionalText(filepath.Join(bi.pkgDir, "android", "manifest_snippets.xml")),
|
ManifestSnip: readOptionalText(filepath.Join(moduleRoot, "android", "manifest_snippets.xml")),
|
||||||
AppSnip: readOptionalText(filepath.Join(bi.pkgDir, "android", "application_snippets.xml")),
|
AppSnip: readOptionalText(filepath.Join(moduleRoot, "android", "application_snippets.xml")),
|
||||||
}
|
}
|
||||||
manifestBuffer, err := renderAndroidManifest(manifestSrc)
|
manifestBuffer, err := renderAndroidManifest(manifestSrc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -839,6 +840,20 @@ func androidExtraJars(dir string) ([]string, error) {
|
|||||||
return jars, nil
|
return jars, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func moduleRootForDir(dir string) string {
|
||||||
|
current := dir
|
||||||
|
for {
|
||||||
|
if _, err := os.Stat(filepath.Join(current, "go.mod")); err == nil {
|
||||||
|
return current
|
||||||
|
}
|
||||||
|
parent := filepath.Dir(current)
|
||||||
|
if parent == current {
|
||||||
|
return dir
|
||||||
|
}
|
||||||
|
current = parent
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func findNDK(androidHome string) (string, error) {
|
func findNDK(androidHome string) (string, error) {
|
||||||
ndks, err := filepath.Glob(filepath.Join(androidHome, "ndk", "*"))
|
ndks, err := filepath.Glob(filepath.Join(androidHome, "ndk", "*"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -83,6 +83,34 @@ func TestCopyTreeCopiesNestedResources(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestModuleRootForDirFindsOwningModule(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
root := t.TempDir()
|
||||||
|
writeTestFile(t, filepath.Join(root, "go.mod"), "module example.invalid/crew\n")
|
||||||
|
dir := filepath.Join(root, "cmd", "keepassgo")
|
||||||
|
if err := os.MkdirAll(dir, 0o755); err != nil {
|
||||||
|
t.Fatalf("MkdirAll(%q) error = %v", dir, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if got := moduleRootForDir(dir); got != root {
|
||||||
|
t.Fatalf("moduleRootForDir(%q) = %q, want %q", dir, got, root)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestModuleRootForDirFallsBackToInputDir(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
dir := filepath.Join(t.TempDir(), "cmd", "keepassgo")
|
||||||
|
if err := os.MkdirAll(dir, 0o755); err != nil {
|
||||||
|
t.Fatalf("MkdirAll(%q) error = %v", dir, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if got := moduleRootForDir(dir); got != dir {
|
||||||
|
t.Fatalf("moduleRootForDir(%q) = %q, want %q", dir, got, dir)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func writeTestFile(t *testing.T, path, contents string) {
|
func writeTestFile(t *testing.T, path, contents string) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
|
if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user