Skip to content
This repository has been archived by the owner on Sep 9, 2020. It is now read-only.

Trim hidden packages from (root) PackageTrees #1271

Merged
merged 11 commits into from
Oct 15, 2017

Conversation

sdboyer
Copy link
Member

@sdboyer sdboyer commented Oct 14, 2017

What does this do / why do we need it?

This deals with a few interrelated issues:

  1. The count of "transitively valid" packages in -v output is including packages that aren't actually being considered, which is misleading.
  2. Respect canonical import comments #1017 introduced a regression by causing conflicting import comments to result in pkgtree.ListPackages() aborting entirely.
  3. dep has been erroneously complaining about errors in its own testdata dirs for a while now.
  4. There appears to be some drift in the way that dep status invokes PackageTree.ToReachMap(), vs. dep init and dep ensure.

This doesn't quite fully fix the fourth item, but it gets us close.

The crux of the fix here is the introduction of PackageTree.TrimHiddenPackages(), which generates a new PackageTree that has hidden, unreachable and optionally ignored packages removed from it. This is not the most efficient way of doing it, as it means ListPackages() is still doing analysis of directories that we may end up throwing away - but it's much cleaner to bolt on top this way, and this isn't mutually exclusive with adding that logic later anyway.

It may also be appropriate to move the checkErrors() function currently in cmd/dep/ensure.go over into the pkgtree package, as its behavior is sufficiently general.

What should your reviewer look out for in this PR?

nothing in particular

Which issue(s) does this PR fix?

Honestly, it's kinda amazing our CI works right now - dep can't run on itself.

This has general utility, independent of ListPackages() being improved
to avoid unnecessary disk reads in typically-hidden directories.
This consolidates calls to parse the root project's code tree into a
single place, so as to avoid confusion about the standard, expected way
that dep's root project tree is to be created. It may not be fully
suitable for all status cases, but standardization is crucial for init
and ensure.
These should never have been global failures within ListPackages(), as
they are entirely package-specific information.
Copy link
Collaborator

@darkowlzz darkowlzz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Covers all the things I had in my incomplete PR. 👍

@sdboyer
Copy link
Member Author

sdboyer commented Oct 14, 2017

i think this is just down to needing some tests specifically for TrimHiddenPackages(), now.

We only perform a single allocation for all []string, and are careful to
copy all possible error values via reflection.
While this would be possible to implement, it would require writing
entirely new entry logic into wmToReach(). That seems like a
sufficiently strong indication of breaking domain assumptions that it's
preferable just to drop the parameter, which was questionable in
the first place.
@sdboyer
Copy link
Member Author

sdboyer commented Oct 15, 2017

i went back and forth on a keepIgnored parameter for PackageTree.TrimHiddenPackages() - with some of the present ambiguity (#1264 (comment)) around whether "ignored" eliminates a node, or merely the node's out-edges, i wasn't feeling confident about whether or not to include it.

however, going some fairly exhaustive combinatorial input tests tests demonstrated that there are semi-absurd edge cases where it would be impossible to keepIgnored without needing to eschew PackageTree.ToReachMap() and instead write an entirely new preprocessing routine for wmToReach(). This struck me as a strong enough indicator that it was a model-breaking concept that I dropped the parameter.

@sdboyer sdboyer merged commit 1d73a4a into golang:master Oct 15, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants