1
1
package action
2
2
3
3
import (
4
+ "encoding/hex"
4
5
"path/filepath"
6
+ "time"
5
7
6
8
"github.com/Masterminds/glide/cfg"
7
9
"github.com/Masterminds/glide/dependency"
8
- "github.com/Masterminds/glide/godep"
9
10
"github.com/Masterminds/glide/msg"
10
11
gpath "github.com/Masterminds/glide/path"
11
12
"github.com/Masterminds/glide/repo"
13
+ "github.com/Sirupsen/logrus"
14
+ "github.com/sdboyer/vsolver"
12
15
)
13
16
14
17
// Update updates repos and the lock file from the main glide yaml.
@@ -18,93 +21,71 @@ func Update(installer *repo.Installer, skipRecursive, strip, stripVendor bool) {
18
21
EnsureVendorDir ()
19
22
conf := EnsureConfig ()
20
23
21
- // Delete unused packages
22
- if installer .DeleteUnused {
23
- dependency .DeleteUnused (conf )
24
- }
24
+ // TODO(mattfarina): Detect when a new dependency has been added or removed
25
+ // from the project. A removed dependency should warn and an added dependency
26
+ // should be added to the glide.yaml file. See issue #193.
25
27
26
- // Try to check out the initial dependencies.
27
- if err := installer .Checkout (conf , false ); err != nil {
28
- msg .Die ("Failed to do initial checkout of config: %s" , err )
28
+ // Create the SourceManager for this run
29
+ sm , err := vsolver .NewSourceManager (filepath .Join (installer .Home , "cache" ), base , true , false , dependency.Analyzer {})
30
+ if err != nil {
31
+ msg .Die (err .Error ())
29
32
}
30
33
31
- // Set the versions for the initial dependencies so that resolved dependencies
32
- // are rooted in the correct version of the base.
33
- if err := repo . SetReference ( conf ); err != nil {
34
- msg . Die ( "Failed to set initial config references: %s" , err )
34
+ opts := vsolver. SolveOpts {
35
+ N : vsolver . ProjectName ( filepath . Dir ( installer . Vendor )),
36
+ Root : filepath . Dir ( installer . Vendor ),
37
+ M : conf ,
35
38
}
36
39
37
- // Prior to resolving dependencies we need to start working with a clone
38
- // of the conf because we'll be making real changes to it.
39
- confcopy := conf .Clone ()
40
-
41
- if ! skipRecursive {
42
- // Get all repos and update them.
43
- err := installer .Update (confcopy )
40
+ if gpath .HasLock (base ) {
41
+ opts .L , err = LoadLockfile (base , conf )
44
42
if err != nil {
45
- msg .Die ("Could not update packages: %s" , err )
43
+ msg .Warn ("Could not load lockfile; all projects will be updated." )
46
44
}
45
+ }
47
46
48
- // TODO: There is no support here for importing Godeps, GPM, and GB files.
49
- // I think that all we really need to do now is hunt for these files, and then
50
- // roll their version numbers into the config file.
51
-
52
- // Set references. There may be no remaining references to set since the
53
- // installer set them as it went to make sure it parsed the right imports
54
- // from the right version of the package.
55
- msg .Info ("Setting references for remaining imports" )
56
- if err := repo .SetReference (confcopy ); err != nil {
57
- msg .Err ("Failed to set references: %s (Skip to cleanup)" , err )
58
- }
47
+ s := vsolver .NewSolver (sm , logrus .New ())
48
+ r , err := s .Solve (opts )
49
+ if err != nil {
50
+ // TODO better error handling
51
+ msg .Die (err .Error ())
59
52
}
60
- // Vendored cleanup
61
- // VendoredCleanup. This should ONLY be run if UpdateVendored was specified.
62
- // When stripping VCS happens this will happen as well. No need for double
63
- // effort.
64
- if installer .UpdateVendored && ! strip {
65
- repo .VendoredCleanup (confcopy )
53
+
54
+ err = writeVendor (installer .Vendor , r , sm )
55
+ if err != nil {
56
+ msg .Die (err .Error ())
66
57
}
67
58
68
- // Write glide.yaml (Why? Godeps/GPM/GB?)
69
- // I think we don't need to write a new Glide file because update should not
70
- // change anything important. It will just generate information about
71
- // transative dependencies, all of which belongs exclusively in the lock
72
- // file, not the glide.yaml file.
73
- // TODO(mattfarina): Detect when a new dependency has been added or removed
74
- // from the project. A removed dependency should warn and an added dependency
75
- // should be added to the glide.yaml file. See issue #193.
59
+ // TODO compare old and new lock, and only change if contents differ
76
60
77
- if stripVendor {
78
- confcopy = godep .RemoveGodepSubpackages (confcopy )
61
+ // Create and write out a new lock file from the result
62
+ lf := & cfg.Lockfile {
63
+ Hash : hex .EncodeToString (r .InputHash ()),
64
+ Updated : time .Now (),
79
65
}
80
66
81
- if ! skipRecursive {
82
- // Write lock
83
- hash , err := conf .Hash ()
84
- if err != nil {
85
- msg .Die ("Failed to generate config hash. Unable to generate lock file." )
86
- }
87
- lock := cfg .NewLockfile (confcopy .Imports , hash )
88
- if err := lock .WriteFile (filepath .Join (base , gpath .LockFile )); err != nil {
89
- msg .Err ("Could not write lock file to %s: %s" , base , err )
90
- return
67
+ for _ , p := range r .Projects () {
68
+ l := & cfg.Lock {
69
+ Name : string (p .Name ()),
70
+ Repository : p .URI (), // TODO this is wrong
71
+ VcsType : "" , // TODO allow this to be extracted from sm
91
72
}
92
73
93
- msg .Info ("Project relies on %d dependencies." , len (confcopy .Imports ))
94
- } else {
95
- msg .Warn ("Skipping lockfile generation because full dependency tree is not being calculated" )
74
+ v := p .Version ()
75
+ if pv , ok := v .(vsolver.PairedVersion ); ok {
76
+ l .Version = pv .Underlying ().String ()
77
+ } else {
78
+ l .Version = pv .String ()
79
+ }
96
80
}
97
81
98
- if strip {
99
- msg . Info ( "Removing version control data from vendor directory..." )
100
- gpath . StripVcs ( )
82
+ err = lf . WriteFile ( filepath . Join ( base , gpath . LockFile ))
83
+ if err != nil {
84
+ msg . Die ( "Error on writing new lock file: %s" , err )
101
85
}
102
86
103
- if stripVendor {
104
- msg .Info ("Removing nested vendor and Godeps/_workspace directories..." )
105
- err := gpath .StripVendor ()
106
- if err != nil {
107
- msg .Err ("Unable to strip vendor directories: %s" , err )
108
- }
87
+ err = writeVendor (installer .Vendor , r , sm )
88
+ if err != nil {
89
+ msg .Die (err .Error ())
109
90
}
110
91
}
0 commit comments