Skip to content
This repository was archived by the owner on Sep 9, 2020. It is now read-only.

Commit 48e3fcf

Browse files
committed
Fix compile errors
1 parent 1a54666 commit 48e3fcf

File tree

2 files changed

+39
-25
lines changed

2 files changed

+39
-25
lines changed

cmd/dep/ensure.go

+38-24
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ type ensureCommand struct {
122122
add bool
123123
noVendor bool
124124
vendorOnly bool
125+
dryRun bool
125126
overrides stringSlice
126127
}
127128

@@ -173,7 +174,6 @@ func (cmd *ensureCommand) Run(ctx *dep.Ctx, args []string) error {
173174
return err
174175
}
175176

176-
var fail error
177177
if cmd.add {
178178
return cmd.runAdd(ctx, args, p, sm, params)
179179
} else if cmd.update {
@@ -191,14 +191,13 @@ func (cmd *ensureCommand) runDefault(ctx *dep.Ctx, args []string, p *dep.Project
191191
return errors.New("dep ensure only takes spec arguments with -add or -update - did you want one of those?")
192192
}
193193

194-
sw := &dep.SafeWriter{}
195194
if cmd.vendorOnly {
196195
if p.Lock == nil {
197196
return errors.Errorf("no %s exists from which to populate vendor/ directory", dep.LockName)
198197
}
199198
// Pass the same lock as old and new so that the writer will observe no
200199
// difference and choose not to write it out.
201-
err := sw.Prepare(nil, p.Lock, p.Lock, dep.VendorAlways)
200+
sw, err := dep.NewSafeWriter(nil, p.Lock, p.Lock, dep.VendorAlways)
202201
if err != nil {
203202
return err
204203
}
@@ -229,7 +228,7 @@ func (cmd *ensureCommand) runDefault(ctx *dep.Ctx, args []string, p *dep.Project
229228
// that "verification" is supposed to look like (#121); in the meantime,
230229
// we unconditionally write out vendor/ so that `dep ensure`'s behavior
231230
// is maximally compatible with what it will eventually become.
232-
err := sw.Prepare(nil, p.Lock, p.Lock, dep.VendorAlways)
231+
sw, err := dep.NewSafeWriter(nil, p.Lock, p.Lock, dep.VendorAlways)
233232
if err != nil {
234233
return err
235234
}
@@ -248,17 +247,20 @@ func (cmd *ensureCommand) runDefault(ctx *dep.Ctx, args []string, p *dep.Project
248247
return errors.Wrap(err, "ensure Solve()")
249248
}
250249

251-
sw.Prepare(nil, p.Lock, dep.LockFromInterface(solution), dep.VendorOnChanged)
250+
sw, err := dep.NewSafeWriter(nil, p.Lock, dep.LockFromInterface(solution), dep.VendorOnChanged)
251+
if err != nil {
252+
return err
253+
}
252254
if cmd.dryRun {
253-
return sw.PrintPreparedActions()
255+
return sw.PrintPreparedActions(ctx.Loggers.Out)
254256
}
255257

256258
return nil
257259
}
258260

259261
func (cmd *ensureCommand) runUpdate(ctx *dep.Ctx, args []string, p *dep.Project, sm gps.SourceManager, params gps.SolveParameters) error {
260262
if p.Lock == nil {
261-
return errors.New("%s does not exist. nothing to do, as -update works by updating the values in %s.", dep.LockName, dep.LockName)
263+
return errors.Errorf("%s does not exist. nothing to do, as -update works by updating the values in %s.", dep.LockName, dep.LockName)
262264
}
263265

264266
// We'll need to discard this prepared solver as later work changes params,
@@ -283,7 +285,6 @@ func (cmd *ensureCommand) runUpdate(ctx *dep.Ctx, args []string, p *dep.Project,
283285
// versions, regardless of the lock file.
284286
if len(args) == 0 {
285287
params.ChangeAll = true
286-
return
287288
}
288289

289290
// Allow any of specified project versions to change, regardless of the lock
@@ -302,8 +303,8 @@ func (cmd *ensureCommand) runUpdate(ctx *dep.Ctx, args []string, p *dep.Project,
302303
return errors.Errorf("%s is not present in %s, cannot -update it", pc.Ident.ProjectRoot, dep.LockName)
303304
}
304305

305-
if p.Ident.Source != "" {
306-
return errors.Errorf("cannot specify alternate sources on -update (%s)", p.Ident)
306+
if pc.Ident.Source != "" {
307+
return errors.Errorf("cannot specify alternate sources on -update (%s)", pc.Ident)
307308
}
308309

309310
if !gps.IsAny(pc.Constraint) {
@@ -326,8 +327,10 @@ func (cmd *ensureCommand) runUpdate(ctx *dep.Ctx, args []string, p *dep.Project,
326327
return errors.Wrap(err, "ensure Solve()")
327328
}
328329

329-
var sw dep.SafeWriter
330-
sw.Prepare(nil, p.Lock, dep.LockFromInterface(solution), dep.VendorOnChanged)
330+
sw, err := dep.NewSafeWriter(nil, p.Lock, dep.LockFromInterface(solution), dep.VendorOnChanged)
331+
if err != nil {
332+
return err
333+
}
331334
// TODO(sdboyer) special handling for warning cases as described in spec -
332335
// e.g., named projects did not upgrade even though newer versions were
333336
// available.
@@ -343,6 +346,14 @@ func (cmd *ensureCommand) runAdd(ctx *dep.Ctx, args []string, p *dep.Project, sm
343346
return errors.New("must specify at least one project or package to add")
344347
}
345348

349+
// We'll need to discard this prepared solver as later work changes params,
350+
// but solver preparation is cheap and worth doing up front in order to
351+
// perform the fastpath check of hash comparison.
352+
solver, err := gps.Prepare(params, sm)
353+
if err != nil {
354+
return errors.Wrap(err, "fastpath solver prepare")
355+
}
356+
346357
// Compare the hashes. If they're not equal, bail out and ask the user to
347358
// run a straight `dep ensure` before updating. This is handholding the
348359
// user a bit, but the extra effort required is minimal, and it ensures the
@@ -357,25 +368,29 @@ func (cmd *ensureCommand) runAdd(ctx *dep.Ctx, args []string, p *dep.Project, sm
357368
// Having some problematic internal packages isn't cause for termination,
358369
// but the user needs to be warned.
359370
for fail := range errmap {
360-
internal.Logf("Warning: %s", fail)
371+
ctx.Loggers.Err.Printf("Warning: %s", fail)
361372
}
362373

374+
// Compile unique sets of 1) all external packages imported or required, and
375+
// 2) the project roots under which they fall.
363376
exmap := make(map[string]bool)
364377
exrmap := make(map[gps.ProjectRoot]bool)
365-
for _, ex := range append(rm.Flatten(false), p.Manifest.RequiredPackages()...) {
378+
379+
for _, ex := range append(rm.Flatten(false), p.Manifest.Required...) {
366380
exmap[ex] = true
367381
root, err := sm.DeduceProjectRoot(ex)
368382
if err != nil {
369-
// This should be essentially impossible to hit, as it entails that
370-
// we couldn't deduce the root for an import, but that some previous
371-
// solve run WAS able to deduce the root.
372-
return errors.Wrap(err, "could not deduce project root")
383+
// This should be very uncommon to hit, as it entails that we
384+
// couldn't deduce the root for an import, but that some previous
385+
// solve run WAS able to deduce the root. It's most likely to occur
386+
// if the user has e.g. not connected to their organization's VPN,
387+
// and thus cannot access an internal go-get metadata service.
388+
return errors.Wrapf(err, "could not deduce project root for %s", ex)
373389
}
374390
exrmap[root] = true
375391
}
376392

377393
var reqlist []string
378-
//pclist := make(map[gps.ProjectRoot]gps.ProjectConstraint)
379394

380395
for _, arg := range args {
381396
// TODO(sdboyer) return all errors, not just the first one we encounter
@@ -394,10 +409,10 @@ func (cmd *ensureCommand) runAdd(ctx *dep.Ctx, args []string, p *dep.Project, sm
394409

395410
err = sm.SyncSourceFor(pc.Ident)
396411
if err != nil {
397-
return errors.Wrap(err, "failed to fetch source for %s", pc.Ident.ProjectRoot)
412+
return errors.Wrapf(err, "failed to fetch source for %s", pc.Ident.ProjectRoot)
398413
}
399414

400-
someConstraint = pc.Constraint != nil || pc.Ident.Source != ""
415+
someConstraint := pc.Constraint != nil || pc.Ident.Source != ""
401416
if inManifest {
402417
if someConstraint {
403418
return errors.Errorf("%s already contains constraints for %s, cannot specify a version constraint or alternate source", arg, dep.ManifestName)
@@ -457,13 +472,12 @@ func (cmd *ensureCommand) runAdd(ctx *dep.Ctx, args []string, p *dep.Project, sm
457472
return errors.Wrap(err, "ensure Solve()")
458473
}
459474

460-
var sw dep.SafeWriter
461-
sw.Prepare(nil, p.Lock, dep.LockFromInterface(solution), dep.VendorOnChanged)
475+
sw, err := dep.NewSafeWriter(nil, p.Lock, dep.LockFromInterface(solution), dep.VendorOnChanged)
462476
// TODO(sdboyer) special handling for warning cases as described in spec -
463477
// e.g., named projects did not upgrade even though newer versions were
464478
// available.
465479
if cmd.dryRun {
466-
return sw.PrintPreparedActions()
480+
return sw.PrintPreparedActions(ctx.Loggers.Out)
467481
}
468482

469483
return errors.Wrap(sw.Write(p.AbsRoot, sm, true), "grouped write of manifest, lock and vendor")

lock.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ func (l *Lock) HasProjectWithRoot(root gps.ProjectRoot) bool {
106106
}
107107
}
108108

109-
return root
109+
return false
110110
}
111111

112112
// toRaw converts the manifest into a representation suitable to write to the lock file

0 commit comments

Comments
 (0)