Skip to content

Commit

Permalink
go-fuzz-build: added support for '-tags'
Browse files Browse the repository at this point in the history
  • Loading branch information
obscuren committed Feb 14, 2017
1 parent af3f5df commit 65a9ad3
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions go-fuzz-build/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
)

var (
flagTag = flag.String("tags", "", "a space-separated list of build tags to consider satisfied during the build.")
flagOut = flag.String("o", "", "output file")
flagFunc = flag.String("func", "Fuzz", "entry function")
flagWork = flag.Bool("work", false, "don't remove working directory")
Expand All @@ -32,6 +33,14 @@ var (
GOROOT string
)

func makeTags() string {
tags := "gofuzz"
if len(*flagTag) > 0 {
tags += " " + *flagTag
}
return tags
}

// Copies the package with all dependent packages into a temp dir,
// instruments Go source files there and builds setting GOROOT to the temp dir.
func main() {
Expand Down Expand Up @@ -136,7 +145,7 @@ func testNormalBuild(pkg string) {
}()
copyFuzzDep(workdir, false)
mainPkg := createFuzzMain(pkg)
cmd := exec.Command("go", "build", "-tags", "gofuzz", "-o", filepath.Join(workdir, "bin"), mainPkg)
cmd := exec.Command("go", "build", "-tags", makeTags(), "-o", filepath.Join(workdir, "bin"), mainPkg)
for _, v := range os.Environ() {
if strings.HasPrefix(v, "GOPATH") {
continue
Expand Down Expand Up @@ -202,7 +211,7 @@ func buildInstrumentedBinary(pkg string, deps map[string]bool, lits map[Literal]
outf := tempFile()
os.Remove(outf)
outf += ".exe"
cmd := exec.Command("go", "build", "-tags", "gofuzz", "-o", outf, mainPkg)
cmd := exec.Command("go", "build", "-tags", makeTags(), "-o", outf, mainPkg)
for _, v := range os.Environ() {
if strings.HasPrefix(v, "GOROOT") || strings.HasPrefix(v, "GOPATH") {
continue
Expand Down Expand Up @@ -435,7 +444,7 @@ func copyDir(dir, newDir string, rec bool, pred func(string) bool) {

func goListList(pkg, what string) []string {
templ := fmt.Sprintf("{{range .%v}}{{.}}|{{end}}", what)
out, err := exec.Command("go", "list", "-tags", "gofuzz", "-f", templ, pkg).CombinedOutput()
out, err := exec.Command("go", "list", "-tags", makeTags(), "-f", templ, pkg).CombinedOutput()
if err != nil {
failf("failed to execute 'go list -f \"%v\" %v': %v\n%v", templ, pkg, err, string(out))
}
Expand All @@ -451,7 +460,7 @@ func goListProps(pkg string, props ...string) []string {
for _, p := range props {
templ += fmt.Sprintf("{{.%v}}|", p)
}
out, err := exec.Command("go", "list", "-tags", "gofuzz", "-f", templ, pkg).CombinedOutput()
out, err := exec.Command("go", "list", "-tags", makeTags(), "-f", templ, pkg).CombinedOutput()
if err != nil {
failf("failed to execute 'go list -f \"%v\" %v': %v\n%v", templ, pkg, err, string(out))
}
Expand All @@ -464,7 +473,7 @@ func goListProps(pkg string, props ...string) []string {

func goListBool(pkg, what string) bool {
templ := fmt.Sprintf("{{.%v}}", what)
out, err := exec.Command("go", "list", "-tags", "gofuzz", "-f", templ, pkg).CombinedOutput()
out, err := exec.Command("go", "list", "-tags", makeTags(), "-f", templ, pkg).CombinedOutput()
if err != nil {
failf("failed to execute 'go list -f \"%v\" %v': %v\n%v", templ, pkg, err, string(out))
}
Expand Down

0 comments on commit 65a9ad3

Please sign in to comment.