From ae16b2b3c6ba0603e43ad75177bf9c0591ae794c Mon Sep 17 00:00:00 2001 From: Jim Teeuwen Date: Wed, 30 Oct 2013 02:16:14 +0100 Subject: [PATCH] Finishes imlpementing the various debug and release output modes. For debug we always read assets from disk and ignore the compression and memcopy options. For release mode, the assets are all embedded and the compression/memcopy options are taken into account. --- debug.go | 2 +- release.go | 18 +++++++++++-- testdata/out/bindata_release.go | 48 ++++++++++++++++++++++++--------- 3 files changed, 53 insertions(+), 15 deletions(-) diff --git a/debug.go b/debug.go index 0b70c8a..0434c69 100644 --- a/debug.go +++ b/debug.go @@ -9,7 +9,7 @@ import ( "io" ) -// writeDebugHeader writes output file headers with the given build tags. +// writeDebugHeader writes output file headers. // This targets debug builds. func writeDebugHeader(w io.Writer, c *Config) { // Write build tags, if applicable. diff --git a/release.go b/release.go index a893001..3565728 100644 --- a/release.go +++ b/release.go @@ -11,7 +11,7 @@ import ( "os" ) -// writeReleaseHeader writes output file headers with the given build tags. +// writeReleaseHeader writes output file headers. // This targets release builds. func writeReleaseHeader(w io.Writer, c *Config) { // Write build tags, if applicable. @@ -138,7 +138,6 @@ func bindata_read(data []byte, name string) []byte { func header_uncompressed_nomemcopy(w io.Writer) { fmt.Fprintf(w, ` import ( - "log" "reflect" "unsafe" ) @@ -198,7 +197,22 @@ func compressed_memcopy(w io.Writer, asset *Asset, r io.Reader) { } func uncompressed_nomemcopy(w io.Writer, asset *Asset, r io.Reader) { + fmt.Fprintf(w, `var _%s = "`, asset.Func) + gz := gzip.NewWriter(&StringWriter{Writer: w}) + io.Copy(gz, r) + gz.Close() + + fmt.Fprintf(w, `" + +func %s() []byte { + return bindata_read( + _%s, + %q, + ) +} + +`, asset.Func, asset.Func, asset.Name) } func uncompressed_memcopy(w io.Writer, asset *Asset, r io.Reader) { diff --git a/testdata/out/bindata_release.go b/testdata/out/bindata_release.go index 61aa67f..8c11112 100644 --- a/testdata/out/bindata_release.go +++ b/testdata/out/bindata_release.go @@ -2,23 +2,47 @@ package main -func testdata_in_b_test_asset() []byte { - return []byte{ -0x2f,0x2f,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x20,0x66,0x69, -0x6c,0x65,0x0a, - } + +import ( + "reflect" + "unsafe" +) + +func bindata_read(data, name string) []byte { + var empty [0]byte + sx := (*reflect.StringHeader)(unsafe.Pointer(&data)) + b := empty[:] + bx := (*reflect.SliceHeader)(unsafe.Pointer(&b)) + bx.Data = sx.Data + bx.Len = len(data) + bx.Cap = bx.Len + return b } +var _testdata_in_b_test_asset = "\x1f\x8b\x08\x00\x00\x09\x6e\x88\x00\xff\xd2\xd7\x57\x28\x4e\xcc\x2d\xc8\x49\x55\x48\xcb\xcc\x49\xe5\x02\x04\x00\x00\xff\xff\x8a\x82\x8c\x85\x0f\x00\x00\x00" + +func testdata_in_b_test_asset() []byte { + return bindata_read( + _testdata_in_b_test_asset, + "../testdata/in/b/test.asset", + ) +} + +var _testdata_in_a_test_asset = "\x1f\x8b\x08\x00\x00\x09\x6e\x88\x00\xff\x2a\x4e\xcc\x2d\xc8\x49\x55\x48\xcb\xcc\x49\xe5\x02\x04\x00\x00\xff\xff\xda\x3d\x49\xdd\x0c\x00\x00\x00" + func testdata_in_a_test_asset() []byte { - return []byte{ -0x73,0x61,0x6d,0x70,0x6c,0x65,0x20,0x66,0x69,0x6c,0x65,0x0a, - } + return bindata_read( + _testdata_in_a_test_asset, + "../testdata/in/a/test.asset", + ) } +var _testdata_in_c_test_asset = "\x1f\x8b\x08\x00\x00\x09\x6e\x88\x00\xff\xd2\xd7\x57\x28\x4e\xcc\x2d\xc8\x49\x55\x48\xcb\xcc\x49\xe5\x02\x04\x00\x00\xff\xff\x8a\x82\x8c\x85\x0f\x00\x00\x00" + func testdata_in_c_test_asset() []byte { - return []byte{ -0x2f,0x2f,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x20,0x66,0x69, -0x6c,0x65,0x0a, - } + return bindata_read( + _testdata_in_c_test_asset, + "../testdata/in/c/test.asset", + ) }