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 `registeredMain`, 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 ¶
Types ¶
type Opts ¶
type Opts struct { // Env are the environment variables used in Go compilation and package // discovery. Env *golang.Environ // LookupEnv is the environment for looking up and resolving command // paths. // // If left unset, DefaultEnv will be used. LookupEnv *findpkg.Env // GenSrcDir is an empty directory to generate the busybox source code // in. // // If GenSrcDir has children, BuildBusybox will return an error. If // GenSrcDir does not exist, it will be created. If no GenSrcDir is // given, a temporary directory will be generated. The generated // directory will be deleted if compilation succeeds. // // In GOPATH mode, GOPATH=GenSrcDir for compilation. GenSrcDir string // CommandPaths is a list of file system directories containing Go // commands, or Go import paths. CommandPaths []string // BinaryPath is the file to write the binary to. BinaryPath string // GoBuildOpts is configuration for the `go build` command that // compiles the busybox binary. GoBuildOpts *golang.BuildOpts // Generate the tree but don't build it. This is useful for systems // like Tamago which have their own way of building. GenerateOnly bool }
Opts are the arguments to BuildBusybox.
Directories ¶
Path | Synopsis |
---|---|
Package bbinternal is the internal API for both bazel and standard Go busybox builds.
|
Package bbinternal is the internal API for both bazel and standard Go busybox builds. |
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. |
Package findpkg finds packages from user-input strings that are either file paths or Go package paths.
|
Package findpkg finds packages from user-input strings that are either file paths or Go package paths. |