Skip to content

Commit

Permalink
remove sourceOverrides from Context
Browse files Browse the repository at this point in the history
  • Loading branch information
alessio-perugini committed Sep 12, 2023
1 parent 27f5fbc commit 0a2b707
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 16 deletions.
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

0 comments on commit 0a2b707

Please sign in to comment.