Skip to content

Commit 227dbd1

Browse files
remove sketch property from context
1 parent 326ee92 commit 227dbd1

File tree

8 files changed

+26
-24
lines changed

8 files changed

+26
-24
lines changed

Diff for: arduino/builder/sketch.go

+6
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"regexp"
2222

2323
"github.com/arduino/arduino-cli/arduino/builder/cpp"
24+
"github.com/arduino/arduino-cli/arduino/sketch"
2425
"github.com/arduino/arduino-cli/i18n"
2526
"github.com/arduino/go-paths-helper"
2627

@@ -32,6 +33,11 @@ var (
3233
tr = i18n.Tr
3334
)
3435

36+
// Sketch fixdoc
37+
func (b *Builder) Sketch() *sketch.Sketch {
38+
return b.sketch
39+
}
40+
3541
// PrepareSketchBuildPath copies the sketch source files in the build path.
3642
// The .ino files are merged together to create a .cpp file (by the way, the
3743
// .cpp file still needs to be Arduino-preprocessed to compile).

Diff for: commands/compile/compile.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,6 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
204204
builderCtx.BuildProperties = buildProperties
205205
builderCtx.CustomBuildProperties = customBuildPropertiesArgs
206206
builderCtx.FQBN = fqbn
207-
builderCtx.Sketch = sk
208207
builderCtx.BuildPath = buildPath
209208
builderCtx.ProgressCB = progressCB
210209

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

