From ba0852c19a4031e157d6a8f3f03ec075363d6c7f Mon Sep 17 00:00:00 2001 From: Alessio Perugini Date: Fri, 8 Sep 2023 16:35:47 +0200 Subject: [PATCH] refactor WarnAboutArchIncompatibleLibraries in a function --- legacy/builder/builder.go | 17 ++++++++++++-- .../warn_about_arch_incompatible_libraries.go | 22 +++++++++---------- 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/legacy/builder/builder.go b/legacy/builder/builder.go index 13880efcc9f..6c23599ffa2 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") + _ = WarnAboutArchIncompatibleLibraries( + ctx.TargetPlatform, + overrides, + ctx.SketchLibrariesDetector.ImportedLibraries(), + func(s string) { ctx.Info(s) }, + ) + return nil + }) +} diff --git a/legacy/builder/warn_about_arch_incompatible_libraries.go b/legacy/builder/warn_about_arch_incompatible_libraries.go index c815a54f3aa..954fbb047d3 100644 --- a/legacy/builder/warn_about_arch_incompatible_libraries.go +++ b/legacy/builder/warn_about_arch_incompatible_libraries.go @@ -18,24 +18,24 @@ package builder import ( "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, + printInfoFn func(string), +) error { 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( + printInfoFn( 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, ", "),