Add toggle to switch to full resolver, improved output.
diff --git a/dependency/resolver.go b/dependency/resolver.go index 9e279c2..77f1c9a 100644 --- a/dependency/resolver.go +++ b/dependency/resolver.go
@@ -116,15 +116,21 @@ type Resolver struct { Handler MissingPackageHandler VersionHandler VersionHandler - basedir string VendorDir string BuildContext *util.BuildCtxt - seen map[string]bool Config *cfg.Config + // ResolveAllFiles toggles deep scanning. + // If this is true, resolve by scanning all files, not by walking the + // import tree. + ResolveAllFiles bool + // Items already in the queue. alreadyQ map[string]bool + basedir string + seen map[string]bool + // findCache caches hits from Find. This reduces the number of filesystem // touches that have to be done for dependency resolution. findCache map[string]*PkgInfo @@ -186,7 +192,11 @@ //msg.Debug("Scanning %s", target) l := list.New() l.PushBack(target) - //return r.resolveList(l) + + // In this mode, walk the entire tree. + if r.ResolveAllFiles { + return r.resolveList(l) + } return r.resolveImports(l) } @@ -253,7 +263,9 @@ } if deep { - //return r.resolveList(l) + if r.ResolveAllFiles { + return r.resolveList(l) + } return r.resolveImports(l) } @@ -290,7 +302,9 @@ queue.PushBack(l) } - //return r.resolveList(queue) + if r.ResolveAllFiles { + return r.resolveList(queue) + } return r.resolveImports(queue) } @@ -330,9 +344,6 @@ } r.VersionHandler.Process(dep) - // FIXME: mattfarina, where do we need to put the VersionHandler.SetVersion - // call in this particular pattern? - // Here, we want to import the package and see what imports it has. msg.Debug("Trying to open %s", vdep) pkg, err := r.BuildContext.ImportDir(vdep, 0) @@ -343,11 +354,6 @@ continue } if ok, err := r.Handler.NotFound(dep); ok { - //if _, ok := r.alreadyQ[dep]; ok { - //// This was already processed, possibly by another - //// concurrent iteration. - //continue - //} r.alreadyQ[dep] = true queue.PushBack(r.vpath(dep)) } else if err != nil { @@ -369,7 +375,7 @@ } switch pi.Loc { case LocVendor: - msg.Info("In vendor: %s", imp) + msg.Debug("In vendor: %s", imp) if _, ok := r.alreadyQ[imp]; !ok { msg.Debug("Marking %s to be scanned.", imp) r.alreadyQ[imp] = true @@ -426,7 +432,6 @@ r.Config.Imports = append(r.Config.Imports, newDep) } - //res = append(res, e.Value.(string)) res = append(res, t) } @@ -434,6 +439,10 @@ } // resolveList takes a list and resolves it. +// +// This walks the entire file tree for the given dependencies, not just the +// parts that are imported directly. Using this will discover dependencies +// regardless of OS, and arch. func (r *Resolver) resolveList(queue *list.List) ([]string, error) { var failedDep string
diff --git a/glide.go b/glide.go index e7900a8..ade25c9 100644 --- a/glide.go +++ b/glide.go
@@ -171,6 +171,10 @@ Usage: "If there was a change in the repo or VCS switch to new one. Warning, changes will be lost.", }, cli.BoolFlag{ + Name: "all-dependencies", + Usage: "This will resolve all dependencies for all packages, not just those directly used.", + }, + cli.BoolFlag{ Name: "update-vendored, u", Usage: "Update vendored packages (without local VCS repo). Warning, changes will be lost.", }, @@ -194,11 +198,12 @@ } inst := &repo.Installer{ - Force: c.Bool("force"), - UseCache: c.Bool("cache"), - UseGopath: c.Bool("use-gopath"), - UseCacheGopath: c.Bool("cache-gopath"), - UpdateVendored: c.Bool("update-vendored"), + Force: c.Bool("force"), + UseCache: c.Bool("cache"), + UseGopath: c.Bool("use-gopath"), + UseCacheGopath: c.Bool("cache-gopath"), + UpdateVendored: c.Bool("update-vendored"), + ResolveAllFiles: c.Bool("all-dependencies"), } packages := []string(c.Args()) insecure := c.Bool("insecure") @@ -425,6 +430,10 @@ Usage: "If there was a change in the repo or VCS switch to new one. Warning, changes will be lost.", }, cli.BoolFlag{ + Name: "all-dependencies", + Usage: "This will resolve all dependencies for all packages, not just those directly used.", + }, + cli.BoolFlag{ Name: "update-vendored, u", Usage: "Update vendored packages (without local VCS repo). Warning, changes will be lost.", }, @@ -447,13 +456,14 @@ }, Action: func(c *cli.Context) { installer := &repo.Installer{ - DeleteUnused: c.Bool("deleteOptIn"), - UpdateVendored: c.Bool("update-vendored"), - Force: c.Bool("force"), - UseCache: c.Bool("cache"), - UseCacheGopath: c.Bool("cache-gopath"), - UseGopath: c.Bool("use-gopath"), - Home: gpath.Home(), + DeleteUnused: c.Bool("deleteOptIn"), + UpdateVendored: c.Bool("update-vendored"), + ResolveAllFiles: c.Bool("all-dependencies"), + Force: c.Bool("force"), + UseCache: c.Bool("cache"), + UseCacheGopath: c.Bool("cache-gopath"), + UseGopath: c.Bool("use-gopath"), + Home: gpath.Home(), } action.Update(installer, c.Bool("no-recursive")) @@ -474,7 +484,7 @@ }, { Name: "list", - Usage: "List prints all dependencies that Glide could discover.", + Usage: "List prints all dependencies that the present code references.", Description: `List scans your code and lists all of the packages that are used. It does not use the glide.yaml. Instead, it inspects the code to determine what packages are
diff --git a/repo/installer.go b/repo/installer.go index 29f67f3..3401108 100644 --- a/repo/installer.go +++ b/repo/installer.go
@@ -47,6 +47,11 @@ // imported pacakgage references this pacakage it does not need to be // downloaded and searched out again. RootPackage string + + // ResolveAllFiles enables a resolver that will examine the dependencies + // of every file of every package, rather than only following imported + // packages. + ResolveAllFiles bool } // VendorPath returns the path to the location to put vendor packages @@ -173,13 +178,16 @@ res.Config = conf res.Handler = m res.VersionHandler = v + res.ResolveAllFiles = i.ResolveAllFiles msg.Info("Resolving imports") _, err = allPackages(conf.Imports, res) if err != nil { msg.Die("Failed to retrieve a list of dependencies: %s", err) } - msg.Warn("devImports not resolved.") + if len(conf.DevImports) > 0 { + msg.Warn("dev imports not resolved.") + } err = ConcurrentUpdate(conf.Imports, vpath, i) @@ -207,6 +215,7 @@ } res.Config = conf res.VersionHandler = v + res.ResolveAllFiles = i.ResolveAllFiles msg.Info("Resolving imports") _, err = allPackages(conf.Imports, res) @@ -214,7 +223,9 @@ msg.Die("Failed to retrieve a list of dependencies: %s", err) } - msg.Warn("devImports not resolved.") + if len(conf.DevImports) > 0 { + msg.Warn("dev imports not resolved.") + } return conf.Imports } @@ -257,6 +268,7 @@ in <- dep } + msg.Info("Downloading dependencies. Please wait...") wg.Wait() // Close goroutines setting the version @@ -320,7 +332,7 @@ return true, nil } - msg.Info("Fetching %s into %s", pkg, m.destination) + msg.Info("- Fetching %s into %s", pkg, m.destination) d := m.Config.Imports.Get(root) // If the dependency is nil it means the Config doesn't yet know about it.
diff --git a/repo/vcs.go b/repo/vcs.go index d463b22..d2a5d5d 100644 --- a/repo/vcs.go +++ b/repo/vcs.go
@@ -30,7 +30,7 @@ return nil } - msg.Info("Fetching updates for %s.\n", dep.Name) + msg.Info("- Fetching updates for %s.\n", dep.Name) if filterArchOs(dep) { msg.Info("%s is not used for %s/%s.\n", dep.Name, runtime.GOOS, runtime.GOARCH)