From c5cf6624076a644906aa7ec5c91c4e01ccd375d3 Mon Sep 17 00:00:00 2001 From: "Bryan C. Mills" Date: Fri, 1 Mar 2019 10:12:30 -0500 Subject: all: move internal/x to vendor/golang.org/x and revendor using 'go mod vendor' This also updates the vendored-in versions of several packages: 'go mod vendor' selects a consistent version of each module, but we had previously vendored an ad-hoc selection of packages. Notably, x/crypto/hkdf was previously vendored in at a much newer commit than the rest of x/crypto. Bringing the rest of x/crypto up to that commit introduced an import of golang.org/x/sys/cpu, which broke the js/wasm build, requiring an upgrade of x/sys to pick up CL 165749. Updates #30228 Updates #30241 Updates #25822 Change-Id: I5b3dbc232b7e6a048a158cbd8d36137af1efb711 Reviewed-on: https://go-review.googlesource.com/c/go/+/164623 Reviewed-by: Filippo Valsorda --- src/cmd/dist/build.go | 15 +++++++++++++++ src/cmd/dist/test.go | 3 ++- src/cmd/go/testdata/script/gopath_std_vendor.txt | 4 ++-- src/cmd/go/testdata/script/list_std.txt | 2 +- src/cmd/go/testdata/script/mod_list_std.txt | 12 ++++++------ src/cmd/go/testdata/script/mod_std_vendor.txt | 17 ++++++++++------- src/cmd/go/testdata/script/std_vendor.txt | 6 +++--- src/cmd/vet/all/whitelist/s390x.txt | 7 +++++++ 8 files changed, 46 insertions(+), 20 deletions(-) (limited to 'src/cmd') diff --git a/src/cmd/dist/build.go b/src/cmd/dist/build.go index 87739a510d..c31d36acae 100644 --- a/src/cmd/dist/build.go +++ b/src/cmd/dist/build.go @@ -192,6 +192,21 @@ func xinit() { gogcflags = os.Getenv("BOOT_GO_GCFLAGS") + // Add -mod=vendor to GOFLAGS so that commands won't try to resolve go.mod + // files for vendored external modules. + // TODO(golang.org/issue/30240): If the vendor directory contains the go.mod + // files, this probably won't be necessary. + // TODO(golang.org/issue/26849): Escape spaces in GOFLAGS if needed. + goflags := strings.Fields(os.Getenv("GOFLAGS")) + for i, flag := range goflags { + if strings.HasPrefix(flag, "-mod=") { + goflags = append(goflags[0:i], goflags[i+1:]...) + break + } + } + goflags = append(goflags, "-mod=vendor") + os.Setenv("GOFLAGS", strings.Join(goflags, " ")) + cc, cxx := "gcc", "g++" if defaultclang { cc, cxx = "clang", "clang++" diff --git a/src/cmd/dist/test.go b/src/cmd/dist/test.go index a58cee7518..1a54752f35 100644 --- a/src/cmd/dist/test.go +++ b/src/cmd/dist/test.go @@ -419,9 +419,10 @@ func (t *tester) registerTests() { if !t.race { cmd.Args = append(cmd.Args, "cmd") } + cmd.Stderr = new(bytes.Buffer) all, err := cmd.Output() if err != nil { - log.Fatalf("Error running go list std cmd: %v, %s", err, all) + log.Fatalf("Error running go list std cmd: %v:\n%s", err, cmd.Stderr) } pkgs := strings.Fields(string(all)) for _, pkg := range pkgs { diff --git a/src/cmd/go/testdata/script/gopath_std_vendor.txt b/src/cmd/go/testdata/script/gopath_std_vendor.txt index 8bb1dc4430..a0a41a50de 100644 --- a/src/cmd/go/testdata/script/gopath_std_vendor.txt +++ b/src/cmd/go/testdata/script/gopath_std_vendor.txt @@ -9,8 +9,8 @@ stdout $GOPATH[/\\]src[/\\]vendor # to the package 'vendor/golang.org/x/net/http2/hpack' within GOROOT. cd importnethttp go list -deps -f '{{.ImportPath}} {{.Dir}}' -stdout ^internal/x/net/http2/hpack -stdout $GOROOT[/\\]src[/\\]internal[/\\]x[/\\]net[/\\]http2[/\\]hpack +stdout ^vendor/golang.org/x/net/http2/hpack +stdout $GOROOT[/\\]src[/\\]vendor[/\\]golang.org[/\\]x[/\\]net[/\\]http2[/\\]hpack ! stdout $GOPATH[/\\]src[/\\]vendor # In the presence of $GOPATH/src/vendor/golang.org/x/net/http2/hpack, diff --git a/src/cmd/go/testdata/script/list_std.txt b/src/cmd/go/testdata/script/list_std.txt index 5960d442e5..deddaa61ea 100644 --- a/src/cmd/go/testdata/script/list_std.txt +++ b/src/cmd/go/testdata/script/list_std.txt @@ -16,7 +16,7 @@ stdout cmd/compile # In GOPATH mode, packages vendored into GOROOT should be reported as standard. go list -f '{{if .Standard}}{{.ImportPath}}{{end}}' std cmd -stdout internal/x/net/http2/hpack +stdout golang.org/x/net/http2/hpack stdout cmd/vendor/golang\.org/x/arch/x86/x86asm # However, vendored packages should not match wildcard patterns beginning with cmd. diff --git a/src/cmd/go/testdata/script/mod_list_std.txt b/src/cmd/go/testdata/script/mod_list_std.txt index 15642cd0b7..f5136a5de0 100644 --- a/src/cmd/go/testdata/script/mod_list_std.txt +++ b/src/cmd/go/testdata/script/mod_list_std.txt @@ -5,7 +5,7 @@ env GOPROXY=off # Outside of GOROOT, our vendored packages should be reported as part of the standard library. go list -f '{{if .Standard}}{{.ImportPath}}{{end}}' std cmd -stdout ^internal/x/net/http2/hpack +stdout ^vendor/golang.org/x/net/http2/hpack stdout ^cmd/vendor/golang\.org/x/arch/x86/x86asm # cmd/... should match the same packages it used to match in GOPATH mode. @@ -20,15 +20,15 @@ stdout ^cmd/compile # Today, they are listed in 'std' but not './...'. cd $GOROOT/src go list ./... -stdout ^internal/x +! stdout ^vendor/golang.org/x # TODO: should be included, or should be omitted from 'std'. cp stdout $WORK/listdot.txt go list std -stdout ^internal/x +stdout ^vendor/golang.org/x # TODO: remove vendor/ prefix # TODO: cmp stdout $WORK/listdot.txt go list all -stdout ^internal/x +stdout ^vendor/golang.org/x # TODO: remove vendor/ prefix. ! stdout ^std/ @@ -37,11 +37,11 @@ stdout ^internal/x # TODO(golang.org/issue/30241): Make that work. # Today, they still have the vendor/ prefix. go list std -stdout ^internal/x/net/http2/hpack # TODO +stdout ^vendor/golang.org/x/net/http2/hpack # TODO ! stdout ^golang.org/x/net/http2/hpack # TODO go list -deps -f '{{if not .Standard}}{{.ImportPath}}{{end}}' std -# ! stdout ^internal/x/net/http2/hpack # TODO +# ! stdout ^vendor/golang.org/x/net/http2/hpack # TODO ! stdout ^golang.org/x/net/http2/hpack # TODO diff --git a/src/cmd/go/testdata/script/mod_std_vendor.txt b/src/cmd/go/testdata/script/mod_std_vendor.txt index 17818c4536..5aa544cb77 100644 --- a/src/cmd/go/testdata/script/mod_std_vendor.txt +++ b/src/cmd/go/testdata/script/mod_std_vendor.txt @@ -1,17 +1,20 @@ env GO111MODULE=on env GOPROXY=off +[!gc] skip + +# 'go list' should report imports from _test.go in the TestImports field. go list -f '{{.TestImports}}' stdout net/http # from .TestImports # 'go list' should find standard-vendored packages. -go list -f '{{.Dir}}' internal/x/net/http2/hpack -stdout $GOROOT[/\\]src[/\\]internal +go list -f '{{.Dir}}' vendor/golang.org/x/net/http2/hpack +stdout $GOROOT[/\\]src[/\\]vendor # 'go list -test' should report vendored transitive dependencies of _test.go # imports in the Deps field. go list -test -f '{{range .Deps}}{{.}}{{"\n"}}{{end}}' -stdout internal/x/crypto # dep of .TestImports +stdout ^vendor/golang.org/x/crypto # dep of .TestImports # Modules outside the standard library should not use the packages vendored there... @@ -29,7 +32,7 @@ stderr 'use of vendored package' cd ../importstd ! go build . -stderr 'use of internal package' +stderr 'use of vendored package' # When run within the 'std' module, 'go list -test' should report vendored @@ -38,8 +41,8 @@ stderr 'use of internal package' # Today, they're standard packages as long as they exist. cd $GOROOT/src go list -test -f '{{range .Deps}}{{.}}{{"\n"}}{{end}}' net/http -! stdout ^vendor/golang.org/x/net/http2/hpack # TODO: this will exist later -stdout ^internal/x/net/http2/hpack +stdout ^vendor/golang.org/x/net/http2/hpack # TODO: remove vendor/ prefix +! stdout ^golang.org/x/net/http2/hpack -- go.mod -- module m @@ -74,4 +77,4 @@ module importvendor -- importstd/x.go -- package importstd -import _ "internal/x/net/http2/hpack" +import _ "vendor/golang.org/x/net/http2/hpack" diff --git a/src/cmd/go/testdata/script/std_vendor.txt b/src/cmd/go/testdata/script/std_vendor.txt index e769dff481..6cb015fc07 100644 --- a/src/cmd/go/testdata/script/std_vendor.txt +++ b/src/cmd/go/testdata/script/std_vendor.txt @@ -7,13 +7,13 @@ go list -f '{{.TestImports}}' stdout net/http # from .TestImports # 'go list' should report standard-vendored packages by path. -go list -f '{{.Dir}}' internal/x/net/http2/hpack -stdout $GOROOT[/\\]src[/\\]internal +go list -f '{{.Dir}}' vendor/golang.org/x/net/http2/hpack +stdout $GOROOT[/\\]src[/\\]vendor # 'go list -test' should report vendored transitive dependencies of _test.go # imports in the Deps field, with a 'vendor' prefix on their import paths. go list -test -f '{{.Deps}}' -stdout internal/x/crypto # dep of .TestImports +stdout golang.org/x/crypto # dep of .TestImports # Packages outside the standard library should not use its copy of vendored packages. cd broken diff --git a/src/cmd/vet/all/whitelist/s390x.txt b/src/cmd/vet/all/whitelist/s390x.txt index 55cf44a519..c8fd385c4a 100644 --- a/src/cmd/vet/all/whitelist/s390x.txt +++ b/src/cmd/vet/all/whitelist/s390x.txt @@ -10,3 +10,10 @@ internal/cpu/cpu_s390x.s: [s390x] kmctrQuery: invalid MOVD of ret+0(FP); interna internal/cpu/cpu_s390x.s: [s390x] kmaQuery: invalid MOVD of ret+0(FP); internal/cpu.queryResult is 16-byte value internal/cpu/cpu_s390x.s: [s390x] kimdQuery: invalid MOVD of ret+0(FP); internal/cpu.queryResult is 16-byte value internal/cpu/cpu_s390x.s: [s390x] klmdQuery: invalid MOVD of ret+0(FP); internal/cpu.queryResult is 16-byte value +vendor/golang.org/x/sys/cpu/cpu_s390x.s: [s390x] stfle: invalid MOVD of ret+0(FP); vendor/golang.org/x/sys/cpu.facilityList is 32-byte value +vendor/golang.org/x/sys/cpu/cpu_s390x.s: [s390x] kmQuery: invalid MOVD of ret+0(FP); vendor/golang.org/x/sys/cpu.queryResult is 16-byte value +vendor/golang.org/x/sys/cpu/cpu_s390x.s: [s390x] kmcQuery: invalid MOVD of ret+0(FP); vendor/golang.org/x/sys/cpu.queryResult is 16-byte value +vendor/golang.org/x/sys/cpu/cpu_s390x.s: [s390x] kmctrQuery: invalid MOVD of ret+0(FP); vendor/golang.org/x/sys/cpu.queryResult is 16-byte value +vendor/golang.org/x/sys/cpu/cpu_s390x.s: [s390x] kmaQuery: invalid MOVD of ret+0(FP); vendor/golang.org/x/sys/cpu.queryResult is 16-byte value +vendor/golang.org/x/sys/cpu/cpu_s390x.s: [s390x] kimdQuery: invalid MOVD of ret+0(FP); vendor/golang.org/x/sys/cpu.queryResult is 16-byte value +vendor/golang.org/x/sys/cpu/cpu_s390x.s: [s390x] klmdQuery: invalid MOVD of ret+0(FP); vendor/golang.org/x/sys/cpu.queryResult is 16-byte value -- cgit v1.3