builder

package
v0.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 31, 2020 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	BusyBox = BBBuilder{}
	Source  = SourceBuilder{}
	Binary  = BinaryBuilder{}
)

Functions

This section is empty.

Types

type BBBuilder

type BBBuilder struct{}

BBBuilder is an implementation of Builder that compiles many Go commands into one busybox-style binary.

BBBuilder will also include symlinks for each command to the busybox binary.

BBBuilder does all this by rewriting the source files of the packages given to create one busybox-like binary containing all commands.

The compiled binary uses argv[0] to decide which Go command to run.

See bb/README.md for a detailed explanation of the implementation of busybox mode.

func (BBBuilder) Build

func (BBBuilder) Build(af *initramfs.Files, opts Opts) error

Build is an implementation of Builder.Build for a busybox-like initramfs.

func (BBBuilder) DefaultBinaryDir

func (BBBuilder) DefaultBinaryDir() string

DefaultBinaryDir implements Builder.DefaultBinaryDir.

The default initramfs binary dir is bbin for busybox binaries.

type BinaryBuilder

type BinaryBuilder struct{}

BinaryBuilder builds each Go command as a separate binary.

BinaryBuilder is an implementation of Builder.

func (BinaryBuilder) Build

func (BinaryBuilder) Build(af *initramfs.Files, opts Opts) error

Build implements Builder.Build.

func (BinaryBuilder) DefaultBinaryDir

func (BinaryBuilder) DefaultBinaryDir() string

DefaultBinaryDir implements Builder.DefaultBinaryDir.

"bin" is the default initramfs binary directory for these binaries.

type Builder

type Builder interface {
	// Build uses the given options to build Go packages and adds its files
	// to be included in the initramfs to the given ArchiveFiles.
	Build(*initramfs.Files, Opts) error

	// DefaultBinaryDir is the initramfs' default directory for binaries
	// built using this builder.
	DefaultBinaryDir() string
}

Builder builds Go packages and adds the binaries to an initramfs.

The resulting files need not be binaries per se, but exec'ing the resulting file should result in the Go program being executed.

type Opts

type Opts struct {
	// Env is the Go compiler environment.
	Env golang.Environ

	// Packages are the Go packages to compile.
	//
	// Only an explicit list of Go import paths is accepted.
	//
	// E.g. cmd/go or github.com/u-root/u-root/cmds/ls.
	Packages []string

	// TempDir is a temporary directory where the compilation mode compiled
	// binaries can be placed.
	//
	// TempDir should contain no files.
	TempDir string

	// BinaryDir is the initramfs directory for built binaries.
	//
	// BinaryDir must be specified.
	BinaryDir string

	// NoStrip builds unstripped binaries.
	NoStrip bool
}

Opts are options passed to the Builder.Build function.

type SourceBuilder added in v0.2.0

type SourceBuilder struct {
	// FourBins, if true, will cause us to not build
	// an installcommand. This only makes sense if you are using the
	// fourbins command in the u-root command, but that's your call.
	// In operation, the default behavior is the one most people will want,
	// i.e. the installcommand will be built.
	FourBins bool
}

SourceBuilder includes full source for Go commands in the initramfs.

SourceBuilder is an implementation of Builder.

It also includes the Go toolchain in the initramfs, and a tool called installcommand that can compile the other commands using symlinks.

E.g. if "ls" is an included command, "ls" will be a symlink to "installcommand" in the initramfs, which uses argv[0] to figure out which command to compile.

func (SourceBuilder) Build added in v0.2.0

func (sb SourceBuilder) Build(af *initramfs.Files, opts Opts) error

Build is an implementation of Builder.Build.

func (SourceBuilder) DefaultBinaryDir added in v0.2.0

func (SourceBuilder) DefaultBinaryDir() string

DefaultBinaryDir implements Builder.DefaultBinaryDir.

The initramfs default binary dir is buildbin.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL