genfileembed: Add flag for adding build tags

The build tags are written into the resulting go files literally, e.g.
a call like

    genfileembed -build-tags "linux,386 darwin,!cgo"

is written as

// +build linux,386 darwin,!cgo

to the resulting files.

Change-Id: Ic8c7e827e3040a33fe3b920c1aaa1551f902a491
This commit is contained in:
Fabian Wickborn 2014-10-17 20:58:15 +02:00
parent 119b38966a
commit 853db6cec8
1 changed files with 7 additions and 1 deletions

View File

@ -51,6 +51,8 @@ var (
destFilesStderr = flag.Bool("output-files-stderr", false, "Write the absolute path of all output files to stderr prefixed with OUTPUT:")
patternFilename = flag.String("pattern-file", "fileembed.go", "Filepath relative to <dir> from which to read the #fileembed pattern")
buildTags = flag.String("build-tags", "", "Add these tags as +build constraints to the resulting zembed_*.go files")
)
const (
@ -151,7 +153,11 @@ func main() {
var b bytes.Buffer
fmt.Fprintf(&b, "// THIS FILE IS AUTO-GENERATED FROM %s\n", fileName)
fmt.Fprintf(&b, "// DO NOT EDIT.\n\n")
fmt.Fprintf(&b, "// DO NOT EDIT.\n")
if *buildTags != "" {
fmt.Fprintf(&b, "// +build %s\n", *buildTags)
}
fmt.Fprintf(&b, "\n")
fmt.Fprintf(&b, "package %s\n\n", pkgName)
fmt.Fprintf(&b, "import \"time\"\n\n")
fmt.Fprintf(&b, "import \""+*fileEmbedPkgPath+"\"\n\n")