forked from joejulian/gio
cmd/gogio: restore package path handling
A previous change converted the package argument to gogio to an absolute path. However, gogio supports all package paths that may appear in Go import statements. For example, the path "gioui.org/cmd/example/kitchen" should not be converted. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
+6
-12
@@ -5,7 +5,6 @@ import (
|
||||
"fmt"
|
||||
"os/exec"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@@ -22,8 +21,8 @@ type buildInfo struct {
|
||||
version int
|
||||
}
|
||||
|
||||
func newBuildInfo(pkgAbsPath string) (*buildInfo, error) {
|
||||
pkgMetadata, err := getPkgMetadata(pkgAbsPath)
|
||||
func newBuildInfo(pkgPath string) (*buildInfo, error) {
|
||||
pkgMetadata, err := getPkgMetadata(pkgPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -35,7 +34,7 @@ func newBuildInfo(pkgAbsPath string) (*buildInfo, error) {
|
||||
minsdk: *minsdk,
|
||||
name: getPkgName(pkgMetadata),
|
||||
pkgDir: pkgMetadata.Dir,
|
||||
pkgPath: pkgAbsPath,
|
||||
pkgPath: pkgPath,
|
||||
tags: *extraTags,
|
||||
target: *target,
|
||||
version: *version,
|
||||
@@ -43,11 +42,6 @@ func newBuildInfo(pkgAbsPath string) (*buildInfo, error) {
|
||||
return bi, nil
|
||||
}
|
||||
|
||||
func getPkgAbsPath() string {
|
||||
absPath, _ := filepath.Abs(flag.Arg(0))
|
||||
return absPath
|
||||
}
|
||||
|
||||
func getArchs() []string {
|
||||
if *archNames != "" {
|
||||
return strings.Split(*archNames, ",")
|
||||
@@ -88,12 +82,12 @@ type packageMetadata struct {
|
||||
Dir string
|
||||
}
|
||||
|
||||
func getPkgMetadata(absPath string) (*packageMetadata, error) {
|
||||
pkgImportPath, err := runCmd(exec.Command("go", "list", "-f", "{{.ImportPath}}", absPath))
|
||||
func getPkgMetadata(pkgPath string) (*packageMetadata, error) {
|
||||
pkgImportPath, err := runCmd(exec.Command("go", "list", "-f", "{{.ImportPath}}", pkgPath))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pkgDir, err := runCmd(exec.Command("go", "list", "-f", "{{.Dir}}", absPath))
|
||||
pkgDir, err := runCmd(exec.Command("go", "list", "-f", "{{.Dir}}", pkgPath))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
+1
-4
@@ -46,7 +46,7 @@ func main() {
|
||||
fmt.Fprintf(os.Stderr, "gogio: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
buildInfo, err := newBuildInfo(getPkgAbsPath())
|
||||
buildInfo, err := newBuildInfo(flag.Arg(0))
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "gogio: %v\n", err)
|
||||
os.Exit(1)
|
||||
@@ -63,9 +63,6 @@ func flagValidate() error {
|
||||
if pkgPathArg == "" {
|
||||
return errors.New("specify a package")
|
||||
}
|
||||
if _, err := filepath.Abs(pkgPathArg); err != nil {
|
||||
return err
|
||||
}
|
||||
if *target == "" {
|
||||
return errors.New("please specify -target")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user