-
Notifications
You must be signed in to change notification settings - Fork 229
/
builder.go
117 lines (97 loc) · 2.72 KB
/
builder.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package builder
import (
"context"
"io"
"io/fs"
"runtime"
"slices"
"github.com/rs/zerolog"
"encore.dev/appruntime/exported/experiments"
"encr.dev/cli/daemon/apps"
"encr.dev/internal/optracker"
"encr.dev/pkg/cueutil"
"encr.dev/pkg/option"
"encr.dev/pkg/paths"
meta "encr.dev/proto/encore/parser/meta/v1"
)
var LocalBuildTags = []string{"encore_local", "encore_no_gcp", "encore_no_aws", "encore_no_azure"}
type BuildInfo struct {
BuildTags []string
CgoEnabled bool
StaticLink bool
Debug bool
GOOS, GOARCH string
KeepOutput bool
Revision string
UncommittedChanges bool
// MainPkg is the path to the existing main package to use, if any.
MainPkg option.Option[paths.Pkg]
// Overrides to explicitly set the GoRoot and EncoreRuntime paths.
// if not set, they will be inferred from the current executable.
GoRoot option.Option[paths.FS]
EncoreRuntime option.Option[paths.FS]
// Logger allows a custom logger to be used by the various phases of the builder.
Logger option.Option[zerolog.Logger]
}
// DefaultBuildInfo returns a BuildInfo with default values.
// It can be modified afterwards.
func DefaultBuildInfo() BuildInfo {
return BuildInfo{
BuildTags: slices.Clone(LocalBuildTags),
CgoEnabled: true,
StaticLink: false,
Debug: false,
GOOS: runtime.GOOS,
GOARCH: runtime.GOARCH,
KeepOutput: false,
Revision: "",
UncommittedChanges: false,
}
}
type ParseParams struct {
Build BuildInfo
App *apps.Instance
Experiments *experiments.Set
WorkingDir string
ParseTests bool
}
type ParseResult struct {
Meta *meta.Data
Data any
}
type CompileParams struct {
Build BuildInfo
App *apps.Instance
Parse *ParseResult
OpTracker *optracker.OpTracker
Experiments *experiments.Set
WorkingDir string
CueMeta *cueutil.Meta
// Override to explicitly allow the Encore version to be set.
EncoreVersion option.Option[string]
}
type CompileResult struct {
Dir string
Exe string
Configs map[string]string
ConfigFiles fs.FS
}
type TestParams struct {
Compile CompileParams
// Env sets environment variables for "go test".
Env []string
// Args sets extra arguments for "go test".
Args []string
// Stdout and Stderr are where to redirect "go test" output.
Stdout, Stderr io.Writer
}
type GenUserFacingParams struct {
App *apps.Instance
Parse *ParseResult
}
type Impl interface {
Parse(context.Context, ParseParams) (*ParseResult, error)
Compile(context.Context, CompileParams) (*CompileResult, error)
Test(context.Context, TestParams) error
GenUserFacing(context.Context, GenUserFacingParams) error
}