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:
Elias Naur
2019-07-13 20:19:25 +02:00
parent 41990e3275
commit cde040369c
4 changed files with 13 additions and 9 deletions
+3 -3
View File
@@ -158,7 +158,7 @@ func compileAndroid(tmpDir string, tools *androidTools, bi *buildInfo) (err erro
func archiveAndroid(tmpDir string, bi *buildInfo) (err error) {
aarFile := *destPath
if aarFile == "" {
aarFile = fmt.Sprintf("%s.aar", filepath.Base(bi.pkg))
aarFile = fmt.Sprintf("%s.aar", bi.name)
}
if filepath.Ext(aarFile) != ".aar" {
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.
appName := strings.Title(filepath.Base(bi.pkg))
appName := strings.Title(bi.name)
manifestSrc := fmt.Sprintf(`<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
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 {
apkFile := *destPath
if apkFile == "" {
apkFile = fmt.Sprintf("%s.apk", filepath.Base(bi.pkg))
apkFile = fmt.Sprintf("%s.apk", bi.name)
}
if filepath.Ext(apkFile) != ".apk" {
return fmt.Errorf("the specified output %q does not end in '.apk'", apkFile)
+7 -3
View File
@@ -10,6 +10,7 @@ import (
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"strings"
)
@@ -24,6 +25,7 @@ var (
)
type buildInfo struct {
name string
pkg string
ldflags string
archs []string
@@ -56,13 +58,15 @@ func main() {
default:
errorf("invalid -buildmode %s\n", *buildMode)
}
// Expand relative package paths.
pkg, err := runCmd(exec.Command("go", "list", pkg))
// Find package name.
name, err := runCmd(exec.Command("go", "list", "-f", "{{.ImportPath}}", pkg))
if err != nil {
errorf("gio: %v", err)
}
name = filepath.Base(name)
bi := &buildInfo{
pkg: pkg,
name: name,
pkg: pkg,
}
switch *target {
case "js":
+2 -2
View File
@@ -19,7 +19,7 @@ import (
)
func buildIOS(tmpDir, target string, bi *buildInfo) error {
appName := filepath.Base(bi.pkg)
appName := bi.name
switch *buildMode {
case "archive":
framework := *destPath
@@ -174,7 +174,7 @@ int main(int argc, char * argv[]) {
if _, err := runCmd(lipo); err != nil {
return err
}
appName := strings.Title(filepath.Base(bi.pkg))
appName := strings.Title(bi.name)
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">
<plist version="1.0">
+1 -1
View File
@@ -13,7 +13,7 @@ import (
func buildJS(bi *buildInfo) error {
out := *destPath
if out == "" {
out = filepath.Base(bi.pkg)
out = bi.name
}
if err := os.MkdirAll(out, 0700); err != nil {
return err