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

Commit

Permalink
dep: add prune options to manifests
Browse files Browse the repository at this point in the history
Signed-off-by: Ibrahim AshShohail <ibra.sho@gmail.com>
  • Loading branch information
ibrasho committed Sep 29, 2017
1 parent 9742768 commit fa76bb8
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 10 deletions.
10 changes: 10 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,21 @@
[[constraint]]
name = "github.com/boltdb/bolt"
version = "1.0.0"
[constraint.prune]
non-go = true
go-tests = true
unused-packages = true

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

[[constraint]]
name = "github.com/golang/protobuf"
branch = "master"

[prune]
non-go = true
go-tests = true
unused-packages = true
56 changes: 46 additions & 10 deletions manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,25 @@ var (
errInvalidOverride = errors.New("\"override\" must be a TOML array of tables")
errInvalidRequired = errors.New("\"required\" must be a TOML list of strings")
errInvalidIgnored = errors.New("\"ignored\" must be a TOML list of strings")
errInvalidPrune = errors.New("\"prune\" must be a TOML table of boolean values")
errInvalidProjectRoot = errors.New("ProjectRoot name validation failed")
)

// Manifest holds manifest file data and implements gps.RootManifest.
type Manifest struct {
Constraints gps.ProjectConstraints
Ovr gps.ProjectConstraints
Ignored []string
Required []string
Constraints gps.ProjectConstraints
Ovr gps.ProjectConstraints
Ignored []string
Required []string
PruneOptions gps.PruneOptions
}

type rawManifest struct {
Constraints []rawProject `toml:"constraint,omitempty"`
Overrides []rawProject `toml:"override,omitempty"`
Ignored []string `toml:"ignored,omitempty"`
Required []string `toml:"required,omitempty"`
Constraints []rawProject `toml:"constraint,omitempty"`
Overrides []rawProject `toml:"override,omitempty"`
Ignored []string `toml:"ignored,omitempty"`
Required []string `toml:"required,omitempty"`
PruneOptions rawPruneOptions `toml:"prune,omitempty"`
}

type rawProject struct {
Expand All @@ -53,11 +56,18 @@ type rawProject struct {
Source string `toml:"source,omitempty"`
}

type rawPruneOptions struct {
UnusedPackages bool `toml:"unused-packages,omitempty"`
NonGoFiles bool `toml:"non-go,omitempty"`
GoTests bool `toml:"go-tests,omitempty"`
}

// NewManifest instantites a new manifest.
func NewManifest() *Manifest {
return &Manifest{
Constraints: make(gps.ProjectConstraints),
Ovr: make(gps.ProjectConstraints),
Constraints: make(gps.ProjectConstraints),
Ovr: make(gps.ProjectConstraints),
PruneOptions: gps.PruneNestedVendorDirs,
}
}

Expand Down Expand Up @@ -150,6 +160,22 @@ func validateManifest(s string) ([]error, error) {
return warns, errInvalidRequired
}
}
case "prune":
// Check if prune is of Map type
if reflect.TypeOf(val).Kind() != reflect.Map {
warns = append(warns, errors.New("prune should be a TOML table"))
}
for key, value := range val.(map[string]interface{}) {
switch key {
case "non-go", "go-tests", "unused-packages":
if _, ok := value.(bool); !ok {
warns = append(warns, errors.Errorf("unexpected type for prune.%s: %T", key, value))
return warns, errInvalidPrune
}
default:
warns = append(warns, errors.Errorf("unknown field: prune.%s", key))
}
}
default:
warns = append(warns, fmt.Errorf("unknown field in manifest: %v", prop))
}
Expand Down Expand Up @@ -253,6 +279,16 @@ func fromRawManifest(raw rawManifest) (*Manifest, error) {
m.Ovr[name] = prj
}

if raw.PruneOptions.UnusedPackages {
m.PruneOptions |= gps.PruneUnusedPackages
}
if raw.PruneOptions.GoTests {
m.PruneOptions |= gps.PruneGoTestFiles
}
if raw.PruneOptions.NonGoFiles {
m.PruneOptions |= gps.PruneNonGoFiles
}

return m, nil
}

Expand Down
40 changes: 40 additions & 0 deletions manifest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,46 @@ func TestValidateManifest(t *testing.T) {
wantWarn: []error{errors.New("revision \"8d43f8c0b836\" should not be in abbreviated form")},
wantError: nil,
},
{
name: "valid prune options",
tomlString: `
[[constraint]]
name = "github.com/foo/bar"
version = "1.0.0"
[prune]
non-go = true
`,
wantWarn: []error{},
wantError: nil,
},
{
name: "valid prune options in constraint",
tomlString: `
[[constraint]]
name = "github.com/foo/bar"
version = "1.0.0"
[constraint.prune]
non-go = true
`,
wantWarn: []error{
errors.New("invalid key \"prune\" in \"constraint\""),
},
wantError: nil,
},
{
name: "valid inline prune options in constraint",
tomlString: `
[[constraint]]
name = "github.com/foo/bar"
version = "1.0.0"
prune = { non-go = true , go-tests = true }
`,
wantWarn: []error{
errors.New("invalid key \"prune\" in \"constraint\""),
},
wantError: nil,
},
}

// contains for error
Expand Down

0 comments on commit fa76bb8

Please sign in to comment.