Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
matt2e committed Oct 1, 2024
1 parent 9a16275 commit 127579e
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 54 deletions.
6 changes: 3 additions & 3 deletions internal/buildengine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -501,13 +501,13 @@ func (e *Engine) watchForModuleChanges(ctx context.Context, period time.Duration
// ftl.toml file has changed
meta, ok := e.moduleMetas.Load(event.Config.Module)
if !ok {
logger.Warnf("module %q not found", event.Config.Module)
logger.Warnf("Module %q not found", event.Config.Module)
continue
}

updatedConfig, err := moduleconfig.LoadModuleConfig(event.Config.Dir)
if err != nil {
logger.Errorf(err, "could not load updated toml for %s", event.Config.Module)
logger.Errorf(err, "Could not load updated toml for %s", event.Config.Module)
continue
}
meta.module.Config = updatedConfig
Expand All @@ -518,7 +518,7 @@ func (e *Engine) watchForModuleChanges(ctx context.Context, period time.Duration
didError = true
e.reportBuildFailed(err)
terminal.UpdateModuleState(ctx, event.Config.Module, terminal.BuildStateFailed)
logger.Errorf(err, "build and deploy failed for module %q", event.Config.Module)
logger.Errorf(err, "Build and deploy failed for module %q", event.Config.Module)
} else {
didUpdateDeployments = true
}
Expand Down
6 changes: 2 additions & 4 deletions internal/buildengine/filehash.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import (
"path/filepath"

"github.com/bmatcuk/doublestar/v4"

"github.com/TBD54566975/ftl/internal/moduleconfig"
)

type FileChangeType rune
Expand Down Expand Up @@ -66,10 +64,10 @@ func CompareFileHashes(oldFiles, newFiles FileHashes) (FileChangeType, string, b

// ComputeFileHashes computes the SHA256 hash of all (non-git-ignored) files in
// the given directory.
func computeFileHashes(config moduleconfig.ModuleConfig, patterns []string) (FileHashes, error) {
func computeFileHashes(dir string, patterns []string) (FileHashes, error) {
// Watch paths are allowed to be outside the deploy directory.
fileHashes := make(FileHashes)
rootDirs := computeRootDirs(config.Dir, patterns)
rootDirs := computeRootDirs(dir, patterns)

for _, rootDir := range rootDirs {
err := WalkDir(rootDir, func(srcPath string, entry fs.DirEntry) error {
Expand Down
15 changes: 12 additions & 3 deletions internal/buildengine/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ type buildCommand struct {

func (buildCommand) pluginCmd() {}

type dependenciesFunc = func() ([]string, error)
type dependenciesFunc func() ([]string, error)
type getDependenciesCommand struct {
dependenciesFunc dependenciesFunc

Expand Down Expand Up @@ -161,11 +161,20 @@ func newInternalPlugin(ctx context.Context, config moduleconfig.ModuleConfig, bu
return plugin
}

func (p *internalPlugin) build(ctx context.Context, projectRoot string, config moduleconfig.ModuleConfig, schema *schema.Schema, buildEnv []string, devMode bool) (BuildResult, error) {
func (p *internalPlugin) Updates() *pubsub.Topic[PluginEvent] {
return p.updates
}

func (p *internalPlugin) Kill(ctx context.Context) error {
p.cancel()
return nil
}

func (p *internalPlugin) Build(ctx context.Context, projectRoot string, config moduleconfig.ModuleConfig, sch *schema.Schema, buildEnv []string, devMode bool) (BuildResult, error) {
cmd := buildCommand{
projectRoot: projectRoot,
config: config,
schema: schema,
schema: sch,
buildEnv: buildEnv,
devMode: devMode,
result: make(chan either.Either[BuildResult, error]),
Expand Down
14 changes: 0 additions & 14 deletions internal/buildengine/plugin_go.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"strings"

"github.com/TBD54566975/scaffolder"
"github.com/alecthomas/types/pubsub"
"golang.org/x/exp/maps"

"github.com/TBD54566975/ftl/backend/schema"
Expand All @@ -38,15 +37,6 @@ func newGoPlugin(ctx context.Context, config moduleconfig.ModuleConfig) *goPlugi
}
}

func (p *goPlugin) Updates() *pubsub.Topic[PluginEvent] {
return p.internalPlugin.updates
}

func (p *goPlugin) Kill(ctx context.Context) error {
p.cancel()
return nil
}

type scaffoldingContext struct {
Name string
GoVersion string
Expand Down Expand Up @@ -126,10 +116,6 @@ func (p *goPlugin) GetDependencies(ctx context.Context) ([]string, error) {
})
}

func (p *goPlugin) Build(ctx context.Context, projectRoot string, config moduleconfig.ModuleConfig, sch *schema.Schema, buildEnv []string, devMode bool) (BuildResult, error) {
return p.internalPlugin.build(ctx, projectRoot, config, sch, buildEnv, devMode)
}

func buildGo(ctx context.Context, projectRoot string, config moduleconfig.AbsModuleConfig, sch *schema.Schema, buildEnv []string, devMode bool, transaction ModifyFilesTransaction) error {
if err := compile.Build(ctx, projectRoot, config.Dir, sch, transaction, buildEnv, devMode); err != nil {
return CompilerBuildError{err: fmt.Errorf("failed to build module %q: %w", config.Module, err)}
Expand Down
14 changes: 0 additions & 14 deletions internal/buildengine/plugin_java.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"strings"

"github.com/TBD54566975/scaffolder"
"github.com/alecthomas/types/pubsub"
"github.com/beevik/etree"
"golang.org/x/exp/maps"

Expand All @@ -40,15 +39,6 @@ func newJavaPlugin(ctx context.Context, config moduleconfig.ModuleConfig) *javaP
}
}

func (p *javaPlugin) Updates() *pubsub.Topic[PluginEvent] {
return p.internalPlugin.updates
}

func (p *javaPlugin) Kill(ctx context.Context) error {
p.cancel()
return nil
}

func (p *javaPlugin) CreateModule(ctx context.Context, config moduleconfig.ModuleConfig, includeBinDir bool, replacements map[string]string, group string) error {
logger := log.FromContext(ctx)

Expand Down Expand Up @@ -179,10 +169,6 @@ func extractKotlinFTLImports(self, dir string) ([]string, error) {
return modules, nil
}

func (p *javaPlugin) Build(ctx context.Context, projectRoot string, config moduleconfig.ModuleConfig, sch *schema.Schema, buildEnv []string, devMode bool) (BuildResult, error) {
return p.internalPlugin.build(ctx, projectRoot, config, sch, buildEnv, devMode)
}

func buildJava(ctx context.Context, projectRoot string, config moduleconfig.AbsModuleConfig, sch *schema.Schema, buildEnv []string, devMode bool, transaction ModifyFilesTransaction) error {
logger := log.FromContext(ctx)
if config.Java.BuildTool == moduleconfig.JavaBuildToolMaven {
Expand Down
15 changes: 0 additions & 15 deletions internal/buildengine/plugin_rust.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import (
"context"
"fmt"

"github.com/alecthomas/types/pubsub"

"github.com/TBD54566975/ftl/backend/schema"
"github.com/TBD54566975/ftl/internal/exec"
"github.com/TBD54566975/ftl/internal/log"
Expand All @@ -25,15 +23,6 @@ func newRustPlugin(ctx context.Context, config moduleconfig.ModuleConfig) *rustP
}
}

func (p *rustPlugin) Updates() *pubsub.Topic[PluginEvent] {
return p.internalPlugin.updates
}

func (p *rustPlugin) Kill(ctx context.Context) error {
p.cancel()
return nil
}

func (p *rustPlugin) CreateModule(ctx context.Context, config moduleconfig.ModuleConfig, includeBinDir bool, replacements map[string]string, group string) error {
return fmt.Errorf("not implemented")
}
Expand All @@ -42,10 +31,6 @@ func (p *rustPlugin) GetDependencies(ctx context.Context) ([]string, error) {
return nil, fmt.Errorf("not implemented")
}

func (p *rustPlugin) Build(ctx context.Context, projectRoot string, config moduleconfig.ModuleConfig, sch *schema.Schema, buildEnv []string, devMode bool) (BuildResult, error) {
return p.internalPlugin.build(ctx, projectRoot, config, sch, buildEnv, devMode)
}

func buildRust(ctx context.Context, projectRoot string, config moduleconfig.AbsModuleConfig, sch *schema.Schema, buildEnv []string, devMode bool, transaction ModifyFilesTransaction) error {
logger := log.FromContext(ctx)
logger.Debugf("Using build command '%s'", config.Build)
Expand Down
2 changes: 1 addition & 1 deletion internal/buildengine/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func (w *Watcher) Watch(ctx context.Context, period time.Duration, moduleDirs []
continue
}
existingModule, haveExistingModule := w.existingModules[config.Dir]
hashes, err := computeFileHashes(config, w.patterns)
hashes, err := computeFileHashes(config.Dir, w.patterns)
if err != nil {
logger.Tracef("error computing file hashes for %s: %v", config.Dir, err)
continue
Expand Down

0 comments on commit 127579e

Please sign in to comment.