@@ -399,11 +399,7 @@ func (rp *IndexPackage) Import(bctxt build.Context, mode build.ImportMode) (p *b
399
399
// In build.go, p.Root should only be set in the non-local-import case, or in
400
400
// GOROOT or GOPATH. Since module mode only calls Import with path set to "."
401
401
// and the module index doesn't apply outside modules, the GOROOT case is
402
- // the only case where GOROOT needs to be set.
403
- // But: p.Root is actually set in the local-import case outside GOROOT, if
404
- // the directory is contained in GOPATH/src
405
- // TODO(#37015): fix that behavior in go/build and remove the gopath case
406
- // below.
402
+ // the only case where p.Root needs to be set.
407
403
if ctxt .GOROOT != "" && str .HasFilePathPrefix (p .Dir , cfg .GOROOTsrc ) && p .Dir != cfg .GOROOTsrc {
408
404
p .Root = ctxt .GOROOT
409
405
p .Goroot = true
@@ -412,47 +408,32 @@ func (rp *IndexPackage) Import(bctxt build.Context, mode build.ImportMode) (p *b
412
408
if modprefix != "" {
413
409
p .ImportPath = filepath .Join (modprefix , p .ImportPath )
414
410
}
415
- }
416
- for _ , root := range ctxt .gopath () {
417
- // TODO(matloob): do we need to reimplement the conflictdir logic?
418
-
419
- // TODO(matloob): ctxt.hasSubdir evaluates symlinks, so it
420
- // can be slower than we'd like. Find out if we can drop this
421
- // logic before the release.
422
- if sub , ok := ctxt .hasSubdir (filepath .Join (root , "src" ), p .Dir ); ok {
423
- p .ImportPath = sub
424
- p .Root = root
411
+
412
+ // Set GOROOT-specific fields (sometimes for modules in a GOPATH directory).
413
+ // The fields set below (SrcRoot, PkgRoot, BinDir, PkgTargetRoot, and PkgObj)
414
+ // are only set in build.Import if p.Root != "".
415
+ var pkgtargetroot string
416
+ var pkga string
417
+ suffix := ""
418
+ if ctxt .InstallSuffix != "" {
419
+ suffix = "_" + ctxt .InstallSuffix
420
+ }
421
+ switch ctxt .Compiler {
422
+ case "gccgo" :
423
+ pkgtargetroot = "pkg/gccgo_" + ctxt .GOOS + "_" + ctxt .GOARCH + suffix
424
+ dir , elem := path .Split (p .ImportPath )
425
+ pkga = pkgtargetroot + "/" + dir + "lib" + elem + ".a"
426
+ case "gc" :
427
+ pkgtargetroot = "pkg/" + ctxt .GOOS + "_" + ctxt .GOARCH + suffix
428
+ pkga = pkgtargetroot + "/" + p .ImportPath + ".a"
429
+ }
430
+ p .SrcRoot = ctxt .joinPath (p .Root , "src" )
431
+ p .PkgRoot = ctxt .joinPath (p .Root , "pkg" )
432
+ p .BinDir = ctxt .joinPath (p .Root , "bin" )
433
+ if pkga != "" {
434
+ p .PkgTargetRoot = ctxt .joinPath (p .Root , pkgtargetroot )
435
+ p .PkgObj = ctxt .joinPath (p .Root , pkga )
425
436
}
426
- }
427
- }
428
- if p .Root != "" {
429
- // Set GOROOT-specific fields (sometimes for modules in a GOPATH directory).
430
- // The fields set below (SrcRoot, PkgRoot, BinDir, PkgTargetRoot, and PkgObj)
431
- // are only set in build.Import if p.Root != "". As noted in the comment
432
- // on setting p.Root above, p.Root should only be set in the GOROOT case for the
433
- // set of packages we care about, but is also set for modules in a GOPATH src
434
- // directory.
435
- var pkgtargetroot string
436
- var pkga string
437
- suffix := ""
438
- if ctxt .InstallSuffix != "" {
439
- suffix = "_" + ctxt .InstallSuffix
440
- }
441
- switch ctxt .Compiler {
442
- case "gccgo" :
443
- pkgtargetroot = "pkg/gccgo_" + ctxt .GOOS + "_" + ctxt .GOARCH + suffix
444
- dir , elem := path .Split (p .ImportPath )
445
- pkga = pkgtargetroot + "/" + dir + "lib" + elem + ".a"
446
- case "gc" :
447
- pkgtargetroot = "pkg/" + ctxt .GOOS + "_" + ctxt .GOARCH + suffix
448
- pkga = pkgtargetroot + "/" + p .ImportPath + ".a"
449
- }
450
- p .SrcRoot = ctxt .joinPath (p .Root , "src" )
451
- p .PkgRoot = ctxt .joinPath (p .Root , "pkg" )
452
- p .BinDir = ctxt .joinPath (p .Root , "bin" )
453
- if pkga != "" {
454
- p .PkgTargetRoot = ctxt .joinPath (p .Root , pkgtargetroot )
455
- p .PkgObj = ctxt .joinPath (p .Root , pkga )
456
437
}
457
438
}
458
439
0 commit comments