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

legacy: Builder refactorization (part 3...) #2302

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
alessio-perugini merged 15 commits into master from refactor_legacy_part3
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
6834568
refactor RecipeRunner in a function
alessio-perugini Sep 8, 2023
4ec72f6
refactor CreateBuildOptionsMap in a function
alessio-perugini Sep 8, 2023
1a20cf5
refactor LoadPreviousBuildOptionsMap in a function
alessio-perugini Sep 8, 2023
8512ca3
refactor StoreBuildOptionsMap in a function
alessio-perugini Sep 8, 2023
6321095
refactor WipeoutBuildPathIfBuildOptionsChanged in a function
alessio-perugini Sep 8, 2023
7fc0034
refactor ContainerBuildOptions in a function
alessio-perugini Sep 8, 2023
fc9d011
refactor MergeSketchWithBootloader in a function
alessio-perugini Sep 8, 2023
8d6c6d3
refactor PrintUsedLibrariesIfVerbose in a function
alessio-perugini Sep 8, 2023
cc6f676
refactor UnusedCompiledLibrariesRemover in a function
alessio-perugini Sep 8, 2023
ba0852c
refactor WarnAboutArchIncompatibleLibraries in a function
alessio-perugini Sep 8, 2023
90e539b
refactor CreateMakeRule in a function
alessio-perugini Sep 8, 2023
dd0eea0
move include finder with regex tests under detector
alessio-perugini Sep 11, 2023
326ee92
move jobs properites in arduino/builder component
alessio-perugini Sep 11, 2023
227dbd1
remove sketch property from context
alessio-perugini Sep 11, 2023
a38853b
apply CR suggestion
alessio-perugini Sep 11, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions arduino/builder/builder.go
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ type Builder struct {
sketch *sketch.Sketch
buildProperties *properties.Map

// Parallel processes
jobs int

// core related
coreBuildCachePath *paths.Path
}
Expand All @@ -37,6 +40,7 @@ func NewBuilder(
buildPath *paths.Path,
optimizeForDebug bool,
coreBuildCachePath *paths.Path,
jobs int,
) *Builder {
buildProperties := properties.NewMap()
if boardBuildProperties != nil {
Expand Down Expand Up @@ -64,10 +68,16 @@ func NewBuilder(
sketch: sk,
buildProperties: buildProperties,
coreBuildCachePath: coreBuildCachePath,
jobs: jobs,
}
}

// GetBuildProperties returns the build properties for running this build
func (b *Builder) GetBuildProperties() *properties.Map {
return b.buildProperties
}

// Jobs number of parallel processes
func (b *Builder) Jobs() int {
return b.jobs
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// Arduino software without disclosing the source code of your own applications.
// To purchase a commercial license, send an email to license@arduino.cc.

package test
package detector_test

import (
"testing"
Expand Down
6 changes: 6 additions & 0 deletions arduino/builder/sketch.go
View file Open in desktop
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
6 changes: 3 additions & 3 deletions arduino/builder/sketch_test.go
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func TestMergeSketchSources(t *testing.T) {
}
mergedSources := strings.ReplaceAll(string(mergedBytes), "%s", pathToGoldenSource)

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

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

// copy the sketch over, create a fake main file we don't care about it
// but we need it for `SketchLoad` to succeed later
Expand Down
31 changes: 23 additions & 8 deletions commands/compile/compile.go
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,14 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
coreBuildCachePath = buildCachePath.Join("core")
}

sketchBuilder := bldr.NewBuilder(sk, boardBuildProperties, buildPath, req.GetOptimizeForDebug(), coreBuildCachePath)
sketchBuilder := bldr.NewBuilder(
sk,
boardBuildProperties,
buildPath,
req.GetOptimizeForDebug(),
coreBuildCachePath,
int(req.GetJobs()),
)

buildProperties := sketchBuilder.GetBuildProperties()

Expand Down Expand Up @@ -197,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 All @@ -212,7 +218,6 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
)

builderCtx.Verbose = req.GetVerbose()
builderCtx.Jobs = int(req.GetJobs())

builderCtx.WarningsLevel = req.GetWarnings()
if builderCtx.WarningsLevel == "" {
Expand Down Expand Up @@ -243,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 Expand Up @@ -365,8 +370,13 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
exportBinaries = false
}
if exportBinaries {
presaveHex := builder.RecipeByPrefixSuffixRunner{Prefix: "recipe.hooks.savehex.presavehex", Suffix: ".pattern"}
if err := presaveHex.Run(builderCtx); err != nil {
err := builder.RecipeByPrefixSuffixRunner(
"recipe.hooks.savehex.presavehex", ".pattern", false,
builderCtx.OnlyUpdateCompilationDatabase, builderCtx.Verbose,
builderCtx.BuildProperties, builderCtx.Stdout, builderCtx.Stderr,
func(msg string) { builderCtx.Info(msg) },
)
if err != nil {
return r, err
}

Expand Down Expand Up @@ -404,8 +414,13 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
}
}

postsaveHex := builder.RecipeByPrefixSuffixRunner{Prefix: "recipe.hooks.savehex.postsavehex", Suffix: ".pattern"}
if err := postsaveHex.Run(builderCtx); err != nil {
err = builder.RecipeByPrefixSuffixRunner(
"recipe.hooks.savehex.postsavehex", ".pattern", false,
builderCtx.OnlyUpdateCompilationDatabase, builderCtx.Verbose,
builderCtx.BuildProperties, builderCtx.Stdout, builderCtx.Stderr,
func(msg string) { builderCtx.Info(msg) },
)
if err != nil {
return r, err
}
}
Expand Down
Loading

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