build

package module
v1.13.1 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2023 License: MIT Imports: 24 Imported by: 5

README

Build

Yet another implementation of Makefile concept in go. Advantages over all the other available packages:

  • go only, except really small bash script
  • no magic command discovery based on go source code, you explicitly declare paths and functions for your commands
  • bash autocompletion supported
  • command functions are executed using IoC container so they may receive any interfaces required to do the job

Example

Take a look at example/main.go

Compilation

This build system is written in pure go so you have to compile it using go build before first usage. Take a look at the script I use in my setup.

I configure this script using alias feature delivered by bash in my ~/.bashrc:

alias projname="outofforest-build <path-to-project>"

outofforest-build is this script. Each release delivers rpm package for compatible distros, installing it in your system.

Then I may call:

$ projname <command> <command>

to execute commands.

Autocompletion

build supports autocompletion natively. To use it add this line to your ~/.bashrc:

complete -o nospace -C projname projname

assuming you defined projname alias specified above.

Executing commands

Commands are organised in paths similar to the one in normal filesystem. Some examples how commands may be structured:

projname tools/apiClient
projname deploy/db
projname tests/backend/web-server
projname lint

You may specify many commands at once:

projname tests deploy

They are executed in specified order. This will save some time if both commands execute same dependencies.

Dependencies

Every command may specify dependencies - other commands which have to finish before the actual one may continue. It allows you to move some code common to many commands to another function.

If many commands require the same dependency, it is executed once.

Dependencies are executed one by one in order.

If circular dependency is detected error is raised.

Other features

List of commands

Execute

$ projname @

to print available commands with their descriptions.

Verbose logging

If you want to see more logs during command execution, use -v or --verbose:

$ projname <command> -v

Errors

build always breaks on first failure.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EnsureTool added in v1.5.1

func EnsureTool(ctx context.Context, tool Tool) error

EnsureTool ensures that tool exists, if not it is installed

func GetName added in v1.5.1

func GetName(ctx context.Context) string

GetName returns name passed to `Main` function

func InstallTools added in v1.5.1

func InstallTools(ctx context.Context, tools ...map[string]Tool) error

InstallTools installs tools

func Main added in v1.7.14

func Main(name string, commands map[string]Command)

Main receives configuration and runs commands

Types

type Command added in v1.8.0

type Command struct {
	Description string
	Fn          interface{}
}

type DepsFunc

type DepsFunc func(deps ...interface{})

DepsFunc represents function for executing dependencies

type Executor

type Executor interface {
	// Execute executes commands by their paths
	Execute(ctx context.Context, name string, paths []string) error
}

Executor defines interface of command executor

func NewIoCExecutor

func NewIoCExecutor(commands map[string]Command, c *ioc.Container) Executor

NewIoCExecutor returns new executor using IoC container to resolve parameters of commands

type Tool added in v1.5.1

type Tool struct {
	// Name is the name of the tool
	Name string

	// Version is the version of the tool
	Version string

	// IsGlobal instructs us to install the tool in global bin folder
	IsGlobal bool

	// URL is the url to the archive containing the tool
	URL string

	// Hash is the hash of the downloaded file
	Hash string

	// Binaries is the list of relative paths to binaries to install in local bin folder
	Binaries map[string]string
}

Tool represents the tool to be required by the build system

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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