Skip to content

[pull] master from arduino:master #40

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/platform-specification.md
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,10 @@ compiler.libraries.ldflags=
recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" {compiler.c.elf.flags} -mmcu={build.mcu} -o "{build.path}/{build.project_name}.elf" {object_files} {compiler.libraries.ldflags} "{archive_file_path}" "-L{build.path}" -lm
```

If the linking process requires multiple steps, the recipe can be written using the **recipe.c.combine.NUMBER.pattern**
syntax. In this case, each step will be executed in the order specified by the number. When multiple steps are defined,
the **recipe.c.combine.pattern** property is ignored.

#### Recipes for extraction of executable files and other binary data

An arbitrary number of extra steps can be performed at the end of objects linking. These steps can be used to extract
Expand Down
2 changes: 1 addition & 1 deletion internal/arduino/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ func (b *Builder) build() error {
}
b.Progress.CompleteStep()

if err := b.RunRecipe("recipe.objcopy.", ".pattern", true); err != nil {
if err := b.RunRecipe("recipe.objcopy", ".pattern", true); err != nil {
return err
}
b.Progress.CompleteStep()
Expand Down
7 changes: 1 addition & 6 deletions internal/arduino/builder/linker.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,5 @@ func (b *Builder) link() error {
properties.Set("archive_file_path", b.buildArtifacts.coreArchiveFilePath.String())
properties.Set("object_files", objectFileList)

command, err := b.prepareCommandForRecipe(properties, "recipe.c.combine.pattern", false)
if err != nil {
return err
}

return b.execCommand(command)
return b.RunRecipeWithProps("recipe.c.combine", ".pattern", properties, false)
}
20 changes: 14 additions & 6 deletions internal/arduino/builder/recipe.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,18 @@ import (

// RunRecipe fixdoc
func (b *Builder) RunRecipe(prefix, suffix string, skipIfOnlyUpdatingCompilationDatabase bool) error {
return b.RunRecipeWithProps(prefix, suffix, b.buildProperties, skipIfOnlyUpdatingCompilationDatabase)
}

func (b *Builder) RunRecipeWithProps(prefix, suffix string, buildProperties *properties.Map, skipIfOnlyUpdatingCompilationDatabase bool) error {
logrus.Debugf("Looking for recipes like %s", prefix+"*"+suffix)

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

// TODO is it necessary to use Clone?
properties := buildProperties.Clone()
for _, recipe := range recipes {
logrus.Debugf("Running recipe: %s", recipe)

command, err := b.prepareCommandForRecipe(properties, recipe, false)
command, err := b.prepareCommandForRecipe(buildProperties, recipe, false)
if err != nil {
return err
}
Expand All @@ -60,12 +60,20 @@ func (b *Builder) RunRecipe(prefix, suffix string, skipIfOnlyUpdatingCompilation

func findRecipes(buildProperties *properties.Map, patternPrefix string, patternSuffix string) []string {
var recipes []string

exactKey := patternPrefix + patternSuffix

for _, key := range buildProperties.Keys() {
if strings.HasPrefix(key, patternPrefix) && strings.HasSuffix(key, patternSuffix) && buildProperties.Get(key) != "" {
if key != exactKey && strings.HasPrefix(key, patternPrefix) && strings.HasSuffix(key, patternSuffix) && buildProperties.Get(key) != "" {
recipes = append(recipes, key)
}
}

// If no recipes were found, check if the exact key exists
if len(recipes) == 0 && buildProperties.Get(exactKey) != "" {
recipes = append(recipes, exactKey)
}

sort.Strings(recipes)

return recipes
Expand Down
81 changes: 81 additions & 0 deletions internal/arduino/builder/recipe_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// This file is part of arduino-cli.
//
// Copyright 2020 ARDUINO SA (http://www.arduino.cc/)
//
// This software is released under the GNU General Public License version 3,
// which covers the main part of arduino-cli.
// The terms of this license can be found at:
// https://www.gnu.org/licenses/gpl-3.0.en.html
//
// You can be released from the requirements of the above licenses by purchasing
// a commercial license. Buying such a license is mandatory if you want to
// modify or otherwise use the software for commercial activities involving the
// Arduino software without disclosing the source code of your own applications.
// To purchase a commercial license, send an email to license@arduino.cc.

package builder

import (
"testing"

properties "github.com/arduino/go-properties-orderedmap"
"github.com/stretchr/testify/require"
)

func TestRecipeFinder(t *testing.T) {
t.Run("NumberedRecipes", func(t *testing.T) {
buildProperties := properties.NewMap()
buildProperties.Set("recipe.test", "test")
buildProperties.Set("recipe.1.test", "test2")
buildProperties.Set("recipe.2.test", "test3")
recipes := findRecipes(buildProperties, "recipe", ".test")
require.Equal(t, []string{"recipe.1.test", "recipe.2.test"}, recipes)
})
t.Run("NumberedRecipesWithGaps", func(t *testing.T) {
buildProperties := properties.NewMap()
buildProperties.Set("recipe.test", "test")
buildProperties.Set("recipe.2.test", "test3")
buildProperties.Set("recipe.0.test", "test2")
recipes := findRecipes(buildProperties, "recipe", ".test")
require.Equal(t, []string{"recipe.0.test", "recipe.2.test"}, recipes)
})
t.Run("NumberedRecipesWithGapsAndDifferentLenghtNumbers", func(t *testing.T) {
buildProperties := properties.NewMap()
buildProperties.Set("recipe.test", "test")
buildProperties.Set("recipe.12.test", "test3")
buildProperties.Set("recipe.2.test", "test2")
recipes := findRecipes(buildProperties, "recipe", ".test")
// The order is sorted alphabetically, not numerically
require.Equal(t, []string{"recipe.12.test", "recipe.2.test"}, recipes)
})
t.Run("NumberedRecipesWithGapsAndNumbers", func(t *testing.T) {
buildProperties := properties.NewMap()
buildProperties.Set("recipe.test", "test")
buildProperties.Set("recipe.12.test", "test3")
buildProperties.Set("recipe.02.test", "test2")
buildProperties.Set("recipe.09.test", "test2")
recipes := findRecipes(buildProperties, "recipe", ".test")
require.Equal(t, []string{"recipe.02.test", "recipe.09.test", "recipe.12.test"}, recipes)
})
t.Run("UnnumberedRecipies", func(t *testing.T) {
buildProperties := properties.NewMap()
buildProperties.Set("recipe.test", "test")
buildProperties.Set("recipe.a.test", "test3")
buildProperties.Set("recipe.b.test", "test2")
recipes := findRecipes(buildProperties, "recipe", ".test")
require.Equal(t, []string{"recipe.a.test", "recipe.b.test"}, recipes)
})
t.Run("ObjcopyRecipies/1", func(t *testing.T) {
buildProperties := properties.NewMap()
buildProperties.Set("recipe.objcopy.eep.pattern", "test")
buildProperties.Set("recipe.objcopy.hex.pattern", "test")
recipes := findRecipes(buildProperties, "recipe.objcopy", ".pattern")
require.Equal(t, []string{"recipe.objcopy.eep.pattern", "recipe.objcopy.hex.pattern"}, recipes)
})
t.Run("ObjcopyRecipies/2", func(t *testing.T) {
buildProperties := properties.NewMap()
buildProperties.Set("recipe.objcopy.partitions.bin.pattern", "test")
recipes := findRecipes(buildProperties, "recipe.objcopy", ".pattern")
require.Equal(t, []string{"recipe.objcopy.partitions.bin.pattern"}, recipes)
})
}
19 changes: 11 additions & 8 deletions internal/integrationtest/arduino-cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,17 +354,15 @@ func (cli *ArduinoCLI) RunWithCustomInput(in io.Reader, args ...string) ([]byte,
return stdoutBuf.Bytes(), errBuf, err
}

func (cli *ArduinoCLI) run(ctx context.Context, stdoutBuff, stderrBuff io.Writer, stdinBuff io.Reader, env map[string]string, args ...string) error {
func (cli *ArduinoCLI) run(ctx context.Context, stdoutBuff, stderrBuff io.Writer, stdinBuff io.Reader, env map[string]string, args ...string) (_err error) {
if cli.cliConfigPath != nil {
args = append([]string{"--config-file", cli.cliConfigPath.String()}, args...)
}

// Accumulate all output to terminal and spit-out all at once at the end of the test
// This allows to correctly group test output when running t.Parallel() tests.
terminalOut := new(bytes.Buffer)
defer func() {
fmt.Print(terminalOut.String())
}()
terminalErr := new(bytes.Buffer)

// Github-actions workflow tags to fold log lines
if os.Getenv("GITHUB_ACTIONS") != "" {
Expand All @@ -373,6 +371,12 @@ func (cli *ArduinoCLI) run(ctx context.Context, stdoutBuff, stderrBuff io.Writer
}

fmt.Fprintln(terminalOut, color.HiBlackString(">>> Running: ")+color.HiYellowString("%s %s %s", cli.path, strings.Join(args, " "), env))
defer func() {
fmt.Print(terminalOut.String())
fmt.Print(terminalErr.String())
fmt.Println(color.HiBlackString("<<< Run completed (err = %v)", _err))
}()

cliProc, err := paths.NewProcessFromPath(cli.convertEnvForExecutils(env), cli.path, args...)
cli.t.NoError(err)
stdout, err := cliProc.StdoutPipe()
Expand Down Expand Up @@ -401,20 +405,19 @@ func (cli *ArduinoCLI) run(ctx context.Context, stdoutBuff, stderrBuff io.Writer
if stderrBuff == nil {
stderrBuff = io.Discard
}
if _, err := io.Copy(stderrBuff, io.TeeReader(stderr, terminalOut)); err != nil {
fmt.Fprintln(terminalOut, color.HiBlackString("<<< stderr copy error:"), err)
if _, err := io.Copy(stderrBuff, io.TeeReader(stderr, terminalErr)); err != nil {
fmt.Fprintln(terminalErr, color.HiBlackString("<<< stderr copy error:"), err)
}
}()
if stdinBuff != nil {
go func() {
if _, err := io.Copy(stdin, stdinBuff); err != nil {
fmt.Fprintln(terminalOut, color.HiBlackString("<<< stdin copy error:"), err)
fmt.Fprintln(terminalErr, color.HiBlackString("<<< stdin copy error:"), err)
}
}()
}
cliErr := cliProc.WaitWithinContext(ctx)
wg.Wait()
fmt.Fprintln(terminalOut, color.HiBlackString("<<< Run completed (err = %v)", cliErr))

return cliErr
}
Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy