Skip to content

Commit

Permalink
no longer need bind allocator everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
matt2e committed Nov 8, 2024
1 parent 8ea679c commit d01410a
Show file tree
Hide file tree
Showing 9 changed files with 7 additions and 107 deletions.
46 changes: 0 additions & 46 deletions frontend/cli/bind.go

This file was deleted.

26 changes: 0 additions & 26 deletions frontend/cli/bind_test.go

This file was deleted.

9 changes: 1 addition & 8 deletions frontend/cli/cmd_box.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,7 @@ func (b *boxCmd) Run(ctx context.Context, client ftlv1connect.ControllerServiceC
if len(b.Build.Dirs) == 0 {
return errors.New("no directories specified")
}

// use the cli endpoint to create the bind allocator, but leave the first port unused as it is meant to be reserved by a controller
bindAllocator, err := bindAllocatorWithoutController()
if err != nil {
return err
}

engine, err := buildengine.New(ctx, client, projConfig, b.Build.Dirs, bindAllocator, buildengine.BuildEnv(b.Build.BuildEnv), buildengine.Parallelism(b.Build.Parallelism))
engine, err := buildengine.New(ctx, client, projConfig, b.Build.Dirs, buildengine.BuildEnv(b.Build.BuildEnv), buildengine.Parallelism(b.Build.Parallelism))
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion frontend/cli/cmd_box_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (b *boxRunCmd) Run(
return fmt.Errorf("controller failed to start: %w", err)
}

engine, err := buildengine.New(ctx, client, projConfig, []string{b.Dir}, bindAllocator)
engine, err := buildengine.New(ctx, client, projConfig, []string{b.Dir})
if err != nil {
return fmt.Errorf("failed to create build engine: %w", err)
}
Expand Down
7 changes: 1 addition & 6 deletions frontend/cli/cmd_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,11 @@ func (b *buildCmd) Run(ctx context.Context, client ftlv1connect.ControllerServic
if len(b.Dirs) == 0 {
return errors.New("no directories specified")
}
// use the cli endpoint to create the bind allocator, but leave the first port unused as it is meant to be reserved by a controller
bindAllocator, err := bindAllocatorWithoutController()
if err != nil {
return err
}

// Cancel build engine context to ensure all language plugins are killed.
ctx, cancel := context.WithCancel(ctx)
defer cancel()
engine, err := buildengine.New(ctx, client, projConfig, b.Dirs, bindAllocator, buildengine.BuildEnv(b.BuildEnv), buildengine.Parallelism(b.Parallelism))
engine, err := buildengine.New(ctx, client, projConfig, b.Dirs, buildengine.BuildEnv(b.BuildEnv), buildengine.Parallelism(b.Parallelism))
if err != nil {
return err
}
Expand Down
7 changes: 1 addition & 6 deletions frontend/cli/cmd_deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,10 @@ func (d *deployCmd) Run(ctx context.Context, projConfig projectconfig.Config) er
client = rpc.ClientFromContext[ftlv1connect.ControllerServiceClient](ctx)
}

bindAllocator, err := bindAllocatorWithoutController()
if err != nil {
return err
}

// Cancel build engine context to ensure all language plugins are killed.
ctx, cancel := context.WithCancel(ctx)
defer cancel()
engine, err := buildengine.New(ctx, client, projConfig, d.Build.Dirs, bindAllocator, buildengine.BuildEnv(d.Build.BuildEnv), buildengine.Parallelism(d.Build.Parallelism))
engine, err := buildengine.New(ctx, client, projConfig, d.Build.Dirs, buildengine.BuildEnv(d.Build.BuildEnv), buildengine.Parallelism(d.Build.Parallelism))
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion frontend/cli/cmd_dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func (d *devCmd) Run(
})
}

engine, err := buildengine.New(ctx, client, projConfig, d.Build.Dirs, bindAllocator, opts...)
engine, err := buildengine.New(ctx, client, projConfig, d.Build.Dirs, opts...)
if err != nil {
return err
}
Expand Down
5 changes: 1 addition & 4 deletions internal/buildengine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"golang.org/x/sync/errgroup"

