Skip to content

Commit

Permalink
add docs
Browse files Browse the repository at this point in the history
  • Loading branch information
matt2e committed Oct 7, 2024
1 parent 67f705b commit 1de7d64
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 10 deletions.
2 changes: 1 addition & 1 deletion internal/buildengine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ func (e *Engine) watchForModuleChanges(ctx context.Context, period time.Duration
continue
}

updatedConfig, err := moduleconfig.LoadModuleConfig(event.Config.Dir)
updatedConfig, err := moduleconfig.LoadConfig(event.Config.Dir)
if err != nil {
logger.Errorf(err, "Could not load updated toml for %s", event.Config.Module)
continue
Expand Down
2 changes: 1 addition & 1 deletion internal/buildengine/languageplugin/go_plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func TestExtractModuleDepsGo(t *testing.T) {
ctx := context.Background()
dir, err := filepath.Abs("../testdata/alpha")
assert.NoError(t, err)
uncheckedConfig, err := moduleconfig.LoadModuleConfig(dir)
uncheckedConfig, err := moduleconfig.LoadConfig(dir)
assert.NoError(t, err)

plugin, err := New(ctx, uncheckedConfig.Language)
Expand Down
10 changes: 8 additions & 2 deletions internal/buildengine/languageplugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,17 @@ func (e AutoRebuildEndedEvent) ModuleName() string { return e.Module }

// LanguagePlugin handles building and scaffolding modules in a specific language.
type LanguagePlugin interface {
// Topic for all update events from the plugin
// Updates topic for all update events from the plugin
// The same topic must be returned each time this method is called
Updates() *pubsub.Topic[PluginEvent]

// TODO: docs
// GetModuleConfigDefaults provides custom defaults for the module config.
//
// The result may be cached by FTL, so defaulting logic should not be changing due to normal module changes.
// For example it is valid to return defaults based on which build tool is configured within the module directory,
// as that is not expected to change during normal operation.
// It is not recommended to read the module's toml file to determine defaults, as when the toml file is updated,
// the defaults will not be recalculated.
ModuleConfigDefaults(ctx context.Context, dir string) (moduleconfig.CustomDefaults, error)

// GetCreateModuleFlags returns the flags that can be used to create a module for this language.
Expand Down
11 changes: 7 additions & 4 deletions internal/moduleconfig/moduleconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,10 @@ func (c *ModuleConfig) UnmarshalTOML(data []byte) error {
// This is a type alias to prevent accidental use of the wrong type.
type AbsModuleConfig ModuleConfig

// UnvalidatedModuleConfig is a ModuleConfig that has been loaded from disk
// but has not had it's defaults set or been validated.
// UnvalidatedModuleConfig is a ModuleConfig that holds only the values read from the toml file.
//
// It has not had it's defaults set or been validated, so values may be empty or invalid.
// Use FillDefaultsAndValidate() to get a ModuleConfig.
type UnvalidatedModuleConfig ModuleConfig

type CustomDefaults struct {
Expand All @@ -64,8 +66,9 @@ type CustomDefaults struct {
LanguageConfig map[string]any `toml:"-"`
}

// LoadModuleConfig from a directory.
func LoadModuleConfig(dir string) (UnvalidatedModuleConfig, error) {
// LoadConfig from a directory.
// This returns only the values found in the toml file. To get the full config with defaults and validation, use FillDefaultsAndValidate.
func LoadConfig(dir string) (UnvalidatedModuleConfig, error) {
path := filepath.Join(dir, "ftl.toml")

// Parse toml into generic map so that we can capture language config with a dynamic key
Expand Down
2 changes: 1 addition & 1 deletion internal/watch/discover.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func discoverModules(dirs ...string) ([]moduleconfig.UnvalidatedModuleConfig, er
return nil
}
moduleDir := filepath.Dir(path)
config, err := moduleconfig.LoadModuleConfig(moduleDir)
config, err := moduleconfig.LoadConfig(moduleDir)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion internal/watch/watch_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func TestWatchWithBuildAndUserModifyingFiles(t *testing.T) {

func loadModule(t *testing.T, dir, name string) moduleconfig.UnvalidatedModuleConfig {
t.Helper()
config, err := moduleconfig.LoadModuleConfig(filepath.Join(dir, name))
config, err := moduleconfig.LoadConfig(filepath.Join(dir, name))
assert.NoError(t, err)
return config
}
Expand Down

0 comments on commit 1de7d64

Please sign in to comment.