forked from joejulian/gio-cmd
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 {
|
||||
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
|
||||
}
|
||||
resZip := filepath.Join(tmpDir, "resources.zip")
|
||||
@@ -452,8 +453,8 @@ func exeAndroid(tmpDir string, tools *androidTools, bi *buildInfo, extraJars, pe
|
||||
AppName: appName,
|
||||
Schemes: bi.schemes,
|
||||
PackageQueries: bi.packageQueries,
|
||||
ManifestSnip: readOptionalText(filepath.Join(bi.pkgDir, "android", "manifest_snippets.xml")),
|
||||
AppSnip: readOptionalText(filepath.Join(bi.pkgDir, "android", "application_snippets.xml")),
|
||||
ManifestSnip: readOptionalText(filepath.Join(moduleRoot, "android", "manifest_snippets.xml")),
|
||||
AppSnip: readOptionalText(filepath.Join(moduleRoot, "android", "application_snippets.xml")),
|
||||
}
|
||||
manifestBuffer, err := renderAndroidManifest(manifestSrc)
|
||||
if err != nil {
|
||||
@@ -839,6 +840,20 @@ func androidExtraJars(dir string) ([]string, error) {
|
||||
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) {
|
||||
ndks, err := filepath.Glob(filepath.Join(androidHome, "ndk", "*"))
|
||||
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) {
|
||||
t.Helper()
|
||||
if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user