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

Enable glob syntax (/...) in ignored packages #709

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

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,5 @@
ignored = ["./samples/..."]

[[constraint]]
branch = "master"
name = "github.com/sdboyer/deptest"

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,5 @@
ignored = ["./samples/..."]

[[constraint]]
branch = "master"
name = "github.com/sdboyer/deptest"
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 samples

import _ "github.com/sdboyer/dep-test"
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"commands": [
["ensure"]
],
"error-expected": "",
"vendor-final": [
"github.com/sdboyer/deptest"
]
}

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,5 @@
ignored = ["./samples", "github.com/Sirupsen/logrus"]

[[constraint]]
branch = "master"
name = "github.com/sdboyer/deptest"

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,5 @@
ignored = ["./samples", "github.com/Sirupsen/logrus"]

[[constraint]]
branch = "master"
name = "github.com/sdboyer/deptest"
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 samples

import _ "github.com/sdboyer/dep-test"
10 changes: 10 additions & 0 deletions cmd/dep/testdata/harness_tests/ensure/empty/case5/testcase.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"commands": [
["ensure"]
],
"error-expected": "",
"vendor-final": [
"github.com/sdboyer/dep-test",
"github.com/sdboyer/deptest"
]
}
4 changes: 2 additions & 2 deletions internal/gps/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ type RootManifest interface {
//
// It is an error to include a package in both the ignored and required
// sets.
IgnoredPackages() map[string]bool
IgnoredPackages(SolveParameters) map[string]bool

// 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 @@ -103,7 +103,7 @@ func (m simpleRootManifest) TestDependencyConstraints() ProjectConstraints {
func (m simpleRootManifest) Overrides() ProjectConstraints {
return m.ovr
}
func (m simpleRootManifest) IgnoredPackages() map[string]bool {
func (m simpleRootManifest) IgnoredPackages(SolveParameters) map[string]bool {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whatever route we take to accomplishing this goal, this interface needs to remain unchanged. In particular, we don't want to muddy the waters around SolveParameters by reusing it in this way.

return m.ig
}
func (m simpleRootManifest) RequiredPackages() map[string]bool {
Expand Down
2 changes: 1 addition & 1 deletion internal/gps/solver.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ func (params SolveParameters) toRootdata() (rootdata, error) {
}

rd := rootdata{
ig: params.Manifest.IgnoredPackages(),
ig: params.Manifest.IgnoredPackages(params),
req: params.Manifest.RequiredPackages(),
ovr: params.Manifest.Overrides(),
rpt: params.RootPackageTree.Copy(),
Expand Down
38 changes: 36 additions & 2 deletions manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@ import (
"bytes"
"fmt"
"io"
"path/filepath"
"reflect"
"regexp"
"sort"
"strings"

"github.com/golang/dep/internal/gps"
"github.com/golang/dep/internal/gps/pkgtree"
"github.com/pelletier/go-toml"
"github.com/pkg/errors"
)
Expand Down Expand Up @@ -282,14 +285,45 @@ func (m *Manifest) Overrides() gps.ProjectConstraints {
}

// IgnoredPackages returns a set of import paths to ignore.
func (m *Manifest) IgnoredPackages() map[string]bool {
func (m *Manifest) IgnoredPackages(solveParam gps.SolveParameters) map[string]bool {
if len(m.Ignored) == 0 {
return nil
}

mp := make(map[string]bool, len(m.Ignored))
for _, i := range m.Ignored {
mp[i] = true
// Check if it's a local package path
if strings.HasPrefix(i, "./") {
// Clean ./ from path
i = filepath.Clean(i)
rootPkgT := solveParam.RootPackageTree

// Check if the path has glob syntax (/...)
if strings.HasSuffix(i, "/...") {
dir := filepath.Dir(i)
pkgT, _ := pkgtree.ListPackages(filepath.Join(solveParam.RootDir, dir), dir)

// Ignore root packages found in package tree of ignored package
for p := range pkgT.Packages {
for rp := range solveParam.RootPackageTree.Packages {
if strings.HasSuffix(rp, filepath.Join(rootPkgT.ImportRoot, p)) {
mp[rp] = true
break
}
}
}
} else {
// Ignore root package found in local ignored package
for rp := range solveParam.RootPackageTree.Packages {
if strings.HasSuffix(rp, filepath.Join(rootPkgT.ImportRoot, i)) {
mp[rp] = true
break
}
}
}
} else {
mp[i] = true
}
}

return mp
Expand Down