make

package module
v0.0.0-...-af4a42d Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2022 License: BSD-3-Clause Imports: 11 Imported by: 1

README

import.name/make is a build system where you specify tasks by writing Go code. It is not intended for building Go code, as the Go toolchain already has that covered. Instead, it can be used to build non-Go artifacts of projects that already depend on the Go toolchain.

Add file make.go to your project root:

//go:build ignore
// +build ignore

package main

import . "import.name/make"

func main() { Main(targets, "make.go", "go.mod") }

func targets() (targets Tasks) {
	// ...
	return
}

Build your project by invoking:

go run make.go
go run make.go my-target
go run make.go my-target another-target FOO=bar BAZ=quux

Show usage and list available targets and variables:

go run make.go -h

See a practical example. If, after eyeballing that for a while, you wonder whether some feature is supported, the answer is probably no (unless you're willing to implement it yourself in Go).

Documentation

Overview

Package make is a simple build system.

Index

Constants

View Source
const (
	GOARCH = runtime.GOARCH
	GOOS   = runtime.GOOS
)

Variables

View Source
var Vars = make(map[string]string)

Vars specified on the command-line.

Functions

func All

func All(conds ...func() bool) func() bool

All conditions.

func Any

func Any(conds ...func() bool) func() bool

Any condition.

func Base

func Base(filename string) string

Base is path.Base().

func Dir

func Dir(filename string) string

Dir is path.Dir().

func Exists

func Exists(path string) bool

Exists path?

func Fields

func Fields(s string) []string

Fields is strings.Fields().

func Flatten

func Flatten(strings ...interface{}) []string

Flatten strings and string slices into single string slice. Flatten("foo", []string{"bar", "baz"}) returns []string{"foo", "bar", "baz"}. Flatten will panic if called with a type that is not string, []string, func() []string or []interface{}.

func Flattener

func Flattener(strings ...interface{}) func() []string

Flattener is a lazy version of Flatten.

func Getenv

func Getenv(key, defaultValue string) string

Getenv is like os.Getenv(), with default value support.

func Getvar

func Getvar(key, defaultValue string) string

Getvar specified on the command-line.

func Glob

func Glob(patterns ...string) []string

Glob terminates program on error. Results of multiple pattern will be concatenated.

func Globber

func Globber(patterns ...string) func() []string

Globber returns a function which globs or terminates program on error. Results of multiple pattern will be concatenated.

func Install

func Install(destination, sourceName string, executable bool) error

Install file.

func InstallData

func InstallData(destName string, source io.Reader, executable bool) error

InstallData file.

func Join

func Join(elem ...string) string

Join is path.Join().

func Main

func Main(getTargets func() Tasks, main string, deps ...string)

Main program.

func Missing

func Missing(path string) func() bool

Missing condition.

func Outdated

func Outdated(target string, sources func() []string) func() bool

Outdated condition.

func Println

func Println(strs ...interface{})

Println prints space-separated strings and a newline. The arguments will be Flatten'ed.

func ReplaceSuffix

func ReplaceSuffix(s, newSuffix string) string

ReplaceSuffix replaces the dot-separated suffix of the filename part of a path, or panics.

func Run

func Run(command ...string) error

Run command.

func RunIO

func RunIO(input io.Reader, command ...string) (output []byte, err error)

RunIO command.

func Setenv

func Setenv(key, value string)

Setenv is like os.Setenv(), but program is terminated on error.

func Thunk

func Thunk(strings ...string) func() []string

Thunk returns a function which returns the string in a slice.

func Touch

func Touch(filename string) error

Touch file. Directories are created as needed.

Types

type Env

type Env map[string]string

Env variables.

func (Env) Command

func (env Env) Command(command ...interface{}) Task

Command task.

func (Env) String

func (env Env) String() string

String of environment variables.

func (Env) System

func (env Env) System(commandline string) Task

System task.

type Task

type Task struct {
	// contains filtered or unexported fields
}

Task to run.

func Command

func Command(command ...interface{}) Task

Command task.

func Directory

func Directory(dirpath string) Task

Directory creation task.

func DirectoryOf

func DirectoryOf(filename string) Task

DirectoryOf creation task.

func Func

func Func(f func() error) Task

Func task.

func Group

func Group(tasks ...Task) Task

Group tasks.

func If

func If(cond func() bool, tasks ...Task) Task

If task.

func Installation

func Installation(destName, sourceName string, executable bool) Task

Installation task.

func Removal

func Removal(directories ...string) Task

Removal task. Tries to os.RemoveAll the directory trees, and returns the first error.

func System

func System(commandline string) Task

System task.

func Target

func Target(name string, tasks ...Task) Task

Target tasks.

func TargetDefault

func TargetDefault(name string, tasks ...Task) Task

TargetDefault tasks.

type Tasks

type Tasks []Task

Tasks slice.

func (*Tasks) Add

func (ptr *Tasks) Add(task Task) Task

Add task at the end of the slice. Returns a copy.

Jump to

Keyboard shortcuts

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