Skip to content

Commit

Permalink
make RunRecipe a method recevier of arduino/builder
Browse files Browse the repository at this point in the history
  • Loading branch information
alessio-perugini committed Sep 12, 2023
1 parent a9cfb1c commit 1ff5393
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 18 deletions.
18 changes: 8 additions & 10 deletions legacy/builder/recipe_runner.go → arduino/builder/recipe.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,21 @@ import (
"sort"
"strings"

"github.com/arduino/arduino-cli/arduino/builder/logger"
"github.com/arduino/arduino-cli/arduino/builder/utils"
properties "github.com/arduino/go-properties-orderedmap"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)

func RecipeByPrefixSuffixRunner(
// RunRecipe fixdoc
func (b *Builder) RunRecipe(
prefix, suffix string,
skipIfOnlyUpdatingCompilationDatabase, onlyUpdateCompilationDatabase bool,
buildProps *properties.Map,
builderLogger *logger.BuilderLogger,
) error {
logrus.Debugf(fmt.Sprintf("Looking for recipes like %s", prefix+"*"+suffix))

// TODO is it necessary to use Clone?
buildProperties := buildProps.Clone()
buildProperties := b.buildProperties.Clone()
recipes := findRecipes(buildProperties, prefix, suffix)

// TODO is it necessary to use Clone?
Expand All @@ -50,15 +48,15 @@ func RecipeByPrefixSuffixRunner(
}

if onlyUpdateCompilationDatabase && skipIfOnlyUpdatingCompilationDatabase {
if builderLogger.Verbose() {
builderLogger.Info(tr("Skipping: %[1]s", strings.Join(command.GetArgs(), " ")))
if b.logger.Verbose() {
b.logger.Info(tr("Skipping: %[1]s", strings.Join(command.GetArgs(), " ")))
}
return nil
}

verboseInfo, _, _, err := utils.ExecCommand(builderLogger.Verbose(), builderLogger.Stdout(), builderLogger.Stderr(), command, utils.ShowIfVerbose /* stdout */, utils.Show /* stderr */)
if builderLogger.Verbose() {
builderLogger.Info(string(verboseInfo))
verboseInfo, _, _, err := utils.ExecCommand(b.logger.Verbose(), b.logger.Stdout(), b.logger.Stderr(), command, utils.ShowIfVerbose /* stdout */, utils.Show /* stderr */)
if b.logger.Verbose() {
b.logger.Info(string(verboseInfo))
}
if err != nil {
return errors.WithStack(err)
Expand Down
7 changes: 2 additions & 5 deletions commands/compile/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,11 +339,9 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
exportBinaries = false
}
if exportBinaries {
err := builder.RecipeByPrefixSuffixRunner(
err := sketchBuilder.RunRecipe(
"recipe.hooks.savehex.presavehex", ".pattern", false,
builderCtx.OnlyUpdateCompilationDatabase,
sketchBuilder.GetBuildProperties(),
builderLogger,
)
if err != nil {
return r, err
Expand Down Expand Up @@ -383,10 +381,9 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
}
}

err = builder.RecipeByPrefixSuffixRunner(
err = sketchBuilder.RunRecipe(
"recipe.hooks.savehex.postsavehex", ".pattern", false,
builderCtx.OnlyUpdateCompilationDatabase,
sketchBuilder.GetBuildProperties(), builderLogger,
)
if err != nil {
return r, err
Expand Down
4 changes: 1 addition & 3 deletions legacy/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,11 +390,9 @@ func logIfVerbose(warn bool, msg string) types.BareCommand {
}

func recipeByPrefixSuffixRunner(ctx *types.Context, prefix, suffix string, skipIfOnlyUpdatingCompilationDatabase bool) error {
return RecipeByPrefixSuffixRunner(
return ctx.Builder.RunRecipe(
prefix, suffix, skipIfOnlyUpdatingCompilationDatabase,
ctx.OnlyUpdateCompilationDatabase,
ctx.Builder.GetBuildProperties(),
ctx.BuilderLogger,
)
}

Expand Down

0 comments on commit 1ff5393

Please sign in to comment.