Documentation ¶
Overview ¶
Package gomk helps to write build scripts in Go for projects where just running 'go build' is not enough. Instead of using platform-specific tools, a build script written in Go can better ensure platform independence. gomk is built around the core concepts of [Project], [Goal] and [Action]. The details are described in sub package gomkore. This packge wraps the code model from gomkore with a user-friendly API for building projects (see Edit).
gomk is just a Go library. Is can be used in any context of reasonable programming with Go. But gomk is not a comprehensive library for all types of project builds. It is focussed on the fundamentals of a build system. Specific applications shall be implemented in separate libraries, such as gomk-lib.
Nevertheless, a few conventions can be helpful. A build script is a Go executable. As such it cannot be used by other packages (using plugins is not considered, primarily for not generally being portable).
"mk.go" is the recommended file name for a build script
The build scripts of a project must not collide with the rest of the code. Here are a few ideas for structuring the build scripts:
Simple Go project with source in the root directory ¶
module/ ├── bar.go ├── foo.go ├── go.mod ├── go.sum └── mk └── mk.go
Build with
module$ go run mk/mk.go
Go project without code in the root directory ¶
module/ ├── cmd │ ├── bar │ │ └── main.go │ └── foo │ └── main.go ├── explib │ └── stuff.go ├── go.mod ├── go.sum ├── internal │ └── lib.go └── mk.go
Build with
module$ go run mk.go
Editing Projects ¶
TODO: gomkore vs. simple API through [gomk.Edit]
Example (PrefixWriter) ¶
pw := newPrefixWriterString(os.Stdout, "PRE:") io.WriteString(pw, "foo") io.WriteString(pw, "bar\n") io.WriteString(pw, "baz\nquux")
Output: PRE:foobar PRE:baz PRE:quux
Index ¶
- Constants
- func AType[A gomkore.Artefact](g *gomkore.Goal) bool
- func Clean(prj *gomkore.Project, dryrun bool, tr *gomkore.Trace) error
- func Edit(prj *gomkore.Project, do func(prj ProjectEd)) (err error)
- func Goals(gs []*gomkore.Goal, exclusive bool, matchAll ...func(*gomkore.Goal) bool) ([]*gomkore.Goal, error)
- func NewBuilder(tr *gomkore.Trace, env *gomkore.Env) *gomkore.Builder
- func NewChanger(tr *gomkore.Trace, env *gomkore.Env) *gomkore.Changer
- func OpFunc(desc string, f func(*gomkore.Trace, *gomkore.Action, *gomkore.Env) error) gomkore.Operation
- func Tangible(g *gomkore.Goal) bool
- type ActionEd
- type CmdOp
- type ConvertCmd
- type Diagrammer
- type ExtMap
- type GoBuild
- type GoGenerate
- type GoRun
- type GoTest
- type GoTool
- type GoalEd
- func (ed GoalEd) Artefact() gomkore.Artefact
- func (result GoalEd) By(op gomkore.Operation, premises ...GoalEd) (GoalEd, ActionEd)
- func (ed GoalEd) Goal() *gomkore.Goal
- func (ed GoalEd) ImpliedBy(premises ...GoalEd) GoalEd
- func (ed GoalEd) IsAbstract() bool
- func (ed GoalEd) Project() ProjectEd
- func (ed GoalEd) Removable() bool
- func (ed GoalEd) SetRemovable(flag bool)
- func (ed GoalEd) SetUpdateMode(m gomkore.UpdateMode)
- func (ed GoalEd) UpdateMode() gomkore.UpdateMode
- type OutFile
- type PipeOp
- type ProjectEd
- func (ed ProjectEd) AbstractGoal(name string) GoalEd
- func (ed ProjectEd) Dir() string
- func (ed ProjectEd) FsExists(a mkfs.Artefact) bool
- func (ed ProjectEd) FsStat(a mkfs.Artefact) fs.FileInfo
- func (ed ProjectEd) Goal(atf gomkore.Artefact) GoalEd
- func (ed ProjectEd) NewAction(premises, results []GoalEd, op gomkore.Operation) ActionEd
- func (ed ProjectEd) Project() *gomkore.Project
- func (ed ProjectEd) RelPath(p string) string
- type TestTracer
- func (tr TestTracer) CheckGoal(t *gomkore.Trace, g *gomkore.Goal)
- func (tr TestTracer) CloseActionEnv(t *gomkore.Trace, env *gomkore.Env) error
- func (tr TestTracer) Debug(t *gomkore.Trace, msg string, args ...any)
- func (tr TestTracer) DoneProject(t *gomkore.Trace, p *gomkore.Project, activity string, dt time.Duration)
- func (tr TestTracer) GoalNeedsActions(t *gomkore.Trace, g *gomkore.Goal, n int)
- func (tr TestTracer) GoalUpToDate(t *gomkore.Trace, g *gomkore.Goal)
- func (tr TestTracer) Info(t *gomkore.Trace, msg string, args ...any)
- func (tr TestTracer) RemoveArtefact(t *gomkore.Trace, g *gomkore.Goal)
- func (tr TestTracer) RunAction(_ *gomkore.Trace, a *gomkore.Action)
- func (tr TestTracer) RunImplicitAction(_ *gomkore.Trace, a *gomkore.Action)
- func (tr TestTracer) ScheduleNotPremises(t *gomkore.Trace, a *gomkore.Action, res *gomkore.Goal)
- func (tr TestTracer) ScheduleOutdated(t *gomkore.Trace, a *gomkore.Action, res, pre *gomkore.Goal)
- func (tr TestTracer) SchedulePreTimeZero(t *gomkore.Trace, a *gomkore.Action, res, pre *gomkore.Goal)
- func (tr TestTracer) ScheduleResTimeZero(t *gomkore.Trace, a *gomkore.Action, res *gomkore.Goal)
- func (tr TestTracer) SetupActionEnv(t *gomkore.Trace, env *gomkore.Env) (*gomkore.Env, error)
- func (tr TestTracer) StartProject(t *gomkore.Trace, p *gomkore.Project, activity string)
- func (tr TestTracer) Warn(t *gomkore.Trace, msg string, args ...any)
- type TraceLevel
- type WriteTracer
- func (tr WriteTracer) CheckGoal(t *gomkore.Trace, g *gomkore.Goal)
- func (tr WriteTracer) CloseActionEnv(t *gomkore.Trace, env *gomkore.Env) error
- func (tr WriteTracer) Debug(t *gomkore.Trace, msg string, args ...any)
- func (tr WriteTracer) DoneProject(t *gomkore.Trace, p *gomkore.Project, activity string, dt time.Duration)
- func (tr WriteTracer) GoalNeedsActions(t *gomkore.Trace, g *gomkore.Goal, n int)
- func (tr WriteTracer) GoalUpToDate(t *gomkore.Trace, g *gomkore.Goal)
- func (tr WriteTracer) Info(t *gomkore.Trace, msg string, args ...any)
- func (tr *WriteTracer) ParseLevelFlag(f string) error
- func (tr WriteTracer) RemoveArtefact(t *gomkore.Trace, g *gomkore.Goal)
- func (tr WriteTracer) RunAction(t *gomkore.Trace, a *gomkore.Action)
- func (tr WriteTracer) RunImplicitAction(t *gomkore.Trace, _ *gomkore.Action)
- func (tr WriteTracer) ScheduleNotPremises(t *gomkore.Trace, a *gomkore.Action, res *gomkore.Goal)
- func (tr WriteTracer) ScheduleOutdated(t *gomkore.Trace, a *gomkore.Action, res, pre *gomkore.Goal)
- func (tr WriteTracer) SchedulePreTimeZero(t *gomkore.Trace, a *gomkore.Action, res, pre *gomkore.Goal)
- func (tr WriteTracer) ScheduleResTimeZero(t *gomkore.Trace, a *gomkore.Action, res *gomkore.Goal)
- func (tr WriteTracer) SetupActionEnv(t *gomkore.Trace, env *gomkore.Env) (*gomkore.Env, error)
- func (tr WriteTracer) StartProject(t *gomkore.Trace, p *gomkore.Project, activity string)
- func (tr WriteTracer) Warn(t *gomkore.Trace, msg string, args ...any)
Examples ¶
Constants ¶
const ( UpdAllActions gomkore.UpdateMode = 0 UpdSomeActions gomkore.UpdateMode = 1 UpdAnyAction gomkore.UpdateMode = 2 UpdOneAction gomkore.UpdateMode = 3 UpdUnordered gomkore.UpdateMode = 4 )
const ( TraceImportant TraceLevel = (1 << iota) TraceNormal TraceDetails TraceNothing = 0 TraceLeast = TraceImportant TraceMedium = TraceLeast | TraceNormal TraceMost = TraceMedium | TraceDetails )
const WriteTraceLevelFlagDoc = `Set trace level: l/least; m/medium; M/most`
Variables ¶
This section is empty.
Functions ¶
func Edit ¶ added in v0.11.9
Edit calls do with wrappers of gomkore types that allow easy editing of project definitions. Edit recovers from any panic and returns it as an error, so the idiomatic error handling within do can be skipped.
func Goals ¶ added in v0.11.12
func Goals(gs []*gomkore.Goal, exclusive bool, matchAll ...func(*gomkore.Goal) bool) ([]*gomkore.Goal, error)
Goals is meant to be used when implementing [Operation] to select and check linked goals gs.
func NewBuilder ¶ added in v0.11.14
func NewChanger ¶ added in v0.11.14
Types ¶
type ActionEd ¶ added in v0.11.9
type ActionEd struct {
// contains filtered or unexported fields
}
ActionEd is used with Edit.
func (ActionEd) SetIgnoreError ¶ added in v0.11.9
type CmdOp ¶ added in v0.11.0
type CmdOp struct { CWD string Exe string Args []string InFile, OutFile string Desc string UsesEnv []string }
type ConvertCmd ¶ added in v0.11.6
type ConvertCmd struct { Exe string Args []string // PassOut controls how the output of the convert command is to be passed to // the command: // "1" : The output file name is put after .Args before the input file name. // "2" : The output file name is put after input file name, i.e. as the last argument. // "stdout": Stdout is redirected to the output file. // "-"<opt>: Flags to set output file name, e.g. "-o". PassOut string // If the convert command interprets the output relative to the input // instead of the current working directory. OutRelToIn bool // If the convert command wants the output directiory instead of the output // file name. OutDir bool mkfs.MkDirs }
type Diagrammer ¶ added in v0.11.12
type Diagrammer struct {
RankDir string
}
type GoBuild ¶ added in v0.11.0
type GoBuild struct { GoTool Install bool TrimPath bool LDFlags []string // See https://pkg.go.dev/cmd/link SetVars []string // See https://pkg.go.dev/cmd/link Flag: -X }
GoBuild is an [ActionBuilder] that expects exactly one result [Goal] with either a [File] or [Directory] artefact. The created action will run 'go build' with -C to change into the result's deirectory.
type GoGenerate ¶ added in v0.11.0
type GoGenerate struct { GoTool CWD string FilesPkgs []string // TODO use action prems instead Run string Skip string }
type GoRun ¶ added in v0.11.6
type GoRun struct { GoTool CWD string Exec string Pkg string // TODO use action prems instead (>1) Args []string }
type GoTest ¶ added in v0.11.0
type GoalEd ¶ added in v0.11.9
type GoalEd struct {
// contains filtered or unexported fields
}
GoalEd is used with Edit.
func (GoalEd) IsAbstract ¶ added in v0.11.9
func (GoalEd) SetRemovable ¶ added in v0.11.13
func (GoalEd) SetUpdateMode ¶ added in v0.11.9
func (ed GoalEd) SetUpdateMode(m gomkore.UpdateMode)
func (GoalEd) UpdateMode ¶ added in v0.11.9
func (ed GoalEd) UpdateMode() gomkore.UpdateMode
type PipeOp ¶ added in v0.11.0
type PipeOp []CmdOp
type ProjectEd ¶ added in v0.11.9
type ProjectEd struct {
// contains filtered or unexported fields
}
ProjectEd is used with Edit.
func (ProjectEd) AbstractGoal ¶ added in v0.11.14
type TestTracer ¶ added in v0.11.13
type TestTracer struct {
// contains filtered or unexported fields
}
func (TestTracer) CheckGoal ¶ added in v0.11.13
func (tr TestTracer) CheckGoal(t *gomkore.Trace, g *gomkore.Goal)
func (TestTracer) CloseActionEnv ¶ added in v0.11.14
func (TestTracer) Debug ¶ added in v0.11.13
func (tr TestTracer) Debug(t *gomkore.Trace, msg string, args ...any)
func (TestTracer) DoneProject ¶ added in v0.11.13
func (TestTracer) GoalNeedsActions ¶ added in v0.11.13
func (TestTracer) GoalUpToDate ¶ added in v0.11.13
func (tr TestTracer) GoalUpToDate(t *gomkore.Trace, g *gomkore.Goal)
func (TestTracer) Info ¶ added in v0.11.13
func (tr TestTracer) Info(t *gomkore.Trace, msg string, args ...any)
func (TestTracer) RemoveArtefact ¶ added in v0.11.13
func (tr TestTracer) RemoveArtefact(t *gomkore.Trace, g *gomkore.Goal)
func (TestTracer) RunAction ¶ added in v0.11.13
func (tr TestTracer) RunAction(_ *gomkore.Trace, a *gomkore.Action)
func (TestTracer) RunImplicitAction ¶ added in v0.11.13
func (tr TestTracer) RunImplicitAction(_ *gomkore.Trace, a *gomkore.Action)
func (TestTracer) ScheduleNotPremises ¶ added in v0.11.13
func (TestTracer) ScheduleOutdated ¶ added in v0.11.13
func (TestTracer) SchedulePreTimeZero ¶ added in v0.11.13
func (TestTracer) ScheduleResTimeZero ¶ added in v0.11.13
func (TestTracer) SetupActionEnv ¶ added in v0.11.14
func (TestTracer) StartProject ¶ added in v0.11.13
type TraceLevel ¶ added in v0.11.14
type TraceLevel int
var DefaultTraceLevel TraceLevel = TraceLeast
func (TraceLevel) Traces ¶ added in v0.11.14
func (cfg TraceLevel) Traces(l TraceLevel) bool
type WriteTracer ¶ added in v0.11.13
type WriteTracer struct { W io.Writer Log TraceLevel }
func NewDefaultTracer ¶ added in v0.11.14
func NewDefaultTracer() *WriteTracer
func (WriteTracer) CheckGoal ¶ added in v0.11.13
func (tr WriteTracer) CheckGoal(t *gomkore.Trace, g *gomkore.Goal)
func (WriteTracer) CloseActionEnv ¶ added in v0.11.14
func (WriteTracer) Debug ¶ added in v0.11.13
func (tr WriteTracer) Debug(t *gomkore.Trace, msg string, args ...any)
func (WriteTracer) DoneProject ¶ added in v0.11.13
func (WriteTracer) GoalNeedsActions ¶ added in v0.11.13
func (WriteTracer) GoalUpToDate ¶ added in v0.11.13
func (tr WriteTracer) GoalUpToDate(t *gomkore.Trace, g *gomkore.Goal)
func (WriteTracer) Info ¶ added in v0.11.13
func (tr WriteTracer) Info(t *gomkore.Trace, msg string, args ...any)
func (*WriteTracer) ParseLevelFlag ¶ added in v0.11.14
func (tr *WriteTracer) ParseLevelFlag(f string) error
func (WriteTracer) RemoveArtefact ¶ added in v0.11.13
func (tr WriteTracer) RemoveArtefact(t *gomkore.Trace, g *gomkore.Goal)
func (WriteTracer) RunAction ¶ added in v0.11.13
func (tr WriteTracer) RunAction(t *gomkore.Trace, a *gomkore.Action)
func (WriteTracer) RunImplicitAction ¶ added in v0.11.13
func (tr WriteTracer) RunImplicitAction(t *gomkore.Trace, _ *gomkore.Action)
func (WriteTracer) ScheduleNotPremises ¶ added in v0.11.13
func (WriteTracer) ScheduleOutdated ¶ added in v0.11.13
func (WriteTracer) SchedulePreTimeZero ¶ added in v0.11.13
func (WriteTracer) ScheduleResTimeZero ¶ added in v0.11.13
func (WriteTracer) SetupActionEnv ¶ added in v0.11.14
func (WriteTracer) StartProject ¶ added in v0.11.13
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
This is an example gomk project that offers you a practical approach.
|
This is an example gomk project that offers you a practical approach. |
Package gomkore implements the core model of gomk for the representation of buildable projects.
|
Package gomkore implements the core model of gomk for the representation of buildable projects. |