Adding ingore list to glide.yaml to ignore packages
diff --git a/cfg/config.go b/cfg/config.go
index 0daa26f..63c3676 100644
--- a/cfg/config.go
+++ b/cfg/config.go
@@ -14,6 +14,7 @@
// Config is the top-level configuration object.
type Config struct {
Name string `yaml:"package"`
+ Ignore []string `yaml:"ignore,omitempty"`
Imports Dependencies `yaml:"import"`
DevImports Dependencies `yaml:"devimport,omitempty"`
}
@@ -21,6 +22,7 @@
// A transitive representation of a dependency for importing and exploting to yaml.
type cf struct {
Name string `yaml:"package"`
+ Ignore []string `yaml:"ignore,omitempty"`
Imports Dependencies `yaml:"import"`
DevImports Dependencies `yaml:"devimport,omitempty"`
}
@@ -48,6 +50,7 @@
return err
}
c.Name = newConfig.Name
+ c.Ignore = newConfig.Ignore
c.Imports = newConfig.Imports
c.DevImports = newConfig.DevImports
@@ -60,7 +63,8 @@
// MarshalYAML is a hook for gopkg.in/yaml.v2 in the marshaling process
func (c *Config) MarshalYAML() (interface{}, error) {
newConfig := &cf{
- Name: c.Name,
+ Name: c.Name,
+ Ignore: c.Ignore,
}
i, err := c.Imports.Clone().DeDupe()
if err != nil {
@@ -93,10 +97,22 @@
return false
}
+// HasIgnore returns true if the given name is listed on the ignore list.
+func (c *Config) HasIgnore(name string) bool {
+ for _, v := range c.Ignore {
+ if v == name {
+ return true
+ }
+ }
+
+ return false
+}
+
// Clone performs a deep clone of the Config instance
func (c *Config) Clone() *Config {
n := &Config{}
n.Name = c.Name
+ n.Ignore = c.Ignore
n.Imports = c.Imports.Clone()
n.DevImports = c.DevImports.Clone()
return n
@@ -134,7 +150,30 @@
}
}
if found >= 0 {
- c.Imports = append(c.DevImports[:found], c.DevImports[found+1:]...)
+ c.DevImports = append(c.DevImports[:found], c.DevImports[found+1:]...)
+ }
+
+ // If something is on the ignore list remove it from the imports.
+ for _, v := range c.Ignore {
+ found = -1
+ for k, d := range c.Imports {
+ if v == d.Name {
+ found = k
+ }
+ }
+ if found >= 0 {
+ c.Imports = append(c.Imports[:found], c.Imports[found+1:]...)
+ }
+
+ found = -1
+ for k, d := range c.DevImports {
+ if v == d.Name {
+ found = k
+ }
+ }
+ if found >= 0 {
+ c.DevImports = append(c.DevImports[:found], c.DevImports[found+1:]...)
+ }
}
return nil
diff --git a/cmd/flatten.go b/cmd/flatten.go
index bb0f055..1bf9adc 100644
--- a/cmd/flatten.go
+++ b/cmd/flatten.go
@@ -115,15 +115,15 @@
Debug("----> Scanning %s", imp)
base := path.Join(f.top, imp)
mod := []string{}
- if m, ok := mergeGlide(base, imp, f.deps, f.top); ok {
+ if m, ok := mergeGlide(base, imp, f); ok {
mod = m
- } else if m, ok = mergeGodep(base, imp, f.deps, f.top); ok {
+ } else if m, ok = mergeGodep(base, imp, f); ok {
mod = m
- } else if m, ok = mergeGPM(base, imp, f.deps, f.top); ok {
+ } else if m, ok = mergeGPM(base, imp, f); ok {
mod = m
- } else if m, ok = mergeGb(base, imp, f.deps, f.top); ok {
+ } else if m, ok = mergeGb(base, imp, f); ok {
mod = m
- } else if m, ok = mergeGuess(base, imp, f.deps, f.top, scanned); ok {
+ } else if m, ok = mergeGuess(base, imp, f, scanned); ok {
mod = m
}
@@ -197,7 +197,9 @@
}
}
-func mergeGlide(dir, name string, deps map[string]*cfg.Dependency, vend string) ([]string, bool) {
+func mergeGlide(dir, name string, f *flattening) ([]string, bool) {
+ deps := f.deps
+ vend := f.top
gp := path.Join(dir, "glide.yaml")
if _, err := os.Stat(gp); err != nil {
return []string{}, false
@@ -217,14 +219,16 @@
Info("Found glide.yaml in %s", gp)
- return mergeDeps(deps, conf.Imports, vend), true
+ return mergeDeps(deps, conf.Imports, vend, f), true
}
// listGodep appends Godeps entries to the deps.
//
// It returns true if any dependencies were found (even if not added because
// they are duplicates).
-func mergeGodep(dir, name string, deps map[string]*cfg.Dependency, vend string) ([]string, bool) {
+func mergeGodep(dir, name string, f *flattening) ([]string, bool) {
+ deps := f.deps
+ vend := f.top
Debug("Looking in %s/Godeps/ for a Godeps.json file.\n", dir)
d, err := parseGodepGodeps(dir)
if err != nil {
@@ -235,28 +239,32 @@
}
Info("Found Godeps.json file for %q", name)
- return mergeDeps(deps, d, vend), true
+ return mergeDeps(deps, d, vend, f), true
}
// listGb merges GB dependencies into the deps.
-func mergeGb(dir, pkg string, deps map[string]*cfg.Dependency, vend string) ([]string, bool) {
+func mergeGb(dir, pkg string, f *flattening) ([]string, bool) {
+ deps := f.deps
+ vend := f.top
Debug("Looking in %s/vendor/ for a manifest file.\n", dir)
d, err := parseGbManifest(dir)
if err != nil || len(d) == 0 {
return []string{}, false
}
Info("Found gb manifest file for %q", pkg)
- return mergeDeps(deps, d, vend), true
+ return mergeDeps(deps, d, vend, f), true
}
// mergeGPM merges GPM Godeps files into deps.
-func mergeGPM(dir, pkg string, deps map[string]*cfg.Dependency, vend string) ([]string, bool) {
+func mergeGPM(dir, pkg string, f *flattening) ([]string, bool) {
+ deps := f.deps
+ vend := f.top
d, err := parseGPMGodeps(dir)
if err != nil || len(d) == 0 {
return []string{}, false
}
Info("Found GPM file for %q", pkg)
- return mergeDeps(deps, d, vend), true
+ return mergeDeps(deps, d, vend, f), true
}
// mergeGuess guesses dependencies and merges.
@@ -264,7 +272,8 @@
// This always returns true because it always handles the job of searching
// for dependencies. So generally it should be the last merge strategy
// that you try.
-func mergeGuess(dir, pkg string, deps map[string]*cfg.Dependency, vend string, scanned map[string]bool) ([]string, bool) {
+func mergeGuess(dir, pkg string, f *flattening, scanned map[string]bool) ([]string, bool) {
+ deps := f.deps
Info("Scanning %s for dependencies.", pkg)
buildContext, err := GetBuildContext()
if err != nil {
@@ -292,6 +301,10 @@
//Debug("====> Seen %s already. Skipping", name)
//continue
//}
+ if f.conf.HasIgnore(name) {
+ Debug("==> Skipping %s because it is on the ignore list", name)
+ continue
+ }
found := findPkg(buildContext, name, dir)
switch found.PType {
@@ -326,11 +339,13 @@
}
// mergeDeps merges any dependency array into deps.
-func mergeDeps(orig map[string]*cfg.Dependency, add []*cfg.Dependency, vend string) []string {
+func mergeDeps(orig map[string]*cfg.Dependency, add []*cfg.Dependency, vend string, f *flattening) []string {
mod := []string{}
for _, dd := range add {
- // Add it unless it's already there.
- if existing, ok := orig[dd.Name]; !ok {
+ if f.conf.HasIgnore(dd.Name) {
+ Debug("Skipping %s because it is on the ignore list", dd.Name)
+ } else if existing, ok := orig[dd.Name]; !ok {
+ // Add it unless it's already there.
orig[dd.Name] = dd
Debug("Adding %s to the scan list", dd.Name)
mod = append(mod, dd.Name)
diff --git a/cmd/get_imports.go b/cmd/get_imports.go
index ff0d810..ab103eb 100644
--- a/cmd/get_imports.go
+++ b/cmd/get_imports.go
@@ -72,6 +72,11 @@
continue
}
+ if conf.HasIgnore(root) {
+ Warn("Package %q is set to be ignored in glide.yaml. Skipping", root)
+ continue
+ }
+
dest := path.Join(cwd, root)
if err != nil {
@@ -803,6 +808,16 @@
return ""
}
+// 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))
+ for _, v := range in {
+ v, _ := NormalizeName(v)
+ out[v] = true
+ }
+ return out
+}
+
func envForDir(dir string) []string {
env := os.Environ()
return mergeEnvLists([]string{"PWD=" + dir}, env)
diff --git a/cmd/update_references.go b/cmd/update_references.go
deleted file mode 100644
index 92fe235..0000000
--- a/cmd/update_references.go
+++ /dev/null
@@ -1,113 +0,0 @@
-package cmd
-
-import (
- "path"
-
- "github.com/Masterminds/cookoo"
- "github.com/Masterminds/glide/cfg"
-)
-
-// UpdateReferences updates the revision numbers on all of the imports.
-//
-// If a `packages` list is supplied, only the given base packages will
-// be updated.
-//
-// Params:
-// - conf (*cfg.Config): Configuration
-// - packages ([]string): A list of packages to update. Default is all packages.
-func UpdateReferences(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Interrupt) {
- conf := p.Get("conf", &cfg.Config{}).(*cfg.Config)
- plist := p.Get("packages", []string{}).([]string)
- vend, _ := VendorPath(c)
- pkgs := list2map(plist)
- restrict := len(pkgs) > 0
-
- cwd, err := VendorPath(c)
- if err != nil {
- return false, err
- }
-
- if len(conf.Imports) == 0 {
- return conf, nil
- }
-
- // Walk the dependency tree to discover all the packages to pin.
- packages := make([]string, len(conf.Imports))
- for i, v := range conf.Imports {
- packages[i] = v.Name
- }
- deps := make(map[string]*cfg.Dependency, len(conf.Imports))
- for _, imp := range conf.Imports {
- deps[imp.Name] = imp
- }
- f := &flattening{conf, vend, vend, deps, packages}
- err = discoverDependencyTree(f)
- if err != nil {
- return conf, err
- }
-
- exportFlattenedDeps(conf, deps)
-
- err = conf.DeDupe()
- if err != nil {
- return conf, err
- }
-
- for _, imp := range conf.Imports {
- if restrict && !pkgs[imp.Name] {
- Debug("===> Skipping %q", imp.Name)
- continue
- }
- commit, err := VcsLastCommit(imp, cwd)
- if err != nil {
- Warn("Could not get commit on %s: %s", imp.Name, err)
- }
- imp.Reference = commit
- }
-
- return conf, nil
-}
-
-func discoverDependencyTree(f *flattening) error {
- Debug("---> Inspecting %s for dependencies (%d packages).\n", f.curr, len(f.scan))
- scanned := map[string]bool{}
- 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, scanned); 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))
- for _, v := range in {
- v, _ := NormalizeName(v)
- out[v] = true
- }
- return out
-}