-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Basic lockfile support #49
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -93,6 +93,7 @@ func main() { | |
UpdateCommand, | ||
DvcsDepsCommand, | ||
LinkCommand, | ||
LockGenCommand, | ||
|
||
DevCopyCommand, | ||
// Go tool compat: | ||
|
@@ -129,6 +130,44 @@ var DepMapCommand = cli.Command{ | |
}, | ||
} | ||
|
||
var LockGenCommand = cli.Command{ | ||
Name: "lock-gen", | ||
Usage: "Generate a lock file", | ||
Flags: []cli.Flag{ | ||
cli.BoolFlag{ | ||
Name: "ignore-conflicts", | ||
Usage: "Does not error on conflicting import in sub-packages", | ||
}, | ||
}, | ||
Action: func(c *cli.Context) error { | ||
ignoreConflict := c.Bool("ignore-conflicts") | ||
|
||
pkg, err := LoadPackageFile(gx.PkgFileName) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
done := make(map[string]bool) | ||
lockFile := gx.LockFile{ | ||
Language: pkg.Language, | ||
LockVersion: gx.LockVersion, | ||
} | ||
lockFile.Deps = make(map[string]gx.LockDep) | ||
|
||
if err := genLockDeps(pkg, lockFile.Deps, done, ignoreConflict); err != nil { | ||
return err | ||
} | ||
|
||
m, err := json.MarshalIndent(lockFile, "", " ") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
_, err = os.Stdout.Write(m) | ||
return err | ||
}, | ||
} | ||
|
||
var HookCommand = cli.Command{ | ||
Name: "hook", | ||
Usage: "go specific hooks to be called by the gx tool", | ||
|
@@ -783,6 +822,43 @@ var DevCopyCommand = cli.Command{ | |
}, | ||
} | ||
|
||
func genLockDeps(pkg *Package, deps map[string]gx.LockDep, done map[string]bool, ignoreConflict bool) error { | ||
for _, dep := range pkg.Dependencies { | ||
if done[dep.Hash] { | ||
continue | ||
} | ||
|
||
done[dep.Hash] = true | ||
|
||
var cpkg Package | ||
err := gx.LoadPackage(&cpkg, pkg.Language, dep.Hash) | ||
if err != nil { | ||
if os.IsNotExist(err) { | ||
VLog("LoadPackage error: ", err) | ||
return fmt.Errorf("package %s (%s) not found", dep.Name, dep.Hash) | ||
} | ||
return err | ||
} | ||
|
||
ref := fmt.Sprintf("/ipfs/%s/%s", dep.Hash, dep.Name) | ||
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 seems to be (along with the |
||
if d, found := deps[cpkg.Gx.DvcsImport]; found { | ||
if !ignoreConflict && ref != d.Ref { | ||
return fmt.Errorf("Found a duplicate import %s for package %s", cpkg.Gx.DvcsImport, pkg.Name) | ||
} | ||
} else { | ||
deps[cpkg.Gx.DvcsImport] = gx.LockDep{ | ||
Ref: ref, | ||
} | ||
} | ||
|
||
if err := genLockDeps(&cpkg, deps, done, ignoreConflict); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func devCopySymlinking(root string, pkg *Package, done map[string]bool) error { | ||
for _, dep := range pkg.Dependencies { | ||
if done[dep.Hash] { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Could we use the
DependencyQueue
here? (I'm not sure, since it belongs to thegx
repo).Ideally I would like to have a function that just returns all the (unique) dependencies of a package. From what I'm seeing in the gx/gx-go code bases we're doing a lot of "get me all your direct and transitive dependencies" (converting
Dependency
toPackage
) types of operation.