// LoadLockfile loads the contents of a glide.lock file. // // TODO: This should go in another package. func LoadLockfile(base string, conf *cfg.Config) (*cfg.Lockfile, error) { yml, err := ioutil.ReadFile(filepath.Join(base, gpath.LockFile)) if err != nil { return nil, err } lock, err := cfg.LockfileFromYaml(yml) if err != nil { return nil, err } hash, err := conf.Hash() if err != nil { return nil, err } if hash != lock.Hash { msg.Warn("Lock file may be out of date. Hash check of YAML failed. You may need to run 'update'") } return lock, nil }
func main() { yml, err := ioutil.ReadFile("glide.lock") if err != nil && os.IsNotExist(err) { fmt.Println("glide.lock file not found. Please run glide up to generate it.") os.Exit(1) } if err != nil { fmt.Println(err) os.Exit(2) } l, err := cfg.LockfileFromYaml(yml) if err != nil { fmt.Println("Unable to parse glide.lock file.") os.Exit(1) } for _, d := range l.Imports { dir := filepath.Join("vendor", filepath.FromSlash(d.Name)) t, err := vcs.DetectVcsFromFS(dir) if err != nil { fmt.Println(err) continue } p := filepath.Join(dir, "."+string(t)) if _, err = os.Stat(p); os.IsNotExist(err) { fmt.Println("VCS data not present for", d.Name) continue } fmt.Println("Removing VCS data for", d.Name) err = os.RemoveAll(p) if err != nil { fmt.Println(err) } } }
// LoadLockFile loads the lock file to the context and checks if it is correct // for the loaded cfg file. func LoadLockFile(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Interrupt) { fname := p.Get("filename", "glide.lock").(string) conf := p.Get("conf", nil).(*cfg.Config) yml, err := ioutil.ReadFile(fname) if err != nil { return nil, err } lock, err := cfg.LockfileFromYaml(yml) if err != nil { return nil, err } hash, err := conf.Hash() if err != nil { return nil, err } if hash != lock.Hash { Warn("Lock file may be out of date. Hash check of YAML failed. You may need to run 'update'") } return lock, nil }
// Update updates repos and the lock file from the main glide yaml. func Update(installer *repo.Installer, skipRecursive, strip, stripVendor bool) { if installer.UseCache { cache.SystemLock() } base := "." EnsureGopath() EnsureVendorDir() conf := EnsureConfig() // Delete unused packages if installer.DeleteUnused { dependency.DeleteUnused(conf) } // Try to check out the initial dependencies. if err := installer.Checkout(conf, 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 { 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() if !skipRecursive { // Get all repos and update them. err := installer.Update(confcopy) if err != nil { msg.Die("Could not update packages: %s", err) } // TODO: There is no support here for importing Godeps, GPM, and GB files. // I think that all we really need to do now is hunt for these files, and then // roll their version numbers into the config file. // Set references. There may be no remaining references to set since the // 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 { msg.Err("Failed to set references: %s (Skip to cleanup)", err) } } // Vendored cleanup // 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(confcopy) } // Write glide.yaml (Why? Godeps/GPM/GB?) // I think we don't need to write a new Glide file because update should not // change anything important. It will just generate information about // transative dependencies, all of which belongs exclusively in the lock // file, not the glide.yaml file. // TODO(mattfarina): Detect when a new dependency has been added or removed // from the project. A removed dependency should warn and an added dependency // should be added to the glide.yaml file. See issue #193. if stripVendor { confcopy = godep.RemoveGodepSubpackages(confcopy) } if !skipRecursive { // Write lock hash, err := conf.Hash() if err != nil { msg.Die("Failed to generate config hash. Unable to generate lock file.") } lock := cfg.NewLockfile(confcopy.Imports, hash) wl := true if gpath.HasLock(base) { yml, err := ioutil.ReadFile(filepath.Join(base, gpath.LockFile)) if err == nil { l2, err := cfg.LockfileFromYaml(yml) if err == nil { f1, err := l2.Fingerprint() f2, err2 := lock.Fingerprint() if err == nil && err2 == nil && f1 == f2 { wl = false } } } } if wl { if err := lock.WriteFile(filepath.Join(base, gpath.LockFile)); err != nil { msg.Err("Could not write lock file to %s: %s", base, err) return } } else { msg.Info("Versions did not change. Skipping glide.lock update.") } msg.Info("Project relies on %d dependencies.", len(confcopy.Imports)) } else { msg.Warn("Skipping lockfile generation because full dependency tree is not being calculated") } if strip { msg.Info("Removing version control data from vendor directory...") gpath.StripVcs() } if stripVendor { msg.Info("Removing nested vendor and Godeps/_workspace directories...") err := gpath.StripVendor() if err != nil { msg.Err("Unable to strip vendor directories: %s", err) } } }
// Update updates repos and the lock file from the main glide yaml. func Update(installer *repo.Installer, skipRecursive, stripVendor bool) { cache.SystemLock() base := "." EnsureGopath() EnsureVendorDir() conf := EnsureConfig() // Try to check out the initial dependencies. if err := installer.Checkout(conf); 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, installer.ResolveTest); 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() if !skipRecursive { // Get all repos and update them. err := installer.Update(confcopy) if err != nil { msg.Die("Could not update packages: %s", err) } // Set references. There may be no remaining references to set since the // 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, installer.ResolveTest); err != nil { msg.Err("Failed to set references: %s (Skip to cleanup)", err) } } err := installer.Export(confcopy) if err != nil { msg.Die("Unable to export dependencies to vendor directory: %s", err) } // Write glide.yaml (Why? Godeps/GPM/GB?) // I think we don't need to write a new Glide file because update should not // change anything important. It will just generate information about // transative dependencies, all of which belongs exclusively in the lock // file, not the glide.yaml file. // TODO(mattfarina): Detect when a new dependency has been added or removed // from the project. A removed dependency should warn and an added dependency // should be added to the glide.yaml file. See issue #193. if !skipRecursive { // Write lock hash, err := conf.Hash() if err != nil { msg.Die("Failed to generate config hash. Unable to generate lock file.") } lock, err := cfg.NewLockfile(confcopy.Imports, confcopy.DevImports, hash) if err != nil { msg.Die("Failed to generate lock file: %s", err) } wl := true if gpath.HasLock(base) { yml, err := ioutil.ReadFile(filepath.Join(base, gpath.LockFile)) if err == nil { l2, err := cfg.LockfileFromYaml(yml) if err == nil { f1, err := l2.Fingerprint() f2, err2 := lock.Fingerprint() if err == nil && err2 == nil && f1 == f2 { wl = false } } } } if wl { if err := lock.WriteFile(filepath.Join(base, gpath.LockFile)); err != nil { msg.Err("Could not write lock file to %s: %s", base, err) return } } else { msg.Info("Versions did not change. Skipping glide.lock update.") } msg.Info("Project relies on %d dependencies.", len(confcopy.Imports)) } else { msg.Warn("Skipping lockfile generation because full dependency tree is not being calculated") } if stripVendor { msg.Info("Removing nested vendor and Godeps/_workspace directories...") err := gpath.StripVendor() if err != nil { msg.Err("Unable to strip vendor directories: %s", err) } } }