Skip to content

Commit

Permalink
Updating install to use the cache by default
Browse files Browse the repository at this point in the history
  • Loading branch information
mattfarina committed Aug 11, 2016
1 parent a8dd867 commit 520f6b8
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 65 deletions.
30 changes: 8 additions & 22 deletions action/install.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package action

import (
"fmt"
"path/filepath"

"github.com/Masterminds/glide/cache"
"github.com/Masterminds/glide/cfg"
"github.com/Masterminds/glide/dependency"
"github.com/Masterminds/glide/msg"
gpath "github.com/Masterminds/glide/path"
"github.com/Masterminds/glide/repo"
)

// Install installs a vendor directory based on an existing Glide configuration.
func Install(installer *repo.Installer, strip, stripVendor bool) {
func Install(installer *repo.Installer, stripVendor bool) {
if installer.UseCache {
cache.SystemLock()
}
Expand All @@ -39,6 +39,9 @@ func Install(installer *repo.Installer, strip, stripVendor bool) {
if err != nil {
msg.Die("Could not load lockfile.")
} else if hash != lock.Hash {
fmt.Println(hash, lock.Hash)
foo, _ := conf.Marshal()
fmt.Println(string(foo))
msg.Warn("Lock file may be out of date. Hash check of YAML failed. You may need to run 'update'")
}

Expand All @@ -55,26 +58,9 @@ func Install(installer *repo.Installer, strip, stripVendor bool) {
msg.Err("Failed to set references: %s (Skip to cleanup)", err)
}

// Delete unused packages
if installer.DeleteUnused {
// newConf is calculated based on the lock file so it should be
// accurate to the project list.
dependency.DeleteUnused(newConf)
}

// VendoredCleanup. This should ONLY be run if UpdateVendored was specified.
// When stripping VCS happens this will happen as well. No need for double
// effort.
if installer.UpdateVendored && !strip {
repo.VendoredCleanup(newConf)
}

if strip {
msg.Info("Removing version control data from vendor directory...")
err := gpath.StripVcs()
if err != nil {
msg.Err("Unable to strip version control data: %s", err)
}
err = installer.Export(newConf)
if err != nil {
msg.Die("Unable to export dependencies to vendor directory: %s", err)
}

if stripVendor {
Expand Down
68 changes: 42 additions & 26 deletions glide.go
Original file line number Diff line number Diff line change
Expand Up @@ -441,36 +441,43 @@ Example:
from the lock file.`,
Flags: []cli.Flag{
cli.BoolFlag{
Name: "delete",
Usage: "Delete vendor packages not specified in config.",
Name: "delete",
Usage: "Delete vendor packages not specified in config.",
Hidden: true,
},
cli.BoolFlag{
Name: "force",
Usage: "If there was a change in the repo or VCS switch to new one. Warning: changes will be lost.",
},
cli.BoolFlag{
Name: "update-vendored, u",
Usage: "Update vendored packages (without local VCS repo). Warning: this may destroy local modifications to vendor/.",
Name: "update-vendored, u",
Usage: "Update vendored packages (without local VCS repo). Warning: this may destroy local modifications to vendor/.",
Hidden: true,
},
cli.StringFlag{
Name: "file, f",
Usage: "Save all of the discovered dependencies to a Glide YAML file. (DEPRECATED: This has no impact.)",
Name: "file, f",
Usage: "Save all of the discovered dependencies to a Glide YAML file. (DEPRECATED: This has no impact.)",
Hidden: true,
},
cli.BoolFlag{
Name: "cache",
Usage: "When downloading dependencies attempt to cache them.",
Name: "cache",
Usage: "When downloading dependencies attempt to cache them.",
Hidden: true,
},
cli.BoolFlag{
Name: "cache-gopath",
Usage: "When downloading dependencies attempt to put them in the GOPATH, too.",
Name: "cache-gopath",
Usage: "When downloading dependencies attempt to put them in the GOPATH, too.",
Hidden: true,
},
cli.BoolFlag{
Name: "use-gopath",
Usage: "Copy dependencies from the GOPATH if they exist there.",
Name: "use-gopath",
Usage: "Copy dependencies from the GOPATH if they exist there.",
Hidden: true,
},
cli.BoolFlag{
Name: "strip-vcs, s",
Usage: "Removes version control metadata (e.g, .git directory) from the vendor folder.",
Name: "strip-vcs, s",
Usage: "Removes version control metadata (e.g, .git directory) from the vendor folder.",
Hidden: true,
},
cli.BoolFlag{
Name: "strip-vendor, v",
Expand All @@ -482,21 +489,34 @@ Example:
},
},
Action: func(c *cli.Context) error {
if c.Bool("strip-vendor") && !c.Bool("strip-vcs") {
msg.Die("--strip-vendor cannot be used without --strip-vcs")
if c.Bool("delete") {
msg.Warn("The --delete flag is deprecated. This now works by default.")
}
if c.Bool("update-vendored") {
msg.Warn("The --update-vendored flag is deprecated. This now works by default.")
}
if c.String("file") != "" {
msg.Warn("The --flag flag is deprecated.")
}
if c.Bool("cache") {
msg.Warn("The --cache flag is deprecated. This now works by default.")
}
if c.Bool("cache-gopath") {
msg.Warn("The --cache-gopath flag is deprecated.")
}
if c.Bool("use-gopath") {
msg.Warn("The --use-gopath flag is deprecated. Please see overrides.")
}
if c.Bool("strip-vcs") {
msg.Warn("The --strip-vcs flag is deprecated. This now works by default.")
}

installer := repo.NewInstaller()
installer.Force = c.Bool("force")
installer.UseCache = c.Bool("cache")
installer.UseGopath = c.Bool("use-gopath")
installer.UseCacheGopath = c.Bool("cache-gopath")
installer.UpdateVendored = c.Bool("update-vendored")
installer.Home = c.GlobalString("home")
installer.DeleteUnused = c.Bool("delete")
installer.ResolveTest = !c.Bool("skip-test")

action.Install(installer, c.Bool("strip-vcs"), c.Bool("strip-vendor"))
action.Install(installer, c.Bool("strip-vendor"))
return nil
},
},
Expand Down Expand Up @@ -609,10 +629,6 @@ Example:
msg.Warn("The --strip-vcs flag is deprecated. This now works by default.")
}

if c.Bool("strip-vendor") && !c.Bool("strip-vcs") {
msg.Die("--strip-vendor cannot be used without --strip-vcs")
}

if c.Bool("resolve-current") {
util.ResolveCurrent = true
msg.Warn("Only resolving dependencies for the current OS/Arch")
Expand Down
2 changes: 1 addition & 1 deletion glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 9 additions & 16 deletions repo/installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,6 @@ func (i *Installer) VendorPath() string {
// Install installs the dependencies from a Lockfile.
func (i *Installer) Install(lock *cfg.Lockfile, conf *cfg.Config) (*cfg.Config, error) {

cwd, err := gpath.Vendor()
if err != nil {
return conf, err
}

// Create a config setup based on the Lockfile data to process with
// existing commands.
newConf := &cfg.Config{}
Expand All @@ -111,8 +106,8 @@ func (i *Installer) Install(lock *cfg.Lockfile, conf *cfg.Config) (*cfg.Config,

msg.Info("Downloading dependencies. Please wait...")

LazyConcurrentUpdate(newConf.Imports, cwd, i, newConf)
LazyConcurrentUpdate(newConf.DevImports, cwd, i, newConf)
LazyConcurrentUpdate(newConf.Imports, i, newConf)
LazyConcurrentUpdate(newConf.DevImports, i, newConf)
return newConf, nil
}

Expand All @@ -122,16 +117,14 @@ func (i *Installer) Install(lock *cfg.Lockfile, conf *cfg.Config) (*cfg.Config,
// vendor directory based on changed config.
func (i *Installer) Checkout(conf *cfg.Config) error {

dest := i.VendorPath()

msg.Info("Downloading dependencies. Please wait...")

if err := ConcurrentUpdate(conf.Imports, dest, i, conf); err != nil {
if err := ConcurrentUpdate(conf.Imports, i, conf); err != nil {
return err
}

if i.ResolveTest {
return ConcurrentUpdate(conf.DevImports, dest, i, conf)
return ConcurrentUpdate(conf.DevImports, i, conf)
}

return nil
Expand Down Expand Up @@ -251,13 +244,13 @@ func (i *Installer) Update(conf *cfg.Config) error {

msg.Info("Downloading dependencies. Please wait...")

err = ConcurrentUpdate(conf.Imports, vpath, i, conf)
err = ConcurrentUpdate(conf.Imports, i, conf)
if err != nil {
return err
}

if i.ResolveTest {
err = ConcurrentUpdate(conf.DevImports, vpath, i, conf)
err = ConcurrentUpdate(conf.DevImports, i, conf)
if err != nil {
return err
}
Expand Down Expand Up @@ -390,7 +383,7 @@ func (i *Installer) List(conf *cfg.Config) []*cfg.Dependency {
// LazyConcurrentUpdate updates only deps that are not already checkout out at the right version.
//
// This is only safe when updating from a lock file.
func LazyConcurrentUpdate(deps []*cfg.Dependency, cwd string, i *Installer, c *cfg.Config) error {
func LazyConcurrentUpdate(deps []*cfg.Dependency, i *Installer, c *cfg.Config) error {

newDeps := []*cfg.Dependency{}
for _, dep := range deps {
Expand Down Expand Up @@ -418,14 +411,14 @@ func LazyConcurrentUpdate(deps []*cfg.Dependency, cwd string, i *Installer, c *c
newDeps = append(newDeps, dep)
}
if len(newDeps) > 0 {
return ConcurrentUpdate(newDeps, cwd, i, c)
return ConcurrentUpdate(newDeps, i, c)
}

return nil
}

// ConcurrentUpdate takes a list of dependencies and updates in parallel.
func ConcurrentUpdate(deps []*cfg.Dependency, cwd string, i *Installer, c *cfg.Config) error {
func ConcurrentUpdate(deps []*cfg.Dependency, i *Installer, c *cfg.Config) error {
done := make(chan struct{}, concurrentWorkers)
in := make(chan *cfg.Dependency, concurrentWorkers)
var wg sync.WaitGroup
Expand Down

0 comments on commit 520f6b8

Please sign in to comment.