gomake

package module
v0.0.0-...-97f1b17 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 26, 2017 License: MIT Imports: 6 Imported by: 0

README

gomake

Build Status GoDoc codebeat badge Go Report Card gocover badge

Makefile for gophers

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

View Source
const (
	// Version is the current version of gomake.
	Version = "0.1.0"
)

Variables

View Source
var (
	// ErrNoSuchTarget is returned if a Gomakefile is ran with an unknown target.
	ErrNoSuchTarget = errors.New("no such target")
)

Functions

func Evaluate

func Evaluate(root *Rule) map[string]error

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

func HandleResults(results map[string]error) error

HandleResults displays all the target errs and returns a combined error.

Types

type Gomakefile

type Gomakefile struct {
	// Targets is the map of target names to Rules.
	Targets map[string]*Rule
}

Gomakefile is a Makefile representation for gophers.

func NewGomakefile

func NewGomakefile() *Gomakefile

NewGomakefile initializes a Gomakefile that can rebuild itself.

func (*Gomakefile) AddRule

func (g *Gomakefile) AddRule(target string, dependencies []*Rule, evaluate func() error) *Rule

AddRule creates a new rule and adds it to the Gomakefile.

func (*Gomakefile) Make

func (g *Gomakefile) Make(target string) map[string]error

Make makes the target rule and its dependencies.

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.

func NewRule

func NewRule(target string, dependencies []*Rule, evaluate func() error) *Rule

NewRule initializes a new named Rule with its direct dependencies and evaluate function.

Directories

Path Synopsis
cmd
pkg
cli
Package cli is a very minimal framework for creating command line applications.
Package cli is a very minimal framework for creating command line applications.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL