Removes output of both debug and release code. There really
is no point to this. All output (including TOC) is now written to a single output file. This allows us to have different output file names to be specified. Each for a different version generated code with its own build tags. Consequently offering much greater flexibility in the way generated code is to be used in a host application. Fixes test outputs to match all these changes.
This commit is contained in:
parent
12a480432a
commit
cca9f8e6b7
2
asset.go
2
asset.go
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
package bindata
|
package bindata
|
||||||
|
|
||||||
// File is an asset entry for the table of contents.
|
// Asset holds information about a single asset to be processed.
|
||||||
type Asset struct {
|
type Asset struct {
|
||||||
Path string // Full file path.
|
Path string // Full file path.
|
||||||
Name string // Key used in TOC -- name by which asset is referenced.
|
Name string // Key used in TOC -- name by which asset is referenced.
|
||||||
|
|
65
config.go
65
config.go
|
@ -4,6 +4,12 @@
|
||||||
|
|
||||||
package bindata
|
package bindata
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
)
|
||||||
|
|
||||||
// Config defines a set of options for the asset conversion.
|
// Config defines a set of options for the asset conversion.
|
||||||
type Config struct {
|
type Config struct {
|
||||||
// Name of the package to use. Defaults to 'main'.
|
// Name of the package to use. Defaults to 'main'.
|
||||||
|
@ -20,7 +26,9 @@ type Config struct {
|
||||||
// conversion.
|
// conversion.
|
||||||
Input string
|
Input string
|
||||||
|
|
||||||
// Output defines the output directory for the generated code.
|
// Output defines the output file for the generated code.
|
||||||
|
// If left empty, this defaults to 'bindata.go' in the current
|
||||||
|
// working directory.
|
||||||
Output string
|
Output string
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -87,11 +95,22 @@ type Config struct {
|
||||||
NoMemCopy bool
|
NoMemCopy bool
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Compress means the assets are GZIP compressed before being turned
|
NoCompress means the assets are /not/ GZIP compressed before being turned
|
||||||
into Go code. The generated function will automatically unzip
|
into Go code. The generated function will automatically unzip
|
||||||
the file data when called. Defaults to true.
|
the file data when called. Defaults to true.
|
||||||
*/
|
*/
|
||||||
Compress bool
|
NoCompress bool
|
||||||
|
|
||||||
|
// Perform a debug build. This generates an asset file, which
|
||||||
|
// loads the asset contents directly from disk at their original
|
||||||
|
// location, instead of embedding the contents in the code.
|
||||||
|
//
|
||||||
|
// This is mostly useful if you anticipate that the assets are
|
||||||
|
// going to change during your development cycle. You will always
|
||||||
|
// want your code to access the latest version of the asset.
|
||||||
|
// Only in release mode, will the assets actually be embedded
|
||||||
|
// in the code. The default behaviour is Release mode.
|
||||||
|
Debug bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewConfig returns a default configuration struct.
|
// NewConfig returns a default configuration struct.
|
||||||
|
@ -99,6 +118,44 @@ func NewConfig() *Config {
|
||||||
c := new(Config)
|
c := new(Config)
|
||||||
c.Package = "main"
|
c.Package = "main"
|
||||||
c.NoMemCopy = false
|
c.NoMemCopy = false
|
||||||
c.Compress = true
|
c.NoCompress = false
|
||||||
|
c.Debug = false
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// validate ensures the config has sane values.
|
||||||
|
// Part of which means checking if certain file/directory paths exist.
|
||||||
|
func (c *Config) validate() error {
|
||||||
|
if len(c.Package) == 0 {
|
||||||
|
return fmt.Errorf("Missing package name")
|
||||||
|
}
|
||||||
|
|
||||||
|
stat, err := os.Lstat(c.Input)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Input path: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !stat.IsDir() {
|
||||||
|
return fmt.Errorf("Input path is not a directory.")
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(c.Output) == 0 {
|
||||||
|
cwd, err := os.Getwd()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Unable to determine current working directory.")
|
||||||
|
}
|
||||||
|
|
||||||
|
c.Output = filepath.Join(cwd, "bindata.go")
|
||||||
|
}
|
||||||
|
|
||||||
|
stat, err = os.Lstat(c.Output)
|
||||||
|
if err != nil && !os.IsNotExist(err) {
|
||||||
|
return fmt.Errorf("Output path: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if stat != nil && stat.IsDir() {
|
||||||
|
return fmt.Errorf("Output path is a directory.")
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
53
convert.go
53
convert.go
|
@ -13,38 +13,59 @@ import (
|
||||||
"unicode"
|
"unicode"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ProgressFunc is a callback handler which is fired whenever
|
|
||||||
// bindata begins translating a new file.
|
|
||||||
//
|
|
||||||
// It takes the file path and the current and total file counts.
|
|
||||||
// This can be used to indicate progress of the conversion.
|
|
||||||
//
|
|
||||||
// If this handler returns true, the processing is stopped and
|
|
||||||
// Translate() returns immediately.
|
|
||||||
type ProgressFunc func(file string, current, total int) bool
|
|
||||||
|
|
||||||
// Translate reads assets from an input directory, converts them
|
// Translate reads assets from an input directory, converts them
|
||||||
// to Go code and writes new files to the output directory specified
|
// to Go code and writes new files to the output file specified
|
||||||
// in the given configuration.
|
// in the given configuration.
|
||||||
func Translate(c *Config, pf ProgressFunc) error {
|
func Translate(c *Config) error {
|
||||||
var toc []Asset
|
var toc []Asset
|
||||||
|
|
||||||
err := findFiles(c.Input, c.Prefix, &toc)
|
// Ensure our configuration has sane values.
|
||||||
|
err := c.validate()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = writeDebug(c, toc)
|
// Locate all the assets.
|
||||||
|
err = findFiles(c.Input, c.Prefix, &toc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = writeRelease(c, toc)
|
// Create output file.
|
||||||
|
fd, err := os.Create(c.Output)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return writeTOC(c, toc)
|
defer fd.Close()
|
||||||
|
|
||||||
|
// Write build tags, if applicable.
|
||||||
|
if len(c.Tags) > 0 {
|
||||||
|
_, err = fmt.Fprintf(fd, "// +build %s\n\n", c.Tags)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Write package declaration.
|
||||||
|
_, err = fmt.Fprintf(fd, "package %s\n\n", c.Package)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Write assets.
|
||||||
|
if c.Debug {
|
||||||
|
err = writeDebug(fd, toc)
|
||||||
|
} else {
|
||||||
|
err = writeRelease(fd, c, toc)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Write table of contents
|
||||||
|
return writeTOC(fd, toc)
|
||||||
}
|
}
|
||||||
|
|
||||||
// fillTOC recursively finds all the file paths in the given directory tree.
|
// fillTOC recursively finds all the file paths in the given directory tree.
|
||||||
|
|
51
debug.go
51
debug.go
|
@ -7,26 +7,17 @@ package bindata
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
|
||||||
"path/filepath"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// writeDebug writes the debug code file.
|
// writeDebug writes the debug code file.
|
||||||
func writeDebug(c *Config, toc []Asset) error {
|
func writeDebug(w io.Writer, toc []Asset) error {
|
||||||
fd, err := os.Create(filepath.Join(c.Output, "bindata_debug.go"))
|
err := writeDebugHeader(w)
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
defer fd.Close()
|
|
||||||
|
|
||||||
err = writeDebugHeader(fd, c)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := range toc {
|
for i := range toc {
|
||||||
err = writeDebugAsset(fd, c, &toc[i])
|
err = writeDebugAsset(w, &toc[i])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -37,30 +28,8 @@ func writeDebug(c *Config, toc []Asset) error {
|
||||||
|
|
||||||
// writeDebugHeader writes output file headers.
|
// writeDebugHeader writes output file headers.
|
||||||
// This targets debug builds.
|
// This targets debug builds.
|
||||||
func writeDebugHeader(w io.Writer, c *Config) error {
|
func writeDebugHeader(w io.Writer) error {
|
||||||
var err error
|
_, err := fmt.Fprintf(w, `import (
|
||||||
|
|
||||||
// Write build tags, if applicable.
|
|
||||||
if len(c.Tags) > 0 {
|
|
||||||
_, err = fmt.Fprintf(w, "// +build !release %s\n\n", c.Tags)
|
|
||||||
} else {
|
|
||||||
_, err = fmt.Fprintf(w, "// +build !release\n\n")
|
|
||||||
}
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Write package declaration
|
|
||||||
_, err = fmt.Fprintf(w, "package %s\n\n", c.Package)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Define packages we need to import.
|
|
||||||
// And add the asset_read function. This is called
|
|
||||||
// from asset-specific functions.
|
|
||||||
_, err = fmt.Fprintf(w, `import (
|
|
||||||
"bytes"
|
"bytes"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
|
@ -93,14 +62,16 @@ func bindata_read(path, name string) []byte {
|
||||||
// writeDebugAsset write a debug entry for the given asset.
|
// writeDebugAsset write a debug entry for the given asset.
|
||||||
// A debug entry is simply a function which reads the asset from
|
// A debug entry is simply a function which reads the asset from
|
||||||
// the original file (e.g.: from disk).
|
// the original file (e.g.: from disk).
|
||||||
func writeDebugAsset(w io.Writer, c *Config, asset *Asset) error {
|
func writeDebugAsset(w io.Writer, asset *Asset) error {
|
||||||
_, err := fmt.Fprintf(w, `func %s() []byte {
|
_, err := fmt.Fprintf(w, `
|
||||||
|
// %s reads file data from disk.
|
||||||
|
// It panics if something went wrong in the process.
|
||||||
|
func %s() []byte {
|
||||||
return bindata_read(
|
return bindata_read(
|
||||||
%q,
|
%q,
|
||||||
%q,
|
%q,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
`, asset.Func, asset.Func, asset.Path, asset.Name)
|
||||||
`, asset.Func, asset.Path, asset.Name)
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,11 +13,11 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
cfg, status := parseArgs()
|
cfg := parseArgs()
|
||||||
err := bindata.Translate(cfg, status)
|
err := bindata.Translate(cfg)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "bindata: %v", err)
|
fmt.Fprintf(os.Stderr, "bindata: %v\n", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,23 +26,23 @@ func main() {
|
||||||
//
|
//
|
||||||
// This function exits the program with an error, if
|
// This function exits the program with an error, if
|
||||||
// any of the command line options are incorrect.
|
// any of the command line options are incorrect.
|
||||||
func parseArgs() (*bindata.Config, bindata.ProgressFunc) {
|
func parseArgs() *bindata.Config {
|
||||||
var version, quiet bool
|
var version bool
|
||||||
|
|
||||||
c := bindata.NewConfig()
|
c := bindata.NewConfig()
|
||||||
|
|
||||||
flag.Usage = func() {
|
flag.Usage = func() {
|
||||||
fmt.Printf("Usage: %s [options] <input> [<output>]\n\n", os.Args[0])
|
fmt.Printf("Usage: %s [options] <input dir> [<output file>]\n\n", os.Args[0])
|
||||||
flag.PrintDefaults()
|
flag.PrintDefaults()
|
||||||
}
|
}
|
||||||
|
|
||||||
flag.StringVar(&c.Tags, "tags", c.Tags, "Comma-separated list of build tags to include.")
|
flag.BoolVar(&c.Debug, "debug", c.Debug, "Do not embed the assets, but provide the embedding API. Contents will still be loaded from disk.")
|
||||||
flag.StringVar(&c.Prefix, "prefix", c.Prefix, "Optional path prefix to strip off map keys and function names.")
|
flag.StringVar(&c.Tags, "tags", c.Tags, "Optional set of uild tags to include.")
|
||||||
|
flag.StringVar(&c.Prefix, "prefix", c.Prefix, "Optional path prefix to strip off asset names.")
|
||||||
flag.StringVar(&c.Package, "pkg", c.Package, "Package name to use in the generated code.")
|
flag.StringVar(&c.Package, "pkg", c.Package, "Package name to use in the generated code.")
|
||||||
flag.BoolVar(&c.NoMemCopy, "nomemcopy", c.NoMemCopy, "Use a .rodata hack to get rid of unnecessary memcopies. Refer to the documentation to see what implications this carries.")
|
flag.BoolVar(&c.NoMemCopy, "nomemcopy", c.NoMemCopy, "Use a .rodata hack to get rid of unnecessary memcopies. Refer to the documentation to see what implications this carries.")
|
||||||
flag.BoolVar(&c.Compress, "nocompress", !c.Compress, "Assets will /not/ be GZIP compressed when this flag is specified.")
|
flag.BoolVar(&c.NoCompress, "nocompress", c.NoCompress, "Assets will *not* be GZIP compressed when this flag is specified.")
|
||||||
flag.BoolVar(&version, "version", false, "Displays version information.")
|
flag.BoolVar(&version, "version", false, "Displays version information.")
|
||||||
flag.BoolVar(&quiet, "quiet", false, "Do not print conversion status.")
|
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
if version {
|
if version {
|
||||||
|
@ -52,64 +52,15 @@ func parseArgs() (*bindata.Config, bindata.ProgressFunc) {
|
||||||
|
|
||||||
// Make sure we have in/output paths.
|
// Make sure we have in/output paths.
|
||||||
if flag.NArg() == 0 {
|
if flag.NArg() == 0 {
|
||||||
fmt.Fprintf(os.Stderr, "Missing asset directory.\n")
|
fmt.Fprintf(os.Stderr, "Missing input path.\n")
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test validity of input path.
|
|
||||||
c.Input = filepath.Clean(flag.Arg(0))
|
c.Input = filepath.Clean(flag.Arg(0))
|
||||||
|
|
||||||
stat, err := os.Lstat(c.Input)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Fprintf(os.Stderr, "Input path: %v.\n", err)
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
if !stat.IsDir() {
|
|
||||||
fmt.Fprintf(os.Stderr, "Input path is not a directory.\n")
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Find and test validity of output path.
|
|
||||||
if flag.NArg() > 1 {
|
if flag.NArg() > 1 {
|
||||||
c.Output = filepath.Clean(flag.Arg(1))
|
c.Output = filepath.Clean(flag.Arg(1))
|
||||||
|
|
||||||
stat, err := os.Lstat(c.Output)
|
|
||||||
if err != nil {
|
|
||||||
if !os.IsNotExist(err) {
|
|
||||||
fmt.Fprintf(os.Stderr, "Output path: %v.\n", err)
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create output directory
|
return c
|
||||||
err = os.MkdirAll(c.Output, 0744)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Fprintf(os.Stderr, "Create Output directory: %v.\n", err)
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
} else if !stat.IsDir() {
|
|
||||||
fmt.Fprintf(os.Stderr, "Output path is not a directory.\n")
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// If no output path is specified, use the current directory.
|
|
||||||
c.Output, err = os.Getwd()
|
|
||||||
if err != nil {
|
|
||||||
fmt.Fprintf(os.Stderr, "Unable to determine current working directory: %v\n", err)
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// The command line flag supplies the inversion of this value.
|
|
||||||
c.Compress = !c.Compress
|
|
||||||
|
|
||||||
if quiet {
|
|
||||||
return c, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return c, func(file string, current, total int) bool {
|
|
||||||
fmt.Printf("[%d/%d] %s\n", current, total, file)
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
70
release.go
70
release.go
|
@ -9,25 +9,17 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// writeRelease writes the release code file.
|
// writeRelease writes the release code file.
|
||||||
func writeRelease(c *Config, toc []Asset) error {
|
func writeRelease(w io.Writer, c *Config, toc []Asset) error {
|
||||||
fd, err := os.Create(filepath.Join(c.Output, "bindata_release.go"))
|
err := writeReleaseHeader(w, c)
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
defer fd.Close()
|
|
||||||
|
|
||||||
err = writeReleaseHeader(fd, c)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := range toc {
|
for i := range toc {
|
||||||
err = writeReleaseAsset(fd, c, &toc[i])
|
err = writeReleaseAsset(w, c, &toc[i])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -39,37 +31,18 @@ func writeRelease(c *Config, toc []Asset) error {
|
||||||
// writeReleaseHeader writes output file headers.
|
// writeReleaseHeader writes output file headers.
|
||||||
// This targets release builds.
|
// This targets release builds.
|
||||||
func writeReleaseHeader(w io.Writer, c *Config) error {
|
func writeReleaseHeader(w io.Writer, c *Config) error {
|
||||||
var err error
|
if c.NoCompress {
|
||||||
|
|
||||||
// Write build tags, if applicable.
|
|
||||||
if len(c.Tags) > 0 {
|
|
||||||
_, err = fmt.Fprintf(w, "// +build release %s\n\n", c.Tags)
|
|
||||||
} else {
|
|
||||||
_, err = fmt.Fprintf(w, "// +build release\n\n")
|
|
||||||
}
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Write package declaration
|
|
||||||
_, err = fmt.Fprintf(w, "package %s\n\n", c.Package)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if c.Compress {
|
|
||||||
if c.NoMemCopy {
|
|
||||||
return header_compressed_nomemcopy(w)
|
|
||||||
} else {
|
|
||||||
return header_compressed_memcopy(w)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if c.NoMemCopy {
|
if c.NoMemCopy {
|
||||||
return header_uncompressed_nomemcopy(w)
|
return header_uncompressed_nomemcopy(w)
|
||||||
} else {
|
} else {
|
||||||
return header_uncompressed_memcopy(w)
|
return header_uncompressed_memcopy(w)
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
if c.NoMemCopy {
|
||||||
|
return header_compressed_nomemcopy(w)
|
||||||
|
} else {
|
||||||
|
return header_compressed_memcopy(w)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,26 +57,25 @@ func writeReleaseAsset(w io.Writer, c *Config, asset *Asset) error {
|
||||||
|
|
||||||
defer fd.Close()
|
defer fd.Close()
|
||||||
|
|
||||||
if c.Compress {
|
if c.NoCompress {
|
||||||
if c.NoMemCopy {
|
|
||||||
return compressed_nomemcopy(w, asset, fd)
|
|
||||||
} else {
|
|
||||||
return compressed_memcopy(w, asset, fd)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if c.NoMemCopy {
|
if c.NoMemCopy {
|
||||||
return uncompressed_nomemcopy(w, asset, fd)
|
return uncompressed_nomemcopy(w, asset, fd)
|
||||||
} else {
|
} else {
|
||||||
return uncompressed_memcopy(w, asset, fd)
|
return uncompressed_memcopy(w, asset, fd)
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
if c.NoMemCopy {
|
||||||
|
return compressed_nomemcopy(w, asset, fd)
|
||||||
|
} else {
|
||||||
|
return compressed_memcopy(w, asset, fd)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func header_compressed_nomemcopy(w io.Writer) error {
|
func header_compressed_nomemcopy(w io.Writer) error {
|
||||||
_, err := fmt.Fprintf(w, `
|
_, err := fmt.Fprintf(w, `import (
|
||||||
import (
|
|
||||||
"bytes"
|
"bytes"
|
||||||
"compress/gzip"
|
"compress/gzip"
|
||||||
"io"
|
"io"
|
||||||
|
@ -142,8 +114,7 @@ func bindata_read(data, name string) []byte {
|
||||||
}
|
}
|
||||||
|
|
||||||
func header_compressed_memcopy(w io.Writer) error {
|
func header_compressed_memcopy(w io.Writer) error {
|
||||||
_, err := fmt.Fprintf(w, `
|
_, err := fmt.Fprintf(w, `import (
|
||||||
import (
|
|
||||||
"bytes"
|
"bytes"
|
||||||
"compress/gzip"
|
"compress/gzip"
|
||||||
"io"
|
"io"
|
||||||
|
@ -172,8 +143,7 @@ func bindata_read(data []byte, name string) []byte {
|
||||||
}
|
}
|
||||||
|
|
||||||
func header_uncompressed_nomemcopy(w io.Writer) error {
|
func header_uncompressed_nomemcopy(w io.Writer) error {
|
||||||
_, err := fmt.Fprintf(w, `
|
_, err := fmt.Fprintf(w, `import (
|
||||||
import (
|
|
||||||
"reflect"
|
"reflect"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
// +build release
|
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -69,3 +67,20 @@ func in_c_test_asset() []byte {
|
||||||
"in/c/test.asset",
|
"in/c/test.asset",
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Asset loads and returns the asset for the given name.
|
||||||
|
// This returns nil of the asset could not be found.
|
||||||
|
func Asset(name string) []byte {
|
||||||
|
if f, ok := _bindata[name]; ok {
|
||||||
|
return f()
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// _bindata is a table, holding each asset generator, mapped to its name.
|
||||||
|
var _bindata = map[string]func() []byte{
|
||||||
|
"in/b/test.asset": in_b_test_asset,
|
||||||
|
"in/test.asset": in_test_asset,
|
||||||
|
"in/a/test.asset": in_a_test_asset,
|
||||||
|
"in/c/test.asset": in_c_test_asset,
|
||||||
|
}
|
18
testdata/out/compress-memcpy/bindata.go
vendored
18
testdata/out/compress-memcpy/bindata.go
vendored
|
@ -1,18 +0,0 @@
|
||||||
package main
|
|
||||||
|
|
||||||
// Asset loads and returns the asset for the given name.
|
|
||||||
// This returns nil of the asset could not be found.
|
|
||||||
func Asset(name string) []byte {
|
|
||||||
if f, ok := _bindata[name]; ok {
|
|
||||||
return f()
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// _bindata is a table, holding each asset generator, mapped to its name.
|
|
||||||
var _bindata = map[string]func() []byte{
|
|
||||||
"in/b/test.asset": in_b_test_asset,
|
|
||||||
"in/test.asset": in_test_asset,
|
|
||||||
"in/a/test.asset": in_a_test_asset,
|
|
||||||
"in/c/test.asset": in_c_test_asset,
|
|
||||||
}
|
|
57
testdata/out/compress-memcpy/bindata_debug.go
vendored
57
testdata/out/compress-memcpy/bindata_debug.go
vendored
|
@ -1,57 +0,0 @@
|
||||||
// +build !release
|
|
||||||
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"io"
|
|
||||||
"log"
|
|
||||||
"os"
|
|
||||||
)
|
|
||||||
|
|
||||||
// bindata_read reads the given file from disk.
|
|
||||||
// It panics if anything went wrong.
|
|
||||||
func bindata_read(path, name string) []byte {
|
|
||||||
fd, err := os.Open(path)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Read %s: %v", name, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
defer fd.Close()
|
|
||||||
|
|
||||||
var buf bytes.Buffer
|
|
||||||
_, err = io.Copy(&buf, fd)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Read %s: %v", name, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return buf.Bytes()
|
|
||||||
}
|
|
||||||
|
|
||||||
func in_b_test_asset() []byte {
|
|
||||||
return bindata_read(
|
|
||||||
"/a/code/go/src/github.com/jteeuwen/go-bindata/testdata/in/b/test.asset",
|
|
||||||
"in/b/test.asset",
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
func in_test_asset() []byte {
|
|
||||||
return bindata_read(
|
|
||||||
"/a/code/go/src/github.com/jteeuwen/go-bindata/testdata/in/test.asset",
|
|
||||||
"in/test.asset",
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
func in_a_test_asset() []byte {
|
|
||||||
return bindata_read(
|
|
||||||
"/a/code/go/src/github.com/jteeuwen/go-bindata/testdata/in/a/test.asset",
|
|
||||||
"in/a/test.asset",
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
func in_c_test_asset() []byte {
|
|
||||||
return bindata_read(
|
|
||||||
"/a/code/go/src/github.com/jteeuwen/go-bindata/testdata/in/c/test.asset",
|
|
||||||
"in/c/test.asset",
|
|
||||||
)
|
|
||||||
}
|
|
|
@ -1,5 +1,3 @@
|
||||||
// +build release
|
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -71,3 +69,20 @@ func in_c_test_asset() []byte {
|
||||||
"in/c/test.asset",
|
"in/c/test.asset",
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Asset loads and returns the asset for the given name.
|
||||||
|
// This returns nil of the asset could not be found.
|
||||||
|
func Asset(name string) []byte {
|
||||||
|
if f, ok := _bindata[name]; ok {
|
||||||
|
return f()
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// _bindata is a table, holding each asset generator, mapped to its name.
|
||||||
|
var _bindata = map[string]func() []byte{
|
||||||
|
"in/b/test.asset": in_b_test_asset,
|
||||||
|
"in/test.asset": in_test_asset,
|
||||||
|
"in/a/test.asset": in_a_test_asset,
|
||||||
|
"in/c/test.asset": in_c_test_asset,
|
||||||
|
}
|
18
testdata/out/compress-nomemcpy/bindata.go
vendored
18
testdata/out/compress-nomemcpy/bindata.go
vendored
|
@ -1,18 +0,0 @@
|
||||||
package main
|
|
||||||
|
|
||||||
// Asset loads and returns the asset for the given name.
|
|
||||||
// This returns nil of the asset could not be found.
|
|
||||||
func Asset(name string) []byte {
|
|
||||||
if f, ok := _bindata[name]; ok {
|
|
||||||
return f()
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// _bindata is a table, holding each asset generator, mapped to its name.
|
|
||||||
var _bindata = map[string]func() []byte{
|
|
||||||
"in/b/test.asset": in_b_test_asset,
|
|
||||||
"in/test.asset": in_test_asset,
|
|
||||||
"in/a/test.asset": in_a_test_asset,
|
|
||||||
"in/c/test.asset": in_c_test_asset,
|
|
||||||
}
|
|
57
testdata/out/compress-nomemcpy/bindata_debug.go
vendored
57
testdata/out/compress-nomemcpy/bindata_debug.go
vendored
|
@ -1,57 +0,0 @@
|
||||||
// +build !release
|
|
||||||
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"io"
|
|
||||||
"log"
|
|
||||||
"os"
|
|
||||||
)
|
|
||||||
|
|
||||||
// bindata_read reads the given file from disk.
|
|
||||||
// It panics if anything went wrong.
|
|
||||||
func bindata_read(path, name string) []byte {
|
|
||||||
fd, err := os.Open(path)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Read %s: %v", name, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
defer fd.Close()
|
|
||||||
|
|
||||||
var buf bytes.Buffer
|
|
||||||
_, err = io.Copy(&buf, fd)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Read %s: %v", name, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return buf.Bytes()
|
|
||||||
}
|
|
||||||
|
|
||||||
func in_b_test_asset() []byte {
|
|
||||||
return bindata_read(
|
|
||||||
"/a/code/go/src/github.com/jteeuwen/go-bindata/testdata/in/b/test.asset",
|
|
||||||
"in/b/test.asset",
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
func in_test_asset() []byte {
|
|
||||||
return bindata_read(
|
|
||||||
"/a/code/go/src/github.com/jteeuwen/go-bindata/testdata/in/test.asset",
|
|
||||||
"in/test.asset",
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
func in_a_test_asset() []byte {
|
|
||||||
return bindata_read(
|
|
||||||
"/a/code/go/src/github.com/jteeuwen/go-bindata/testdata/in/a/test.asset",
|
|
||||||
"in/a/test.asset",
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
func in_c_test_asset() []byte {
|
|
||||||
return bindata_read(
|
|
||||||
"/a/code/go/src/github.com/jteeuwen/go-bindata/testdata/in/c/test.asset",
|
|
||||||
"in/c/test.asset",
|
|
||||||
)
|
|
||||||
}
|
|
|
@ -1,5 +1,3 @@
|
||||||
// +build release
|
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
func in_b_test_asset() []byte {
|
func in_b_test_asset() []byte {
|
||||||
|
@ -29,3 +27,20 @@ func in_c_test_asset() []byte {
|
||||||
0x6c, 0x65, 0x0a,
|
0x6c, 0x65, 0x0a,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Asset loads and returns the asset for the given name.
|
||||||
|
// This returns nil of the asset could not be found.
|
||||||
|
func Asset(name string) []byte {
|
||||||
|
if f, ok := _bindata[name]; ok {
|
||||||
|
return f()
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// _bindata is a table, holding each asset generator, mapped to its name.
|
||||||
|
var _bindata = map[string]func() []byte{
|
||||||
|
"in/b/test.asset": in_b_test_asset,
|
||||||
|
"in/test.asset": in_test_asset,
|
||||||
|
"in/a/test.asset": in_a_test_asset,
|
||||||
|
"in/c/test.asset": in_c_test_asset,
|
||||||
|
}
|
18
testdata/out/nocompress-memcpy/bindata.go
vendored
18
testdata/out/nocompress-memcpy/bindata.go
vendored
|
@ -1,18 +0,0 @@
|
||||||
package main
|
|
||||||
|
|
||||||
// Asset loads and returns the asset for the given name.
|
|
||||||
// This returns nil of the asset could not be found.
|
|
||||||
func Asset(name string) []byte {
|
|
||||||
if f, ok := _bindata[name]; ok {
|
|
||||||
return f()
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// _bindata is a table, holding each asset generator, mapped to its name.
|
|
||||||
var _bindata = map[string]func() []byte{
|
|
||||||
"in/b/test.asset": in_b_test_asset,
|
|
||||||
"in/test.asset": in_test_asset,
|
|
||||||
"in/a/test.asset": in_a_test_asset,
|
|
||||||
"in/c/test.asset": in_c_test_asset,
|
|
||||||
}
|
|
57
testdata/out/nocompress-memcpy/bindata_debug.go
vendored
57
testdata/out/nocompress-memcpy/bindata_debug.go
vendored
|
@ -1,57 +0,0 @@
|
||||||
// +build !release
|
|
||||||
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"io"
|
|
||||||
"log"
|
|
||||||
"os"
|
|
||||||
)
|
|
||||||
|
|
||||||
// bindata_read reads the given file from disk.
|
|
||||||
// It panics if anything went wrong.
|
|
||||||
func bindata_read(path, name string) []byte {
|
|
||||||
fd, err := os.Open(path)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Read %s: %v", name, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
defer fd.Close()
|
|
||||||
|
|
||||||
var buf bytes.Buffer
|
|
||||||
_, err = io.Copy(&buf, fd)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Read %s: %v", name, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return buf.Bytes()
|
|
||||||
}
|
|
||||||
|
|
||||||
func in_b_test_asset() []byte {
|
|
||||||
return bindata_read(
|
|
||||||
"/a/code/go/src/github.com/jteeuwen/go-bindata/testdata/in/b/test.asset",
|
|
||||||
"in/b/test.asset",
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
func in_test_asset() []byte {
|
|
||||||
return bindata_read(
|
|
||||||
"/a/code/go/src/github.com/jteeuwen/go-bindata/testdata/in/test.asset",
|
|
||||||
"in/test.asset",
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
func in_a_test_asset() []byte {
|
|
||||||
return bindata_read(
|
|
||||||
"/a/code/go/src/github.com/jteeuwen/go-bindata/testdata/in/a/test.asset",
|
|
||||||
"in/a/test.asset",
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
func in_c_test_asset() []byte {
|
|
||||||
return bindata_read(
|
|
||||||
"/a/code/go/src/github.com/jteeuwen/go-bindata/testdata/in/c/test.asset",
|
|
||||||
"in/c/test.asset",
|
|
||||||
)
|
|
||||||
}
|
|
|
@ -1,5 +1,3 @@
|
||||||
// +build release
|
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -53,3 +51,20 @@ func in_c_test_asset() []byte {
|
||||||
"in/c/test.asset",
|
"in/c/test.asset",
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Asset loads and returns the asset for the given name.
|
||||||
|
// This returns nil of the asset could not be found.
|
||||||
|
func Asset(name string) []byte {
|
||||||
|
if f, ok := _bindata[name]; ok {
|
||||||
|
return f()
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// _bindata is a table, holding each asset generator, mapped to its name.
|
||||||
|
var _bindata = map[string]func() []byte{
|
||||||
|
"in/b/test.asset": in_b_test_asset,
|
||||||
|
"in/test.asset": in_test_asset,
|
||||||
|
"in/a/test.asset": in_a_test_asset,
|
||||||
|
"in/c/test.asset": in_c_test_asset,
|
||||||
|
}
|
18
testdata/out/nocompress-nomemcpy/bindata.go
vendored
18
testdata/out/nocompress-nomemcpy/bindata.go
vendored
|
@ -1,18 +0,0 @@
|
||||||
package main
|
|
||||||
|
|
||||||
// Asset loads and returns the asset for the given name.
|
|
||||||
// This returns nil of the asset could not be found.
|
|
||||||
func Asset(name string) []byte {
|
|
||||||
if f, ok := _bindata[name]; ok {
|
|
||||||
return f()
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// _bindata is a table, holding each asset generator, mapped to its name.
|
|
||||||
var _bindata = map[string]func() []byte{
|
|
||||||
"in/b/test.asset": in_b_test_asset,
|
|
||||||
"in/test.asset": in_test_asset,
|
|
||||||
"in/a/test.asset": in_a_test_asset,
|
|
||||||
"in/c/test.asset": in_c_test_asset,
|
|
||||||
}
|
|
|
@ -1,57 +0,0 @@
|
||||||
// +build !release
|
|
||||||
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"io"
|
|
||||||
"log"
|
|
||||||
"os"
|
|
||||||
)
|
|
||||||
|
|
||||||
// bindata_read reads the given file from disk.
|
|
||||||
// It panics if anything went wrong.
|
|
||||||
func bindata_read(path, name string) []byte {
|
|
||||||
fd, err := os.Open(path)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Read %s: %v", name, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
defer fd.Close()
|
|
||||||
|
|
||||||
var buf bytes.Buffer
|
|
||||||
_, err = io.Copy(&buf, fd)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Read %s: %v", name, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return buf.Bytes()
|
|
||||||
}
|
|
||||||
|
|
||||||
func in_b_test_asset() []byte {
|
|
||||||
return bindata_read(
|
|
||||||
"/a/code/go/src/github.com/jteeuwen/go-bindata/testdata/in/b/test.asset",
|
|
||||||
"in/b/test.asset",
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
func in_test_asset() []byte {
|
|
||||||
return bindata_read(
|
|
||||||
"/a/code/go/src/github.com/jteeuwen/go-bindata/testdata/in/test.asset",
|
|
||||||
"in/test.asset",
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
func in_a_test_asset() []byte {
|
|
||||||
return bindata_read(
|
|
||||||
"/a/code/go/src/github.com/jteeuwen/go-bindata/testdata/in/a/test.asset",
|
|
||||||
"in/a/test.asset",
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
func in_c_test_asset() []byte {
|
|
||||||
return bindata_read(
|
|
||||||
"/a/code/go/src/github.com/jteeuwen/go-bindata/testdata/in/c/test.asset",
|
|
||||||
"in/c/test.asset",
|
|
||||||
)
|
|
||||||
}
|
|
28
toc.go
28
toc.go
|
@ -7,38 +7,28 @@ package bindata
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
|
||||||
"path/filepath"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// writeTOC writes the table of contents file.
|
// writeTOC writes the table of contents file.
|
||||||
func writeTOC(c *Config, toc []Asset) error {
|
func writeTOC(w io.Writer, toc []Asset) error {
|
||||||
fd, err := os.Create(filepath.Join(c.Output, "bindata.go"))
|
err := writeTOCHeader(w)
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
defer fd.Close()
|
|
||||||
|
|
||||||
err = writeTOCHeader(fd, c)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := range toc {
|
for i := range toc {
|
||||||
err = writeTOCAsset(fd, c, &toc[i])
|
err = writeTOCAsset(w, &toc[i])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return writeTOCFooter(fd, c)
|
return writeTOCFooter(w)
|
||||||
}
|
}
|
||||||
|
|
||||||
// writeTOCHeader writes the table of contents file header.
|
// writeTOCHeader writes the table of contents file header.
|
||||||
func writeTOCHeader(w io.Writer, c *Config) error {
|
func writeTOCHeader(w io.Writer) error {
|
||||||
_, err := fmt.Fprintf(w, `package %s
|
_, err := fmt.Fprintf(w, `
|
||||||
|
|
||||||
// Asset loads and returns the asset for the given name.
|
// Asset loads and returns the asset for the given name.
|
||||||
// This returns nil of the asset could not be found.
|
// This returns nil of the asset could not be found.
|
||||||
func Asset(name string) []byte {
|
func Asset(name string) []byte {
|
||||||
|
@ -50,18 +40,18 @@ func Asset(name string) []byte {
|
||||||
|
|
||||||
// _bindata is a table, holding each asset generator, mapped to its name.
|
// _bindata is a table, holding each asset generator, mapped to its name.
|
||||||
var _bindata = map[string] func() []byte {
|
var _bindata = map[string] func() []byte {
|
||||||
`, c.Package)
|
`)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// writeTOCAsset write a TOC entry for the given asset.
|
// writeTOCAsset write a TOC entry for the given asset.
|
||||||
func writeTOCAsset(w io.Writer, c *Config, asset *Asset) error {
|
func writeTOCAsset(w io.Writer, asset *Asset) error {
|
||||||
_, err := fmt.Fprintf(w, "\t%q: %s,\n", asset.Name, asset.Func)
|
_, err := fmt.Fprintf(w, "\t%q: %s,\n", asset.Name, asset.Func)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// writeTOCFooter writes the table of contents file footer.
|
// writeTOCFooter writes the table of contents file footer.
|
||||||
func writeTOCFooter(w io.Writer, c *Config) error {
|
func writeTOCFooter(w io.Writer) error {
|
||||||
_, err := fmt.Fprintf(w, `
|
_, err := fmt.Fprintf(w, `
|
||||||
}
|
}
|
||||||
`)
|
`)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user