Skip to content

legacy: Builder refactorization (part 5...) #2312

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 34 commits into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
1709a8f
move customBuildProperties to arduino/builder
alessio-perugini Sep 12, 2023
c19a712
remove BuildProperties from context
alessio-perugini Sep 12, 2023
c22f1c7
remove BuildPath from context
alessio-perugini Sep 12, 2023
2c22616
remove sketch,libraries,core build path from Context
alessio-perugini Sep 12, 2023
0afe884
remove buildPath parameter to PrepareSketchBuildPath func
alessio-perugini Sep 12, 2023
7ff4427
Make CoreBuilder a method recevier of arduino/builder
alessio-perugini Sep 12, 2023
2297f2b
Add BuilderLogger in arduino/builder
alessio-perugini Sep 12, 2023
d704e4c
Remove BuilderLogger from CoreBuild parameter
alessio-perugini Sep 12, 2023
f8cbfe5
Make getCachedCoreArchiveDirName unexported
alessio-perugini Sep 12, 2023
5916daa
heavily refactored the ContainerBuildOptions
alessio-perugini Sep 12, 2023
895c593
remove fqbn from Context
alessio-perugini Sep 12, 2023
b4891ea
remove clean from Context
alessio-perugini Sep 12, 2023
870f624
remove unsued properties in Context
alessio-perugini Sep 12, 2023
a6e1ef2
remove sourceOverrides from Context
alessio-perugini Sep 12, 2023
776ed23
make SketchBuilder a method recevier of arduino/builder
alessio-perugini Sep 12, 2023
93a9cfa
make BuildLibraries a method recevier of arduino/builder
alessio-perugini Sep 12, 2023
e965599
make RunRecipe a method recevier of arduino/builder
alessio-perugini Sep 12, 2023
f1fdf17
make RemoveUnusedCompiledLibraries a method recevier of arduino/builder
alessio-perugini Sep 12, 2023
41b47b7
make MergeSketchWithBootloader a method recevier of arduino/builder
alessio-perugini Sep 12, 2023
4f99d33
make WarnAboutArchIncompatibleLibraries a method recevier of arduino/…
alessio-perugini Sep 12, 2023
16f7fe0
make PrintUsedLibraries a method recevier of arduino/builder
alessio-perugini Sep 12, 2023
97a15a4
make ExportCmake and PreprocessorSketch a method recevier of arduino/…
alessio-perugini Sep 12, 2023
f4f7298
remove legacy/constans pkg
alessio-perugini Sep 12, 2023
5e9f9ca
make Linker a method recevier of arduino/builder
alessio-perugini Sep 12, 2023
290e8b1
make Size a method recevier of arduino/builder
alessio-perugini Sep 12, 2023
2279e9b
remove onlyUpdateCompilationDatabase from Context
alessio-perugini Sep 12, 2023
a0f8e30
remove Progress from Context
alessio-perugini Sep 12, 2023
aa904b6
remove ExecutableSectionSize from Context
alessio-perugini Sep 12, 2023
34e6204
remove CompilationDatabase from Context
alessio-perugini Sep 12, 2023
d5c040f
remove LineOffset from Context
alessio-perugini Sep 12, 2023
8995aff
introduce BuilderArtifacts to better isolate write operations
alessio-perugini Sep 12, 2023
e005586
remove ActualPlatform and TargetPlatform from Context
alessio-perugini Sep 13, 2023
a7963f4
directly pass the remaining properties of Context in the builder cons…
alessio-perugini Sep 13, 2023
6004057
polish legacy test
alessio-perugini Sep 13, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
remove sourceOverrides from Context
  • Loading branch information
alessio-perugini committed Sep 15, 2023
commit a6e1ef2c34bfc1b725201c564dce273a6633d59b
7 changes: 7 additions & 0 deletions arduino/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ type Builder struct {
logger *logger.BuilderLogger
clean bool

// Source code overrides (filename -> content map).
// The provided source data is used instead of reading it from disk.
// The keys of the map are paths relative to sketch folder.
sourceOverrides map[string]string

*BuildOptionsManager
}

