Description
In writing #36875, I realized that we will have a bit of a problem with vendored dependencies if and when we start making incompatible changes to the language.
Specifically, the vendor
directory is a flattened package tree, and it does not include go.mod
files unless the vendored package dependencies happen to include a package at the root of the vendored module. Many modules (such as golang.org/x/tools
) don't even have an importable package at the root, let alone one that someone would want to import.
Unfortunately, the go.mod
files are currently the only place where we record the language version to use for those dependencies. (I don't know what language version we end up using for -mod=vendor
builds today, but I don't see how it could possibly be the correct one in general.)
I can think of two possible fixes:
-
Extend the
##
annotation comments that we added for cmd/go: automatically check and use vendored packages #33848 so that, for any module that provides one or more packages, we annotate thego
version (if any) found in the dependency's originalgo.mod
file. (Fortunately, we intentionally designed that part of the format to tolerate the addition of new annotations.)
For example:# golang.org/x/text v0.3.3 ## explicit, go 1.14 golang.org/x/text/number
-
Explicitly copy in the
go.mod
files for each module that provides one or more packages, even if there is no corresponding package in that part of thevendor
tree.
I have a slight preference for approach (1) but don't feel strongly about it.