diff --git a/arduino/cores/packagemanager/package_manager.go b/arduino/cores/packagemanager/package_manager.go index f385faf2299..5dfbecf5985 100644 --- a/arduino/cores/packagemanager/package_manager.go +++ b/arduino/cores/packagemanager/package_manager.go @@ -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") { diff --git a/legacy/builder/add_additional_entries_to_context.go b/legacy/builder/add_additional_entries_to_context.go index 64ee1ee8a67..e6ee138855f 100644 --- a/legacy/builder/add_additional_entries_to_context.go +++ b/legacy/builder/add_additional_entries_to_context.go @@ -16,7 +16,6 @@ package builder import ( - "github.com/arduino/arduino-cli/arduino/cores" "github.com/arduino/arduino-cli/legacy/builder/constants" "github.com/arduino/arduino-cli/legacy/builder/types" "github.com/pkg/errors" @@ -57,7 +56,6 @@ func (*AddAdditionalEntriesToContext) Run(ctx *types.Context) error { ctx.CollectedSourceFiles = &types.UniqueSourceFileQueue{} ctx.LibrariesResolutionResults = map[string]types.LibraryResolutionResult{} - ctx.HardwareRewriteResults = map[*cores.PlatformRelease][]types.PlatforKeyRewrite{} return nil } diff --git a/legacy/builder/add_missing_build_properties_from_parent_platform_txt_files.go b/legacy/builder/add_missing_build_properties_from_parent_platform_txt_files.go deleted file mode 100644 index 0cf893b33d8..00000000000 --- a/legacy/builder/add_missing_build_properties_from_parent_platform_txt_files.go +++ /dev/null @@ -1,34 +0,0 @@ -// 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 ( - "github.com/arduino/arduino-cli/legacy/builder/ctags" - "github.com/arduino/arduino-cli/legacy/builder/types" -) - -type AddMissingBuildPropertiesFromParentPlatformTxtFiles struct{} - -func (s *AddMissingBuildPropertiesFromParentPlatformTxtFiles) Run(ctx *types.Context) error { - buildProperties := ctx.BuildProperties - - newBuildProperties := ctags.CtagsProperties.Clone() - newBuildProperties.Merge(ArduinoPreprocessorProperties) - newBuildProperties.Merge(buildProperties) - ctx.BuildProperties = newBuildProperties - - return nil -} diff --git a/legacy/builder/builder.go b/legacy/builder/builder.go index d94308839f0..d73ec778ca7 100644 --- a/legacy/builder/builder.go +++ b/legacy/builder/builder.go @@ -44,8 +44,6 @@ func (s *Builder) Run(ctx *types.Context) error { &ContainerBuildOptions{}, - &WarnAboutPlatformRewrites{}, - &RecipeByPrefixSuffixRunner{Prefix: "recipe.hooks.prebuild", Suffix: ".pattern"}, &ContainerMergeCopySketchFiles{}, diff --git a/legacy/builder/constants/constants.go b/legacy/builder/constants/constants.go index 49229438887..e4b772b00e6 100644 --- a/legacy/builder/constants/constants.go +++ b/legacy/builder/constants/constants.go @@ -33,7 +33,6 @@ const BUILD_PROPERTIES_INCLUDES = "includes" const BUILD_PROPERTIES_OBJECT_FILE = "object_file" const BUILD_PROPERTIES_RUNTIME_PLATFORM_PATH = "runtime.platform.path" const EMPTY_STRING = "" -const FILE_PLATFORM_KEYS_REWRITE_TXT = "platform.keys.rewrite.txt" const FOLDER_BOOTLOADERS = "bootloaders" const FOLDER_CORE = "core" const FOLDER_PREPROC = "preproc" @@ -52,15 +51,10 @@ const LOG_LEVEL_WARN = "warn" const PACKAGE_NAME = "name" const PACKAGE_TOOLS = "tools" const PLATFORM_ARCHITECTURE = "architecture" -const PLATFORM_NAME = "name" -const PLATFORM_REWRITE_NEW = "new" -const PLATFORM_REWRITE_OLD = "old" const PLATFORM_URL = "url" const PLATFORM_VERSION = "version" const RECIPE_AR_PATTERN = "recipe.ar.pattern" const RECIPE_C_COMBINE_PATTERN = "recipe.c.combine.pattern" -const REWRITING_DISABLED = "disabled" -const REWRITING = "rewriting" const SPACE = " " const TOOL_NAME = "name" const TOOL_URL = "url" diff --git a/legacy/builder/container_setup.go b/legacy/builder/container_setup.go index 1b76ad8eb1d..a89434db90a 100644 --- a/legacy/builder/container_setup.go +++ b/legacy/builder/container_setup.go @@ -31,8 +31,6 @@ func (s *ContainerSetupHardwareToolsLibsSketchAndProps) Run(ctx *types.Context) &AddAdditionalEntriesToContext{}, &FailIfBuildPathEqualsSketchPath{}, &HardwareLoader{}, - &PlatformKeysRewriteLoader{}, - &RewriteHardwareKeys{}, &TargetBoardResolver{}, &LibrariesLoader{}, } @@ -53,7 +51,6 @@ func (s *ContainerSetupHardwareToolsLibsSketchAndProps) Run(ctx *types.Context) commands = []types.Command{ &SetupBuildProperties{}, &SetCustomBuildProperties{}, - &AddMissingBuildPropertiesFromParentPlatformTxtFiles{}, } for _, command := range commands { diff --git a/legacy/builder/ctags/ctags_properties.go b/legacy/builder/ctags/ctags_properties.go deleted file mode 100644 index 29c4d4833c1..00000000000 --- a/legacy/builder/ctags/ctags_properties.go +++ /dev/null @@ -1,33 +0,0 @@ -// 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 ctags - -import properties "github.com/arduino/go-properties-orderedmap" - -// CtagsProperties are the platform properties needed to run ctags -var CtagsProperties = properties.NewFromHashmap(map[string]string{ - // Ctags - "tools.ctags.path": "{runtime.tools.ctags.path}", - "tools.ctags.cmd.path": "{path}/ctags", - "tools.ctags.pattern": `"{cmd.path}" -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives "{source_file}"`, - - // additional entries - "tools.avrdude.path": "{runtime.tools.avrdude.path}", - - "preproc.macros.flags": "-w -x c++ -E -CC", - //"preproc.macros.compatibility_flags": `{build.mbed_api_include} {build.nRF51822_api_include} {build.ble_api_include} {compiler.libsam.c.flags} {compiler.arm.cmsis.path} {build.variant_system_include}`, - //"recipe.preproc.macros": `"{compiler.path}{compiler.cpp.cmd}" {compiler.cpreprocessor.flags} {compiler.cpp.flags} {preproc.macros.flags} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.cpp.extra_flags} {build.extra_flags} {preproc.macros.compatibility_flags} {includes} "{source_file}" -o "{preprocessed_file_path}"`, -}) diff --git a/legacy/builder/ctags_runner.go b/legacy/builder/ctags_runner.go index 998cbdf0902..2e42bdca234 100644 --- a/legacy/builder/ctags_runner.go +++ b/legacy/builder/ctags_runner.go @@ -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) diff --git a/legacy/builder/gcc_preproc_runner.go b/legacy/builder/gcc_preproc_runner.go index 7a87d07c1f4..c1118d5889c 100644 --- a/legacy/builder/gcc_preproc_runner.go +++ b/legacy/builder/gcc_preproc_runner.go @@ -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" ) @@ -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) } @@ -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 -} diff --git a/legacy/builder/hardware/platform.keys.rewrite.txt b/legacy/builder/hardware/platform.keys.rewrite.txt deleted file mode 100644 index 4e8c93fbb44..00000000000 --- a/legacy/builder/hardware/platform.keys.rewrite.txt +++ /dev/null @@ -1,42 +0,0 @@ -old.0.compiler.path={runtime.ide.path}/hardware/tools/avr/bin/ -new.0.compiler.path={runtime.tools.avr-gcc.path}/bin/ - -old.1.tools.avrdude.cmd.path={runtime.ide.path}/hardware/tools/avr/bin/avrdude -new.1.tools.avrdude.cmd.path={path}/bin/avrdude - -old.2.tools.avrdude.config.path={runtime.ide.path}/hardware/tools/avr/etc/avrdude.conf -new.2.tools.avrdude.config.path={path}/etc/avrdude.conf - -old.3.compiler.path={runtime.ide.path}/hardware/tools/gcc-arm-none-eabi-4.8.3-2014q1/bin/ -new.3.compiler.path={runtime.tools.arm-none-eabi-gcc.path}/bin/ - -old.4.tools.bossac.path={runtime.ide.path}/hardware/tools -new.4.tools.bossac.path={runtime.tools.bossac.path} - -old.5.recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" {compiler.c.elf.flags} -mcpu={build.mcu} "-T{build.variant.path}/{build.ldscript}" "-Wl,-Map,{build.path}/{build.project_name}.map" {compiler.c.elf.extra_flags} -o "{build.path}/{build.project_name}.elf" "-L{build.path}" -mthumb -Wl,--cref -Wl,--check-sections -Wl,--gc-sections -Wl,--entry=Reset_Handler -Wl,--unresolved-symbols=report-all -Wl,--warn-common -Wl,--warn-section-align -Wl,--warn-unresolved-symbols -Wl,--start-group "{build.path}/syscalls_sam3.c.o" {object_files} "{build.variant.path}/{build.variant_system_lib}" "{build.path}/{archive_file}" -Wl,--end-group -lm -gcc -new.5.recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" {compiler.c.elf.flags} -mcpu={build.mcu} "-T{build.variant.path}/{build.ldscript}" "-Wl,-Map,{build.path}/{build.project_name}.map" {compiler.c.elf.extra_flags} -o "{build.path}/{build.project_name}.elf" "-L{build.path}" -mthumb -Wl,--cref -Wl,--check-sections -Wl,--gc-sections -Wl,--entry=Reset_Handler -Wl,--unresolved-symbols=report-all -Wl,--warn-common -Wl,--warn-section-align -Wl,--warn-unresolved-symbols -Wl,--start-group "{build.path}/core/syscalls_sam3.c.o" {object_files} "{build.variant.path}/{build.variant_system_lib}" "{build.path}/{archive_file}" -Wl,--end-group -lm -gcc - -#specific to RedBearLab nRF51822 Boards -old.6.recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" -mcpu={build.mcu} -mthumb -Wl,--gc-sections --specs=nano.specs -Wl,--wrap,main -Wl,-Map={build.path}/{build.project_name}.map,--cref "-T{build.variant.path}/{build.ldscript}" -o "{build.path}/{build.project_name}.elf" -Wl,--start-group "{build.path}/system_nrf51.c.o" {object_files} "{build.path}/startup_NRF51822.s.o" "{build.path}/{archive_file}" -Wl,--end-group -lstdc++ -lsupc++ -lm -lc -lgcc -lnosys -new.6.recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" -mcpu={build.mcu} -mthumb -Wl,--gc-sections --specs=nano.specs -Wl,--wrap,main -Wl,-Map={build.path}/{build.project_name}.map,--cref "-T{build.variant.path}/{build.ldscript}" -o "{build.path}/{build.project_name}.elf" -Wl,--start-group "{build.path}/core/mbed/targets/cmsis/TARGET_NORDIC/TARGET_MCU_NRF51822/system_nrf51.c.o" {object_files} "{build.path}/core/startup_NRF51822.S.o" "{build.path}/{archive_file}" -Wl,--end-group -lstdc++ -lsupc++ -lm -lc -lgcc -lnosys - -#specific to RFduino 1.6.3 -old.7.recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" {compiler.c.elf.flags} -mcpu={build.mcu} {build.extra_flags} "-T{build.variant.path}/{build.ldscript}" "-Wl,-Map,{build.path}/{build.project_name}.map" -Wl,--cref -o "{build.path}/{build.project_name}.elf" "-L{build.path}" -Wl,--warn-common -Wl,--warn-section-align -Wl,--start-group "{build.path}/syscalls.c.o" {object_files} "{build.variant.path}/{build.variant_system_lib}" "{build.variant.path}/libRFduino.a" "{build.variant.path}/libRFduinoBLE.a" "{build.variant.path}/libRFduinoGZLL.a" "{build.path}/{archive_file}" -Wl,--end-group -new.7.recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" {compiler.c.elf.flags} -mcpu={build.mcu} {build.extra_flags} "-T{build.variant.path}/{build.ldscript}" "-Wl,-Map,{build.path}/{build.project_name}.map" -Wl,--cref -o "{build.path}/{build.project_name}.elf" "-L{build.path}" -Wl,--warn-common -Wl,--warn-section-align -Wl,--start-group "{build.path}/core/syscalls.c.o" {object_files} "{build.variant.path}/{build.variant_system_lib}" "{build.variant.path}/libRFduino.a" "{build.variant.path}/libRFduinoBLE.a" "{build.variant.path}/libRFduinoGZLL.a" "{build.path}/{archive_file}" -Wl,--end-group - -old.8.recipe.ar.pattern="{compiler.path}{compiler.ar.cmd}" {compiler.ar.flags} {compiler.ar.extra_flags} "{build.path}/{archive_file}" "{object_file}" -new.8.recipe.ar.pattern="{compiler.path}{compiler.ar.cmd}" {compiler.ar.flags} {compiler.ar.extra_flags} "{archive_file_path}" "{object_file}" - -old.9.recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" {compiler.c.elf.flags} -mcpu={build.mcu} "-T{build.variant.path}/{build.ldscript}" "-Wl,-Map,{build.path}/{build.project_name}.map" {compiler.c.elf.extra_flags} -o "{build.path}/{build.project_name}.elf" "-L{build.path}" -mthumb -Wl,--cref -Wl,--check-sections -Wl,--gc-sections -Wl,--entry=Reset_Handler -Wl,--unresolved-symbols=report-all -Wl,--warn-common -Wl,--warn-section-align -Wl,--start-group "{build.path}/syscalls_sam3.c.o" {object_files} "{build.variant.path}/{build.variant_system_lib}" "{build.path}/{archive_file}" -Wl,--end-group -lm -gcc -new.9.recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" {compiler.c.elf.flags} -mcpu={build.mcu} "-T{build.variant.path}/{build.ldscript}" "-Wl,-Map,{build.path}/{build.project_name}.map" {compiler.c.elf.extra_flags} -o "{build.path}/{build.project_name}.elf" "-L{build.path}" -mthumb -Wl,--cref -Wl,--check-sections -Wl,--gc-sections -Wl,--entry=Reset_Handler -Wl,--unresolved-symbols=report-all -Wl,--warn-common -Wl,--warn-section-align -Wl,--start-group "{build.path}/core/syscalls_sam3.c.o" {object_files} "{build.variant.path}/{build.variant_system_lib}" "{build.path}/{archive_file}" -Wl,--end-group -lm -gcc - -#specific to Digistump AVR Boards 1.5.4 -old.10.recipe.ar.pattern="{compiler.path}{compiler.ar.cmd}" {compiler.ar.flags} "{build.path}/{archive_file}" "{object_file}" -new.10.recipe.ar.pattern="{compiler.path}{compiler.ar.cmd}" {compiler.ar.flags} "{archive_file_path}" "{object_file}" - -old.11.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} "{build.path}/{archive_file}" "-L{build.path}" -lm -new.11.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} "{archive_file_path}" "-L{build.path}" -lm - -#generic again -old.12.recipe.preproc.macros="{compiler.path}{compiler.cpp.cmd}" {compiler.cpp.flags} {preproc.macros.flags} -mmcu={build.mcu} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.cpp.extra_flags} {build.extra_flags} {includes} "{source_file}" -new.12.recipe.preproc.macros="{compiler.path}{compiler.cpp.cmd}" {compiler.cpp.flags} {preproc.macros.flags} -mmcu={build.mcu} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.cpp.extra_flags} {build.extra_flags} {includes} "{source_file}" -o "{preprocessed_file_path}" \ No newline at end of file diff --git a/legacy/builder/platform_keys_rewrite_loader.go b/legacy/builder/platform_keys_rewrite_loader.go deleted file mode 100644 index 31709971c29..00000000000 --- a/legacy/builder/platform_keys_rewrite_loader.go +++ /dev/null @@ -1,94 +0,0 @@ -// 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 ( - "sort" - "strconv" - "strings" - - "github.com/arduino/arduino-cli/legacy/builder/constants" - "github.com/arduino/arduino-cli/legacy/builder/types" - "github.com/arduino/go-paths-helper" - "github.com/arduino/go-properties-orderedmap" - "github.com/pkg/errors" -) - -type PlatformKeysRewriteLoader struct{} - -func (s *PlatformKeysRewriteLoader) Run(ctx *types.Context) error { - folders := ctx.HardwareDirs - - platformKeysRewriteTxtPath, err := findPlatformKeysRewriteTxt(folders) - if err != nil { - return errors.WithStack(err) - } - if platformKeysRewriteTxtPath == nil { - return nil - } - - platformKeysRewrite := types.PlatforKeysRewrite{} - platformKeysRewrite.Rewrites = []types.PlatforKeyRewrite{} - - txt, err := properties.LoadFromPath(platformKeysRewriteTxtPath) - if err != nil { - return errors.WithStack(err) - } - keys := txt.Keys() - sort.Strings(keys) - - for _, key := range keys { - keyParts := strings.Split(key, ".") - if keyParts[0] == constants.PLATFORM_REWRITE_OLD { - index, err := strconv.Atoi(keyParts[1]) - if err != nil { - return errors.WithStack(err) - } - rewriteKey := strings.Join(keyParts[2:], ".") - oldValue := txt.Get(key) - newValue := txt.Get(constants.PLATFORM_REWRITE_NEW + "." + strings.Join(keyParts[1:], ".")) - platformKeyRewrite := types.PlatforKeyRewrite{Key: rewriteKey, OldValue: oldValue, NewValue: newValue} - platformKeysRewrite.Rewrites = growSliceOfRewrites(platformKeysRewrite.Rewrites, index) - platformKeysRewrite.Rewrites[index] = platformKeyRewrite - } - } - - ctx.PlatformKeyRewrites = platformKeysRewrite - - return nil -} - -func findPlatformKeysRewriteTxt(folders paths.PathList) (*paths.Path, error) { - for _, folder := range folders { - txtPath := folder.Join(constants.FILE_PLATFORM_KEYS_REWRITE_TXT) - if exist, err := txtPath.ExistCheck(); exist { - return txtPath, nil - } else if err != nil { - return nil, errors.WithStack(err) - } - } - - return nil, nil -} - -func growSliceOfRewrites(originalSlice []types.PlatforKeyRewrite, maxIndex int) []types.PlatforKeyRewrite { - if cap(originalSlice) > maxIndex { - return originalSlice - } - newSlice := make([]types.PlatforKeyRewrite, maxIndex+1) - copy(newSlice, originalSlice) - return newSlice -} diff --git a/legacy/builder/preprocess_sketch.go b/legacy/builder/preprocess_sketch.go index 27d86b0f974..31c19ca3bc1 100644 --- a/legacy/builder/preprocess_sketch.go +++ b/legacy/builder/preprocess_sketch.go @@ -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) @@ -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) } diff --git a/legacy/builder/rewrite_hardware_keys.go b/legacy/builder/rewrite_hardware_keys.go deleted file mode 100644 index 0218a8f4aff..00000000000 --- a/legacy/builder/rewrite_hardware_keys.go +++ /dev/null @@ -1,60 +0,0 @@ -// 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 ( - "github.com/arduino/arduino-cli/arduino/cores" - "github.com/arduino/arduino-cli/legacy/builder/constants" - "github.com/arduino/arduino-cli/legacy/builder/types" -) - -type RewriteHardwareKeys struct{} - -func (s *RewriteHardwareKeys) Run(ctx *types.Context) error { - if ctx.PlatformKeyRewrites.Empty() { - return nil - } - - packages := ctx.Hardware - platformKeysRewrite := ctx.PlatformKeyRewrites - hardwareRewriteResults := ctx.HardwareRewriteResults - - for _, aPackage := range packages { - for _, platform := range aPackage.Platforms { - for _, platformRelease := range platform.Releases { - if platformRelease.Properties.Get(constants.REWRITING) != constants.REWRITING_DISABLED { - for _, rewrite := range platformKeysRewrite.Rewrites { - if platformRelease.Properties.Get(rewrite.Key) == rewrite.OldValue { - platformRelease.Properties.Set(rewrite.Key, rewrite.NewValue) - appliedRewrites := rewritesAppliedToPlatform(platformRelease, hardwareRewriteResults) - appliedRewrites = append(appliedRewrites, rewrite) - hardwareRewriteResults[platformRelease] = appliedRewrites - } - } - } - } - } - } - - return nil -} - -func rewritesAppliedToPlatform(platform *cores.PlatformRelease, hardwareRewriteResults map[*cores.PlatformRelease][]types.PlatforKeyRewrite) []types.PlatforKeyRewrite { - if hardwareRewriteResults[platform] == nil { - hardwareRewriteResults[platform] = []types.PlatforKeyRewrite{} - } - return hardwareRewriteResults[platform] -} diff --git a/legacy/builder/test/hardware_loader_test.go b/legacy/builder/test/hardware_loader_test.go index 74a8bf80f10..e0cd7148b3a 100644 --- a/legacy/builder/test/hardware_loader_test.go +++ b/legacy/builder/test/hardware_loader_test.go @@ -82,8 +82,6 @@ func TestLoadHardwareMixingUserHardwareFolder(t *testing.T) { commands := []types.Command{ &builder.AddAdditionalEntriesToContext{}, &builder.HardwareLoader{}, - &builder.PlatformKeysRewriteLoader{}, - &builder.RewriteHardwareKeys{}, } for _, command := range commands { diff --git a/legacy/builder/test/platform_keys_rewrite_loader_test.go b/legacy/builder/test/platform_keys_rewrite_loader_test.go deleted file mode 100644 index 80a7190c242..00000000000 --- a/legacy/builder/test/platform_keys_rewrite_loader_test.go +++ /dev/null @@ -1,60 +0,0 @@ -// 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 test - -import ( - "path/filepath" - "testing" - - "github.com/arduino/arduino-cli/legacy/builder" - "github.com/arduino/arduino-cli/legacy/builder/types" - paths "github.com/arduino/go-paths-helper" - "github.com/stretchr/testify/require" -) - -func TestLoadPlatformKeysRewrite(t *testing.T) { - ctx := &types.Context{ - HardwareDirs: paths.NewPathList("downloaded_hardware", filepath.Join("..", "hardware")), - } - - commands := []types.Command{ - &builder.PlatformKeysRewriteLoader{}, - } - - for _, command := range commands { - err := command.Run(ctx) - NoError(t, err) - } - - platformKeysRewrite := ctx.PlatformKeyRewrites - - require.Equal(t, 13, len(platformKeysRewrite.Rewrites)) - require.Equal(t, "compiler.path", platformKeysRewrite.Rewrites[0].Key) - require.Equal(t, "{runtime.ide.path}/hardware/tools/avr/bin/", platformKeysRewrite.Rewrites[0].OldValue) - require.Equal(t, "{runtime.tools.avr-gcc.path}/bin/", platformKeysRewrite.Rewrites[0].NewValue) - - require.Equal(t, "tools.avrdude.cmd.path", platformKeysRewrite.Rewrites[1].Key) - require.Equal(t, "{runtime.ide.path}/hardware/tools/avr/bin/avrdude", platformKeysRewrite.Rewrites[1].OldValue) - require.Equal(t, "{path}/bin/avrdude", platformKeysRewrite.Rewrites[1].NewValue) - - require.Equal(t, "compiler.path", platformKeysRewrite.Rewrites[3].Key) - require.Equal(t, "{runtime.ide.path}/hardware/tools/gcc-arm-none-eabi-4.8.3-2014q1/bin/", platformKeysRewrite.Rewrites[3].OldValue) - require.Equal(t, "{runtime.tools.arm-none-eabi-gcc.path}/bin/", platformKeysRewrite.Rewrites[3].NewValue) - - require.Equal(t, "recipe.c.combine.pattern", platformKeysRewrite.Rewrites[5].Key) - require.Equal(t, "\"{compiler.path}{compiler.c.elf.cmd}\" {compiler.c.elf.flags} -mcpu={build.mcu} \"-T{build.variant.path}/{build.ldscript}\" \"-Wl,-Map,{build.path}/{build.project_name}.map\" {compiler.c.elf.extra_flags} -o \"{build.path}/{build.project_name}.elf\" \"-L{build.path}\" -mthumb -Wl,--cref -Wl,--check-sections -Wl,--gc-sections -Wl,--entry=Reset_Handler -Wl,--unresolved-symbols=report-all -Wl,--warn-common -Wl,--warn-section-align -Wl,--warn-unresolved-symbols -Wl,--start-group \"{build.path}/syscalls_sam3.c.o\" {object_files} \"{build.variant.path}/{build.variant_system_lib}\" \"{build.path}/{archive_file}\" -Wl,--end-group -lm -gcc", platformKeysRewrite.Rewrites[5].OldValue) - require.Equal(t, "\"{compiler.path}{compiler.c.elf.cmd}\" {compiler.c.elf.flags} -mcpu={build.mcu} \"-T{build.variant.path}/{build.ldscript}\" \"-Wl,-Map,{build.path}/{build.project_name}.map\" {compiler.c.elf.extra_flags} -o \"{build.path}/{build.project_name}.elf\" \"-L{build.path}\" -mthumb -Wl,--cref -Wl,--check-sections -Wl,--gc-sections -Wl,--entry=Reset_Handler -Wl,--unresolved-symbols=report-all -Wl,--warn-common -Wl,--warn-section-align -Wl,--warn-unresolved-symbols -Wl,--start-group \"{build.path}/core/syscalls_sam3.c.o\" {object_files} \"{build.variant.path}/{build.variant_system_lib}\" \"{build.path}/{archive_file}\" -Wl,--end-group -lm -gcc", platformKeysRewrite.Rewrites[5].NewValue) -} diff --git a/legacy/builder/test/rewrite_hardware_keys_test.go b/legacy/builder/test/rewrite_hardware_keys_test.go deleted file mode 100644 index 596ee1a6a66..00000000000 --- a/legacy/builder/test/rewrite_hardware_keys_test.go +++ /dev/null @@ -1,109 +0,0 @@ -// 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 test - -import ( - "testing" - - "github.com/arduino/arduino-cli/arduino/cores" - "github.com/arduino/arduino-cli/legacy/builder" - "github.com/arduino/arduino-cli/legacy/builder/types" - properties "github.com/arduino/go-properties-orderedmap" - "github.com/stretchr/testify/require" - semver "go.bug.st/relaxed-semver" -) - -func TestRewriteHardwareKeys(t *testing.T) { - ctx := &types.Context{} - - packages := cores.Packages{} - aPackage := &cores.Package{Name: "dummy"} - packages["dummy"] = aPackage - aPackage.Platforms = map[string]*cores.Platform{} - - platform := &cores.PlatformRelease{ - Properties: properties.NewFromHashmap(map[string]string{ - "name": "A test platform", - "compiler.path": "{runtime.ide.path}/hardware/tools/avr/bin/", - }), - } - aPackage.Platforms["dummy"] = &cores.Platform{ - Architecture: "dummy", - Releases: map[semver.NormalizedString]*cores.PlatformRelease{ - "": platform, - }, - } - - ctx.Hardware = packages - - rewrite := types.PlatforKeyRewrite{Key: "compiler.path", OldValue: "{runtime.ide.path}/hardware/tools/avr/bin/", NewValue: "{runtime.tools.avr-gcc.path}/bin/"} - platformKeysRewrite := types.PlatforKeysRewrite{Rewrites: []types.PlatforKeyRewrite{rewrite}} - ctx.PlatformKeyRewrites = platformKeysRewrite - - commands := []types.Command{ - &builder.AddAdditionalEntriesToContext{}, - &builder.RewriteHardwareKeys{}, - } - - for _, command := range commands { - err := command.Run(ctx) - NoError(t, err) - } - - require.Equal(t, "{runtime.tools.avr-gcc.path}/bin/", platform.Properties.Get("compiler.path")) -} - -func TestRewriteHardwareKeysWithRewritingDisabled(t *testing.T) { - ctx := &types.Context{} - - packages := cores.Packages{} - aPackage := &cores.Package{Name: "dummy"} - packages["dummy"] = aPackage - aPackage.Platforms = make(map[string]*cores.Platform) - - platform := &cores.PlatformRelease{ - Properties: properties.NewFromHashmap(map[string]string{ - "name": "A test platform", - "compiler.path": "{runtime.ide.path}/hardware/tools/avr/bin/", - "rewriting": "disabled", - }), - } - aPackage.Platforms["dummy"] = &cores.Platform{ - Architecture: "dummy", - Releases: map[semver.NormalizedString]*cores.PlatformRelease{ - "": platform, - }, - } - - ctx.Hardware = packages - - rewrite := types.PlatforKeyRewrite{Key: "compiler.path", OldValue: "{runtime.ide.path}/hardware/tools/avr/bin/", NewValue: "{runtime.tools.avr-gcc.path}/bin/"} - platformKeysRewrite := types.PlatforKeysRewrite{Rewrites: []types.PlatforKeyRewrite{rewrite}} - - ctx.PlatformKeyRewrites = platformKeysRewrite - - commands := []types.Command{ - &builder.AddAdditionalEntriesToContext{}, - &builder.RewriteHardwareKeys{}, - } - - for _, command := range commands { - err := command.Run(ctx) - NoError(t, err) - } - - require.Equal(t, "{runtime.ide.path}/hardware/tools/avr/bin/", platform.Properties.Get("compiler.path")) -} diff --git a/legacy/builder/types/context.go b/legacy/builder/types/context.go index 6af1fb72104..ebf85b19f39 100644 --- a/legacy/builder/types/context.go +++ b/legacy/builder/types/context.go @@ -88,9 +88,6 @@ type Context struct { TargetPlatform *cores.PlatformRelease ActualPlatform *cores.PlatformRelease - PlatformKeyRewrites PlatforKeysRewrite - HardwareRewriteResults map[*cores.PlatformRelease][]PlatforKeyRewrite - BuildProperties *properties.Map BuildPath *paths.Path SketchBuildPath *paths.Path diff --git a/legacy/builder/warn_about_platform_rewrites.go b/legacy/builder/warn_about_platform_rewrites.go deleted file mode 100644 index 6349ff9e276..00000000000 --- a/legacy/builder/warn_about_platform_rewrites.go +++ /dev/null @@ -1,49 +0,0 @@ -// 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 ( - "github.com/arduino/arduino-cli/arduino/cores" - "github.com/arduino/arduino-cli/legacy/builder/constants" - "github.com/arduino/arduino-cli/legacy/builder/types" -) - -type WarnAboutPlatformRewrites struct{} - -func (s *WarnAboutPlatformRewrites) Run(ctx *types.Context) error { - hardwareRewriteResults := ctx.HardwareRewriteResults - targetPlatform := ctx.TargetPlatform - actualPlatform := ctx.ActualPlatform - - platforms := []*cores.PlatformRelease{targetPlatform} - if actualPlatform != targetPlatform { - platforms = append(platforms, actualPlatform) - } - - for _, platform := range platforms { - if hardwareRewriteResults[platform] != nil { - for _, rewrite := range hardwareRewriteResults[platform] { - ctx.Info( - tr("Warning: platform.txt from core '%[1]s' contains deprecated %[2]s, automatically converted to %[3]s. Consider upgrading this core.", - platform.Properties.Get(constants.PLATFORM_NAME), - rewrite.Key+"="+rewrite.OldValue, - rewrite.Key+"="+rewrite.NewValue)) - } - } - } - - return nil -}