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

Commit da33cb1

Browse files
committed
internal/gps: ensure packages are deducible before attempting to solve
Signed-off-by: Ibrahim AshShohail <[email protected]>
1 parent 1c168c0 commit da33cb1

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

cmd/dep/ensure.go

+10
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,18 @@ func (cmd *ensureCommand) Run(ctx *dep.Ctx, args []string) error {
144144

145145
solver, err := gps.Prepare(params, sm)
146146
if err != nil {
147+
if deduceErrs, ok := err.(gps.DeductionFailureErrs); ok {
148+
ctx.Loggers.Err.Println("The following errors occurred while deducing packages:")
149+
for ip, error := range deduceErrs {
150+
ctx.Loggers.Err.Printf(" * \"%s\": %s", ip, error)
151+
}
152+
ctx.Loggers.Err.Println()
153+
154+
return errors.New("could not deduce packages to ensure constraints")
155+
}
147156
return errors.Wrap(err, "ensure Prepare")
148157
}
158+
149159
solution, err := solver.Solve()
150160
if err != nil {
151161
handleAllTheFailuresOfTheWorld(err)

internal/gps/solve_failures.go

+7
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,13 @@ func (e badOptsFailure) Error() string {
239239
return string(e)
240240
}
241241

242+
// DeductionFailureErrs maps package import path to errors occurring during deduction.
243+
type DeductionFailureErrs map[string]error
244+
245+
func (e DeductionFailureErrs) Error() string {
246+
return fmt.Sprintf("%v", e)
247+
}
248+
242249
type sourceMismatchFailure struct {
243250
// The ProjectRoot over which there is disagreement about where it should be
244251
// sourced from

internal/gps/solver.go

+23
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"log"
1111
"sort"
1212
"strings"
13+
"sync"
1314

1415
"github.com/armon/go-radix"
1516
"github.com/golang/dep/internal/gps/paths"
@@ -289,6 +290,28 @@ func Prepare(params SolveParameters, sm SourceManager) (Solver, error) {
289290
rd: rd,
290291
}
291292

293+
var deducePkgsGroup sync.WaitGroup
294+
deductionErrs := make(DeductionFailureErrs)
295+
296+
checkPkg := func(ip string, sm SourceManager) {
297+
_, err := sm.DeduceProjectRoot(ip)
298+
if err != nil {
299+
deductionErrs[ip] = err
300+
}
301+
deducePkgsGroup.Done()
302+
}
303+
304+
for _, ip := range rd.externalImportList(params.stdLibFn) {
305+
deducePkgsGroup.Add(1)
306+
go checkPkg(ip, sm)
307+
}
308+
309+
deducePkgsGroup.Wait()
310+
311+
if len(deductionErrs) > 0 {
312+
return nil, deductionErrs
313+
}
314+
292315
// Set up the bridge and ensure the root dir is in good, working order
293316
// before doing anything else.
294317
if params.mkBridgeFn == nil {

0 commit comments

Comments
 (0)