Skip to content

Commit

Permalink
remove sketch property from context
Browse files Browse the repository at this point in the history
  • Loading branch information
alessio-perugini committed Sep 11, 2023
1 parent 326ee92 commit 227dbd1
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 24 deletions.
6 changes: 6 additions & 0 deletions arduino/builder/sketch.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ 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"

Expand All @@ -32,6 +33,11 @@ var (
tr = i18n.Tr
)

// Sketch fixdoc
func (b *Builder) Sketch() *sketch.Sketch {
return b.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).
Expand Down
3 changes: 1 addition & 2 deletions commands/compile/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,6 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
builderCtx.BuildProperties = buildProperties
builderCtx.CustomBuildProperties = customBuildPropertiesArgs
builderCtx.FQBN = fqbn
builderCtx.Sketch = sk
builderCtx.BuildPath = buildPath
builderCtx.ProgressCB = progressCB

Expand Down Expand Up @@ -249,7 +248,7 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
builderCtx.LibrariesBuildPath = librariesBuildPath
builderCtx.CoreBuildPath = coreBuildPath

if builderCtx.BuildPath.Canonical().EqualsTo(builderCtx.Sketch.FullPath.Canonical()) {
if builderCtx.BuildPath.Canonical().EqualsTo(sk.FullPath.Canonical()) {
return r, &arduino.CompileFailedError{
Message: tr("Sketch cannot be located in build path. Please specify a different build path"),
}
Expand Down
12 changes: 6 additions & 6 deletions legacy/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ func (s *Builder) Run(ctx *types.Context) error {
types.BareCommand(func(ctx *types.Context) error {
return MergeSketchWithBootloader(
ctx.OnlyUpdateCompilationDatabase, ctx.Verbose,
ctx.BuildPath, ctx.Sketch, ctx.BuildProperties,
ctx.BuildPath, ctx.Builder.Sketch(), ctx.BuildProperties,
func(s string) { ctx.Info(s) },
func(s string) { ctx.Warn(s) },
)
Expand Down Expand Up @@ -258,7 +258,7 @@ func (s *Builder) Run(ctx *types.Context) error {
ctx.BuildPath, ctx.SketchBuildPath,
ctx.SketchLibrariesDetector.ImportedLibraries(),
ctx.BuildProperties,
ctx.Sketch,
ctx.Builder.Sketch(),
ctx.SketchLibrariesDetector.IncludeFolders(),
ctx.LineOffset,
ctx.OnlyUpdateCompilationDatabase,
Expand Down Expand Up @@ -305,7 +305,7 @@ func (s *Builder) Run(ctx *types.Context) error {
func preprocessSketchCommand(ctx *types.Context) types.BareCommand {
return func(ctx *types.Context) error {
normalOutput, verboseOutput, err := PreprocessSketch(
ctx.Sketch, ctx.BuildPath, ctx.SketchLibrariesDetector.IncludeFolders(), ctx.LineOffset,
ctx.Builder.Sketch(), ctx.BuildPath, ctx.SketchLibrariesDetector.IncludeFolders(), ctx.LineOffset,
ctx.BuildProperties, ctx.OnlyUpdateCompilationDatabase)
if ctx.Verbose {
ctx.WriteStdout(verboseOutput)
Expand Down Expand Up @@ -357,7 +357,7 @@ func (s *Preprocess) Run(ctx *types.Context) error {
}

// Output arduino-preprocessed source
preprocessedSketch, err := ctx.SketchBuildPath.Join(ctx.Sketch.MainFile.Base() + ".cpp").ReadFile()
preprocessedSketch, err := ctx.SketchBuildPath.Join(ctx.Builder.Sketch().MainFile.Base() + ".cpp").ReadFile()
if err != nil {
return err
}
Expand Down Expand Up @@ -401,7 +401,7 @@ func findIncludes(ctx *types.Context) types.BareCommand {
ctx.BuildProperties.GetPath("build.core.path"),
ctx.BuildProperties.GetPath("build.variant.path"),
ctx.SketchBuildPath,
ctx.Sketch,
ctx.Builder.Sketch(),
ctx.LibrariesBuildPath,
ctx.BuildProperties,
ctx.TargetPlatform.Platform.Architecture,
Expand Down Expand Up @@ -438,7 +438,7 @@ func containerBuildOptions(ctx *types.Context) types.BareCommand {
// ctx.BuildProperties
buildOptionsJSON, buildOptionsJSONPrevious, infoMessage, err := ContainerBuildOptions(
ctx.HardwareDirs, ctx.BuiltInToolsDirs, ctx.OtherLibrariesDirs,
ctx.BuiltInLibrariesDirs, ctx.BuildPath, ctx.Sketch, ctx.CustomBuildProperties,
ctx.BuiltInLibrariesDirs, ctx.BuildPath, ctx.Builder.Sketch(), ctx.CustomBuildProperties,
ctx.FQBN.String(), ctx.Clean, ctx.BuildProperties,
)
if infoMessage != "" {
Expand Down
13 changes: 7 additions & 6 deletions legacy/builder/test/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,21 +91,22 @@ func prepareBuilderTestContext(t *testing.T, ctx *types.Context, sketchPath *pat
pme, _ /* never release... */ := pm.NewExplorer()
ctx.PackageManager = pme

var sk *sketch.Sketch
if sketchPath != nil {
sk, err := sketch.New(sketchPath)
s, err := sketch.New(sketchPath)
require.NoError(t, err)
ctx.Sketch = sk
sk = s
}

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

ctx.Builder = bldr.NewBuilder(ctx.Sketch, boardBuildProperties, ctx.BuildPath, false /*OptimizeForDebug*/, nil, 0)
ctx.Builder = bldr.NewBuilder(sk, boardBuildProperties, ctx.BuildPath, false /*OptimizeForDebug*/, nil, 0)
ctx.PackageManager = pme
ctx.TargetBoard = targetBoard
ctx.BuildProperties = ctx.Builder.GetBuildProperties()
Expand All @@ -115,8 +116,8 @@ func prepareBuilderTestContext(t *testing.T, ctx *types.Context, sketchPath *pat
ctx.RequiredTools = requiredTools
}

if ctx.Sketch != nil {
require.False(t, ctx.BuildPath.Canonical().EqualsTo(ctx.Sketch.FullPath.Canonical()))
if sk != nil {
require.False(t, ctx.BuildPath.Canonical().EqualsTo(sk.FullPath.Canonical()))
}

if !stepToSkip[skipLibraries] {
Expand Down
3 changes: 1 addition & 2 deletions legacy/builder/test/create_build_options_map_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ func TestCreateBuildOptionsMap(t *testing.T) {
HardwareDirs: paths.NewPathList("hardware", "hardware2"),
BuiltInToolsDirs: paths.NewPathList("tools"),
OtherLibrariesDirs: paths.NewPathList("libraries"),
Sketch: &sketch.Sketch{FullPath: paths.New("sketchLocation")},
FQBN: parseFQBN(t, "my:nice:fqbn"),
Verbose: true,
BuildPath: paths.New("buildPath"),
Expand All @@ -40,7 +39,7 @@ func TestCreateBuildOptionsMap(t *testing.T) {

buildPropertiesJSON, err := builder.CreateBuildOptionsMap(
ctx.HardwareDirs, ctx.BuiltInToolsDirs, ctx.OtherLibrariesDirs,
ctx.BuiltInLibrariesDirs, ctx.Sketch, ctx.CustomBuildProperties,
ctx.BuiltInLibrariesDirs, &sketch.Sketch{FullPath: paths.New("sketchLocation")}, ctx.CustomBuildProperties,
ctx.FQBN.String(), ctx.BuildProperties.Get("compiler.optimization_flags"),
)
require.NoError(t, err)
Expand Down
8 changes: 4 additions & 4 deletions legacy/builder/test/merge_sketch_with_bootloader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func TestMergeSketchWithBootloader(t *testing.T) {

err = builder.MergeSketchWithBootloader(
ctx.OnlyUpdateCompilationDatabase, ctx.Verbose,
ctx.BuildPath, ctx.Sketch, ctx.BuildProperties,
ctx.BuildPath, ctx.Builder.Sketch(), ctx.BuildProperties,
func(s string) { ctx.Info(s) },
func(s string) { ctx.Warn(s) },
)
Expand Down Expand Up @@ -128,7 +128,7 @@ func TestMergeSketchWithBootloaderSketchInBuildPath(t *testing.T) {

err = builder.MergeSketchWithBootloader(
ctx.OnlyUpdateCompilationDatabase, ctx.Verbose,
ctx.BuildPath, ctx.Sketch, ctx.BuildProperties,
ctx.BuildPath, ctx.Builder.Sketch(), ctx.BuildProperties,
func(s string) { ctx.Info(s) },
func(s string) { ctx.Warn(s) },
)
Expand All @@ -154,7 +154,7 @@ func TestMergeSketchWithBootloaderWhenNoBootloaderAvailable(t *testing.T) {

err := builder.MergeSketchWithBootloader(
ctx.OnlyUpdateCompilationDatabase, ctx.Verbose,
ctx.BuildPath, ctx.Sketch, ctx.BuildProperties,
ctx.BuildPath, ctx.Builder.Sketch(), ctx.BuildProperties,
func(s string) { ctx.Info(s) },
func(s string) { ctx.Warn(s) },
)
Expand Down Expand Up @@ -214,7 +214,7 @@ func TestMergeSketchWithBootloaderPathIsParameterized(t *testing.T) {

err = builder.MergeSketchWithBootloader(
ctx.OnlyUpdateCompilationDatabase, ctx.Verbose,
ctx.BuildPath, ctx.Sketch, ctx.BuildProperties,
ctx.BuildPath, ctx.Builder.Sketch(), ctx.BuildProperties,
func(s string) { ctx.Info(s) },
func(s string) { ctx.Warn(s) },
)
Expand Down
3 changes: 1 addition & 2 deletions legacy/builder/test/store_build_options_map_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ func TestStoreBuildOptionsMap(t *testing.T) {
BuiltInToolsDirs: paths.NewPathList("tools"),
BuiltInLibrariesDirs: paths.New("built-in libraries"),
OtherLibrariesDirs: paths.NewPathList("libraries"),
Sketch: &sketch.Sketch{FullPath: paths.New("sketchLocation")},
FQBN: parseFQBN(t, "my:nice:fqbn"),
CustomBuildProperties: []string{"custom=prop"},
Verbose: true,
Expand All @@ -45,7 +44,7 @@ func TestStoreBuildOptionsMap(t *testing.T) {

buildPropertiesJSON, err := builder.CreateBuildOptionsMap(
ctx.HardwareDirs, ctx.BuiltInToolsDirs, ctx.OtherLibrariesDirs,
ctx.BuiltInLibrariesDirs, ctx.Sketch, ctx.CustomBuildProperties,
ctx.BuiltInLibrariesDirs, &sketch.Sketch{FullPath: paths.New("sketchLocation")}, ctx.CustomBuildProperties,
ctx.FQBN.String(), ctx.BuildProperties.Get("compiler.optimization_flags"),
)
require.NoError(t, err)
Expand Down
2 changes: 0 additions & 2 deletions legacy/builder/types/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"github.com/arduino/arduino-cli/arduino/builder/progress"
"github.com/arduino/arduino-cli/arduino/cores"
"github.com/arduino/arduino-cli/arduino/cores/packagemanager"
"github.com/arduino/arduino-cli/arduino/sketch"
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
paths "github.com/arduino/go-paths-helper"
properties "github.com/arduino/go-properties-orderedmap"
Expand Down Expand Up @@ -66,7 +65,6 @@ type Context struct {
LibrariesObjectFiles paths.PathList
SketchObjectFiles paths.PathList

Sketch *sketch.Sketch
WarningsLevel string

// C++ Parsing
Expand Down

0 comments on commit 227dbd1

Please sign in to comment.