-
Notifications
You must be signed in to change notification settings - Fork 1k
Process import comments properly #902
Comments
I gave it some time yesterday and the beginnings didn't seem too difficult indeed. Got import comment extraction working here (sans tests and some error checking). Tried looking at solver to find a place where it would use the new data, but that bit looks a bit overwhelming at first. |
oh, awesome!! 🎉 🎉 🎉 🎊 🎊 that looks like a great start. we should probably do this in two stages - first, getting in a subsequent PR, then, the place to integrate into the solver will be right around here in at the linked line, we're visiting an atom (a project@a particular version), and there is a set of inbound imports on the atom that've already been established, retrieved by this call. the question to answer is whether the shape of those import statements complies with the package comments metadata on the atom's package tree. the check itself, which i think will be fairly straightforward (though you will have to decipher the data in the we'll probably also need a new solver-specific error, as |
Okay, I tried following your suggestions and here's what I ended up with. Didn't submit a PR yet, since I wasn't able to introduce a new error while maintaining what Also, no tests for the new code path, couldn't find where can I stick it in. |
oh, that seems like it's heading in a good direction! honestly, idk if this seems like a small thing to you, but having other people touch the solver logic is a big deal for me, as it's scarcely happened yet 😄 so, i haven't looked at the logic in basically, we have two options. ideally, i would like to see the fixture types + the associated DSL expand to fully cover these conditions as we add them. that might be a bit tricky, though, so i could accept a fallback: basically, you could craft a test similar to if we go the latter route, then i'd want to make sure we have an issue opened for follow-up. if you're willing to do the former...well, actually, it might not be that bad. really, we'll want to work from the |
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 viewvendor/
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 inpkgtree.fillPackage()
. We'll need:go/build
does (it's not exported, may not even exist as a type).importRoot
argument topkgtree.ListPackages()
. This'll definitely require a new error type.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
The text was updated successfully, but these errors were encountered: