Skip to content

Commit 2012227

Browse files
author
Bryan C. Mills
committed
vendor/golang_org/x: move to internal/x
Packages in vendor/ directories have a "vendor/" path prefix in GOPATH mode, but intentionally do not in module mode. Since the import path is embedded in the compiled output, changing that path invalidates cache entries and causes cmd/go to try to rebuild (and reinstall) the vendored libraries, which will fail if the directory containing those libraries is read-only. If I understood correctly, this is the approach Russ suggested as an alternative to https://golang.org/cl/136138. Fixes #27285 Fixes #26988 Change-Id: I8a2507fa892b84cde0a803aaa79e460723da572b Reviewed-on: https://go-review.googlesource.com/c/147443 Run-TryBot: Bryan C. Mills <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Russ Cox <[email protected]>
1 parent 70a684c commit 2012227

File tree

196 files changed

+148
-152
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

196 files changed

+148
-152
lines changed

Diff for: src/cmd/api/goapi.go

+1-6
Original file line numberDiff line numberDiff line change
@@ -442,13 +442,8 @@ func (w *Walker) Import(name string) (*types.Package, error) {
442442
}
443443
w.imported[name] = &importing
444444

445-
root := w.root
446-
if strings.HasPrefix(name, "golang_org/x/") {
447-
root = filepath.Join(root, "vendor")
448-
}
449-
450445
// Determine package files.
451-
dir := filepath.Join(root, filepath.FromSlash(name))
446+
dir := filepath.Join(w.root, filepath.FromSlash(name))
452447
if fi, err := os.Stat(dir); err != nil || !fi.IsDir() {
453448
log.Fatalf("no source in tree for import %q: %v", name, err)
454449
}

Diff for: src/cmd/go/go_test.go

-16
Original file line numberDiff line numberDiff line change
@@ -1207,22 +1207,6 @@ func TestImportCycle(t *testing.T) {
12071207
tg.run("list", "-e", "-json", "selfimport")
12081208
}
12091209

