Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 5a1c2fe

Browse files
authoredMar 30, 2023
Remove legacy "rewrite-rules" feature (#2132)
* 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. * Removed platform rewrite-rules functionality
1 parent 51e50e1 commit 5a1c2fe

18 files changed

+42
-562
lines changed
 

‎arduino/cores/packagemanager/package_manager.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,7 @@ func (pme *Explorer) ResolveFQBN(fqbn *cores.FQBN) (
360360
buildProperties.Set("runtime.os", properties.GetOSSuffix())
361361
buildProperties.Set("build.library_discovery_phase", "0")
362362
// Deprecated properties
363+
buildProperties.Set("tools.avrdude.path", "{runtime.tools.avrdude.path}")
363364
buildProperties.Set("ide_version", "10607")
364365
buildProperties.Set("runtime.ide.version", "10607")
365366
if !buildProperties.ContainsKey("software") {

‎legacy/builder/add_additional_entries_to_context.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
package builder
1717

1818
import (
19-
"github.com/arduino/arduino-cli/arduino/cores"
2019
"github.com/arduino/arduino-cli/legacy/builder/constants"
2120
"github.com/arduino/arduino-cli/legacy/builder/types"
2221
"github.com/pkg/errors"
@@ -57,7 +56,6 @@ func (*AddAdditionalEntriesToContext) Run(ctx *types.Context) error {
5756
ctx.CollectedSourceFiles = &types.UniqueSourceFileQueue{}
5857

5958
ctx.LibrariesResolutionResults = map[string]types.LibraryResolutionResult{}
60-
ctx.HardwareRewriteResults = map[*cores.PlatformRelease][]types.PlatforKeyRewrite{}
6159

6260
return nil
6361
}

‎legacy/builder/add_missing_build_properties_from_parent_platform_txt_files.go

Lines changed: 0 additions & 34 deletions
This file was deleted.

‎legacy/builder/builder.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ func (s *Builder) Run(ctx *types.Context) error {
4444

4545
&ContainerBuildOptions{},
4646

47-
&WarnAboutPlatformRewrites{},
48-
4947
&RecipeByPrefixSuffixRunner{Prefix: "recipe.hooks.prebuild", Suffix: ".pattern"},
5048

5149
&ContainerMergeCopySketchFiles{},

‎legacy/builder/constants/constants.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ const BUILD_PROPERTIES_INCLUDES = "includes"
3333
const BUILD_PROPERTIES_OBJECT_FILE = "object_file"
3434
const BUILD_PROPERTIES_RUNTIME_PLATFORM_PATH = "runtime.platform.path"
3535
const EMPTY_STRING = ""
36-
const FILE_PLATFORM_KEYS_REWRITE_TXT = "platform.keys.rewrite.txt"
3736
const FOLDER_BOOTLOADERS = "bootloaders"
3837
const FOLDER_CORE = "core"
3938
const FOLDER_PREPROC = "preproc"
@@ -52,15 +51,10 @@ const LOG_LEVEL_WARN = "warn"
5251
const PACKAGE_NAME = "name"
5352
const PACKAGE_TOOLS = "tools"
5453
const PLATFORM_ARCHITECTURE = "architecture"
55-
const PLATFORM_NAME = "name"
56-
const PLATFORM_REWRITE_NEW = "new"
57-
const PLATFORM_REWRITE_OLD = "old"
5854
const PLATFORM_URL = "url"
5955
const PLATFORM_VERSION = "version"
6056
const RECIPE_AR_PATTERN = "recipe.ar.pattern"
6157
const RECIPE_C_COMBINE_PATTERN = "recipe.c.combine.pattern"
62-
const REWRITING_DISABLED = "disabled"
63-
const REWRITING = "rewriting"
6458
const SPACE = " "
6559
const TOOL_NAME = "name"
6660
const TOOL_URL = "url"

‎legacy/builder/container_setup.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ func (s *ContainerSetupHardwareToolsLibsSketchAndProps) Run(ctx *types.Context)
3131
&AddAdditionalEntriesToContext{},
3232
&FailIfBuildPathEqualsSketchPath{},
3333
&HardwareLoader{},
34-
&PlatformKeysRewriteLoader{},
35-
&RewriteHardwareKeys{},
3634
&TargetBoardResolver{},
3735
&LibrariesLoader{},
3836
}
@@ -53,7 +51,6 @@ func (s *ContainerSetupHardwareToolsLibsSketchAndProps) Run(ctx *types.Context)
5351
commands = []types.Command{
5452
&SetupBuildProperties{},
5553
&SetCustomBuildProperties{},
56-
&AddMissingBuildPropertiesFromParentPlatformTxtFiles{},
5754
}
5855

5956
for _, command := range commands {

‎legacy/builder/ctags/ctags_properties.go

Lines changed: 0 additions & 33 deletions
This file was deleted.

‎legacy/builder/ctags_runner.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,22 @@ import (
2929
type CTagsRunner struct{}
3030

3131
func (s *CTagsRunner) Run(ctx *types.Context) error {
32-
buildProperties := ctx.BuildProperties
3332
ctagsTargetFilePath := ctx.CTagsTargetFile
3433

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

39-
pattern := ctagsProperties.Get("pattern")
42+
pattern := buildProperties.Get("pattern")
4043
if pattern == "" {
4144
return errors.Errorf(tr("%s pattern is missing"), "ctags")
4245
}
4346

44-
commandLine := ctagsProperties.ExpandPropsInString(pattern)
47+
commandLine := buildProperties.ExpandPropsInString(pattern)
4548
parts, err := properties.SplitQuotedString(commandLine, `"'`, false)
4649
if err != nil {
4750
return errors.WithStack(err)

‎legacy/builder/gcc_preproc_runner.go

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"github.com/arduino/arduino-cli/legacy/builder/types"
2424
"github.com/arduino/arduino-cli/legacy/builder/utils"
2525
"github.com/arduino/go-paths-helper"
26+
properties "github.com/arduino/go-properties-orderedmap"
2627
"github.com/pkg/errors"
2728
)
2829

@@ -55,20 +56,28 @@ func GCCPreprocRunnerForDiscoveringIncludes(ctx *types.Context, sourceFilePath *
5556
}
5657

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

6366
includesStrings := utils.Map(includes.AsStrings(), utils.WrapWithHyphenI)
64-
properties.Set("includes", strings.Join(includesStrings, " "))
67+
buildProperties.Set("includes", strings.Join(includesStrings, " "))
6568

66-
if properties.Get("recipe.preproc.macros") == "" {
67-
//generate PREPROC_MACROS from RECIPE_CPP_PATTERN
68-
properties.Set("recipe.preproc.macros", GeneratePreprocPatternFromCompile(properties.Get("recipe.cpp.o.pattern")))
69+
if buildProperties.Get("recipe.preproc.macros") == "" {
70+
// autogenerate preprocess macros recipe from compile recipe
71+
preprocPattern := buildProperties.Get("recipe.cpp.o.pattern")
72+
// add {preproc.macros.flags} to {compiler.cpp.flags}
73+
preprocPattern = strings.Replace(preprocPattern, "{compiler.cpp.flags}", "{compiler.cpp.flags} {preproc.macros.flags}", 1)
74+
// replace "{object_file}" with "{preprocessed_file_path}"
75+
preprocPattern = strings.Replace(preprocPattern, "{object_file}", "{preprocessed_file_path}", 1)
76+
77+
buildProperties.Set("recipe.preproc.macros", preprocPattern)
6978
}
7079

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

8089
return cmd, nil
8190
}
82-
83-
func GeneratePreprocPatternFromCompile(compilePattern string) string {
84-
// add {preproc.macros.flags}
85-
// replace "{object_file}" with "{preprocessed_file_path}"
86-
returnString := compilePattern
87-
returnString = strings.Replace(returnString, "{compiler.cpp.flags}", "{compiler.cpp.flags} {preproc.macros.flags}", 1)
88-
returnString = strings.Replace(returnString, "{object_file}", "{preprocessed_file_path}", 1)
89-
return returnString
90-
}

‎legacy/builder/hardware/platform.keys.rewrite.txt

Lines changed: 0 additions & 42 deletions
This file was deleted.

‎legacy/builder/platform_keys_rewrite_loader.go

Lines changed: 0 additions & 94 deletions
This file was deleted.

‎legacy/builder/preprocess_sketch.go

Lines changed: 14 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -29,56 +29,30 @@ import (
2929
"github.com/pkg/errors"
3030
)
3131

32-
// ArduinoPreprocessorProperties are the platform properties needed to run arduino-preprocessor
33-
var ArduinoPreprocessorProperties = properties.NewFromHashmap(map[string]string{
34-
// Ctags
35-
"tools.arduino-preprocessor.path": "{runtime.tools.arduino-preprocessor.path}",
36-
"tools.arduino-preprocessor.cmd.path": "{path}/arduino-preprocessor",
37-
"tools.arduino-preprocessor.pattern": `"{cmd.path}" "{source_file}" -- -std=gnu++11`,
38-
39-
"preproc.macros.flags": "-w -x c++ -E -CC",
40-
})
41-
4232
func PreprocessSketchWithArduinoPreprocessor(ctx *types.Context) error {
43-
sourceFile := ctx.SketchBuildPath.Join(ctx.Sketch.MainFile.Base() + ".cpp")
44-
commands := []types.Command{
45-
&ArduinoPreprocessorRunner{},
46-
}
47-
4833
if err := ctx.PreprocPath.MkdirAll(); err != nil {
4934
return errors.WithStack(err)
5035
}
5136

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

54-
for _, command := range commands {
55-
PrintRingNameIfDebug(ctx, command)
56-
err := command.Run(ctx)
57-
if err != nil {
58-
return errors.WithStack(err)
59-
}
60-
}
61-
62-
return bldr.SketchSaveItemCpp(ctx.Sketch.MainFile, []byte(ctx.Source), ctx.SketchBuildPath)
63-
}
64-
65-
type ArduinoPreprocessorRunner struct{}
66-
67-
func (s *ArduinoPreprocessorRunner) Run(ctx *types.Context) error {
68-
buildProperties := ctx.BuildProperties
6940
targetFilePath := ctx.PreprocPath.Join("ctags_target_for_gcc_minus_e.cpp")
70-
71-
preprocProperties := buildProperties.Clone()
72-
toolProps := buildProperties.SubTree("tools").SubTree("arduino-preprocessor")
73-
preprocProperties.Merge(toolProps)
74-
preprocProperties.SetPath("source_file", targetFilePath)
75-
76-
pattern := preprocProperties.Get("pattern")
41+
buildProperties := properties.NewMap()
42+
buildProperties.Set("tools.arduino-preprocessor.path", "{runtime.tools.arduino-preprocessor.path}")
43+
buildProperties.Set("tools.arduino-preprocessor.cmd.path", "{path}/arduino-preprocessor")
44+
buildProperties.Set("tools.arduino-preprocessor.pattern", `"{cmd.path}" "{source_file}" -- -std=gnu++11`)
45+
buildProperties.Set("preproc.macros.flags", "-w -x c++ -E -CC")
46+
buildProperties.Merge(ctx.BuildProperties)
47+
buildProperties.Merge(buildProperties.SubTree("tools").SubTree("arduino-preprocessor"))
48+
buildProperties.SetPath("source_file", targetFilePath)
49+
50+
pattern := buildProperties.Get("pattern")
7751
if pattern == "" {
7852
return errors.New(tr("arduino-preprocessor pattern is missing"))
7953
}
8054

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

10781
//fmt.Printf("PREPROCESSOR OUTPUT:\n%s\n", output)
10882
ctx.Source = string(result)
109-
return nil
83+
84+
return bldr.SketchSaveItemCpp(ctx.Sketch.MainFile, []byte(ctx.Source), ctx.SketchBuildPath)
11085
}

‎legacy/builder/rewrite_hardware_keys.go

Lines changed: 0 additions & 60 deletions
This file was deleted.

‎legacy/builder/test/hardware_loader_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,6 @@ func TestLoadHardwareMixingUserHardwareFolder(t *testing.T) {
8282
commands := []types.Command{
8383
&builder.AddAdditionalEntriesToContext{},
8484
&builder.HardwareLoader{},
85-
&builder.PlatformKeysRewriteLoader{},
86-
&builder.RewriteHardwareKeys{},
8785
}
8886

8987
for _, command := range commands {

‎legacy/builder/test/platform_keys_rewrite_loader_test.go

Lines changed: 0 additions & 60 deletions
This file was deleted.

‎legacy/builder/test/rewrite_hardware_keys_test.go

Lines changed: 0 additions & 109 deletions
This file was deleted.

‎legacy/builder/types/context.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,6 @@ type Context struct {
8888
TargetPlatform *cores.PlatformRelease
8989
ActualPlatform *cores.PlatformRelease
9090

91-
PlatformKeyRewrites PlatforKeysRewrite
92-
HardwareRewriteResults map[*cores.PlatformRelease][]PlatforKeyRewrite
93-
9491
BuildProperties *properties.Map
9592
BuildPath *paths.Path
9693
SketchBuildPath *paths.Path

‎legacy/builder/warn_about_platform_rewrites.go

Lines changed: 0 additions & 49 deletions
This file was deleted.

0 commit comments

Comments
 (0)
Please sign in to comment.