gomk

package module
v0.11.9 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2024 License: AGPL-3.0 Imports: 17 Imported by: 5

README

gomk - Make things Go

Go Reference

  • Just a Go library module, no extra DSL to learn, and your Go IDE will help you right away.

  • As portable as Go is – as long as you don't add any platform specifics.

  • No extra tools implied. Having Go SDK installed, run a build script with go run.

You will find the details in the Go docs. For a more pragmatic approach, you should take a look at the example project.

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

View Source
const (
	UpdAllActions  gomkore.UpdateMode = 0
	UpdSomeActions gomkore.UpdateMode = 1
	UpdAnyAction   gomkore.UpdateMode = 2
	UpdOneAction   gomkore.UpdateMode = 3

	UpdUnordered gomkore.UpdateMode = 4
)
View Source
const (
	DirListFiles = 1
	DirListDirs  = 2
)

Variables

This section is empty.

Functions

func Clean added in v0.11.6

func Clean(prj *Project, dryrun bool, log *slog.Logger) error

func Edit added in v0.11.9

func Edit(prj *Project, do func(ProjectEd)) (err error)

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 FsDirList added in v0.11.9

func FsDirList(d DirList, in *Project) (ls []string, err error)

func FsExists added in v0.11.9

func FsExists(a FsArtefact, in *Project) bool

func FsStat added in v0.11.9

func FsStat(a FsArtefact, in *Project) (fs.FileInfo, error)

Types

type Abstract added in v0.11.0

type Abstract = gomkore.Abstract

type Action added in v0.11.0

type Action = gomkore.Action

type ActionEd added in v0.11.9

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

ActionEd is used with Edit.

func (ActionEd) Project added in v0.11.9

func (ed ActionEd) Project() ProjectEd

func (ActionEd) SetIgnoreError added in v0.11.9

func (ed ActionEd) SetIgnoreError(ignore bool)

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) Goal added in v0.11.0

func (bd *Builder) Goal(gs ...*Goal) error

func (*Builder) GoalsContext added in v0.11.0

func (bd *Builder) GoalsContext(ctx context.Context, gs ...*Goal) error

TODO LogDir

func (*Builder) NamedGoals added in v0.11.0

func (bd *Builder) NamedGoals(prj *Project, names ...string) error

func (*Builder) NamedGoalsContext added in v0.11.0

func (bd *Builder) NamedGoalsContext(ctx context.Context, prj *Project, names ...string) error

func (*Builder) Project added in v0.11.0

func (bd *Builder) Project(prj *Project) error

Project builds all leafs in prj.

func (*Builder) ProjectContext added in v0.11.0

func (bd *Builder) ProjectContext(ctx context.Context, prj *Project) error

ProjectContext builds all leafs in prj.

type CmdOp added in v0.11.0

type CmdOp struct {
	CWD             string
	Exe             string
	Args            []string
	InFile, OutFile string
	Desc            string
}

func (*CmdOp) Describe added in v0.11.0

func (op *CmdOp) Describe(a *Action, _ *Env) string

func (*CmdOp) Do added in v0.11.0

func (op *CmdOp) Do(ctx context.Context, a *Action, env *Env) error

func (*CmdOp) WriteHash added in v0.11.6

func (op *CmdOp) WriteHash(h hash.Hash, a *Action, _ *Env) (bool, error)

TODO include environment values

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
}

func (*ConvertCmd) Describe added in v0.11.9

func (cc *ConvertCmd) Describe(*Action, *Env) string

func (*ConvertCmd) Do added in v0.11.9

func (cc *ConvertCmd) Do(ctx context.Context, a *Action, env *Env) error

func (*ConvertCmd) WriteHash added in v0.11.9

func (cc *ConvertCmd) WriteHash(hash.Hash, *Action, *Env) (bool, error)

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

func (DirContent) Stat added in v0.11.6

func (d DirContent) Stat(in ProjectEd) (fs.FileInfo, error)

func (DirContent) StateAt added in v0.11.6

func (d DirContent) StateAt(in *Project) (t time.Time)

type DirList added in v0.11.6

type DirList struct {
	Dir    string
	Glob   string
	Select DirListSelect
}

func (DirList) Exists added in v0.11.6

func (d DirList) Exists(in ProjectEd) bool

func (DirList) List added in v0.11.6

func (d DirList) List(in ProjectEd) (ls []string, err error)

func (DirList) Name added in v0.11.6

func (d DirList) Name(prj *Project) string

func (DirList) Path added in v0.11.6

func (d DirList) Path() string

func (DirList) Rel added in v0.11.6

func (d DirList) Rel(in ProjectEd) string

func (DirList) Stat added in v0.11.6

func (d DirList) Stat(in ProjectEd) (fs.FileInfo, error)

func (DirList) StateAt added in v0.11.6

func (d DirList) StateAt(in *Project) time.Time

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 Env

type Env = gomkore.Env

func DefaultEnv added in v0.11.0

func DefaultEnv() *Env

type File added in v0.11.0

type File string

func (File) Exists added in v0.11.6

func (f File) Exists(in ProjectEd) bool

func (File) Name added in v0.11.0

func (f File) Name(in *Project) string

func (File) Path added in v0.11.0

func (f File) Path() string

func (File) Rel added in v0.11.6

func (f File) Rel(prj ProjectEd) string

func (File) Stat added in v0.11.0

func (f File) Stat(in ProjectEd) (fs.FileInfo, error)

func (File) StateAt added in v0.11.0

