]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: when expanding "cmd", skip vendored main packages
authorIan Lance Taylor <iant@golang.org>
Fri, 10 Mar 2017 18:04:42 +0000 (10:04 -0800)
committerIan Lance Taylor <iant@golang.org>
Fri, 10 Mar 2017 22:05:37 +0000 (22:05 +0000)
We are vendoring pprof from github.com/google/pprof, which comes with
a main package. If we don't explicitly skip that main package, then
`go install cmd` will install the compiled program in $GOROOT/bin.

Fixes #19441.

Change-Id: Ib268ffd16d4be65f7d80e4f8d9dc6e71523a94de
Reviewed-on: https://go-review.googlesource.com/38007
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Raul Silvera <rsilvera@google.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
src/cmd/go/internal/load/search.go
src/make.bash

index 784a0716f287efd7728f5940e19382fca7c3c565..670fbbb7e4ab738ff07933c863391320cf53048e 100644 (file)
@@ -93,12 +93,21 @@ func MatchPackages(pattern string) []string {
                        if !match(name) {
                                return nil
                        }
-                       _, err = cfg.BuildContext.ImportDir(path, 0)
+                       pkg, err := cfg.BuildContext.ImportDir(path, 0)
                        if err != nil {
                                if _, noGo := err.(*build.NoGoError); noGo {
                                        return nil
                                }
                        }
+
+                       // If we are expanding "cmd", skip main
+                       // packages under cmd/vendor. At least as of
+                       // March, 2017, there is one there for the
+                       // vendored pprof tool.
+                       if pattern == "cmd" && strings.HasPrefix(pkg.ImportPath, "cmd/vendor") && pkg.Name == "main" {
+                               return nil
+                       }
+
                        pkgs = append(pkgs, name)
                        return nil
                })
index 62d8b80fca3493ed915c83764a9eb6724cc39189..6e6f96d5c7faf4607a1fac1641d3ce325f585985 100755 (executable)
@@ -172,7 +172,20 @@ if [ "$GOHOSTARCH" != "$GOARCH" -o "$GOHOSTOS" != "$GOOS" ]; then
 fi
 
 echo "##### Building packages and commands for $GOOS/$GOARCH."
+
+old_bin_files=$(cd $GOROOT/bin && echo *)
+
 CC=$CC_FOR_TARGET "$GOTOOLDIR"/go_bootstrap install $GO_FLAGS -gcflags "$GO_GCFLAGS" -ldflags "$GO_LDFLAGS" -v std cmd
+
+# Check that there are no new files in $GOROOT/bin other than go and gofmt
+# and $GOOS_$GOARCH (a directory used when cross-compiling).
+(cd $GOROOT/bin && for f in *; do
+       if ! expr " $old_bin_files go gofmt ${GOOS}_${GOARCH} " : ".* $f " >/dev/null 2>/dev/null; then
+               echo 1>&2 "ERROR: unexpected new file in $GOROOT/bin: $f"
+               exit 1
+       fi
+done)
+
 echo
 
 rm -f "$GOTOOLDIR"/go_bootstrap