Skip to content

Commit

Permalink
chore: migrate verb, data schema parsing
Browse files Browse the repository at this point in the history
restructuring and adding some additional passes to provide data for the extractors-
1. metadata pass parses all comments in the packages and provides results via facts
2. transitive pass extracts nodes marked as needing extraction via transitive reference from other decls
  • Loading branch information
worstell committed Jun 17, 2024
1 parent 6cb3ed0 commit e0e5a12
Show file tree
Hide file tree
Showing 60 changed files with 2,196 additions and 1,243 deletions.
4 changes: 2 additions & 2 deletions backend/controller/cronjobs/testdata/go/cron/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions backend/controller/dal/testdata/go/fsm/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions backend/controller/dal/testdata/go/fsmretry/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions backend/controller/ingress/testdata/go/httpingress/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions backend/controller/leases/testdata/go/leases/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions backend/controller/pubsub/testdata/go/publisher/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions backend/controller/pubsub/testdata/go/subscriber/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions backend/controller/sql/testdata/go/database/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions buildengine/testdata/projects/alpha/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions buildengine/testdata/projects/another/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions buildengine/testdata/projects/external/.ftl-build-lock
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
64666
4 changes: 2 additions & 2 deletions buildengine/testdata/projects/other/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions common/projectconfig/testdata/go/echo/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions common/projectconfig/testdata/go/findconfig/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions examples/go/echo/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions go-runtime/compile/build-template/_ftl.tmpl/go/main/main.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 29 additions & 6 deletions go-runtime/compile/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"strings"
"unicode"

"github.com/TBD54566975/ftl/go-runtime/schema/analyzers"
"github.com/TBD54566975/ftl/go-runtime/schema/finalize"
sets "github.com/deckarep/golang-set/v2"
gomaps "golang.org/x/exp/maps"
"golang.org/x/mod/modfile"
Expand Down Expand Up @@ -45,6 +45,8 @@ type ExternalModuleContext struct {

type goVerb struct {
Name string
Package string
MustImport string
HasRequest bool
HasResponse bool
}
Expand Down Expand Up @@ -169,7 +171,10 @@ func Build(ctx context.Context, moduleDir string, sch *schema.Schema, filesTrans
return fmt.Errorf("missing native name for verb %s", verb.Name)
}

goverb := goVerb{Name: nativeName}
goverb, err := goVerbFromQualifiedName(nativeName)
if err != nil {
return err
}
if _, ok := verb.Request.(*schema.Unit); !ok {
goverb.HasRequest = true
}
Expand Down Expand Up @@ -330,6 +335,9 @@ var scaffoldFuncs = scaffolder.FuncMap{
if len(ctx.Verbs) > 0 {
imports.Add(ctx.Name)
}
for _, v := range ctx.Verbs {
imports.Add(strings.TrimPrefix(v.MustImport, "ftl/"))
}
for _, st := range ctx.SumTypes {
if i := strings.LastIndex(st.Discriminator, "."); i != -1 {
imports.Add(st.Discriminator[:i])
Expand Down Expand Up @@ -612,22 +620,22 @@ func getExternalTypeEnums(module *schema.Module, sch *schema.Schema) []externalE
//
// TODO: once migrated off of the legacy extractor, we can inline `extract.Extract(dir)` and delete this
// function
func ExtractModuleSchema(dir string, sch *schema.Schema) (analyzers.ExtractResult, error) {
func ExtractModuleSchema(dir string, sch *schema.Schema) (finalize.Result, error) {
result, err := extract.Extract(dir)
if err != nil {
return analyzers.ExtractResult{}, err
return finalize.Result{}, err
}

// merge with legacy results for now
if err = legacyExtractModuleSchema(dir, sch, &result); err != nil {
return analyzers.ExtractResult{}, err
return finalize.Result{}, err
}

schema.SortErrorsByPosition(result.Errors)
if !schema.ContainsTerminalError(result.Errors) {
err = schema.ValidateModule(result.Module)
if err != nil {
return analyzers.ExtractResult{}, err
return finalize.Result{}, err
}
}
updateVisibility(result.Module)
Expand Down Expand Up @@ -678,3 +686,18 @@ func updateTransitiveVisibility(d schema.Decl, module *schema.Module) {
return next()
})
}

func goVerbFromQualifiedName(qualifiedName string) (goVerb, error) {
lastDotIndex := strings.LastIndex(qualifiedName, ".")
if lastDotIndex == -1 {
return goVerb{}, fmt.Errorf("invalid qualified type format %q", qualifiedName)
}
pkgPath := qualifiedName[:lastDotIndex]
typeName := qualifiedName[lastDotIndex+1:]
pkgName := path.Base(pkgPath)
return goVerb{
Name: typeName,
Package: pkgName,
MustImport: pkgPath,
}, nil
}
Loading

0 comments on commit e0e5a12

Please sign in to comment.