1
0
mirror of https://github.com/prometheus-community/postgres_exporter.git synced 2025-08-08 04:42:07 +03:00

Add cross-compilation Makefile targets and tar-based releases.

Revamp the build system to be more inline with other Prometheus exporters.
Notably add Darwin and Windows build targets, and add support for releases
using tar files.
This commit is contained in:
Will Rouesnel
2017-11-30 03:15:53 +11:00
parent 61b93a17a6
commit 5b9fea01ee
98 changed files with 10599 additions and 1487 deletions

View File

@@ -12,7 +12,7 @@ import (
"strings"
"github.com/mibk/dupl/job"
"github.com/mibk/dupl/output"
"github.com/mibk/dupl/printer"
"github.com/mibk/dupl/syntax"
)
@@ -20,18 +20,18 @@ const defaultThreshold = 15
var (
paths = []string{"."}
vendor = flag.Bool("vendor", false, "check files in vendor directory")
verbose = flag.Bool("verbose", false, "explain what is being done")
threshold = flag.Int("threshold", defaultThreshold, "minimum token sequence as a clone")
files = flag.Bool("files", false, "files names from stdin")
vendor = flag.Bool("vendor", false, "")
verbose = flag.Bool("verbose", false, "")
threshold = flag.Int("threshold", defaultThreshold, "")
files = flag.Bool("files", false, "")
html = flag.Bool("html", false, "html output")
plumbing = flag.Bool("plumbing", false, "plumbing output for consumption by scripts or tools")
html = flag.Bool("html", false, "")
plumbing = flag.Bool("plumbing", false, "")
)
const (
vendorDirPrefix = "vendor" + string(filepath.Separator)
vendorDirInPath = string(filepath.Separator) + "vendor" + string(filepath.Separator)
vendorDirInPath = string(filepath.Separator) + vendorDirPrefix
)
func init() {
@@ -39,43 +39,6 @@ func init() {
flag.IntVar(threshold, "t", defaultThreshold, "alias for -threshold")
}
func usage() {
fmt.Fprintln(os.Stderr, `Usage of dupl:
dupl [flags] [paths]
Paths:
If the given path is a file, dupl will use it regardless of
the file extension. If it is a directory it will recursively
search for *.go files in that directory.
If no path is given dupl will recursively search for *.go
files in the current directory.
Flags:
-files
read file names from stdin one at each line
-html
output the results as HTML, including duplicate code fragments
-plumbing
plumbing (easy-to-parse) output for consumption by scripts or tools
-t, -threshold size
minimum token sequence size as a clone (default 15)
-vendor
check files in vendor directory
-v, -verbose
explain what is being done
Examples:
dupl -t 100
Search clones in the current directory of size at least
100 tokens.
dupl $(find app/ -name '*_test.go')
Search for clones in tests in the app directory.
find app/ -name '*_test.go' |dupl -files
The same as above.`)
os.Exit(2)
}
func main() {
flag.Usage = usage
flag.Parse()
@@ -110,7 +73,17 @@ func main() {
}
close(duplChan)
}()
printDupls(duplChan)
newPrinter := printer.NewText
if *html {
newPrinter = printer.NewHTML
} else if *plumbing {
newPrinter = printer.NewPlumbing
}
p := newPrinter(os.Stdout, ioutil.ReadFile)
if err := printDupls(p, duplChan); err != nil {
log.Fatal(err)
}
}
func filesFeed() chan string {
@@ -120,10 +93,7 @@ func filesFeed() chan string {
s := bufio.NewScanner(os.Stdin)
for s.Scan() {
f := s.Text()
if strings.HasPrefix(f, "./") {
f = f[2:]
}
fchan <- f
fchan <- strings.TrimPrefix(f, "./")
}
close(fchan)
}()
@@ -160,7 +130,7 @@ func crawlPaths(paths []string) chan string {
return fchan
}
func printDupls(duplChan <-chan syntax.Match) {
func printDupls(p printer.Printer, duplChan <-chan syntax.Match) error {
groups := make(map[string][][]*syntax.Node)
for dupl := range duplChan {
groups[dupl.Hash] = append(groups[dupl.Hash], dupl.Frags...)
@@ -171,32 +141,18 @@ func printDupls(duplChan <-chan syntax.Match) {
}
sort.Strings(keys)
p := getPrinter()
if err := p.PrintHeader(); err != nil {
return err
}
for _, k := range keys {
uniq := unique(groups[k])
if len(uniq) > 1 {
if err := p.Print(uniq); err != nil {
log.Fatal(err)
if err := p.PrintClones(uniq); err != nil {
return err
}
}
}
p.Finish()
}
func getPrinter() output.Printer {
var fr fileReader
if *html {
return output.NewHTMLPrinter(os.Stdout, fr)
} else if *plumbing {
return output.NewPlumbingPrinter(os.Stdout, fr)
}
return output.NewTextPrinter(os.Stdout, fr)
}
type fileReader struct{}
func (fileReader) ReadFile(filename string) ([]byte, error) {
return ioutil.ReadFile(filename)
return p.PrintFooter()
}
func unique(group [][]*syntax.Node) [][]*syntax.Node {
@@ -217,3 +173,39 @@ func unique(group [][]*syntax.Node) [][]*syntax.Node {
}
return newGroup
}
func usage() {
fmt.Fprintln(os.Stderr, `Usage: dupl [flags] [paths]
Paths:
If the given path is a file, dupl will use it regardless of
the file extension. If it is a directory, it will recursively
search for *.go files in that directory.
If no path is given, dupl will recursively search for *.go
files in the current directory.
Flags:
-files
read file names from stdin one at each line
-html
output the results as HTML, including duplicate code fragments
-plumbing
plumbing (easy-to-parse) output for consumption by scripts or tools
-t, -threshold size
minimum token sequence size as a clone (default 15)
-vendor
check files in vendor directory
-v, -verbose
explain what is being done
Examples:
dupl -t 100
Search clones in the current directory of size at least
100 tokens.
dupl $(find app/ -name '*_test.go')
Search for clones in tests in the app directory.
find app/ -name '*_test.go' |dupl -files
The same as above.`)
os.Exit(2)
}