Skip to content

Commit

Permalink
refactor WarnAboutArchIncompatibleLibraries in a function
Browse files Browse the repository at this point in the history
  • Loading branch information
alessio-perugini committed Sep 8, 2023
1 parent cc6f676 commit 788da0a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 13 deletions.
17 changes: 15 additions & 2 deletions legacy/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -317,7 +317,7 @@ func (s *Preprocess) Run(ctx *types.Context) error {

findIncludes(ctx),

&WarnAboutArchIncompatibleLibraries{},
warnAboutArchIncompatibleLibraries(ctx),

types.BareCommand(PreprocessSketch),
}
Expand Down Expand Up @@ -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
})
}
24 changes: 13 additions & 11 deletions legacy/builder/warn_about_arch_incompatible_libraries.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,34 @@
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, ", "),
strings.Join(archs, ", ")))
}
}

return nil
return infoBuf.Bytes(), nil
}

0 comments on commit 788da0a

Please sign in to comment.