github.com/daniel-garcia/glide@v0.0.0-20160218012856-2eab91fab790/action/update.go (about) 1 package action 2 3 import ( 4 "path/filepath" 5 6 "github.com/Masterminds/glide/cfg" 7 "github.com/Masterminds/glide/dependency" 8 "github.com/Masterminds/glide/msg" 9 gpath "github.com/Masterminds/glide/path" 10 "github.com/Masterminds/glide/repo" 11 ) 12 13 // Update updates repos and the lock file from the main glide yaml. 14 func Update(installer *repo.Installer, skipRecursive bool) { 15 base := "." 16 EnsureGopath() 17 EnsureVendorDir() 18 conf := EnsureConfig() 19 20 // Delete unused packages 21 if installer.DeleteUnused { 22 dependency.DeleteUnused(conf) 23 } 24 25 // Try to check out the initial dependencies. 26 if err := installer.Checkout(conf, false); err != nil { 27 msg.Die("Failed to do initial checkout of config: %s", err) 28 } 29 30 // Set the versions for the initial dependencies so that resolved dependencies 31 // are rooted in the correct version of the base. 32 if err := repo.SetReference(conf); err != nil { 33 msg.Die("Failed to set initial config references: %s", err) 34 } 35 36 // Prior to resolving dependencies we need to start working with a clone 37 // of the conf because we'll be making real changes to it. 38 confcopy := conf.Clone() 39 40 if !skipRecursive { 41 // Get all repos and update them. 42 err := installer.Update(confcopy) 43 if err != nil { 44 msg.Die("Could not update packages: %s", err) 45 } 46 47 // TODO: There is no support here for importing Godeps, GPM, and GB files. 48 // I think that all we really need to do now is hunt for these files, and then 49 // roll their version numbers into the config file. 50 51 // Set references. There may be no remaining references to set since the 52 // installer set them as it went to make sure it parsed the right imports 53 // from the right version of the package. 54 msg.Info("Setting references for remaining imports") 55 if err := repo.SetReference(confcopy); err != nil { 56 msg.Err("Failed to set references: %s (Skip to cleanup)", err) 57 } 58 } 59 // Vendored cleanup 60 // VendoredCleanup. This should ONLY be run if UpdateVendored was specified. 61 if installer.UpdateVendored { 62 repo.VendoredCleanup(confcopy) 63 } 64 65 // Write glide.yaml (Why? Godeps/GPM/GB?) 66 // I think we don't need to write a new Glide file because update should not 67 // change anything important. It will just generate information about 68 // transative dependencies, all of which belongs exclusively in the lock 69 // file, not the glide.yaml file. 70 // TODO(mattfarina): Detect when a new dependency has been added or removed 71 // from the project. A removed dependency should warn and an added dependency 72 // should be added to the glide.yaml file. See issue #193. 73 74 if !skipRecursive { 75 // Write lock 76 hash, err := conf.Hash() 77 if err != nil { 78 msg.Die("Failed to generate config hash. Unable to generate lock file.") 79 } 80 lock := cfg.NewLockfile(confcopy.Imports, hash) 81 if err := lock.WriteFile(filepath.Join(base, gpath.LockFile)); err != nil { 82 msg.Err("Could not write lock file to %s: %s", base, err) 83 return 84 } 85 86 msg.Info("Project relies on %d dependencies.", len(confcopy.Imports)) 87 } else { 88 msg.Warn("Skipping lockfile generation because full dependency tree is not being calculated") 89 } 90 }