building

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

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

Go to latest
Published: Dec 2, 2018 License: Apache-2.0 Imports: 27 Imported by: 0

README

Brique

A quest for the perfect build tool.

Why Brique?

Many Go projects use make to drive the build, however it has several drawbacks including its severe lack of portability on the Windows platform.

Even if it's possible to find an implementation of make for Windows, it's not as readily available as for Linux and Darwin. The biggest problem however is that a Makefile usually relies on the underlying shell for most features and something as simple as tar or even rm is difficult to provide or write properly on Windows.

For any good size multi-platform project this often means ending up with build code difficult to maintain sometimes using multiple scripting languages (Makefile, shell, bash, PowerShell, batch, python, …).

Brique aims at unifying all this by making it possible to use Go as the build code.

What is Brique?

Brique is a build tool for Go projects made of three parts:

  • a Go binary called b (or b.exe on Windows) which creates and invokes on the fly a custom binary specifically tailored to build each project
  • a Go package of bricks (called building) to help with implementing the build features needed by each project
  • a Shell and a Batch script to bootstrap the build and allow to vendor the whole tool chain in each project

The goal of Brique is to create a build environment which is:

  • with a low barrier of entry (build written in Go, no tool chain to install)
  • fast (especially when nothing needs to be done)
  • extensible (linters, coverage, release, signing, …)
  • multi-platform (single code, cross-compilation, parallel builds)
  • build server friendly (reproducible, cleans after itself, no requirements other than Docker)

Using containers provides a nice way to fulfill most of these requirements, however they tend to be slow: either project files must be baked into an image and artifacts copied back from a container, or volumes must be mounted to share project files with a container and they are quite slow (on Windows mainly and Darwin also).

Brique works around this by providing build fallbacks. For instance if a tool (e.g. go) is available it will be used directly, if not but Docker is available, Brique will spin a container to use the tool.

This flexibility allows for casual developpers on a project (or product managers or build servers) to build a project right away without having to figure out which tool chain is needed, while core developpers building more frequently will probably want to install most of the required tools to minimize the build times.

Brique provides a library of build tools wrappers and is very easy to extend with more custom wrappers as needed.

How to get started with Brique?

Of course Brique can be used on itself!

For a quick glance at a project build code using Brique look at cmd/build/build.go.

To find out how to build simply invoke ./build.sh or build.bat at the root of the project with the -help flag:

$ ./build.sh -help
Usage: build [OPTIONS] [TARGETS]

Options:
  -containers
        always build in containers
  -cross
        build for all platforms (linux, darwin, windows)
  -parallel
        build in parallel
  -q    quiet output
  -test.run string
        pattern to filter the tests
  -v    verbose output

Targets:
  all   does everything
  depends
        retrieves the dependencies
  test  runs the tests

This output gets generated on the fly, a bit like what go test does with parsing files ending in _test.go to extract test functions matching the test designated signature, except here Brique looks for an exported func Xyz(b *building.B).

The comments above target functions are used as descriptions for the targets listed in the help.

The first target in the Go build file becomes the default one, meaning here calling ./build.sh or build.bat with no argument will invoke the all target, e.g.:

$ ./build.sh
build started
> all
running [dep ensure]
running [go test -test.run  ./...]
ok      github.com/mat007/brique        (cached)
?       github.com/mat007/brique/cmd/build      [no test files]
< all (took 19.5013775s)
build finished (took 19.503879s)

How to use Brique?

Brique releases no binary because it's designed to be entirely vendored.

To add Brique to a project follow these steps:

  • Add both build.sh and build.bat to the project root folder
  • In both build.sh and build.bat change the PACKAGE_NAME variable to the project package name
  • Create a file cmd/build/build.go with the content:
package build

import (
	"github.com/mat007/brique"
)

// All does everything
func All(b *building.B) {
	fmt.Println("OK!)
}
  • Use your vendoring tool to bring Brique in
  • Test by invoking build.sh or build.bat from the project root folder

Where to go next with Brique?

The project is still in alpha phase and has no stable API yet, meaning it may be a bit early to use in production. However the only way to gather feedback and shape it properly now would be to start using it in real world projects.

It also needs proper end-to-end tests, continuous integration, more documentation and also feedback, feedback and feedback!

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Quiet   = flag.Bool("q", false, "quiet output")
	Verbose = flag.Bool("v", false, "verbose output")
)
View Source
var (
	AlpineVersion = "3.8"
)
View Source
var DepVersion = "v0.4.1"
View Source
var GoMetaLinterVersion = "2.0.5"
View Source
var GoVersion = "1.10.3"
View Source
var VndrCommit = "1fc68ee0c852556a9ed53cbde16247033f104111"

Functions

func CatchFailure

func CatchFailure(start time.Time)

func Main

func Main()

Types

type B

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

func Builder

func Builder() *B

