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]
Index ¶
- Constants
- func Clean(prj *Project, dryrun bool, log *slog.Logger) error
- func Edit(prj *Project, do func(ProjectEd)) (err error)
- func FsDirContent(d DirContent, in *Project) (ls []string, err error)
- func FsDirList(d DirList, in *Project) (ls []string, err error)
- func FsExists(a FsArtefact, in *Project) bool
- func FsStat(a FsArtefact, in *Project) (fs.FileInfo, error)
- type Abstract
- type Action
- type ActionEd
- type Builder
- func (bd *Builder) Goal(gs ...*Goal) error
- func (bd *Builder) GoalsContext(ctx context.Context, gs ...*Goal) error
- func (bd *Builder) NamedGoals(prj *Project, names ...string) error
- func (bd *Builder) NamedGoalsContext(ctx context.Context, prj *Project, names ...string) error
- func (bd *Builder) Project(prj *Project) error
- func (bd *Builder) ProjectContext(ctx context.Context, prj *Project) error
- type CmdOp
- type ConvertCmd
- type DirContent
- func (d DirContent) Exists(in ProjectEd) bool
- func (d DirContent) List(in ProjectEd) (ls []string, err error)
- func (d DirContent) Name(in *Project) string
- func (d DirContent) Path() string
- func (d DirContent) Rel(prj ProjectEd) string
- func (d DirContent) Stat(in ProjectEd) (fs.FileInfo, error)
- func (d DirContent) StateAt(in *Project) (t time.Time)
- type DirList
- func (d DirList) Exists(in ProjectEd) bool
- func (d DirList) List(in ProjectEd) (ls []string, err error)
- func (d DirList) Name(prj *Project) string
- func (d DirList) Path() string
- func (d DirList) Rel(in ProjectEd) string
- func (d DirList) Stat(in ProjectEd) (fs.FileInfo, error)
- func (d DirList) StateAt(in *Project) time.Time
- type DirListSelect
- type Directory
- type Env
- type File
- type FileExt
- type FsArtefact
- type FsCopy
- type GoBuild
- type GoGenerate
- type GoRun
- type GoTest
- type GoTool
- type Goal
- type GoalEd
- func (ed GoalEd) Artefact() gomkore.Artefact
- func (result GoalEd) By(op gomkore.Operation, premises ...GoalEd) GoalEd
- func (ed GoalEd) ImpliedBy(premises ...GoalEd) GoalEd
- func (ed GoalEd) IsAbstract() bool
- func (ed GoalEd) Project() ProjectEd
- func (ed GoalEd) SetUpdateMode(m gomkore.UpdateMode)
- func (ed GoalEd) UpdateMode() gomkore.UpdateMode
- type PipeOp
- type Project
- type ProjectEd
Constants ¶
const ( UpdAllActions gomkore.UpdateMode = 0 UpdSomeActions gomkore.UpdateMode = 1 UpdAnyAction gomkore.UpdateMode = 2 UpdOneAction gomkore.UpdateMode = 3 UpdUnordered gomkore.UpdateMode = 4 )
const ( DirListFiles = 1 DirListDirs = 2 )
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 FsDirContent ¶ added in v0.11.9
func FsDirContent(d DirContent, in *Project) (ls []string, err error)
func FsExists ¶ added in v0.11.9
func FsExists(a FsArtefact, in *Project) bool
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 Builder ¶ added in v0.11.0
type Builder struct { Env *Env LogDir string MkDirMode fs.FileMode // contains filtered or unexported fields }
TODO Add a "dry-run" option
func (*Builder) GoalsContext ¶ added in v0.11.0
TODO LogDir
func (*Builder) NamedGoals ¶ added in v0.11.0
func (*Builder) NamedGoalsContext ¶ added in v0.11.0
type ConvertCmd ¶ added in v0.11.6
type ConvertCmd struct { Exe string // Output controls how the output of the convert command is to be written to // the result file. // "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". Output string Args []string }
type DirContent ¶ added in v0.11.6
type DirContent struct { Dir string Glob string Select DirListSelect }
func (DirContent) Exists ¶ added in v0.11.6
func (d DirContent) Exists(in ProjectEd) bool
func (DirContent) List ¶ added in v0.11.6
func (d DirContent) List(in ProjectEd) (ls []string, err error)
func (DirContent) Name ¶ added in v0.11.6
func (d DirContent) Name(in *Project) string
func (DirContent) Path ¶ added in v0.11.6
func (d DirContent) Path() string
func (DirContent) Rel ¶ added in v0.11.6
func (d DirContent) Rel(prj ProjectEd) string
type DirList ¶ added in v0.11.6
type DirList struct { Dir string Glob string Select DirListSelect }
type DirListSelect ¶ added in v0.11.9
type DirListSelect int
type Directory ¶ added in v0.11.0
type Directory interface { FsArtefact List(in ProjectEd) ([]string, error) }
type FsArtefact ¶ added in v0.11.6
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
func (*GoGenerate) Describe ¶ added in v0.11.9
func (gg *GoGenerate) Describe(a *Action, _ *Env) string
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) 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 Project ¶ added in v0.7.0
func NewProject ¶ added in v0.7.0
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. |