gb: github.com/constabulary/gb Index | Examples | Files | Directories

package gb

import "github.com/constabulary/gb"

Package gb is a tool kit for building Go packages and programs.

The executable, cmd/gb, is located in the respective subdirectory along with several plugin programs.

Index

Examples

Package Files

build.go cgo.go context.go defaultcc.go depfile.go executor.go gb.go gc.go package.go project.go resolver.go

func Build Uses

func Build(pkgs ...*Package) error

Build builds each of pkgs in succession. If pkg is a command, then the results of build include linking the final binary into pkg.Context.Bindir().

func BuildDependencies Uses

func BuildDependencies(targets map[string]*Action, pkg *Package) ([]*Action, error)

BuildDependencies returns a slice of Actions representing the steps required to build all dependant packages of this package.

func Execute Uses

func Execute(a *Action) error

Execute executes a tree of *Actions sequentually in depth first order.

func ExecuteConcurrent Uses

func ExecuteConcurrent(a *Action, n int, interrupt <-chan struct{}) error

ExecuteConcurrent executes all actions in a tree concurrently. Each Action will wait until its dependant actions are complete.

func GOARCH Uses

func GOARCH(goarch string) func(*Context) error

GOARCH configures the Context to use goarch as the target arch.

func GOOS Uses

func GOOS(goos string) func(*Context) error

GOOS configures the Context to use goos as the target os.

func GcToolchain Uses

func GcToolchain() func(c *Context) error

func Gcflags Uses

func Gcflags(flags ...string) func(*Context) error

Gcflags appends flags to the list passed to the compiler.

func Ldflags Uses

func Ldflags(flags ...string) func(*Context) error

Ldflags appends flags to the list passed to the linker.

func Tags Uses

func Tags(tags ...string) func(*Context) error

Tags configured the context to use these additional build tags

func WithDebug Uses

func WithDebug(w io.Writer) func(*Context) error

func WithRace Uses

func WithRace(c *Context) error

WithRace enables the race detector and adds the tag "race" to the Context build tags.

type Action Uses

type Action struct {

    // Name describes the action.
    Name string

    // Deps identifies the Actions that this Action depends.
    Deps []*Action

    // Run identifies the task that this action represents.
    Run func() error
}

An Action describes a task to be performed and a set of Actions that the task depends on.

func BuildPackage Uses

func BuildPackage(targets map[string]*Action, pkg *Package) (*Action, error)

BuildPackage returns an Action representing the steps required to build this package.

func BuildPackages Uses

func BuildPackages(pkgs ...*Package) (*Action, error)

BuildPackages produces a tree of *Actions that can be executed to build a *Package. BuildPackages walks the tree of *Packages and returns a corresponding tree of *Actions representing the steps required to build *Package and any of its dependencies

func Compile Uses

func Compile(pkg *Package, deps ...*Action) (*Action, error)

Compile returns an Action representing the steps required to compile this package.

type Context Uses

type Context struct {
    Project

    Statistics

    Force   bool // force rebuild of packages
    Install bool // copy packages into $PROJECT/pkg
    Verbose bool // verbose output
    Nope    bool // command specific flag, under test it skips the execute action.
    // contains filtered or unexported fields
}

Context represents an execution of one or more Targets inside a Project.

func NewContext Uses

func NewContext(p Project, opts ...func(*Context) error) (*Context, error)

NewContext returns a new build context from this project. By default this context will use the gc toolchain with the host's GOOS and GOARCH values.

func (*Context) Debug Uses

func (c *Context) Debug(format string, args ...interface{})

func (*Context) Destroy Uses

func (c *Context) Destroy() error

Destroy removes the temporary working files of this context.

func (*Context) NewPackage Uses

func (c *Context) NewPackage(p *build.Package) (*Package, error)

NewPackage creates a resolved Package for p.

func (*Context) Pkgdir Uses

func (c *Context) Pkgdir() string

Pkgdir returns the path to precompiled packages.

func (*Context) ResolvePackage Uses

func (c *Context) ResolvePackage(path string) (*Package, error)

ResolvePackage resolves the package at path using the current context.

func (*Context) Suffix Uses

func (c *Context) Suffix() string

Suffix returns the suffix (if any) for binaries produced by this context.

func (*Context) Workdir Uses

func (c *Context) Workdir() string

Workdir returns the path to this Context's working directory.

type Importer Uses

type Importer interface {

    // Import attempts to resolve the package import path, path,
    // to an *importer.Package.
    Import(path string) (*build.Package, error)
}

Importer resolves package import paths to *importer.Packages.

type Package Uses

type Package struct {
    *Context
    *build.Package
    TestScope bool
    NotStale  bool // this package _and_ all its dependencies are not stale
    Main      bool // is this a command
    Imports   []*Package
}

Package represents a resolved package from the Project with respect to the Context.

func (*Package) Binfile Uses

func (pkg *Package) Binfile() string

Binfile returns the destination of the compiled target of this command.

func (*Package) String Uses

func (p *Package) String() string

func (*Package) Workdir Uses

func (pkg *Package) Workdir() string

type Project Uses

type Project interface {

    // Projectdir returns the path root of this project.
    Projectdir() string

    // Pkgdir returns the path to precompiled packages.
    Pkgdir() string
    // contains filtered or unexported methods
}

Project represents a gb project. A gb project has a simlar layout to a $GOPATH workspace. Each gb project has a standard directory layout starting at the project root, which we'll refer too as $PROJECT.

$PROJECT/                       - the project root
$PROJECT/src/                   - base directory for the source of packages
$PROJECT/bin/                   - base directory for the compiled binaries

func NewProject Uses

func NewProject(root string) Project

Code:


// Every project begins with a project root.
// Normally you'd check this out of source control.
root := filepath.Join("home", "dfc", "devel", "demo")

// Create a new Project passing in the source directories
// under this project's root.
proj := gb.NewProject(root)

// Create a new Context from the Project. A Context holds
// the state of a specific compilation or test within the Project.
ctx, err := gb.NewContext(proj)
if err != nil {
    log.Fatal("Could not create new context:", err)
}

// Always remember to clean up your Context
ctx.Destroy()

type Statistics Uses

type Statistics struct {
    sync.Mutex
    // contains filtered or unexported fields
}

Statistics records the various Durations

func (*Statistics) Record Uses

func (s *Statistics) Record(name string, d time.Duration)

func (*Statistics) String Uses

func (s *Statistics) String() string

func (*Statistics) Total Uses

func (s *Statistics) Total() time.Duration

type Toolchain Uses

type Toolchain interface {
    Gc(pkg *Package, files []string) error
    Asm(pkg *Package, ofile, sfile string) error
    Pack(pkg *Package, afiles ...string) error
    Ld(*Package) error
    Cc(pkg *Package, ofile string, cfile string) error
    // contains filtered or unexported methods
}

Toolchain represents a standardised set of command line tools used to build and test Go programs.

Directories

PathSynopsis
cmdPackage command holds support functions and types for writing gb and gb plugins
cmd/gbgb, a project based build tool for the Go programming language.
cmd/gb/internal/match
cmd/gb-vendorgb-vendor, a gb plugin to manage your vendored dependencies.
internal/depfilePackage depfile loads a file of tagged key value pairs.
internal/fileutilsPackage fileutils provides utililty methods to copy and move files and directories.
internal/untar
internal/vendor
internal/version
test

Package gb imports 26 packages (graph) and is imported by 8 packages. Updated 2017-05-11. Refresh now. Tools for package owners.