Documentation
¶
Overview ¶
A very simple build system written in 100% golang to avoid the need to have cmake as a dependency.
Index ¶
- Constants
- Variables
- func AllGoTargets() *goTargets
- func Cd(dir string) error
- func CreateFile(name string) (*os.File, error)
- func GitRevParse(ctxt context.Context) (string, error)
- func LogErr(fmt string, args ...any)
- func LogInfo(fmt string, args ...any)
- func LogPanic(fmt string, args ...any)
- func LogQuietInfo(fmt string, args ...any)
- func LogSuccess(fmt string, args ...any)
- func LogWarn(fmt string, args ...any)
- func Main(progName string)
- func Mkdir(path string) error
- func NewGoTargets() *goTargets
- func Open(name string) (*os.File, error)
- func RegisterBsBuildTarget()
- func RegisterCommonGoCmdTargets(g *goTargets)
- func RegisterGoEnumTargets()
- func RegisterGoMarkDocTargets()
- func RegisterMergegateTarget(a MergegateTargets)
- func RegisterSqlcTargets(pathInRepo string)
- func RegisterTarget(ctxt context.Context, name string, stages ...StageFunc)
- func RegisterUpdateDepsTarget()
- func RmDir(path string) error
- func RmFile(path string) error
- func Run(ctxt context.Context, pipe io.Writer, prog string, args ...string) error
- func RunCwd(ctxt context.Context, pipe io.Writer, cwd string, prog string, args ...string) error
- func RunCwdStdout(ctxt context.Context, cwd string, prog string, args ...string) error
- func RunStdout(ctxt context.Context, prog string, args ...string) error
- func RunTarget(ctxt context.Context, target string, cmdLineArgs ...string)
- func TmpEnvVarSet(name string, val string) (reset func() error, err error)
- func Touch(name string) error
- type MergegateTargets
- type StageFunc
- type TargetFunc
Constants ¶
const DefaultBenchTargetName = "bench"
const DefaultFmtTargetName = "fmt"
const DefaultGenerateTargetName = "generate"
const DefaultTestTargetName = "test"
Variables ¶
var ( // An error that a stage can return to stop the target it is part of from // further execution. This is intended to be used when other error // information has been printed to the console. StopErr = errors.New("Generic stop error. See log above for error details.") )
Functions ¶
func AllGoTargets ¶
func AllGoTargets() *goTargets
func Cd ¶
A utility function that changes the programs current working directory and logs the old and new current working directories.
func CreateFile ¶
A utility function that creates a file and logs the file's path.
func GitRevParse ¶
A helpful utility function that runs `git rev-parse --show-toplevel` and returns the stdout. This is often useful when attempting to change the current working directory to a repositories root directory.
func Main ¶
func Main(progName string)
The main function that runs the build system. This is intended to be called by the `main` function of any code that uses this library.
func Mkdir ¶
A utility function that creates the supplied directory as well as all necessary parent directories.
func NewGoTargets ¶
func NewGoTargets() *goTargets
func RegisterBsBuildTarget ¶
func RegisterBsBuildTarget()
Registers a target that rebuilds the build system. This is often useful when changes are made to the build system of a project.
func RegisterCommonGoCmdTargets ¶
func RegisterCommonGoCmdTargets(g *goTargets)
Registers some common go cmds as targets. See the MergegateTargets struct for details about the available targets that can be added.
func RegisterGoEnumTargets ¶
func RegisterGoEnumTargets()
Registers one target:
- The first target will run install go-enum in ~/go/bin
func RegisterGoMarkDocTargets ¶
func RegisterGoMarkDocTargets()
Registers two targets:
- The first target will run gomarkdoc, embeding the results in README.md
- The second target will install gomarkdoc using go intstall
func RegisterMergegateTarget ¶
func RegisterMergegateTarget(a MergegateTargets)
Registers a mergegate target that will perform the actions that are defined by the MergegateTargets struct. See the MergegateTargets struct for details about the available stages the mergegate target can run.
func RegisterSqlcTargets ¶
func RegisterSqlcTargets(pathInRepo string)
Registers two targets:
- The first target will run sqlc generate in the provided path, relative to the repo root dir.
- The second target will install sqlc using go intstall
func RegisterTarget ¶
Registers a new build target to the build system. When run, the new target will sequentially run all provided stages, stopping if an error is encountered.
func RegisterUpdateDepsTarget ¶
func RegisterUpdateDepsTarget()
Registers a target that updates all dependences. Dependencies that are in the `barbell-math` repo will always be pinned at latest and all other dependencies will be updated to the latest version.
func Run ¶
Runs the program with the specified `args` using the supplied context in the current working directory. The supplied pipe will be used to capture Stdout. Stderr will always be printed to the console.
func RunCwd ¶
Runs the program with the specified `args` using the supplied context. The supplied pipe will be used to capture Stdout. Stderr will always be printed to the console.
func RunCwdStdout ¶
Runs the program with the specified `args` using the supplied context. All output of the program will be printed to stdout. Equivalent to calling Run and providing os.Stdout for the `pipe` argument.
func RunStdout ¶
Runs the program with the specified `args` using the supplied context in the current working directory. All output of the program will be printed to stdout. Equivalent to calling Run and providing os.Stdout for the `pipe` argument.
func RunTarget ¶
Runs the supplied target, given that the supplied target is present in the build systems target list. Execution of all further targets/stages will stop if running the supplied target fails.
func TmpEnvVarSet ¶
A utility function that changes the supplied env variable to the supplied value, returning a closure that can be used to set the env variable back to it's original value. If the supplied env variable did not exist before calling this function then the returned closure will remove the env variable instead of reseting it to it's original value.
Types ¶
type MergegateTargets ¶
type MergegateTargets struct {
// When true a stage will update all deps and run a diff to make sure that
// the commited code is using all of the up to date dependencies.
CheckDepsUpdated bool
// When true a stage will install gomarkdoc, update the readme using the
// `gomarkdocReadme` target, and run a diff to make sure that the committed
// readme is up to date.
CheckReadmeGomarkdoc bool
// When supplied, the given target will be expected to format the code. A
// diff will then be run to make sure that the commited code is properly
// formated.
FmtTarget string
// When supplied, the given target will be expected to test the code to make
// sure the commited code passes all unit tests.
TestTarget string
// When supplied, the given target will be expected to generate the code
// required for the project. A diff will then be run to make sure that the
// commited code is properly formated.
GenerateTarget string
// Any stages that should be run prior to all other mergegate stages as
// defined by the other flags in this struct. Useful for installing
// dependencies that the other stages might rely upon.
PreStages []StageFunc
// Any stages that should be run after all other mergegate stages as defined
// by the other flags in this struct. Useful for adding additional mergegate
// checks.
PostStages []StageFunc
}
Defines all possible stages that can run in a mergegate target.
type StageFunc ¶
The function that will be executed to perform an operation for a given target. The supplied context is meant to be used to control the runtime of the stage operation.
func CdToRepoRoot ¶
func CdToRepoRoot() StageFunc
Changes the current working directory to the repositories root directory if the current working directory is inside a repo. Results in an error if the current working directory is not inside a repo.
func GitDiffStage ¶
Runs git diff on the current directory and if any output is returned prints the given error message, the diff result, and suggests a target to run to fix the issue if `targetToRun` is not an empty string. An error will be returned if the diff returns any a non-empty result.
func Stage ¶
Creates a stage that can be added to a build target. Stages define the operations that will take place when a build target is executing. The supplied context can be modified and passed to Run functions to deterministically control how long various operations take. This prevents builds from hanging forever.
func TargetAsStage ¶
Runs the supplied target as though it were a stage, given that the supplied target is preset in the build systems target list. Execution of all further targets/stages will stop if running the supplied target fails.
type TargetFunc ¶
type TargetFunc func(cmdLineArgs ...string)
The function that will be executed when a target is run. This function will be given all of the leftover cmd line arguments that were supplied after the target. Parsing of these arguments is up to the logic defined be the targets stages.