forked from Masterminds/glide
/
install.go
99 lines (84 loc) · 2.42 KB
/
install.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package action
import (
"io/ioutil"
"path/filepath"
"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) {
base := "."
// Ensure GOPATH
EnsureGopath()
EnsureVendorDir()
conf := EnsureConfig()
// Lockfile exists
if !gpath.HasLock(base) {
msg.Info("Lock file (glide.lock) does not exist. Performing update.")
Update(installer, false, strip, stripVendor)
return
}
// Load lockfile
lock, err := LoadLockfile(base, conf)
if err != nil {
msg.Die("Could not load lockfile.")
}
// Delete unused packages
if installer.DeleteUnused {
// It's unclear whether this should operate off of the lock, or off
// of the glide.yaml file. I'd think that doing this based on the
// lock would be much more reliable.
dependency.DeleteUnused(conf)
}
// Install
newConf, err := installer.Install(lock, conf)
if err != nil {
msg.Die("Failed to install: %s", err)
}
msg.Info("Setting references.")
// Set reference
if err := repo.SetReference(newConf); err != nil {
msg.Err("Failed to set references: %s (Skip to cleanup)", err)
}
// 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...")
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)
}
}
}
// 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
}