Documentation ¶
Overview ¶
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 ¶
- Variables
- func Build(pkgs ...*Package) error
- func Debugf(format string, args ...interface{})
- func Errorf(format string, args ...interface{})
- func Execute(a *Action) error
- func ExecuteConcurrent(a *Action, n int) error
- func Fatalf(format string, args ...interface{})
- func GOARCH(goarch string) func(*Context) error
- func GOOS(goos string) func(*Context) error
- func GcToolchain() func(c *Context) error
- func Gcflags(flags string) func(*Context) error
- func Infof(format string, args ...interface{})
- func Ldflags(flags string) func(*Context) error
- func SourceDir(root string) func(*Project)
- func Warnf(format string, args ...interface{})
- type Action
- type Context
- func (c *Context) AllPackages(pattern string) []string
- func (c *Context) Destroy() error
- func (c *Context) IncludePaths() []string
- func (c *Context) Pkgdir() string
- func (c *Context) ResolvePackage(path string) (*Package, error)
- func (c *Context) ResolvePackageWithTests(path string) (*Package, error)
- func (c *Context) Workdir() string
- type Package
- type Project
- type Srcdir
- type Statistics
- type Task
- type TaskFn
- type Toolchain
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( // Quiet suppresses all logging output below ERROR Quiet bool // Verbose enables logging output below INFO Verbose bool )
Functions ¶
func Build ¶
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 ExecuteConcurrent ¶
ExecuteConcurrent executes all actions in a tree concurrently. Each Action will wait until its dependant actions are complete.
func GcToolchain ¶
Types ¶
type Action ¶
type Action struct { // Name describes the action. Name string // Deps identifies the Actions that this Action depends. Deps []*Action // Task identifies the that this action represents. Task }
An Action describes a task to be performed and a set of Actions that the task depends on.
func BuildDependencies ¶
BuildDependencies returns a slice of Actions representing the steps required to build all dependant packages of this package.
func BuildPackage ¶
BuildPackage returns an Action representing the steps required to build this package.
func BuildPackages ¶
BuildAction produces a tree of *Actions that can be executed to build a *Package. BuildAction walks the tree of *Packages and returns a corresponding tree of *Actions representing the steps required to build *Package and any of its dependencies
type Context ¶
type Context struct { *Project Context *build.Context Statistics Force bool // force rebuild of packages SkipInstall bool // do not cache compiled packages // contains filtered or unexported fields }
Context represents an execution of one or more Targets inside a Project.
func (*Context) AllPackages ¶
AllPackages returns all the packages that can be found under the $PROJECT/src directory. The pattern is a path including "...".
func (*Context) IncludePaths ¶
IncludePaths returns the include paths visible in this context.
func (*Context) ResolvePackage ¶
ResolvePackage resolves the package at path using the current context.
func (*Context) ResolvePackageWithTests ¶
ResolvePackageWithTests resolves the package at path using the current context it also resolves the internal and external test dependenices, although these are not returned, only cached in the Context.
type Package ¶
type Package struct { *Context *build.Package Scope string // scope: build, test, etc ExtraIncludes string // hook for test Stale bool // is the package out of date wrt. its cached copy Standard bool // is this package part of the standard library }
Package represents a resolved package from the Project with respect to the Context.
func NewPackage ¶
NewPackage creates a resolved Package.
Example ¶
package main import ( "log" "path/filepath" "github.com/constabulary/gb" ) func main() { // 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, gb.SourceDir(filepath.Join(root, "src")), // $PROJECT/src gb.SourceDir(filepath.Join(root, "vendor", "src")), // $PROJECT/vendor/src ) // Create a new Context from the Project. A Context holds // the state of a specific compilation or test within the Project. ctx, err := proj.NewContext() if err != nil { log.Fatal("Could not create new context:", err) } // Always remember to clean up your Context ctx.Destroy() }
Output:
type Project ¶
type Project struct {
// contains filtered or unexported fields
}
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 ¶
func (*Project) NewContext ¶
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 (*Project) Projectdir ¶
Projectdir returns the path root of this project.
type Statistics ¶
Statistics records the various Durations
func (*Statistics) String ¶
func (s *Statistics) String() string
func (*Statistics) Total ¶
func (s *Statistics) Total() time.Duration
type Task ¶
type Task interface { // Run will initiate the work that this task represents and // block until the work is complete. Run() error }
Task represents some work to be performed. It contains a single method Run, which is expected to be executed at most once.
type Toolchain ¶
type Toolchain interface { Gc(pkg *Package, searchpaths []string, importpath, srcdir, outfile string, files []string) error Asm(pkg *Package, srcdir, ofile, sfile string) error Pack(pkg *Package, afiles ...string) error Ld(*Package, []string, string, string) 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.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package command holds support functions and types for writing gb and gb plugins
|
Package command holds support functions and types for writing gb and gb plugins |
gb
gb, a project based build tool for the Go programming language.
|
gb, a project based build tool for the Go programming language. |
gb-vendor
gb-vendor, a gb plugin to manage your vendored dependencies.
|
gb-vendor, a gb plugin to manage your vendored dependencies. |