diff --git a/arduino/builder/sketch.go b/arduino/builder/sketch.go index 43a5e635237..f8eff7caafa 100644 --- a/arduino/builder/sketch.go +++ b/arduino/builder/sketch.go @@ -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" @@ -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). diff --git a/commands/compile/compile.go b/commands/compile/compile.go index 1a58a5c0d99..f04a239a870 100644 --- a/commands/compile/compile.go +++ b/commands/compile/compile.go @@ -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 @@ -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"), } diff --git a/legacy/builder/builder.go b/legacy/builder/builder.go index ced469f40cb..500575374e3 100644 --- a/legacy/builder/builder.go +++ b/legacy/builder/builder.go @@ -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) }, ) @@ -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, @@ -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) @@ -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 } @@ -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, @@ -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 != "" { diff --git a/legacy/builder/test/builder_test.go b/legacy/builder/test/builder_test.go index a70cb85dc2e..4ec13627315 100644 --- a/legacy/builder/test/builder_test.go +++ b/legacy/builder/test/builder_test.go @@ -91,13 +91,14 @@ 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) @@ -105,7 +106,7 @@ func prepareBuilderTestContext(t *testing.T, ctx *types.Context, sketchPath *pat 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() @@ -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] { diff --git a/legacy/builder/test/create_build_options_map_test.go b/legacy/builder/test/create_build_options_map_test.go index 8cfc8c8cd29..b2d90ffa253 100644 --- a/legacy/builder/test/create_build_options_map_test.go +++ b/legacy/builder/test/create_build_options_map_test.go @@ -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"), @@ -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) diff --git a/legacy/builder/test/merge_sketch_with_bootloader_test.go b/legacy/builder/test/merge_sketch_with_bootloader_test.go index 3dbf1f086ef..6305a174928 100644 --- a/legacy/builder/test/merge_sketch_with_bootloader_test.go +++ b/legacy/builder/test/merge_sketch_with_bootloader_test.go @@ -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) }, ) @@ -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) }, ) @@ -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) }, ) @@ -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) }, ) diff --git a/legacy/builder/test/store_build_options_map_test.go b/legacy/builder/test/store_build_options_map_test.go index 7c171c588ec..a532ac5007a 100644 --- a/legacy/builder/test/store_build_options_map_test.go +++ b/legacy/builder/test/store_build_options_map_test.go @@ -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, @@ -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) diff --git a/legacy/builder/types/context.go b/legacy/builder/types/context.go index d17bea4d8ca..6d7ac15952f 100644 --- a/legacy/builder/types/context.go +++ b/legacy/builder/types/context.go @@ -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" @@ -66,7 +65,6 @@ type Context struct { LibrariesObjectFiles paths.PathList SketchObjectFiles paths.PathList - Sketch *sketch.Sketch WarningsLevel string // C++ Parsing