mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-06 01:45:36 +00:00
cmd/gio: use the import path as basis for the output file
Before this change `go list <pkg>` was used to sanitize the import
path of the package argument. That doesn't work well for building
Go source files directly:
gio -target android helloworld.go
where `go list helloworld.go` simply returns "command-line-arguments".
A better way is to leave the package path alone, and compute the
output file separately from the import path, as reported by
`go list -f {{.ImportPath}} <pkg>`.
Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
@@ -158,7 +158,7 @@ func compileAndroid(tmpDir string, tools *androidTools, bi *buildInfo) (err erro
|
|||||||
func archiveAndroid(tmpDir string, bi *buildInfo) (err error) {
|
func archiveAndroid(tmpDir string, bi *buildInfo) (err error) {
|
||||||
aarFile := *destPath
|
aarFile := *destPath
|
||||||
if aarFile == "" {
|
if aarFile == "" {
|
||||||
aarFile = fmt.Sprintf("%s.aar", filepath.Base(bi.pkg))
|
aarFile = fmt.Sprintf("%s.aar", bi.name)
|
||||||
}
|
}
|
||||||
if filepath.Ext(aarFile) != ".aar" {
|
if filepath.Ext(aarFile) != ".aar" {
|
||||||
return fmt.Errorf("the specified output %q does not end in '.aar'", aarFile)
|
return fmt.Errorf("the specified output %q does not end in '.aar'", aarFile)
|
||||||
@@ -276,7 +276,7 @@ func exeAndroid(tmpDir string, tools *androidTools, bi *buildInfo) (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Link APK.
|
// Link APK.
|
||||||
appName := strings.Title(filepath.Base(bi.pkg))
|
appName := strings.Title(bi.name)
|
||||||
manifestSrc := fmt.Sprintf(`<?xml version="1.0" encoding="utf-8"?>
|
manifestSrc := fmt.Sprintf(`<?xml version="1.0" encoding="utf-8"?>
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
package="%s"
|
package="%s"
|
||||||
@@ -355,7 +355,7 @@ func exeAndroid(tmpDir string, tools *androidTools, bi *buildInfo) (err error) {
|
|||||||
func signAPK(tmpDir string, tools *androidTools, bi *buildInfo) error {
|
func signAPK(tmpDir string, tools *androidTools, bi *buildInfo) error {
|
||||||
apkFile := *destPath
|
apkFile := *destPath
|
||||||
if apkFile == "" {
|
if apkFile == "" {
|
||||||
apkFile = fmt.Sprintf("%s.apk", filepath.Base(bi.pkg))
|
apkFile = fmt.Sprintf("%s.apk", bi.name)
|
||||||
}
|
}
|
||||||
if filepath.Ext(apkFile) != ".apk" {
|
if filepath.Ext(apkFile) != ".apk" {
|
||||||
return fmt.Errorf("the specified output %q does not end in '.apk'", apkFile)
|
return fmt.Errorf("the specified output %q does not end in '.apk'", apkFile)
|
||||||
|
|||||||
+7
-3
@@ -10,6 +10,7 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -24,6 +25,7 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type buildInfo struct {
|
type buildInfo struct {
|
||||||
|
name string
|
||||||
pkg string
|
pkg string
|
||||||
ldflags string
|
ldflags string
|
||||||
archs []string
|
archs []string
|
||||||
@@ -56,13 +58,15 @@ func main() {
|
|||||||
default:
|
default:
|
||||||
errorf("invalid -buildmode %s\n", *buildMode)
|
errorf("invalid -buildmode %s\n", *buildMode)
|
||||||
}
|
}
|
||||||
// Expand relative package paths.
|
// Find package name.
|
||||||
pkg, err := runCmd(exec.Command("go", "list", pkg))
|
name, err := runCmd(exec.Command("go", "list", "-f", "{{.ImportPath}}", pkg))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errorf("gio: %v", err)
|
errorf("gio: %v", err)
|
||||||
}
|
}
|
||||||
|
name = filepath.Base(name)
|
||||||
bi := &buildInfo{
|
bi := &buildInfo{
|
||||||
pkg: pkg,
|
name: name,
|
||||||
|
pkg: pkg,
|
||||||
}
|
}
|
||||||
switch *target {
|
switch *target {
|
||||||
case "js":
|
case "js":
|
||||||
|
|||||||
+2
-2
@@ -19,7 +19,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func buildIOS(tmpDir, target string, bi *buildInfo) error {
|
func buildIOS(tmpDir, target string, bi *buildInfo) error {
|
||||||
appName := filepath.Base(bi.pkg)
|
appName := bi.name
|
||||||
switch *buildMode {
|
switch *buildMode {
|
||||||
case "archive":
|
case "archive":
|
||||||
framework := *destPath
|
framework := *destPath
|
||||||
@@ -174,7 +174,7 @@ int main(int argc, char * argv[]) {
|
|||||||
if _, err := runCmd(lipo); err != nil {
|
if _, err := runCmd(lipo); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
appName := strings.Title(filepath.Base(bi.pkg))
|
appName := strings.Title(bi.name)
|
||||||
infoPlistSrc := fmt.Sprintf(`<?xml version="1.0" encoding="UTF-8"?>
|
infoPlistSrc := fmt.Sprintf(`<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||||
<plist version="1.0">
|
<plist version="1.0">
|
||||||
|
|||||||
+1
-1
@@ -13,7 +13,7 @@ import (
|
|||||||
func buildJS(bi *buildInfo) error {
|
func buildJS(bi *buildInfo) error {
|
||||||
out := *destPath
|
out := *destPath
|
||||||
if out == "" {
|
if out == "" {
|
||||||
out = filepath.Base(bi.pkg)
|
out = bi.name
|
||||||
}
|
}
|
||||||
if err := os.MkdirAll(out, 0700); err != nil {
|
if err := os.MkdirAll(out, 0700); err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
Reference in New Issue
Block a user