2023-03-15 17:56:38 +00:00
|
|
|
package modules
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2023-04-14 18:08:59 +00:00
|
|
|
"io"
|
2023-08-23 18:14:02 +00:00
|
|
|
"log/slog"
|
2023-03-15 17:56:38 +00:00
|
|
|
|
2023-05-02 16:44:47 +00:00
|
|
|
"code.icb4dc0.de/buildr/buildr/modules/state"
|
|
|
|
|
2023-04-18 16:06:13 +00:00
|
|
|
"github.com/hashicorp/hcl/v2"
|
2023-03-15 17:56:38 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type ExecutionContext interface {
|
|
|
|
context.Context
|
2023-05-24 20:10:01 +00:00
|
|
|
Name() string
|
2023-04-14 18:08:59 +00:00
|
|
|
WorkingDir() string
|
|
|
|
OutDir() string
|
2023-04-24 08:37:08 +00:00
|
|
|
BinariesDir() string
|
2023-04-14 18:08:59 +00:00
|
|
|
StdOut() io.Writer
|
|
|
|
StdErr() io.Writer
|
2023-03-15 17:56:38 +00:00
|
|
|
Logger() *slog.Logger
|
2023-05-02 16:44:47 +00:00
|
|
|
GetState(ctx context.Context, key string) ([]byte, state.Metadata, error)
|
|
|
|
SetState(ctx context.Context, key string, value []byte) error
|
|
|
|
}
|
|
|
|
|
|
|
|
type StateEncoder[T any] interface {
|
|
|
|
Get(ctx context.Context, key string) (val T, ok bool, meta state.Metadata, err error)
|
|
|
|
Set(ctx context.Context, key string, val T) error
|
2023-03-15 17:56:38 +00:00
|
|
|
}
|
|
|
|
|
2023-04-18 16:06:13 +00:00
|
|
|
type ModuleWithMeta interface {
|
|
|
|
Module
|
|
|
|
Unwrap() Module
|
2023-05-24 20:10:01 +00:00
|
|
|
SetModule(m Module)
|
2023-03-15 17:56:38 +00:00
|
|
|
ID() string
|
2023-04-18 16:06:13 +00:00
|
|
|
Name() string
|
2023-05-27 15:42:23 +00:00
|
|
|
SetName(name string)
|
2023-04-30 08:59:26 +00:00
|
|
|
ShouldSkip() bool
|
2023-03-15 17:56:38 +00:00
|
|
|
Dependencies() []string
|
|
|
|
InputMappings() map[string]string
|
2023-04-18 16:06:13 +00:00
|
|
|
OutDir() string
|
|
|
|
ContainerSpec() *ContainerSpec
|
|
|
|
UnmarshalHCL(body hcl.Body, ctx *hcl.EvalContext) hcl.Diagnostics
|
2023-03-15 17:56:38 +00:00
|
|
|
}
|
|
|
|
|
2023-05-24 20:10:01 +00:00
|
|
|
type Initializer interface {
|
|
|
|
Init(hclCtx *hcl.EvalContext) (Module, error)
|
|
|
|
}
|
|
|
|
|
2023-06-19 18:19:56 +00:00
|
|
|
type Helper interface {
|
2023-08-23 18:14:02 +00:00
|
|
|
Help(ctx context.Context) (help Help, err error)
|
2023-06-19 18:19:56 +00:00
|
|
|
}
|
|
|
|
|
2023-04-18 16:06:13 +00:00
|
|
|
type Module interface {
|
|
|
|
Execute(ctx ExecutionContext) error
|
2023-05-01 08:15:53 +00:00
|
|
|
Category() Category
|
2023-04-18 16:06:13 +00:00
|
|
|
Type() string
|
2023-03-15 17:56:38 +00:00
|
|
|
}
|
|
|
|
|
2023-04-24 08:37:08 +00:00
|
|
|
type BinaryNamer interface {
|
2023-09-12 16:43:34 +00:00
|
|
|
BinaryName(ctx context.Context) (binaryName string, err error)
|
2023-04-24 08:37:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type ToolModule interface {
|
|
|
|
Module
|
|
|
|
BinaryNamer
|
|
|
|
}
|
|
|
|
|
|
|
|
type Factory interface {
|
2023-04-18 16:06:13 +00:00
|
|
|
Create() ModuleWithMeta
|
2023-04-11 20:30:48 +00:00
|
|
|
}
|
|
|
|
|
2023-04-24 08:37:08 +00:00
|
|
|
var _ Factory = (*ModuleFactoryFunc)(nil)
|
2023-04-11 20:30:48 +00:00
|
|
|
|
2023-04-18 16:06:13 +00:00
|
|
|
type ModuleFactoryFunc func() ModuleWithMeta
|
2023-04-11 20:30:48 +00:00
|
|
|
|
2023-04-18 16:06:13 +00:00
|
|
|
func (f ModuleFactoryFunc) Create() ModuleWithMeta {
|
2023-04-11 20:30:48 +00:00
|
|
|
return f()
|
2023-03-15 17:56:38 +00:00
|
|
|
}
|