Documentation ¶
Overview ¶
Package bb builds one busybox-like binary out of many Go command sources.
This allows you to take two Go commands, such as Go implementations of `sl` and `cowsay` and compile them into one binary, callable like `./bb sl` and `./bb cowsay`.
Which command is invoked is determined by `argv[0]` or `argv[1]` if `argv[0]` is not recognized.
Under the hood, bb implements a Go source-to-source transformation on pure Go code. This AST transformation does the following:
- Takes a Go command's source files and rewrites them into Go package files without global side effects.
- Writes a `main.go` file with a `main()` that calls into the appropriate Go command package based on `argv[0]`.
Principally, the AST transformation moves all global side-effects into callable package functions. E.g. `main` becomes `Main`, each `init` becomes `InitN`, and global variable assignments are moved into their own `InitN`.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildBusybox ¶
BuildBusybox builds a busybox of the given Go packages.
pkgs is a list of Go import paths. If nil is returned, binaryPath will hold the busybox-style binary.
func CreateBBMainSource ¶
CreateBBMainSource creates a bb Go command that imports all given pkgs.
p must be the bb template.
- For each pkg in pkgs, add import _ "pkg" to astp's first file.
- Write source file out to destDir.
Types ¶
type Package ¶
type Package struct { // Name is the executable command name. // // In the standard Go tool chain, this is usually the base name of the // directory containing its source files. Name string // Pkg is the actual data about the package. Pkg *packages.Package // contains filtered or unexported fields }
Package is a Go package.
func NewPackage ¶
NewPackage creates a new Package based on an existing packages.Package.
func NewPackages ¶
NewPackages collects package metadata about all named packages.
Directories ¶
Path | Synopsis |
---|---|
Package bbmain is the package imported by all rewritten busybox command-packages to register themselves.
|
Package bbmain is the package imported by all rewritten busybox command-packages to register themselves. |
cmd
Package main is the busybox main.go template.
|
Package main is the busybox main.go template. |