Skip to content

Commit 82e1064

Browse files
refactor SketchBuilder in a function
1 parent 10aea3c commit 82e1064

File tree

2 files changed

+68
-36
lines changed

2 files changed

+68
-36
lines changed

Diff for: legacy/builder/builder.go

+22-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,28 @@ func (s *Builder) Run(ctx *types.Context) error {
6060

6161
logIfVerbose(false, tr("Compiling sketch...")),
6262
&RecipeByPrefixSuffixRunner{Prefix: "recipe.hooks.sketch.prebuild", Suffix: ".pattern"},
63-
&phases.SketchBuilder{},
63+
types.BareCommand(func(ctx *types.Context) error {
64+
sketchObjectFiles, err := phases.SketchBuilder(
65+
ctx.SketchBuildPath,
66+
ctx.BuildProperties,
67+
ctx.SketchLibrariesDetector.IncludeFolders(),
68+
ctx.OnlyUpdateCompilationDatabase,
69+
ctx.Verbose,
70+
ctx.CompilationDatabase,
71+
ctx.Jobs,
72+
ctx.WarningsLevel,
73+
ctx.Stdout, ctx.Stderr,
74+
func(msg string) { ctx.Info(msg) },
75+
func(data []byte) { ctx.WriteStdout(data) },
76+
func(data []byte) { ctx.WriteStderr(data) },
77+
&ctx.Progress, ctx.ProgressCB,
78+
)
79+
if err != nil {
80+
return err
81+
}
82+
ctx.SketchObjectFiles = sketchObjectFiles
83+
return nil
84+
}),
6485
&RecipeByPrefixSuffixRunner{Prefix: "recipe.hooks.sketch.postbuild", Suffix: ".pattern", SkipIfOnlyUpdatingCompilationDatabase: true},
6586

6687
logIfVerbose(false, tr("Compiling libraries...")),

Diff for: legacy/builder/phases/sketch_builder.go

+46-35
Original file line numberDiff line numberDiff line change
@@ -16,65 +16,76 @@
1616
package phases
1717

1818
import (
19+
"io"
20+
21+
"github.com/arduino/arduino-cli/arduino/builder"
1922
"github.com/arduino/arduino-cli/arduino/builder/cpp"
23+
"github.com/arduino/arduino-cli/arduino/builder/progress"
2024
"github.com/arduino/arduino-cli/arduino/builder/utils"
2125
f "github.com/arduino/arduino-cli/internal/algorithms"
22-
"github.com/arduino/arduino-cli/legacy/builder/types"
26+
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
27+
"github.com/arduino/go-paths-helper"
28+
"github.com/arduino/go-properties-orderedmap"
2329
"github.com/pkg/errors"
2430
)
2531

26-
type SketchBuilder struct{}
27-
28-
func (s *SketchBuilder) Run(ctx *types.Context) error {
29-
sketchBuildPath := ctx.SketchBuildPath
30-
buildProperties := ctx.BuildProperties
31-
includesFolders := ctx.SketchLibrariesDetector.IncludeFolders()
32+
func SketchBuilder(
33+
sketchBuildPath *paths.Path,
34+
buildProperties *properties.Map,
35+
includesFolders paths.PathList,
36+
onlyUpdateCompilationDatabase, verbose bool,
37+
compilationDatabase *builder.CompilationDatabase,
38+
jobs int,
39+
warningsLevel string,
40+
stdoutWriter, stderrWriter io.Writer,
41+
verboseInfoFn func(msg string),
42+
verboseStdoutFn, verboseStderrFn func(data []byte),
43+
progress *progress.Struct, progressCB rpc.TaskProgressCB,
44+
) (paths.PathList, error) {
3245
includes := f.Map(includesFolders.AsStrings(), cpp.WrapWithHyphenI)
3346

3447
if err := sketchBuildPath.MkdirAll(); err != nil {
35-
return errors.WithStack(err)
48+
return nil, errors.WithStack(err)
3649
}
3750

38-
objectFiles, err := utils.CompileFiles(
51+
sketchObjectFiles, err := utils.CompileFiles(
3952
sketchBuildPath, sketchBuildPath, buildProperties, includes,
40-
ctx.OnlyUpdateCompilationDatabase,
41-
ctx.CompilationDatabase,
42-
ctx.Jobs,
43-
ctx.Verbose,
44-
ctx.WarningsLevel,
45-
ctx.Stdout, ctx.Stderr,
46-
func(msg string) { ctx.Info(msg) },
47-
func(data []byte) { ctx.WriteStdout(data) },
48-
func(data []byte) { ctx.WriteStderr(data) },
49-
&ctx.Progress, ctx.ProgressCB,
53+
onlyUpdateCompilationDatabase,
54+
compilationDatabase,
55+
jobs,
56+
verbose,
57+
warningsLevel,
58+
stdoutWriter, stderrWriter,
59+
verboseInfoFn,
60+
verboseStdoutFn,
61+
verboseStderrFn,
62+
progress, progressCB,
5063
)
5164
if err != nil {
52-
return errors.WithStack(err)
65+
return nil, errors.WithStack(err)
5366
}
5467

5568
// The "src/" subdirectory of a sketch is compiled recursively
5669
sketchSrcPath := sketchBuildPath.Join("src")
5770
if sketchSrcPath.IsDir() {
5871
srcObjectFiles, err := utils.CompileFilesRecursive(
5972
sketchSrcPath, sketchSrcPath, buildProperties, includes,
60-
ctx.OnlyUpdateCompilationDatabase,
61-
ctx.CompilationDatabase,
62-
ctx.Jobs,
63-
ctx.Verbose,
64-
ctx.WarningsLevel,
65-
ctx.Stdout, ctx.Stderr,
66-
func(msg string) { ctx.Info(msg) },
67-
func(data []byte) { ctx.WriteStdout(data) },
68-
func(data []byte) { ctx.WriteStderr(data) },
69-
&ctx.Progress, ctx.ProgressCB,
73+
onlyUpdateCompilationDatabase,
74+
compilationDatabase,
75+
jobs,
76+
verbose,
77+
warningsLevel,
78+
stdoutWriter, stderrWriter,
79+
verboseInfoFn,
80+
verboseStdoutFn,
81+
verboseStderrFn,
82+
progress, progressCB,
7083
)
7184
if err != nil {
72-
return errors.WithStack(err)
85+
return nil, errors.WithStack(err)
7386
}
74-
objectFiles.AddAll(srcObjectFiles)
87+
sketchObjectFiles.AddAll(srcObjectFiles)
7588
}
7689

77-
ctx.SketchObjectFiles = objectFiles
78-
79-
return nil
90+
return sketchObjectFiles, nil
8091
}

0 commit comments

Comments
 (0)