buildengine

package
v0.215.0 Latest Latest
Warning

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

Go to latest
Published: May 15, 2024 License: Apache-2.0 Imports: 51 Imported by: 0

Documentation

Overview

Package buildengine provides a framework for building FTL modules.

Index

Constants

This section is empty.

Variables

View Source
var ErrSkip = errors.New("skip directory")

ErrSkip can be returned by the WalkDir callback to skip a file or directory.

Functions

func Build

func Build(ctx context.Context, sch *schema.Schema, project Project, filesTransaction ModifyFilesTransaction) error

Build a project in the given directory given the schema and project config. For a module, this will build the module. For an external library, this will build stubs for imported modules.

func ComputeFileHash added in v0.182.2

func ComputeFileHash(baseDir, srcPath string, watch []string) (hash []byte, matched bool, err error)

func Deploy added in v0.139.0

func Deploy(ctx context.Context, module Module, replicas int32, waitForDeployOnline bool, client DeployClient) error

Deploy a module to the FTL controller with the given number of replicas. Optionally wait for the deployment to become ready.

func SetPOMProperties added in v0.133.1

func SetPOMProperties(ctx context.Context, baseDir string) error

SetPOMProperties updates the ftl.version properties in the pom.xml file in the given base directory.

func StringsFromProjectKeys added in v0.155.0

func StringsFromProjectKeys(keys []ProjectKey) []string

func TopologicalSort added in v0.134.1

func TopologicalSort(graph map[string][]string) [][]string

TopologicalSort returns a sequence of groups of modules in topological order that may be built in parallel.

func WalkDir

func WalkDir(dir string, fn func(path string, d fs.DirEntry) error) error

WalkDir performs a depth-first walk of the file tree rooted at dir, calling fn for each file or directory in the tree, including dir.

It will adhere to .gitignore files. The callback "fn" can return ErrSkip to skip recursion.

Types

type BuildStartedListenerFunc added in v0.161.1

type BuildStartedListenerFunc func(project Project)

func (BuildStartedListenerFunc) OnBuildStarted added in v0.161.1

func (b BuildStartedListenerFunc) OnBuildStarted(project Project)

type Engine added in v0.134.1

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

Engine for building a set of modules.

func New added in v0.134.1

func New(ctx context.Context, client ftlv1connect.ControllerServiceClient, moduleDirs []string, externalDirs []string, options ...Option) (*Engine, error)

New constructs a new Engine.

Completely offline builds are possible if the full dependency graph is locally available. If the FTL controller is available, it will be used to pull in missing schemas.

"dirs" are directories to scan for local modules.

func (*Engine) Build added in v0.134.1

func (e *Engine) Build(ctx context.Context) error

Build attempts to build all local modules.

func (*Engine) Close added in v0.134.1

func (e *Engine) Close() error

Close stops the Engine's schema sync.

func (*Engine) Deploy added in v0.139.0

func (e *Engine) Deploy(ctx context.Context, replicas int32, waitForDeployOnline bool) error

Deploy attempts to build and deploy all local modules.

func (*Engine) Dev added in v0.142.0

func (e *Engine) Dev(ctx context.Context, period time.Duration, commands projectconfig.Commands) error

Dev builds and deploys all local modules and watches for changes, redeploying as necessary.

func (*Engine) Graph added in v0.134.1

func (e *Engine) Graph(projects ...ProjectKey) (map[string][]string, error)

Graph returns the dependency graph for the given modules.

If no modules are provided, the entire graph is returned. An error is returned if any dependencies are missing.

func (*Engine) Import added in v0.134.1

func (e *Engine) Import(ctx context.Context, schema *schema.Module)

Import manually imports a schema for a module as if it were retrieved from the FTL controller.

type ExternalLibrary added in v0.155.0

type ExternalLibrary struct {
	Dir          string
	Language     string
	Dependencies []string
}

ExternalLibrary represents a library that makes use of FTL modules, but is not itself an FTL module

func LoadExternalLibrary added in v0.155.0

func LoadExternalLibrary(dir string) (ExternalLibrary, error)

func (ExternalLibrary) Config added in v0.155.0

func (e ExternalLibrary) Config() ProjectConfig

func (ExternalLibrary) CopyWithDependencies added in v0.155.0

func (e ExternalLibrary) CopyWithDependencies(dependencies []string) Project

func (ExternalLibrary) TypeString added in v0.157.0

func (e ExternalLibrary) TypeString() string

type FileChangeType added in v0.131.0

type FileChangeType rune
const (
	FileAdded   FileChangeType = '+'
	FileRemoved FileChangeType = '-'
	FileChanged FileChangeType = '*'
)

