-
Notifications
You must be signed in to change notification settings - Fork 1k
gb project importer #818
gb project importer #818
Changes from 1 commit
73a3c60
2fefb88
0df95d4
e9e8a9b
c1167c6
0cf51a3
5ac982a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -115,20 +115,21 @@ func (i *gbImporter) convert(pr gps.ProjectRoot) (*dep.Manifest, *dep.Lock, erro | |
|
||
// Deduce the project root. This is necessary because gb manifests can have | ||
// multiple entries for the same project root, one for each imported subpackage | ||
var ip gps.ProjectRoot | ||
var root gps.ProjectRoot | ||
var err error | ||
if ip, err = i.sm.DeduceProjectRoot(pkg.Importpath); err != nil { | ||
if root, err = i.sm.DeduceProjectRoot(pkg.Importpath); err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
// Set the proper import path back on the dependency | ||
pkg.Importpath = string(ip) | ||
pkg.Importpath = string(root) | ||
|
||
// If we've already locked this project root then we can skip | ||
if projectExistsInLock(lock, pkg.Importpath) { | ||
continue | ||
} | ||
|
||
// Otherwise, attempt to convert this specific package, which returns a constraint and a lock | ||
pc, lp, err := i.convertOne(pkg) | ||
if err != nil { | ||
return nil, nil, err | ||
|
@@ -156,6 +157,11 @@ func (i *gbImporter) convertOne(pkg gbDependency) (pc gps.ProjectConstraint, lp | |
|
||
However, if we can infer a tag that points to the revision or the branch, we may be able | ||
to use that as the constraint | ||
|
||
So, the order of operations to convert a single dependency in a gb manifest is: | ||
- Find a specific version for the revision (and branch, if set) | ||
- If there's a branch available, use that as the constraint | ||
- If there's no branch, but we found a version from step 1, use the version as the constraint | ||
*/ | ||
pc.Ident = gps.ProjectIdentifier{ProjectRoot: gps.ProjectRoot(pkg.Importpath), Source: pkg.Repository} | ||
|
||
|
@@ -164,7 +170,7 @@ func (i *gbImporter) convertOne(pkg gbDependency) (pc gps.ProjectConstraint, lp | |
|
||
// But if the branch field is not "HEAD", we can use that as the initial constraint | ||
var constraint gps.Constraint | ||
if pkg.Branch != "HEAD" { | ||
if pkg.Branch != "" && pkg.Branch != "HEAD" { | ||
constraint = gps.NewBranch(pkg.Branch) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This method is missing a conditional branch that uses the constraint if a branch is set, and otherwise uses the result of Here are the steps we need:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, I misunderstood some of the functions I was calling. I'll rejigger it. |
||
} | ||
|
||
|
@@ -175,12 +181,21 @@ func (i *gbImporter) convertOne(pkg gbDependency) (pc gps.ProjectConstraint, lp | |
i.logger.Println(err.Error()) | ||
} | ||
|
||
// And now try to infer a constraint from the returned version | ||
pc.Constraint, err = i.sm.InferConstraint(version.String(), pc.Ident) | ||
if err != nil { | ||
return | ||
// If the constraint is nil (no branch), but there's a version, infer a constraint from there | ||
if constraint == nil && version != nil { | ||
constraint, err = i.sm.InferConstraint(version.String(), pc.Ident) | ||
if err != nil { | ||
return | ||
} | ||
} | ||
|
||
// If there's *still* no constraint, set the constraint to the revision | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this the proper behavior? Should there just not be a constraint if there's no branch specified and no tag that points to the revision? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In general, Instead of not adding a constraint, what we should do in this case (i.e. they haven't picked a branch and are using a revision that isn't tagged) is to set The result will be an entry in the manifest without any restriction on it: [[constraint]]
name = "github.com/carolyn/lovesponies" |
||
if constraint == nil { | ||
constraint = revision | ||
} | ||
|
||
pc.Constraint = constraint | ||
|
||
lp = gps.NewLockedProject(pc.Ident, version, nil) | ||
|
||
fb.NewConstraintFeedback(pc, fb.DepTypeImported).LogFeedback(i.logger) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The convention is to log the (general) constraint first, and then the (specific) lock, giving us output that looks like this:
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The inline doc is very helpful! 👍