Skip to content

Commit

Permalink
Merge pull request #547 from Masterminds/feat/resolve-in-cache
Browse files Browse the repository at this point in the history
Resolve deps in cache and mirrors
  • Loading branch information
mattfarina authored Aug 18, 2016
2 parents 3e49dce + c47164b commit 6ca050c
Show file tree
Hide file tree
Showing 57 changed files with 5,057 additions and 1,838 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ install: build
install -m 755 ./glide ${DESTDIR}/usr/local/bin/glide

test:
${GLIDE_GO_EXECUTABLE} test . ./gb ./path ./action ./tree ./util ./godep ./godep/strip ./gpm ./cfg ./dependency ./importer ./msg ./repo
${GLIDE_GO_EXECUTABLE} test . ./gb ./path ./action ./tree ./util ./godep ./godep/strip ./gpm ./cfg ./dependency ./importer ./msg ./repo ./mirrors

clean:
rm -f ./glide.test
Expand Down
12 changes: 3 additions & 9 deletions action/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,15 @@ import (

// CacheClear clears the Glide cache
func CacheClear() {
l, err := cache.Location()
if err != nil {
msg.Die("Unable to clear the cache: %s", err)
}
l := cache.Location()

err = os.RemoveAll(l)
err := os.RemoveAll(l)
if err != nil {
msg.Die("Unable to clear the cache: %s", err)
}

cache.SetupReset()
err = cache.Setup()
if err != nil {
msg.Die("Unable to clear the cache: %s", err)
}
cache.Setup()

msg.Info("Glide cache has been cleared.")
}
26 changes: 5 additions & 21 deletions action/config_wizard.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
// ConfigWizard reads configuration from a glide.yaml file and attempts to suggest
// improvements. The wizard is interactive.
func ConfigWizard(base string) {
cache.SystemLock()
_, err := gpath.Glide()
glidefile := gpath.GlideFile
if err != nil {
Expand All @@ -37,10 +38,7 @@ func ConfigWizard(base string) {

conf := EnsureConfig()

err = cache.Setup()
if err != nil {
msg.Die("Problem setting up cache: %s", err)
}
cache.Setup()

msg.Info("Looking for dependencies to make suggestions on")
msg.Info("--> Scanning for dependencies not using version ranges")
Expand All @@ -67,12 +65,7 @@ func ConfigWizard(base string) {

var changes int
for _, dep := range deps {
var remote string
if dep.Repository != "" {
remote = dep.Repository
} else {
remote = "https://" + dep.Name
}
remote := dep.Remote()

// First check, ask if the tag should be used instead of the commit id for it.
cur := cache.MemCurrent(remote)
Expand Down Expand Up @@ -257,17 +250,8 @@ func wizardLookInto(d *cfg.Dependency) bool {
var createGitParseVersion = regexp.MustCompile(`(?m-s)(?:tags)/(\S+)$`)

func wizardFindVersions(d *cfg.Dependency) {
l, err := cache.Location()
if err != nil {
msg.Debug("Problem detecting cache location: %s", err)
return
}
var remote string
if d.Repository != "" {
remote = d.Repository
} else {
remote = "https://" + d.Name
}
l := cache.Location()
remote := d.Remote()

key, err := cache.Key(remote)
if err != nil {
Expand Down
6 changes: 6 additions & 0 deletions action/ensure.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"strings"

"github.com/Masterminds/glide/cfg"
"github.com/Masterminds/glide/mirrors"
"github.com/Masterminds/glide/msg"
gpath "github.com/Masterminds/glide/path"
"github.com/Masterminds/glide/util"
Expand Down Expand Up @@ -56,6 +57,11 @@ func EnsureConfig() *cfg.Config {
}
}

err = mirrors.Load()
if err != nil {
msg.Err("Unable to load mirrors: %s", err)
}

return conf
}

Expand Down
29 changes: 6 additions & 23 deletions action/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@ import (
// Get fetches one or more dependencies and installs.
//
// This includes resolving dependency resolution and re-generating the lock file.
func Get(names []string, installer *repo.Installer, insecure, skipRecursive, strip, stripVendor, nonInteract, testDeps bool) {
if installer.UseCache {
cache.SystemLock()
}
func Get(names []string, installer *repo.Installer, insecure, skipRecursive, stripVendor, nonInteract, testDeps bool) {
cache.SystemLock()

base := gpath.Basepath()
EnsureGopath()
Expand Down Expand Up @@ -72,11 +70,9 @@ func Get(names []string, installer *repo.Installer, insecure, skipRecursive, str
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)
err = installer.Export(confcopy)
if err != nil {
msg.Die("Unable to export dependencies to vendor directory: %s", err)
}

// Write YAML
Expand All @@ -93,14 +89,6 @@ func Get(names []string, installer *repo.Installer, insecure, skipRecursive, str
msg.Warn("Skipping lockfile generation because full dependency tree is not being calculated")
}

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)
}
}

if stripVendor {
msg.Info("Removing nested vendor and Godeps/_workspace directories...")
err := gpath.StripVendor()
Expand Down Expand Up @@ -237,12 +225,7 @@ func addPkgsToConfig(conf *cfg.Config, names []string, insecure, nonInteract, te
}

func getWizard(dep *cfg.Dependency) {
var remote string
if dep.Repository != "" {
remote = dep.Repository
} else {
remote = "https://" + dep.Name
}
remote := dep.Remote()

// Lookup dependency info and store in cache.
msg.Info("--> Gathering release information for %s", dep.Name)
Expand Down
38 changes: 11 additions & 27 deletions action/install.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
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) {
if installer.UseCache {
cache.SystemLock()
}
func Install(installer *repo.Installer, stripVendor bool) {
cache.SystemLock()

base := "."
// Ensure GOPATH
Expand All @@ -26,7 +24,7 @@ func Install(installer *repo.Installer, strip, stripVendor bool) {
// Lockfile exists
if !gpath.HasLock(base) {
msg.Info("Lock file (glide.lock) does not exist. Performing update.")
Update(installer, false, strip, stripVendor)
Update(installer, false, stripVendor)
return
}
// Load lockfile
Expand All @@ -39,6 +37,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 @@ -52,29 +53,12 @@ func Install(installer *repo.Installer, strip, stripVendor bool) {

// Set reference
if err := repo.SetReference(newConf, installer.ResolveTest); err != nil {
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)
msg.Die("Failed to set references: %s (Skip to cleanup)", err)
}

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
2 changes: 1 addition & 1 deletion action/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func List(basedir string, deep bool, format string) {
if err != nil {
msg.Die("Could not create a resolver: %s", err)
}
h := &dependency.DefaultMissingPackageHandler{Missing: []string{}, Gopath: []string{}}
h := &dependency.DefaultMissingPackageHandler{Missing: []string{}, Gopath: []string{}, Prefix: "vendor"}
r.Handler = h

localPkgs, _, err := r.ResolveLocal(deep)
Expand Down
146 changes: 146 additions & 0 deletions action/mirrors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
package action

import (
"os"
"path/filepath"

"github.com/Masterminds/glide/mirrors"
"github.com/Masterminds/glide/msg"
gpath "github.com/Masterminds/glide/path"
)

// MirrorsList displays a list of currently setup mirrors.
func MirrorsList() error {
home := gpath.Home()

op := filepath.Join(home, "mirrors.yaml")

if _, err := os.Stat(op); os.IsNotExist(err) {
msg.Info("No mirrors exist. No mirrors.yaml file not found")
return nil
}

ov, err := mirrors.ReadMirrorsFile(op)
if err != nil {
msg.Die("Unable to read mirrors.yaml file: %s", err)
}

if len(ov.Repos) == 0 {
msg.Info("No mirrors found")
return nil
}

msg.Info("Mirrors...")
for _, r := range ov.Repos {
if r.Vcs == "" {
msg.Info("--> %s replaced by %s", r.Original, r.Repo)
} else {
msg.Info("--> %s replaced by %s (%s)", r.Original, r.Repo, r.Vcs)
}
}

return nil
}

// MirrorsSet sets a mirror to use
func MirrorsSet(o, r, v string) error {
if o == "" || r == "" {
msg.Err("Both the original and mirror values are required")
return nil
}

home := gpath.Home()

op := filepath.Join(home, "mirrors.yaml")

var ov *mirrors.Mirrors
if _, err := os.Stat(op); os.IsNotExist(err) {
msg.Info("No mirrors.yaml file exists. Creating new one")
ov = &mirrors.Mirrors{
Repos: make(mirrors.MirrorRepos, 0),
}
} else {
ov, err = mirrors.ReadMirrorsFile(op)
if err != nil {
msg.Die("Error reading existing mirrors.yaml file: %s", err)
}
}

found := false
for i, re := range ov.Repos {
if re.Original == o {
found = true
msg.Info("%s found in mirrors. Replacing with new settings", o)
ov.Repos[i].Repo = r
ov.Repos[i].Vcs = v
}
}

if !found {
nr := &mirrors.MirrorRepo{
Original: o,
Repo: r,
Vcs: v,
}
ov.Repos = append(ov.Repos, nr)
}

msg.Info("%s being set to %s", o, r)

err := ov.WriteFile(op)
if err != nil {
msg.Err("Error writing mirrors.yaml file: %s", err)
} else {
msg.Info("mirrors.yaml written with changes")
}

return nil
}

// MirrorsRemove removes a mirrors setting
func MirrorsRemove(k string) error {
if k == "" {
msg.Err("The mirror to remove is required")
return nil
}

home := gpath.Home()

op := filepath.Join(home, "mirrors.yaml")

if _, err := os.Stat(op); os.IsNotExist(err) {
msg.Err("mirrors.yaml file not found")
return nil
}

ov, err := mirrors.ReadMirrorsFile(op)
if err != nil {
msg.Die("Unable to read mirrors.yaml file: %s", err)
}

var nre mirrors.MirrorRepos
var found bool
for _, re := range ov.Repos {
if re.Original != k {
nre = append(nre, re)
} else {
found = true
}
}

if !found {
msg.Warn("%s was not found in mirrors", k)
} else {
msg.Info("%s was removed from mirrors", k)
ov.Repos = nre

err = ov.WriteFile(op)
if err != nil {
msg.Err("Error writing mirrors.yaml file: %s", err)
} else {
msg.Info("mirrors.yaml written with changes")
}
}

return nil
}
Loading

0 comments on commit 6ca050c

Please sign in to comment.