Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor installer / vcs creation & configuration #380

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions action/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ func Get(names []string, installer *repo.Installer, insecure, skipRecursive, str
base := gpath.Basepath()
EnsureGopath()
EnsureVendorDir()
conf := EnsureConfig()

glidefile, err := gpath.Glide()
if err != nil {
msg.Die("Could not find Glide file: %s", err)
}

// Add the packages to the config.
if count, err := addPkgsToConfig(conf, names, insecure); err != nil {
if count, err := addPkgsToConfig(installer.Config, names, insecure); err != nil {
msg.Die("Failed to get new packages: %s", err)
} else if count == 0 {
msg.Warn("Nothing to do")
Expand All @@ -37,14 +37,15 @@ func Get(names []string, installer *repo.Installer, insecure, skipRecursive, str
// Fetch the new packages. Can't resolve versions via installer.Update if
// get is called while the vendor/ directory is empty so we checkout
// everything.
err = installer.Checkout(conf, false)
err = installer.Checkout(false)
if err != nil {
msg.Die("Failed to checkout packages: %s", err)
}

// Prior to resolving dependencies we need to start working with a clone
// of the conf because we'll be making real changes to it.
confcopy := conf.Clone()
conforig := installer.Config
installer.Config = installer.Config.Clone()

if !skipRecursive {
// Get all repos and update them.
Expand All @@ -55,38 +56,40 @@ func Get(names []string, installer *repo.Installer, insecure, skipRecursive, str
// to be between 1.0 and 2.0. But changing that dependency may then result
// in that dependency's dependencies changing... so we sorta do the whole
// thing to be safe.
err = installer.Update(confcopy)
err = installer.Update()
if err != nil {
msg.Die("Could not update packages: %s", err)
}
}

// Set Reference
if err := repo.SetReference(confcopy); err != nil {
if err := installer.SetReferences(); err != nil {
msg.Err("Failed to set references: %s", err)
}

// VendoredCleanup
// When stripping VCS happens this will happen as well. No need for double
// effort.
if installer.UpdateVendored && !strip {
repo.VendoredCleanup(confcopy)
repo.VendoredCleanup(installer.Config)
}

// Write YAML
if err := conf.WriteFile(glidefile); err != nil {
if err := installer.Config.WriteFile(glidefile); err != nil {
msg.Die("Failed to write glide YAML file: %s", err)
}
if !skipRecursive {
// Write lock
if stripVendor {
confcopy = godep.RemoveGodepSubpackages(confcopy)
installer.Config = godep.RemoveGodepSubpackages(installer.Config)
}
writeLock(conf, confcopy, base)
writeLock(conforig, installer.Config, base)
} else {
msg.Warn("Skipping lockfile generation because full dependency tree is not being calculated")
}

installer.Config = conforig

if strip {
msg.Info("Removing version control data from vendor directory...")
gpath.StripVcs()
Expand Down
6 changes: 3 additions & 3 deletions action/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func Install(installer *repo.Installer, strip, stripVendor bool) {
return
}
// Load lockfile
lock, err := LoadLockfile(base, conf)
lock, err := LoadLockfile(base, installer.Config)
if err != nil {
msg.Die("Could not load lockfile.")
}
Expand All @@ -40,15 +40,15 @@ func Install(installer *repo.Installer, strip, stripVendor bool) {
}

// Install
newConf, err := installer.Install(lock, conf)
newConf, err := installer.Install(lock)
if err != nil {
msg.Die("Failed to install: %s", err)
}

msg.Info("Setting references.")

// Set reference
if err := repo.SetReference(newConf); err != nil {
if err := installer.SetReferences(); err != nil {
msg.Err("Failed to set references: %s (Skip to cleanup)", err)
}

Expand Down
20 changes: 11 additions & 9 deletions action/remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,38 +12,40 @@ func Remove(packages []string, inst *repo.Installer) {
base := gpath.Basepath()
EnsureGopath()
EnsureVendorDir()
conf := EnsureConfig()
glidefile, err := gpath.Glide()

if err != nil {
msg.Die("Could not find Glide file: %s", err)
}

msg.Info("Preparing to remove %d packages.", len(packages))
conf.Imports = rmDeps(packages, conf.Imports)
conf.DevImports = rmDeps(packages, conf.DevImports)
inst.Config.Imports = rmDeps(packages, inst.Config.Imports)
inst.Config.DevImports = rmDeps(packages, inst.Config.DevImports)

// Copy used to generate locks.
confcopy := conf.Clone()
conforig := inst.Config
inst.Config = inst.Config.Clone()

confcopy.Imports = inst.List(confcopy)
inst.Config.Imports = inst.List()

if err := repo.SetReference(confcopy); err != nil {
if err := inst.SetReferences(); err != nil {
msg.Err("Failed to set references: %s", err)
}

// TODO: Right now, there is no flag to enable this, so this will never be
// run. I am not sure whether we should allow this in a rm op or not.
if inst.UpdateVendored {
repo.VendoredCleanup(confcopy)
repo.VendoredCleanup(inst.Config)
}

// Write glide.yaml
if err := conf.WriteFile(glidefile); err != nil {
if err := inst.Config.WriteFile(glidefile); err != nil {
msg.Die("Failed to write glide YAML file: %s", err)
}

// Write glide lock
writeLock(conf, confcopy, base)
writeLock(conforig, inst.Config, base)
inst.Config = conforig
}

// rmDeps returns a list of dependencies that do not contain the given pkgs.
Expand Down
26 changes: 14 additions & 12 deletions action/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,31 @@ func Update(installer *repo.Installer, skipRecursive, strip, stripVendor bool) {
base := "."
EnsureGopath()
EnsureVendorDir()
conf := EnsureConfig()

// Delete unused packages
if installer.DeleteUnused {
dependency.DeleteUnused(conf)
dependency.DeleteUnused(installer.Config)
}

// Try to check out the initial dependencies.
if err := installer.Checkout(conf, false); err != nil {
if err := installer.Checkout(false); err != nil {
msg.Die("Failed to do initial checkout of config: %s", err)
}

// Set the versions for the initial dependencies so that resolved dependencies
// are rooted in the correct version of the base.
if err := repo.SetReference(conf); err != nil {
if err := installer.SetReferences(); err != nil {
msg.Die("Failed to set initial config references: %s", err)
}

// Prior to resolving dependencies we need to start working with a clone
// of the conf because we'll be making real changes to it.
confcopy := conf.Clone()
conforig := installer.Config
installer.Config = installer.Config.Clone()

if !skipRecursive {
// Get all repos and update them.
err := installer.Update(confcopy)
err := installer.Update()
if err != nil {
msg.Die("Could not update packages: %s", err)
}
Expand All @@ -53,7 +53,7 @@ func Update(installer *repo.Installer, skipRecursive, strip, stripVendor bool) {
// installer set them as it went to make sure it parsed the right imports
// from the right version of the package.
msg.Info("Setting references for remaining imports")
if err := repo.SetReference(confcopy); err != nil {
if err := installer.SetReferences(); err != nil {
msg.Err("Failed to set references: %s (Skip to cleanup)", err)
}
}
Expand All @@ -62,7 +62,7 @@ func Update(installer *repo.Installer, skipRecursive, strip, stripVendor bool) {
// When stripping VCS happens this will happen as well. No need for double
// effort.
if installer.UpdateVendored && !strip {
repo.VendoredCleanup(confcopy)
repo.VendoredCleanup(installer.Config)
}

// Write glide.yaml (Why? Godeps/GPM/GB?)
Expand All @@ -75,26 +75,28 @@ func Update(installer *repo.Installer, skipRecursive, strip, stripVendor bool) {
// should be added to the glide.yaml file. See issue #193.

if stripVendor {
confcopy = godep.RemoveGodepSubpackages(confcopy)
installer.Config = godep.RemoveGodepSubpackages(installer.Config)
}

if !skipRecursive {
// Write lock
hash, err := conf.Hash()
hash, err := conforig.Hash()
if err != nil {
msg.Die("Failed to generate config hash. Unable to generate lock file.")
}
lock := cfg.NewLockfile(confcopy.Imports, hash)
lock := cfg.NewLockfile(installer.Config.Imports, hash)
if err := lock.WriteFile(filepath.Join(base, gpath.LockFile)); err != nil {
msg.Err("Could not write lock file to %s: %s", base, err)
return
}

msg.Info("Project relies on %d dependencies.", len(confcopy.Imports))
msg.Info("Project relies on %d dependencies.", len(installer.Config.Imports))
} else {
msg.Warn("Skipping lockfile generation because full dependency tree is not being calculated")
}

installer.Config = conforig

if strip {
msg.Info("Removing version control data from vendor directory...")
gpath.StripVcs()
Expand Down
61 changes: 35 additions & 26 deletions glide.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,13 +242,16 @@ func commands() []cli.Command {
msg.Warn("Only resolving dependencies for the current OS/Arch")
}

inst := repo.NewInstaller()
inst.Force = c.Bool("force")
inst.UseCache = c.Bool("cache")
inst.UseGopath = c.Bool("use-gopath")
inst.UseCacheGopath = c.Bool("cache-gopath")
inst.UpdateVendored = c.Bool("update-vendored")
inst.ResolveAllFiles = c.Bool("all-dependencies")
inst := repo.NewInstaller(repo.InstallerOptions{
Config: action.EnsureConfig(),
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")
action.Get(packages, inst, insecure, c.Bool("no-recursive"), c.Bool("strip-vcs"), c.Bool("strip-vendor"))
Expand Down Expand Up @@ -280,8 +283,10 @@ func commands() []cli.Command {
// FIXME: Implement this in the installer.
fmt.Println("Delete is not currently implemented.")
}
inst := repo.NewInstaller()
inst.Force = c.Bool("force")
inst := repo.NewInstaller(repo.InstallerOptions{
Config: action.EnsureConfig(),
Force: c.Bool("force"),
})
packages := []string(c.Args())
action.Remove(packages, inst)
},
Expand Down Expand Up @@ -438,14 +443,16 @@ Example:
msg.Die("--strip-vendor cannot be used without --strip-vcs")
}

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 = gpath.Home()
installer.DeleteUnused = c.Bool("deleteOptIn")
installer := repo.NewInstaller(repo.InstallerOptions{
Config: action.EnsureConfig(),
Force: c.Bool("force"),
UseCache: c.Bool("cache"),
UseGopath: c.Bool("use-gopath"),
UseCacheGopath: c.Bool("cache-gopath"),
UpdateVendored: c.Bool("update-vendored"),
Home: gpath.Home(),
DeleteUnused: c.Bool("deleteOptIn"),
})

action.Install(installer, c.Bool("strip-vcs"), c.Bool("strip-vendor"))
},
Expand Down Expand Up @@ -550,15 +557,17 @@ Example:
msg.Warn("Only resolving dependencies for the current OS/Arch")
}

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.ResolveAllFiles = c.Bool("all-dependencies")
installer.Home = gpath.Home()
installer.DeleteUnused = c.Bool("deleteOptIn")
installer := repo.NewInstaller(repo.InstallerOptions{
Config: action.EnsureConfig(),
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"),
Home: gpath.Home(),
DeleteUnused: c.Bool("deleteOptIn"),
})

action.Update(installer, c.Bool("no-recursive"), c.Bool("strip-vcs"), c.Bool("strip-vendor"))
},
Expand Down
Loading