From f813d1c931997741c88c6abf48e74a04cf0e26fd Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Thu, 19 Sep 2013 17:27:54 +0200 Subject: [PATCH] Added support for build tags with the -tags flag --- README.md | 10 ++++++++++ main.go | 5 +++++ 2 files changed, 15 insertions(+) diff --git a/README.md b/README.md index be4993f..4db2921 100644 --- a/README.md +++ b/README.md @@ -161,3 +161,13 @@ package $PACKAGENAME // supplied to go-bindata. var go_bindata = make(map[string] func() []byte) ``` + +#### Build tags + +With the optional -tags flag, you can specify any go build tags that +must be fulfilled for the output file to be included in a build. This +is useful for including binary data in multiple formats, where the desired +format is specified at build time with the appropriate tag(s). + +The tags are appended to a `// +build` line in the beginning of the output file +and must follow the build tags syntax specified by the go tool. diff --git a/main.go b/main.go index 3541d92..718edd6 100644 --- a/main.go +++ b/main.go @@ -24,6 +24,7 @@ var ( prefix = flag.String("prefix", "", "Optional path prefix to strip off map keys and function names.") uncompressed = flag.Bool("uncompressed", false, "The specified resource will /not/ be GZIP compressed when this flag is specified. This alters the generated output code.") nomemcopy = flag.Bool("nomemcopy", false, "Use a .rodata hack to get rid of unnecessary memcopies. Refer to the documentation to see what implications this carries.") + tags = flag.String("tags", "", "Optional build tags") toc = flag.Bool("toc", false, "Generate a table of contents for this and other files. The input filepath becomes the map key. This option is only useable in non-pipe mode.") version = flag.Bool("version", false, "Display version information.") regFuncName = regexp.MustCompile(`[^a-zA-Z0-9_]`) @@ -53,6 +54,10 @@ func main() { defer fd.Close() + if *tags != "" { + fmt.Fprintf(fd, "// +build %s\n\n", *tags) + } + // Translate binary to Go code. translate(fs, fd, *pkgname, *funcname, *uncompressed, *nomemcopy)