From a876439b4aad2edbbd627905c3073d577b55cf6a Mon Sep 17 00:00:00 2001 From: Sunny Date: Sat, 13 Jan 2018 20:00:11 +0530 Subject: [PATCH 1/2] manifest: skip ProjectRoot validation for alt source Alternate source could be used to bypass network reachability issues and when that is the case, PR validation fails because gps tries to reach the project over network and the project isn't reachable. This change skips PR validation for projects with alternate source only. --- manifest.go | 26 ++++++++++++++++++++++++-- manifest_test.go | 14 ++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/manifest.go b/manifest.go index add9236fdf..be1f9054ff 100644 --- a/manifest.go +++ b/manifest.go @@ -304,15 +304,37 @@ func ValidateProjectRoots(c *Ctx, m *Manifest, sm gps.SourceManager) error { } } - for pr := range m.Constraints { + // A map to register projects with alternate source. + projectsWithAltSrc := make(map[gps.ProjectRoot]bool) + + for pr, pp := range m.Constraints { + // If an alternate source is specified, it could be to bypass some network + // reachability issue. Trying to deduce ProjectRoot would fail if the + // the project isn't reachable. Do not validate such ProjectRoots. + if pp.Source != "" { + projectsWithAltSrc[pr] = true + continue + } + wg.Add(1) go validate(pr) } - for pr := range m.Ovr { + for pr, pp := range m.Ovr { + // Skip validation for alternate source. + if pp.Source != "" { + projectsWithAltSrc[pr] = true + continue + } + wg.Add(1) go validate(pr) } for pr := range m.PruneOptions.PerProjectOptions { + // Skip validation for alternate source. + if projectsWithAltSrc[pr] { + continue + } + wg.Add(1) go validate(pr) } diff --git a/manifest_test.go b/manifest_test.go index 28d5e43b9d..e35642ef83 100644 --- a/manifest_test.go +++ b/manifest_test.go @@ -618,6 +618,20 @@ func TestValidateProjectRoots(t *testing.T) { wantError: errInvalidProjectRoot, wantWarn: []string{}, }, + { + name: "skip project root deduction for alternate source", + manifest: Manifest{ + Constraints: map[gps.ProjectRoot]gps.ProjectProperties{ + // bad ProjectRoot + gps.ProjectRoot("golang.org/x"): { + Constraint: gps.NewBranch("master"), + Source: "github.com/golang/text", + }, + }, + }, + wantError: nil, + wantWarn: []string{}, + }, } h := test.NewHelper(t) From a8a1a5f4e68d582f5e53cae3b792f846545d8e2e Mon Sep 17 00:00:00 2001 From: Sunny Date: Sun, 11 Feb 2018 21:55:47 +0530 Subject: [PATCH 2/2] solver: ValidateParams skip alt src PR validation This change modifies the ValidateParams() function ignore deducing project root of projects that have an alternate source. This is needed when the project repository is not reachable and an alternate repo is used. --- gps/solver.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/gps/solver.go b/gps/solver.go index bede9d53b4..4afa713e2b 100644 --- a/gps/solver.go +++ b/gps/solver.go @@ -399,6 +399,17 @@ func (e DeductionErrs) Error() string { // ValidateParams validates the solver parameters to ensure solving can be completed. func ValidateParams(params SolveParameters, sm SourceManager) error { + // Create a list of projects to skip project root deduction. This is + // required for projects with an alternate source. + altSrc := make(map[string]bool) + if params.Manifest != nil { + for proj, prop := range params.Manifest.DependencyConstraints() { + if prop.Source != "" { + altSrc[string(proj)] = true + } + } + } + // Ensure that all packages are deducible without issues. var deducePkgsGroup sync.WaitGroup deductionErrs := make(DeductionErrs) @@ -420,6 +431,10 @@ func ValidateParams(params SolveParameters, sm SourceManager) error { } for _, ip := range rd.externalImportList(paths.IsStandardImportPath) { + if altSrc[ip] { + // Skip project root deduction for project with alternate source. + continue + } deducePkgsGroup.Add(1) go deducePkg(ip, sm) }