Commit 2012227b authored by Bryan C. Mills's avatar Bryan C. Mills

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 <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarRuss Cox <rsc@golang.org>
parent 70a684cf
......@@ -442,13 +442,8 @@ func (w *Walker) Import(name string) (*types.Package, error) {
}
w.imported[name] = &importing
root := w.root
if strings.HasPrefix(name, "golang_org/x/") {
root = filepath.Join(root, "vendor")
}
// Determine package files.
dir := filepath.Join(root, filepath.FromSlash(name))
dir := filepath.Join(w.root, filepath.FromSlash(name))
if fi, err := os.Stat(dir); err != nil || !fi.IsDir() {
log.Fatalf("no source in tree for import %q: %v", name, err)
}
......
......@@ -1207,22 +1207,6 @@ func TestImportCycle(t *testing.T) {
tg.run("list", "-e", "-json", "selfimport")
}
func TestListImportMap(t *testing.T) {
skipIfGccgo(t, "gccgo does not have standard packages")
tg := testgo(t)
defer tg.cleanup()
tg.parallel()
tg.run("list", "-f", "{{.ImportPath}}: {{.ImportMap}}", "net", "fmt")
tg.grepStdout(`^net: map\[(.* )?golang_org/x/net/dns/dnsmessage:vendor/golang_org/x/net/dns/dnsmessage.*\]`, "net/http should have rewritten dnsmessage import")
tg.grepStdout(`^fmt: map\[\]`, "fmt should have no rewritten imports")
tg.run("list", "-deps", "-test", "-f", "{{.ImportPath}} MAP: {{.ImportMap}}\n{{.ImportPath}} IMPORT: {{.Imports}}", "fmt")
tg.grepStdout(`^flag \[fmt\.test\] MAP: map\[fmt:fmt \[fmt\.test\]\]`, "flag [fmt.test] should import fmt [fmt.test] as fmt")
tg.grepStdout(`^fmt\.test MAP: map\[(.* )?testing:testing \[fmt\.test\]`, "fmt.test should import testing [fmt.test] as testing")
tg.grepStdout(`^fmt\.test MAP: map\[(.* )?testing:testing \[fmt\.test\]`, "fmt.test should import testing [fmt.test] as testing")
tg.grepStdoutNot(`^fmt\.test MAP: map\[(.* )?os:`, "fmt.test should not import a modified os")
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")
}
// cmd/go: custom import path checking should not apply to Go packages without import comment.
func TestIssue10952(t *testing.T) {
testenv.MustHaveExternalNetwork(t)
......
......@@ -1051,20 +1051,6 @@ func disallowVendor(srcDir string, importer *Package, importerPath, path string,
return p
}
// Modules must not import vendor packages in the standard library,
// but the usual vendor visibility check will not catch them
// because the module loader presents them with an ImportPath starting
// with "golang_org/" instead of "vendor/".
if p.Standard && !importer.Standard && strings.HasPrefix(p.ImportPath, "golang_org") {
perr := *p
perr.Error = &PackageError{
ImportStack: stk.Copy(),
Err: "use of vendored package " + path + " not allowed",
}
perr.Incomplete = true
return &perr
}
if perr := disallowVendorVisibility(srcDir, p, stk); perr != p {
return perr
}
......
......@@ -58,9 +58,6 @@ func Import(path string) (m module.Version, dir string, err error) {
// Is the package in the standard library?
if search.IsStandardImportPath(path) {
if strings.HasPrefix(path, "golang_org/") {
return module.Version{}, filepath.Join(cfg.GOROOT, "src/vendor", path), nil
}
if goroot.IsStandardPackage(cfg.GOROOT, cfg.BuildContext.Compiler, path) {
dir := filepath.Join(cfg.GOROOT, "src", path)
return module.Version{}, dir, nil
......
# gccgo does not have standard packages.
[gccgo] skip
# fmt should have no rewritten imports.
# The import from a/b should map c/d to a's vendor directory.
go list -f '{{.ImportPath}}: {{.ImportMap}}' fmt a/b
stdout 'fmt: map\[\]'
stdout 'a/b: map\[c/d:a/vendor/c/d\]'
# flag [fmt.test] should import fmt [fmt.test] as fmt
# fmt.test should import testing [fmt.test] as testing
# fmt.test should not import a modified os
go list -deps -test -f '{{.ImportPath}} MAP: {{.ImportMap}}{{"\n"}}{{.ImportPath}} IMPORT: {{.Imports}}' fmt
stdout '^flag \[fmt\.test\] MAP: map\[fmt:fmt \[fmt\.test\]\]'
stdout '^fmt\.test MAP: map\[(.* )?testing:testing \[fmt\.test\]'
! stdout '^fmt\.test MAP: map\[(.* )?os:'
stdout '^fmt\.test IMPORT: \[fmt \[fmt\.test\] fmt_test \[fmt\.test\] os testing \[fmt\.test\] testing/internal/testdeps \[fmt\.test\]\]'
-- a/b/b.go --
package b
import _ "c/d"
-- a/vendor/c/d/d.go --
package d
......@@ -8,5 +8,5 @@ go list -f '{{if not .Standard}}{{.ImportPath}}{{end}}' ./...
# our vendored packages should be reported as standard
go list std cmd
stdout golang_org/x/net/http2/hpack
stdout internal/x/net/http2/hpack
stdout cmd/vendor/golang\.org/x/arch/x86/x86asm
......@@ -18,15 +18,6 @@ stderr 'use of internal package golang.org/x/.* not allowed'
! go build ./fromstd
stderr 'use of internal package internal/testenv not allowed'
# Packages found via standard-library vendoring should not leak.
! go build ./fromstdvendor
stderr 'use of vendored package golang_org/x/net/http/httpguts not allowed'
env GO111MODULE=off
! go build ./fromstdvendor
stderr 'cannot find package "golang_org/x/net/http/httpguts" in any of:'
env GO111MODULE=on
# Dependencies should be able to use their own internal modules...
rm go.mod
go mod init golang.org/notx
......@@ -83,10 +74,6 @@ import _ "golang.org/notx/useinternal"
package fromstd
import _ "internal/testenv"
-- fromstdvendor/useinternal.go --
package fromstdvendor
import _ "golang_org/x/net/http/httpguts"
-- replace/golang.org/notx/internal/go.mod --
module golang.org/x/internal
......
......@@ -4,7 +4,7 @@ go list -f '{{.TestImports}}'
stdout net/http # from .TestImports
go list -test -f '{{.Deps}}'
stdout golang_org/x/crypto # dep of .TestImports
stdout internal/x/crypto # dep of .TestImports
-- go.mod --
module m
......
......@@ -14,8 +14,8 @@ import (
"crypto/sha1"
"crypto/sha256"
"crypto/x509"
"golang_org/x/crypto/chacha20poly1305"
"hash"
"internal/x/crypto/chacha20poly1305"
)
// a keyAgreement implements the client and server side of a TLS key agreement
......
......@@ -6,7 +6,7 @@ package tls
import (
"fmt"
"golang_org/x/crypto/cryptobyte"
"internal/x/crypto/cryptobyte"
"strings"
)
......
......@@ -8,10 +8,10 @@ import (
"crypto/elliptic"
"crypto/hmac"
"errors"
"golang_org/x/crypto/cryptobyte"
"golang_org/x/crypto/curve25519"
"golang_org/x/crypto/hkdf"
"hash"
"internal/x/crypto/cryptobyte"
"internal/x/crypto/curve25519"
"internal/x/crypto/hkdf"
"io"
"math/big"
)
......
......@@ -12,7 +12,7 @@ import (
"crypto/sha256"
"crypto/subtle"
"errors"
"golang_org/x/crypto/cryptobyte"
"internal/x/crypto/cryptobyte"
"io"
)
......
......@@ -24,8 +24,8 @@ import (
"encoding/pem"
"errors"
"fmt"
"golang_org/x/crypto/cryptobyte"
cryptobyte_asn1 "golang_org/x/crypto/cryptobyte/asn1"
"internal/x/crypto/cryptobyte"
cryptobyte_asn1 "internal/x/crypto/cryptobyte/asn1"
"io"
"math/big"
"net"
......
......@@ -351,12 +351,16 @@ func TestImportDirNotExist(t *testing.T) {
func TestImportVendor(t *testing.T) {
testenv.MustHaveGoBuild(t) // really must just have source
ctxt := Default
ctxt.GOPATH = ""
p, err := ctxt.Import("golang_org/x/net/http2/hpack", filepath.Join(ctxt.GOROOT, "src/net/http"), 0)
wd, err := os.Getwd()
if err != nil {
t.Fatal(err)
}
ctxt.GOPATH = filepath.Join(wd, "testdata/withvendor")
p, err := ctxt.Import("c/d", filepath.Join(ctxt.GOPATH, "src/a/b"), 0)
if err != nil {
t.Fatalf("cannot find vendored golang_org/x/net/http2/hpack from net/http directory: %v", err)
t.Fatalf("cannot find vendored c/d from testdata src/a/b directory: %v", err)
}
want := "vendor/golang_org/x/net/http2/hpack"
want := "a/vendor/c/d"
if p.ImportPath != want {
t.Fatalf("Import succeeded but found %q, want %q", p.ImportPath, want)
}
......@@ -365,8 +369,12 @@ func TestImportVendor(t *testing.T) {
func TestImportVendorFailure(t *testing.T) {
testenv.MustHaveGoBuild(t) // really must just have source
ctxt := Default
ctxt.GOPATH = ""
p, err := ctxt.Import("x.com/y/z", filepath.Join(ctxt.GOROOT, "src/net/http"), 0)
wd, err := os.Getwd()
if err != nil {
t.Fatal(err)
}
ctxt.GOPATH = filepath.Join(wd, "testdata/withvendor")
p, err := ctxt.Import("x.com/y/z", filepath.Join(ctxt.GOPATH, "src/a/b"), 0)
if err == nil {
t.Fatalf("found made-up package x.com/y/z in %s", p.Dir)
}
......@@ -380,9 +388,13 @@ func TestImportVendorFailure(t *testing.T) {
func TestImportVendorParentFailure(t *testing.T) {
testenv.MustHaveGoBuild(t) // really must just have source
ctxt := Default
ctxt.GOPATH = ""
// This import should fail because the vendor/golang.org/x/net/http2 directory has no source code.
p, err := ctxt.Import("golang_org/x/net/http2", filepath.Join(ctxt.GOROOT, "src/net/http"), 0)
wd, err := os.Getwd()
if err != nil {
t.Fatal(err)
}
ctxt.GOPATH = filepath.Join(wd, "testdata/withvendor")
// This import should fail because the vendor/c directory has no source code.
p, err := ctxt.Import("c", filepath.Join(ctxt.GOPATH, "src/a/b"), 0)
if err == nil {
t.Fatalf("found empty parent in %s", p.Dir)
}
......
......@@ -320,7 +320,7 @@ var pkgDeps = map[string][]string{
"context", "math/rand", "os", "reflect", "sort", "syscall", "time",
"internal/nettrace", "internal/poll", "internal/syscall/unix",
"internal/syscall/windows", "internal/singleflight", "internal/race",
"golang_org/x/net/dns/dnsmessage", "golang_org/x/net/lif", "golang_org/x/net/route",
"internal/x/net/dns/dnsmessage", "internal/x/net/lif", "internal/x/net/route",
},
// NET enables use of basic network-related packages.
......@@ -357,9 +357,9 @@ var pkgDeps = map[string][]string{
"crypto/sha1",
"crypto/sha256",
"crypto/sha512",
"golang_org/x/crypto/chacha20poly1305",
"golang_org/x/crypto/curve25519",
"golang_org/x/crypto/poly1305",
"internal/x/crypto/chacha20poly1305",
"internal/x/crypto/curve25519",
"internal/x/crypto/poly1305",
},
// Random byte, number generation.
......@@ -387,13 +387,13 @@ var pkgDeps = map[string][]string{
// SSL/TLS.
"crypto/tls": {
"L4", "CRYPTO-MATH", "OS", "golang_org/x/crypto/cryptobyte", "golang_org/x/crypto/hkdf",
"L4", "CRYPTO-MATH", "OS", "internal/x/crypto/cryptobyte", "internal/x/crypto/hkdf",
"container/list", "crypto/x509", "encoding/pem", "net", "syscall",
},
"crypto/x509": {
"L4", "CRYPTO-MATH", "OS", "CGO",
"crypto/x509/pkix", "encoding/pem", "encoding/hex", "net", "os/user", "syscall", "net/url",
"golang_org/x/crypto/cryptobyte", "golang_org/x/crypto/cryptobyte/asn1",
"internal/x/crypto/cryptobyte", "internal/x/crypto/cryptobyte/asn1",
},
"crypto/x509/pkix": {"L4", "CRYPTO-MATH", "encoding/hex"},
......@@ -409,12 +409,12 @@ var pkgDeps = map[string][]string{
"context",
"crypto/rand",
"crypto/tls",
"golang_org/x/net/http/httpguts",
"golang_org/x/net/http/httpproxy",
"golang_org/x/net/http2/hpack",
"golang_org/x/net/idna",
"golang_org/x/text/unicode/norm",
"golang_org/x/text/width",
"internal/x/net/http/httpguts",
"internal/x/net/http/httpproxy",
"internal/x/net/http2/hpack",
"internal/x/net/idna",
"internal/x/text/unicode/norm",
"internal/x/text/width",
"internal/nettrace",
"mime/multipart",
"net/http/httptrace",
......@@ -432,9 +432,9 @@ var pkgDeps = map[string][]string{
"net/http/fcgi": {"L4", "NET", "OS", "context", "net/http", "net/http/cgi"},
"net/http/httptest": {
"L4", "NET", "OS", "crypto/tls", "flag", "net/http", "net/http/internal", "crypto/x509",
"golang_org/x/net/http/httpguts",
"internal/x/net/http/httpguts",
},
"net/http/httputil": {"L4", "NET", "OS", "context", "net/http", "net/http/internal", "golang_org/x/net/http/httpguts"},
"net/http/httputil": {"L4", "NET", "OS", "context", "net/http", "net/http/internal", "internal/x/net/http/httpguts"},
"net/http/pprof": {"L4", "OS", "html/template", "net/http", "runtime/pprof", "runtime/trace"},
"net/rpc": {"L4", "NET", "encoding/gob", "html/template", "net/http"},
"net/rpc/jsonrpc": {"L4", "NET", "encoding/json", "net/rpc"},
......@@ -485,7 +485,7 @@ func listStdPkgs(goroot string) ([]string, error) {
}
name := filepath.ToSlash(path[len(src):])
if name == "builtin" || name == "cmd" || strings.Contains(name, "golang_org") {
if name == "builtin" || name == "cmd" || strings.Contains(name, "internal/x/") {
return filepath.SkipDir
}
......
......@@ -99,7 +99,7 @@ var importedObjectTests = []struct {
{"math.Pi", "const Pi untyped float"},
{"math.Sin", "func Sin(x float64) float64"},
{"math/big.Int", "type Int struct{neg bool; abs nat}"},
{"golang_org/x/text/unicode/norm.MaxSegmentSize", "const MaxSegmentSize untyped int"},
{"internal/x/text/unicode/norm.MaxSegmentSize", "const MaxSegmentSize untyped int"},
}
func TestImportedTypes(t *testing.T) {
......
......@@ -3,7 +3,7 @@
// license that can be found in the LICENSE file.
// Package chacha20poly1305 implements the ChaCha20-Poly1305 AEAD as specified in RFC 7539.
package chacha20poly1305 // import "golang.org/x/crypto/chacha20poly1305"
package chacha20poly1305
import (
"crypto/cipher"
......
......@@ -7,8 +7,8 @@ package chacha20poly1305
import (
"encoding/binary"
"golang_org/x/crypto/internal/chacha20"
"golang_org/x/crypto/poly1305"
"internal/x/crypto/internal/chacha20"
"internal/x/crypto/poly1305"
)
func roundTo16(n int) int {
......
......@@ -11,7 +11,7 @@ import (
"reflect"
"time"
"golang_org/x/crypto/cryptobyte/asn1"
"internal/x/crypto/cryptobyte/asn1"
)
// This file contains ASN.1-related methods for String and Builder.
......
......@@ -4,7 +4,7 @@
// Package asn1 contains supporting types for parsing and building ASN.1
// messages with the cryptobyte package.
package asn1 // import "golang.org/x/crypto/cryptobyte/asn1"
package asn1
// Tag represents an ASN.1 identifier octet, consisting of a tag number
// (indicating a type) and class (such as context-specific or constructed).
......
......@@ -12,7 +12,7 @@ import (
"testing"
"time"
"golang_org/x/crypto/cryptobyte/asn1"
"internal/x/crypto/cryptobyte/asn1"
)
type readASN1Test struct {
......
......@@ -8,8 +8,8 @@ import (
"errors"
"fmt"
"golang_org/x/crypto/cryptobyte"
"golang_org/x/crypto/cryptobyte/asn1"
"internal/x/crypto/cryptobyte"
"internal/x/crypto/cryptobyte/asn1"
)
func ExampleString_lengthPrefixed() {
......
......@@ -15,7 +15,7 @@
//
// See the documentation and examples for the Builder and String types to get
// started.
package cryptobyte // import "golang.org/x/crypto/cryptobyte"
package cryptobyte
// String represents a string of bytes. It provides methods for parsing
// fixed-length and length-prefixed values from it.
......
......@@ -4,7 +4,7 @@
// Package curve25519 provides an implementation of scalar multiplication on
// the elliptic curve known as curve25519. See https://cr.yp.to/ecdh.html
package curve25519 // import "golang.org/x/crypto/curve25519"
package curve25519
// basePoint is the x coordinate of the generator of the curve.
var basePoint = [32]byte{9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
......
......@@ -11,7 +11,7 @@ import (
"fmt"
"io"
"golang_org/x/crypto/hkdf"
"internal/x/crypto/hkdf"
)
// Usage example that expands one master secret into three other
......
......@@ -8,7 +8,7 @@
// HKDF is a cryptographic key derivation function (KDF) with the goal of
// expanding limited input keying material into one or more cryptographically
// strong secret keys.
package hkdf // import "golang.org/x/crypto/hkdf"
package hkdf
import (
"crypto/hmac"
......
......@@ -17,7 +17,7 @@ used with a fixed key in order to generate one-time keys from an nonce.
However, in this package AES isn't used and the one-time key is specified
directly.
*/
package poly1305 // import "golang.org/x/crypto/poly1305"
package poly1305
import "crypto/subtle"
......
#!/bin/bash
# To fix import paths when importing new snapshots from the golang.org/x
# repositories, run this script in the current directory.
sed -i 's,"golang\.org/x,"internal/x,g' $(grep -lr 'golang.org')
......@@ -9,7 +9,7 @@ import (
"net"
"strings"
"golang_org/x/net/dns/dnsmessage"
"internal/x/net/dns/dnsmessage"
)
func mustNewName(name string) dnsmessage.Name {
......
......@@ -9,7 +9,7 @@ import (
"strings"
"unicode/utf8"
"golang_org/x/net/idna"
"internal/x/net/idna"
)
var isTokenTable = [127]bool{
......
......@@ -19,7 +19,7 @@ import (
"strings"
"unicode/utf8"
"golang_org/x/net/idna"
"internal/x/net/idna"
)
// Config holds configuration for HTTP proxy settings. See
......
......@@ -13,7 +13,7 @@ import (
"strings"
"testing"
"golang_org/x/net/http/httpproxy"
"internal/x/net/http/httpproxy"
)
// setHelper calls t.Helper() for Go 1.9+ (see go19_test.go) and does nothing otherwise.
......
......@@ -13,16 +13,16 @@
// UTS #46 is defined in http://www.unicode.org/reports/tr46.
// See http://unicode.org/cldr/utility/idna.jsp for a visualization of the
// differences between these two standards.
package idna // import "golang_org/x/text/internal/export/idna"
package idna
import (
"fmt"
"strings"
"unicode/utf8"
"golang_org/x/text/secure/bidirule"
"golang_org/x/text/unicode/bidi"
"golang_org/x/text/unicode/norm"
"internal/x/text/secure/bidirule"
"internal/x/text/unicode/bidi"
"internal/x/text/unicode/norm"
)
// NOTE: Unlike common practice in Go APIs, the functions will return a
......
// Code generated by running "go generate" in golang.org/x/text. DO NOT EDIT.
// Code generated by running "go generate" in golang_org/x/text. DO NOT EDIT.
// Code generated by running "go generate" in internal/x/text. DO NOT EDIT.
package idna
......
// Code generated by running "go generate" in golang.org/x/text. DO NOT EDIT.
// Code generated by running "go generate" in golang_org/x/text. DO NOT EDIT.
// Code generated by running "go generate" in internal/x/text. DO NOT EDIT.
package idna
......
......@@ -3,7 +3,7 @@
// license that can be found in the LICENSE file.
// Package nettest provides utilities for network testing.
package nettest // import "golang.org/x/net/internal/nettest"
package nettest
import (
"fmt"
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment