]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: handle path to cmd directory
authorRuss Cox <rsc@golang.org>
Thu, 12 Jan 2012 23:27:57 +0000 (15:27 -0800)
committerRuss Cox <rsc@golang.org>
Thu, 12 Jan 2012 23:27:57 +0000 (15:27 -0800)
Now it works to run 'go install' (no args) in cmd/go.

Fixes #2679.

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/5543046

src/cmd/go/main.go
src/cmd/go/pkg.go

index 4b1ff357da4af8dbe9c77a97d0543223ba633eb5..8ef6395f4f71a3ab71866e4124e3fec1071ac819 100644 (file)
@@ -192,7 +192,7 @@ func importPaths(args []string) []string {
        }
        var out []string
        for _, a := range args {
-               if (strings.HasPrefix(a, "./") || strings.HasPrefix(a, "../")) && strings.Contains(a, "...") {
+               if isLocalPath(a) && strings.Contains(a, "...") {
                        out = append(out, allPackagesInFS(a)...)
                        continue
                }
@@ -246,6 +246,17 @@ func run(cmdargs ...interface{}) {
        }
 }
 
+func runOut(cmdargs ...interface{}) []byte {
+       cmdline := stringList(cmdargs...)
+       out, err := exec.Command(cmdline[0], cmdline[1:]...).CombinedOutput()
+       if err != nil {
+               os.Stderr.Write(out)
+               errorf("%v", err)
+               out = nil
+       }
+       return out
+}
+
 // matchPattern(pattern)(name) reports whether
 // name matches pattern.  Pattern is a limited glob
 // pattern in which '...' means 'any string' and there
@@ -422,3 +433,10 @@ func stringList(args ...interface{}) []string {
        }
        return x
 }
+
+// isLocalPath returns true if arg is an import path denoting
+// a local file system directory.  That is, it returns true if the
+// path begins with ./ or ../ .
+func isLocalPath(arg string) bool {
+       return arg == "." || arg == ".." || strings.HasPrefix(arg, "./") || strings.HasPrefix(arg, "../")
+}
index d2060b0a388736c3b0a47083316a424f726068af..9c41c7db0b9af48f6a9f2c5f7c25d58bc67a3527 100644 (file)
@@ -79,7 +79,7 @@ func loadPackage(arg string) (*Package, error) {
        t, importPath, err := build.FindTree(arg)
        dir := ""
        // Maybe it is a standard command.
-       if err != nil && !filepath.IsAbs(arg) && strings.HasPrefix(arg, "cmd/") {
+       if err != nil && strings.HasPrefix(arg, "cmd/") {
                goroot := build.Path[0]
                p := filepath.Join(goroot.Path, "src", arg)
                if st, err1 := os.Stat(p); err1 == nil && st.IsDir() {
@@ -89,6 +89,19 @@ func loadPackage(arg string) (*Package, error) {
                        err = nil
                }
        }
+       // Maybe it is a path to a standard command.
+       if err != nil && (filepath.IsAbs(arg) || isLocalPath(arg)) {
+               arg, _ := filepath.Abs(arg)
+               goroot := build.Path[0]
+               cmd := filepath.Join(goroot.Path, "src", "cmd") + string(filepath.Separator)
+               if st, err1 := os.Stat(arg); err1 == nil && st.IsDir() && strings.HasPrefix(arg, cmd) {
+                       t = goroot
+                       importPath = filepath.FromSlash(arg[len(cmd):])
+                       dir = arg
+                       err = nil
+               }
+       }
+
        if err != nil {
                return nil, err
        }