252-
if builderCtx.BuildPath.Canonical().EqualsTo(builderCtx.Sketch.FullPath.Canonical()) {
251+
if builderCtx.BuildPath.Canonical().EqualsTo(sk.FullPath.Canonical()) {
253252
return r, &arduino.CompileFailedError{
254253
Message: tr("Sketch cannot be located in build path. Please specify a different build path"),
255254
}

Diff for: legacy/builder/builder.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ func (s *Builder) Run(ctx *types.Context) error {
210210
types.BareCommand(func(ctx *types.Context) error {
211211
return MergeSketchWithBootloader(
212212
ctx.OnlyUpdateCompilationDatabase, ctx.Verbose,
213-
ctx.BuildPath, ctx.Sketch, ctx.BuildProperties,
213+
ctx.BuildPath, ctx.Builder.Sketch(), ctx.BuildProperties,
214214
func(s string) { ctx.Info(s) },
215215
func(s string) { ctx.Warn(s) },
216216
)
@@ -258,7 +258,7 @@ func (s *Builder) Run(ctx *types.Context) error {
258258
ctx.BuildPath, ctx.SketchBuildPath,
259259
ctx.SketchLibrariesDetector.ImportedLibraries(),
260260
ctx.BuildProperties,
261-
ctx.Sketch,
261+
ctx.Builder.Sketch(),
262262
ctx.SketchLibrariesDetector.IncludeFolders(),
263263
ctx.LineOffset,
264264
ctx.OnlyUpdateCompilationDatabase,
@@ -305,7 +305,7 @@ func (s *Builder) Run(ctx *types.Context) error {
305305
func preprocessSketchCommand(ctx *types.Context) types.BareCommand {
306306
return func(ctx *types.Context) error {
307307
normalOutput, verboseOutput, err := PreprocessSketch(
308-
ctx.Sketch, ctx.BuildPath, ctx.SketchLibrariesDetector.IncludeFolders(), ctx.LineOffset,
308+
ctx.Builder.Sketch(), ctx.BuildPath, ctx.SketchLibrariesDetector.IncludeFolders(), ctx.LineOffset,
309309
ctx.BuildProperties, ctx.OnlyUpdateCompilationDatabase)
310310
if ctx.Verbose {
311311
ctx.WriteStdout(verboseOutput)
@@ -357,7 +357,7 @@ func (s *Preprocess) Run(ctx *types.Context) error {
357357
}
358358

359359
// Output arduino-preprocessed source
360-
preprocessedSketch, err := ctx.SketchBuildPath.Join(ctx.Sketch.MainFile.Base() + ".cpp").ReadFile()
360+
preprocessedSketch, err := ctx.SketchBuildPath.Join(ctx.Builder.Sketch().MainFile.Base() + ".cpp").ReadFile()
361361
if err != nil {
362362
return err
363363
}
@@ -401,7 +401,7 @@ func findIncludes(ctx *types.Context) types.BareCommand {
401401
ctx.BuildProperties.GetPath("build.core.path"),
402402
ctx.BuildProperties.GetPath("build.variant.path"),
403403
ctx.SketchBuildPath,
404-
ctx.Sketch,
404+
ctx.Builder.Sketch(),
405405
ctx.LibrariesBuildPath,
406406
ctx.BuildProperties,
407407
ctx.TargetPlatform.Platform.Architecture,
@@ -438,7 +438,7 @@ func containerBuildOptions(ctx *types.Context) types.BareCommand {
438438
// ctx.BuildProperties
439439
buildOptionsJSON, buildOptionsJSONPrevious, infoMessage, err := ContainerBuildOptions(
440440
ctx.HardwareDirs, ctx.BuiltInToolsDirs, ctx.OtherLibrariesDirs,
441-
ctx.BuiltInLibrariesDirs, ctx.BuildPath, ctx.Sketch, ctx.CustomBuildProperties,
441+
ctx.BuiltInLibrariesDirs, ctx.BuildPath, ctx.Builder.Sketch(), ctx.CustomBuildProperties,
442442
ctx.FQBN.String(), ctx.Clean, ctx.BuildProperties,
443443
)
444444
if infoMessage != "" {

Diff for: legacy/builder/test/builder_test.go

+7-6
Original file line numberDiff line numberDiff line change
@@ -91,21 +91,22 @@ func prepareBuilderTestContext(t *testing.T, ctx *types.Context, sketchPath *pat
9191
pme, _ /* never release... */ := pm.NewExplorer()
9292
ctx.PackageManager = pme
9393

94+
var sk *sketch.Sketch
9495
if sketchPath != nil {
95-
sk, err := sketch.New(sketchPath)
96+
s, err := sketch.New(sketchPath)
9697
require.NoError(t, err)
97-
ctx.Sketch = sk
98+
sk = s
9899
}
99100

100-
ctx.Builder = bldr.NewBuilder(ctx.Sketch, nil, nil, false, nil, 0)
101+
ctx.Builder = bldr.NewBuilder(sk, nil, nil, false, nil, 0)
101102
if fqbn != "" {
102103
ctx.FQBN = parseFQBN(t, fqbn)
103104
targetPackage, targetPlatform, targetBoard, boardBuildProperties, buildPlatform, err := pme.ResolveFQBN(ctx.FQBN)
104105
require.NoError(t, err)
105106
requiredTools, err := pme.FindToolsRequiredForBuild(targetPlatform, buildPlatform)
106107
require.NoError(t, err)
107108

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

118-
if ctx.Sketch != nil {
119-
require.False(t, ctx.BuildPath.Canonical().EqualsTo(ctx.Sketch.FullPath.Canonical()))
119+
if sk != nil {
120+
require.False(t, ctx.BuildPath.Canonical().EqualsTo(sk.FullPath.Canonical()))
120121
}
121122

122123
if !stepToSkip[skipLibraries] {

Diff for: legacy/builder/test/create_build_options_map_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ func TestCreateBuildOptionsMap(t *testing.T) {
3131
HardwareDirs: paths.NewPathList("hardware", "hardware2"),
3232
BuiltInToolsDirs: paths.NewPathList("tools"),
3333
OtherLibrariesDirs: paths.NewPathList("libraries"),
34-
Sketch: &sketch.Sketch{FullPath: paths.New("sketchLocation")},
3534
FQBN: parseFQBN(t, "my:nice:fqbn"),
3635
Verbose: true,
3736
BuildPath: paths.New("buildPath"),
@@ -40,7 +39,7 @@ func TestCreateBuildOptionsMap(t *testing.T) {
4039

4140
buildPropertiesJSON, err := builder.CreateBuildOptionsMap(
4241
ctx.HardwareDirs, ctx.BuiltInToolsDirs, ctx.OtherLibrariesDirs,
43-
ctx.BuiltInLibrariesDirs, ctx.Sketch, ctx.CustomBuildProperties,
42+
ctx.BuiltInLibrariesDirs, &sketch.Sketch{FullPath: paths.New("sketchLocation")}, ctx.CustomBuildProperties,
4443
ctx.FQBN.String(), ctx.BuildProperties.Get("compiler.optimization_flags"),
4544
)
4645
require.NoError(t, err)

Diff for: legacy/builder/test/merge_sketch_with_bootloader_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func TestMergeSketchWithBootloader(t *testing.T) {
7171

7272
err = builder.MergeSketchWithBootloader(
7373
ctx.OnlyUpdateCompilationDatabase, ctx.Verbose,
74-
ctx.BuildPath, ctx.Sketch, ctx.BuildProperties,
74+
ctx.BuildPath, ctx.Builder.Sketch(), ctx.BuildProperties,
7575
func(s string) { ctx.Info(s) },
7676
func(s string) { ctx.Warn(s) },
7777
)
@@ -128,7 +128,7 @@ func TestMergeSketchWithBootloaderSketchInBuildPath(t *testing.T) {
128128

129129
err = builder.MergeSketchWithBootloader(
130130
ctx.OnlyUpdateCompilationDatabase, ctx.Verbose,
131-
ctx.BuildPath, ctx.Sketch, ctx.BuildProperties,
131+
ctx.BuildPath, ctx.Builder.Sketch(), ctx.BuildProperties,
132132
func(s string) { ctx.Info(s) },
133133
func(s string) { ctx.Warn(s) },
134134
)
@@ -154,7 +154,7 @@ func TestMergeSketchWithBootloaderWhenNoBootloaderAvailable(t *testing.T) {
154154

155155
err := builder.MergeSketchWithBootloader(
156156
ctx.OnlyUpdateCompilationDatabase, ctx.Verbose,
157-
ctx.BuildPath, ctx.Sketch, ctx.BuildProperties,
157+
ctx.BuildPath, ctx.Builder.Sketch(), ctx.BuildProperties,
158158
func(s string) { ctx.Info(s) },
159159
func(s string) { ctx.Warn(s) },
160160
)
@@ -214,7 +214,7 @@ func TestMergeSketchWithBootloaderPathIsParameterized(t *testing.T) {
214214

215215
err = builder.MergeSketchWithBootloader(
216216
ctx.OnlyUpdateCompilationDatabase, ctx.Verbose,
217-
ctx.BuildPath, ctx.Sketch, ctx.BuildProperties,
217+
ctx.BuildPath, ctx.Builder.Sketch(), ctx.BuildProperties,
218218
func(s string) { ctx.Info(s) },
219219
func(s string) { ctx.Warn(s) },
220220
)

Diff for: legacy/builder/test/store_build_options_map_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ func TestStoreBuildOptionsMap(t *testing.T) {
3333
BuiltInToolsDirs: paths.NewPathList("tools"),
3434
BuiltInLibrariesDirs: paths.New("built-in libraries"),
3535
OtherLibrariesDirs: paths.NewPathList("libraries"),
36-
Sketch: &sketch.Sketch{FullPath: paths.New("sketchLocation")},
3736
FQBN: parseFQBN(t, "my:nice:fqbn"),
3837
CustomBuildProperties: []string{"custom=prop"},
3938
Verbose: true,
@@ -45,7 +44,7 @@ func TestStoreBuildOptionsMap(t *testing.T) {
4544

4645
buildPropertiesJSON, err := builder.CreateBuildOptionsMap(
4746
ctx.HardwareDirs, ctx.BuiltInToolsDirs, ctx.OtherLibrariesDirs,
48-
ctx.BuiltInLibrariesDirs, ctx.Sketch, ctx.CustomBuildProperties,
47+
ctx.BuiltInLibrariesDirs, &sketch.Sketch{FullPath: paths.New("sketchLocation")}, ctx.CustomBuildProperties,
4948
ctx.FQBN.String(), ctx.BuildProperties.Get("compiler.optimization_flags"),
5049
)
5150
require.NoError(t, err)

Diff for: legacy/builder/types/context.go

-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import (
2626
"github.com/arduino/arduino-cli/arduino/builder/progress"
2727
"github.com/arduino/arduino-cli/arduino/cores"
2828
"github.com/arduino/arduino-cli/arduino/cores/packagemanager"
29-
"github.com/arduino/arduino-cli/arduino/sketch"
3029
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
3130
paths "github.com/arduino/go-paths-helper"
3231
properties "github.com/arduino/go-properties-orderedmap"
@@ -66,7 +65,6 @@ type Context struct {
6665
LibrariesObjectFiles paths.PathList
6766
SketchObjectFiles paths.PathList
6867

69-
Sketch *sketch.Sketch
7068
WarningsLevel string
7169

7270
// C++ Parsing

0 commit comments

Comments
 (0)