Skip to content

Commit

Permalink
all: report whether built with the debug flag enabled
Browse files Browse the repository at this point in the history
Fixes #31.
  • Loading branch information
kevinburke committed May 18, 2020
1 parent 43c0ff8 commit e37081c
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 34 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,9 @@ For most use-cases this is not a problem, but if you ever try to alter the
returned byte slice, a runtime panic is thrown. Use this mode only on target
platforms where memory constraints are an issue.

The default behaviour is to use the old code generation method. This
prevents the two previously mentioned issues, but will employ at least one
extra memcopy and thus increase memory requirements.
The default behavior is to use the old code generation method. This prevents the
two previously mentioned issues, but will employ at least one extra memcopy and
thus increase memory requirements.

For instance, consider the following two examples:

Expand Down Expand Up @@ -189,7 +189,7 @@ This feature is useful if you do not care for compression, or the supplied
resource is already compressed. Doing it again would not add any value and may
even increase the size of the data.

The default behaviour of the program is to use compression.
The default behavior of the program is to use compression.


### Path prefix stripping
Expand Down
36 changes: 18 additions & 18 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,18 @@ type Config struct {
// the compiled program's `.rodata` section. This ensures that when we call
// call our generated function, we omit unnecessary mem copies.
//
// The downside of this, is that it requires dependencies on the `reflect` and
// `unsafe` packages. These may be restricted on platforms like AppEngine and
// thus prevent you from using this mode.
// The downside of this is that it requires dependencies on the `reflect`
// and `unsafe` packages. These may be restricted on platforms like
// AppEngine and thus prevent you from using this mode.
//
// Another disadvantage is that the byte slice we create, is strictly read-only.
// For most use-cases this is not a problem, but if you ever try to alter the
// returned byte slice, a runtime panic is thrown. Use this mode only on target
// platforms where memory constraints are an issue.
// Another disadvantage is that the byte slice we create is strictly
// read-only. For most use-cases this is not a problem, but if you ever try
// to alter the returned byte slice, a runtime panic is thrown. Use this
// mode only on target platforms where memory constraints are an issue.
//
// The default behaviour is to use the old code generation method. This
// prevents the two previously mentioned issues, but will employ at least one
// extra memcopy and thus increase memory requirements.
// The default behavior is to use the old code generation method. This
// prevents the two previously mentioned issues, but will employ at least
// one extra memcopy and thus increase memory requirements.
//
// For instance, consider the following two examples:
//
Expand Down Expand Up @@ -106,15 +106,15 @@ type Config struct {
// the file data when called. Defaults to false.
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.
// 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.
// 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 behavior is Release
// mode.
Debug bool

// Perform a dev build, which is nearly identical to the debug option. The
Expand Down
8 changes: 6 additions & 2 deletions convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ func Translate(c *Config) error {
toc[i].Path = strings.Replace(toc[i].Path, wd, "/test", 1)
}
}
err = writeDebug(buf, c, toc)
err = writeDebugFunctions(buf, c, toc)
} else {
err = writeRelease(buf, c, toc)
err = writeReleaseFunctions(buf, c, toc)
}
if err != nil {
return err
Expand All @@ -96,6 +96,10 @@ func Translate(c *Config) error {
if err := writeTOC(buf, toc); err != nil {
return err
}
_, err = fmt.Fprintf(buf, `// Debug is true if the assets were built with the debug flag enabled.
const Debug = %t
`, c.Debug)
// Write hierarchical tree of assets
if err := writeTOCTree(buf, toc); err != nil {
return err
Expand Down
4 changes: 2 additions & 2 deletions debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"io"
)

// writeDebug writes the debug code file.
func writeDebug(w io.Writer, c *Config, toc []Asset) error {
// writeDebugFunctions writes the debug code file.
func writeDebugFunctions(w io.Writer, c *Config, toc []Asset) error {
err := writeDebugHeader(w)
if err != nil {
return err
Expand Down
8 changes: 4 additions & 4 deletions doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ For most use-cases this is not a problem, but if you ever try to alter the
returned byte slice, a runtime panic is thrown. Use this mode only on target
platforms where memory constraints are an issue.
The default behaviour is to use the old code generation method. This
prevents the two previously mentioned issues, but will employ at least one
extra memcopy and thus increase memory requirements.
The default behavior is to use the old code generation method. This prevents the
two previously mentioned issues, but will employ at least one extra memcopy and
thus increase memory requirements.
For instance, consider the following two examples:
Expand Down Expand Up @@ -90,7 +90,7 @@ This feature is useful if you do not care for compression, or the supplied
resource is already compressed. Doing it again would not add any value and may
even increase the size of the data.
The default behaviour of the program is to use compression.
The default behavior of the program is to use compression.
Path prefix stripping
Expand Down
7 changes: 3 additions & 4 deletions release.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,15 @@ import (
"unicode/utf8"
)

// writeRelease writes the release code file.
func writeRelease(w io.Writer, c *Config, toc []Asset) error {
// writeReleaseFunctions writes the release code file.
func writeReleaseFunctions(w io.Writer, c *Config, toc []Asset) error {
err := writeReleaseHeader(w, c)
if err != nil {
return err
}

for i := range toc {
err = writeReleaseAsset(w, c, &toc[i])
if err != nil {
if err := writeReleaseAsset(w, c, &toc[i]); err != nil {
return err
}
}
Expand Down
3 changes: 3 additions & 0 deletions testdata/out/compress-memcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions testdata/out/compress-nomemcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions testdata/out/debug.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions testdata/out/nocompress-memcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions testdata/out/nocompress-nomemcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e37081c

Please sign in to comment.