Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Refactored AddMissingBuildPropertiesFromParentPlatformTxtFiles
Previously the specific recipes to run CTags were added to global build
properties. Now the global build properties are not altered anymore and
the CTags-specific properties are created only to run CTags and dropped
afterward.
  • Loading branch information
cmaglie committed Mar 29, 2023
commit b4a27ed4268a89857ad595f869b31d8206dc7d7f
1 change: 1 addition & 0 deletions arduino/cores/packagemanager/package_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ func (pme *Explorer) ResolveFQBN(fqbn *cores.FQBN) (
buildProperties.Set("runtime.os", properties.GetOSSuffix())
buildProperties.Set("build.library_discovery_phase", "0")
// Deprecated properties
buildProperties.Set("tools.avrdude.path", "{runtime.tools.avrdude.path}")
buildProperties.Set("ide_version", "10607")
buildProperties.Set("runtime.ide.version", "10607")
if !buildProperties.ContainsKey("software") {
Expand Down

This file was deleted.

1 change: 0 additions & 1 deletion legacy/builder/container_setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ func (s *ContainerSetupHardwareToolsLibsSketchAndProps) Run(ctx *types.Context)
commands = []types.Command{
&SetupBuildProperties{},
&SetCustomBuildProperties{},
&AddMissingBuildPropertiesFromParentPlatformTxtFiles{},
}

for _, command := range commands {
Expand Down
33 changes: 0 additions & 33 deletions legacy/builder/ctags/ctags_properties.go

This file was deleted.

15 changes: 9 additions & 6 deletions legacy/builder/ctags_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,22 @@ import (
type CTagsRunner struct{}

func (s *CTagsRunner) Run(ctx *types.Context) error {
buildProperties := ctx.BuildProperties
ctagsTargetFilePath := ctx.CTagsTargetFile

ctagsProperties := buildProperties.Clone()
ctagsProperties.Merge(buildProperties.SubTree("tools").SubTree("ctags"))
ctagsProperties.SetPath("source_file", ctagsTargetFilePath)
buildProperties := properties.NewMap()
buildProperties.Set("tools.ctags.path", "{runtime.tools.ctags.path}")
buildProperties.Set("tools.ctags.cmd.path", "{path}/ctags")
buildProperties.Set("tools.ctags.pattern", `"{cmd.path}" -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives "{source_file}"`)
buildProperties.Merge(ctx.BuildProperties)
buildProperties.Merge(buildProperties.SubTree("tools").SubTree("ctags"))
buildProperties.SetPath("source_file", ctagsTargetFilePath)

pattern := ctagsProperties.Get("pattern")
pattern := buildProperties.Get("pattern")
if pattern == "" {
return errors.Errorf(tr("%s pattern is missing"), "ctags")
}

commandLine := ctagsProperties.ExpandPropsInString(pattern)
commandLine := buildProperties.ExpandPropsInString(pattern)
parts, err := properties.SplitQuotedString(commandLine, `"'`, false)
if err != nil {
return errors.WithStack(err)
Expand Down
36 changes: 18 additions & 18 deletions legacy/builder/gcc_preproc_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/arduino/arduino-cli/legacy/builder/types"
"github.com/arduino/arduino-cli/legacy/builder/utils"
"github.com/arduino/go-paths-helper"
properties "github.com/arduino/go-properties-orderedmap"
"github.com/pkg/errors"
)

Expand Down Expand Up @@ -55,20 +56,28 @@ func GCCPreprocRunnerForDiscoveringIncludes(ctx *types.Context, sourceFilePath *
}

func prepareGCCPreprocRecipeProperties(ctx *types.Context, sourceFilePath *paths.Path, targetFilePath *paths.Path, includes paths.PathList) (*exec.Cmd, error) {
properties := ctx.BuildProperties.Clone()
properties.Set("build.library_discovery_phase", "1")
properties.SetPath("source_file", sourceFilePath)
properties.SetPath("preprocessed_file_path", targetFilePath)
buildProperties := properties.NewMap()
buildProperties.Set("preproc.macros.flags", "-w -x c++ -E -CC")
buildProperties.Merge(ctx.BuildProperties)
buildProperties.Set("build.library_discovery_phase", "1")
buildProperties.SetPath("source_file", sourceFilePath)
buildProperties.SetPath("preprocessed_file_path", targetFilePath)

includesStrings := utils.Map(includes.AsStrings(), utils.WrapWithHyphenI)
properties.Set("includes", strings.Join(includesStrings, " "))
buildProperties.Set("includes", strings.Join(includesStrings, " "))

if properties.Get("recipe.preproc.macros") == "" {
//generate PREPROC_MACROS from RECIPE_CPP_PATTERN
properties.Set("recipe.preproc.macros", GeneratePreprocPatternFromCompile(properties.Get("recipe.cpp.o.pattern")))
if buildProperties.Get("recipe.preproc.macros") == "" {
// autogenerate preprocess macros recipe from compile recipe
preprocPattern := buildProperties.Get("recipe.cpp.o.pattern")
// add {preproc.macros.flags} to {compiler.cpp.flags}
preprocPattern = strings.Replace(preprocPattern, "{compiler.cpp.flags}", "{compiler.cpp.flags} {preproc.macros.flags}", 1)
// replace "{object_file}" with "{preprocessed_file_path}"
preprocPattern = strings.Replace(preprocPattern, "{object_file}", "{preprocessed_file_path}", 1)

buildProperties.Set("recipe.preproc.macros", preprocPattern)
}

cmd, err := builder_utils.PrepareCommandForRecipe(properties, "recipe.preproc.macros", true, ctx.PackageManager.GetEnvVarsForSpawnedProcess())
cmd, err := builder_utils.PrepareCommandForRecipe(buildProperties, "recipe.preproc.macros", true, ctx.PackageManager.GetEnvVarsForSpawnedProcess())
if err != nil {
return nil, errors.WithStack(err)
}
Expand All @@ -79,12 +88,3 @@ func prepareGCCPreprocRecipeProperties(ctx *types.Context, sourceFilePath *paths

return cmd, nil
}

func GeneratePreprocPatternFromCompile(compilePattern string) string {
// add {preproc.macros.flags}
// replace "{object_file}" with "{preprocessed_file_path}"
returnString := compilePattern
returnString = strings.Replace(returnString, "{compiler.cpp.flags}", "{compiler.cpp.flags} {preproc.macros.flags}", 1)
returnString = strings.Replace(returnString, "{object_file}", "{preprocessed_file_path}", 1)
return returnString
}
53 changes: 14 additions & 39 deletions legacy/builder/preprocess_sketch.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,56 +29,30 @@ import (
"github.com/pkg/errors"
)

// ArduinoPreprocessorProperties are the platform properties needed to run arduino-preprocessor
var ArduinoPreprocessorProperties = properties.NewFromHashmap(map[string]string{
// Ctags
"tools.arduino-preprocessor.path": "{runtime.tools.arduino-preprocessor.path}",
"tools.arduino-preprocessor.cmd.path": "{path}/arduino-preprocessor",
"tools.arduino-preprocessor.pattern": `"{cmd.path}" "{source_file}" -- -std=gnu++11`,

"preproc.macros.flags": "-w -x c++ -E -CC",
})

func PreprocessSketchWithArduinoPreprocessor(ctx *types.Context) error {
sourceFile := ctx.SketchBuildPath.Join(ctx.Sketch.MainFile.Base() + ".cpp")
commands := []types.Command{
&ArduinoPreprocessorRunner{},
}

if err := ctx.PreprocPath.MkdirAll(); err != nil {
return errors.WithStack(err)
}

sourceFile := ctx.SketchBuildPath.Join(ctx.Sketch.MainFile.Base() + ".cpp")
GCCPreprocRunner(ctx, sourceFile, ctx.PreprocPath.Join("ctags_target_for_gcc_minus_e.cpp"), ctx.IncludeFolders)

for _, command := range commands {
PrintRingNameIfDebug(ctx, command)
err := command.Run(ctx)
if err != nil {
return errors.WithStack(err)
}
}

return bldr.SketchSaveItemCpp(ctx.Sketch.MainFile, []byte(ctx.Source), ctx.SketchBuildPath)
}

type ArduinoPreprocessorRunner struct{}

func (s *ArduinoPreprocessorRunner) Run(ctx *types.Context) error {
buildProperties := ctx.BuildProperties
targetFilePath := ctx.PreprocPath.Join("ctags_target_for_gcc_minus_e.cpp")

preprocProperties := buildProperties.Clone()
toolProps := buildProperties.SubTree("tools").SubTree("arduino-preprocessor")
preprocProperties.Merge(toolProps)
preprocProperties.SetPath("source_file", targetFilePath)

pattern := preprocProperties.Get("pattern")
buildProperties := properties.NewMap()
buildProperties.Set("tools.arduino-preprocessor.path", "{runtime.tools.arduino-preprocessor.path}")
buildProperties.Set("tools.arduino-preprocessor.cmd.path", "{path}/arduino-preprocessor")
buildProperties.Set("tools.arduino-preprocessor.pattern", `"{cmd.path}" "{source_file}" -- -std=gnu++11`)
buildProperties.Set("preproc.macros.flags", "-w -x c++ -E -CC")
buildProperties.Merge(ctx.BuildProperties)
buildProperties.Merge(buildProperties.SubTree("tools").SubTree("arduino-preprocessor"))
buildProperties.SetPath("source_file", targetFilePath)

pattern := buildProperties.Get("pattern")
if pattern == "" {
return errors.New(tr("arduino-preprocessor pattern is missing"))
}

commandLine := preprocProperties.ExpandPropsInString(pattern)
commandLine := buildProperties.ExpandPropsInString(pattern)
parts, err := properties.SplitQuotedString(commandLine, `"'`, false)
if err != nil {
return errors.WithStack(err)
Expand Down Expand Up @@ -106,5 +80,6 @@ func (s *ArduinoPreprocessorRunner) Run(ctx *types.Context) error {

//fmt.Printf("PREPROCESSOR OUTPUT:\n%s\n", output)
ctx.Source = string(result)
return nil

return bldr.SketchSaveItemCpp(ctx.Sketch.MainFile, []byte(ctx.Source), ctx.SketchBuildPath)
}