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

fix(status): add constraint for locked projects #962

Merged
merged 5 commits into from
Nov 27, 2017

Conversation

darkowlzz
Copy link
Collaborator

@darkowlzz darkowlzz commented Aug 6, 2017

What does this do / why do we need it?

Uses project lock to get the constraints of projects not in manifest.

What should your reviewer look out for in this PR?

Correctness of implementation.

Do you need help or clarification on anything?

Before:

PROJECT                             CONSTRAINT     VERSION        REVISION  LATEST   PKGS USED
github.com/Masterminds/semver       branch 2.x     branch 2.x     139cc09   c2e7f6c  1
github.com/Masterminds/vcs          ^1.11.0        v1.11.1        3084677   3084677  1
github.com/armon/go-radix           *              branch master  4239b77   1fca145  1
github.com/go-yaml/yaml             branch v2      branch v2      cd8b52f   25c4ec8  1
github.com/nightlyone/lockfile      *              branch master  e83dc5e   6a197d5  1
github.com/pelletier/go-buffruneio  *              v0.2.0         c37440a   c37440a  1
github.com/pelletier/go-toml        branch master  branch master  fe206ef   69d355d  1
github.com/pkg/errors               ^0.8.0         v0.8.0         645ef00   645ef00  1
github.com/sdboyer/constext         *              branch master  836a144   836a144  1

With this change:

PROJECT                             CONSTRAINT     VERSION        REVISION  LATEST   PKGS USED
github.com/Masterminds/semver       branch 2.x     branch 2.x     139cc09   c2e7f6c  1
github.com/Masterminds/vcs          ^1.11.0        v1.11.1        3084677   3084677  1
github.com/armon/go-radix           branch master  branch master  4239b77            1
github.com/go-yaml/yaml             branch v2      branch v2      cd8b52f   25c4ec8  1
github.com/nightlyone/lockfile      branch master  branch master  e83dc5e            1
github.com/pelletier/go-buffruneio  v0.2.0         v0.2.0         c37440a   c37440a  1
github.com/pelletier/go-toml        branch master  branch master  fe206ef   69d355d  1
github.com/pkg/errors               ^0.8.0         v0.8.0         645ef00   645ef00  1
github.com/sdboyer/constext         branch master  branch master  836a144   836a144  1

For some reason, LATEST of go-radix and lockfile aren't showing up. Constraint.Matches() seems to be failing. Some help in figuring out the reason would be great.

Update: The missing LATEST above is because those projects don't have any release.

Which issue(s) does this PR fix?

Related to #893

// Get constraint for locked project
for _, lockedP := range p.Lock.P {
if lockedP.Ident().ProjectRoot == proj.Ident().ProjectRoot {
c.Constraint = lockedP.Version()
Copy link
Member

Choose a reason for hiding this comment

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

We can't make this jump, unfortunately - the version in the lock doesn't really tell us anything about what the constraints were that got us there. For any possible version that would be in a lock, there are at least two possible constraints that would allow it:

  1. An exact match for that version
  2. An Any constraint

so yeah, we've gotta do the CollectConstraints thing in order to be able to fill this in accurately 😢

@darkowlzz darkowlzz force-pushed the status-transitive-constraint branch from 7cdb8f6 to ea8b946 Compare August 8, 2017 13:07
@darkowlzz
Copy link
Collaborator Author

@sdboyer I have implemented collectConstraints() from what I understood. Can you verify if this is how it should be done?

sdboyer
sdboyer previously requested changes Oct 7, 2017
Copy link
Member

@sdboyer sdboyer left a comment

Choose a reason for hiding this comment

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

sorry i dawdled so much on this 😢

collectConstraints implementation looks good, though let's make sure to add some tests for it. after that, shouldn't be too much more work to get this squared away!

// Create a root analyzer
rootAnalyzer := newRootAnalyzer(false, ctx, directDeps, sm)

// Iterate through the locked projects and collect constrains of all the projects
Copy link
Member

Choose a reason for hiding this comment

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

nit: s/constrains/constraints/

also, missing period

for pr, pp := range pc {
// Check if a collection exists for a project root and append to
// existing one or create a new constraint collection.
if cc, exists := constraintCollection[string(pr)]; exists {
Copy link
Member

Choose a reason for hiding this comment

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

i think this can be safely shortened to a one-liner, as lookups to nonexistent keys on maps will return the zero value for the map's value type:

constraintCollection[string(pr)] = append(constraintCollection[string(pr)], pp.Constraint)

@darkowlzz darkowlzz force-pushed the status-transitive-constraint branch 2 times, most recently from 439d7f9 to 0d33290 Compare October 29, 2017 12:14
@darkowlzz
Copy link
Collaborator Author

darkowlzz commented Oct 29, 2017

@sdboyer I'm not sure how to write a test for this without creating new projects with the manifest file in them. Can we reuse some of your test repos for this? Or should I create repos of my own?

@darkowlzz
Copy link
Collaborator Author

I created https://github.com/darkowlzz/deptest-project-1 and https://github.com/darkowlzz/deptest-project-2 for testing collectConstraints() with different version of same project.

@darkowlzz darkowlzz force-pushed the status-transitive-constraint branch 2 times, most recently from 3632c8c to 8d2d1cd Compare November 12, 2017 13:34
@darkowlzz
Copy link
Collaborator Author

Added projectConstraint and constraintsCollection types to store information about which project sets a constraint on a given dependency project. This would be required in #1367 to create PROJECT IMPORTERS list.

@sdboyer sdboyer dismissed their stale review November 13, 2017 21:48

needs new review

Use project lock to get the constraints of projects not in manifest.
The resultant collection obtained from collectConstraints() should
contain data about which project set a particular constraint on a
dependency project. `projectConstraint` consists of the project and the
constraint it sets on a given dependency.

And `constraintsCollection` is a map to store the pair of dependency project
and a collection of `projectConstraint` for different constraints.

This would be used by project argument status (status for a single project),
to show the importers of the project.
// Iterate through the project constraints to get individual dependency
// project and constraint values.
for pr, pp := range pc {
constraintCollection[string(pr)] = append(
Copy link
Member

Choose a reason for hiding this comment

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

so this is overzealous right now - it pulls in constraints regardless of whether they're actually applicable or not. it's unlikely to create problems right now, but it will need to be updated in the future (please open an issue!) to do the equivalent of something like intersectConstraintsWithImports() or getApplicableConstraints()

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants