Skip to content

Commit

Permalink
remove fqbn from Context
Browse files Browse the repository at this point in the history
  • Loading branch information
alessio-perugini committed Sep 12, 2023
1 parent 4d6f1b7 commit 1b3a6e5
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 18 deletions.
7 changes: 3 additions & 4 deletions arduino/builder/build_options_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (

"github.com/arduino/arduino-cli/arduino/builder/logger"
"github.com/arduino/arduino-cli/arduino/builder/utils"
"github.com/arduino/arduino-cli/arduino/cores"
"github.com/arduino/arduino-cli/arduino/sketch"
"github.com/arduino/go-paths-helper"
properties "github.com/arduino/go-properties-orderedmap"
Expand All @@ -42,7 +43,6 @@ type BuildOptionsManager struct {
buildCorePath *paths.Path
sketch *sketch.Sketch
customBuildProperties []string
fqbn string
compilerOptimizationFlags string
clean bool
builderLogger *logger.BuilderLogger
Expand All @@ -54,7 +54,7 @@ func NewBuildOptionsManager(
builtInLibrariesDirs, buildPath *paths.Path,
sketch *sketch.Sketch,
customBuildProperties []string,
fqbn string,
fqbn *cores.FQBN,
clean bool,
compilerOptimizationFlags string,
runtimePlatformPath, buildCorePath *paths.Path,
Expand All @@ -66,7 +66,7 @@ func NewBuildOptionsManager(
opts.Set("builtInToolsFolders", strings.Join(builtInToolsDirs.AsStrings(), ","))
opts.Set("otherLibrariesFolders", strings.Join(otherLibrariesDirs.AsStrings(), ","))
opts.SetPath("sketchLocation", sketch.FullPath)
opts.Set("fqbn", fqbn)
opts.Set("fqbn", fqbn.String())
opts.Set("customBuildProperties", strings.Join(customBuildProperties, ","))
opts.Set("compiler.optimization_flags", compilerOptimizationFlags)

Expand Down Expand Up @@ -96,7 +96,6 @@ func NewBuildOptionsManager(
buildCorePath: buildCorePath,
sketch: sketch,
customBuildProperties: customBuildProperties,
fqbn: fqbn,
compilerOptimizationFlags: compilerOptimizationFlags,
clean: clean,
builderLogger: buildLogger,
Expand Down
4 changes: 2 additions & 2 deletions arduino/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"fmt"

"github.com/arduino/arduino-cli/arduino/builder/logger"
"github.com/arduino/arduino-cli/arduino/cores"
"github.com/arduino/arduino-cli/arduino/sketch"
"github.com/arduino/go-paths-helper"
"github.com/arduino/go-properties-orderedmap"
Expand Down Expand Up @@ -53,7 +54,6 @@ type Builder struct {

hardwareDirs, builtInToolsDirs, otherLibrariesDirs paths.PathList
builtInLibrariesDirs *paths.Path
fqbn string
clean bool

compilerOptimizationFlags string
Expand All @@ -71,7 +71,7 @@ func NewBuilder(
requestBuildProperties []string,
hardwareDirs, builtInToolsDirs, otherLibrariesDirs paths.PathList,
builtInLibrariesDirs *paths.Path,
fqbn string,
fqbn *cores.FQBN,
clean bool,
logger *logger.BuilderLogger,
) (*Builder, error) {
Expand Down
17 changes: 14 additions & 3 deletions arduino/builder/sketch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"strings"
"testing"

"github.com/arduino/arduino-cli/arduino/cores"
"github.com/arduino/arduino-cli/arduino/sketch"
"github.com/arduino/go-paths-helper"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -48,9 +49,12 @@ func TestMergeSketchSources(t *testing.T) {
}
mergedSources := strings.ReplaceAll(string(mergedBytes), "%s", pathToGoldenSource)

fqbn, err := cores.ParseFQBN("a:b:c")
require.NoError(t, err)

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

offset, source, err := b.sketchMergeSources(nil)
Expand All @@ -64,9 +68,12 @@ func TestMergeSketchSourcesArduinoIncluded(t *testing.T) {
require.Nil(t, err)
require.NotNil(t, sk)

fqbn, err := cores.ParseFQBN("a:b:c")
require.NoError(t, err)

// 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, "", false, nil)
nil, nil, nil, nil, fqbn, false, nil)
require.NoError(t, err)

_, source, err := b.sketchMergeSources(nil)
Expand All @@ -83,8 +90,12 @@ func TestCopyAdditionalFiles(t *testing.T) {
sk1, err := sketch.New(paths.New("testdata", t.Name()))
require.Nil(t, err)
require.Equal(t, sk1.AdditionalFiles.Len(), 1)

fqbn, err := cores.ParseFQBN("a:b:c")
require.NoError(t, err)

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

// copy the sketch over, create a fake main file we don't care about it
Expand Down
3 changes: 1 addition & 2 deletions commands/compile/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
builderCtx.TargetPackage = targetPackage
builderCtx.ActualPlatform = buildPlatform
builderCtx.RequiredTools = requiredTools
builderCtx.FQBN = fqbn
builderCtx.ProgressCB = progressCB

// FIXME: This will be redundant when arduino-builder will be part of the cli
Expand Down Expand Up @@ -212,7 +211,7 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
builderCtx.BuiltInToolsDirs,
builderCtx.OtherLibrariesDirs,
builderCtx.BuiltInLibrariesDirs,
builderCtx.FQBN.String(),
fqbn,
builderCtx.Clean,
builderLogger,
)
Expand Down
10 changes: 5 additions & 5 deletions legacy/builder/test/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type skipContextPreparationStepName string

const skipLibraries = skipContextPreparationStepName("libraries")

func prepareBuilderTestContext(t *testing.T, ctx *types.Context, sketchPath *paths.Path, fqbn string, skips ...skipContextPreparationStepName) *types.Context {
func prepareBuilderTestContext(t *testing.T, ctx *types.Context, sketchPath *paths.Path, fqbnString string, skips ...skipContextPreparationStepName) *types.Context {
DownloadCoresAndToolsAndLibraries(t)

stepToSkip := map[skipContextPreparationStepName]bool{}
Expand Down Expand Up @@ -106,12 +106,12 @@ 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, fqbn, ctx.Clean, builderLogger,
ctx.BuiltInLibrariesDirs, parseFQBN(t, "a:b:c"), ctx.Clean, builderLogger,
)
require.NoError(t, err)
if fqbn != "" {
ctx.FQBN = parseFQBN(t, fqbn)
targetPackage, targetPlatform, targetBoard, boardBuildProperties, buildPlatform, err := pme.ResolveFQBN(ctx.FQBN)
if fqbnString != "" {
fqbn := parseFQBN(t, fqbnString)
targetPackage, targetPlatform, targetBoard, boardBuildProperties, buildPlatform, err := pme.ResolveFQBN(fqbn)
require.NoError(t, err)
requiredTools, err := pme.FindToolsRequiredForBuild(targetPlatform, buildPlatform)
require.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion legacy/builder/test/store_build_options_map_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func TestCheckIfBuildOptionsChanged(t *testing.T) {
buildOptionsManager := builder.NewBuildOptionsManager(
hardwareDirs, builtInToolsDirs, otherLibrariesDirs,
builtInLibrariesDirs, buildPath, &sketch.Sketch{FullPath: paths.New("sketchLocation")}, []string{"custom=prop"},
fqbn.String(), false,
fqbn, false,
buildProperties.Get("compiler.optimization_flags"),
buildProperties.GetPath("runtime.platform.path"),
buildProperties.GetPath("build.core.path"),
Expand Down
1 change: 0 additions & 1 deletion legacy/builder/types/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ type Context struct {
BuiltInToolsDirs paths.PathList
BuiltInLibrariesDirs *paths.Path
OtherLibrariesDirs paths.PathList
FQBN *cores.FQBN
Clean bool

PackageManager *packagemanager.Explorer
Expand Down

0 comments on commit 1b3a6e5

Please sign in to comment.