Skip to content

Commit ba0852c

Browse files
refactor WarnAboutArchIncompatibleLibraries in a function
1 parent cc6f676 commit ba0852c

File tree

2 files changed

+26
-13
lines changed

2 files changed

+26
-13
lines changed

legacy/builder/builder.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func (s *Builder) Run(ctx *types.Context) error {
5555
logIfVerbose(false, tr("Detecting libraries used...")),
5656
findIncludes(ctx),
5757

58-
&WarnAboutArchIncompatibleLibraries{},
58+
warnAboutArchIncompatibleLibraries(ctx),
5959

6060
logIfVerbose(false, tr("Generating function prototypes...")),
6161
types.BareCommand(PreprocessSketch),
@@ -317,7 +317,7 @@ func (s *Preprocess) Run(ctx *types.Context) error {
317317

318318
findIncludes(ctx),
319319

320-
&WarnAboutArchIncompatibleLibraries{},
320+
warnAboutArchIncompatibleLibraries(ctx),
321321

322322
types.BareCommand(PreprocessSketch),
323323
}
@@ -424,3 +424,16 @@ func containerBuildOptions(ctx *types.Context) types.BareCommand {
424424
return nil
425425
})
426426
}
427+
428+
func warnAboutArchIncompatibleLibraries(ctx *types.Context) types.BareCommand {
429+
return types.BareCommand(func(ctx *types.Context) error {
430+
overrides, _ := ctx.BuildProperties.GetOk("architecture.override_check")
431+
_ = WarnAboutArchIncompatibleLibraries(
432+
ctx.TargetPlatform,
433+
overrides,
434+
ctx.SketchLibrariesDetector.ImportedLibraries(),
435+
func(s string) { ctx.Info(s) },
436+
)
437+
return nil
438+
})
439+
}

legacy/builder/warn_about_arch_incompatible_libraries.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,24 @@ package builder
1818
import (
1919
"strings"
2020

21-
"github.com/arduino/arduino-cli/legacy/builder/constants"
22-
"github.com/arduino/arduino-cli/legacy/builder/types"
21+
"github.com/arduino/arduino-cli/arduino/cores"
22+
"github.com/arduino/arduino-cli/arduino/libraries"
2323
)
2424

25-
type WarnAboutArchIncompatibleLibraries struct{}
26-
27-
func (s *WarnAboutArchIncompatibleLibraries) Run(ctx *types.Context) error {
28-
targetPlatform := ctx.TargetPlatform
29-
buildProperties := ctx.BuildProperties
30-
25+
func WarnAboutArchIncompatibleLibraries(
26+
targetPlatform *cores.PlatformRelease,
27+
overrides string,
28+
importedLibraries libraries.List,
29+
printInfoFn func(string),
30+
) error {
3131
archs := []string{targetPlatform.Platform.Architecture}
32-
if overrides, ok := buildProperties.GetOk(constants.BUILD_PROPERTIES_ARCH_OVERRIDE_CHECK); ok {
32+
if overrides != "" {
3333
archs = append(archs, strings.Split(overrides, ",")...)
3434
}
3535

36-
for _, importedLibrary := range ctx.SketchLibrariesDetector.ImportedLibraries() {
36+
for _, importedLibrary := range importedLibraries {
3737
if !importedLibrary.SupportsAnyArchitectureIn(archs...) {
38-
ctx.Info(
38+
printInfoFn(
3939
tr("WARNING: library %[1]s claims to run on %[2]s architecture(s) and may be incompatible with your current board which runs on %[3]s architecture(s).",
4040
importedLibrary.Name,
4141
strings.Join(importedLibrary.Architectures, ", "),

0 commit comments

Comments
 (0)