Skip to content

Commit 788da0a

Browse files
refactor WarnAboutArchIncompatibleLibraries in a function
1 parent cc6f676 commit 788da0a

File tree

2 files changed

+28
-13
lines changed

2 files changed

+28
-13
lines changed

Diff for: legacy/builder/builder.go

+15-2
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+
infoBuf, _ := WarnAboutArchIncompatibleLibraries(
432+
ctx.TargetPlatform,
433+
overrides,
434+
ctx.SketchLibrariesDetector.ImportedLibraries(),
435+
)
436+
ctx.Info(string(infoBuf))
437+
return nil
438+
})
439+
}

Diff for: legacy/builder/warn_about_arch_incompatible_libraries.go

+13-11
Original file line numberDiff line numberDiff line change
@@ -16,32 +16,34 @@
1616
package builder
1717

1818
import (
19+
"bytes"
1920
"strings"
2021

21-
"github.com/arduino/arduino-cli/legacy/builder/constants"
22-
"github.com/arduino/arduino-cli/legacy/builder/types"
22+
"github.com/arduino/arduino-cli/arduino/cores"
23+
"github.com/arduino/arduino-cli/arduino/libraries"
2324
)
2425

25-
type WarnAboutArchIncompatibleLibraries struct{}
26-
27-
func (s *WarnAboutArchIncompatibleLibraries) Run(ctx *types.Context) error {
28-
targetPlatform := ctx.TargetPlatform
29-
buildProperties := ctx.BuildProperties
26+
func WarnAboutArchIncompatibleLibraries(
27+
targetPlatform *cores.PlatformRelease,
28+
overrides string,
29+
importedLibraries libraries.List,
30+
) ([]byte, error) {
31+
infoBuf := &bytes.Buffer{}
3032

3133
archs := []string{targetPlatform.Platform.Architecture}
32-
if overrides, ok := buildProperties.GetOk(constants.BUILD_PROPERTIES_ARCH_OVERRIDE_CHECK); ok {
34+
if overrides != "" {
3335
archs = append(archs, strings.Split(overrides, ",")...)
3436
}
3537

36-
for _, importedLibrary := range ctx.SketchLibrariesDetector.ImportedLibraries() {
38+
for _, importedLibrary := range importedLibraries {
3739
if !importedLibrary.SupportsAnyArchitectureIn(archs...) {
38-
ctx.Info(
40+
infoBuf.WriteString(
3941
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).",
4042
importedLibrary.Name,
4143
strings.Join(importedLibrary.Architectures, ", "),
4244
strings.Join(archs, ", ")))
4345
}
4446
}
4547

46-
return nil
48+
return infoBuf.Bytes(), nil
4749
}

0 commit comments

Comments
 (0)