diff --git a/legacy/builder/builder.go b/legacy/builder/builder.go index 13880efcc9f..1a94647f696 100644 --- a/legacy/builder/builder.go +++ b/legacy/builder/builder.go @@ -55,7 +55,7 @@ func (s *Builder) Run(ctx *types.Context) error { logIfVerbose(false, tr("Detecting libraries used...")), findIncludes(ctx), - &WarnAboutArchIncompatibleLibraries{}, + warnAboutArchIncompatibleLibraries(ctx), logIfVerbose(false, tr("Generating function prototypes...")), types.BareCommand(PreprocessSketch), @@ -317,7 +317,7 @@ func (s *Preprocess) Run(ctx *types.Context) error { findIncludes(ctx), - &WarnAboutArchIncompatibleLibraries{}, + warnAboutArchIncompatibleLibraries(ctx), types.BareCommand(PreprocessSketch), } @@ -424,3 +424,16 @@ func containerBuildOptions(ctx *types.Context) types.BareCommand { return nil }) } + +func warnAboutArchIncompatibleLibraries(ctx *types.Context) types.BareCommand { + return types.BareCommand(func(ctx *types.Context) error { + overrides, _ := ctx.BuildProperties.GetOk("architecture.override_check") + infoBuf, _ := WarnAboutArchIncompatibleLibraries( + ctx.TargetPlatform, + overrides, + ctx.SketchLibrariesDetector.ImportedLibraries(), + ) + ctx.Info(string(infoBuf)) + return nil + }) +} diff --git a/legacy/builder/warn_about_arch_incompatible_libraries.go b/legacy/builder/warn_about_arch_incompatible_libraries.go index c815a54f3aa..1f52c04d0e4 100644 --- a/legacy/builder/warn_about_arch_incompatible_libraries.go +++ b/legacy/builder/warn_about_arch_incompatible_libraries.go @@ -16,26 +16,28 @@ package builder import ( + "bytes" "strings" - "github.com/arduino/arduino-cli/legacy/builder/constants" - "github.com/arduino/arduino-cli/legacy/builder/types" + "github.com/arduino/arduino-cli/arduino/cores" + "github.com/arduino/arduino-cli/arduino/libraries" ) -type WarnAboutArchIncompatibleLibraries struct{} - -func (s *WarnAboutArchIncompatibleLibraries) Run(ctx *types.Context) error { - targetPlatform := ctx.TargetPlatform - buildProperties := ctx.BuildProperties +func WarnAboutArchIncompatibleLibraries( + targetPlatform *cores.PlatformRelease, + overrides string, + importedLibraries libraries.List, +) ([]byte, error) { + infoBuf := &bytes.Buffer{} archs := []string{targetPlatform.Platform.Architecture} - if overrides, ok := buildProperties.GetOk(constants.BUILD_PROPERTIES_ARCH_OVERRIDE_CHECK); ok { + if overrides != "" { archs = append(archs, strings.Split(overrides, ",")...) } - for _, importedLibrary := range ctx.SketchLibrariesDetector.ImportedLibraries() { + for _, importedLibrary := range importedLibraries { if !importedLibrary.SupportsAnyArchitectureIn(archs...) { - ctx.Info( + infoBuf.WriteString( 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).", importedLibrary.Name, strings.Join(importedLibrary.Architectures, ", "), @@ -43,5 +45,5 @@ func (s *WarnAboutArchIncompatibleLibraries) Run(ctx *types.Context) error { } } - return nil + return infoBuf.Bytes(), nil }