func Init

func Init(pkgName string) *B

func (*B) Assert

func (b *B) Assert(err error)

func (*B) Build

func (b *B) Build(t target)

func (*B) Check

func (b *B) Check(err error)

func (*B) Close

func (b *B) Close(c io.Closer)

func (*B) Copy

func (b *B) Copy(destination string, paths ...string) Copy

Copy handles copying files and folders.

func (*B) Debug

func (b *B) Debug(v ...interface{})

func (*B) Debugf

func (b *B) Debugf(format string, v ...interface{})

func (*B) Debugln

func (b *B) Debugln(v ...interface{})

func (*B) Dep

func (b *B) Dep(args ...string) Tool

func (*B) Docker

func (b *B) Docker(args ...string) Tool

func (*B) Exe

func (b *B) Exe(os string) string

func (*B) Fatal

func (b *B) Fatal(v ...interface{})

func (*B) Fatalf

func (b *B) Fatalf(format string, v ...interface{})

func (*B) Fatalln

func (b *B) Fatalln(v ...interface{})

func (*B) Git

func (b *B) Git(args ...string) Tool

func (*B) GitCommit

func (b *B) GitCommit() string

func (*B) GitDirty

func (b *B) GitDirty() bool

func (*B) GitShortCommit

func (b *B) GitShortCommit() string

func (*B) GitTag

func (b *B) GitTag() string

func (*B) GitVersion

func (b *B) GitVersion() string

func (*B) Go

func (b *B) Go(args ...string) Tool

$$$$ MAT go verbose with -v ?

func (*B) GoMetaLinter

func (b *B) GoMetaLinter(args ...string) Tool

func (*B) Helper

func (b *B) Helper()

func (*B) Jq

func (b *B) Jq(args ...string) Tool

func (*B) MakeCommand

func (b *B) MakeCommand(name string, args ...string) Command

func (*B) MakeTarget

func (b *B) MakeTarget(name, description string, f func(*B)) target

func (*B) MakeTool

func (b *B) MakeTool(name, check, url, instructions string, args ...string) Tool

func (*B) Print

func (b *B) Print(v ...interface{})

func (*B) Printf

func (b *B) Printf(format string, v ...interface{})

func (*B) Println

func (b *B) Println(v ...interface{})

func (*B) Remove

func (b *B) Remove(paths ...string) Remove

Remove handles files and folders deletion.

func (*B) Run

func (b *B) Run()

func (*B) Tar

func (b *B) Tar(args ...string) compression

func (*B) Vndr

func (b *B) Vndr(args ...string) Tool

$$$$ MAT: with-git-proxy

func (*B) WithOS

func (b *B) WithOS(f func(goos string))

func (*B) Zip

func (b *B) Zip(args ...string) compression

type Command

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

func (Command) Run

func (c Command) Run(args ...string) int

func (Command) WithDir

func (c Command) WithDir(dir string) Command

func (Command) WithEnv

func (c Command) WithEnv(env ...string) Command

func (Command) WithOutput

func (c Command) WithOutput(w io.Writer) Command

func (Command) WithSuccess

func (c Command) WithSuccess() Command

type Copy

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

Copy wraps a files and folders copy operation.

func (Copy) Run

func (c Copy) Run()

Run performs the copy.

func (Copy) WithFiles

func (c Copy) WithFiles(paths ...string) Copy

WithFiles adds files and folders to copy.

func (Copy) WithFileset

func (c Copy) WithFileset(dir, includes, excludes string) Copy

WithFileset adds a fileset to copy.

type Remove

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

Remove wraps a files and folders remove operation.

func (Remove) Run

func (r Remove) Run(paths ...string)

Run performs the deletion.

func (Remove) WithFiles

func (r Remove) WithFiles(paths ...string) Remove

WithFiles adds a list of files and folders for deletion.

func (Remove) WithFileset

func (r Remove) WithFileset(dir, includes, excludes string) Remove

WithFileset adds a fileset for deletion.

type Tar

type Tar struct{}

func (Tar) Write

func (t Tar) Write(w io.Writer, level int, dst string, srcs []fileset) error

type Tool

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

func (Tool) Run

func (t Tool) Run(args ...string) int

func (Tool) WithDir

func (t Tool) WithDir(dir string) Tool

func (Tool) WithEnv

func (t Tool) WithEnv(env ...string) Tool

func (Tool) WithInput

func (t Tool) WithInput(r io.Reader) Tool

func (Tool) WithOutput

func (t Tool) WithOutput(w io.Writer) Tool

func (Tool) WithSuccess

func (t Tool) WithSuccess() Tool

func (Tool) WithTool

func (t Tool) WithTool(tool Tool) Tool

type Zip

type Zip struct{}

func (Zip) Write

func (z Zip) Write(w io.Writer, level int, dst string, srcs []fileset) error

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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