bundle
commandThis package is not in the latest version of its module.
Details
Validgo.mod file
The Go module system was introduced in Go 1.11 and is the official dependency management solution for Go.
Redistributable license
Redistributable licenses place minimal restrictions on how software can be used, modified, and redistributed.
Tagged version
Modules with tagged versions give importers more predictable builds.
Stable version
When a project reaches major version v1 it is considered stable.
- Learn more about best practices
Repository
Links
Documentation¶
Overview¶
Bundle creates a single-source-file version of a source packagesuitable for inclusion in a particular target package.
Usage:
bundle [-o file] [-dst path] [-pkg name] [-prefix p] [-import old=new] [-tags build_constraints] <src>
The src argument specifies the import path of the package to bundle.The bundling of a directory of source files into a single source filenecessarily imposes a number of constraints.The package being bundled must not use cgo; must not use conditionalfile compilation, whether with build tags or system-specific file nameslike code_amd64.go; must not depend on any special comments, whichmay not be preserved; must not use any assembly sources;must not use renaming imports; and must not use reflection-based APIsthat depend on the specific names of types or struct fields.
By default, bundle writes the bundled code to standard output.If the -o argument is given, bundle writes to the named fileand also includes a “//go:generate” comment giving the exactcommand line used, for regenerating the file with “go generate.”
Bundle customizes its output for inclusion in a particular package, the destination package.By default bundle assumes the destination is the package in the current directory,but the destination package can be specified explicitly using the -dst option,which takes an import path as its argument.If the source package imports the destination package, bundle will removethose imports and rewrite any references to use direct references to thecorresponding symbols.Bundle also must write a package declaration in the output and mustchoose a name to use in that declaration.If the -pkg option is given, bundle uses that name.Otherwise, the name of the destination package is used.Build constraints for the generated file can be specified using the -tags option.
To avoid collisions, bundle inserts a prefix at the beginning ofevery package-level const, func, type, and var identifier in src's code,updating references accordingly. The default prefix is the package nameof the source package followed by an underscore. The -prefix optionspecifies an alternate prefix.
Occasionally it is necessary to rewrite imports during the bundlingprocess. The -import option, which may be repeated, specifies thatan import of "old" should be rewritten to import "new" instead.
Example¶
Bundle archive/zip for inclusion in cmd/dist:
cd $GOROOT/src/cmd/distbundle -o zip.go archive/zip
Bundle golang.org/x/net/http2 for inclusion in net/http,prefixing all identifiers by "http2" instead of "http2_", andincluding a "!nethttpomithttp2" build constraint:
cd $GOROOT/src/net/httpbundle -o h2_bundle.go -prefix http2 -tags '!nethttpomithttp2' golang.org/x/net/http2
Update the http2 bundle in net/http:
go generate net/http
Update all bundles in the standard library:
go generate -run bundle std
Notes¶
Bugs¶
bundle may generate incorrect codedue to shadowing between identifiers and imported package names.
The generated code will either fail to compile or(unlikely) compile successfully but have different behaviorthan the original package. The risk of this happening is higherwhen the original package has renamed imports (they're typicallyrenamed in order to resolve a shadow inside that particular .go file).