Fixed pin file generation.
- Does the entire tree rather than just the top level. Pins all
the things.
- Removes the top level project if it shows up in the recursive
dependeinces so it's not placed in the vendor folder.
diff --git a/cmd/flatten.go b/cmd/flatten.go
index e9bdcaa..652b522 100644
--- a/cmd/flatten.go
+++ b/cmd/flatten.go
@@ -56,6 +56,13 @@
f := &flattening{conf, vend, vend, deps, packages}
err := recFlatten(f, force, home, cache, cacheGopath, skipGopath)
+ if err != nil {
+ return conf, err
+ }
+ err = conf.DeDupe()
+ if err != nil {
+ return conf, err
+ }
flattenSetRefs(f)
Info("Project relies on %d dependencies.", len(deps))
@@ -134,6 +141,11 @@
func flattenGlideUp(f *flattening, base, home string, force, cache, cacheGopath, skipGopath bool) error {
//vdir := path.Join(base, "vendor")
for _, imp := range f.deps {
+ // If the top package name in the glide.yaml file is present in the deps
+ // skip it because we already have it.
+ if imp.Name == f.conf.Name {
+ continue
+ }
wd := path.Join(f.top, imp.Name)
if VcsExists(imp, wd) {
if updateCache[imp.Name] {
diff --git a/cmd/update_references.go b/cmd/update_references.go
index 33c8eeb..c81a95c 100644
--- a/cmd/update_references.go
+++ b/cmd/update_references.go
@@ -1,6 +1,8 @@
package cmd
import (
+ "path"
+
"github.com/Masterminds/cookoo"
"github.com/Masterminds/glide/yaml"
)
@@ -16,7 +18,7 @@
func UpdateReferences(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Interrupt) {
cfg := p.Get("conf", &yaml.Config{}).(*yaml.Config)
plist := p.Get("packages", []string{}).([]string)
-
+ vend, _ := VendorPath(c)
pkgs := list2map(plist)
restrict := len(pkgs) > 0
@@ -29,6 +31,28 @@
return cfg, nil
}
+ // Walk the dependency tree to discover all the packages to pin.
+ packages := make([]string, len(cfg.Imports))
+ for i, v := range cfg.Imports {
+ packages[i] = v.Name
+ }
+ deps := make(map[string]*yaml.Dependency, len(cfg.Imports))
+ for _, imp := range cfg.Imports {
+ deps[imp.Name] = imp
+ }
+ f := &flattening{cfg, vend, vend, deps, packages}
+ err = discoverDependencyTree(f)
+ if err != nil {
+ return cfg, err
+ }
+
+ exportFlattenedDeps(cfg, deps)
+
+ err = cfg.DeDupe()
+ if err != nil {
+ return cfg, err
+ }
+
for _, imp := range cfg.Imports {
if restrict && !pkgs[imp.Name] {
Debug("===> Skipping %q", imp.Name)
@@ -44,6 +68,39 @@
return cfg, nil
}
+func discoverDependencyTree(f *flattening) error {
+ Debug("---> Inspecting %s for dependencies (%d packages).\n", f.curr, len(f.scan))
+ for _, imp := range f.scan {
+ Debug("----> Scanning %s", imp)
+ base := path.Join(f.top, imp)
+ mod := []string{}
+ if m, ok := mergeGlide(base, imp, f.deps, f.top); ok {
+ mod = m
+ } else if m, ok = mergeGodep(base, imp, f.deps, f.top); ok {
+ mod = m
+ } else if m, ok = mergeGPM(base, imp, f.deps, f.top); ok {
+ mod = m
+ } else if m, ok = mergeGb(base, imp, f.deps, f.top); ok {
+ mod = m
+ } else if m, ok = mergeGuess(base, imp, f.deps, f.top); ok {
+ mod = m
+ }
+
+ if len(mod) > 0 {
+ Debug("----> Looking for dependencies in %q (%d)", imp, len(mod))
+ f2 := &flattening{
+ conf: f.conf,
+ top: f.top,
+ curr: base,
+ deps: f.deps,
+ scan: mod}
+ discoverDependencyTree(f2)
+ }
+ }
+
+ return nil
+}
+
// list2map takes a list of packages names and creates a map of normalized names.
func list2map(in []string) map[string]bool {
out := make(map[string]bool, len(in))
diff --git a/yaml/yaml.go b/yaml/yaml.go
index d88ac65..5648e22 100644
--- a/yaml/yaml.go
+++ b/yaml/yaml.go
@@ -56,11 +56,7 @@
}
}
- c.Imports, err = c.Imports.DeDupe()
- if err != nil {
- return c, err
- }
- c.DevImports, err = c.DevImports.DeDupe()
+ c.DeDupe()
if err != nil {
return c, err
}
@@ -110,6 +106,43 @@
return false
}
+func (c *Config) DeDupe() error {
+
+ // Remove duplicates in the imports
+ var err error
+ c.Imports, err = c.Imports.DeDupe()
+ if err != nil {
+ return err
+ }
+ c.DevImports, err = c.DevImports.DeDupe()
+ if err != nil {
+ return err
+ }
+
+ // If the name on the config object is part of the imports remove it.
+ found := -1
+ for i, dep := range c.Imports {
+ if dep.Name == c.Name {
+ found = i
+ }
+ }
+ if found >= 0 {
+ c.Imports = append(c.Imports[:found], c.Imports[found+1:]...)
+ }
+
+ found = -1
+ for i, dep := range c.DevImports {
+ if dep.Name == c.Name {
+ found = i
+ }
+ }
+ if found >= 0 {
+ c.Imports = append(c.DevImports[:found], c.DevImports[found+1:]...)
+ }
+
+ return nil
+}
+
// GetRoot follows the Parent down to the top node
func (c *Config) GetRoot() *Config {
if c.Parent != nil {