Skip to content

Commit

Permalink
linker: add getpackages by filter
Browse files Browse the repository at this point in the history
  • Loading branch information
scbizu committed Mar 16, 2020
1 parent d758959 commit 613db06
Show file tree
Hide file tree
Showing 31 changed files with 5,610 additions and 0 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ require (
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/onsi/ginkgo v1.12.0 // indirect
github.com/onsi/gomega v1.9.0 // indirect
github.com/scylladb/go-set v1.0.2
github.com/sirupsen/logrus v1.0.5
github.com/spf13/cobra v0.0.2
github.com/spf13/pflag v1.0.1 // indirect
Expand Down
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ github.com/awalterschulze/gographviz v0.0.0-20190522210029-fa59802746ab h1:+cdNq
github.com/awalterschulze/gographviz v0.0.0-20190522210029-fa59802746ab/go.mod h1:GEV5wmg4YquNw7v1kkyoX9etIk8yVmXj+AkDHuuETHs=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fatih/set v0.2.1/go.mod h1:+RKtMCH+favT2+3YecHGxcc0b4KyVWA1QWWJUs4E0CI=
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM=
Expand All @@ -18,6 +19,8 @@ github.com/onsi/gomega v1.9.0 h1:R1uwffexN6Pr340GtYRIdZmAiN4J+iw6WG4wog1DUXg=
github.com/onsi/gomega v1.9.0/go.mod h1:Ho0h+IUsWyvy1OpqCwxlQ/21gkhVunqlU8fDGcoTdcA=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/scylladb/go-set v1.0.2 h1:SkvlMCKhP0wyyct6j+0IHJkBkSZL+TDzZ4E7f7BCcRE=
github.com/scylladb/go-set v1.0.2/go.mod h1:DkpGd78rljTxKAnTDPFqXSGxvETQnJyuSOQwsHycqfs=
github.com/sirupsen/logrus v1.0.5 h1:8c8b5uO0zS4X6RPl/sd1ENwSkIc0/H2PaHxE3udaE8I=
github.com/sirupsen/logrus v1.0.5/go.mod h1:pMByvHTf9Beacp5x1UXfOR9xyW/9antXMhjMPG0dEzc=
github.com/spf13/cobra v0.0.2 h1:NfkwRbgViGoyjBKsLI0QMDcuMnhM+SBg3T0cGfpvKDE=
Expand Down
42 changes: 42 additions & 0 deletions linker/linker.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"os"
"strings"

set "github.com/scylladb/go-set"
"github.com/sirupsen/logrus"
)

Expand Down Expand Up @@ -45,6 +46,47 @@ func SetLinkerLogLevel(lv logrus.Level) {
logrus.SetLevel(lv)
}

type Filter func([]string) []string

type Searcher interface {
Filt(...Filter) Searcher
List() []string
Error() error
}

type SearchFilter struct {
err error
src []string
}

func (sf *SearchFilter) Error() error { return sf.err }
func (sf *SearchFilter) List() []string { return sf.src }
func (sf *SearchFilter) Filt(fs ...Filter) Searcher {
for _, f := range fs {
sf.src = f(sf.src)
}
return sf
}

func (l *Linker) GetPackagesByFilter(allowDup bool, excludeDirs []string) Searcher {
sf := new(SearchFilter)
pkgsmap, err := l.GetAllPKGNames(allowDup, excludeDirs)
if err != nil {
sf.err = err
}
s := set.NewStringSet()
for _, pkgs := range pkgsmap {
for _, pkg := range pkgs {
if s.Has(pkg) {
continue
}
s.Add(pkg)
}
}
sf.src = s.List()
return sf
}

// GetAllPKGNames gets the full layers packages names
func (l *Linker) GetAllPKGNames(allowDup bool, excludeDirs []string) (map[string][]string, error) {

Expand Down
21 changes: 21 additions & 0 deletions vendor/github.com/scylladb/go-set/.golangci.yml

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

10 changes: 10 additions & 0 deletions vendor/github.com/scylladb/go-set/.travis.yml

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

177 changes: 177 additions & 0 deletions vendor/github.com/scylladb/go-set/LICENSE

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

38 changes: 38 additions & 0 deletions vendor/github.com/scylladb/go-set/Makefile

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

Loading

0 comments on commit 613db06

Please sign in to comment.