Description
Go 1.4 introduced support for declaring canonical import paths via import comments. Now, TIL that these import comments are ignored by the compiler when within a vendor/
directory, so we could disregard them. But that seems unwise. Given that we view vendor/
as an implementation detail, there's a time in the foreseeable future where the compiler may start enforcing these comments again, and we should enforce them in order for our generated lock files to be maximally forwards-compatible.
Beyond this practical reason, import comments are a useful bit of information that establish internal identity and canonicality for code locations in a world where identity is otherwise entirely determined by the importer/addresser. That makes them a very useful signal, and we should take advantage of it.
The place where this information needs to enter the system is in pkgtree.ListPackages()
; the processing work itself is done in pkgtree.fillPackage()
. We'll need:
- Basic error coverage, in the event that a single package has multiple, incompatible import comments. We'll need to make our own type for this, as we can't reuse whatever
go/build
does (it's not exported, may not even exist as a type). - Validation that the import comment aligns as expected with the
importRoot
argument topkgtree.ListPackages()
. This'll definitely require a new error type. - New tests that cover all possibilities, happy and not, codified via new fixtures under
internal/gps/_testdata/src
and utilized inTestListPackages()
.
Note that changing this will probably entail bumping the solver version (the number in Gopkg.lock
). It's our first time doing that, so we'll need to plan a little bit around it. In a follow-up issue, we can modify the solver to incorporate a new satisfiability check that the import comment data is respected.
/cc @ChimeraCoder