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

Commit fa76bb8

Browse files
committed
dep: add prune options to manifests
Signed-off-by: Ibrahim AshShohail <[email protected]>
1 parent 9742768 commit fa76bb8

File tree

3 files changed

+96
-10
lines changed

3 files changed

+96
-10
lines changed

Gopkg.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,21 @@
2222
[[constraint]]
2323
name = "github.com/boltdb/bolt"
2424
version = "1.0.0"
25+
[constraint.prune]
26+
non-go = true
27+
go-tests = true
28+
unused-packages = true
2529

2630
[[constraint]]
2731
name = "github.com/jmank88/nuts"
2832
version = "0.2.0"
33+
prune = { non-go = true, go-tests = true, unused-packages = true }
2934

3035
[[constraint]]
3136
name = "github.com/golang/protobuf"
3237
branch = "master"
38+
39+
[prune]
40+
non-go = true
41+
go-tests = true
42+
unused-packages = true

manifest.go

Lines changed: 46 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,25 @@ var (
2727
errInvalidOverride = errors.New("\"override\" must be a TOML array of tables")
2828
errInvalidRequired = errors.New("\"required\" must be a TOML list of strings")
2929
errInvalidIgnored = errors.New("\"ignored\" must be a TOML list of strings")
30+
errInvalidPrune = errors.New("\"prune\" must be a TOML table of boolean values")
3031
errInvalidProjectRoot = errors.New("ProjectRoot name validation failed")
3132
)
3233

3334
// Manifest holds manifest file data and implements gps.RootManifest.
3435
type Manifest struct {
35-
Constraints gps.ProjectConstraints
36-
Ovr gps.ProjectConstraints
37-
Ignored []string
38-
Required []string
36+
Constraints gps.ProjectConstraints
37+
Ovr gps.ProjectConstraints
38+
Ignored []string
39+
Required []string
40+
PruneOptions gps.PruneOptions
3941
}
4042

4143
type rawManifest struct {
42-
Constraints []rawProject `toml:"constraint,omitempty"`
43-
Overrides []rawProject `toml:"override,omitempty"`
44-
Ignored []string `toml:"ignored,omitempty"`
45-
Required []string `toml:"required,omitempty"`
44+
Constraints []rawProject `toml:"constraint,omitempty"`
45+
Overrides []rawProject `toml:"override,omitempty"`
46+
Ignored []string `toml:"ignored,omitempty"`
47+
Required []string `toml:"required,omitempty"`
48+
PruneOptions rawPruneOptions `toml:"prune,omitempty"`
4649
}
4750

4851
type rawProject struct {
@@ -53,11 +56,18 @@ type rawProject struct {
5356
Source string `toml:"source,omitempty"`
5457
}
5558

59+
type rawPruneOptions struct {
60+
UnusedPackages bool `toml:"unused-packages,omitempty"`
61+
NonGoFiles bool `toml:"non-go,omitempty"`
62+
GoTests bool `toml:"go-tests,omitempty"`
63+
}
64+
5665
// NewManifest instantites a new manifest.
5766
func NewManifest() *Manifest {
5867
return &Manifest{
59-
Constraints: make(gps.ProjectConstraints),
60-
Ovr: make(gps.ProjectConstraints),
68+
Constraints: make(gps.ProjectConstraints),
69+
Ovr: make(gps.ProjectConstraints),
70+
PruneOptions: gps.PruneNestedVendorDirs,
6171
}
6272
}
6373

@@ -150,6 +160,22 @@ func validateManifest(s string) ([]error, error) {
150160
return warns, errInvalidRequired
151161
}
152162
}
163+
case "prune":
164+
// Check if prune is of Map type
165+
if reflect.TypeOf(val).Kind() != reflect.Map {
166+
warns = append(warns, errors.New("prune should be a TOML table"))
167+
}
168+
for key, value := range val.(map[string]interface{}) {
169+
switch key {
170+
case "non-go", "go-tests", "unused-packages":
171+
if _, ok := value.(bool); !ok {
172+
warns = append(warns, errors.Errorf("unexpected type for prune.%s: %T", key, value))
173+
return warns, errInvalidPrune
174+
}
175+
default:
176+
warns = append(warns, errors.Errorf("unknown field: prune.%s", key))
177+
}
178+
}
153179
default:
154180
warns = append(warns, fmt.Errorf("unknown field in manifest: %v", prop))
155181
}
@@ -253,6 +279,16 @@ func fromRawManifest(raw rawManifest) (*Manifest, error) {
253279
m.Ovr[name] = prj
254280
}
255281

282+
if raw.PruneOptions.UnusedPackages {
283+
m.PruneOptions |= gps.PruneUnusedPackages
284+
}
285+
if raw.PruneOptions.GoTests {
286+
m.PruneOptions |= gps.PruneGoTestFiles
287+
}
288+
if raw.PruneOptions.NonGoFiles {
289+
m.PruneOptions |= gps.PruneNonGoFiles
290+
}
291+
256292
return m, nil
257293
}
258294

manifest_test.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,46 @@ func TestValidateManifest(t *testing.T) {
368368
wantWarn: []error{errors.New("revision \"8d43f8c0b836\" should not be in abbreviated form")},
369369
wantError: nil,
370370
},
371+
{
372+
name: "valid prune options",
373+
tomlString: `
374+
[[constraint]]
375+
name = "github.com/foo/bar"
376+
version = "1.0.0"
377+
378+
[prune]
379+
non-go = true
380+
`,
381+
wantWarn: []error{},
382+
wantError: nil,
383+
},
384+
{
385+
name: "valid prune options in constraint",
386+
tomlString: `
387+
[[constraint]]
388+
name = "github.com/foo/bar"
389+
version = "1.0.0"
390+
[constraint.prune]
391+
non-go = true
392+
`,
393+
wantWarn: []error{
394+
errors.New("invalid key \"prune\" in \"constraint\""),
395+
},
396+
wantError: nil,
397+
},
398+
{
399+
name: "valid inline prune options in constraint",
400+
tomlString: `
401+
[[constraint]]
402+
name = "github.com/foo/bar"
403+
version = "1.0.0"
404+
prune = { non-go = true , go-tests = true }
405+
`,
406+
wantWarn: []error{
407+
errors.New("invalid key \"prune\" in \"constraint\""),
408+
},
409+
wantError: nil,
410+
},
371411
}
372412

373413
// contains for error

0 commit comments

Comments
 (0)