Documentation
¶
Overview ¶
Package builder is a driver for Go builds
It does about the following
GOWORK=off cd $(mktemp -d) go mod init _ go get <path>@<version> go build -o <output> <path>
Example Usage
// prepare the build environment (creates a temporary directory, go // gets the required packages) builder, err := New("go.schlittermann.de/heiko/hello") if err != nil { … } // set a global timeout for the whole build process ctx, cancel := context.WithTimeout(context.Background(), 120 * time.Second) defer cancel() // get the required module err = builder.Get(ctx) if err != nil { … } res, err := builder.Build(ctx, "linux", "amd64") if err != nil { … } log.Println("build info:", build.Result.BuildInfo)
Index ¶
- func GetTest(yes bool) func(*bool)
- func RunTest(test string, flags ...string) buildOption
- func SkipTest(yes bool) buildOption
- func TestArgs(args ...string) buildOption
- type Build
- type Builder
- func (b *Builder) Build(ctx context.Context, os, arch string, options ...buildOption) (*Result, error)
- func (b *Builder) Cleanup()
- func (b *Builder) Command(argv0 string, args ...string) (cmd *exec.Cmd)
- func (b *Builder) CommandContext(ctx context.Context, argv0 string, args ...string) (cmd *exec.Cmd)
- func (b *Builder) FindTargets(ss []string) (Targets, error)
- func (b *Builder) Get(ctx context.Context, withTest ...func(*bool)) (err error)
- func (b *Builder) Start(ctx context.Context, goos, goarch string, options ...buildOption) (build *Build, err error)
- func (b *Builder) System(argv0 string, args ...string) error
- type Option
- type Result
- type Targets
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RunTest ¶ added in v0.7.1
RunTest sets the test to be run prior build (passed to "go test -run) and options
Types ¶
type Build ¶
type Build struct { *Builder Target target // contains filtered or unexported fields }
Build is a build, which may be started or running. Once it finishes, it returns a Result.
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
Builder represents a builder, which may have many have child builds
func New ¶
New creates a new builder. The caller must call Cleanup once they're done, to make sure that the temporary directory gets removed. It starts "go get …" in the background, the result can be fetched explicitly using Wait, or implicitly with Start.
func (*Builder) Build ¶
func (b *Builder) Build(ctx context.Context, os, arch string, options ...buildOption) (*Result, error)
Build starts the build and waits for its completion
func (*Builder) Cleanup ¶
func (b *Builder) Cleanup()
Cleanup purges the build environment (removes the temporary directory)
func (*Builder) Command ¶
Command returns a exec.Cmd which will run within the tmpdir of the Builder. The output channels are connected to the respective channels of the os.
func (*Builder) CommandContext ¶
CommandContext returns a exec.Cmd with the context set. The directory of the command is set to the directory of b
func (*Builder) FindTargets ¶
FindTargets expands the list of "os/arch" to a more structured list.
func (*Builder) Get ¶
Get downloads the required module. A specific commit can be given using the WithCommit method.
type Option ¶
Option represents a With* option for the New method
func WithCommit ¶
WithCommit specifies the commit we're building (if not used, defaults to "latest".
func WithEnv ¶
WithEnv appends the environment env to the OS environment for each call of an external command.
func WithEnvMap ¶
WithEnvMap appends the environment env to the OS environment for each call to an external command.