1210-
func TestListImportMap(t *testing.T) {
1211-
skipIfGccgo(t, "gccgo does not have standard packages")
1212-
tg := testgo(t)
1213-
defer tg.cleanup()
1214-
tg.parallel()
1215-
tg.run("list", "-f", "{{.ImportPath}}: {{.ImportMap}}", "net", "fmt")
1216-
tg.grepStdout(`^net: map\[(.* )?golang_org/x/net/dns/dnsmessage:vendor/golang_org/x/net/dns/dnsmessage.*\]`, "net/http should have rewritten dnsmessage import")
1217-
tg.grepStdout(`^fmt: map\[\]`, "fmt should have no rewritten imports")
1218-
tg.run("list", "-deps", "-test", "-f", "{{.ImportPath}} MAP: {{.ImportMap}}\n{{.ImportPath}} IMPORT: {{.Imports}}", "fmt")
1219-
tg.grepStdout(`^flag \[fmt\.test\] MAP: map\[fmt:fmt \[fmt\.test\]\]`, "flag [fmt.test] should import fmt [fmt.test] as fmt")
1220-
tg.grepStdout(`^fmt\.test MAP: map\[(.* )?testing:testing \[fmt\.test\]`, "fmt.test should import testing [fmt.test] as testing")
1221-
tg.grepStdout(`^fmt\.test MAP: map\[(.* )?testing:testing \[fmt\.test\]`, "fmt.test should import testing [fmt.test] as testing")
1222-
tg.grepStdoutNot(`^fmt\.test MAP: map\[(.* )?os:`, "fmt.test should not import a modified os")
1223-
tg.grepStdout(`^fmt\.test IMPORT: \[fmt \[fmt\.test\] fmt_test \[fmt\.test\] os testing \[fmt\.test\] testing/internal/testdeps \[fmt\.test\]\]`, "wrong imports for fmt.test")
1224-
}
1225-
12261210
// cmd/go: custom import path checking should not apply to Go packages without import comment.
12271211
func TestIssue10952(t *testing.T) {
12281212
testenv.MustHaveExternalNetwork(t)

Diff for: src/cmd/go/internal/load/pkg.go

-14
Original file line numberDiff line numberDiff line change
@@ -1051,20 +1051,6 @@ func disallowVendor(srcDir string, importer *Package, importerPath, path string,
10511051
return p
10521052
}
10531053

1054-
// Modules must not import vendor packages in the standard library,
1055-
// but the usual vendor visibility check will not catch them
1056-
// because the module loader presents them with an ImportPath starting
1057-
// with "golang_org/" instead of "vendor/".
1058-
if p.Standard && !importer.Standard && strings.HasPrefix(p.ImportPath, "golang_org") {
1059-
perr := *p
1060-
perr.Error = &PackageError{
1061-
ImportStack: stk.Copy(),
1062-
Err: "use of vendored package " + path + " not allowed",
1063-
}
1064-
perr.Incomplete = true
1065-
return &perr
1066-
}
1067-
10681054
if perr := disallowVendorVisibility(srcDir, p, stk); perr != p {
10691055
return perr
10701056
}

Diff for: src/cmd/go/internal/modload/import.go

-3
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,6 @@ func Import(path string) (m module.Version, dir string, err error) {
5858

5959
// Is the package in the standard library?
6060
if search.IsStandardImportPath(path) {
61-
if strings.HasPrefix(path, "golang_org/") {
62-
return module.Version{}, filepath.Join(cfg.GOROOT, "src/vendor", path), nil
63-
}
6461
if goroot.IsStandardPackage(cfg.GOROOT, cfg.BuildContext.Compiler, path) {
6562
dir := filepath.Join(cfg.GOROOT, "src", path)
6663
return module.Version{}, dir, nil

Diff for: src/cmd/go/testdata/script/list_importmap.txt

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# gccgo does not have standard packages.
2+
[gccgo] skip
3+
4+
# fmt should have no rewritten imports.
5+
# The import from a/b should map c/d to a's vendor directory.
6+
go list -f '{{.ImportPath}}: {{.ImportMap}}' fmt a/b
7+
stdout 'fmt: map\[\]'
8+
stdout 'a/b: map\[c/d:a/vendor/c/d\]'
9+
10+
# flag [fmt.test] should import fmt [fmt.test] as fmt
11+
# fmt.test should import testing [fmt.test] as testing
12+
# fmt.test should not import a modified os
13+
go list -deps -test -f '{{.ImportPath}} MAP: {{.ImportMap}}{{"\n"}}{{.ImportPath}} IMPORT: {{.Imports}}' fmt
14+
stdout '^flag \[fmt\.test\] MAP: map\[fmt:fmt \[fmt\.test\]\]'
15+
stdout '^fmt\.test MAP: map\[(.* )?testing:testing \[fmt\.test\]'
16+
! stdout '^fmt\.test MAP: map\[(.* )?os:'
17+
stdout '^fmt\.test IMPORT: \[fmt \[fmt\.test\] fmt_test \[fmt\.test\] os testing \[fmt\.test\] testing/internal/testdeps \[fmt\.test\]\]'
18+
19+
20+
-- a/b/b.go --
21+
package b
22+
23+
import _ "c/d"
24+
-- a/vendor/c/d/d.go --
25+
package d

Diff for: src/cmd/go/testdata/script/list_std.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ go list -f '{{if not .Standard}}{{.ImportPath}}{{end}}' ./...
88

99
# our vendored packages should be reported as standard
1010
go list std cmd
11-
stdout golang_org/x/net/http2/hpack
11+
stdout internal/x/net/http2/hpack
1212
stdout cmd/vendor/golang\.org/x/arch/x86/x86asm

Diff for: src/cmd/go/testdata/script/mod_internal.txt

-13
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,6 @@ stderr 'use of internal package golang.org/x/.* not allowed'
1818
! go build ./fromstd
1919
stderr 'use of internal package internal/testenv not allowed'
2020

21-
# Packages found via standard-library vendoring should not leak.
22-
! go build ./fromstdvendor
23-
stderr 'use of vendored package golang_org/x/net/http/httpguts not allowed'
24-
25-
env GO111MODULE=off
26-
! go build ./fromstdvendor
27-
stderr 'cannot find package "golang_org/x/net/http/httpguts" in any of:'
28-
env GO111MODULE=on
29-
3021
# Dependencies should be able to use their own internal modules...
3122
rm go.mod
3223
go mod init golang.org/notx
@@ -83,10 +74,6 @@ import _ "golang.org/notx/useinternal"
8374
package fromstd
8475
import _ "internal/testenv"
8576

86-
-- fromstdvendor/useinternal.go --
87-
package fromstdvendor
88-
import _ "golang_org/x/net/http/httpguts"
89-
9077
-- replace/golang.org/notx/internal/go.mod --
9178
module golang.org/x/internal
9279

Diff for: src/cmd/go/testdata/script/mod_std_vendor.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go list -f '{{.TestImports}}'
44
stdout net/http # from .TestImports
55

66
go list -test -f '{{.Deps}}'
7-
stdout golang_org/x/crypto # dep of .TestImports
7+
stdout internal/x/crypto # dep of .TestImports
88

99
-- go.mod --
1010
module m

Diff for: src/crypto/tls/cipher_suites.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ import (
1414
"crypto/sha1"
1515
"crypto/sha256"
1616
"crypto/x509"
17-
"golang_org/x/crypto/chacha20poly1305"
1817
"hash"
18+
"internal/x/crypto/chacha20poly1305"
1919
)
2020

2121
// a keyAgreement implements the client and server side of a TLS key agreement

Diff for: src/crypto/tls/handshake_messages.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ package tls
66

77
import (
88
"fmt"
9-
"golang_org/x/crypto/cryptobyte"
9+
"internal/x/crypto/cryptobyte"
1010
"strings"
1111
)
1212

Diff for: src/crypto/tls/key_schedule.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ import (
88
"crypto/elliptic"
99
"crypto/hmac"
1010
"errors"
11-
"golang_org/x/crypto/cryptobyte"
12-
"golang_org/x/crypto/curve25519"
13-
"golang_org/x/crypto/hkdf"
1411
"hash"
12+
"internal/x/crypto/cryptobyte"
13+
"internal/x/crypto/curve25519"
14+
"internal/x/crypto/hkdf"
1515
"io"
1616
"math/big"
1717
)

Diff for: src/crypto/tls/ticket.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
"crypto/sha256"
1313
"crypto/subtle"
1414
"errors"
15-
"golang_org/x/crypto/cryptobyte"
15+
"internal/x/crypto/cryptobyte"
1616
"io"
1717
)
1818

Diff for: src/crypto/x509/x509.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ import (
2424
"encoding/pem"
2525
"errors"
2626
"fmt"
27-
"golang_org/x/crypto/cryptobyte"
28-
cryptobyte_asn1 "golang_org/x/crypto/cryptobyte/asn1"
27+
"internal/x/crypto/cryptobyte"
28+
cryptobyte_asn1 "internal/x/crypto/cryptobyte/asn1"
2929
"io"
3030
"math/big"
3131
"net"

Diff for: src/go/build/build_test.go

+21-9
Original file line numberDiff line numberDiff line change
@@ -351,12 +351,16 @@ func TestImportDirNotExist(t *testing.T) {
351351
func TestImportVendor(t *testing.T) {
352352
testenv.MustHaveGoBuild(t) // really must just have source
353353
ctxt := Default
354-
ctxt.GOPATH = ""
355-
p, err := ctxt.Import("golang_org/x/net/http2/hpack", filepath.Join(ctxt.GOROOT, "src/net/http"), 0)
354+
wd, err := os.Getwd()
355+
if err != nil {
356+
t.Fatal(err)
357+
}
358+
ctxt.GOPATH = filepath.Join(wd, "testdata/withvendor")
359+
p, err := ctxt.Import("c/d", filepath.Join(ctxt.GOPATH, "src/a/b"), 0)
356360
if err != nil {
357-
t.Fatalf("cannot find vendored golang_org/x/net/http2/hpack from net/http directory: %v", err)
361+
t.Fatalf("cannot find vendored c/d from testdata src/a/b directory: %v", err)
358362
}
359-
want := "vendor/golang_org/x/net/http2/hpack"
363+
want := "a/vendor/c/d"
360364
if p.ImportPath != want {
361365
t.Fatalf("Import succeeded but found %q, want %q", p.ImportPath, want)
362366
}
@@ -365,8 +369,12 @@ func TestImportVendor(t *testing.T) {
365369
func TestImportVendorFailure(t *testing.T) {
366370
testenv.MustHaveGoBuild(t) // really must just have source
367371
ctxt := Default
368-
ctxt.GOPATH = ""
369-
p, err := ctxt.Import("x.com/y/z", filepath.Join(ctxt.GOROOT, "src/net/http"), 0)
372+
wd, err := os.Getwd()
373+
if err != nil {
374+
t.Fatal(err)
375+
}
376+
ctxt.GOPATH = filepath.Join(wd, "testdata/withvendor")
377+
p, err := ctxt.Import("x.com/y/z", filepath.Join(ctxt.GOPATH, "src/a/b"), 0)
370378
if err == nil {
371379
t.Fatalf("found made-up package x.com/y/z in %s", p.Dir)
372380
}
@@ -380,9 +388,13 @@ func TestImportVendorFailure(t *testing.T) {
380388
func TestImportVendorParentFailure(t *testing.T) {
381389
testenv.MustHaveGoBuild(t) // really must just have source
382390
ctxt := Default
383-
ctxt.GOPATH = ""
384-
// This import should fail because the vendor/golang.org/x/net/http2 directory has no source code.
385-
p, err := ctxt.Import("golang_org/x/net/http2", filepath.Join(ctxt.GOROOT, "src/net/http"), 0)
391+
wd, err := os.Getwd()
392+
if err != nil {
393+
t.Fatal(err)
394+
}
395+
ctxt.GOPATH = filepath.Join(wd, "testdata/withvendor")
396+
// This import should fail because the vendor/c directory has no source code.
397+
p, err := ctxt.Import("c", filepath.Join(ctxt.GOPATH, "src/a/b"), 0)
386398
if err == nil {
387399
t.Fatalf("found empty parent in %s", p.Dir)
388400
}

Diff for: src/go/build/deps_test.go

+15-15
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ var pkgDeps = map[string][]string{
320320
"context", "math/rand", "os", "reflect", "sort", "syscall", "time",
321321
"internal/nettrace", "internal/poll", "internal/syscall/unix",
322322
"internal/syscall/windows", "internal/singleflight", "internal/race",
323-
"golang_org/x/net/dns/dnsmessage", "golang_org/x/net/lif", "golang_org/x/net/route",
323+
"internal/x/net/dns/dnsmessage", "internal/x/net/lif", "internal/x/net/route",
324324
},
325325

326326
// NET enables use of basic network-related packages.
@@ -357,9 +357,9 @@ var pkgDeps = map[string][]string{
357357
"crypto/sha1",
358358
"crypto/sha256",
359359
"crypto/sha512",
360-
"golang_org/x/crypto/chacha20poly1305",
361-
"golang_org/x/crypto/curve25519",
362-
"golang_org/x/crypto/poly1305",
360+
"internal/x/crypto/chacha20poly1305",
361+
"internal/x/crypto/curve25519",
362+
"internal/x/crypto/poly1305",
363363
},
364364

365365
// Random byte, number generation.
@@ -387,13 +387,13 @@ var pkgDeps = map[string][]string{
387387

388388
// SSL/TLS.
389389
"crypto/tls": {
390-
"L4", "CRYPTO-MATH", "OS", "golang_org/x/crypto/cryptobyte", "golang_org/x/crypto/hkdf",
390+
"L4", "CRYPTO-MATH", "OS", "internal/x/crypto/cryptobyte", "internal/x/crypto/hkdf",
391391
"container/list", "crypto/x509", "encoding/pem", "net", "syscall",
392392
},
393393
"crypto/x509": {
394394
"L4", "CRYPTO-MATH", "OS", "CGO",
395395
"crypto/x509/pkix", "encoding/pem", "encoding/hex", "net", "os/user", "syscall", "net/url",
396-
"golang_org/x/crypto/cryptobyte", "golang_org/x/crypto/cryptobyte/asn1",
396+
"internal/x/crypto/cryptobyte", "internal/x/crypto/cryptobyte/asn1",
397397
},
398398
"crypto/x509/pkix": {"L4", "CRYPTO-MATH", "encoding/hex"},
399399

@@ -409,12 +409,12 @@ var pkgDeps = map[string][]string{
409409
"context",
410410
"crypto/rand",
411411
"crypto/tls",
412-
"golang_org/x/net/http/httpguts",
413-
"golang_org/x/net/http/httpproxy",
414-
"golang_org/x/net/http2/hpack",
415-
"golang_org/x/net/idna",
416-
"golang_org/x/text/unicode/norm",
417-
"golang_org/x/text/width",
412+
"internal/x/net/http/httpguts",
413+
"internal/x/net/http/httpproxy",
414+
"internal/x/net/http2/hpack",
415+
"internal/x/net/idna",
416+
"internal/x/text/unicode/norm",
417+
"internal/x/text/width",
418418
"internal/nettrace",
419419
"mime/multipart",
420420
"net/http/httptrace",
@@ -432,9 +432,9 @@ var pkgDeps = map[string][]string{
432432
"net/http/fcgi": {"L4", "NET", "OS", "context", "net/http", "net/http/cgi"},
433433
"net/http/httptest": {
434434
"L4", "NET", "OS", "crypto/tls", "flag", "net/http", "net/http/internal", "crypto/x509",
435-
"golang_org/x/net/http/httpguts",
435+
"internal/x/net/http/httpguts",
436436
},
437-
"net/http/httputil": {"L4", "NET", "OS", "context", "net/http", "net/http/internal", "golang_org/x/net/http/httpguts"},
437+
"net/http/httputil": {"L4", "NET", "OS", "context", "net/http", "net/http/internal", "internal/x/net/http/httpguts"},
438438
"net/http/pprof": {"L4", "OS", "html/template", "net/http", "runtime/pprof", "runtime/trace"},
439439
"net/rpc": {"L4", "NET", "encoding/gob", "html/template", "net/http"},
440440
"net/rpc/jsonrpc": {"L4", "NET", "encoding/json", "net/rpc"},
@@ -485,7 +485,7 @@ func listStdPkgs(goroot string) ([]string, error) {
485485
}
486486

487487
name := filepath.ToSlash(path[len(src):])
488-
if name == "builtin" || name == "cmd" || strings.Contains(name, "golang_org") {
488+
if name == "builtin" || name == "cmd" || strings.Contains(name, "internal/x/") {
489489
return filepath.SkipDir
490490
}
491491

Diff for: src/go/build/testdata/withvendor/src/a/b/b.go

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package b
2+
3+
import _ "c/d"
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package d

Diff for: src/go/internal/srcimporter/srcimporter_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ var importedObjectTests = []struct {
9999
{"math.Pi", "const Pi untyped float"},
100100
{"math.Sin", "func Sin(x float64) float64"},
101101
{"math/big.Int", "type Int struct{neg bool; abs nat}"},
102-
{"golang_org/x/text/unicode/norm.MaxSegmentSize", "const MaxSegmentSize untyped int"},
102+
{"internal/x/text/unicode/norm.MaxSegmentSize", "const MaxSegmentSize untyped int"},
103103
}
104104

105105
func TestImportedTypes(t *testing.T) {

Diff for: src/vendor/golang_org/x/crypto/chacha20poly1305/chacha20poly1305.go renamed to src/internal/x/crypto/chacha20poly1305/chacha20poly1305.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// license that can be found in the LICENSE file.
44

55
// Package chacha20poly1305 implements the ChaCha20-Poly1305 AEAD as specified in RFC 7539.
6-
package chacha20poly1305 // import "golang.org/x/crypto/chacha20poly1305"
6+
package chacha20poly1305
77

88
import (
99
"crypto/cipher"

Diff for: src/vendor/golang_org/x/crypto/chacha20poly1305/chacha20poly1305_generic.go renamed to src/internal/x/crypto/chacha20poly1305/chacha20poly1305_generic.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ package chacha20poly1305
77
import (
88
"encoding/binary"
99

10-
"golang_org/x/crypto/internal/chacha20"
11-
"golang_org/x/crypto/poly1305"
10+
"internal/x/crypto/internal/chacha20"
11+
"internal/x/crypto/poly1305"
1212
)
1313

1414
func roundTo16(n int) int {

Diff for: src/vendor/golang_org/x/crypto/cryptobyte/asn1.go renamed to src/internal/x/crypto/cryptobyte/asn1.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"reflect"
1212
"time"
1313

14-
"golang_org/x/crypto/cryptobyte/asn1"
14+
"internal/x/crypto/cryptobyte/asn1"
1515
)
1616

1717
// This file contains ASN.1-related methods for String and Builder.

Diff for: src/vendor/golang_org/x/crypto/cryptobyte/asn1/asn1.go renamed to src/internal/x/crypto/cryptobyte/asn1/asn1.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
// Package asn1 contains supporting types for parsing and building ASN.1
66
// messages with the cryptobyte package.
7-
package asn1 // import "golang.org/x/crypto/cryptobyte/asn1"
7+
package asn1
88

99
// Tag represents an ASN.1 identifier octet, consisting of a tag number
1010
// (indicating a type) and class (such as context-specific or constructed).

Diff for: src/vendor/golang_org/x/crypto/cryptobyte/asn1_test.go renamed to src/internal/x/crypto/cryptobyte/asn1_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
"testing"
1313
"time"
1414

15-
"golang_org/x/crypto/cryptobyte/asn1"
15+
"internal/x/crypto/cryptobyte/asn1"
1616
)
1717

1818
type readASN1Test struct {

Diff for: src/vendor/golang_org/x/crypto/cryptobyte/example_test.go renamed to src/internal/x/crypto/cryptobyte/example_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import (
88
"errors"
99
"fmt"
1010

11-
"golang_org/x/crypto/cryptobyte"
12-
"golang_org/x/crypto/cryptobyte/asn1"
11+
"internal/x/crypto/cryptobyte"
12+
"internal/x/crypto/cryptobyte/asn1"
1313
)
1414

1515
func ExampleString_lengthPrefixed() {

0 commit comments

Comments
 (0)