Skip to content

Commit

Permalink
Made SetupBuildProperties a method of the new Builder
Browse files Browse the repository at this point in the history
  • Loading branch information
cmaglie committed Aug 30, 2023
1 parent a5bd7dc commit 868d325
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
9 changes: 4 additions & 5 deletions arduino/builder/sketch.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"regexp"

"github.com/arduino/arduino-cli/arduino/builder/cpp"
"github.com/arduino/arduino-cli/arduino/sketch"
"github.com/arduino/arduino-cli/i18n"
"github.com/arduino/go-paths-helper"
"github.com/arduino/go-properties-orderedmap"
Expand Down Expand Up @@ -170,16 +169,16 @@ func writeIfDifferent(source []byte, destPath *paths.Path) error {

// SetupBuildProperties adds the build properties related to the sketch to the
// default board build properties map.
func SetupBuildProperties(boardBuildProperties *properties.Map, buildPath *paths.Path, sketch *sketch.Sketch, optimizeForDebug bool) *properties.Map {
func (b *Builder) SetupBuildProperties(boardBuildProperties *properties.Map, buildPath *paths.Path, optimizeForDebug bool) *properties.Map {
buildProperties := properties.NewMap()
buildProperties.Merge(boardBuildProperties)

if buildPath != nil {
buildProperties.SetPath("build.path", buildPath)
}
if sketch != nil {
buildProperties.Set("build.project_name", sketch.MainFile.Base())
buildProperties.SetPath("build.source.path", sketch.FullPath)
if b.sketch != nil {
buildProperties.Set("build.project_name", b.sketch.MainFile.Base())
buildProperties.SetPath("build.source.path", b.sketch.FullPath)
}
if optimizeForDebug {
if debugFlags, ok := buildProperties.GetOk("compiler.optimization_flags.debug"); ok {
Expand Down
6 changes: 4 additions & 2 deletions commands/compile/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,10 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
// cache is purged after compilation to not remove entries that might be required
defer maybePurgeBuildCache()

sketchBuilder := bldr.NewBuilder(sk)

// Add build properites related to sketch data
buildProperties = bldr.SetupBuildProperties(buildProperties, buildPath, sk, req.GetOptimizeForDebug())
buildProperties = sketchBuilder.SetupBuildProperties(buildProperties, buildPath, req.GetOptimizeForDebug())

// Add user provided custom build properties
customBuildPropertiesArgs := append(req.GetBuildProperties(), "build.warn_data_percentage=75")
Expand All @@ -169,7 +171,7 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
}

builderCtx := &types.Context{}
builderCtx.Builder = bldr.NewBuilder(sk)
builderCtx.Builder = sketchBuilder
builderCtx.PackageManager = pme
if pme.GetProfile() != nil {
builderCtx.LibrariesManager = lm
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 @@ -83,14 +83,15 @@ func prepareBuilderTestContext(t *testing.T, ctx *types.Context, sketchPath *pat
ctx.Sketch = sk
}

ctx.Builder = bldr.NewBuilder(ctx.Sketch)
if fqbn != "" {
ctx.FQBN = parseFQBN(t, fqbn)
targetPackage, targetPlatform, targetBoard, buildProperties, buildPlatform, err := pme.ResolveFQBN(ctx.FQBN)
require.NoError(t, err)
requiredTools, err := pme.FindToolsRequiredForBuild(targetPlatform, buildPlatform)
require.NoError(t, err)

buildProperties = bldr.SetupBuildProperties(buildProperties, ctx.BuildPath, ctx.Sketch, false /*OptimizeForDebug*/)
buildProperties = ctx.Builder.SetupBuildProperties(buildProperties, ctx.BuildPath, false /*OptimizeForDebug*/)
ctx.PackageManager = pme
ctx.TargetBoard = targetBoard
ctx.BuildProperties = buildProperties
Expand All @@ -100,7 +101,6 @@ func prepareBuilderTestContext(t *testing.T, ctx *types.Context, sketchPath *pat
ctx.RequiredTools = requiredTools
}

ctx.Builder = bldr.NewBuilder(ctx.Sketch)
return ctx
}

Expand Down

0 comments on commit 868d325

Please sign in to comment.