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

Commit

Permalink
Merge pull request #1268 from sdboyer/ignore-trie
Browse files Browse the repository at this point in the history
Introduce IgnoredRuleset
  • Loading branch information
sdboyer authored Oct 14, 2017
2 parents 7d9726b + da9b750 commit 31dfa52
Show file tree
Hide file tree
Showing 29 changed files with 463 additions and 333 deletions.
8 changes: 6 additions & 2 deletions cmd/dep/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,12 @@ func testIntegration(name, relPath, wd string, run integration.RunFunc) func(t *
// Check error raised in final command
testCase.CompareError(err, testProj.GetStderr())

// Check output
testCase.CompareOutput(testProj.GetStdout())
if *test.UpdateGolden {
testCase.UpdateOutput(testProj.GetStdout())
} else {
// Check output
testCase.CompareOutput(testProj.GetStdout())
}

// Check vendor paths
testProj.CompareImportPaths()
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
-CONSTRAINTS-
github.com/sdboyer/deptest
b-master
-IMPORTS/REQS-
github.com/sdboyer/deptest
-IGNORES-
-OVERRIDES-
-ANALYZER-
dep
1

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"commands": [
["ensure"]
["ensure"],
["hash-inputs"]
],
"error-expected": "",
"vendor-final": [
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ignored = ["github.com/sdboyer/deptest*", "github.com/golang/notexist/samples*"]

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ignored = ["github.com/sdboyer/deptest*", "github.com/golang/notexist/samples*"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright 2017 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package main

import (
_ "github.com/sdboyer/deptest"
)

func main() {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Copyright 2017 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package samples

import _ "github.com/sdboyer/deptestdos"
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Copyright 2017 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package subsamples

import _ "github.com/sdboyer/dep-test"
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
-CONSTRAINTS-
-IMPORTS/REQS-
-IGNORES-
github.com/sdboyer/deptest*
-OVERRIDES-
-ANALYZER-
dep
1

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"commands": [
["ensure"],
["hash-inputs"]
],
"error-expected": "",
"vendor-final": []
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ignored = ["github.com/sdboyer/dep-test","github.com/golang/notexist/samples"]
ignored = ["github.com/golang/notexist/samples","github.com/sdboyer/dep-test"]

[[constraint]]
name = "github.com/carolynvs/deptest-subpkg"
Expand Down
30 changes: 7 additions & 23 deletions internal/gps/hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ import (
"strings"
)

const wcIgnoreSuffix = "*"

// string headers used to demarcate sections in hash input creation
const (
hhConstraints = "-CONSTRAINTS-"
Expand Down Expand Up @@ -81,30 +79,16 @@ func (s *solver) writeHashingInputs(w io.Writer) {
// those will have already been implicitly incorporated by the import
// lister.
writeString(hhIgnores)
ig := make([]string, 0, len(s.rd.ig))
for pkg := range s.rd.ig {
// Skip wildcard ignore. They are handled separately below.
if strings.HasSuffix(pkg, wcIgnoreSuffix) {
continue
}

if !strings.HasPrefix(pkg, s.rd.rpt.ImportRoot) || !isPathPrefixOrEqual(s.rd.rpt.ImportRoot, pkg) {
ig = append(ig, pkg)
}
}

// Add wildcard ignores to ignore list.
if s.rd.igpfx != nil {
s.rd.igpfx.Walk(func(s string, v interface{}) bool {
ig = append(ig, s+"*")
return false
})
}

ig := s.rd.ir.ToSlice()
sort.Strings(ig)

for _, igp := range ig {
writeString(igp)
// Typical prefix comparison checks will erroneously fail if the wildcard
// is present. Trim it off, if present.
tigp := strings.TrimSuffix(igp, "*")
if !strings.HasPrefix(tigp, s.rd.rpt.ImportRoot) || !isPathPrefixOrEqual(s.rd.rpt.ImportRoot, tigp) {
writeString(igp)
}
}

// Overrides *also* need their own special entry distinct from basic
Expand Down
19 changes: 9 additions & 10 deletions internal/gps/hash_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
"strings"
"testing"
"text/tabwriter"

"github.com/golang/dep/internal/gps/pkgtree"
)

func TestHashInputs(t *testing.T) {
Expand Down Expand Up @@ -64,10 +66,7 @@ func TestHashInputsReqsIgs(t *testing.T) {
fix := basicFixtures["shared dependency with overlapping constraints"]

rm := fix.rootmanifest().(simpleRootManifest).dup()
rm.ig = map[string]bool{
"foo": true,
"bar": true,
}
rm.ig = pkgtree.NewIgnoredRuleset([]string{"foo", "bar"})

params := SolveParameters{
RootDir: string(fix.ds[0].n),
Expand Down Expand Up @@ -611,7 +610,7 @@ func TestHashInputsIneffectualWildcardIgs(t *testing.T) {

cases := []struct {
name string
ignoreMap map[string]bool
ignoreMap []string
elems []string
}{
{
Expand All @@ -634,10 +633,10 @@ func TestHashInputsIneffectualWildcardIgs(t *testing.T) {
},
{
name: "different wildcard ignores",
ignoreMap: map[string]bool{
"foobar*": true,
"foobarbaz*": true,
"foozapbar*": true,
ignoreMap: []string{
"foobar*",
"foobarbaz*",
"foozapbar*",
},
elems: []string{
hhConstraints,
Expand All @@ -662,7 +661,7 @@ func TestHashInputsIneffectualWildcardIgs(t *testing.T) {
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {

rm.ig = c.ignoreMap
rm.ig = pkgtree.NewIgnoredRuleset(c.ignoreMap)

params.Manifest = rm

Expand Down
27 changes: 15 additions & 12 deletions internal/gps/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

package gps

import "github.com/golang/dep/internal/gps/pkgtree"

// Manifest represents manifest-type data for a project at a particular version.
// The constraints expressed in a manifest determine the set of versions that
// are acceptable to try for a given project.
Expand Down Expand Up @@ -36,14 +38,15 @@ type RootManifest interface {
// them can harm the ecosystem as a whole.
Overrides() ProjectConstraints

// IngoredPackages returns a set of import paths to ignore. These import
// paths can be within the root project, or part of other projects. Ignoring
// a package means that both it and its (unique) imports will be disregarded
// by all relevant solver operations.
// IngoredPackages returns a pkgtree.IgnoredRuleset, which comprises a set
// of import paths, or import path patterns, that are to be ignored during
// solving. These ignored import paths can be within the root project, or
// part of other projects. Ignoring a package means that both it and its
// (unique) imports will be disregarded by all relevant solver operations.
//
// It is an error to include a package in both the ignored and required
// sets.
IgnoredPackages() map[string]bool
IgnoredPackages() *pkgtree.IgnoredRuleset

// RequiredPackages returns a set of import paths to require. These packages
// are required to be present in any solution. The list can include main
Expand Down Expand Up @@ -76,8 +79,9 @@ func (m SimpleManifest) DependencyConstraints() ProjectConstraints {
// simpleRootManifest exists so that we have a safe value to swap into solver
// params when a nil Manifest is provided.
type simpleRootManifest struct {
c, ovr ProjectConstraints
ig, req map[string]bool
c, ovr ProjectConstraints
ig *pkgtree.IgnoredRuleset
req map[string]bool
}

func (m simpleRootManifest) DependencyConstraints() ProjectConstraints {
Expand All @@ -86,7 +90,7 @@ func (m simpleRootManifest) DependencyConstraints() ProjectConstraints {
func (m simpleRootManifest) Overrides() ProjectConstraints {
return m.ovr
}
func (m simpleRootManifest) IgnoredPackages() map[string]bool {
func (m simpleRootManifest) IgnoredPackages() *pkgtree.IgnoredRuleset {
return m.ig
}
func (m simpleRootManifest) RequiredPackages() map[string]bool {
Expand All @@ -96,7 +100,6 @@ func (m simpleRootManifest) dup() simpleRootManifest {
m2 := simpleRootManifest{
c: make(ProjectConstraints, len(m.c)),
ovr: make(ProjectConstraints, len(m.ovr)),
ig: make(map[string]bool, len(m.ig)),
req: make(map[string]bool, len(m.req)),
}

Expand All @@ -106,13 +109,13 @@ func (m simpleRootManifest) dup() simpleRootManifest {
for k, v := range m.ovr {
m2.ovr[k] = v
}
for k, v := range m.ig {
m2.ig[k] = v
}
for k, v := range m.req {
m2.req[k] = v
}

// IgnoredRulesets are immutable, and safe to reuse.
m2.ig = m.ig

return m2
}

Expand Down
Loading

0 comments on commit 31dfa52

Please sign in to comment.