Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 5e01a2e

Browse files
[skip-changelog] legacy: refactor (part 3) (#2302)
* refactor RecipeRunner in a function * refactor CreateBuildOptionsMap in a function * refactor LoadPreviousBuildOptionsMap in a function * refactor StoreBuildOptionsMap in a function * refactor WipeoutBuildPathIfBuildOptionsChanged in a function * refactor ContainerBuildOptions in a function * refactor MergeSketchWithBootloader in a function * refactor PrintUsedLibrariesIfVerbose in a function * refactor UnusedCompiledLibrariesRemover in a function * refactor WarnAboutArchIncompatibleLibraries in a function * refactor CreateMakeRule in a function * move include finder with regex tests under detector * move jobs properites in arduino/builder component * remove sketch property from context * apply CR suggestion
1 parent 65915d8 commit 5e01a2e

27 files changed

+478
-406
lines changed

‎arduino/builder/builder.go‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ type Builder struct {
2626
sketch *sketch.Sketch
2727
buildProperties *properties.Map
2828

29+
// Parallel processes
30+
jobs int
31+
2932
// core related
3033
coreBuildCachePath *paths.Path
3134
}
@@ -37,6 +40,7 @@ func NewBuilder(
3740
buildPath *paths.Path,
3841
optimizeForDebug bool,
3942
coreBuildCachePath *paths.Path,
43+
jobs int,
4044
) *Builder {
4145
buildProperties := properties.NewMap()
4246
if boardBuildProperties != nil {
@@ -64,10 +68,16 @@ func NewBuilder(
6468
sketch: sk,
6569
buildProperties: buildProperties,
6670
coreBuildCachePath: coreBuildCachePath,
71+
jobs: jobs,
6772
}
6873
}
6974

7075
// GetBuildProperties returns the build properties for running this build
7176
func (b *Builder) GetBuildProperties() *properties.Map {
7277
return b.buildProperties
7378
}
79+
80+
// Jobs number of parallel processes
81+
func (b *Builder) Jobs() int {
82+
return b.jobs
83+
}

‎legacy/builder/test/includes_finder_with_regexp_test.go‎ renamed to ‎arduino/builder/detector/detector_test.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// Arduino software without disclosing the source code of your own applications.
1414
// To purchase a commercial license, send an email to license@arduino.cc.
1515

16-
package test
16+
package detector_test
1717

1818
import (
1919
"testing"

‎arduino/builder/sketch.go‎

Lines changed: 6 additions & 0 deletions
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).

‎arduino/builder/sketch_test.go‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func TestMergeSketchSources(t *testing.T) {
4848
}
4949
mergedSources := strings.ReplaceAll(string(mergedBytes), "%s", pathToGoldenSource)
5050

51-
b := NewBuilder(sk, nil, nil, false, nil)
51+
b := NewBuilder(sk, nil, nil, false, nil, 0)
5252
offset, source, err := b.sketchMergeSources(nil)
5353
require.Nil(t, err)
5454
require.Equal(t, 2, offset)
@@ -61,7 +61,7 @@ func TestMergeSketchSourcesArduinoIncluded(t *testing.T) {
6161
require.NotNil(t, sk)
6262

6363
// ensure not to include Arduino.h when it's already there
64-
b := NewBuilder(sk, nil, nil, false, nil)
64+
b := NewBuilder(sk, nil, nil, false, nil, 0)
6565
_, source, err := b.sketchMergeSources(nil)
6666
require.Nil(t, err)
6767
require.Equal(t, 1, strings.Count(source, "<Arduino.h>"))
@@ -76,7 +76,7 @@ func TestCopyAdditionalFiles(t *testing.T) {
7676
sk1, err := sketch.New(paths.New("testdata", t.Name()))
7777
require.Nil(t, err)
7878
require.Equal(t, sk1.AdditionalFiles.Len(), 1)
79-
b1 := NewBuilder(sk1, nil, nil, false, nil)
79+
b1 := NewBuilder(sk1, nil, nil, false, nil, 0)
8080

8181
// copy the sketch over, create a fake main file we don't care about it
8282
// but we need it for `SketchLoad` to succeed later

‎commands/compile/compile.go‎

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,14 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
169169
coreBuildCachePath = buildCachePath.Join("core")
170170
}
171171

172-
sketchBuilder := bldr.NewBuilder(sk, boardBuildProperties, buildPath, req.GetOptimizeForDebug(), coreBuildCachePath)
172+
sketchBuilder := bldr.NewBuilder(
173+
sk,
174+
boardBuildProperties,
175+
buildPath,
176+
req.GetOptimizeForDebug(),
177+
coreBuildCachePath,
178+
int(req.GetJobs()),
179+
)
173180

174181
buildProperties := sketchBuilder.GetBuildProperties()
175182

@@ -197,7 +204,6 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
197204
builderCtx.BuildProperties = buildProperties
198205
builderCtx.CustomBuildProperties = customBuildPropertiesArgs
199206
builderCtx.FQBN = fqbn
200-
builderCtx.Sketch = sk
201207
builderCtx.BuildPath = buildPath
202208
builderCtx.ProgressCB = progressCB
203209

@@ -212,7 +218,6 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
212218
)
213219

214220
builderCtx.Verbose = req.GetVerbose()
215-
builderCtx.Jobs = int(req.GetJobs())
216221

217222
builderCtx.WarningsLevel = req.GetWarnings()
218223
if builderCtx.WarningsLevel == "" {
@@ -243,7 +248,7 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
243248
builderCtx.LibrariesBuildPath = librariesBuildPath
244249
builderCtx.CoreBuildPath = coreBuildPath
245250

246-
if builderCtx.BuildPath.Canonical().EqualsTo(builderCtx.Sketch.FullPath.Canonical()) {
251+
if builderCtx.BuildPath.Canonical().EqualsTo(sk.FullPath.Canonical()) {
247252
return r, &arduino.CompileFailedError{
248253
Message: tr("Sketch cannot be located in build path. Please specify a different build path"),
249254
}
@@ -365,8 +370,13 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
365370
exportBinaries = false
366371
}
367372
if exportBinaries {
368-
presaveHex := builder.RecipeByPrefixSuffixRunner{Prefix: "recipe.hooks.savehex.presavehex", Suffix: ".pattern"}
369-
if err := presaveHex.Run(builderCtx); err != nil {
373+
err := builder.RecipeByPrefixSuffixRunner(
374+
"recipe.hooks.savehex.presavehex", ".pattern", false,
375+
builderCtx.OnlyUpdateCompilationDatabase, builderCtx.Verbose,
376+
builderCtx.BuildProperties, builderCtx.Stdout, builderCtx.Stderr,
377+
func(msg string) { builderCtx.Info(msg) },
378+
)
379+
if err != nil {
370380
return r, err
371381
}
372382

@@ -404,8 +414,13 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
404414
}
405415
}
406416

407-
postsaveHex := builder.RecipeByPrefixSuffixRunner{Prefix: "recipe.hooks.savehex.postsavehex", Suffix: ".pattern"}
408-
if err := postsaveHex.Run(builderCtx); err != nil {
417+
err = builder.RecipeByPrefixSuffixRunner(
418+
"recipe.hooks.savehex.postsavehex", ".pattern", false,
419+
builderCtx.OnlyUpdateCompilationDatabase, builderCtx.Verbose,
420+
builderCtx.BuildProperties, builderCtx.Stdout, builderCtx.Stderr,
421+
func(msg string) { builderCtx.Info(msg) },
422+
)
423+
if err != nil {
409424
return r, err
410425
}
411426
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /