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 ¶
- func Build(pkgs ...*Package) error
- func Execute(a *Action) error
- func ExecuteConcurrent(a *Action, n int) error
- 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 Ldflags(flags ...string) func(*Context) error
- func SourceDir(root string) func(*Project)
- func Tags(tags ...string) func(*Context) error
- func Workdir(pkg *Package) string
- type Action
- type Context
- type Package
- type Project
- type Resolver
- type Srcdir
- type Statistics
- type Toolchain
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
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 // 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 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 ¶
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
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.
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:
func ResolvePackages ¶ added in v0.3.0
ResolvePackages resolves import paths to packages.
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 Resolver ¶ added in v0.3.0
type Resolver interface { // ResolvePackage resolves the import path to a *Package ResolvePackage(path string) (*Package, error) }
Resolver resolves packages.
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 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. |