func CompareFileHashes

func CompareFileHashes(oldFiles, newFiles FileHashes) (FileChangeType, string, bool)

CompareFileHashes compares the hashes of the files in the oldFiles and newFiles maps.

Returns true if the hashes are equal, false otherwise.

If false, the returned string will be a file that caused the difference and the returned FileChangeType will be the type of change that occurred.

func (FileChangeType) GoString added in v0.131.0

func (f FileChangeType) GoString() string

func (FileChangeType) String added in v0.131.0

func (f FileChangeType) String() string

type FileHashes added in v0.131.0

type FileHashes map[string][]byte

func ComputeFileHashes

func ComputeFileHashes(project Project) (FileHashes, error)

ComputeFileHashes computes the SHA256 hash of all (non-git-ignored) files in the given directory.

type Listener added in v0.160.0

type Listener interface {
	OnBuildStarted(project Project)
}

type ModifyFilesTransaction added in v0.182.2

type ModifyFilesTransaction interface {
	Begin() error
	ModifiedFiles(paths ...string) error
	End() error
}

ModifyFilesTransaction allows builds to modify files in a module without triggering a watch event. This helps us avoid infinite loops with builds changing files, and those changes triggering new builds.as a no-op

type Module added in v0.131.0

type Module struct {
	moduleconfig.ModuleConfig
	Dependencies []string
}

Module represents an FTL module in the build engine

func LoadModule added in v0.133.1

func LoadModule(dir string) (Module, error)

LoadModule loads a module from the given directory.

func (Module) Config added in v0.155.0

func (m Module) Config() ProjectConfig

func (Module) CopyWithDependencies added in v0.155.0

func (m Module) CopyWithDependencies(dependencies []string) Project

func (Module) TypeString added in v0.157.0

func (m Module) TypeString() string

type Option added in v0.147.0

type Option func(o *Engine)

func Parallelism added in v0.147.0

func Parallelism(n int) Option

func WithListener added in v0.160.0

func WithListener(listener Listener) Option

WithListener sets the event listener for the Engine.

type Project added in v0.155.0

type Project interface {
	Config() ProjectConfig
	CopyWithDependencies(deps []string) Project
	TypeString() string
	// contains filtered or unexported methods
}

Project models FTL modules and external libraries and is used to manage dependencies within the build engine

func DiscoverProjects added in v0.155.0

func DiscoverProjects(ctx context.Context, moduleDirs []string, externalLibDirs []string) ([]Project, error)

DiscoverProjects recursively loads all modules under the given directories (or if none provided, the current working directory is used) and external libraries in externalLibDirs.

func UpdateDependencies

func UpdateDependencies(ctx context.Context, project Project) (Project, error)

UpdateDependencies finds the dependencies for a project and returns a Project with those dependencies populated.

type ProjectConfig added in v0.155.0

type ProjectConfig struct {
	Key          ProjectKey
	Dir          string
	Language     string
	Watch        []string
	Dependencies []string
}

type ProjectKey added in v0.155.0

type ProjectKey string

ProjectKey is a unique identifier for the project (ie: a module name or a library path) It is used to: - build the dependency graph - map changes in the file system to the project

func ProjectKeysFromModuleNames added in v0.155.0

func ProjectKeysFromModuleNames(names []string) []ProjectKey

type WatchEvent added in v0.131.0

type WatchEvent interface {
	// contains filtered or unexported methods
}

A WatchEvent is an event that occurs when a project is added, removed, or changed.

type WatchEventProjectAdded added in v0.155.0

type WatchEventProjectAdded struct{ Project Project }

type WatchEventProjectChanged added in v0.155.0

type WatchEventProjectChanged struct {
	Project Project
	Change  FileChangeType
	Path    string
	Time    time.Time
}

type WatchEventProjectRemoved added in v0.155.0

type WatchEventProjectRemoved struct{ Project Project }

type Watcher added in v0.182.2

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

func NewWatcher added in v0.182.2

func NewWatcher() *Watcher

func (*Watcher) GetTransaction added in v0.182.2

func (w *Watcher) GetTransaction(moduleDir string) ModifyFilesTransaction

func (*Watcher) Watch added in v0.182.2

func (w *Watcher) Watch(ctx context.Context, period time.Duration, moduleDirs []string, externalLibDirs []string) (*pubsub.Topic[WatchEvent], error)

Watch the given directories for new projects, deleted projects, and changes to existing projects, publishing a change event for each.

Jump to

Keyboard shortcuts

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