github.com/please-build/go-rules/tools/please_go@v0.0.0-20240319165128-ea27d6f5caba/filter/filter.go (about) 1 package filter 2 3 import ( 4 "fmt" 5 "go/build" 6 "os" 7 "path/filepath" 8 "strings" 9 ) 10 11 12 func Filter(tags []string, srcs []string) { 13 ctxt := build.Default 14 ctxt.BuildTags = tags 15 16 for _, f := range srcs { 17 dir, file := filepath.Split(f) 18 19 // MatchFile skips _ prefixed files by default, assuming they're editor 20 // temporary files - but we need to include cgo generated files. 21 if strings.HasPrefix(file, "_cgo_") { 22 fmt.Println(f) 23 continue 24 } 25 26 ok, err := ctxt.MatchFile(dir, file) 27 if err != nil { 28 fmt.Fprintf(os.Stderr, "Error checking %v: %v\n", f, err) 29 os.Exit(1) 30 } 31 32 if ok { 33 fmt.Println(f) 34 } 35 } 36 }