@@ -15,7 +15,6 @@ import (
15
15
"github.com/golang/dep/internal"
16
16
"github.com/golang/dep/internal/gps"
17
17
"github.com/golang/dep/internal/gps/pkgtree"
18
- "github.com/golang/dep/internal/importer"
19
18
"github.com/pkg/errors"
20
19
)
21
20
@@ -58,13 +57,6 @@ type initCommand struct {
58
57
skipTools bool
59
58
}
60
59
61
- func trimPathPrefix (p1 , p2 string ) string {
62
- if internal .HasFilepathPrefix (p1 , p2 ) {
63
- return p1 [len (p2 ):]
64
- }
65
- return p1
66
- }
67
-
68
60
func (cmd * initCommand ) Run (ctx * dep.Ctx , loggers * Loggers , args []string ) error {
69
61
if len (args ) > 1 {
70
62
return errors .Errorf ("too many args (%d)" , len (args ))
@@ -118,85 +110,37 @@ func (cmd *initCommand) Run(ctx *dep.Ctx, loggers *Loggers, args []string) error
118
110
sm .UseDefaultSignalHandling ()
119
111
defer sm .Release ()
120
112
121
- pd , err := getProjectData (ctx , loggers , pkgT , cpr , sm )
122
- if err != nil {
123
- return err
124
- }
125
-
126
113
var rootAnalyzer internal.RootProjectAnalyzer
127
114
var analyzer gps.ProjectAnalyzer
128
115
if cmd .skipTools {
129
- rootAnalyzer = internal.GopathAnalyzer {}
116
+ rootAnalyzer = internal .NewGopathAnalyzer ( ctx , pkgtree , cpr , sm )
130
117
analyzer = dep.Analyzer {}
131
118
} else {
132
119
rootAnalyzer = internal.CompositeAnalyzer {
133
120
Analyzers : []internal.RootProjectAnalyzer {
134
- internal.GopathAnalyzer {} ,
121
+ internal .NewGopathAnalyzer ( ctx , pkgtree , cpr , sm ) ,
135
122
internal.ImportAnalyzer {},
136
123
}}
137
124
analyzer = internal.ImportAnalyzer {}
138
125
}
139
126
140
127
// Analyze the root project to create an root manifest and lock
141
- rootM , rootL , err := rootAnalyzer .DeriveRootManifestAndLock (root , gps .ProjectRoot (cpr ))
128
+ m , l , err := rootAnalyzer .DeriveRootManifestAndLock (root , gps .ProjectRoot (cpr ))
129
+ if err != nil {
130
+ return errors .Wrap (err , "Error initializing a manifest and lock" )
131
+ }
142
132
143
133
if loggers .Verbose {
144
134
loggers .Err .Println ("dep: Solving..." )
145
135
}
146
136
params := gps.SolveParameters {
147
137
RootDir : root ,
148
138
RootPackageTree : pkgT ,
149
- Manifest : rootM ,
150
- Lock : rootL ,
139
+ Manifest : m ,
140
+ Lock : l ,
151
141
ProjectAnalyzer : analyzer ,
152
142
}
153
143
154
- // BEGIN
155
- m := & dep.Manifest {
156
- Dependencies : pd .constraints ,
157
- }
158
-
159
- if ! cmd .skipTools {
160
- ipd , err := importer .Import (root , cpr )
161
- if err != nil {
162
- return errors .Wrap (err , "Error importing dependency management configuration" )
163
- }
164
-
165
- if ipd != nil {
166
- m .Ignored = ipd .Ignored
167
- for pr , c := range ipd .Dependencies {
168
- internal .Vlogf ("Importing dependency on %s: %s" , pr , c )
169
- m .Dependencies [pr ] = c
170
- }
171
- }
172
- }
173
-
174
- // Make an initial lock from what knowledge we've collected about the
175
- // versions on disk
176
- l := & dep.Lock {
177
- P : make ([]gps.LockedProject , 0 , len (pd .ondisk )),
178
- }
179
-
180
- for pr , v := range pd .ondisk {
181
- // That we have to chop off these path prefixes is a symptom of
182
- // a problem in gps itself
183
- pkgs := make ([]string , 0 , len (pd .dependencies [pr ]))
184
- prslash := string (pr ) + "/"
185
- for _ , pkg := range pd .dependencies [pr ] {
186
- if pkg == string (pr ) {
187
- pkgs = append (pkgs , "." )
188
- } else {
189
- pkgs = append (pkgs , trimPathPrefix (pkg , prslash ))
190
- }
191
- }
192
-
193
- l .P = append (l .P , gps .NewLockedProject (
194
- gps.ProjectIdentifier {ProjectRoot : pr }, v , pkgs ),
195
- )
196
- }
197
-
198
- // END
199
-
200
144
if * verbose {
201
145
params .Trace = true
202
146
params .TraceLogger = log .New (os .Stderr , "" , 0 )
@@ -249,30 +193,6 @@ func (cmd *initCommand) Run(ctx *dep.Ctx, loggers *Loggers, args []string) error
249
193
return nil
250
194
}
251
195
252
- // contains checks if a array of strings contains a value
253
- func contains (a []string , b string ) bool {
254
- for _ , v := range a {
255
- if b == v {
256
- return true
257
- }
258
- }
259
- return false
260
- }
261
-
262
- // isStdLib reports whether $GOROOT/src/path should be considered
263
- // part of the standard distribution. For historical reasons we allow people to add
264
- // their own code to $GOROOT instead of using $GOPATH, but we assume that
265
- // code will start with a domain name (dot in the first element).
266
- // This was loving taken from src/cmd/go/pkg.go in Go's code (isStandardImportPath).
267
- func isStdLib (path string ) bool {
268
- i := strings .Index (path , "/" )
269
- if i < 0 {
270
- i = len (path )
271
- }
272
- elem := path [:i ]
273
- return ! strings .Contains (elem , "." )
274
- }
275
-
276
196
// TODO solve failures can be really creative - we need to be similarly creative
277
197
// in handling them and informing the user appropriately
278
198
func handleAllTheFailuresOfTheWorld (err error ) {
@@ -284,7 +204,6 @@ func hasImportPathPrefix(s, prefix string) bool {
284
204
}
285
205
return strings .HasPrefix (s , prefix + "/" )
286
206
}
287
-
288
207
// getProjectPropertiesFromVersion takes a gps.Version and returns a proper
289
208
// gps.ProjectProperties with Constraint value based on the provided version.
290
209
func getProjectPropertiesFromVersion (v gps.Version ) gps.ProjectProperties {
0 commit comments