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

Commit b40c5c1

Browse files
committed
dep: add NewManifest and add prune options
This change updates the manifest to accept a new table: prune. This table defines pruning options accepted by dep. By default, dep will always prune nested vendor directories. Three additional options can be toggled in the manifest: * non-go: Prune non-Go files (will keep LICENSE & COPYING files) * go-tests: Prune Go test files * unused-packages: Prune unused Go packages from dependencies. The implementation of these flags is not part of this commit. A constructor for dep.Manifest was also added. Signed-off-by: Ibrahim AshShohail <[email protected]>
1 parent be66afc commit b40c5c1

13 files changed

+146
-88
lines changed

Gopkg.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,8 @@
1818
[[constraint]]
1919
name = "github.com/pkg/errors"
2020
version = "0.8.0"
21+
22+
[prune]
23+
non-go = true
24+
go-tests = true
25+
unused-packages = true

cmd/dep/ensure.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -577,9 +577,8 @@ func (cmd *ensureCommand) runAdd(ctx *dep.Ctx, args []string, p *dep.Project, sm
577577

578578
// Prep post-actions and feedback from adds.
579579
var reqlist []string
580-
appender := &dep.Manifest{
581-
Constraints: make(gps.ProjectConstraints),
582-
}
580+
appender := dep.NewManifest()
581+
583582
for pr, instr := range addInstructions {
584583
for path := range instr.ephReq {
585584
reqlist = append(reqlist, path)

cmd/dep/glide_importer.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,7 @@ func (g *glideImporter) convert(pr gps.ProjectRoot) (*dep.Manifest, *dep.Lock, e
141141
task.WriteString("...")
142142
g.logger.Println(task)
143143

144-
manifest := &dep.Manifest{
145-
Constraints: make(gps.ProjectConstraints),
146-
}
144+
manifest := dep.NewManifest()
147145

148146
for _, pkg := range append(g.yaml.Imports, g.yaml.TestImports...) {
149147
pc, err := g.buildProjectConstraint(pkg)

cmd/dep/godep_importer.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,7 @@ func (g *godepImporter) load(projectDir string) error {
8888
func (g *godepImporter) convert(pr gps.ProjectRoot) (*dep.Manifest, *dep.Lock, error) {
8989
g.logger.Println("Converting from Godeps.json ...")
9090

91-
manifest := &dep.Manifest{
92-
Constraints: make(gps.ProjectConstraints),
93-
}
91+
manifest := dep.NewManifest()
9492
lock := &dep.Lock{}
9593

9694
for _, pkg := range g.json.Imports {

cmd/dep/gopath_scanner.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,9 @@ func (g *gopathScanner) InitializeRootManifestAndLock(rootM *dep.Manifest, rootL
5252
return err
5353
}
5454

55-
g.origM = &dep.Manifest{
56-
Constraints: g.pd.constraints,
57-
Ovr: make(gps.ProjectConstraints),
58-
}
55+
g.origM = dep.NewManifest()
56+
g.origM.Constraints = g.pd.constraints
57+
5958
g.origL = &dep.Lock{
6059
P: make([]gps.LockedProject, 0, len(g.pd.ondisk)),
6160
}

cmd/dep/gopath_scanner_test.go

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,14 @@ func TestGopathScanner_OverlayManifestConstraints(t *testing.T) {
2727
v1 := gps.NewVersion("v1.0.0")
2828
v2 := gps.NewVersion("v2.0.0")
2929
v3 := gps.NewVersion("v3.0.0")
30-
rootM := &dep.Manifest{
31-
Constraints: gps.ProjectConstraints{
32-
pi1.ProjectRoot: gps.ProjectProperties{Constraint: v1},
33-
},
34-
}
30+
rootM := dep.NewManifest()
31+
rootM.Constraints[pi1.ProjectRoot] = gps.ProjectProperties{Constraint: v1}
3532
rootL := &dep.Lock{}
33+
origM := dep.NewManifest()
34+
origM.Constraints[pi1.ProjectRoot] = gps.ProjectProperties{Constraint: v2}
35+
origM.Constraints[pi2.ProjectRoot] = gps.ProjectProperties{Constraint: v3}
3636
gs := gopathScanner{
37-
origM: &dep.Manifest{
38-
Constraints: gps.ProjectConstraints{
39-
pi1.ProjectRoot: gps.ProjectProperties{Constraint: v2},
40-
pi2.ProjectRoot: gps.ProjectProperties{Constraint: v3},
41-
},
42-
},
37+
origM: origM,
4338
origL: &dep.Lock{},
4439
ctx: ctx,
4540
pd: projectData{
@@ -79,7 +74,7 @@ func TestGopathScanner_OverlayLockProjects(t *testing.T) {
7974
h := test.NewHelper(t)
8075
ctx := newTestContext(h)
8176

82-
rootM := &dep.Manifest{}
77+
rootM := dep.NewManifest()
8378
pi1 := gps.ProjectIdentifier{ProjectRoot: gps.ProjectRoot(testProject1)}
8479
pi2 := gps.ProjectIdentifier{ProjectRoot: gps.ProjectRoot(testProject2)}
8580
v1 := gps.NewVersion("v1.0.0")
@@ -89,7 +84,7 @@ func TestGopathScanner_OverlayLockProjects(t *testing.T) {
8984
P: []gps.LockedProject{gps.NewLockedProject(pi1, v1, []string{})},
9085
}
9186
gs := gopathScanner{
92-
origM: &dep.Manifest{Constraints: make(gps.ProjectConstraints)},
87+
origM: dep.NewManifest(),
9388
origL: &dep.Lock{
9489
P: []gps.LockedProject{
9590
gps.NewLockedProject(pi1, v2, []string{}), // ignored, already exists in lock

cmd/dep/root_analyzer.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,7 @@ func (a *rootAnalyzer) InitializeRootManifestAndLock(dir string, pr gps.ProjectR
5252
}
5353

5454
if rootM == nil {
55-
rootM = &dep.Manifest{
56-
Constraints: make(gps.ProjectConstraints),
57-
Ovr: make(gps.ProjectConstraints),
58-
}
55+
rootM = dep.NewManifest()
5956
}
6057
if rootL == nil {
6158
rootL = &dep.Lock{}
@@ -88,7 +85,8 @@ func (a *rootAnalyzer) importManifestAndLock(dir string, pr gps.ProjectRoot, sup
8885
}
8986
}
9087

91-
var emptyManifest = &dep.Manifest{Constraints: make(gps.ProjectConstraints), Ovr: make(gps.ProjectConstraints)}
88+
var emptyManifest = dep.NewManifest()
89+
9290
return emptyManifest, nil, nil
9391
}
9492

cmd/dep/vndr_importer.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,9 @@ func (v *vndrImporter) loadVndrFile(dir string) error {
8686

8787
func (v *vndrImporter) convert(pr gps.ProjectRoot) (*dep.Manifest, *dep.Lock, error) {
8888
var (
89-
manifest = &dep.Manifest{
90-
Constraints: make(gps.ProjectConstraints),
91-
}
92-
lock = &dep.Lock{}
93-
err error
89+
manifest = dep.NewManifest()
90+
lock = &dep.Lock{}
91+
err error
9492
)
9593

9694
for _, pkg := range v.packages {

cmd/dep/vndr_importer_test.go

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -175,16 +175,13 @@ func TestVndrConfig_Import(t *testing.T) {
175175

176176
constraint, err := gps.NewSemverConstraint("^2.0.0")
177177
h.Must(err)
178-
wantM := &dep.Manifest{
179-
Constraints: gps.ProjectConstraints{
180-
"github.com/sdboyer/deptest": gps.ProjectProperties{
181-
Source: "https://github.com/sdboyer/deptest.git",
182-
Constraint: gps.Revision("3f4c3bea144e112a69bbe5d8d01c1b09a544253f"),
183-
},
184-
"github.com/sdboyer/deptestdos": gps.ProjectProperties{
185-
Constraint: constraint,
186-
},
187-
},
178+
wantM := dep.NewManifest()
179+
wantM.Constraints["github.com/sdboyer/deptest"] = gps.ProjectProperties{
180+
Source: "https://github.com/sdboyer/deptest.git",
181+
Constraint: gps.Revision("3f4c3bea144e112a69bbe5d8d01c1b09a544253f"),
182+
}
183+
wantM.Constraints["github.com/sdboyer/deptestdosdeptest"] = gps.ProjectProperties{
184+
Constraint: constraint,
188185
}
189186
if !reflect.DeepEqual(wantM, m) {
190187
t.Errorf("unexpected manifest\nhave=%+v\nwant=%+v", m, wantM)

internal/gps/prune.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright 2017 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package gps
6+
7+
// PruneOptions represents the pruning options used to write the dependecy tree.
8+
type PruneOptions uint8
9+
10+
const (
11+
// PruneNestedVendorDirs indicates if nested vendor directories should be pruned.
12+
PruneNestedVendorDirs = 1 << iota
13+
// PruneUnusedPackages indicates if unused Go packages should be pruned.
14+
PruneUnusedPackages
15+
// PruneNonGoFiles indicates if non-Go files should be pruned.
16+
// LICENSE & COPYING files are kept for convience.
17+
PruneNonGoFiles
18+
// PruneGoTestFiles indicates if Go test files should be pruned.
19+
PruneGoTestFiles
20+
)
21+
22+
var (
23+
preservedNonGoFiles = []string{
24+
"LICENSE",
25+
"COPYING",
26+
}
27+
)

0 commit comments

Comments
 (0)