From 853db6cec8d449266f6382f1ecbc039a285b89d4 Mon Sep 17 00:00:00 2001 From: Fabian Wickborn Date: Fri, 17 Oct 2014 20:58:15 +0200 Subject: [PATCH] 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 --- pkg/fileembed/genfileembed/genfileembed.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pkg/fileembed/genfileembed/genfileembed.go b/pkg/fileembed/genfileembed/genfileembed.go index da47987d1..a19fb3d00 100644 --- a/pkg/fileembed/genfileembed/genfileembed.go +++ b/pkg/fileembed/genfileembed/genfileembed.go @@ -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 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")