Documentation
¶
Overview ¶
Package gomake provides a makefile-like syntax to define rules and their dependencies.
gomake is designed to be imported and used to create a main package with rules to make your program. We can start off by writing a Gomakefile that will build itself:
package main import ( "fmt" "os" "os/exec" "github.com/hinshun/gomake" ) func main() { gomakefile := gomake.NewGomakefile() rebuild := gomakefile.AddRule("gomake", nil, func() error { cmd := exec.Command("go", "build") cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr return build.Run() }) // Sets the default target gomakefile.Targets[""] = rebuild err := gomake.Gomake(gomakefile).Run(os.Args) if err != nil { fmt.Println(err) os.Exit(-1) } }
Index ¶
Constants ¶
const (
// Version is the current version of gomake.
Version = "0.1.0"
)
Variables ¶
var ( // ErrNoSuchTarget is returned if a Gomakefile is ran with an unknown target. ErrNoSuchTarget = errors.New("no such target") )
Functions ¶
func Evaluate ¶
Evaluate traverses root rule's dependency graph and creates goroutines for all rules it visit. Each goroutine will wait for its dependencies to be evaluated before evaluating itself, but if any dependency evaluates with an error, it will exit early.
func Gomake ¶
func Gomake(gomakefile *Gomakefile) *cli.App
Gomake creates a cli app for the given Gomakefile.
func HandleResults ¶
HandleResults displays all the target errs and returns a combined error.
Types ¶
type Gomakefile ¶
Gomakefile is a Makefile representation for gophers.
func NewGomakefile ¶
func NewGomakefile() *Gomakefile
NewGomakefile initializes a Gomakefile that can rebuild itself.
type Rule ¶
type Rule struct { // Target is the identifier for the rule in the results from Evaluate. Target string // Description is an optional field describing the rule. Description string // Dependencies is a list of rules that must be evaluated before this. Dependencies []*Rule // Evaluate is the arbitrary function to evaluate the rule. Evaluate func() error }
Rule is a node in a dependency graph.