ftlv1 "github.com/TBD54566975/ftl/backend/protos/xyz/block/ftl/v1"
"github.com/TBD54566975/ftl/internal/bind"
"github.com/TBD54566975/ftl/internal/buildengine/languageplugin"
"github.com/TBD54566975/ftl/internal/log"
"github.com/TBD54566975/ftl/internal/moduleconfig"
Expand Down Expand Up @@ -176,7 +175,6 @@ type rebuildRequest struct {
// Engine for building a set of modules.
type Engine struct {
client DeployClient
bindAllocator *bind.BindAllocator
moduleMetas *xsync.MapOf[string, moduleMeta]
projectConfig projectconfig.Config
moduleDirs []string
Expand Down Expand Up @@ -238,7 +236,7 @@ func WithStartTime(startTime time.Time) Option {
// pull in missing schemas.
//
// "dirs" are directories to scan for local modules.
func New(ctx context.Context, client DeployClient, projectConfig projectconfig.Config, moduleDirs []string, bindAllocator *bind.BindAllocator, options ...Option) (*Engine, error) {
func New(ctx context.Context, client DeployClient, projectConfig projectconfig.Config, moduleDirs []string, options ...Option) (*Engine, error) {
ctx = rpc.ContextWithClient(ctx, client)
e := &Engine{
client: client,
Expand All @@ -254,7 +252,6 @@ func New(ctx context.Context, client DeployClient, projectConfig projectconfig.C
rebuildRequests: make(chan rebuildRequest, 128),
rawEngineUpdates: make(chan rawEngineEvent, 128),
EngineUpdates: pubsub.New[EngineEvent](),
bindAllocator: bindAllocator,
}
for _, option := range options {
option(e)
Expand Down
10 changes: 1 addition & 9 deletions internal/buildengine/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@ package buildengine_test

import (
"context"
"net/url"
"path/filepath"
"testing"

"github.com/alecthomas/assert/v2"

"github.com/TBD54566975/ftl/internal/bind"
"github.com/TBD54566975/ftl/internal/buildengine"
"github.com/TBD54566975/ftl/internal/log"
"github.com/TBD54566975/ftl/internal/projectconfig"
Expand All @@ -18,17 +16,11 @@ import (
func TestGraph(t *testing.T) {
ctx, cancel := context.WithCancel(log.ContextWithNewDefaultLogger(context.Background()))
t.Cleanup(cancel)

bindURL, err := url.Parse("http://127.0.0.1:8893")
assert.NoError(t, err)
bindAllocator, err := bind.NewBindAllocator(bindURL, 0)
assert.NoError(t, err)

projConfig := projectconfig.Config{
Path: filepath.Join(t.TempDir(), "ftl-project.toml"),
Name: "test",
}
engine, err := buildengine.New(ctx, nil, projConfig, []string{"testdata/alpha", "testdata/other", "testdata/another"}, bindAllocator)
engine, err := buildengine.New(ctx, nil, projConfig, []string{"testdata/alpha", "testdata/other", "testdata/another"})
assert.NoError(t, err)

Check failure on line 24 in internal/buildengine/engine_test.go

View workflow job for this annotation

GitHub Actions / Test Go

=== RUN TestGraph debug: Deleting all generated stubs info:: Received Ping debug: Ping succeeded in 0.10s debug:alpha: Online debug: Extracting dependencies for "alpha" debug: Unary RPC failed: unknown: could not extract dependencies: alpha: failed to extract dependencies from Go module: stat testdata/alpha: no such file or directory: /xyz.block.ftl.v1.language.LanguageService/GetDependencies info:: Received Ping info:: Received Ping debug: Ping succeeded in 0.10s debug: Ping succeeded in 0.10s debug:another: Online debug:other: Online debug: Extracting dependencies for "another" debug: Extracting dependencies for "other" debug: Unary RPC failed: unknown: could not extract dependencies: another: failed to extract dependencies from Go module: stat testdata/another: no such file or directory: /xyz.block.ftl.v1.language.LanguageService/GetDependencies debug: Unary RPC failed: unknown: could not extract dependencies: other: failed to extract dependencies from Go module: stat testdata/other: no such file or directory: /xyz.block.ftl.v1.language.LanguageService/GetDependencies internal/buildengine/engine_test.go:24: Did not expect an error but got: could not get dependencies for alpha: failed to get dependencies from plugin: unknown: could not extract dependencies: alpha: failed to extract dependencies from Go module: stat testdata/alpha: no such file or directory --- FAIL: TestGraph (0.13s)

defer engine.Close()
Expand Down

0 comments on commit d01410a

Please sign in to comment.