Expand All @@ -67,6 +72,7 @@ func NewBuilder(
builtInLibrariesDirs *paths.Path,
fqbn *cores.FQBN,
clean bool,
sourceOverrides map[string]string,
logger *logger.BuilderLogger,
) (*Builder, error) {
buildProperties := properties.NewMap()
Expand Down Expand Up @@ -128,6 +134,7 @@ func NewBuilder(
coreBuildCachePath: coreBuildCachePath,
logger: logger,
clean: clean,
sourceOverrides: sourceOverrides,
BuildOptionsManager: NewBuildOptionsManager(
hardwareDirs, builtInToolsDirs, otherLibrariesDirs,
builtInLibrariesDirs, buildPath,
Expand Down
6 changes: 3 additions & 3 deletions arduino/builder/sketch.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ func (b *Builder) Sketch() *sketch.Sketch {
// PrepareSketchBuildPath copies the sketch source files in the build path.
// The .ino files are merged together to create a .cpp file (by the way, the
// .cpp file still needs to be Arduino-preprocessed to compile).
func (b *Builder) PrepareSketchBuildPath(sourceOverrides map[string]string) (int, error) {
func (b *Builder) PrepareSketchBuildPath() (int, error) {
if err := b.sketchBuildPath.MkdirAll(); err != nil {
return 0, errors.Wrap(err, tr("unable to create a folder to save the sketch"))
}

offset, mergedSource, err := b.sketchMergeSources(sourceOverrides)
offset, mergedSource, err := b.sketchMergeSources(b.sourceOverrides)
if err != nil {
return 0, err
}
Expand All @@ -63,7 +63,7 @@ func (b *Builder) PrepareSketchBuildPath(sourceOverrides map[string]string) (int
return 0, err
}

if err := b.sketchCopyAdditionalFiles(b.sketchBuildPath, sourceOverrides); err != nil {
if err := b.sketchCopyAdditionalFiles(b.sketchBuildPath, b.sourceOverrides); err != nil {
return 0, err
}

Expand Down
6 changes: 3 additions & 3 deletions arduino/builder/sketch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func TestMergeSketchSources(t *testing.T) {

b, err := NewBuilder(
sk, nil, paths.New("testdata"), false, nil, 0, nil,
nil, nil, nil, nil, fqbn, false, nil)
nil, nil, nil, nil, fqbn, false, nil, nil)
require.NoError(t, err)

offset, source, err := b.sketchMergeSources(nil)
Expand All @@ -73,7 +73,7 @@ func TestMergeSketchSourcesArduinoIncluded(t *testing.T) {

// ensure not to include Arduino.h when it's already there
b, err := NewBuilder(sk, nil, paths.New("testdata"), false, nil, 0, nil,
nil, nil, nil, nil, fqbn, false, nil)
nil, nil, nil, nil, fqbn, false, nil, nil)
require.NoError(t, err)

_, source, err := b.sketchMergeSources(nil)
Expand All @@ -95,7 +95,7 @@ func TestCopyAdditionalFiles(t *testing.T) {
require.NoError(t, err)

b1, err := NewBuilder(sk1, nil, paths.New("testdata"), false, nil, 0, nil,
nil, nil, nil, nil, fqbn, false, nil)
nil, nil, nil, nil, fqbn, false, nil, nil)
require.NoError(t, err)

// copy the sketch over, create a fake main file we don't care about it
Expand Down
2 changes: 1 addition & 1 deletion commands/compile/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
builderCtx.BuiltInLibrariesDirs = configuration.IDEBuiltinLibrariesDir(configuration.Settings)

builderCtx.OnlyUpdateCompilationDatabase = req.GetCreateCompilationDatabaseOnly()
builderCtx.SourceOverride = req.GetSourceOverride()

builderLogger := logger.New(outStream, errStream, req.GetVerbose(), req.GetWarnings())
builderCtx.BuilderLogger = builderLogger
Expand All @@ -208,6 +207,7 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
builderCtx.BuiltInLibrariesDirs,
fqbn,
req.GetClean(),
req.GetSourceOverride(),
builderLogger,
)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions legacy/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (s *Builder) Run(ctx *types.Context) error {
}),

types.BareCommand(func(ctx *types.Context) error {
ctx.LineOffset, _err = ctx.Builder.PrepareSketchBuildPath(ctx.SourceOverride)
ctx.LineOffset, _err = ctx.Builder.PrepareSketchBuildPath()
return _err
}),

Expand Down Expand Up @@ -315,7 +315,7 @@ func (s *Preprocess) Run(ctx *types.Context) error {
}),

types.BareCommand(func(ctx *types.Context) error {
ctx.LineOffset, _err = ctx.Builder.PrepareSketchBuildPath(ctx.SourceOverride)
ctx.LineOffset, _err = ctx.Builder.PrepareSketchBuildPath()
return _err
}),

Expand Down
4 changes: 2 additions & 2 deletions legacy/builder/test/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func prepareBuilderTestContext(t *testing.T, ctx *types.Context, sketchPath *pat
ctx.Builder, err = bldr.NewBuilder(
sk, nil, buildPath, false, nil, 0, nil,
ctx.HardwareDirs, ctx.BuiltInToolsDirs, ctx.OtherLibrariesDirs,
ctx.BuiltInLibrariesDirs, parseFQBN(t, "a:b:c"), false, builderLogger,
ctx.BuiltInLibrariesDirs, parseFQBN(t, "a:b:c"), false, nil, builderLogger,
)
require.NoError(t, err)
if fqbnString != "" {
Expand All @@ -119,7 +119,7 @@ func prepareBuilderTestContext(t *testing.T, ctx *types.Context, sketchPath *pat
ctx.Builder, err = bldr.NewBuilder(
sk, boardBuildProperties, buildPath, false, nil, 0, nil,
ctx.HardwareDirs, ctx.BuiltInToolsDirs, ctx.OtherLibrariesDirs,
ctx.BuiltInLibrariesDirs, fqbn, false, builderLogger)
ctx.BuiltInLibrariesDirs, fqbn, false, nil, builderLogger)
require.NoError(t, err)

ctx.PackageManager = pme
Expand Down
5 changes: 0 additions & 5 deletions legacy/builder/types/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,6 @@ type Context struct {
CompilationDatabase *compilation.Database
// Set to true to skip build and produce only Compilation Database
OnlyUpdateCompilationDatabase bool

// Source code overrides (filename -> content map).
// The provided source data is used instead of reading it from disk.
// The keys of the map are paths relative to sketch folder.
SourceOverride map[string]string
}

func (ctx *Context) PushProgress() {
Expand Down