|
5 | 5 | package main
|
6 | 6 |
|
7 | 7 | import (
|
| 8 | + "encoding/hex" |
8 | 9 | "flag"
|
9 |
| - "fmt" |
10 | 10 | "log"
|
11 | 11 | "os"
|
12 | 12 | "path/filepath"
|
@@ -246,37 +246,67 @@ func hasImportPathPrefix(s, prefix string) bool {
|
246 | 246 | // feedback.
|
247 | 247 | func itemizedFeedback(m *dep.Manifest, l *dep.Lock, pkgT pkgtree.PackageTree) {
|
248 | 248 | // Algo:
|
249 |
| - // loop through lock projects |
250 |
| - // 1. check in manifest for for same entry |
251 |
| - // 2. if exists in manifest, it's direct dep, goes to manifest & lock |
252 |
| - // 3. if not exists in manifest, check in pkgT |
253 |
| - // 3.a. if exists in pkgT, it's direct dep, hint constraint, lock only |
254 |
| - // 3.b. if not exists in pkgT, it's transitive dep, lock only |
255 |
| - // 4. log feedback |
| 249 | + // 1. collect direct external deps from PackageTree |
| 250 | + // 2. loop through lock projects |
| 251 | + // 2.a. check if the projects exists in direct deps list |
| 252 | + // 2.b. if it's a direct dep: |
| 253 | + // 2.b.i. if it has a version attached, constraint dep |
| 254 | + // 2.b.ii. if it has revision only, hint dep |
| 255 | + // 2.c. else it's a transitive dep |
| 256 | + // 2.d. log feedback |
| 257 | + |
| 258 | + // Extract direct external deps |
| 259 | + rm, errmap := pkgT.ToReachMap(true, true, false, nil) |
| 260 | + for fail := range errmap { |
| 261 | + internal.Logf("Warning: %s", fail) |
| 262 | + } |
| 263 | + |
| 264 | + directDeps := rm.Flatten(false) |
| 265 | + |
256 | 266 | for _, lock := range l.Projects() {
|
257 |
| - r, v, _ := gps.VersionComponentStrings(lock.Version()) |
258 |
| - projectPath := lock.Ident().ProjectRoot |
| 267 | + // Get locked revision, version and branch |
| 268 | + r, v, b := gps.VersionComponentStrings(lock.Version()) |
| 269 | + |
| 270 | + // Check if it's a valid SHA1 digest and trim to 7 characters. |
| 271 | + if len(r) == 40 { |
| 272 | + if _, err := hex.DecodeString(r); err == nil { |
| 273 | + // Valid SHA1 digest |
| 274 | + r = r[0:7] |
| 275 | + } |
| 276 | + } |
| 277 | + |
| 278 | + // Get LockedVersion |
| 279 | + var ver string |
| 280 | + if v != "" { |
| 281 | + ver = v |
| 282 | + } else if b != "" { |
| 283 | + ver = b |
| 284 | + } |
259 | 285 |
|
260 | 286 | cf := &internal.ConstraintFeedback{
|
261 |
| - Version: v, |
262 |
| - Revision: r, |
263 |
| - ProjectPath: projectPath, |
| 287 | + LockedVersion: ver, |
| 288 | + Revision: r, |
| 289 | + ProjectPath: string(lock.Ident().ProjectRoot), |
264 | 290 | }
|
265 | 291 |
|
266 |
| - if _, ok := m.Dependencies[projectPath]; ok { |
| 292 | + // Get manifest version if available |
| 293 | + if pr, ok := m.Dependencies[lock.Ident().ProjectRoot]; ok { |
| 294 | + cf.Version = pr.Constraint.String() |
| 295 | + } |
| 296 | + |
| 297 | + if contains(directDeps, cf.ProjectPath) { |
267 | 298 | // Direct dependency
|
268 | 299 | cf.DependencyType = internal.DepTypeDirect
|
269 |
| - cf.ConstraintType = internal.ConsTypeConstraint |
270 |
| - } else { |
271 |
| - if _, ok := pkgT.Packages[string(projectPath)]; ok { |
272 |
| - // Direct dependency, hint |
273 |
| - cf.DependencyType = internal.DepTypeDirect |
274 |
| - cf.ConstraintType = internal.ConsTypeHint |
| 300 | + if cf.LockedVersion != "" { |
| 301 | + cf.ConstraintType = internal.ConsTypeConstraint |
275 | 302 | } else {
|
276 |
| - // Transitive dependency |
277 |
| - cf.DependencyType = internal.DepTypeTransitive |
| 303 | + cf.ConstraintType = internal.ConsTypeHint |
278 | 304 | }
|
| 305 | + } else { |
| 306 | + // Transitive dependency |
| 307 | + cf.DependencyType = internal.DepTypeTransitive |
279 | 308 | }
|
| 309 | + |
280 | 310 | cf.LogFeedback()
|
281 | 311 | }
|
282 | 312 | }
|
@@ -324,11 +354,9 @@ func getProjectData(ctx *dep.Ctx, pkgT pkgtree.PackageTree, cpr string, sm *gps.
|
324 | 354 | ondisk := make(map[gps.ProjectRoot]gps.Version)
|
325 | 355 |
|
326 | 356 | syncDep := func(pr gps.ProjectRoot, sm *gps.SourceMgr) {
|
327 |
| - message := "Cached" |
328 | 357 | if err := sm.SyncSourceFor(gps.ProjectIdentifier{ProjectRoot: pr}); err != nil {
|
329 |
| - message = "Unable to cache" |
| 358 | + internal.Logf("%s %s", "Unable to cache", pr) |
330 | 359 | }
|
331 |
| - fmt.Fprintf(os.Stderr, "%s %s\n", message, pr) |
332 | 360 | }
|
333 | 361 |
|
334 | 362 | rm, _ := pkgT.ToReachMap(true, true, false, nil)
|
|
0 commit comments