@@ -222,20 +222,25 @@ func moduleLine(m, r module.Version) string {
222
222
}
223
223
224
224
func vendorPkg (vdir , pkg string ) {
225
- // TODO(#42504): Instead of calling modload.ImportMap then build.ImportDir,
226
- // just call load.PackagesAndErrors. To do that, we need to add a good way
227
- // to ignore build constraints.
228
- realPath := modload .ImportMap (pkg )
229
- if realPath != pkg && modload .ImportMap (realPath ) != "" {
225
+ src , realPath , _ := modload .Lookup ("" , false , pkg )
226
+ if src == "" {
227
+ base .Errorf ("internal error: no pkg for %s\n " , pkg )
228
+ return
229
+ }
230
+ if realPath != pkg {
231
+ // TODO(#26904): Revisit whether this behavior still makes sense.
232
+ // This should actually be impossible today, because the import map is the
233
+ // identity function for packages outside of the standard library.
234
+ //
235
+ // Part of the purpose of the vendor directory is to allow the packages in
236
+ // the module to continue to build in GOPATH mode, and GOPATH-mode users
237
+ // won't know about replacement aliasing. How important is it to maintain
238
+ // compatibility?
230
239
fmt .Fprintf (os .Stderr , "warning: %s imported as both %s and %s; making two copies.\n " , realPath , realPath , pkg )
231
240
}
232
241
233
242
copiedFiles := make (map [string ]bool )
234
243
dst := filepath .Join (vdir , pkg )
235
- src := modload .PackageDir (realPath )
236
- if src == "" {
237
- fmt .Fprintf (os .Stderr , "internal error: no pkg for %s -> %s\n " , pkg , realPath )
238
- }
239
244
copyDir (dst , src , matchPotentialSourceFile , copiedFiles )
240
245
if m := modload .PackageModule (realPath ); m .Path != "" {
241
246
copyMetadata (m .Path , realPath , dst , src , copiedFiles )
0 commit comments