diff options
author | Ian Lance Taylor <iant@golang.org> | 2023-03-20 12:53:22 -0700 |
---|---|---|
committer | Gopher Robot <gobot@golang.org> | 2023-03-20 22:03:35 +0000 |
commit | c7f5b3595be77dc86ff99aa170bd40e55961e05f (patch) | |
tree | 6de27aa047157ed2de0b506ca9ee0c6cc7e10234 /src/cmd/go/internal/load/pkg.go | |
parent | 86ad2d570c79e1687ba0782a2be891195da42cbf (diff) | |
download | go-c7f5b3595be77dc86ff99aa170bd40e55961e05f.tar.gz go-c7f5b3595be77dc86ff99aa170bd40e55961e05f.zip |
cmd/go: import runtime/cgo when externally linking
Restore CL 477195, which was reverted in CL 477795.
This version includes CL 477397, which fixes the test problems
with CL 477195. CL 477397 was not submitted because it had an
unrelated failure on darwin-amd64. That failure is fixed by CL 477736.
Fixes #31544
Change-Id: I3a2258cd0ca295cede3511ab212e56fd0114f94a
Reviewed-on: https://go-review.googlesource.com/c/go/+/477839
Reviewed-by: Bryan Mills <bcmills@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Auto-Submit: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Diffstat (limited to 'src/cmd/go/internal/load/pkg.go')
-rw-r--r-- | src/cmd/go/internal/load/pkg.go | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/src/cmd/go/internal/load/pkg.go b/src/cmd/go/internal/load/pkg.go index 40278dda4d..922dc99e69 100644 --- a/src/cmd/go/internal/load/pkg.go +++ b/src/cmd/go/internal/load/pkg.go @@ -684,6 +684,15 @@ const ( // GetTestDeps is for download (part of "go get") and indicates // that test dependencies should be fetched too. GetTestDeps + + // The remainder are internal modes for calls to loadImport. + + // cmdlinePkg is for a package mentioned on the command line. + cmdlinePkg + + // cmdlinePkgLiteral is for a package mentioned on the command line + // without using any wildcards or meta-patterns. + cmdlinePkgLiteral ) // LoadImport scans the directory named by path, which must be an import path, @@ -738,18 +747,30 @@ func loadImport(ctx context.Context, opts PackageOpts, pre *preload, path, srcDi return p } + setCmdline := func(p *Package) { + if mode&cmdlinePkg != 0 { + p.Internal.CmdlinePkg = true + } + if mode&cmdlinePkgLiteral != 0 { + p.Internal.CmdlinePkgLiteral = true + } + } + importPath := bp.ImportPath p := packageCache[importPath] if p != nil { stk.Push(path) p = reusePackage(p, stk) stk.Pop() + setCmdline(p) } else { p = new(Package) p.Internal.Local = build.IsLocalImport(path) p.ImportPath = importPath packageCache[importPath] = p + setCmdline(p) + // Load package. // loadPackageData may return bp != nil even if an error occurs, // in order to return partial information. @@ -2849,15 +2870,15 @@ func PackagesAndErrors(ctx context.Context, opts PackageOpts, patterns []string) if pkg == "" { panic(fmt.Sprintf("ImportPaths returned empty package for pattern %s", m.Pattern())) } - p := loadImport(ctx, opts, pre, pkg, base.Cwd(), nil, &stk, nil, 0) - p.Match = append(p.Match, m.Pattern()) - p.Internal.CmdlinePkg = true + mode := cmdlinePkg if m.IsLiteral() { // Note: do not set = m.IsLiteral unconditionally // because maybe we'll see p matching both // a literal and also a non-literal pattern. - p.Internal.CmdlinePkgLiteral = true + mode |= cmdlinePkgLiteral } + p := loadImport(ctx, opts, pre, pkg, base.Cwd(), nil, &stk, nil, mode) + p.Match = append(p.Match, m.Pattern()) if seenPkg[p] { continue } |