makex

package module
v0.0.0-...-3f62e8d Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2016 License: BSD-3-Clause Imports: 17 Imported by: 53

README

makex

makex is a make clone for Go that makes it easier to write build tools in Go. It lets you define tasks and dependencies in the familiar Makefile format, and unlike just shelling out to make, it gives you programmatic access (in Go) to the progress and console output of your tasks. We use makex at Sourcegraph to compile and analyze hundreds of thousands of your open-source projects.

Documentation: makex on Sourcegraph

Build Status status

Install

go get sourcegraph.com/sourcegraph/makex/cmd/makex
makex -h

Usage

Try running makex on the Makefiles in the testdata/ directory.

$ cat testdata/sample0/y
cat: testdata/sample0/y: No such file or directory
$ makex -v -C testdata -f testdata/Makefile.sample0
makex: [sample0/y] mkdir -p sample0
makex: [sample0/y] echo hello bar > sample0/y
$ cat testdata/sample0/y
hello bar
$ makex -v -C testdata -f testdata/Makefile.sample0
$
$ ls testdata/sample1/
y1
$ makex -v -C testdata -f testdata/Makefile.sample1
makex: [sample1/y0] echo hello bar > sample1/y0
$ ls testdata/sample1/
y0  y1
$ makex -v -C testdata -f testdata/Makefile.sample1
$

Known issues

makex is very incomplete.

  • No support for setting or expanding variables (except for special-cased support for $@ and $^)
  • No support for filesystem globs except in the OS filesystem (not in VFS filesystems).
  • Many other issues.

Documentation

Overview

Package makex implements an experimental, incompatible `make`.

Index

Constants

This section is empty.

Variables

View Source
var Default = Config{
	ParallelJobs: 1,
}

Functions

func ExpandAutoVars

func ExpandAutoVars(rule Rule, s string) string

ExpandAutoVars expands the automatic variables $@ (the current target path) and $^ (the space-separated list of prereqs) in s.

func External

func External(dir string, makefile []byte, args []string) ([]byte, error)

External runs makefile using the system `make` tool, optionally passing extra args.

func Flags

func Flags(fs *flag.FlagSet, conf *Config, prefix string)

Flags adds makex command-line flags to an existing flag.FlagSet (or the global FlagSet if fs is nil).

func Marshal

func Marshal(mf *Makefile) ([]byte, error)

Marshal returns the textual representation of the Makefile, in the usual format:

target: prereqs
	recipes

...

func Quote

func Quote(s string) string

Quote IS NOT A SAFE WAY TO ESCAPE USER INPUT. It hackily escapes special characters in s and surrounds it with quotation marks if needed, so that the shell interprets it as a single argument equal to s. DON'T RELY ON THIS FOR SECURITY.

TODO(sqs): come up with a safe way of escaping user input

func QuoteList

func QuoteList(ss []string) []string

QuoteList IS NOT A SAFE WAY TO ESCAPE USER INPUT. It returns a list whose elements are the escaped elements of ss (using Quote). DON'T RELY ON THIS FOR SECURITY.

TODO(sqs): come up with a safe way of escaping user input

func Targets

func Targets(rules []Rule) []string

Targets returns the list of targets defined by rules.

Types

type BasicRule

type BasicRule struct {
	TargetFile  string
	PrereqFiles []string
	RecipeCmds  []string
}

BasicRule implements Rule.

Use BasicRule for rules that you don't need to introspect programmatically. If you need to store additional metadata about rules, create a separate type that implements Rule and holds the metadata.

func (*BasicRule) Prereqs

func (r *BasicRule) Prereqs() []string

Prereqs implements Rule.

func (*BasicRule) Recipes

func (r *BasicRule) Recipes() []string

Recipes implements rule.

func (*BasicRule) Target

func (r *BasicRule) Target() string

Target implements Rule.

type Config

type Config struct {
	FS           FileSystem
	ParallelJobs int
	Verbose      bool
	DryRun       bool
}

func (*Config) Expand

func (c *Config) Expand(orig *Makefile) (*Makefile, error)

Expand returns a clone of mf with Prereqs filepath globs expanded. If rules contain globs, they are replaced with BasicRules with the globs expanded.

Only globs containing "*" are detected.

func (*Config) NewMaker

func (c *Config) NewMaker(mf *Makefile, goals ...string) *Maker

NewMaker creates a new Maker, which can build goals in a Makefile.

type Errors

type Errors []error

func (Errors) Error

func (e Errors) Error() string

type FileSystem

type FileSystem interface {
	rwvfs.FileSystem
	Join(elem ...string) string
}

A FileSystem is a file system that can be read, written, and walked. Given an existing rwvfs.FileSystem, use NewFileSystem to add the Join method (which will use the current OS's filepath.Separator).

func NewFileSystem

func NewFileSystem(fs rwvfs.FileSystem) FileSystem

NewFileSystem returns a FileSystem with Join method (which will use the current OS's filepath.Separator).

type Makefile

type Makefile struct {
	Rules []Rule
}

Makefile represents a set of rules, each describing how to build a target.

func Parse

func Parse(data []byte) (*Makefile, error)

Parse parses a Makefile into a *Makefile struct.

TODO(sqs): super hacky.

func (*Makefile) DefaultRule

func (mf *Makefile) DefaultRule() Rule

DefaultRule is the first rule whose name does not begin with a ".", or nil if no such rule exists.

func (*Makefile) Rule

func (mf *Makefile) Rule(target string) Rule

Rule returns the rule to make the specified target if it exists, or nil otherwise.

TODO(sqs): support multiple rules for one target (http://www.gnu.org/software/make/manual/html_node/Multiple-Rules.html).

type Maker

type Maker struct {

	// RuleOutput specifies the writers to receive the stdout and stderr output
	// from executing a rule's recipes. After executing a rule, out and err are
	// closed. If RuleOutput is nil, os.Stdout and
	// os.Stderr are used, respectively (but not closed after use).
	RuleOutput func(Rule) (out io.WriteCloser, err io.WriteCloser, logger *log.Logger)

	// Channels to monitor progress. If non-nil, these channels are called at
	// various stages of building targets. Ended is always called *after*
	// Succeeded or Failed.
	Started, Ended, Succeeded chan<- Rule
	Failed                    chan<- RuleBuildError

	*Config
	// contains filtered or unexported fields
}

A Maker can build goals in a Makefile.

func (*Maker) DryRun

func (m *Maker) DryRun(w io.Writer) error

DryRun prints information about what targets *would* be built if Run() was called.

func (*Maker) Run

func (m *Maker) Run() error

Run builds all stale targets.

func (*Maker) TargetSets

func (m *Maker) TargetSets() [][]string

TargetSets returns a topologically sorted list of sets of target names. To only get targets that are stale and need to be built, use TargetSetsNeedingBuild.

func (*Maker) TargetSetsNeedingBuild

func (m *Maker) TargetSetsNeedingBuild() ([][]string, error)

TargetSetsNeedingBuild returns a topologically sorted list of sets of target names that need to be built (i.e., that are stale).

type Rule

type Rule interface {
	Target() string
	Prereqs() []string
	Recipes() []string
}

A Rule describes a target file, a list of commands (recipes) used to create the target output file, and the files (which may also have corresponding rules) that must exist prior to running the recipes.

It is a slightly simplified representation of a standard "make" rule.

type RuleBuildError

type RuleBuildError struct {
	Rule Rule
	Err  error
}

func (RuleBuildError) Error

func (e RuleBuildError) Error() string

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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