Skip to content

Commit

Permalink
Add language field to metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
eandre committed Apr 17, 2024
1 parent c99e939 commit f9948b0
Show file tree
Hide file tree
Showing 17 changed files with 726 additions and 623 deletions.
8 changes: 8 additions & 0 deletions cli/daemon/apps/apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,14 @@ func (i *Instance) Experiments(environ []string) (*experiments.Set, error) {
return experiments.FromAppFileAndEnviron(exp, environ)
}

func (i *Instance) Lang() appfile.Lang {
appFile, err := appfile.ParseFile(filepath.Join(i.root, appfile.Name))
if err != nil {
return appfile.LangGo
}
return appFile.Lang
}

// GlobalCORS returns the CORS configuration for the app which
// will be applied against all API gateways into the app
func (i *Instance) GlobalCORS() (appfile.CORS, error) {
Expand Down
2 changes: 1 addition & 1 deletion cli/daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func (s *Server) GenClient(ctx context.Context, params *daemonpb.GenClientReques
}

// Parse the app to figure out what infrastructure is needed.
bld := builderimpl.Resolve(expSet)
bld := builderimpl.Resolve(app.Lang(), expSet)
defer fns.CloseIgnore(bld)
parse, err := bld.Parse(ctx, builder.ParseParams{
Build: builder.DefaultBuildInfo(),
Expand Down
6 changes: 3 additions & 3 deletions cli/daemon/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (s *Server) dbConnectLocal(ctx context.Context, req *daemonpb.DBConnectRequ
}

// Parse the app to figure out what infrastructure is needed.
bld := builderimpl.Resolve(expSet)
bld := builderimpl.Resolve(app.Lang(), expSet)
defer fns.CloseIgnore(bld)
parse, err := bld.Parse(ctx, builder.ParseParams{
Build: builder.DefaultBuildInfo(),
Expand Down Expand Up @@ -176,7 +176,7 @@ func (s *Server) DBProxy(params *daemonpb.DBProxyRequest, stream daemonpb.Daemon
}

// Parse the app to figure out what infrastructure is needed.
bld := builderimpl.Resolve(expSet)
bld := builderimpl.Resolve(app.Lang(), expSet)
defer fns.CloseIgnore(bld)
parse, err := bld.Parse(ctx, builder.ParseParams{
Build: builder.DefaultBuildInfo(),
Expand Down Expand Up @@ -274,7 +274,7 @@ func (s *Server) DBReset(req *daemonpb.DBResetRequest, stream daemonpb.Daemon_DB
}

// Parse the app to figure out what infrastructure is needed.
bld := builderimpl.Resolve(expSet)
bld := builderimpl.Resolve(app.Lang(), expSet)
defer fns.CloseIgnore(bld)
parse, err := bld.Parse(stream.Context(), builder.ParseParams{
Build: builder.DefaultBuildInfo(),
Expand Down
2 changes: 1 addition & 1 deletion cli/daemon/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (s *Server) DumpMeta(ctx context.Context, req *daemonpb.DumpMetaRequest) (*
UncommittedChanges: vcsRevision.Uncommitted,
}

bld := builderimpl.Resolve(expSet)
bld := builderimpl.Resolve(app.Lang(), expSet)
defer fns.CloseIgnore(bld)
parse, err := bld.Parse(ctx, builder.ParseParams{
Build: buildInfo,
Expand Down
2 changes: 1 addition & 1 deletion cli/daemon/export/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func Docker(ctx context.Context, app *apps.Instance, req *daemonpb.ExportRequest
UncommittedChanges: vcsRevision.Uncommitted,
}

bld := builderimpl.Resolve(expSet)
bld := builderimpl.Resolve(app.Lang(), expSet)
defer fns.CloseIgnore(bld)
parse, err := bld.Parse(ctx, builder.ParseParams{
Build: buildInfo,
Expand Down
2 changes: 1 addition & 1 deletion cli/daemon/run/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (mgr *Manager) Check(ctx context.Context, p CheckParams) (buildDir string,
UncommittedChanges: vcsRevision.Uncommitted,
}

bld := builderimpl.Resolve(expSet)
bld := builderimpl.Resolve(p.App.Lang(), expSet)
defer fns.CloseIgnore(bld)
parse, err := bld.Parse(ctx, builder.ParseParams{
Build: buildInfo,
Expand Down
2 changes: 1 addition & 1 deletion cli/daemon/run/exec_script.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (mgr *Manager) ExecScript(ctx context.Context, p ExecScriptParams) (err err
parseOp := tracker.Add("Building Encore application graph", start)
topoOp := tracker.Add("Analyzing service topology", start)

bld := builderimpl.Resolve(expSet)
bld := builderimpl.Resolve(p.App.Lang(), expSet)
defer fns.CloseIgnore(bld)
vcsRevision := vcs.GetRevision(p.App.Root())
buildInfo := builder.BuildInfo{
Expand Down
2 changes: 1 addition & 1 deletion cli/daemon/run/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ func (r *Run) buildAndStart(ctx context.Context, tracker *optracker.OpTracker, i
}

if r.Builder == nil {
r.Builder = builderimpl.Resolve(expSet)
r.Builder = builderimpl.Resolve(r.App.Lang(), expSet)
}

vcsRevision := vcs.GetRevision(r.App.Root())
Expand Down
4 changes: 2 additions & 2 deletions cli/daemon/run/tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (mgr *Manager) Test(ctx context.Context, params TestParams) (err error) {
if err != nil {
return err
}
bld := builderimpl.Resolve(expSet)
bld := builderimpl.Resolve(params.App.Lang(), expSet)
defer fns.CloseIgnore(bld)

spec, err := mgr.testSpec(ctx, bld, expSet, params.TestSpecParams)
Expand Down Expand Up @@ -95,7 +95,7 @@ func (mgr *Manager) TestSpec(ctx context.Context, params TestSpecParams) (*TestS
if err != nil {
return nil, err
}
bld := builderimpl.Resolve(expSet)
bld := builderimpl.Resolve(params.App.Lang(), expSet)
defer fns.CloseIgnore(bld)

spec, err := mgr.testSpec(ctx, bld, expSet, &params)
Expand Down
2 changes: 1 addition & 1 deletion cli/daemon/userfacing.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (s *Server) genUserFacing(ctx context.Context, app *apps.Instance) error {
UncommittedChanges: vcsRevision.Uncommitted,
}

bld := builderimpl.Resolve(expSet)
bld := builderimpl.Resolve(app.Lang(), expSet)
defer fns.CloseIgnore(bld)

parse, err := bld.Parse(ctx, builder.ParseParams{
Expand Down
2 changes: 1 addition & 1 deletion e2e-tests/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ func testBuild(t testing.TB, appRoot string, env []string) (*builder.ParseResult
t.Fatal(err)
}

bld := builderimpl.Resolve(expSet)
bld := builderimpl.Resolve("", expSet)
defer fns.CloseIgnore(bld)
ctx := context.Background()

Expand Down
20 changes: 20 additions & 0 deletions pkg/appfile/appfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ import (
// (which is usually the Git repository root).
const Name = "encore.app"

type Lang string

const (
LangGo Lang = "go"
LangTS Lang = "typescript"
)

// File is a parsed encore.app file.
type File struct {
// ID is the encore.dev app id for the app.
Expand All @@ -32,6 +39,10 @@ type File struct {
// Do not use these features in production without consulting the Encore team.
Experiments []experiments.Name `json:"experiments,omitempty"`

// Lang is the language the app is written in.
// If empty it defaults to Go.
Lang Lang `json:"lang"`

// Configure global CORS settings for the application which
// will be applied to all API gateways into the application.
GlobalCORS *CORS `json:"global_cors,omitempty"`
Expand Down Expand Up @@ -111,6 +122,15 @@ func Parse(data []byte) (*File, error) {
return nil, fmt.Errorf("appfile.Parse: %v", err)
}

switch f.Lang {
case LangGo, LangTS:
// Do nothing
case "":
f.Lang = LangGo
default:
return nil, fmt.Errorf("appfile.Parse: invalid lang %q", f.Lang)
}

// Parse deprecated fields into the new Build struct.
f.Build.CgoEnabled = f.Build.CgoEnabled || f.CgoEnabled
if f.Build.Docker.BaseImage == "" {
Expand Down
5 changes: 3 additions & 2 deletions pkg/builder/builderimpl/builders.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ package builderimpl

import (
"encore.dev/appruntime/exported/experiments"
"encr.dev/pkg/appfile"
"encr.dev/pkg/builder"
"encr.dev/v2/tsbuilder"
"encr.dev/v2/v2builder"
)

func Resolve(expSet *experiments.Set) builder.Impl {
if experiments.TypeScript.Enabled(expSet) {
func Resolve(lang appfile.Lang, expSet *experiments.Set) builder.Impl {
if lang == appfile.LangTS || experiments.TypeScript.Enabled(expSet) {
return tsbuilder.New()
}
return v2builder.BuilderImpl{}
Expand Down
Loading

0 comments on commit f9948b0

Please sign in to comment.