Skip to content

Commit

Permalink
revert: "fix: use shared .ftl folder for stubs (#1843)" (#2003)
Browse files Browse the repository at this point in the history
This reverts commit 0a69db1.
Due to #2001
  • Loading branch information
matt2e authored Jul 8, 2024
1 parent e6d8499 commit 37423b4
Show file tree
Hide file tree
Showing 35 changed files with 393 additions and 594 deletions.
6 changes: 0 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,9 @@ examples/**/go.work
examples/**/go.work.sum
testdata/**/go.work
testdata/**/go.work.sum

# Leaving old _ftl for now to avoid old stuff getting checked in
**/testdata/**/_ftl
**/examples/**/_ftl
**/examples/**/types.ftl.go
**/testdata/**/.ftl
**/examples/**/.ftl
/.ftl

buildengine/.gitignore
go.work*
junit*.xml
Expand Down
2 changes: 1 addition & 1 deletion Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ KT_RUNTIME_RUNNER_TEMPLATE_OUT := "build/template/ftl/jars/ftl-runtime.jar"
RUNNER_TEMPLATE_ZIP := "backend/controller/scaling/localscaling/template.zip"
TIMESTAMP := `date +%s`
SCHEMA_OUT := "backend/protos/xyz/block/ftl/v1/schema/schema.proto"
ZIP_DIRS := "go-runtime/compile/build-template go-runtime/compile/external-module-template go-runtime/compile/main-work-template common-runtime/scaffolding go-runtime/scaffolding kotlin-runtime/scaffolding kotlin-runtime/external-module-template"
ZIP_DIRS := "go-runtime/compile/build-template go-runtime/compile/external-module-template common-runtime/scaffolding go-runtime/scaffolding kotlin-runtime/scaffolding kotlin-runtime/external-module-template"
FRONTEND_OUT := "frontend/dist/index.html"
EXTENSION_OUT := "extensions/vscode/dist/extension.js"
PROTOS_IN := "backend/protos/xyz/block/ftl/v1/schema/schema.proto backend/protos/xyz/block/ftl/v1/console/console.proto backend/protos/xyz/block/ftl/v1/ftl.proto backend/protos/xyz/block/ftl/v1/schema/runtime.proto"
Expand Down
8 changes: 4 additions & 4 deletions buildengine/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ const BuildLockTimeout = time.Minute
// Build a module in the given directory given the schema and module config.
//
// A lock file is used to ensure that only one build is running at a time.
func Build(ctx context.Context, projectRootDir string, sch *schema.Schema, module Module, filesTransaction ModifyFilesTransaction) error {
return buildModule(ctx, projectRootDir, sch, module, filesTransaction)
func Build(ctx context.Context, sch *schema.Schema, module Module, filesTransaction ModifyFilesTransaction) error {
return buildModule(ctx, sch, module, filesTransaction)
}

func buildModule(ctx context.Context, projectRootDir string, sch *schema.Schema, module Module, filesTransaction ModifyFilesTransaction) error {
func buildModule(ctx context.Context, sch *schema.Schema, module Module, filesTransaction ModifyFilesTransaction) error {
release, err := flock.Acquire(ctx, filepath.Join(module.Config.Dir, ".ftl.lock"), BuildLockTimeout)
if err != nil {
return err
Expand All @@ -46,7 +46,7 @@ func buildModule(ctx context.Context, projectRootDir string, sch *schema.Schema,

switch module.Config.Language {
case "go":
err = buildGoModule(ctx, projectRootDir, sch, module, filesTransaction)
err = buildGoModule(ctx, sch, module, filesTransaction)
case "kotlin":
err = buildKotlinModule(ctx, sch, module)
case "rust":
Expand Down
4 changes: 2 additions & 2 deletions buildengine/build_go.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"github.com/TBD54566975/ftl/go-runtime/compile"
)

func buildGoModule(ctx context.Context, projectRootDir string, sch *schema.Schema, module Module, transaction ModifyFilesTransaction) error {
if err := compile.Build(ctx, projectRootDir, module.Config.Dir, sch, transaction); err != nil {
func buildGoModule(ctx context.Context, sch *schema.Schema, module Module, transaction ModifyFilesTransaction) error {
if err := compile.Build(ctx, module.Config.Dir, sch, transaction); err != nil {
return CompilerBuildError{err: fmt.Errorf("failed to build module %q: %w", module.Config.Module, err)}
}
return nil
Expand Down
249 changes: 242 additions & 7 deletions buildengine/build_go_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,181 @@ import (
"github.com/TBD54566975/ftl/backend/schema"
)

func TestGenerateGoModule(t *testing.T) {
if testing.Short() {
t.SkipNow()
}
sch := &schema.Schema{
Modules: []*schema.Module{
schema.Builtins(),
{Name: "other", Decls: []schema.Decl{
&schema.Enum{
Comments: []string{"This is an enum.", "", "It has 3 variants."},
Name: "Color",
Export: true,
Type: &schema.String{},
Variants: []*schema.EnumVariant{
{Name: "Red", Value: &schema.StringValue{Value: "Red"}},
{Name: "Blue", Value: &schema.StringValue{Value: "Blue"}},
{Name: "Green", Value: &schema.StringValue{Value: "Green"}},
},
},
&schema.Enum{
Name: "ColorInt",
Export: true,
Type: &schema.Int{},
Variants: []*schema.EnumVariant{
{Name: "RedInt", Value: &schema.IntValue{Value: 0}},
{Name: "BlueInt", Value: &schema.IntValue{Value: 1}},
{Name: "GreenInt", Value: &schema.IntValue{Value: 2}},
},
},
&schema.Enum{
Comments: []string{"This is type enum."},
Name: "TypeEnum",
Export: true,
Variants: []*schema.EnumVariant{
{Name: "A", Value: &schema.TypeValue{Value: &schema.Int{}}},
{Name: "B", Value: &schema.TypeValue{Value: &schema.String{}}},
},
},
&schema.Data{Name: "EchoRequest", Export: true},
&schema.Data{
Comments: []string{"This is an echo data response."},
Name: "EchoResponse", Export: true},
&schema.Verb{
Name: "echo",
Export: true,
Request: &schema.Ref{Name: "EchoRequest"},
Response: &schema.Ref{Name: "EchoResponse"},
},
&schema.Data{Name: "SinkReq", Export: true},
&schema.Verb{
Comments: []string{"This is a sink verb.", "", "Here is another line for this comment!"},
Name: "sink",
Export: true,
Request: &schema.Ref{Name: "SinkReq"},
Response: &schema.Unit{},
},
&schema.Data{Name: "SourceResp", Export: true},
&schema.Verb{
Name: "source",
Export: true,
Request: &schema.Unit{},
Response: &schema.Ref{Name: "SourceResp"},
},
&schema.Verb{
Name: "nothing",
Export: true,
Request: &schema.Unit{},
Response: &schema.Unit{},
},
}},
{Name: "test"},
},
}
expected := `// Code generated by FTL. DO NOT EDIT.
package other
import (
"context"
"github.com/TBD54566975/ftl/go-runtime/ftl/reflection"
)
var _ = context.Background
// This is an enum.
//
// It has 3 variants.
//
//ftl:enum
type Color string
const (
Red Color = "Red"
Blue Color = "Blue"
Green Color = "Green"
)
//ftl:enum
type ColorInt int
const (
RedInt ColorInt = 0
BlueInt ColorInt = 1
GreenInt ColorInt = 2
)
// This is type enum.
//
//ftl:enum
type TypeEnum interface { typeEnum() }
type A int
func (A) typeEnum() {}
type B string
func (B) typeEnum() {}
type EchoRequest struct {
}
// This is an echo data response.
//
type EchoResponse struct {
}
//ftl:verb
func Echo(context.Context, EchoRequest) (EchoResponse, error) {
panic("Verb stubs should not be called directly, instead use github.com/TBD54566975/ftl/runtime-go/ftl.Call()")
}
type SinkReq struct {
}
// This is a sink verb.
//
// Here is another line for this comment!
//
//ftl:verb
func Sink(context.Context, SinkReq) error {
panic("Verb stubs should not be called directly, instead use github.com/TBD54566975/ftl/runtime-go/ftl.CallSink()")
}
type SourceResp struct {
}
//ftl:verb
func Source(context.Context) (SourceResp, error) {
panic("Verb stubs should not be called directly, instead use github.com/TBD54566975/ftl/runtime-go/ftl.CallSource()")
}
//ftl:verb
func Nothing(context.Context) error {
panic("Verb stubs should not be called directly, instead use github.com/TBD54566975/ftl/runtime-go/ftl.CallEmpty()")
}
func init() {
reflection.Register(
reflection.SumType[TypeEnum](
*new(A),
*new(B),
),
)
}
`
bctx := buildContext{
moduleDir: "testdata/another",
buildDir: "_ftl",
sch: sch,
}
testBuild(t, bctx, "", []assertion{
assertGeneratedModule("go/modules/other/external_module.go", expected),
})
}

func TestGoBuildClearsBuildDir(t *testing.T) {
if testing.Short() {
t.SkipNow()
Expand All @@ -23,22 +198,82 @@ func TestGoBuildClearsBuildDir(t *testing.T) {
}
bctx := buildContext{
moduleDir: "testdata/another",
buildDir: ".ftl",
buildDir: "_ftl",
sch: sch,
}
testBuildClearsBuildDir(t, bctx)
}

func TestMetadataImportsExcluded(t *testing.T) {
if testing.Short() {
t.SkipNow()
}
sch := &schema.Schema{
Modules: []*schema.Module{
schema.Builtins(),
{Name: "test", Decls: []schema.Decl{
&schema.Data{
Comments: []string{"Request data type."},
Name: "Req", Export: true},
&schema.Data{Name: "Resp", Export: true},
&schema.Verb{
Comments: []string{"This is a verb."},
Name: "call",
Export: true,
Request: &schema.Ref{Name: "Req"},
Response: &schema.Ref{Name: "Resp"},
Metadata: []schema.Metadata{
&schema.MetadataCalls{Calls: []*schema.Ref{{Name: "verb", Module: "other"}}},
},
},
}},
},
}
expected := `// Code generated by FTL. DO NOT EDIT.
package test
import (
"context"
)
var _ = context.Background
// Request data type.
//
type Req struct {
}
type Resp struct {
}
// This is a verb.
//
//ftl:verb
func Call(context.Context, Req) (Resp, error) {
panic("Verb stubs should not be called directly, instead use github.com/TBD54566975/ftl/runtime-go/ftl.Call()")
}
`
bctx := buildContext{
moduleDir: "testdata/another",
buildDir: "_ftl",
sch: sch,
}
testBuild(t, bctx, "", []assertion{
assertGeneratedModule("go/modules/test/external_module.go", expected),
})
}

func TestExternalType(t *testing.T) {
if testing.Short() {
t.SkipNow()
}
bctx := buildContext{
moduleDir: "testdata/external",
buildDir: ".ftl",
buildDir: "_ftl",
sch: &schema.Schema{},
}
testBuild(t, bctx, "", "unsupported external type", []assertion{
testBuild(t, bctx, "unsupported external type", []assertion{
assertBuildProtoErrors(
"unsupported external type \"time.Month\"",
"unsupported type \"time.Month\" for field \"Month\"",
Expand Down Expand Up @@ -67,10 +302,10 @@ func TestGoModVersion(t *testing.T) {
}
bctx := buildContext{
moduleDir: "testdata/highgoversion",
buildDir: ".ftl",
buildDir: "_ftl",
sch: sch,
}
testBuild(t, bctx, fmt.Sprintf("go version %q is not recent enough for this module, needs minimum version \"9000.1.1\"", runtime.Version()[2:]), "", []assertion{})
testBuild(t, bctx, fmt.Sprintf("go version %q is not recent enough for this module, needs minimum version \"9000.1.1\"", runtime.Version()[2:]), []assertion{})
}

func TestGeneratedTypeRegistry(t *testing.T) {
Expand Down Expand Up @@ -110,10 +345,10 @@ func TestGeneratedTypeRegistry(t *testing.T) {
assert.NoError(t, err)
bctx := buildContext{
moduleDir: "testdata/other",
buildDir: ".ftl",
buildDir: "_ftl",
sch: sch,
}
testBuild(t, bctx, "", "", []assertion{
testBuild(t, bctx, "", []assertion{
assertGeneratedMain(string(expected)),
})
}
Loading

0 comments on commit 37423b4

Please sign in to comment.