Recursive glide for 'get' and 'up'.
diff --git a/cmd/recursive_glide.go b/cmd/recursive_glide.go index 1ddd457..26d4f4a 100644 --- a/cmd/recursive_glide.go +++ b/cmd/recursive_glide.go
@@ -5,6 +5,7 @@ "path" "github.com/Masterminds/cookoo" + "github.com/kylelemons/go-gypsy/yaml" ) // Recurse does glide installs on dependent packages. @@ -22,11 +23,13 @@ // Look in each package to see whether it has a glide.yaml, and no vendor/ for _, imp := range conf.Imports { Info("Looking in %s for a glide.yaml file.\n", imp.Name) - if needsGlideUp(path.Join(vend, imp.Name)) { - Info("Package %s needs `glide up`\n", imp.Name) - // How do we want to do this? Should we run the glide command, - // which would allow environmental control, or should we just - // run the update route in that directory? + base := path.Join(vend, imp.Name) + if !needsGlideUp(base) { + Info("Package %s manages its own dependencies.\n", imp.Name) + } + Info("Package %s needs `glide up`\n", imp.Name) + if err := dependencyGlideUp(base); err != nil { + Warn("Failed to update dependency %s: %s", imp.Name, err) } } @@ -34,6 +37,46 @@ return nil, nil } +func dependencyGlideUp(base string) error { + //conf := new(Config) + fname := path.Join(base, "glide.yaml") + f, err := yaml.ReadFile(fname) + if err != nil { + return err + } + + conf, err := FromYaml(f.Root) + if err != nil { + return err + } + for _, imp := range conf.Imports { + Info("Importing %s to project %s\n", imp.Name, base) + // We don't use the global var to find vendor dir name because the + // user may mis-use that var to modify the local vendor dir, and + // we don't want that to break the embedded vendor dirs. + wd := path.Join(base, "vendor", imp.Name) + if err := ensureDir(wd); err != nil { + Warn("Skipped getting %s (vendor/ error): %s\n", imp.Name, err) + continue + } + + // How do we want to do this? Should we run the glide command, + // which would allow environmental control, or should we just + // run the update route in that directory? + if err := VcsGet(imp, wd); err != nil { + Warn("Skipped getting %s: %s\n", imp.Name, err) + } + } + return nil +} + +func ensureDir(dirpath string) error { + if fi, err := os.Stat(dirpath); err == nil && fi.IsDir() { + return nil + } + return os.MkdirAll(dirpath, 0755) +} + func needsGlideUp(dir string) bool { stat, err := os.Stat(path.Join(dir, "glide.yaml")) if err != nil || stat.IsDir() {
diff --git a/glide.go b/glide.go index 535fa03..b5b43fe 100644 --- a/glide.go +++ b/glide.go
@@ -293,6 +293,7 @@ Using("package").From("cxt:package"). Using("conf").From("cxt:cfg"). Does(cmd.MergeToYaml, "merged").Using("conf").From("cxt:cfg"). + Does(cmd.Recurse, "recurse").Using("conf").From("cxt:cfg"). Does(cmd.WriteYaml, "out"). Using("yaml.Node").From("cxt:merged"). Using("filename").WithDefault("glide.yaml").From("cxt:yaml")