func (f File) StateAt(in *Project) time.Time

func (File) WithExt added in v0.11.9

func (f File) WithExt(ext string) File

type FileExt added in v0.11.9

type FileExt string

func (FileExt) Convert added in v0.11.9

func (x FileExt) Convert(g GoalEd) gomkore.Artefact

type FsArtefact added in v0.11.6

type FsArtefact interface {
	gomkore.Artefact
	Path() string
	Rel(in ProjectEd) string
	Stat(in ProjectEd) (fs.FileInfo, error)
	Exists(in ProjectEd) bool
}

type FsCopy added in v0.11.6

type FsCopy struct {
	MkDirMode fs.FileMode
}

func (FsCopy) Describe added in v0.11.6

func (FsCopy) Describe(*Action, *Env) string

func (FsCopy) Do added in v0.11.6

func (cp FsCopy) Do(_ context.Context, a *Action, env *Env) (err error)

func (FsCopy) WriteHash added in v0.11.6

func (cp FsCopy) WriteHash(h hash.Hash, a *Action, _ *Env) (bool, error)

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.

func (*GoBuild) Describe added in v0.11.9

func (gb *GoBuild) Describe(a *Action, _ *Env) string

func (*GoBuild) Do added in v0.11.9

func (gb *GoBuild) Do(ctx context.Context, a *Action, env *Env) error

func (*GoBuild) WriteHash added in v0.11.9

func (*GoBuild) WriteHash(hash.Hash, *Action, *Env) (bool, error)

type GoGenerate added in v0.11.0

type GoGenerate struct {
	GoTool
	CWD       string
	FilesPkgs []string
	Run       string
	Skip      string
}

func (*GoGenerate) Describe added in v0.11.9

func (gg *GoGenerate) Describe(a *Action, _ *Env) string

func (*GoGenerate) Do added in v0.11.9

func (gg *GoGenerate) Do(ctx context.Context, a *Action, env *Env) error

func (*GoGenerate) WriteHash added in v0.11.9

func (*GoGenerate) WriteHash(hash.Hash, *Action, *Env) (bool, error)

type GoRun added in v0.11.6

type GoRun struct {
	GoTool
	CWD  string
	Exec string
	Pkg  string
	Args []string
}

func (*GoRun) Describe added in v0.11.9

func (gr *GoRun) Describe(a *Action, _ *Env) string

func (*GoRun) Do added in v0.11.9

func (gr *GoRun) Do(ctx context.Context, a *Action, env *Env) error

func (*GoRun) WriteHash added in v0.11.9

func (*GoRun) WriteHash(hash.Hash, *Action, *Env) (bool, error)

type GoTest added in v0.11.0

type GoTest struct {
	GoTool
	CWD  string
	Pkgs []string
}

func (*GoTest) Describe added in v0.11.9

func (gt *GoTest) Describe(a *Action, _ *Env) string

func (*GoTest) Do added in v0.11.9

func (gt *GoTest) Do(ctx context.Context, a *Action, env *Env) error

func (*GoTest) WriteHash added in v0.11.9

func (*GoTest) WriteHash(hash.Hash, *Action, *Env) (bool, error)

type GoTool added in v0.11.0

type GoTool struct {
	GoExe string
}

type Goal added in v0.11.0

type Goal = gomkore.Goal

type GoalEd added in v0.11.9

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

GoalEd is used with Edit.

func Convert added in v0.11.9

func Convert(prems []GoalEd, result func(GoalEd) gomkore.Artefact, op gomkore.Operation) (gls []GoalEd)

func FsGoals added in v0.11.9

func FsGoals(prj ProjectEd, dir, dirTmpl Directory) (goals []GoalEd, err error)

func (GoalEd) Artefact added in v0.11.9

func (ed GoalEd) Artefact() gomkore.Artefact

func (GoalEd) By added in v0.11.9

func (result GoalEd) By(op gomkore.Operation, premises ...GoalEd) GoalEd

func (GoalEd) ImpliedBy added in v0.11.9

func (ed GoalEd) ImpliedBy(premises ...GoalEd) GoalEd

func (GoalEd) IsAbstract added in v0.11.9

func (ed GoalEd) IsAbstract() bool

func (GoalEd) Project added in v0.11.9

func (ed GoalEd) Project() ProjectEd

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

func (PipeOp) Describe added in v0.11.6

func (po PipeOp) Describe(a *Action, env *Env) string

func (PipeOp) Do added in v0.11.0

func (po PipeOp) Do(ctx context.Context, a *Action, env *Env) error

func (PipeOp) WriteHash added in v0.11.6

func (po PipeOp) WriteHash(h hash.Hash, a *Action, env *Env) (bool, error)

type Project added in v0.7.0

type Project = gomkore.Project

func NewProject added in v0.7.0

func NewProject(dir string) *Project

type ProjectEd added in v0.11.9

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

ProjectEd is used with Edit.

func (ProjectEd) Dir added in v0.11.9

func (ed ProjectEd) Dir() string

func (ProjectEd) Goal added in v0.11.9

func (ed ProjectEd) Goal(atf gomkore.Artefact) GoalEd

func (ProjectEd) NewAction added in v0.11.9

func (ed ProjectEd) NewAction(premises, results []GoalEd, op gomkore.Operation) ActionEd

func (ProjectEd) RelPath added in v0.11.9

func (ed ProjectEd) RelPath(p string) string

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.

Jump to

Keyboard shortcuts

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