From da86fe8cfc6ac004baae2a01fb851037b916ad21 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Wed, 20 Jan 2016 15:39:44 +0100 Subject: [PATCH 01/25] Introducing types.Context structure For now it is used in conjunction with the old map[string]string, but it will be slowly populated with all the fields currently used in the map in the next commits. When the migration will be completed the old map will be removed. Signed-off-by: Cristian Maglie --- .../add_additional_entries_to_context.go | 2 +- .../add_build_board_property_if_missing.go | 2 +- ...operties_from_parent_platform_txt_files.go | 2 +- .../builder/additional_sketch_files_copier.go | 2 +- src/arduino.cc/builder/builder.go | 30 +++++----- src/arduino.cc/builder/coan_runner.go | 3 +- ..._source_files_from_folders_with_sources.go | 2 +- .../collect_ctags_from_sketch_files.go | 2 +- .../builder/container_add_prototypes.go | 4 +- .../builder/container_build_options.go | 4 +- .../builder/container_find_includes.go | 24 ++++---- .../container_merge_copy_sketch_files.go | 4 +- src/arduino.cc/builder/container_setup.go | 4 +- .../builder/create_build_options_map.go | 3 +- src/arduino.cc/builder/ctags/ctags_parser.go | 2 +- src/arduino.cc/builder/ctags/ctags_runner.go | 3 +- .../builder/ctags/ctags_to_prototypes.go | 2 +- .../builder/ctags_target_file_saver.go | 3 +- .../builder/dump_build_properties.go | 3 +- .../builder/ensure_buildpath_exists.go | 3 +- .../fail_if_buildpath_equals_sketchpath.go | 3 +- .../fail_if_imported_library_is_wrong.go | 2 +- src/arduino.cc/builder/gcc_preproc_runner.go | 4 +- .../builder/generate_buildpath_if_missing.go | 3 +- src/arduino.cc/builder/hardware_loader.go | 2 +- .../builder/includes_finder_with_regexp.go | 3 +- .../builder/includes_to_include_folders.go | 2 +- src/arduino.cc/builder/libraries_loader.go | 2 +- .../builder/load_previous_build_options.go | 3 +- .../load_vid_pid_specific_properties.go | 3 +- .../builder/merge_sketch_with_bootloader.go | 2 +- src/arduino.cc/builder/phases/core_builder.go | 3 +- .../builder/phases/libraries_builder.go | 2 +- src/arduino.cc/builder/phases/linker.go | 3 +- .../builder/phases/sketch_builder.go | 3 +- .../builder/platform_keys_rewrite_loader.go | 2 +- .../builder/print_preprocessed_source.go | 3 +- .../print_used_and_not_used_libraries.go | 2 +- .../print_used_libraries_if_verbose.go | 2 +- src/arduino.cc/builder/prototypes_adder.go | 2 +- .../builder/read_file_and_store_in_context.go | 3 +- src/arduino.cc/builder/recipe_runner.go | 3 +- .../builder/rewrite_hardware_keys.go | 2 +- .../builder/set_custom_build_properties.go | 3 +- .../builder/setup_build_properties.go | 2 +- .../builder/setup_human_logger_if_missing.go | 3 +- src/arduino.cc/builder/sketch_loader.go | 2 +- src/arduino.cc/builder/sketch_saver.go | 2 +- .../builder/sketch_source_merger.go | 2 +- .../builder/store_build_options_map.go | 3 +- .../builder/target_board_resolver.go | 2 +- .../add_additional_entries_to_context_test.go | 6 +- ...dd_build_board_property_if_missing_test.go | 6 +- .../additional_sketch_files_copier_test.go | 8 ++- src/arduino.cc/builder/test/builder_test.go | 36 +++++++---- .../builder/test/coan_runner_test.go | 3 +- ...ce_files_from_folders_with_sources_test.go | 9 ++- .../test/create_build_options_map_test.go | 4 +- .../builder/test/ctags_parser_test.go | 42 ++++++++----- .../builder/test/ctags_runner_test.go | 15 +++-- .../builder/test/ctags_to_prototypes_test.go | 42 ++++++++----- ...ail_if_buildpath_equals_sketchpath_test.go | 7 ++- .../generate_buildpath_if_missing_test.go | 12 ++-- .../builder/test/hardware_loader_test.go | 12 ++-- src/arduino.cc/builder/test/helper.go | 2 +- .../test/includes_finder_with_gcc_test.go | 17 ++++-- .../test/includes_finder_with_regexp_test.go | 21 ++++--- .../test/includes_to_include_folders_test.go | 21 ++++--- .../builder/test/libraries_loader_test.go | 12 ++-- .../load_previous_build_options_map_test.go | 7 ++- .../load_vid_pid_specific_properties_test.go | 6 +- .../test/merge_sketch_with_bootloader_test.go | 14 +++-- .../test/platform_keys_rewrite_loader_test.go | 3 +- .../builder/test/prototypes_adder_test.go | 60 ++++++++++++------- .../read_file_and_store_in_context_test.go | 4 +- .../builder/test/recipe_runner_test.go | 3 +- .../test/rewrite_hardware_keys_test.go | 6 +- .../test/setup_build_properties_test.go | 12 ++-- .../setup_human_logger_if_missing_test.go | 4 +- .../builder/test/sketch_loader_test.go | 27 +++++---- .../builder/test/sketch_source_merger_test.go | 3 +- .../test/store_build_options_map_test.go | 3 +- .../test/target_board_resolver_test.go | 18 ++++-- .../builder/test/tools_loader_test.go | 9 ++- .../try_build_of_problematic_sketch_test.go | 34 ++++++----- .../unused_compiled_libraries_remover_test.go | 9 ++- ...uild_path_if_build_options_changed_test.go | 9 ++- src/arduino.cc/builder/tools_loader.go | 2 +- src/arduino.cc/builder/types/context.go | 10 ++++ src/arduino.cc/builder/types/types.go | 8 +-- .../unused_compiled_libraries_remover.go | 2 +- .../warn_about_arch_incompatible_libraries.go | 2 +- .../builder/warn_about_platform_rewrites.go | 2 +- ...out_build_path_if_build_options_changed.go | 3 +- 94 files changed, 453 insertions(+), 264 deletions(-) create mode 100644 src/arduino.cc/builder/types/context.go diff --git a/src/arduino.cc/builder/add_additional_entries_to_context.go b/src/arduino.cc/builder/add_additional_entries_to_context.go index 742c0be1..f2926adb 100644 --- a/src/arduino.cc/builder/add_additional_entries_to_context.go +++ b/src/arduino.cc/builder/add_additional_entries_to_context.go @@ -38,7 +38,7 @@ import ( type AddAdditionalEntriesToContext struct{} -func (s *AddAdditionalEntriesToContext) Run(context map[string]interface{}) error { +func (s *AddAdditionalEntriesToContext) Run(context map[string]interface{}, ctx *types.Context) error { if utils.MapHas(context, constants.CTX_BUILD_PATH) { buildPath := context[constants.CTX_BUILD_PATH].(string) preprocPath, err := filepath.Abs(filepath.Join(buildPath, constants.FOLDER_PREPROC)) diff --git a/src/arduino.cc/builder/add_build_board_property_if_missing.go b/src/arduino.cc/builder/add_build_board_property_if_missing.go index b819a424..9384fd92 100644 --- a/src/arduino.cc/builder/add_build_board_property_if_missing.go +++ b/src/arduino.cc/builder/add_build_board_property_if_missing.go @@ -39,7 +39,7 @@ import ( type AddBuildBoardPropertyIfMissing struct{} -func (s *AddBuildBoardPropertyIfMissing) Run(context map[string]interface{}) error { +func (s *AddBuildBoardPropertyIfMissing) Run(context map[string]interface{}, ctx *types.Context) error { packages := context[constants.CTX_HARDWARE].(*types.Packages) logger := context[constants.CTX_LOGGER].(i18n.Logger) diff --git a/src/arduino.cc/builder/add_missing_build_properties_from_parent_platform_txt_files.go b/src/arduino.cc/builder/add_missing_build_properties_from_parent_platform_txt_files.go index bf268070..ec531049 100644 --- a/src/arduino.cc/builder/add_missing_build_properties_from_parent_platform_txt_files.go +++ b/src/arduino.cc/builder/add_missing_build_properties_from_parent_platform_txt_files.go @@ -37,7 +37,7 @@ import ( type AddMissingBuildPropertiesFromParentPlatformTxtFiles struct{} -func (s *AddMissingBuildPropertiesFromParentPlatformTxtFiles) Run(context map[string]interface{}) error { +func (s *AddMissingBuildPropertiesFromParentPlatformTxtFiles) Run(context map[string]interface{}, ctx *types.Context) error { packages := context[constants.CTX_HARDWARE].(*types.Packages) targetPackage := context[constants.CTX_TARGET_PACKAGE].(*types.Package) buildProperties := context[constants.CTX_BUILD_PROPERTIES].(props.PropertiesMap) diff --git a/src/arduino.cc/builder/additional_sketch_files_copier.go b/src/arduino.cc/builder/additional_sketch_files_copier.go index 2bceb723..a40c9205 100644 --- a/src/arduino.cc/builder/additional_sketch_files_copier.go +++ b/src/arduino.cc/builder/additional_sketch_files_copier.go @@ -40,7 +40,7 @@ import ( type AdditionalSketchFilesCopier struct{} -func (s *AdditionalSketchFilesCopier) Run(context map[string]interface{}) error { +func (s *AdditionalSketchFilesCopier) Run(context map[string]interface{}, ctx *types.Context) error { sketch := context[constants.CTX_SKETCH].(*types.Sketch) sketchBuildPath := context[constants.CTX_SKETCH_BUILD_PATH].(string) diff --git a/src/arduino.cc/builder/builder.go b/src/arduino.cc/builder/builder.go index 9fb4206f..eab85491 100644 --- a/src/arduino.cc/builder/builder.go +++ b/src/arduino.cc/builder/builder.go @@ -66,7 +66,7 @@ const DEFAULT_BUILD_CORE = "arduino" type Builder struct{} -func (s *Builder) Run(context map[string]interface{}) error { +func (s *Builder) Run(context map[string]interface{}, ctx *types.Context) error { commands := []types.Command{ &SetupHumanLoggerIfMissing{}, @@ -115,14 +115,14 @@ func (s *Builder) Run(context map[string]interface{}) error { &RecipeByPrefixSuffixRunner{Prefix: constants.HOOKS_POSTBUILD, Suffix: constants.HOOKS_PATTERN_SUFFIX}, } - mainErr := runCommands(context, commands, true) + mainErr := runCommands(context, ctx, commands, true) commands = []types.Command{ &PrintUsedAndNotUsedLibraries{}, &PrintUsedLibrariesIfVerbose{}, } - otherErr := runCommands(context, commands, false) + otherErr := runCommands(context, ctx, commands, false) if mainErr != nil { return mainErr @@ -133,7 +133,7 @@ func (s *Builder) Run(context map[string]interface{}) error { type Preprocess struct{} -func (s *Preprocess) Run(context map[string]interface{}) error { +func (s *Preprocess) Run(context map[string]interface{}, ctx *types.Context) error { commands := []types.Command{ &SetupHumanLoggerIfMissing{}, @@ -157,12 +157,12 @@ func (s *Preprocess) Run(context map[string]interface{}) error { &PrintPreprocessedSource{}, } - return runCommands(context, commands, true) + return runCommands(context, ctx, commands, true) } type ParseHardwareAndDumpBuildProperties struct{} -func (s *ParseHardwareAndDumpBuildProperties) Run(context map[string]interface{}) error { +func (s *ParseHardwareAndDumpBuildProperties) Run(context map[string]interface{}, ctx *types.Context) error { commands := []types.Command{ &SetupHumanLoggerIfMissing{}, @@ -173,10 +173,10 @@ func (s *ParseHardwareAndDumpBuildProperties) Run(context map[string]interface{} &DumpBuildProperties{}, } - return runCommands(context, commands, true) + return runCommands(context, ctx, commands, true) } -func runCommands(context map[string]interface{}, commands []types.Command, progressEnabled bool) error { +func runCommands(context map[string]interface{}, ctx *types.Context, commands []types.Command, progressEnabled bool) error { commandsLength := len(commands) progressForEachCommand := float32(100) / float32(commandsLength) @@ -184,7 +184,7 @@ func runCommands(context map[string]interface{}, commands []types.Command, progr for _, command := range commands { PrintRingNameIfDebug(context, command) printProgressIfProgressEnabledAndMachineLogger(progressEnabled, context, progress) - err := command.Run(context) + err := command.Run(context, ctx) if err != nil { return utils.WrapError(err) } @@ -213,17 +213,17 @@ func PrintRingNameIfDebug(context map[string]interface{}, command types.Command) } } -func RunBuilder(context map[string]interface{}) error { +func RunBuilder(context map[string]interface{}, ctx *types.Context) error { command := Builder{} - return command.Run(context) + return command.Run(context, ctx) } -func RunParseHardwareAndDumpBuildProperties(context map[string]interface{}) error { +func RunParseHardwareAndDumpBuildProperties(context map[string]interface{}, ctx *types.Context) error { command := ParseHardwareAndDumpBuildProperties{} - return command.Run(context) + return command.Run(context, ctx) } -func RunPreprocess(context map[string]interface{}) error { +func RunPreprocess(context map[string]interface{}, ctx *types.Context) error { command := Preprocess{} - return command.Run(context) + return command.Run(context, ctx) } diff --git a/src/arduino.cc/builder/coan_runner.go b/src/arduino.cc/builder/coan_runner.go index 01420d2f..b29d9178 100644 --- a/src/arduino.cc/builder/coan_runner.go +++ b/src/arduino.cc/builder/coan_runner.go @@ -33,6 +33,7 @@ import ( "arduino.cc/builder/constants" "arduino.cc/builder/i18n" "arduino.cc/builder/props" + "arduino.cc/builder/types" "arduino.cc/builder/utils" "fmt" "path/filepath" @@ -43,7 +44,7 @@ var ALLOWED_ARG = regexp.MustCompile("^source$|\\-E$|\\-m$|\\-P$|\\-kb$|\\-D.*") type CoanRunner struct{} -func (s *CoanRunner) Run(context map[string]interface{}) error { +func (s *CoanRunner) Run(context map[string]interface{}, ctx *types.Context) error { source := context[constants.CTX_SOURCE].(string) source += "\n" verbose := context[constants.CTX_VERBOSE].(bool) diff --git a/src/arduino.cc/builder/collect_all_source_files_from_folders_with_sources.go b/src/arduino.cc/builder/collect_all_source_files_from_folders_with_sources.go index d9b26c60..834aa912 100644 --- a/src/arduino.cc/builder/collect_all_source_files_from_folders_with_sources.go +++ b/src/arduino.cc/builder/collect_all_source_files_from_folders_with_sources.go @@ -42,7 +42,7 @@ import ( type CollectAllSourceFilesFromFoldersWithSources struct{} -func (s *CollectAllSourceFilesFromFoldersWithSources) Run(context map[string]interface{}) error { +func (s *CollectAllSourceFilesFromFoldersWithSources) Run(context map[string]interface{}, ctx *types.Context) error { foldersWithSources := context[constants.CTX_FOLDERS_WITH_SOURCES_QUEUE].(*types.UniqueSourceFolderQueue) sourceFiles := context[constants.CTX_COLLECTED_SOURCE_FILES_QUEUE].(*types.UniqueStringQueue) diff --git a/src/arduino.cc/builder/collect_ctags_from_sketch_files.go b/src/arduino.cc/builder/collect_ctags_from_sketch_files.go index 471f3411..34c79863 100644 --- a/src/arduino.cc/builder/collect_ctags_from_sketch_files.go +++ b/src/arduino.cc/builder/collect_ctags_from_sketch_files.go @@ -38,7 +38,7 @@ import ( type CollectCTagsFromSketchFiles struct{} -func (s *CollectCTagsFromSketchFiles) Run(context map[string]interface{}) error { +func (s *CollectCTagsFromSketchFiles) Run(context map[string]interface{}, ctx *types.Context) error { sketch := context[constants.CTX_SKETCH].(*types.Sketch) sketchFileNames := collectSketchFileNamesFrom(sketch) diff --git a/src/arduino.cc/builder/container_add_prototypes.go b/src/arduino.cc/builder/container_add_prototypes.go index 6c337af9..8c22dabe 100644 --- a/src/arduino.cc/builder/container_add_prototypes.go +++ b/src/arduino.cc/builder/container_add_prototypes.go @@ -38,7 +38,7 @@ import ( type ContainerAddPrototypes struct{} -func (s *ContainerAddPrototypes) Run(context map[string]interface{}) error { +func (s *ContainerAddPrototypes) Run(context map[string]interface{}, ctx *types.Context) error { commands := []types.Command{ &GCCPreprocRunner{TargetFileName: constants.FILE_CTAGS_TARGET_FOR_GCC_MINUS_E}, &ReadFileAndStoreInContext{TargetField: constants.CTX_GCC_MINUS_E_SOURCE}, @@ -53,7 +53,7 @@ func (s *ContainerAddPrototypes) Run(context map[string]interface{}) error { for _, command := range commands { PrintRingNameIfDebug(context, command) - err := command.Run(context) + err := command.Run(context, ctx) if err != nil { return utils.WrapError(err) } diff --git a/src/arduino.cc/builder/container_build_options.go b/src/arduino.cc/builder/container_build_options.go index 168547a9..3ca87d6b 100644 --- a/src/arduino.cc/builder/container_build_options.go +++ b/src/arduino.cc/builder/container_build_options.go @@ -36,7 +36,7 @@ import ( type ContainerBuildOptions struct{} -func (s *ContainerBuildOptions) Run(context map[string]interface{}) error { +func (s *ContainerBuildOptions) Run(context map[string]interface{}, ctx *types.Context) error { commands := []types.Command{ &CreateBuildOptionsMap{}, &LoadPreviousBuildOptionsMap{}, @@ -46,7 +46,7 @@ func (s *ContainerBuildOptions) Run(context map[string]interface{}) error { for _, command := range commands { PrintRingNameIfDebug(context, command) - err := command.Run(context) + err := command.Run(context, ctx) if err != nil { return utils.WrapError(err) } diff --git a/src/arduino.cc/builder/container_find_includes.go b/src/arduino.cc/builder/container_find_includes.go index ae6a2396..ca70f821 100644 --- a/src/arduino.cc/builder/container_find_includes.go +++ b/src/arduino.cc/builder/container_find_includes.go @@ -38,15 +38,15 @@ import ( type ContainerFindIncludes struct{} -func (s *ContainerFindIncludes) Run(context map[string]interface{}) error { - err := runCommand(context, &IncludesToIncludeFolders{}) +func (s *ContainerFindIncludes) Run(context map[string]interface{}, ctx *types.Context) error { + err := runCommand(context, ctx, &IncludesToIncludeFolders{}) if err != nil { return utils.WrapError(err) } sketchBuildPath := context[constants.CTX_SKETCH_BUILD_PATH].(string) sketch := context[constants.CTX_SKETCH].(*types.Sketch) - err = findIncludesUntilDone(context, filepath.Join(sketchBuildPath, filepath.Base(sketch.MainFile.Name)+".cpp")) + err = findIncludesUntilDone(context, ctx, filepath.Join(sketchBuildPath, filepath.Base(sketch.MainFile.Name)+".cpp")) if err != nil { return utils.WrapError(err) } @@ -62,7 +62,7 @@ func (s *ContainerFindIncludes) Run(context map[string]interface{}) error { } } - err = runCommand(context, &CollectAllSourceFilesFromFoldersWithSources{}) + err = runCommand(context, ctx, &CollectAllSourceFilesFromFoldersWithSources{}) if err != nil { return utils.WrapError(err) } @@ -70,17 +70,17 @@ func (s *ContainerFindIncludes) Run(context map[string]interface{}) error { sourceFilePaths := context[constants.CTX_COLLECTED_SOURCE_FILES_QUEUE].(*types.UniqueStringQueue) for !sourceFilePaths.Empty() { - err = findIncludesUntilDone(context, sourceFilePaths.Pop().(string)) + err = findIncludesUntilDone(context, ctx, sourceFilePaths.Pop().(string)) if err != nil { return utils.WrapError(err) } - err := runCommand(context, &CollectAllSourceFilesFromFoldersWithSources{}) + err := runCommand(context, ctx, &CollectAllSourceFilesFromFoldersWithSources{}) if err != nil { return utils.WrapError(err) } } - err = runCommand(context, &FailIfImportedLibraryIsWrong{}) + err = runCommand(context, ctx, &FailIfImportedLibraryIsWrong{}) if err != nil { return utils.WrapError(err) } @@ -88,16 +88,16 @@ func (s *ContainerFindIncludes) Run(context map[string]interface{}) error { return nil } -func runCommand(context map[string]interface{}, command types.Command) error { +func runCommand(context map[string]interface{}, ctx *types.Context, command types.Command) error { PrintRingNameIfDebug(context, command) - err := command.Run(context) + err := command.Run(context, ctx) if err != nil { return utils.WrapError(err) } return nil } -func findIncludesUntilDone(context map[string]interface{}, sourceFilePath string) error { +func findIncludesUntilDone(context map[string]interface{}, ctx *types.Context, sourceFilePath string) error { targetFilePath := utils.NULLFile() importedLibraries := context[constants.CTX_IMPORTED_LIBRARIES].([]*types.Library) done := false @@ -108,7 +108,7 @@ func findIncludesUntilDone(context map[string]interface{}, sourceFilePath string &IncludesToIncludeFolders{}, } for _, command := range commands { - err := runCommand(context, command) + err := runCommand(context, ctx, command) if err != nil { return utils.WrapError(err) } @@ -116,7 +116,7 @@ func findIncludesUntilDone(context map[string]interface{}, sourceFilePath string if len(context[constants.CTX_INCLUDES_JUST_FOUND].([]string)) == 0 { done = true } else if len(context[constants.CTX_IMPORTED_LIBRARIES].([]*types.Library)) == len(importedLibraries) { - err := runCommand(context, &GCCPreprocRunner{TargetFileName: constants.FILE_CTAGS_TARGET_FOR_GCC_MINUS_E}) + err := runCommand(context, ctx, &GCCPreprocRunner{TargetFileName: constants.FILE_CTAGS_TARGET_FOR_GCC_MINUS_E}) return utils.WrapError(err) } importedLibraries = context[constants.CTX_IMPORTED_LIBRARIES].([]*types.Library) diff --git a/src/arduino.cc/builder/container_merge_copy_sketch_files.go b/src/arduino.cc/builder/container_merge_copy_sketch_files.go index 3dc8eec3..0dcb890b 100644 --- a/src/arduino.cc/builder/container_merge_copy_sketch_files.go +++ b/src/arduino.cc/builder/container_merge_copy_sketch_files.go @@ -36,7 +36,7 @@ import ( type ContainerMergeCopySketchFiles struct{} -func (s *ContainerMergeCopySketchFiles) Run(context map[string]interface{}) error { +func (s *ContainerMergeCopySketchFiles) Run(context map[string]interface{}, ctx *types.Context) error { commands := []types.Command{ &SketchSourceMerger{}, &SketchSaver{}, @@ -45,7 +45,7 @@ func (s *ContainerMergeCopySketchFiles) Run(context map[string]interface{}) erro for _, command := range commands { PrintRingNameIfDebug(context, command) - err := command.Run(context) + err := command.Run(context, ctx) if err != nil { return utils.WrapError(err) } diff --git a/src/arduino.cc/builder/container_setup.go b/src/arduino.cc/builder/container_setup.go index 9c702b1d..a0315e6a 100644 --- a/src/arduino.cc/builder/container_setup.go +++ b/src/arduino.cc/builder/container_setup.go @@ -36,7 +36,7 @@ import ( type ContainerSetupHardwareToolsLibsSketchAndProps struct{} -func (s *ContainerSetupHardwareToolsLibsSketchAndProps) Run(context map[string]interface{}) error { +func (s *ContainerSetupHardwareToolsLibsSketchAndProps) Run(context map[string]interface{}, ctx *types.Context) error { commands := []types.Command{ &AddAdditionalEntriesToContext{}, &FailIfBuildPathEqualsSketchPath{}, @@ -56,7 +56,7 @@ func (s *ContainerSetupHardwareToolsLibsSketchAndProps) Run(context map[string]i for _, command := range commands { PrintRingNameIfDebug(context, command) - err := command.Run(context) + err := command.Run(context, ctx) if err != nil { return utils.WrapError(err) } diff --git a/src/arduino.cc/builder/create_build_options_map.go b/src/arduino.cc/builder/create_build_options_map.go index 3d05db6d..e9634157 100644 --- a/src/arduino.cc/builder/create_build_options_map.go +++ b/src/arduino.cc/builder/create_build_options_map.go @@ -31,6 +31,7 @@ package builder import ( "arduino.cc/builder/constants" + "arduino.cc/builder/types" "arduino.cc/builder/utils" "encoding/json" "reflect" @@ -39,7 +40,7 @@ import ( type CreateBuildOptionsMap struct{} -func (s *CreateBuildOptionsMap) Run(context map[string]interface{}) error { +func (s *CreateBuildOptionsMap) Run(context map[string]interface{}, ctx *types.Context) error { buildOptions := make(map[string]string) buildOptionsMapKeys := []string{ diff --git a/src/arduino.cc/builder/ctags/ctags_parser.go b/src/arduino.cc/builder/ctags/ctags_parser.go index a4a6b0e0..2d1c7603 100644 --- a/src/arduino.cc/builder/ctags/ctags_parser.go +++ b/src/arduino.cc/builder/ctags/ctags_parser.go @@ -57,7 +57,7 @@ var KNOWN_TAG_KINDS = map[string]bool{ type CTagsParser struct{} -func (s *CTagsParser) Run(context map[string]interface{}) error { +func (s *CTagsParser) Run(context map[string]interface{}, ctx *types.Context) error { rows := strings.Split(context[constants.CTX_CTAGS_OUTPUT].(string), "\n") rows = removeEmpty(rows) diff --git a/src/arduino.cc/builder/ctags/ctags_runner.go b/src/arduino.cc/builder/ctags/ctags_runner.go index 4a603fd9..542decab 100644 --- a/src/arduino.cc/builder/ctags/ctags_runner.go +++ b/src/arduino.cc/builder/ctags/ctags_runner.go @@ -33,13 +33,14 @@ import ( "arduino.cc/builder/constants" "arduino.cc/builder/i18n" "arduino.cc/builder/props" + "arduino.cc/builder/types" "arduino.cc/builder/utils" "fmt" ) type CTagsRunner struct{} -func (s *CTagsRunner) Run(context map[string]interface{}) error { +func (s *CTagsRunner) Run(context map[string]interface{}, ctx *types.Context) error { buildProperties := context[constants.CTX_BUILD_PROPERTIES].(props.PropertiesMap) ctagsTargetFilePath := context[constants.CTX_CTAGS_TEMP_FILE_PATH].(string) logger := context[constants.CTX_LOGGER].(i18n.Logger) diff --git a/src/arduino.cc/builder/ctags/ctags_to_prototypes.go b/src/arduino.cc/builder/ctags/ctags_to_prototypes.go index 73e05482..c9f81e75 100644 --- a/src/arduino.cc/builder/ctags/ctags_to_prototypes.go +++ b/src/arduino.cc/builder/ctags/ctags_to_prototypes.go @@ -37,7 +37,7 @@ import ( type CTagsToPrototypes struct{} -func (s *CTagsToPrototypes) Run(context map[string]interface{}) error { +func (s *CTagsToPrototypes) Run(context map[string]interface{}, ctx *types.Context) error { tags := context[constants.CTX_COLLECTED_CTAGS].([]*types.CTag) lineWhereToInsertPrototypes := findLineWhereToInsertPrototypes(tags) diff --git a/src/arduino.cc/builder/ctags_target_file_saver.go b/src/arduino.cc/builder/ctags_target_file_saver.go index f6fe259a..32c0e16e 100644 --- a/src/arduino.cc/builder/ctags_target_file_saver.go +++ b/src/arduino.cc/builder/ctags_target_file_saver.go @@ -31,6 +31,7 @@ package builder import ( "arduino.cc/builder/constants" + "arduino.cc/builder/types" "arduino.cc/builder/utils" "path/filepath" ) @@ -40,7 +41,7 @@ type CTagsTargetFileSaver struct { TargetFileName string } -func (s *CTagsTargetFileSaver) Run(context map[string]interface{}) error { +func (s *CTagsTargetFileSaver) Run(context map[string]interface{}, ctx *types.Context) error { source := context[s.SourceField].(string) preprocPath := context[constants.CTX_PREPROC_PATH].(string) diff --git a/src/arduino.cc/builder/dump_build_properties.go b/src/arduino.cc/builder/dump_build_properties.go index 41db23f2..b48d05ba 100644 --- a/src/arduino.cc/builder/dump_build_properties.go +++ b/src/arduino.cc/builder/dump_build_properties.go @@ -32,6 +32,7 @@ package builder import ( "arduino.cc/builder/constants" "arduino.cc/builder/props" + "arduino.cc/builder/types" "arduino.cc/builder/utils" "fmt" "sort" @@ -39,7 +40,7 @@ import ( type DumpBuildProperties struct{} -func (s *DumpBuildProperties) Run(context map[string]interface{}) error { +func (s *DumpBuildProperties) Run(context map[string]interface{}, ctx *types.Context) error { buildProperties := context[constants.CTX_BUILD_PROPERTIES].(props.PropertiesMap) keys := utils.KeysOfMapOfString(buildProperties) diff --git a/src/arduino.cc/builder/ensure_buildpath_exists.go b/src/arduino.cc/builder/ensure_buildpath_exists.go index d3fc6dc5..884bdcfe 100644 --- a/src/arduino.cc/builder/ensure_buildpath_exists.go +++ b/src/arduino.cc/builder/ensure_buildpath_exists.go @@ -31,12 +31,13 @@ package builder import ( "arduino.cc/builder/constants" + "arduino.cc/builder/types" "arduino.cc/builder/utils" ) type EnsureBuildPathExists struct{} -func (s *EnsureBuildPathExists) Run(context map[string]interface{}) error { +func (s *EnsureBuildPathExists) Run(context map[string]interface{}, ctx *types.Context) error { buildPath := context[constants.CTX_BUILD_PATH].(string) err := utils.EnsureFolderExists(buildPath) diff --git a/src/arduino.cc/builder/fail_if_buildpath_equals_sketchpath.go b/src/arduino.cc/builder/fail_if_buildpath_equals_sketchpath.go index d6bbff33..42be68f0 100644 --- a/src/arduino.cc/builder/fail_if_buildpath_equals_sketchpath.go +++ b/src/arduino.cc/builder/fail_if_buildpath_equals_sketchpath.go @@ -31,13 +31,14 @@ package builder import ( "arduino.cc/builder/constants" + "arduino.cc/builder/types" "arduino.cc/builder/utils" "path/filepath" ) type FailIfBuildPathEqualsSketchPath struct{} -func (s *FailIfBuildPathEqualsSketchPath) Run(context map[string]interface{}) error { +func (s *FailIfBuildPathEqualsSketchPath) Run(context map[string]interface{}, ctx *types.Context) error { if !utils.MapHas(context, constants.CTX_BUILD_PATH) || !utils.MapHas(context, constants.CTX_SKETCH_LOCATION) { return nil } diff --git a/src/arduino.cc/builder/fail_if_imported_library_is_wrong.go b/src/arduino.cc/builder/fail_if_imported_library_is_wrong.go index ab261996..090ae00b 100644 --- a/src/arduino.cc/builder/fail_if_imported_library_is_wrong.go +++ b/src/arduino.cc/builder/fail_if_imported_library_is_wrong.go @@ -40,7 +40,7 @@ import ( type FailIfImportedLibraryIsWrong struct{} -func (s *FailIfImportedLibraryIsWrong) Run(context map[string]interface{}) error { +func (s *FailIfImportedLibraryIsWrong) Run(context map[string]interface{}, ctx *types.Context) error { if !utils.MapHas(context, constants.CTX_IMPORTED_LIBRARIES) { return nil } diff --git a/src/arduino.cc/builder/gcc_preproc_runner.go b/src/arduino.cc/builder/gcc_preproc_runner.go index 19f599c3..d4dd7352 100644 --- a/src/arduino.cc/builder/gcc_preproc_runner.go +++ b/src/arduino.cc/builder/gcc_preproc_runner.go @@ -44,7 +44,7 @@ type GCCPreprocRunner struct { TargetFileName string } -func (s *GCCPreprocRunner) Run(context map[string]interface{}) error { +func (s *GCCPreprocRunner) Run(context map[string]interface{}, ctx *types.Context) error { sketchBuildPath := context[constants.CTX_SKETCH_BUILD_PATH].(string) sketch := context[constants.CTX_SKETCH].(*types.Sketch) properties, targetFilePath, err := prepareGCCPreprocRecipeProperties(context, filepath.Join(sketchBuildPath, filepath.Base(sketch.MainFile.Name)+".cpp"), s.TargetFileName) @@ -74,7 +74,7 @@ type GCCPreprocRunnerForDiscoveringIncludes struct { TargetFilePath string } -func (s *GCCPreprocRunnerForDiscoveringIncludes) Run(context map[string]interface{}) error { +func (s *GCCPreprocRunnerForDiscoveringIncludes) Run(context map[string]interface{}, ctx *types.Context) error { properties, _, err := prepareGCCPreprocRecipeProperties(context, s.SourceFilePath, s.TargetFilePath) if err != nil { return utils.WrapError(err) diff --git a/src/arduino.cc/builder/generate_buildpath_if_missing.go b/src/arduino.cc/builder/generate_buildpath_if_missing.go index 5a04272d..44904ca7 100644 --- a/src/arduino.cc/builder/generate_buildpath_if_missing.go +++ b/src/arduino.cc/builder/generate_buildpath_if_missing.go @@ -32,6 +32,7 @@ package builder import ( "arduino.cc/builder/constants" "arduino.cc/builder/i18n" + "arduino.cc/builder/types" "arduino.cc/builder/utils" "os" "path/filepath" @@ -40,7 +41,7 @@ import ( type GenerateBuildPathIfMissing struct{} -func (s *GenerateBuildPathIfMissing) Run(context map[string]interface{}) error { +func (s *GenerateBuildPathIfMissing) Run(context map[string]interface{}, ctx *types.Context) error { if utils.MapHas(context, constants.CTX_BUILD_PATH) && context[constants.CTX_BUILD_PATH].(string) != constants.EMPTY_STRING { return nil } diff --git a/src/arduino.cc/builder/hardware_loader.go b/src/arduino.cc/builder/hardware_loader.go index 29dce302..f99caaf3 100644 --- a/src/arduino.cc/builder/hardware_loader.go +++ b/src/arduino.cc/builder/hardware_loader.go @@ -41,7 +41,7 @@ import ( type HardwareLoader struct{} -func (s *HardwareLoader) Run(context map[string]interface{}) error { +func (s *HardwareLoader) Run(context map[string]interface{}, ctx *types.Context) error { logger := context[constants.CTX_LOGGER].(i18n.Logger) packages := &types.Packages{} diff --git a/src/arduino.cc/builder/includes_finder_with_regexp.go b/src/arduino.cc/builder/includes_finder_with_regexp.go index e83840f5..80e306e1 100644 --- a/src/arduino.cc/builder/includes_finder_with_regexp.go +++ b/src/arduino.cc/builder/includes_finder_with_regexp.go @@ -31,6 +31,7 @@ package builder import ( "arduino.cc/builder/constants" + "arduino.cc/builder/types" "arduino.cc/builder/utils" "regexp" "strings" @@ -42,7 +43,7 @@ type IncludesFinderWithRegExp struct { ContextField string } -func (s *IncludesFinderWithRegExp) Run(context map[string]interface{}) error { +func (s *IncludesFinderWithRegExp) Run(context map[string]interface{}, ctx *types.Context) error { source := context[s.ContextField].(string) matches := INCLUDE_REGEXP.FindAllStringSubmatch(source, -1) diff --git a/src/arduino.cc/builder/includes_to_include_folders.go b/src/arduino.cc/builder/includes_to_include_folders.go index 9760fb64..e5c21205 100644 --- a/src/arduino.cc/builder/includes_to_include_folders.go +++ b/src/arduino.cc/builder/includes_to_include_folders.go @@ -40,7 +40,7 @@ import ( type IncludesToIncludeFolders struct{} -func (s *IncludesToIncludeFolders) Run(context map[string]interface{}) error { +func (s *IncludesToIncludeFolders) Run(context map[string]interface{}, ctx *types.Context) error { includes := []string{} if utils.MapHas(context, constants.CTX_INCLUDES) { includes = context[constants.CTX_INCLUDES].([]string) diff --git a/src/arduino.cc/builder/libraries_loader.go b/src/arduino.cc/builder/libraries_loader.go index 0c043801..07850f6e 100644 --- a/src/arduino.cc/builder/libraries_loader.go +++ b/src/arduino.cc/builder/libraries_loader.go @@ -42,7 +42,7 @@ import ( type LibrariesLoader struct{} -func (s *LibrariesLoader) Run(context map[string]interface{}) error { +func (s *LibrariesLoader) Run(context map[string]interface{}, ctx *types.Context) error { sortedLibrariesFolders := []string{} builtInLibrariesFolders := []string{} diff --git a/src/arduino.cc/builder/load_previous_build_options.go b/src/arduino.cc/builder/load_previous_build_options.go index 3c884bff..18b79dfc 100644 --- a/src/arduino.cc/builder/load_previous_build_options.go +++ b/src/arduino.cc/builder/load_previous_build_options.go @@ -31,6 +31,7 @@ package builder import ( "arduino.cc/builder/constants" + "arduino.cc/builder/types" "arduino.cc/builder/utils" "io/ioutil" "os" @@ -39,7 +40,7 @@ import ( type LoadPreviousBuildOptionsMap struct{} -func (s *LoadPreviousBuildOptionsMap) Run(context map[string]interface{}) error { +func (s *LoadPreviousBuildOptionsMap) Run(context map[string]interface{}, ctx *types.Context) error { buildPath := context[constants.CTX_BUILD_PATH].(string) buildOptionsFile := filepath.Join(buildPath, constants.BUILD_OPTIONS_FILE) diff --git a/src/arduino.cc/builder/load_vid_pid_specific_properties.go b/src/arduino.cc/builder/load_vid_pid_specific_properties.go index 3f7ccd2d..c7533847 100644 --- a/src/arduino.cc/builder/load_vid_pid_specific_properties.go +++ b/src/arduino.cc/builder/load_vid_pid_specific_properties.go @@ -32,6 +32,7 @@ package builder import ( "arduino.cc/builder/constants" "arduino.cc/builder/props" + "arduino.cc/builder/types" "arduino.cc/builder/utils" "strconv" "strings" @@ -39,7 +40,7 @@ import ( type LoadVIDPIDSpecificProperties struct{} -func (s *LoadVIDPIDSpecificProperties) Run(context map[string]interface{}) error { +func (s *LoadVIDPIDSpecificProperties) Run(context map[string]interface{}, ctx *types.Context) error { if !utils.MapHas(context, constants.CTX_VIDPID) { return nil } diff --git a/src/arduino.cc/builder/merge_sketch_with_bootloader.go b/src/arduino.cc/builder/merge_sketch_with_bootloader.go index 85c5d015..fd2a4773 100644 --- a/src/arduino.cc/builder/merge_sketch_with_bootloader.go +++ b/src/arduino.cc/builder/merge_sketch_with_bootloader.go @@ -42,7 +42,7 @@ import ( type MergeSketchWithBootloader struct{} -func (s *MergeSketchWithBootloader) Run(context map[string]interface{}) error { +func (s *MergeSketchWithBootloader) Run(context map[string]interface{}, ctx *types.Context) error { buildProperties := context[constants.CTX_BUILD_PROPERTIES].(props.PropertiesMap) if !utils.MapStringStringHas(buildProperties, constants.BUILD_PROPERTIES_BOOTLOADER_NOBLINK) && !utils.MapStringStringHas(buildProperties, constants.BUILD_PROPERTIES_BOOTLOADER_FILE) { return nil diff --git a/src/arduino.cc/builder/phases/core_builder.go b/src/arduino.cc/builder/phases/core_builder.go index d1b8cc9b..a6c2ceea 100644 --- a/src/arduino.cc/builder/phases/core_builder.go +++ b/src/arduino.cc/builder/phases/core_builder.go @@ -34,12 +34,13 @@ import ( "arduino.cc/builder/constants" "arduino.cc/builder/i18n" "arduino.cc/builder/props" + "arduino.cc/builder/types" "arduino.cc/builder/utils" ) type CoreBuilder struct{} -func (s *CoreBuilder) Run(context map[string]interface{}) error { +func (s *CoreBuilder) Run(context map[string]interface{}, ctx *types.Context) error { coreBuildPath := context[constants.CTX_CORE_BUILD_PATH].(string) buildProperties := context[constants.CTX_BUILD_PROPERTIES].(props.PropertiesMap) verbose := context[constants.CTX_VERBOSE].(bool) diff --git a/src/arduino.cc/builder/phases/libraries_builder.go b/src/arduino.cc/builder/phases/libraries_builder.go index a26f5b2a..07baf8bc 100644 --- a/src/arduino.cc/builder/phases/libraries_builder.go +++ b/src/arduino.cc/builder/phases/libraries_builder.go @@ -42,7 +42,7 @@ import ( type LibrariesBuilder struct{} -func (s *LibrariesBuilder) Run(context map[string]interface{}) error { +func (s *LibrariesBuilder) Run(context map[string]interface{}, ctx *types.Context) error { librariesBuildPath := context[constants.CTX_LIBRARIES_BUILD_PATH].(string) buildProperties := context[constants.CTX_BUILD_PROPERTIES].(props.PropertiesMap) includes := context[constants.CTX_INCLUDE_FOLDERS].([]string) diff --git a/src/arduino.cc/builder/phases/linker.go b/src/arduino.cc/builder/phases/linker.go index d2530d31..e1a832f0 100644 --- a/src/arduino.cc/builder/phases/linker.go +++ b/src/arduino.cc/builder/phases/linker.go @@ -34,6 +34,7 @@ import ( "arduino.cc/builder/constants" "arduino.cc/builder/i18n" "arduino.cc/builder/props" + "arduino.cc/builder/types" "arduino.cc/builder/utils" "path/filepath" "strings" @@ -41,7 +42,7 @@ import ( type Linker struct{} -func (s *Linker) Run(context map[string]interface{}) error { +func (s *Linker) Run(context map[string]interface{}, ctx *types.Context) error { objectFilesSketch := context[constants.CTX_OBJECT_FILES_SKETCH].([]string) objectFilesLibraries := context[constants.CTX_OBJECT_FILES_LIBRARIES].([]string) objectFilesCore := context[constants.CTX_OBJECT_FILES_CORE].([]string) diff --git a/src/arduino.cc/builder/phases/sketch_builder.go b/src/arduino.cc/builder/phases/sketch_builder.go index cf9befe7..a5f19d65 100644 --- a/src/arduino.cc/builder/phases/sketch_builder.go +++ b/src/arduino.cc/builder/phases/sketch_builder.go @@ -34,12 +34,13 @@ import ( "arduino.cc/builder/constants" "arduino.cc/builder/i18n" "arduino.cc/builder/props" + "arduino.cc/builder/types" "arduino.cc/builder/utils" ) type SketchBuilder struct{} -func (s *SketchBuilder) Run(context map[string]interface{}) error { +func (s *SketchBuilder) Run(context map[string]interface{}, ctx *types.Context) error { sketchBuildPath := context[constants.CTX_SKETCH_BUILD_PATH].(string) buildProperties := context[constants.CTX_BUILD_PROPERTIES].(props.PropertiesMap) includes := context[constants.CTX_INCLUDE_FOLDERS].([]string) diff --git a/src/arduino.cc/builder/platform_keys_rewrite_loader.go b/src/arduino.cc/builder/platform_keys_rewrite_loader.go index 86e9c553..d375ec22 100644 --- a/src/arduino.cc/builder/platform_keys_rewrite_loader.go +++ b/src/arduino.cc/builder/platform_keys_rewrite_loader.go @@ -44,7 +44,7 @@ import ( type PlatformKeysRewriteLoader struct{} -func (s *PlatformKeysRewriteLoader) Run(context map[string]interface{}) error { +func (s *PlatformKeysRewriteLoader) Run(context map[string]interface{}, ctx *types.Context) error { logger := context[constants.CTX_LOGGER].(i18n.Logger) folders := context[constants.CTX_HARDWARE_FOLDERS].([]string) diff --git a/src/arduino.cc/builder/print_preprocessed_source.go b/src/arduino.cc/builder/print_preprocessed_source.go index 5a444d10..48173118 100644 --- a/src/arduino.cc/builder/print_preprocessed_source.go +++ b/src/arduino.cc/builder/print_preprocessed_source.go @@ -31,12 +31,13 @@ package builder import ( "arduino.cc/builder/constants" + "arduino.cc/builder/types" "fmt" ) type PrintPreprocessedSource struct{} -func (s *PrintPreprocessedSource) Run(context map[string]interface{}) error { +func (s *PrintPreprocessedSource) Run(context map[string]interface{}, ctx *types.Context) error { source := context[constants.CTX_GCC_MINUS_E_SOURCE].(string) fmt.Println(source) diff --git a/src/arduino.cc/builder/print_used_and_not_used_libraries.go b/src/arduino.cc/builder/print_used_and_not_used_libraries.go index 7979e6b6..28c9f99a 100644 --- a/src/arduino.cc/builder/print_used_and_not_used_libraries.go +++ b/src/arduino.cc/builder/print_used_and_not_used_libraries.go @@ -40,7 +40,7 @@ import ( type PrintUsedAndNotUsedLibraries struct{} -func (s *PrintUsedAndNotUsedLibraries) Run(context map[string]interface{}) error { +func (s *PrintUsedAndNotUsedLibraries) Run(context map[string]interface{}, ctx *types.Context) error { if utils.DebugLevel(context) <= 0 { return nil } diff --git a/src/arduino.cc/builder/print_used_libraries_if_verbose.go b/src/arduino.cc/builder/print_used_libraries_if_verbose.go index c3528a1a..c67a0e74 100644 --- a/src/arduino.cc/builder/print_used_libraries_if_verbose.go +++ b/src/arduino.cc/builder/print_used_libraries_if_verbose.go @@ -39,7 +39,7 @@ import ( type PrintUsedLibrariesIfVerbose struct{} -func (s *PrintUsedLibrariesIfVerbose) Run(context map[string]interface{}) error { +func (s *PrintUsedLibrariesIfVerbose) Run(context map[string]interface{}, ctx *types.Context) error { verbose := context[constants.CTX_VERBOSE].(bool) logger := context[constants.CTX_LOGGER].(i18n.Logger) diff --git a/src/arduino.cc/builder/prototypes_adder.go b/src/arduino.cc/builder/prototypes_adder.go index 5fa95c65..f339cc1f 100644 --- a/src/arduino.cc/builder/prototypes_adder.go +++ b/src/arduino.cc/builder/prototypes_adder.go @@ -40,7 +40,7 @@ import ( type PrototypesAdder struct{} -func (s *PrototypesAdder) Run(context map[string]interface{}) error { +func (s *PrototypesAdder) Run(context map[string]interface{}, ctx *types.Context) error { debugOutput := context[constants.CTX_DEBUG_PREPROCESSOR] != nil source := context[constants.CTX_SOURCE].(string) diff --git a/src/arduino.cc/builder/read_file_and_store_in_context.go b/src/arduino.cc/builder/read_file_and_store_in_context.go index 03eaa2a9..d3071837 100644 --- a/src/arduino.cc/builder/read_file_and_store_in_context.go +++ b/src/arduino.cc/builder/read_file_and_store_in_context.go @@ -31,6 +31,7 @@ package builder import ( "arduino.cc/builder/constants" + "arduino.cc/builder/types" "arduino.cc/builder/utils" "io/ioutil" ) @@ -39,7 +40,7 @@ type ReadFileAndStoreInContext struct { TargetField string } -func (s *ReadFileAndStoreInContext) Run(context map[string]interface{}) error { +func (s *ReadFileAndStoreInContext) Run(context map[string]interface{}, ctx *types.Context) error { bytes, err := ioutil.ReadFile(context[constants.CTX_FILE_PATH_TO_READ].(string)) if err != nil { return utils.WrapError(err) diff --git a/src/arduino.cc/builder/recipe_runner.go b/src/arduino.cc/builder/recipe_runner.go index 8e656bd7..9f965741 100644 --- a/src/arduino.cc/builder/recipe_runner.go +++ b/src/arduino.cc/builder/recipe_runner.go @@ -34,6 +34,7 @@ import ( "arduino.cc/builder/constants" "arduino.cc/builder/i18n" "arduino.cc/builder/props" + "arduino.cc/builder/types" "arduino.cc/builder/utils" "os" "sort" @@ -45,7 +46,7 @@ type RecipeByPrefixSuffixRunner struct { Suffix string } -func (s *RecipeByPrefixSuffixRunner) Run(context map[string]interface{}) error { +func (s *RecipeByPrefixSuffixRunner) Run(context map[string]interface{}, ctx *types.Context) error { logger := context[constants.CTX_LOGGER].(i18n.Logger) if utils.DebugLevel(context) >= 10 { logger.Fprintln(os.Stdout, constants.LOG_LEVEL_DEBUG, constants.MSG_LOOKING_FOR_RECIPES, s.Prefix, s.Suffix) diff --git a/src/arduino.cc/builder/rewrite_hardware_keys.go b/src/arduino.cc/builder/rewrite_hardware_keys.go index b027165a..9cb6a113 100644 --- a/src/arduino.cc/builder/rewrite_hardware_keys.go +++ b/src/arduino.cc/builder/rewrite_hardware_keys.go @@ -37,7 +37,7 @@ import ( type RewriteHardwareKeys struct{} -func (s *RewriteHardwareKeys) Run(context map[string]interface{}) error { +func (s *RewriteHardwareKeys) Run(context map[string]interface{}, ctx *types.Context) error { if !utils.MapHas(context, constants.CTX_PLATFORM_KEYS_REWRITE) { return nil } diff --git a/src/arduino.cc/builder/set_custom_build_properties.go b/src/arduino.cc/builder/set_custom_build_properties.go index ed908772..29b390c4 100644 --- a/src/arduino.cc/builder/set_custom_build_properties.go +++ b/src/arduino.cc/builder/set_custom_build_properties.go @@ -33,12 +33,13 @@ import ( "arduino.cc/builder/constants" "arduino.cc/builder/i18n" "arduino.cc/builder/props" + "arduino.cc/builder/types" "arduino.cc/builder/utils" ) type SetCustomBuildProperties struct{} -func (s *SetCustomBuildProperties) Run(context map[string]interface{}) error { +func (s *SetCustomBuildProperties) Run(context map[string]interface{}, ctx *types.Context) error { if !utils.MapHas(context, constants.CTX_CUSTOM_BUILD_PROPERTIES) { return nil } diff --git a/src/arduino.cc/builder/setup_build_properties.go b/src/arduino.cc/builder/setup_build_properties.go index 7e9332f7..0cdc6425 100644 --- a/src/arduino.cc/builder/setup_build_properties.go +++ b/src/arduino.cc/builder/setup_build_properties.go @@ -42,7 +42,7 @@ import ( type SetupBuildProperties struct{} -func (s *SetupBuildProperties) Run(context map[string]interface{}) error { +func (s *SetupBuildProperties) Run(context map[string]interface{}, ctx *types.Context) error { packages := context[constants.CTX_HARDWARE].(*types.Packages) targetPlatform := context[constants.CTX_TARGET_PLATFORM].(*types.Platform) diff --git a/src/arduino.cc/builder/setup_human_logger_if_missing.go b/src/arduino.cc/builder/setup_human_logger_if_missing.go index 4726dc32..b19ea136 100644 --- a/src/arduino.cc/builder/setup_human_logger_if_missing.go +++ b/src/arduino.cc/builder/setup_human_logger_if_missing.go @@ -32,12 +32,13 @@ package builder import ( "arduino.cc/builder/constants" "arduino.cc/builder/i18n" + "arduino.cc/builder/types" "arduino.cc/builder/utils" ) type SetupHumanLoggerIfMissing struct{} -func (s *SetupHumanLoggerIfMissing) Run(context map[string]interface{}) error { +func (s *SetupHumanLoggerIfMissing) Run(context map[string]interface{}, ctx *types.Context) error { if !utils.MapHas(context, constants.CTX_LOGGER) { context[constants.CTX_LOGGER] = i18n.HumanLogger{} } diff --git a/src/arduino.cc/builder/sketch_loader.go b/src/arduino.cc/builder/sketch_loader.go index 2c2ec10c..214a2f13 100644 --- a/src/arduino.cc/builder/sketch_loader.go +++ b/src/arduino.cc/builder/sketch_loader.go @@ -44,7 +44,7 @@ import ( type SketchLoader struct{} -func (s *SketchLoader) Run(context map[string]interface{}) error { +func (s *SketchLoader) Run(context map[string]interface{}, ctx *types.Context) error { if !utils.MapHas(context, constants.CTX_SKETCH_LOCATION) { return nil } diff --git a/src/arduino.cc/builder/sketch_saver.go b/src/arduino.cc/builder/sketch_saver.go index 1a6bfb57..2344df64 100644 --- a/src/arduino.cc/builder/sketch_saver.go +++ b/src/arduino.cc/builder/sketch_saver.go @@ -38,7 +38,7 @@ import ( type SketchSaver struct{} -func (s *SketchSaver) Run(context map[string]interface{}) error { +func (s *SketchSaver) Run(context map[string]interface{}, ctx *types.Context) error { sketch := context[constants.CTX_SKETCH].(*types.Sketch) sketchBuildPath := context[constants.CTX_SKETCH_BUILD_PATH].(string) source := context[constants.CTX_SOURCE].(string) diff --git a/src/arduino.cc/builder/sketch_source_merger.go b/src/arduino.cc/builder/sketch_source_merger.go index d4cc71a3..5835c7a7 100644 --- a/src/arduino.cc/builder/sketch_source_merger.go +++ b/src/arduino.cc/builder/sketch_source_merger.go @@ -39,7 +39,7 @@ import ( type SketchSourceMerger struct{} -func (s *SketchSourceMerger) Run(context map[string]interface{}) error { +func (s *SketchSourceMerger) Run(context map[string]interface{}, ctx *types.Context) error { sketch := context[constants.CTX_SKETCH].(*types.Sketch) lineOffset := 0 diff --git a/src/arduino.cc/builder/store_build_options_map.go b/src/arduino.cc/builder/store_build_options_map.go index 4e2172a4..b85355ab 100644 --- a/src/arduino.cc/builder/store_build_options_map.go +++ b/src/arduino.cc/builder/store_build_options_map.go @@ -31,13 +31,14 @@ package builder import ( "arduino.cc/builder/constants" + "arduino.cc/builder/types" "arduino.cc/builder/utils" "path/filepath" ) type StoreBuildOptionsMap struct{} -func (s *StoreBuildOptionsMap) Run(context map[string]interface{}) error { +func (s *StoreBuildOptionsMap) Run(context map[string]interface{}, ctx *types.Context) error { buildPath := context[constants.CTX_BUILD_PATH].(string) buildOptionsJson := context[constants.CTX_BUILD_OPTIONS_JSON].(string) diff --git a/src/arduino.cc/builder/target_board_resolver.go b/src/arduino.cc/builder/target_board_resolver.go index c1c58c4a..4abf08f5 100644 --- a/src/arduino.cc/builder/target_board_resolver.go +++ b/src/arduino.cc/builder/target_board_resolver.go @@ -38,7 +38,7 @@ import ( type TargetBoardResolver struct{} -func (s *TargetBoardResolver) Run(context map[string]interface{}) error { +func (s *TargetBoardResolver) Run(context map[string]interface{}, ctx *types.Context) error { fqbn := context[constants.CTX_FQBN].(string) fqbnParts := strings.Split(fqbn, ":") diff --git a/src/arduino.cc/builder/test/add_additional_entries_to_context_test.go b/src/arduino.cc/builder/test/add_additional_entries_to_context_test.go index 416f5335..e1ef1ddf 100644 --- a/src/arduino.cc/builder/test/add_additional_entries_to_context_test.go +++ b/src/arduino.cc/builder/test/add_additional_entries_to_context_test.go @@ -40,9 +40,10 @@ import ( func TestAddAdditionalEntriesToContextNoBuildPath(t *testing.T) { context := make(map[string]interface{}) + ctx := &types.Context{} command := builder.AddAdditionalEntriesToContext{} - NoError(t, command.Run(context)) + NoError(t, command.Run(context, ctx)) require.Nil(t, context[constants.CTX_PREPROC_PATH]) require.Nil(t, context[constants.CTX_SKETCH_BUILD_PATH]) @@ -61,11 +62,12 @@ func TestAddAdditionalEntriesToContextNoBuildPath(t *testing.T) { func TestAddAdditionalEntriesToContextWithBuildPath(t *testing.T) { context := make(map[string]interface{}) + ctx := &types.Context{} context[constants.CTX_BUILD_PATH] = "folder" command := builder.AddAdditionalEntriesToContext{} - NoError(t, command.Run(context)) + NoError(t, command.Run(context, ctx)) require.Equal(t, Abs(t, filepath.Join("folder", constants.FOLDER_PREPROC)), context[constants.CTX_PREPROC_PATH]) require.Equal(t, Abs(t, filepath.Join("folder", constants.FOLDER_SKETCH)), context[constants.CTX_SKETCH_BUILD_PATH]) diff --git a/src/arduino.cc/builder/test/add_build_board_property_if_missing_test.go b/src/arduino.cc/builder/test/add_build_board_property_if_missing_test.go index 81450f89..1568f098 100644 --- a/src/arduino.cc/builder/test/add_build_board_property_if_missing_test.go +++ b/src/arduino.cc/builder/test/add_build_board_property_if_missing_test.go @@ -40,6 +40,7 @@ import ( func TestAddBuildBoardPropertyIfMissing(t *testing.T) { context := make(map[string]interface{}) + ctx := &types.Context{} context[constants.CTX_HARDWARE_FOLDERS] = []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware", "user_hardware"} context[constants.CTX_FQBN] = "my_avr_platform:avr:mymega" @@ -51,7 +52,7 @@ func TestAddBuildBoardPropertyIfMissing(t *testing.T) { } for _, command := range commands { - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) } @@ -67,6 +68,7 @@ func TestAddBuildBoardPropertyIfMissing(t *testing.T) { func TestAddBuildBoardPropertyIfMissingNotMissing(t *testing.T) { context := make(map[string]interface{}) + ctx := &types.Context{} context[constants.CTX_HARDWARE_FOLDERS] = []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware", "user_hardware"} context[constants.CTX_FQBN] = "my_avr_platform:avr:mymega:cpu=atmega2560" @@ -78,7 +80,7 @@ func TestAddBuildBoardPropertyIfMissingNotMissing(t *testing.T) { } for _, command := range commands { - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) } diff --git a/src/arduino.cc/builder/test/additional_sketch_files_copier_test.go b/src/arduino.cc/builder/test/additional_sketch_files_copier_test.go index 326f6d77..8ed037f8 100644 --- a/src/arduino.cc/builder/test/additional_sketch_files_copier_test.go +++ b/src/arduino.cc/builder/test/additional_sketch_files_copier_test.go @@ -56,6 +56,7 @@ func (s ByFileInfoName) Less(i, j int) bool { func TestCopyOtherFiles(t *testing.T) { context := make(map[string]interface{}) + ctx := &types.Context{} buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) @@ -70,7 +71,7 @@ func TestCopyOtherFiles(t *testing.T) { } for _, command := range commands { - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) } @@ -94,6 +95,7 @@ func TestCopyOtherFiles(t *testing.T) { func TestCopyOtherFilesOnlyIfChanged(t *testing.T) { context := make(map[string]interface{}) + ctx := &types.Context{} buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) @@ -108,7 +110,7 @@ func TestCopyOtherFilesOnlyIfChanged(t *testing.T) { } for _, command := range commands { - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) } @@ -122,7 +124,7 @@ func TestCopyOtherFilesOnlyIfChanged(t *testing.T) { context[constants.CTX_SKETCH_LOCATION] = filepath.Join("sketch1", "sketch.ino") for _, command := range commands { - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) } diff --git a/src/arduino.cc/builder/test/builder_test.go b/src/arduino.cc/builder/test/builder_test.go index 3ec2c459..98992181 100644 --- a/src/arduino.cc/builder/test/builder_test.go +++ b/src/arduino.cc/builder/test/builder_test.go @@ -32,6 +32,7 @@ package test import ( "arduino.cc/builder" "arduino.cc/builder/constants" + "arduino.cc/builder/types" "github.com/stretchr/testify/require" "os" "os/exec" @@ -43,6 +44,7 @@ func TestBuilderEmptySketch(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) + ctx := &types.Context{} buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) @@ -58,7 +60,7 @@ func TestBuilderEmptySketch(t *testing.T) { context[constants.CTX_DEBUG_LEVEL] = 10 command := builder.Builder{} - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) _, err = os.Stat(filepath.Join(buildPath, constants.FOLDER_CORE, "HardwareSerial.cpp.o")) @@ -77,6 +79,7 @@ func TestBuilderBridge(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) + ctx := &types.Context{} buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) @@ -91,7 +94,7 @@ func TestBuilderBridge(t *testing.T) { context[constants.CTX_VERBOSE] = true command := builder.Builder{} - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) _, err = os.Stat(filepath.Join(buildPath, constants.FOLDER_CORE, "HardwareSerial.cpp.o")) @@ -112,6 +115,7 @@ func TestBuilderSketchWithConfig(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) + ctx := &types.Context{} buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) @@ -125,7 +129,7 @@ func TestBuilderSketchWithConfig(t *testing.T) { context[constants.CTX_BUILD_PROPERTIES_RUNTIME_IDE_VERSION] = "10600" command := builder.Builder{} - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) _, err = os.Stat(filepath.Join(buildPath, constants.FOLDER_CORE, "HardwareSerial.cpp.o")) @@ -146,6 +150,7 @@ func TestBuilderBridgeTwice(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) + ctx := &types.Context{} buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) @@ -159,11 +164,11 @@ func TestBuilderBridgeTwice(t *testing.T) { context[constants.CTX_BUILD_PROPERTIES_RUNTIME_IDE_VERSION] = "10600" command := builder.Builder{} - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) command = builder.Builder{} - err = command.Run(context) + err = command.Run(context, ctx) NoError(t, err) _, err = os.Stat(filepath.Join(buildPath, constants.FOLDER_CORE, "HardwareSerial.cpp.o")) @@ -184,6 +189,7 @@ func TestBuilderBridgeSAM(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) + ctx := &types.Context{} buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) @@ -198,7 +204,7 @@ func TestBuilderBridgeSAM(t *testing.T) { context[constants.CTX_WARNINGS_LEVEL] = "all" command := builder.Builder{} - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) _, err = os.Stat(filepath.Join(buildPath, constants.FOLDER_CORE, "syscalls_sam3.c.o")) @@ -228,6 +234,7 @@ func TestBuilderBridgeRedBearLab(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) + ctx := &types.Context{} buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) @@ -241,7 +248,7 @@ func TestBuilderBridgeRedBearLab(t *testing.T) { context[constants.CTX_BUILD_PROPERTIES_RUNTIME_IDE_VERSION] = "10600" command := builder.Builder{} - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) _, err = os.Stat(filepath.Join(buildPath, constants.FOLDER_CORE, "HardwareSerial.cpp.o")) @@ -262,6 +269,7 @@ func TestBuilderSketchNoFunctions(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) + ctx := &types.Context{} buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) @@ -275,7 +283,7 @@ func TestBuilderSketchNoFunctions(t *testing.T) { context[constants.CTX_BUILD_PROPERTIES_RUNTIME_IDE_VERSION] = "10600" command := builder.Builder{} - err := command.Run(context) + err := command.Run(context, ctx) require.Error(t, err) } @@ -283,6 +291,7 @@ func TestBuilderSketchWithBackup(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) + ctx := &types.Context{} buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) @@ -296,7 +305,7 @@ func TestBuilderSketchWithBackup(t *testing.T) { context[constants.CTX_BUILD_PROPERTIES_RUNTIME_IDE_VERSION] = "10600" command := builder.Builder{} - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) } @@ -304,6 +313,7 @@ func TestBuilderSketchWithOldLib(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) + ctx := &types.Context{} buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) @@ -317,7 +327,7 @@ func TestBuilderSketchWithOldLib(t *testing.T) { context[constants.CTX_BUILD_PROPERTIES_RUNTIME_IDE_VERSION] = "10600" command := builder.Builder{} - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) } @@ -325,6 +335,7 @@ func TestBuilderSketchWithSubfolders(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) + ctx := &types.Context{} buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) @@ -338,7 +349,7 @@ func TestBuilderSketchWithSubfolders(t *testing.T) { context[constants.CTX_BUILD_PROPERTIES_RUNTIME_IDE_VERSION] = "10600" command := builder.Builder{} - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) } @@ -346,6 +357,7 @@ func TestBuilderSketchBuildPathContainsUnusedPreviouslyCompiledLibrary(t *testin DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) + ctx := &types.Context{} buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) @@ -361,7 +373,7 @@ func TestBuilderSketchBuildPathContainsUnusedPreviouslyCompiledLibrary(t *testin context[constants.CTX_BUILD_PROPERTIES_RUNTIME_IDE_VERSION] = "10600" command := builder.Builder{} - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) _, err = os.Stat(filepath.Join(buildPath, constants.FOLDER_LIBRARIES, "SPI")) diff --git a/src/arduino.cc/builder/test/coan_runner_test.go b/src/arduino.cc/builder/test/coan_runner_test.go index 0393455b..37a524b0 100644 --- a/src/arduino.cc/builder/test/coan_runner_test.go +++ b/src/arduino.cc/builder/test/coan_runner_test.go @@ -45,6 +45,7 @@ func TestCoanRunner(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) + ctx := &types.Context{} buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) @@ -64,7 +65,7 @@ func TestCoanRunner(t *testing.T) { } for _, command := range commands { - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) } diff --git a/src/arduino.cc/builder/test/collect_all_source_files_from_folders_with_sources_test.go b/src/arduino.cc/builder/test/collect_all_source_files_from_folders_with_sources_test.go index 34acde4a..305c3fe4 100644 --- a/src/arduino.cc/builder/test/collect_all_source_files_from_folders_with_sources_test.go +++ b/src/arduino.cc/builder/test/collect_all_source_files_from_folders_with_sources_test.go @@ -41,6 +41,7 @@ import ( func TestCollectAllSourceFilesFromFoldersWithSources(t *testing.T) { context := make(map[string]interface{}) + ctx := &types.Context{} sourceFiles := &types.UniqueStringQueue{} context[constants.CTX_COLLECTED_SOURCE_FILES_QUEUE] = sourceFiles @@ -54,7 +55,7 @@ func TestCollectAllSourceFilesFromFoldersWithSources(t *testing.T) { } for _, command := range commands { - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) } @@ -68,6 +69,7 @@ func TestCollectAllSourceFilesFromFoldersWithSources(t *testing.T) { func TestCollectAllSourceFilesFromFoldersWithSourcesOfLibrary(t *testing.T) { context := make(map[string]interface{}) + ctx := &types.Context{} sourceFiles := &types.UniqueStringQueue{} context[constants.CTX_COLLECTED_SOURCE_FILES_QUEUE] = sourceFiles @@ -81,7 +83,7 @@ func TestCollectAllSourceFilesFromFoldersWithSourcesOfLibrary(t *testing.T) { } for _, command := range commands { - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) } @@ -103,6 +105,7 @@ func TestCollectAllSourceFilesFromFoldersWithSourcesOfLibrary(t *testing.T) { func TestCollectAllSourceFilesFromFoldersWithSourcesOfOldLibrary(t *testing.T) { context := make(map[string]interface{}) + ctx := &types.Context{} sourceFiles := &types.UniqueStringQueue{} context[constants.CTX_COLLECTED_SOURCE_FILES_QUEUE] = sourceFiles @@ -118,7 +121,7 @@ func TestCollectAllSourceFilesFromFoldersWithSourcesOfOldLibrary(t *testing.T) { } for _, command := range commands { - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) } diff --git a/src/arduino.cc/builder/test/create_build_options_map_test.go b/src/arduino.cc/builder/test/create_build_options_map_test.go index 08002c6f..c7996249 100644 --- a/src/arduino.cc/builder/test/create_build_options_map_test.go +++ b/src/arduino.cc/builder/test/create_build_options_map_test.go @@ -32,6 +32,7 @@ package test import ( "arduino.cc/builder" "arduino.cc/builder/constants" + "arduino.cc/builder/types" "arduino.cc/builder/utils" "github.com/stretchr/testify/require" "testing" @@ -39,6 +40,7 @@ import ( func TestCreateBuildOptionsMap(t *testing.T) { context := make(map[string]interface{}) + ctx := &types.Context{} context[constants.CTX_BUILD_PATH] = "buildPath" context[constants.CTX_HARDWARE_FOLDERS] = []string{"hardware", "hardware2"} @@ -51,7 +53,7 @@ func TestCreateBuildOptionsMap(t *testing.T) { context[constants.CTX_DEBUG_LEVEL] = 5 create := builder.CreateBuildOptionsMap{} - err := create.Run(context) + err := create.Run(context, ctx) NoError(t, err) buildOptions := context[constants.CTX_BUILD_OPTIONS].(map[string]string) diff --git a/src/arduino.cc/builder/test/ctags_parser_test.go b/src/arduino.cc/builder/test/ctags_parser_test.go index 9f671308..f17cee19 100644 --- a/src/arduino.cc/builder/test/ctags_parser_test.go +++ b/src/arduino.cc/builder/test/ctags_parser_test.go @@ -41,6 +41,7 @@ import ( func TestCTagsParserShouldListPrototypes(t *testing.T) { context := make(map[string]interface{}) + ctx := &types.Context{} bytes, err := ioutil.ReadFile(filepath.Join("ctags_output", "TestCTagsParserShouldListPrototypes.txt")) NoError(t, err) @@ -48,7 +49,7 @@ func TestCTagsParserShouldListPrototypes(t *testing.T) { context[constants.CTX_CTAGS_OUTPUT] = string(bytes) ctagsParser := ctags.CTagsParser{} - ctagsParser.Run(context) + ctagsParser.Run(context, ctx) tags := context[constants.CTX_CTAGS_OF_PREPROC_SOURCE].([]*types.CTag) @@ -89,6 +90,7 @@ func TestCTagsParserShouldListPrototypes(t *testing.T) { func TestCTagsParserShouldListTemplates(t *testing.T) { context := make(map[string]interface{}) + ctx := &types.Context{} bytes, err := ioutil.ReadFile(filepath.Join("ctags_output", "TestCTagsParserShouldListTemplates.txt")) NoError(t, err) @@ -96,7 +98,7 @@ func TestCTagsParserShouldListTemplates(t *testing.T) { context[constants.CTX_CTAGS_OUTPUT] = string(bytes) ctagsParser := ctags.CTagsParser{} - ctagsParser.Run(context) + ctagsParser.Run(context, ctx) tags := context[constants.CTX_CTAGS_OF_PREPROC_SOURCE].([]*types.CTag) @@ -117,6 +119,7 @@ func TestCTagsParserShouldListTemplates(t *testing.T) { func TestCTagsParserShouldListTemplates2(t *testing.T) { context := make(map[string]interface{}) + ctx := &types.Context{} bytes, err := ioutil.ReadFile(filepath.Join("ctags_output", "TestCTagsParserShouldListTemplates2.txt")) NoError(t, err) @@ -124,7 +127,7 @@ func TestCTagsParserShouldListTemplates2(t *testing.T) { context[constants.CTX_CTAGS_OUTPUT] = string(bytes) ctagsParser := ctags.CTagsParser{} - ctagsParser.Run(context) + ctagsParser.Run(context, ctx) tags := context[constants.CTX_CTAGS_OF_PREPROC_SOURCE].([]*types.CTag) @@ -147,6 +150,7 @@ func TestCTagsParserShouldListTemplates2(t *testing.T) { func TestCTagsParserShouldDealWithClasses(t *testing.T) { context := make(map[string]interface{}) + ctx := &types.Context{} bytes, err := ioutil.ReadFile(filepath.Join("ctags_output", "TestCTagsParserShouldDealWithClasses.txt")) NoError(t, err) @@ -154,7 +158,7 @@ func TestCTagsParserShouldDealWithClasses(t *testing.T) { context[constants.CTX_CTAGS_OUTPUT] = string(bytes) ctagsParser := ctags.CTagsParser{} - ctagsParser.Run(context) + ctagsParser.Run(context, ctx) tags := context[constants.CTX_CTAGS_OF_PREPROC_SOURCE].([]*types.CTag) @@ -169,6 +173,7 @@ func TestCTagsParserShouldDealWithClasses(t *testing.T) { func TestCTagsParserShouldDealWithStructs(t *testing.T) { context := make(map[string]interface{}) + ctx := &types.Context{} bytes, err := ioutil.ReadFile(filepath.Join("ctags_output", "TestCTagsParserShouldDealWithStructs.txt")) NoError(t, err) @@ -176,7 +181,7 @@ func TestCTagsParserShouldDealWithStructs(t *testing.T) { context[constants.CTX_CTAGS_OUTPUT] = string(bytes) ctagsParser := ctags.CTagsParser{} - ctagsParser.Run(context) + ctagsParser.Run(context, ctx) tags := context[constants.CTX_CTAGS_OF_PREPROC_SOURCE].([]*types.CTag) @@ -201,6 +206,7 @@ func TestCTagsParserShouldDealWithStructs(t *testing.T) { func TestCTagsParserShouldDealWithMacros(t *testing.T) { context := make(map[string]interface{}) + ctx := &types.Context{} bytes, err := ioutil.ReadFile(filepath.Join("ctags_output", "TestCTagsParserShouldDealWithMacros.txt")) NoError(t, err) @@ -208,7 +214,7 @@ func TestCTagsParserShouldDealWithMacros(t *testing.T) { context[constants.CTX_CTAGS_OUTPUT] = string(bytes) ctagsParser := ctags.CTagsParser{} - ctagsParser.Run(context) + ctagsParser.Run(context, ctx) tags := context[constants.CTX_CTAGS_OF_PREPROC_SOURCE].([]*types.CTag) @@ -241,6 +247,7 @@ func TestCTagsParserShouldDealWithMacros(t *testing.T) { func TestCTagsParserShouldDealFunctionWithDifferentSignatures(t *testing.T) { context := make(map[string]interface{}) + ctx := &types.Context{} bytes, err := ioutil.ReadFile(filepath.Join("ctags_output", "TestCTagsParserShouldDealFunctionWithDifferentSignatures.txt")) NoError(t, err) @@ -248,7 +255,7 @@ func TestCTagsParserShouldDealFunctionWithDifferentSignatures(t *testing.T) { context[constants.CTX_CTAGS_OUTPUT] = string(bytes) ctagsParser := ctags.CTagsParser{} - ctagsParser.Run(context) + ctagsParser.Run(context, ctx) tags := context[constants.CTX_CTAGS_OF_PREPROC_SOURCE].([]*types.CTag) @@ -266,6 +273,7 @@ func TestCTagsParserShouldDealFunctionWithDifferentSignatures(t *testing.T) { func TestCTagsParserClassMembersAreFilteredOut(t *testing.T) { context := make(map[string]interface{}) + ctx := &types.Context{} bytes, err := ioutil.ReadFile(filepath.Join("ctags_output", "TestCTagsParserClassMembersAreFilteredOut.txt")) NoError(t, err) @@ -273,7 +281,7 @@ func TestCTagsParserClassMembersAreFilteredOut(t *testing.T) { context[constants.CTX_CTAGS_OUTPUT] = string(bytes) ctagsParser := ctags.CTagsParser{} - ctagsParser.Run(context) + ctagsParser.Run(context, ctx) tags := context[constants.CTX_CTAGS_OF_PREPROC_SOURCE].([]*types.CTag) @@ -300,6 +308,7 @@ func TestCTagsParserClassMembersAreFilteredOut(t *testing.T) { func TestCTagsParserStructWithFunctions(t *testing.T) { context := make(map[string]interface{}) + ctx := &types.Context{} bytes, err := ioutil.ReadFile(filepath.Join("ctags_output", "TestCTagsParserStructWithFunctions.txt")) NoError(t, err) @@ -307,7 +316,7 @@ func TestCTagsParserStructWithFunctions(t *testing.T) { context[constants.CTX_CTAGS_OUTPUT] = string(bytes) ctagsParser := ctags.CTagsParser{} - ctagsParser.Run(context) + ctagsParser.Run(context, ctx) tags := context[constants.CTX_CTAGS_OF_PREPROC_SOURCE].([]*types.CTag) @@ -342,6 +351,7 @@ func TestCTagsParserStructWithFunctions(t *testing.T) { func TestCTagsParserDefaultArguments(t *testing.T) { context := make(map[string]interface{}) + ctx := &types.Context{} bytes, err := ioutil.ReadFile(filepath.Join("ctags_output", "TestCTagsParserDefaultArguments.txt")) NoError(t, err) @@ -349,7 +359,7 @@ func TestCTagsParserDefaultArguments(t *testing.T) { context[constants.CTX_CTAGS_OUTPUT] = string(bytes) ctagsParser := ctags.CTagsParser{} - ctagsParser.Run(context) + ctagsParser.Run(context, ctx) tags := context[constants.CTX_CTAGS_OF_PREPROC_SOURCE].([]*types.CTag) @@ -368,6 +378,7 @@ func TestCTagsParserDefaultArguments(t *testing.T) { func TestCTagsParserNamespace(t *testing.T) { context := make(map[string]interface{}) + ctx := &types.Context{} bytes, err := ioutil.ReadFile(filepath.Join("ctags_output", "TestCTagsParserNamespace.txt")) NoError(t, err) @@ -375,7 +386,7 @@ func TestCTagsParserNamespace(t *testing.T) { context[constants.CTX_CTAGS_OUTPUT] = string(bytes) ctagsParser := ctags.CTagsParser{} - ctagsParser.Run(context) + ctagsParser.Run(context, ctx) tags := context[constants.CTX_CTAGS_OF_PREPROC_SOURCE].([]*types.CTag) @@ -394,6 +405,7 @@ func TestCTagsParserNamespace(t *testing.T) { func TestCTagsParserStatic(t *testing.T) { context := make(map[string]interface{}) + ctx := &types.Context{} bytes, err := ioutil.ReadFile(filepath.Join("ctags_output", "TestCTagsParserStatic.txt")) NoError(t, err) @@ -401,7 +413,7 @@ func TestCTagsParserStatic(t *testing.T) { context[constants.CTX_CTAGS_OUTPUT] = string(bytes) ctagsParser := ctags.CTagsParser{} - ctagsParser.Run(context) + ctagsParser.Run(context, ctx) tags := context[constants.CTX_CTAGS_OF_PREPROC_SOURCE].([]*types.CTag) @@ -419,6 +431,7 @@ func TestCTagsParserStatic(t *testing.T) { func TestCTagsParserFunctionPointer(t *testing.T) { context := make(map[string]interface{}) + ctx := &types.Context{} bytes, err := ioutil.ReadFile(filepath.Join("ctags_output", "TestCTagsParserFunctionPointer.txt")) NoError(t, err) @@ -426,7 +439,7 @@ func TestCTagsParserFunctionPointer(t *testing.T) { context[constants.CTX_CTAGS_OUTPUT] = string(bytes) ctagsParser := ctags.CTagsParser{} - ctagsParser.Run(context) + ctagsParser.Run(context, ctx) tags := context[constants.CTX_CTAGS_OF_PREPROC_SOURCE].([]*types.CTag) @@ -447,6 +460,7 @@ func TestCTagsParserFunctionPointer(t *testing.T) { func TestCTagsParserFunctionPointers(t *testing.T) { context := make(map[string]interface{}) + ctx := &types.Context{} bytes, err := ioutil.ReadFile(filepath.Join("ctags_output", "TestCTagsParserFunctionPointers.txt")) NoError(t, err) @@ -454,7 +468,7 @@ func TestCTagsParserFunctionPointers(t *testing.T) { context[constants.CTX_CTAGS_OUTPUT] = string(bytes) ctagsParser := ctags.CTagsParser{} - ctagsParser.Run(context) + ctagsParser.Run(context, ctx) tags := context[constants.CTX_CTAGS_OF_PREPROC_SOURCE].([]*types.CTag) diff --git a/src/arduino.cc/builder/test/ctags_runner_test.go b/src/arduino.cc/builder/test/ctags_runner_test.go index 8cb77b9e..1c601420 100644 --- a/src/arduino.cc/builder/test/ctags_runner_test.go +++ b/src/arduino.cc/builder/test/ctags_runner_test.go @@ -45,6 +45,7 @@ func TestCTagsRunner(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) + ctx := &types.Context{} buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) @@ -75,7 +76,7 @@ func TestCTagsRunner(t *testing.T) { } for _, command := range commands { - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) } @@ -95,6 +96,7 @@ func TestCTagsRunnerSketchWithClass(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) + ctx := &types.Context{} buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) @@ -125,7 +127,7 @@ func TestCTagsRunnerSketchWithClass(t *testing.T) { } for _, command := range commands { - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) } @@ -143,6 +145,7 @@ func TestCTagsRunnerSketchWithTypename(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) + ctx := &types.Context{} buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) @@ -173,7 +176,7 @@ func TestCTagsRunnerSketchWithTypename(t *testing.T) { } for _, command := range commands { - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) } @@ -190,6 +193,7 @@ func TestCTagsRunnerSketchWithNamespace(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) + ctx := &types.Context{} buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) @@ -220,7 +224,7 @@ func TestCTagsRunnerSketchWithNamespace(t *testing.T) { } for _, command := range commands { - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) } @@ -236,6 +240,7 @@ func TestCTagsRunnerSketchWithTemplates(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) + ctx := &types.Context{} buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) @@ -266,7 +271,7 @@ func TestCTagsRunnerSketchWithTemplates(t *testing.T) { } for _, command := range commands { - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) } diff --git a/src/arduino.cc/builder/test/ctags_to_prototypes_test.go b/src/arduino.cc/builder/test/ctags_to_prototypes_test.go index 29597646..7e30cd00 100644 --- a/src/arduino.cc/builder/test/ctags_to_prototypes_test.go +++ b/src/arduino.cc/builder/test/ctags_to_prototypes_test.go @@ -41,6 +41,7 @@ import ( func TestCTagsToPrototypesShouldListPrototypes(t *testing.T) { context := make(map[string]interface{}) + ctx := &types.Context{} bytes, err := ioutil.ReadFile(filepath.Join("ctags_output", "TestCTagsParserShouldListPrototypes.txt")) NoError(t, err) @@ -54,7 +55,7 @@ func TestCTagsToPrototypesShouldListPrototypes(t *testing.T) { } for _, command := range commands { - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) } @@ -74,6 +75,7 @@ func TestCTagsToPrototypesShouldListPrototypes(t *testing.T) { func TestCTagsToPrototypesShouldListTemplates(t *testing.T) { context := make(map[string]interface{}) + ctx := &types.Context{} bytes, err := ioutil.ReadFile(filepath.Join("ctags_output", "TestCTagsParserShouldListTemplates.txt")) NoError(t, err) @@ -87,7 +89,7 @@ func TestCTagsToPrototypesShouldListTemplates(t *testing.T) { } for _, command := range commands { - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) } @@ -105,6 +107,7 @@ func TestCTagsToPrototypesShouldListTemplates(t *testing.T) { func TestCTagsToPrototypesShouldListTemplates2(t *testing.T) { context := make(map[string]interface{}) + ctx := &types.Context{} bytes, err := ioutil.ReadFile(filepath.Join("ctags_output", "TestCTagsParserShouldListTemplates2.txt")) NoError(t, err) @@ -118,7 +121,7 @@ func TestCTagsToPrototypesShouldListTemplates2(t *testing.T) { } for _, command := range commands { - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) } @@ -137,6 +140,7 @@ func TestCTagsToPrototypesShouldListTemplates2(t *testing.T) { func TestCTagsToPrototypesShouldDealWithClasses(t *testing.T) { context := make(map[string]interface{}) + ctx := &types.Context{} bytes, err := ioutil.ReadFile(filepath.Join("ctags_output", "TestCTagsParserShouldDealWithClasses.txt")) NoError(t, err) @@ -150,7 +154,7 @@ func TestCTagsToPrototypesShouldDealWithClasses(t *testing.T) { } for _, command := range commands { - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) } @@ -164,6 +168,7 @@ func TestCTagsToPrototypesShouldDealWithClasses(t *testing.T) { func TestCTagsToPrototypesShouldDealWithStructs(t *testing.T) { context := make(map[string]interface{}) + ctx := &types.Context{} bytes, err := ioutil.ReadFile(filepath.Join("ctags_output", "TestCTagsParserShouldDealWithStructs.txt")) NoError(t, err) @@ -177,7 +182,7 @@ func TestCTagsToPrototypesShouldDealWithStructs(t *testing.T) { } for _, command := range commands { - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) } @@ -195,6 +200,7 @@ func TestCTagsToPrototypesShouldDealWithStructs(t *testing.T) { func TestCTagsToPrototypesShouldDealWithMacros(t *testing.T) { context := make(map[string]interface{}) + ctx := &types.Context{} bytes, err := ioutil.ReadFile(filepath.Join("ctags_output", "TestCTagsParserShouldDealWithMacros.txt")) NoError(t, err) @@ -208,7 +214,7 @@ func TestCTagsToPrototypesShouldDealWithMacros(t *testing.T) { } for _, command := range commands { - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) } @@ -228,6 +234,7 @@ func TestCTagsToPrototypesShouldDealWithMacros(t *testing.T) { func TestCTagsToPrototypesShouldDealFunctionWithDifferentSignatures(t *testing.T) { context := make(map[string]interface{}) + ctx := &types.Context{} bytes, err := ioutil.ReadFile(filepath.Join("ctags_output", "TestCTagsParserShouldDealFunctionWithDifferentSignatures.txt")) NoError(t, err) @@ -241,7 +248,7 @@ func TestCTagsToPrototypesShouldDealFunctionWithDifferentSignatures(t *testing.T } for _, command := range commands { - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) } @@ -257,6 +264,7 @@ func TestCTagsToPrototypesShouldDealFunctionWithDifferentSignatures(t *testing.T func TestCTagsToPrototypesClassMembersAreFilteredOut(t *testing.T) { context := make(map[string]interface{}) + ctx := &types.Context{} bytes, err := ioutil.ReadFile(filepath.Join("ctags_output", "TestCTagsParserClassMembersAreFilteredOut.txt")) NoError(t, err) @@ -270,7 +278,7 @@ func TestCTagsToPrototypesClassMembersAreFilteredOut(t *testing.T) { } for _, command := range commands { - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) } @@ -287,6 +295,7 @@ func TestCTagsToPrototypesClassMembersAreFilteredOut(t *testing.T) { func TestCTagsToPrototypesStructWithFunctions(t *testing.T) { context := make(map[string]interface{}) + ctx := &types.Context{} bytes, err := ioutil.ReadFile(filepath.Join("ctags_output", "TestCTagsParserStructWithFunctions.txt")) NoError(t, err) @@ -300,7 +309,7 @@ func TestCTagsToPrototypesStructWithFunctions(t *testing.T) { } for _, command := range commands { - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) } @@ -317,6 +326,7 @@ func TestCTagsToPrototypesStructWithFunctions(t *testing.T) { func TestCTagsToPrototypesDefaultArguments(t *testing.T) { context := make(map[string]interface{}) + ctx := &types.Context{} bytes, err := ioutil.ReadFile(filepath.Join("ctags_output", "TestCTagsParserDefaultArguments.txt")) NoError(t, err) @@ -330,7 +340,7 @@ func TestCTagsToPrototypesDefaultArguments(t *testing.T) { } for _, command := range commands { - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) } @@ -348,6 +358,7 @@ func TestCTagsToPrototypesDefaultArguments(t *testing.T) { func TestCTagsToPrototypesNamespace(t *testing.T) { context := make(map[string]interface{}) + ctx := &types.Context{} bytes, err := ioutil.ReadFile(filepath.Join("ctags_output", "TestCTagsParserNamespace.txt")) NoError(t, err) @@ -361,7 +372,7 @@ func TestCTagsToPrototypesNamespace(t *testing.T) { } for _, command := range commands { - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) } @@ -378,6 +389,7 @@ func TestCTagsToPrototypesNamespace(t *testing.T) { func TestCTagsToPrototypesStatic(t *testing.T) { context := make(map[string]interface{}) + ctx := &types.Context{} bytes, err := ioutil.ReadFile(filepath.Join("ctags_output", "TestCTagsParserStatic.txt")) NoError(t, err) @@ -391,7 +403,7 @@ func TestCTagsToPrototypesStatic(t *testing.T) { } for _, command := range commands { - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) } @@ -410,6 +422,7 @@ func TestCTagsToPrototypesStatic(t *testing.T) { func TestCTagsToPrototypesFunctionPointer(t *testing.T) { context := make(map[string]interface{}) + ctx := &types.Context{} bytes, err := ioutil.ReadFile(filepath.Join("ctags_output", "TestCTagsParserFunctionPointer.txt")) NoError(t, err) @@ -423,7 +436,7 @@ func TestCTagsToPrototypesFunctionPointer(t *testing.T) { } for _, command := range commands { - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) } @@ -441,6 +454,7 @@ func TestCTagsToPrototypesFunctionPointer(t *testing.T) { func TestCTagsToPrototypesFunctionPointers(t *testing.T) { context := make(map[string]interface{}) + ctx := &types.Context{} bytes, err := ioutil.ReadFile(filepath.Join("ctags_output", "TestCTagsParserFunctionPointers.txt")) NoError(t, err) @@ -454,7 +468,7 @@ func TestCTagsToPrototypesFunctionPointers(t *testing.T) { } for _, command := range commands { - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) } diff --git a/src/arduino.cc/builder/test/fail_if_buildpath_equals_sketchpath_test.go b/src/arduino.cc/builder/test/fail_if_buildpath_equals_sketchpath_test.go index 2f02bb8b..2d6d7ba6 100644 --- a/src/arduino.cc/builder/test/fail_if_buildpath_equals_sketchpath_test.go +++ b/src/arduino.cc/builder/test/fail_if_buildpath_equals_sketchpath_test.go @@ -32,26 +32,29 @@ package test import ( "arduino.cc/builder" "arduino.cc/builder/constants" + "arduino.cc/builder/types" "github.com/stretchr/testify/require" "testing" ) func TestFailIfBuildPathEqualsSketchPath(t *testing.T) { context := make(map[string]interface{}) + ctx := &types.Context{} context[constants.CTX_BUILD_PATH] = "buildPath" context[constants.CTX_SKETCH_LOCATION] = "buildPath/sketch.ino" command := builder.FailIfBuildPathEqualsSketchPath{} - require.Error(t, command.Run(context)) + require.Error(t, command.Run(context, ctx)) } func TestFailIfBuildPathEqualsSketchPathSketchPathDiffers(t *testing.T) { context := make(map[string]interface{}) + ctx := &types.Context{} context[constants.CTX_BUILD_PATH] = "buildPath" context[constants.CTX_SKETCH_LOCATION] = "sketchPath/sketch.ino" command := builder.FailIfBuildPathEqualsSketchPath{} - NoError(t, command.Run(context)) + NoError(t, command.Run(context, ctx)) } diff --git a/src/arduino.cc/builder/test/generate_buildpath_if_missing_test.go b/src/arduino.cc/builder/test/generate_buildpath_if_missing_test.go index 48830a98..f9c18a61 100644 --- a/src/arduino.cc/builder/test/generate_buildpath_if_missing_test.go +++ b/src/arduino.cc/builder/test/generate_buildpath_if_missing_test.go @@ -41,11 +41,12 @@ import ( func TestGenerateBuildPathIfMissing(t *testing.T) { context := make(map[string]interface{}) + ctx := &types.Context{} context[constants.CTX_SKETCH_LOCATION] = "test" command := builder.GenerateBuildPathIfMissing{} - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) require.Equal(t, filepath.Join(os.TempDir(), "arduino-sketch-098F6BCD4621D373CADE4E832627B4F6"), context[constants.CTX_BUILD_PATH]) @@ -55,12 +56,13 @@ func TestGenerateBuildPathIfMissing(t *testing.T) { func TestGenerateBuildPathIfEmpty(t *testing.T) { context := make(map[string]interface{}) + ctx := &types.Context{} context[constants.CTX_SKETCH_LOCATION] = "test" context[constants.CTX_BUILD_PATH] = constants.EMPTY_STRING createBuildPathIfMissing := builder.GenerateBuildPathIfMissing{} - err := createBuildPathIfMissing.Run(context) + err := createBuildPathIfMissing.Run(context, ctx) NoError(t, err) require.Equal(t, filepath.Join(os.TempDir(), "arduino-sketch-098F6BCD4621D373CADE4E832627B4F6"), context[constants.CTX_BUILD_PATH]) @@ -70,11 +72,12 @@ func TestGenerateBuildPathIfEmpty(t *testing.T) { func TestDontGenerateBuildPathIfPresent(t *testing.T) { context := make(map[string]interface{}) + ctx := &types.Context{} context[constants.CTX_BUILD_PATH] = "test" createBuildPathIfMissing := builder.GenerateBuildPathIfMissing{} - err := createBuildPathIfMissing.Run(context) + err := createBuildPathIfMissing.Run(context, ctx) NoError(t, err) require.Equal(t, "test", context[constants.CTX_BUILD_PATH]) @@ -82,6 +85,7 @@ func TestDontGenerateBuildPathIfPresent(t *testing.T) { func TestGenerateBuildPathAndEnsureItExists(t *testing.T) { context := make(map[string]interface{}) + ctx := &types.Context{} context[constants.CTX_SKETCH_LOCATION] = "test" @@ -91,7 +95,7 @@ func TestGenerateBuildPathAndEnsureItExists(t *testing.T) { } for _, command := range commands { - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) } diff --git a/src/arduino.cc/builder/test/hardware_loader_test.go b/src/arduino.cc/builder/test/hardware_loader_test.go index 443204d2..88843fbb 100644 --- a/src/arduino.cc/builder/test/hardware_loader_test.go +++ b/src/arduino.cc/builder/test/hardware_loader_test.go @@ -42,6 +42,7 @@ import ( func TestLoadHardware(t *testing.T) { context := make(map[string]interface{}) + ctx := &types.Context{} context[constants.CTX_HARDWARE_FOLDERS] = []string{"downloaded_hardware", filepath.Join("..", "hardware"), "hardware"} commands := []types.Command{ @@ -50,7 +51,7 @@ func TestLoadHardware(t *testing.T) { } for _, command := range commands { - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) } @@ -86,6 +87,7 @@ func TestLoadHardware(t *testing.T) { func TestLoadHardwareMixingUserHardwareFolder(t *testing.T) { context := make(map[string]interface{}) + ctx := &types.Context{} context[constants.CTX_HARDWARE_FOLDERS] = []string{"downloaded_hardware", filepath.Join("..", "hardware"), "hardware", "user_hardware"} commands := []types.Command{ @@ -97,7 +99,7 @@ func TestLoadHardwareMixingUserHardwareFolder(t *testing.T) { } for _, command := range commands { - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) } @@ -156,6 +158,7 @@ func TestLoadHardwareMixingUserHardwareFolder(t *testing.T) { func TestLoadHardwareWithBoardManagerFolderStructure(t *testing.T) { context := make(map[string]interface{}) + ctx := &types.Context{} context[constants.CTX_HARDWARE_FOLDERS] = []string{"downloaded_board_manager_stuff"} commands := []types.Command{ @@ -164,7 +167,7 @@ func TestLoadHardwareWithBoardManagerFolderStructure(t *testing.T) { } for _, command := range commands { - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) } @@ -204,6 +207,7 @@ func TestLoadHardwareWithBoardManagerFolderStructure(t *testing.T) { func TestLoadLotsOfHardware(t *testing.T) { context := make(map[string]interface{}) + ctx := &types.Context{} context[constants.CTX_HARDWARE_FOLDERS] = []string{"downloaded_board_manager_stuff", "downloaded_hardware", filepath.Join("..", "hardware"), "hardware", "user_hardware"} @@ -213,7 +217,7 @@ func TestLoadLotsOfHardware(t *testing.T) { } for _, command := range commands { - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) } diff --git a/src/arduino.cc/builder/test/helper.go b/src/arduino.cc/builder/test/helper.go index 0bdffa51..62a3455b 100644 --- a/src/arduino.cc/builder/test/helper.go +++ b/src/arduino.cc/builder/test/helper.go @@ -101,7 +101,7 @@ type CopyContextKeys struct { To string } -func (s *CopyContextKeys) Run(context map[string]interface{}) error { +func (s *CopyContextKeys) Run(context map[string]interface{}, ctx *types.Context) error { context[s.To] = context[s.From] return nil } diff --git a/src/arduino.cc/builder/test/includes_finder_with_gcc_test.go b/src/arduino.cc/builder/test/includes_finder_with_gcc_test.go index 1fc613bd..d6954dd1 100644 --- a/src/arduino.cc/builder/test/includes_finder_with_gcc_test.go +++ b/src/arduino.cc/builder/test/includes_finder_with_gcc_test.go @@ -45,6 +45,7 @@ func TestIncludesFinderWithGCC(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) + ctx := &types.Context{} buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) @@ -67,7 +68,7 @@ func TestIncludesFinderWithGCC(t *testing.T) { } for _, command := range commands { - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) } @@ -78,6 +79,7 @@ func TestIncludesFinderWithGCCSketchWithConfig(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) + ctx := &types.Context{} buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) @@ -102,7 +104,7 @@ func TestIncludesFinderWithGCCSketchWithConfig(t *testing.T) { } for _, command := range commands { - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) } @@ -120,6 +122,7 @@ func TestIncludesFinderWithGCCSketchWithDependendLibraries(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) + ctx := &types.Context{} buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) @@ -143,7 +146,7 @@ func TestIncludesFinderWithGCCSketchWithDependendLibraries(t *testing.T) { } for _, command := range commands { - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) } @@ -171,6 +174,7 @@ func TestIncludesFinderWithGCCSketchWithThatChecksIfSPIHasTransactions(t *testin DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) + ctx := &types.Context{} buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) @@ -195,7 +199,7 @@ func TestIncludesFinderWithGCCSketchWithThatChecksIfSPIHasTransactions(t *testin } for _, command := range commands { - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) } @@ -213,6 +217,7 @@ func TestIncludesFinderWithGCCSketchWithThatChecksIfSPIHasTransactionsAndInclude DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) + ctx := &types.Context{} buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) @@ -235,12 +240,12 @@ func TestIncludesFinderWithGCCSketchWithThatChecksIfSPIHasTransactionsAndInclude } for _, command := range commands { - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) } command := &builder.ContainerFindIncludes{} - err := command.Run(context) + err := command.Run(context, ctx) require.Error(t, err) require.NotNil(t, context[constants.CTX_INCLUDES]) diff --git a/src/arduino.cc/builder/test/includes_finder_with_regexp_test.go b/src/arduino.cc/builder/test/includes_finder_with_regexp_test.go index b87de9db..d572eca9 100644 --- a/src/arduino.cc/builder/test/includes_finder_with_regexp_test.go +++ b/src/arduino.cc/builder/test/includes_finder_with_regexp_test.go @@ -44,6 +44,7 @@ func TestIncludesFinderWithRegExpCoanOutput(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) + ctx := &types.Context{} buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) @@ -68,7 +69,7 @@ func TestIncludesFinderWithRegExpCoanOutput(t *testing.T) { } for _, command := range commands { - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) } @@ -82,6 +83,7 @@ func TestIncludesFinderWithRegExpCoanOutput(t *testing.T) { func TestIncludesFinderWithRegExp(t *testing.T) { context := make(map[string]interface{}) + ctx := &types.Context{} output := "/some/path/sketch.ino:1:17: fatal error: SPI.h: No such file or directory\n" + "#include \n" + @@ -90,7 +92,7 @@ func TestIncludesFinderWithRegExp(t *testing.T) { context["source"] = output parser := builder.IncludesFinderWithRegExp{ContextField: "source"} - err := parser.Run(context) + err := parser.Run(context, ctx) NoError(t, err) require.NotNil(t, context[constants.CTX_INCLUDES]) @@ -101,13 +103,14 @@ func TestIncludesFinderWithRegExp(t *testing.T) { func TestIncludesFinderWithRegExpEmptyOutput(t *testing.T) { context := make(map[string]interface{}) + ctx := &types.Context{} output := "" context["source"] = output parser := builder.IncludesFinderWithRegExp{ContextField: "source"} - err := parser.Run(context) + err := parser.Run(context, ctx) NoError(t, err) require.NotNil(t, context[constants.CTX_INCLUDES]) @@ -117,6 +120,7 @@ func TestIncludesFinderWithRegExpEmptyOutput(t *testing.T) { func TestIncludesFinderWithRegExpPreviousIncludes(t *testing.T) { context := make(map[string]interface{}) + ctx := &types.Context{} context[constants.CTX_INCLUDES] = []string{"test.h"} @@ -128,7 +132,7 @@ func TestIncludesFinderWithRegExpPreviousIncludes(t *testing.T) { context["source"] = output parser := builder.IncludesFinderWithRegExp{ContextField: "source"} - err := parser.Run(context) + err := parser.Run(context, ctx) NoError(t, err) require.NotNil(t, context[constants.CTX_INCLUDES]) @@ -141,6 +145,7 @@ func TestIncludesFinderWithRegExpPreviousIncludes(t *testing.T) { func TestIncludesFinderWithRegExpPaddedIncludes(t *testing.T) { context := make(map[string]interface{}) + ctx := &types.Context{} context[constants.CTX_INCLUDES] = []string{} @@ -151,7 +156,7 @@ func TestIncludesFinderWithRegExpPaddedIncludes(t *testing.T) { context["source"] = output parser := builder.IncludesFinderWithRegExp{ContextField: "source"} - err := parser.Run(context) + err := parser.Run(context, ctx) NoError(t, err) require.NotNil(t, context[constants.CTX_INCLUDES]) @@ -163,6 +168,7 @@ func TestIncludesFinderWithRegExpPaddedIncludes(t *testing.T) { func TestIncludesFinderWithRegExpPaddedIncludes2(t *testing.T) { context := make(map[string]interface{}) + ctx := &types.Context{} context[constants.CTX_INCLUDES] = []string{} @@ -173,7 +179,7 @@ func TestIncludesFinderWithRegExpPaddedIncludes2(t *testing.T) { context["source"] = output parser := builder.IncludesFinderWithRegExp{ContextField: "source"} - err := parser.Run(context) + err := parser.Run(context, ctx) NoError(t, err) require.NotNil(t, context[constants.CTX_INCLUDES]) @@ -185,6 +191,7 @@ func TestIncludesFinderWithRegExpPaddedIncludes2(t *testing.T) { func TestIncludesFinderWithRegExpPaddedIncludes3(t *testing.T) { context := make(map[string]interface{}) + ctx := &types.Context{} context[constants.CTX_INCLUDES] = []string{} @@ -194,7 +201,7 @@ func TestIncludesFinderWithRegExpPaddedIncludes3(t *testing.T) { context["source"] = output parser := builder.IncludesFinderWithRegExp{ContextField: "source"} - err := parser.Run(context) + err := parser.Run(context, ctx) NoError(t, err) require.NotNil(t, context[constants.CTX_INCLUDES]) diff --git a/src/arduino.cc/builder/test/includes_to_include_folders_test.go b/src/arduino.cc/builder/test/includes_to_include_folders_test.go index 8d29018b..49108ba8 100644 --- a/src/arduino.cc/builder/test/includes_to_include_folders_test.go +++ b/src/arduino.cc/builder/test/includes_to_include_folders_test.go @@ -44,6 +44,7 @@ func TestIncludesToIncludeFolders(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) + ctx := &types.Context{} buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) @@ -68,7 +69,7 @@ func TestIncludesToIncludeFolders(t *testing.T) { } for _, command := range commands { - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) } @@ -85,6 +86,7 @@ func TestIncludesToIncludeFoldersSketchWithIfDef(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) + ctx := &types.Context{} buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) @@ -109,7 +111,7 @@ func TestIncludesToIncludeFoldersSketchWithIfDef(t *testing.T) { } for _, command := range commands { - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) } @@ -124,6 +126,7 @@ func TestIncludesToIncludeFoldersIRremoteLibrary(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) + ctx := &types.Context{} buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) @@ -148,7 +151,7 @@ func TestIncludesToIncludeFoldersIRremoteLibrary(t *testing.T) { } for _, command := range commands { - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) } @@ -168,6 +171,7 @@ func TestIncludesToIncludeFoldersANewLibrary(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) + ctx := &types.Context{} buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) @@ -192,7 +196,7 @@ func TestIncludesToIncludeFoldersANewLibrary(t *testing.T) { } for _, command := range commands { - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) } @@ -212,6 +216,7 @@ func TestIncludesToIncludeFoldersDuplicateLibs(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) + ctx := &types.Context{} buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) @@ -235,7 +240,7 @@ func TestIncludesToIncludeFoldersDuplicateLibs(t *testing.T) { } for _, command := range commands { - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) } @@ -254,6 +259,7 @@ func TestIncludesToIncludeFoldersDuplicateLibsWithConflictingLibsOutsideOfPlatfo DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) + ctx := &types.Context{} buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) @@ -278,7 +284,7 @@ func TestIncludesToIncludeFoldersDuplicateLibsWithConflictingLibsOutsideOfPlatfo } for _, command := range commands { - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) } @@ -297,6 +303,7 @@ func TestIncludesToIncludeFoldersDuplicateLibs2(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) + ctx := &types.Context{} buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) @@ -321,7 +328,7 @@ func TestIncludesToIncludeFoldersDuplicateLibs2(t *testing.T) { } for _, command := range commands { - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) } diff --git a/src/arduino.cc/builder/test/libraries_loader_test.go b/src/arduino.cc/builder/test/libraries_loader_test.go index c0ab45bf..f42b3862 100644 --- a/src/arduino.cc/builder/test/libraries_loader_test.go +++ b/src/arduino.cc/builder/test/libraries_loader_test.go @@ -43,6 +43,7 @@ func TestLoadLibrariesAVR(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) + ctx := &types.Context{} context[constants.CTX_HARDWARE_FOLDERS] = []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"} context[constants.CTX_FQBN] = "arduino:avr:leonardo" @@ -58,7 +59,7 @@ func TestLoadLibrariesAVR(t *testing.T) { } for _, command := range commands { - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) } @@ -153,6 +154,7 @@ func TestLoadLibrariesSAM(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) + ctx := &types.Context{} context[constants.CTX_HARDWARE_FOLDERS] = []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"} context[constants.CTX_FQBN] = "arduino:sam:arduino_due_x_dbg" @@ -168,7 +170,7 @@ func TestLoadLibrariesSAM(t *testing.T) { } for _, command := range commands { - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) } @@ -237,6 +239,7 @@ func TestLoadLibrariesAVRNoDuplicateLibrariesFolders(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) + ctx := &types.Context{} context[constants.CTX_HARDWARE_FOLDERS] = []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"} context[constants.CTX_FQBN] = "arduino:avr:leonardo" @@ -252,7 +255,7 @@ func TestLoadLibrariesAVRNoDuplicateLibrariesFolders(t *testing.T) { } for _, command := range commands { - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) } @@ -267,6 +270,7 @@ func TestLoadLibrariesMyAVRPlatform(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) + ctx := &types.Context{} context[constants.CTX_HARDWARE_FOLDERS] = []string{filepath.Join("..", "hardware"), "hardware", "user_hardware", "downloaded_hardware"} context[constants.CTX_FQBN] = "my_avr_platform:avr:custom_yun" @@ -282,7 +286,7 @@ func TestLoadLibrariesMyAVRPlatform(t *testing.T) { } for _, command := range commands { - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) } diff --git a/src/arduino.cc/builder/test/load_previous_build_options_map_test.go b/src/arduino.cc/builder/test/load_previous_build_options_map_test.go index 295e6e3c..bc035872 100644 --- a/src/arduino.cc/builder/test/load_previous_build_options_map_test.go +++ b/src/arduino.cc/builder/test/load_previous_build_options_map_test.go @@ -32,6 +32,7 @@ package test import ( "arduino.cc/builder" "arduino.cc/builder/constants" + "arduino.cc/builder/types" "arduino.cc/builder/utils" "github.com/stretchr/testify/require" "os" @@ -41,6 +42,7 @@ import ( func TestLoadPreviousBuildOptionsMap(t *testing.T) { context := make(map[string]interface{}) + ctx := &types.Context{} buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) @@ -49,7 +51,7 @@ func TestLoadPreviousBuildOptionsMap(t *testing.T) { NoError(t, err) command := builder.LoadPreviousBuildOptionsMap{} - err = command.Run(context) + err = command.Run(context, ctx) NoError(t, err) require.Equal(t, "test", context[constants.CTX_BUILD_OPTIONS_PREVIOUS_JSON]) @@ -57,12 +59,13 @@ func TestLoadPreviousBuildOptionsMap(t *testing.T) { func TestLoadPreviousBuildOptionsMapMissingFile(t *testing.T) { context := make(map[string]interface{}) + ctx := &types.Context{} buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) command := builder.LoadPreviousBuildOptionsMap{} - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) require.False(t, utils.MapHas(context, constants.CTX_BUILD_OPTIONS_PREVIOUS_JSON)) diff --git a/src/arduino.cc/builder/test/load_vid_pid_specific_properties_test.go b/src/arduino.cc/builder/test/load_vid_pid_specific_properties_test.go index f4ef6ff5..24df54f2 100644 --- a/src/arduino.cc/builder/test/load_vid_pid_specific_properties_test.go +++ b/src/arduino.cc/builder/test/load_vid_pid_specific_properties_test.go @@ -44,6 +44,7 @@ func TestLoadVIDPIDSpecificPropertiesWhenNoVIDPIDAreProvided(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) + ctx := &types.Context{} buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) @@ -60,7 +61,7 @@ func TestLoadVIDPIDSpecificPropertiesWhenNoVIDPIDAreProvided(t *testing.T) { } for _, command := range commands { - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) } @@ -75,6 +76,7 @@ func TestLoadVIDPIDSpecificProperties(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) + ctx := &types.Context{} buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) @@ -92,7 +94,7 @@ func TestLoadVIDPIDSpecificProperties(t *testing.T) { } for _, command := range commands { - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) } diff --git a/src/arduino.cc/builder/test/merge_sketch_with_bootloader_test.go b/src/arduino.cc/builder/test/merge_sketch_with_bootloader_test.go index 727ab5c9..992ddb76 100644 --- a/src/arduino.cc/builder/test/merge_sketch_with_bootloader_test.go +++ b/src/arduino.cc/builder/test/merge_sketch_with_bootloader_test.go @@ -47,6 +47,7 @@ func TestMergeSketchWithBootloader(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) + ctx := &types.Context{} buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) @@ -74,7 +75,7 @@ func TestMergeSketchWithBootloader(t *testing.T) { } for _, command := range commands { - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) } @@ -90,6 +91,7 @@ func TestMergeSketchWithBootloaderSketchInBuildPath(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) + ctx := &types.Context{} buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) @@ -117,7 +119,7 @@ func TestMergeSketchWithBootloaderSketchInBuildPath(t *testing.T) { } for _, command := range commands { - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) } @@ -133,6 +135,7 @@ func TestMergeSketchWithBootloaderWhenNoBootloaderAvailable(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) + ctx := &types.Context{} buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) @@ -151,7 +154,7 @@ func TestMergeSketchWithBootloaderWhenNoBootloaderAvailable(t *testing.T) { } for _, command := range commands { - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) } @@ -160,7 +163,7 @@ func TestMergeSketchWithBootloaderWhenNoBootloaderAvailable(t *testing.T) { delete(buildProperties, constants.BUILD_PROPERTIES_BOOTLOADER_FILE) command := &builder.MergeSketchWithBootloader{} - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) _, err = os.Stat(filepath.Join(buildPath, "sketch.ino.with_bootloader.hex")) @@ -172,6 +175,7 @@ func TestMergeSketchWithBootloaderPathIsParameterized(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) + ctx := &types.Context{} buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) @@ -199,7 +203,7 @@ func TestMergeSketchWithBootloaderPathIsParameterized(t *testing.T) { } for _, command := range commands { - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) } diff --git a/src/arduino.cc/builder/test/platform_keys_rewrite_loader_test.go b/src/arduino.cc/builder/test/platform_keys_rewrite_loader_test.go index 694d33af..76be0706 100644 --- a/src/arduino.cc/builder/test/platform_keys_rewrite_loader_test.go +++ b/src/arduino.cc/builder/test/platform_keys_rewrite_loader_test.go @@ -40,6 +40,7 @@ import ( func TestLoadPlatformKeysRewrite(t *testing.T) { context := make(map[string]interface{}) + ctx := &types.Context{} context[constants.CTX_HARDWARE_FOLDERS] = []string{"downloaded_hardware", filepath.Join("..", "hardware"), "hardware"} commands := []types.Command{ @@ -48,7 +49,7 @@ func TestLoadPlatformKeysRewrite(t *testing.T) { } for _, command := range commands { - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) } diff --git a/src/arduino.cc/builder/test/prototypes_adder_test.go b/src/arduino.cc/builder/test/prototypes_adder_test.go index 6976b289..576ac75f 100644 --- a/src/arduino.cc/builder/test/prototypes_adder_test.go +++ b/src/arduino.cc/builder/test/prototypes_adder_test.go @@ -45,6 +45,7 @@ func TestPrototypesAdderBridgeExample(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) + ctx := &types.Context{} buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) @@ -78,7 +79,7 @@ func TestPrototypesAdderBridgeExample(t *testing.T) { } for _, command := range commands { - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) } @@ -90,6 +91,7 @@ func TestPrototypesAdderSketchWithIfDef(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) + ctx := &types.Context{} buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) @@ -119,7 +121,7 @@ func TestPrototypesAdderSketchWithIfDef(t *testing.T) { } for _, command := range commands { - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) } @@ -131,6 +133,7 @@ func TestPrototypesAdderBaladuino(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) + ctx := &types.Context{} buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) @@ -160,7 +163,7 @@ func TestPrototypesAdderBaladuino(t *testing.T) { } for _, command := range commands { - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) } @@ -172,6 +175,7 @@ func TestPrototypesAdderCharWithEscapedDoubleQuote(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) + ctx := &types.Context{} buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) @@ -201,7 +205,7 @@ func TestPrototypesAdderCharWithEscapedDoubleQuote(t *testing.T) { } for _, command := range commands { - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) } @@ -213,6 +217,7 @@ func TestPrototypesAdderIncludeBetweenMultilineComment(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) + ctx := &types.Context{} buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) @@ -242,7 +247,7 @@ func TestPrototypesAdderIncludeBetweenMultilineComment(t *testing.T) { } for _, command := range commands { - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) } @@ -254,6 +259,7 @@ func TestPrototypesAdderLineContinuations(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) + ctx := &types.Context{} buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) @@ -283,7 +289,7 @@ func TestPrototypesAdderLineContinuations(t *testing.T) { } for _, command := range commands { - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) } @@ -295,6 +301,7 @@ func TestPrototypesAdderStringWithComment(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) + ctx := &types.Context{} buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) @@ -324,7 +331,7 @@ func TestPrototypesAdderStringWithComment(t *testing.T) { } for _, command := range commands { - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) } @@ -336,6 +343,7 @@ func TestPrototypesAdderSketchWithStruct(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) + ctx := &types.Context{} buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) @@ -365,7 +373,7 @@ func TestPrototypesAdderSketchWithStruct(t *testing.T) { } for _, command := range commands { - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) } @@ -382,6 +390,7 @@ func TestPrototypesAdderSketchWithConfig(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) + ctx := &types.Context{} buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) @@ -414,7 +423,7 @@ func TestPrototypesAdderSketchWithConfig(t *testing.T) { } for _, command := range commands { - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) } @@ -429,6 +438,7 @@ func TestPrototypesAdderSketchNoFunctionsTwoFiles(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) + ctx := &types.Context{} buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) @@ -461,7 +471,7 @@ func TestPrototypesAdderSketchNoFunctionsTwoFiles(t *testing.T) { } for _, command := range commands { - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) } @@ -473,6 +483,7 @@ func TestPrototypesAdderSketchNoFunctions(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) + ctx := &types.Context{} buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) @@ -505,7 +516,7 @@ func TestPrototypesAdderSketchNoFunctions(t *testing.T) { } for _, command := range commands { - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) } @@ -517,6 +528,7 @@ func TestPrototypesAdderSketchWithDefaultArgs(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) + ctx := &types.Context{} buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) @@ -549,7 +561,7 @@ func TestPrototypesAdderSketchWithDefaultArgs(t *testing.T) { } for _, command := range commands { - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) } @@ -561,6 +573,7 @@ func TestPrototypesAdderSketchWithInlineFunction(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) + ctx := &types.Context{} buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) @@ -593,7 +606,7 @@ func TestPrototypesAdderSketchWithInlineFunction(t *testing.T) { } for _, command := range commands { - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) } @@ -616,6 +629,7 @@ func TestPrototypesAdderSketchWithFunctionSignatureInsideIFDEF(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) + ctx := &types.Context{} buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) @@ -648,7 +662,7 @@ func TestPrototypesAdderSketchWithFunctionSignatureInsideIFDEF(t *testing.T) { } for _, command := range commands { - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) } @@ -660,6 +674,7 @@ func TestPrototypesAdderSketchWithUSBCON(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) + ctx := &types.Context{} buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) @@ -692,7 +707,7 @@ func TestPrototypesAdderSketchWithUSBCON(t *testing.T) { } for _, command := range commands { - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) } @@ -704,6 +719,7 @@ func TestPrototypesAdderSketchWithTypename(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) + ctx := &types.Context{} buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) @@ -735,7 +751,7 @@ func TestPrototypesAdderSketchWithTypename(t *testing.T) { } for _, command := range commands { - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) } @@ -753,6 +769,7 @@ func TestPrototypesAdderSketchWithIfDef2(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) + ctx := &types.Context{} buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) @@ -785,7 +802,7 @@ func TestPrototypesAdderSketchWithIfDef2(t *testing.T) { } for _, command := range commands { - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) } @@ -800,6 +817,7 @@ func TestPrototypesAdderSketchWithIfDef2SAM(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) + ctx := &types.Context{} buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) @@ -832,7 +850,7 @@ func TestPrototypesAdderSketchWithIfDef2SAM(t *testing.T) { } for _, command := range commands { - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) } @@ -847,6 +865,7 @@ func TestPrototypesAdderSketchWithConst(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) + ctx := &types.Context{} buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) @@ -879,7 +898,7 @@ func TestPrototypesAdderSketchWithConst(t *testing.T) { } for _, command := range commands { - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) } @@ -891,6 +910,7 @@ func TestPrototypesAdderSketchWithDosEol(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) + ctx := &types.Context{} buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) @@ -922,7 +942,7 @@ func TestPrototypesAdderSketchWithDosEol(t *testing.T) { } for _, command := range commands { - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) } // only requires no error as result diff --git a/src/arduino.cc/builder/test/read_file_and_store_in_context_test.go b/src/arduino.cc/builder/test/read_file_and_store_in_context_test.go index 2734725a..bc949780 100644 --- a/src/arduino.cc/builder/test/read_file_and_store_in_context_test.go +++ b/src/arduino.cc/builder/test/read_file_and_store_in_context_test.go @@ -32,6 +32,7 @@ package test import ( "arduino.cc/builder" "arduino.cc/builder/constants" + "arduino.cc/builder/types" "arduino.cc/builder/utils" "github.com/stretchr/testify/require" "io/ioutil" @@ -47,10 +48,11 @@ func TestReadFileAndStoreInContext(t *testing.T) { utils.WriteFile(file.Name(), "test test\nciao") context := make(map[string]interface{}) + ctx := &types.Context{} context[constants.CTX_FILE_PATH_TO_READ] = file.Name() command := &builder.ReadFileAndStoreInContext{TargetField: constants.CTX_GCC_MINUS_E_SOURCE} - err = command.Run(context) + err = command.Run(context, ctx) NoError(t, err) require.Equal(t, "test test\nciao", context[constants.CTX_GCC_MINUS_E_SOURCE].(string)) diff --git a/src/arduino.cc/builder/test/recipe_runner_test.go b/src/arduino.cc/builder/test/recipe_runner_test.go index d4d51f64..052dafff 100644 --- a/src/arduino.cc/builder/test/recipe_runner_test.go +++ b/src/arduino.cc/builder/test/recipe_runner_test.go @@ -44,6 +44,7 @@ import ( // So this test is pretty useless func TestRecipeRunner(t *testing.T) { context := make(map[string]interface{}) + ctx := &types.Context{} buildProperties := make(props.PropertiesMap) context[constants.CTX_BUILD_PROPERTIES] = buildProperties @@ -56,7 +57,7 @@ func TestRecipeRunner(t *testing.T) { } for _, command := range commands { - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) } } diff --git a/src/arduino.cc/builder/test/rewrite_hardware_keys_test.go b/src/arduino.cc/builder/test/rewrite_hardware_keys_test.go index 6ad301fb..40b8f6d3 100644 --- a/src/arduino.cc/builder/test/rewrite_hardware_keys_test.go +++ b/src/arduino.cc/builder/test/rewrite_hardware_keys_test.go @@ -39,6 +39,7 @@ import ( func TestRewriteHardwareKeys(t *testing.T) { context := make(map[string]interface{}) + ctx := &types.Context{} packages := &types.Packages{} packages.Packages = make(map[string]*types.Package) @@ -65,7 +66,7 @@ func TestRewriteHardwareKeys(t *testing.T) { } for _, command := range commands { - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) } @@ -74,6 +75,7 @@ func TestRewriteHardwareKeys(t *testing.T) { func TestRewriteHardwareKeysWithRewritingDisabled(t *testing.T) { context := make(map[string]interface{}) + ctx := &types.Context{} packages := &types.Packages{} packages.Packages = make(map[string]*types.Package) @@ -102,7 +104,7 @@ func TestRewriteHardwareKeysWithRewritingDisabled(t *testing.T) { } for _, command := range commands { - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) } diff --git a/src/arduino.cc/builder/test/setup_build_properties_test.go b/src/arduino.cc/builder/test/setup_build_properties_test.go index b933f8a1..cff97fd5 100644 --- a/src/arduino.cc/builder/test/setup_build_properties_test.go +++ b/src/arduino.cc/builder/test/setup_build_properties_test.go @@ -45,6 +45,7 @@ func TestSetupBuildProperties(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) + ctx := &types.Context{} buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) @@ -66,7 +67,7 @@ func TestSetupBuildProperties(t *testing.T) { } for _, command := range commands { - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) } @@ -107,6 +108,7 @@ func TestSetupBuildPropertiesWithSomeCustomOverrides(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) + ctx := &types.Context{} buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) @@ -130,7 +132,7 @@ func TestSetupBuildPropertiesWithSomeCustomOverrides(t *testing.T) { } for _, command := range commands { - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) } @@ -148,6 +150,7 @@ func TestSetupBuildPropertiesUserHardware(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) + ctx := &types.Context{} buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) @@ -169,7 +172,7 @@ func TestSetupBuildPropertiesUserHardware(t *testing.T) { } for _, command := range commands { - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) } @@ -187,6 +190,7 @@ func TestSetupBuildPropertiesWithMissingPropsFromParentPlatformTxtFiles(t *testi DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) + ctx := &types.Context{} buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) @@ -203,7 +207,7 @@ func TestSetupBuildPropertiesWithMissingPropsFromParentPlatformTxtFiles(t *testi } for _, command := range commands { - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) } diff --git a/src/arduino.cc/builder/test/setup_human_logger_if_missing_test.go b/src/arduino.cc/builder/test/setup_human_logger_if_missing_test.go index 8644a567..c00fdb46 100644 --- a/src/arduino.cc/builder/test/setup_human_logger_if_missing_test.go +++ b/src/arduino.cc/builder/test/setup_human_logger_if_missing_test.go @@ -33,6 +33,7 @@ import ( "arduino.cc/builder" "arduino.cc/builder/constants" "arduino.cc/builder/i18n" + "arduino.cc/builder/types" "github.com/stretchr/testify/require" "reflect" "testing" @@ -40,9 +41,10 @@ import ( func TestSetupHumanLogger(t *testing.T) { context := make(map[string]interface{}) + ctx := &types.Context{} command := &builder.SetupHumanLoggerIfMissing{} - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) logger := context[constants.CTX_LOGGER].(i18n.Logger) diff --git a/src/arduino.cc/builder/test/sketch_loader_test.go b/src/arduino.cc/builder/test/sketch_loader_test.go index 120c68f1..dede18e9 100644 --- a/src/arduino.cc/builder/test/sketch_loader_test.go +++ b/src/arduino.cc/builder/test/sketch_loader_test.go @@ -40,14 +40,15 @@ import ( func TestLoadSketchWithFolder(t *testing.T) { context := make(map[string]interface{}) + ctx := &types.Context{} context[constants.CTX_SKETCH_LOCATION] = "sketch1" loggerCommand := builder.SetupHumanLoggerIfMissing{} - err := loggerCommand.Run(context) + err := loggerCommand.Run(context, ctx) NoError(t, err) loader := builder.SketchLoader{} - err = loader.Run(context) + err = loader.Run(context, ctx) require.Error(t, err) @@ -57,14 +58,15 @@ func TestLoadSketchWithFolder(t *testing.T) { func TestLoadSketchNonExistentPath(t *testing.T) { context := make(map[string]interface{}) + ctx := &types.Context{} context[constants.CTX_SKETCH_LOCATION] = "asdasd78128123981723981273asdasd" loggerCommand := builder.SetupHumanLoggerIfMissing{} - err := loggerCommand.Run(context) + err := loggerCommand.Run(context, ctx) NoError(t, err) loader := builder.SketchLoader{} - err = loader.Run(context) + err = loader.Run(context, ctx) require.Error(t, err) @@ -74,6 +76,7 @@ func TestLoadSketchNonExistentPath(t *testing.T) { func TestLoadSketch(t *testing.T) { context := make(map[string]interface{}) + ctx := &types.Context{} context[constants.CTX_SKETCH_LOCATION] = filepath.Join("sketch1", "sketch.ino") commands := []types.Command{ @@ -82,7 +85,7 @@ func TestLoadSketch(t *testing.T) { } for _, command := range commands { - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) } @@ -103,14 +106,15 @@ func TestLoadSketch(t *testing.T) { func TestFailToLoadSketchFromFolder(t *testing.T) { context := make(map[string]interface{}) + ctx := &types.Context{} context[constants.CTX_SKETCH_LOCATION] = "./sketch1" loggerCommand := builder.SetupHumanLoggerIfMissing{} - err := loggerCommand.Run(context) + err := loggerCommand.Run(context, ctx) NoError(t, err) loader := builder.SketchLoader{} - err = loader.Run(context) + err = loader.Run(context, ctx) require.Error(t, err) sketch := context[constants.CTX_SKETCH] @@ -119,6 +123,7 @@ func TestFailToLoadSketchFromFolder(t *testing.T) { func TestLoadSketchFromFolder(t *testing.T) { context := make(map[string]interface{}) + ctx := &types.Context{} context[constants.CTX_SKETCH_LOCATION] = "sketch_with_subfolders" commands := []types.Command{ @@ -127,7 +132,7 @@ func TestLoadSketchFromFolder(t *testing.T) { } for _, command := range commands { - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) } @@ -145,6 +150,7 @@ func TestLoadSketchFromFolder(t *testing.T) { func TestLoadSketchWithBackup(t *testing.T) { context := make(map[string]interface{}) + ctx := &types.Context{} context[constants.CTX_SKETCH_LOCATION] = filepath.Join("sketch_with_backup_files", "sketch.ino") commands := []types.Command{ @@ -153,7 +159,7 @@ func TestLoadSketchWithBackup(t *testing.T) { } for _, command := range commands { - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) } @@ -168,6 +174,7 @@ func TestLoadSketchWithBackup(t *testing.T) { func TestLoadSketchWithMacOSXGarbage(t *testing.T) { context := make(map[string]interface{}) + ctx := &types.Context{} context[constants.CTX_SKETCH_LOCATION] = filepath.Join("sketch_with_macosx_garbage", "sketch.ino") commands := []types.Command{ @@ -176,7 +183,7 @@ func TestLoadSketchWithMacOSXGarbage(t *testing.T) { } for _, command := range commands { - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) } diff --git a/src/arduino.cc/builder/test/sketch_source_merger_test.go b/src/arduino.cc/builder/test/sketch_source_merger_test.go index c0b50698..91cd3dd9 100644 --- a/src/arduino.cc/builder/test/sketch_source_merger_test.go +++ b/src/arduino.cc/builder/test/sketch_source_merger_test.go @@ -42,6 +42,7 @@ import ( func TestMergeSketch(t *testing.T) { context := make(map[string]interface{}) + ctx := &types.Context{} context[constants.CTX_SKETCH_LOCATION] = filepath.Join("sketch1", "sketch.ino") commands := []types.Command{ @@ -51,7 +52,7 @@ func TestMergeSketch(t *testing.T) { } for _, command := range commands { - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) } diff --git a/src/arduino.cc/builder/test/store_build_options_map_test.go b/src/arduino.cc/builder/test/store_build_options_map_test.go index 110bdd6b..1b492fa9 100644 --- a/src/arduino.cc/builder/test/store_build_options_map_test.go +++ b/src/arduino.cc/builder/test/store_build_options_map_test.go @@ -42,6 +42,7 @@ import ( func TestStoreBuildOptionsMap(t *testing.T) { context := make(map[string]interface{}) + ctx := &types.Context{} buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) @@ -62,7 +63,7 @@ func TestStoreBuildOptionsMap(t *testing.T) { } for _, command := range commands { - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) } diff --git a/src/arduino.cc/builder/test/target_board_resolver_test.go b/src/arduino.cc/builder/test/target_board_resolver_test.go index 19268b26..53fce48a 100644 --- a/src/arduino.cc/builder/test/target_board_resolver_test.go +++ b/src/arduino.cc/builder/test/target_board_resolver_test.go @@ -40,6 +40,7 @@ import ( func TestTargetBoardResolverUno(t *testing.T) { context := make(map[string]interface{}) + ctx := &types.Context{} context[constants.CTX_HARDWARE_FOLDERS] = []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"} context[constants.CTX_FQBN] = "arduino:avr:uno" @@ -50,7 +51,7 @@ func TestTargetBoardResolverUno(t *testing.T) { } for _, command := range commands { - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) } @@ -65,6 +66,7 @@ func TestTargetBoardResolverUno(t *testing.T) { func TestTargetBoardResolverDue(t *testing.T) { context := make(map[string]interface{}) + ctx := &types.Context{} context[constants.CTX_HARDWARE_FOLDERS] = []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"} context[constants.CTX_FQBN] = "arduino:sam:arduino_due_x" @@ -75,7 +77,7 @@ func TestTargetBoardResolverDue(t *testing.T) { } for _, command := range commands { - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) } @@ -90,6 +92,7 @@ func TestTargetBoardResolverDue(t *testing.T) { func TestTargetBoardResolverMega1280(t *testing.T) { context := make(map[string]interface{}) + ctx := &types.Context{} context[constants.CTX_HARDWARE_FOLDERS] = []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"} context[constants.CTX_FQBN] = "arduino:avr:mega:cpu=atmega1280" @@ -100,7 +103,7 @@ func TestTargetBoardResolverMega1280(t *testing.T) { } for _, command := range commands { - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) } @@ -116,6 +119,7 @@ func TestTargetBoardResolverMega1280(t *testing.T) { func TestTargetBoardResolverMega2560(t *testing.T) { context := make(map[string]interface{}) + ctx := &types.Context{} context[constants.CTX_HARDWARE_FOLDERS] = []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"} context[constants.CTX_FQBN] = "arduino:avr:mega:cpu=atmega2560" @@ -126,7 +130,7 @@ func TestTargetBoardResolverMega2560(t *testing.T) { } for _, command := range commands { - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) } @@ -142,6 +146,7 @@ func TestTargetBoardResolverMega2560(t *testing.T) { func TestTargetBoardResolverCustomYun(t *testing.T) { context := make(map[string]interface{}) + ctx := &types.Context{} context[constants.CTX_HARDWARE_FOLDERS] = []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware", "user_hardware"} context[constants.CTX_FQBN] = "my_avr_platform:avr:custom_yun" @@ -152,7 +157,7 @@ func TestTargetBoardResolverCustomYun(t *testing.T) { } for _, command := range commands { - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) } @@ -168,6 +173,7 @@ func TestTargetBoardResolverCustomYun(t *testing.T) { func TestTargetBoardResolverCustomCore(t *testing.T) { context := make(map[string]interface{}) + ctx := &types.Context{} context[constants.CTX_HARDWARE_FOLDERS] = []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware", "user_hardware"} context[constants.CTX_FQBN] = "watterott:avr:attiny841:core=spencekonde,info=info" @@ -178,7 +184,7 @@ func TestTargetBoardResolverCustomCore(t *testing.T) { } for _, command := range commands { - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) } diff --git a/src/arduino.cc/builder/test/tools_loader_test.go b/src/arduino.cc/builder/test/tools_loader_test.go index 07965598..cf268b64 100644 --- a/src/arduino.cc/builder/test/tools_loader_test.go +++ b/src/arduino.cc/builder/test/tools_loader_test.go @@ -57,10 +57,11 @@ func TestLoadTools(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) + ctx := &types.Context{} context[constants.CTX_TOOLS_FOLDERS] = []string{"downloaded_tools", "tools_builtin"} loader := builder.ToolsLoader{} - err := loader.Run(context) + err := loader.Run(context, ctx) NoError(t, err) tools := context[constants.CTX_TOOLS].([]*types.Tool) @@ -94,10 +95,11 @@ func TestLoadToolsWithBoardManagerFolderStructure(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) + ctx := &types.Context{} context[constants.CTX_TOOLS_FOLDERS] = []string{"downloaded_board_manager_stuff"} loader := builder.ToolsLoader{} - err := loader.Run(context) + err := loader.Run(context, ctx) NoError(t, err) tools := context[constants.CTX_TOOLS].([]*types.Tool) @@ -119,10 +121,11 @@ func TestLoadLotsOfTools(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) + ctx := &types.Context{} context[constants.CTX_TOOLS_FOLDERS] = []string{"downloaded_tools", "tools_builtin", "downloaded_board_manager_stuff"} loader := builder.ToolsLoader{} - err := loader.Run(context) + err := loader.Run(context, ctx) NoError(t, err) tools := context[constants.CTX_TOOLS].([]*types.Tool) diff --git a/src/arduino.cc/builder/test/try_build_of_problematic_sketch_test.go b/src/arduino.cc/builder/test/try_build_of_problematic_sketch_test.go index 37bfb131..0786f035 100644 --- a/src/arduino.cc/builder/test/try_build_of_problematic_sketch_test.go +++ b/src/arduino.cc/builder/test/try_build_of_problematic_sketch_test.go @@ -33,6 +33,7 @@ package test import ( "arduino.cc/builder" "arduino.cc/builder/constants" + "arduino.cc/builder/types" "os" "path/filepath" "testing" @@ -117,9 +118,9 @@ func TestTryBuild019(t *testing.T) { } func TestTryBuild020(t *testing.T) { - context := makeDefaultContext(t) + context, ctx := makeDefaultContext(t) context[constants.CTX_OTHER_LIBRARIES_FOLDERS] = []string{"dependent_libraries", "libraries"} - tryPreprocessWithContext(t, context, "sketch_with_dependend_libraries", "sketch.ino") + tryPreprocessWithContext(t, context, ctx, "sketch_with_dependend_libraries", "sketch.ino") } func TestTryBuild021(t *testing.T) { @@ -127,9 +128,9 @@ func TestTryBuild021(t *testing.T) { } func TestTryBuild022(t *testing.T) { - context := makeDefaultContext(t) + context, ctx := makeDefaultContext(t) context[constants.CTX_FQBN] = "arduino:samd:arduino_zero_native" - tryBuildWithContext(t, context, "sketch_usbhost", "sketch_usbhost.ino") + tryBuildWithContext(t, context, ctx, "sketch_usbhost", "sketch_usbhost.ino") } func TestTryBuild023(t *testing.T) { @@ -186,9 +187,9 @@ func TestTryBuild035(t *testing.T) { } func TestTryBuild036(t *testing.T) { - context := makeDefaultContext(t) + context, ctx := makeDefaultContext(t) context[constants.CTX_FQBN] = "arduino:samd:arduino_zero_native" - tryBuildWithContext(t, context, "sketch11", "sketch_fastleds.ino") + tryBuildWithContext(t, context, ctx, "sketch11", "sketch_fastleds.ino") } func TestTryBuild037(t *testing.T) { @@ -199,10 +200,11 @@ func TestTryBuild038(t *testing.T) { tryBuild(t, "sketch_with_multiline_prototypes", "sketch_with_multiline_prototypes.ino") } -func makeDefaultContext(t *testing.T) map[string]interface{} { +func makeDefaultContext(t *testing.T) (map[string]interface{}, *types.Context) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) + ctx := &types.Context{} buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) @@ -215,31 +217,31 @@ func makeDefaultContext(t *testing.T) map[string]interface{} { context[constants.CTX_VERBOSE] = true context[constants.CTX_DEBUG_PREPROCESSOR] = true - return context + return context, ctx } func tryBuild(t *testing.T, sketchPath ...string) { - context := makeDefaultContext(t) - tryBuildWithContext(t, context, sketchPath...) + context, ctx := makeDefaultContext(t) + tryBuildWithContext(t, context, ctx, sketchPath...) } -func tryBuildWithContext(t *testing.T, context map[string]interface{}, sketchPath ...string) { +func tryBuildWithContext(t *testing.T, context map[string]interface{}, ctx *types.Context, sketchPath ...string) { sketchLocation := filepath.Join(sketchPath...) context[constants.CTX_SKETCH_LOCATION] = sketchLocation - err := builder.RunBuilder(context) + err := builder.RunBuilder(context, ctx) NoError(t, err, "Build error for "+sketchLocation) } func tryPreprocess(t *testing.T, sketchPath ...string) { - context := makeDefaultContext(t) - tryPreprocessWithContext(t, context, sketchPath...) + context, ctx := makeDefaultContext(t) + tryPreprocessWithContext(t, context, ctx, sketchPath...) } -func tryPreprocessWithContext(t *testing.T, context map[string]interface{}, sketchPath ...string) { +func tryPreprocessWithContext(t *testing.T, context map[string]interface{}, ctx *types.Context, sketchPath ...string) { sketchLocation := filepath.Join(sketchPath...) context[constants.CTX_SKETCH_LOCATION] = sketchLocation - err := builder.RunPreprocess(context) + err := builder.RunPreprocess(context, ctx) NoError(t, err, "Build error for "+sketchLocation) } diff --git a/src/arduino.cc/builder/test/unused_compiled_libraries_remover_test.go b/src/arduino.cc/builder/test/unused_compiled_libraries_remover_test.go index d82af8c0..78fd8f66 100644 --- a/src/arduino.cc/builder/test/unused_compiled_libraries_remover_test.go +++ b/src/arduino.cc/builder/test/unused_compiled_libraries_remover_test.go @@ -50,11 +50,12 @@ func TestUnusedCompiledLibrariesRemover(t *testing.T) { NoError(t, ioutil.WriteFile(filepath.Join(temp, "dummy_file"), []byte{}, os.FileMode(0644))) context := make(map[string]interface{}) + ctx := &types.Context{} context[constants.CTX_LIBRARIES_BUILD_PATH] = temp context[constants.CTX_IMPORTED_LIBRARIES] = []*types.Library{&types.Library{Name: "Bridge"}} cmd := builder.UnusedCompiledLibrariesRemover{} - err = cmd.Run(context) + err = cmd.Run(context, ctx) NoError(t, err) _, err = os.Stat(filepath.Join(temp, "SPI")) @@ -68,11 +69,12 @@ func TestUnusedCompiledLibrariesRemover(t *testing.T) { func TestUnusedCompiledLibrariesRemoverLibDoesNotExist(t *testing.T) { context := make(map[string]interface{}) + ctx := &types.Context{} context[constants.CTX_LIBRARIES_BUILD_PATH] = filepath.Join(os.TempDir(), "test") context[constants.CTX_IMPORTED_LIBRARIES] = []*types.Library{&types.Library{Name: "Bridge"}} cmd := builder.UnusedCompiledLibrariesRemover{} - err := cmd.Run(context) + err := cmd.Run(context, ctx) NoError(t, err) } @@ -86,11 +88,12 @@ func TestUnusedCompiledLibrariesRemoverNoUsedLibraries(t *testing.T) { NoError(t, ioutil.WriteFile(filepath.Join(temp, "dummy_file"), []byte{}, os.FileMode(0644))) context := make(map[string]interface{}) + ctx := &types.Context{} context[constants.CTX_LIBRARIES_BUILD_PATH] = temp context[constants.CTX_IMPORTED_LIBRARIES] = []*types.Library{} cmd := builder.UnusedCompiledLibrariesRemover{} - err = cmd.Run(context) + err = cmd.Run(context, ctx) NoError(t, err) _, err = os.Stat(filepath.Join(temp, "SPI")) diff --git a/src/arduino.cc/builder/test/wipeout_build_path_if_build_options_changed_test.go b/src/arduino.cc/builder/test/wipeout_build_path_if_build_options_changed_test.go index d72b05b2..ed2c22cb 100644 --- a/src/arduino.cc/builder/test/wipeout_build_path_if_build_options_changed_test.go +++ b/src/arduino.cc/builder/test/wipeout_build_path_if_build_options_changed_test.go @@ -43,6 +43,7 @@ import ( func TestWipeoutBuildPathIfBuildOptionsChanged(t *testing.T) { context := make(map[string]interface{}) + ctx := &types.Context{} buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) @@ -58,7 +59,7 @@ func TestWipeoutBuildPathIfBuildOptionsChanged(t *testing.T) { } for _, command := range commands { - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) } @@ -75,6 +76,7 @@ func TestWipeoutBuildPathIfBuildOptionsChanged(t *testing.T) { func TestWipeoutBuildPathIfBuildOptionsChangedNoPreviousBuildOptions(t *testing.T) { context := make(map[string]interface{}) + ctx := &types.Context{} buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) @@ -89,7 +91,7 @@ func TestWipeoutBuildPathIfBuildOptionsChangedNoPreviousBuildOptions(t *testing. } for _, command := range commands { - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) } @@ -106,6 +108,7 @@ func TestWipeoutBuildPathIfBuildOptionsChangedNoPreviousBuildOptions(t *testing. func TestWipeoutBuildPathIfBuildOptionsChangedBuildOptionsMatch(t *testing.T) { context := make(map[string]interface{}) + ctx := &types.Context{} buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) @@ -121,7 +124,7 @@ func TestWipeoutBuildPathIfBuildOptionsChangedBuildOptionsMatch(t *testing.T) { } for _, command := range commands { - err := command.Run(context) + err := command.Run(context, ctx) NoError(t, err) } diff --git a/src/arduino.cc/builder/tools_loader.go b/src/arduino.cc/builder/tools_loader.go index 9da9e727..999b7e07 100644 --- a/src/arduino.cc/builder/tools_loader.go +++ b/src/arduino.cc/builder/tools_loader.go @@ -41,7 +41,7 @@ import ( type ToolsLoader struct{} -func (s *ToolsLoader) Run(context map[string]interface{}) error { +func (s *ToolsLoader) Run(context map[string]interface{}, ctx *types.Context) error { folders := context[constants.CTX_TOOLS_FOLDERS].([]string) tools := []*types.Tool{} diff --git a/src/arduino.cc/builder/types/context.go b/src/arduino.cc/builder/types/context.go new file mode 100644 index 00000000..afe2453e --- /dev/null +++ b/src/arduino.cc/builder/types/context.go @@ -0,0 +1,10 @@ +package types + +// Context structure +type Context struct { + + // For now it is used in conjunction with the old map[string]string, but + // it will be slowly populated with all the fields currently used in the + // map in the next commits. + // When the migration will be completed the old map will be removed. +} diff --git a/src/arduino.cc/builder/types/types.go b/src/arduino.cc/builder/types/types.go index 2eebaf8e..f882cdd7 100644 --- a/src/arduino.cc/builder/types/types.go +++ b/src/arduino.cc/builder/types/types.go @@ -151,10 +151,6 @@ type KeyValuePair struct { Value string } -type Command interface { - Run(context map[string]interface{}) error -} - type Prototype struct { FunctionName string File string @@ -205,3 +201,7 @@ func LibraryToSourceFolder(library *Library) []SourceFolder { } return sourceFolders } + +type Command interface { + Run(context map[string]interface{}, ctx *Context) error +} diff --git a/src/arduino.cc/builder/unused_compiled_libraries_remover.go b/src/arduino.cc/builder/unused_compiled_libraries_remover.go index cd743b04..1bdb984f 100644 --- a/src/arduino.cc/builder/unused_compiled_libraries_remover.go +++ b/src/arduino.cc/builder/unused_compiled_libraries_remover.go @@ -40,7 +40,7 @@ import ( type UnusedCompiledLibrariesRemover struct{} -func (s *UnusedCompiledLibrariesRemover) Run(context map[string]interface{}) error { +func (s *UnusedCompiledLibrariesRemover) Run(context map[string]interface{}, ctx *types.Context) error { librariesBuildPath := context[constants.CTX_LIBRARIES_BUILD_PATH].(string) libraries := context[constants.CTX_IMPORTED_LIBRARIES].([]*types.Library) diff --git a/src/arduino.cc/builder/warn_about_arch_incompatible_libraries.go b/src/arduino.cc/builder/warn_about_arch_incompatible_libraries.go index 8ca59447..d6bf457e 100644 --- a/src/arduino.cc/builder/warn_about_arch_incompatible_libraries.go +++ b/src/arduino.cc/builder/warn_about_arch_incompatible_libraries.go @@ -41,7 +41,7 @@ import ( type WarnAboutArchIncompatibleLibraries struct{} -func (s *WarnAboutArchIncompatibleLibraries) Run(context map[string]interface{}) error { +func (s *WarnAboutArchIncompatibleLibraries) Run(context map[string]interface{}, ctx *types.Context) error { if utils.DebugLevel(context) <= 0 { return nil } diff --git a/src/arduino.cc/builder/warn_about_platform_rewrites.go b/src/arduino.cc/builder/warn_about_platform_rewrites.go index a6be00ab..cea8f49a 100644 --- a/src/arduino.cc/builder/warn_about_platform_rewrites.go +++ b/src/arduino.cc/builder/warn_about_platform_rewrites.go @@ -39,7 +39,7 @@ import ( type WarnAboutPlatformRewrites struct{} -func (s *WarnAboutPlatformRewrites) Run(context map[string]interface{}) error { +func (s *WarnAboutPlatformRewrites) Run(context map[string]interface{}, ctx *types.Context) error { warn := utils.DebugLevel(context) > 0 if !warn { return nil diff --git a/src/arduino.cc/builder/wipeout_build_path_if_build_options_changed.go b/src/arduino.cc/builder/wipeout_build_path_if_build_options_changed.go index a974164e..56fb44d9 100644 --- a/src/arduino.cc/builder/wipeout_build_path_if_build_options_changed.go +++ b/src/arduino.cc/builder/wipeout_build_path_if_build_options_changed.go @@ -33,6 +33,7 @@ import ( "arduino.cc/builder/constants" "arduino.cc/builder/gohasissues" "arduino.cc/builder/i18n" + "arduino.cc/builder/types" "arduino.cc/builder/utils" "os" "path/filepath" @@ -41,7 +42,7 @@ import ( type WipeoutBuildPathIfBuildOptionsChanged struct{} -func (s *WipeoutBuildPathIfBuildOptionsChanged) Run(context map[string]interface{}) error { +func (s *WipeoutBuildPathIfBuildOptionsChanged) Run(context map[string]interface{}, ctx *types.Context) error { if !utils.MapHas(context, constants.CTX_BUILD_OPTIONS_PREVIOUS_JSON) { return nil } From 691b76d228f4ed7bbc666cb2202c62c60d02ca16 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Fri, 1 Apr 2016 15:30:12 +0200 Subject: [PATCH 02/25] Migrated all buildProperties into types.Context Still missing the refactoring of main.go that will be done in one of the next commits Signed-off-by: Cristian Maglie --- src/arduino.cc/builder/constants/constants.go | 10 +- .../builder/create_build_options_map.go | 33 +- .../fail_if_buildpath_equals_sketchpath.go | 4 +- .../builder/generate_buildpath_if_missing.go | 3 +- src/arduino.cc/builder/hardware_loader.go | 2 +- src/arduino.cc/builder/libraries_loader.go | 15 +- .../builder/platform_keys_rewrite_loader.go | 2 +- .../builder/set_custom_build_properties.go | 6 +- .../builder/setup_build_properties.go | 8 +- src/arduino.cc/builder/sketch_loader.go | 9 +- .../builder/target_board_resolver.go | 2 +- ...dd_build_board_property_if_missing_test.go | 14 +- .../additional_sketch_files_copier_test.go | 16 +- src/arduino.cc/builder/test/builder_test.go | 195 ++++----- .../builder/test/coan_runner_test.go | 13 +- .../test/create_build_options_map_test.go | 36 +- .../builder/test/ctags_runner_test.go | 100 +++-- ...ail_if_buildpath_equals_sketchpath_test.go | 10 +- .../generate_buildpath_if_missing_test.go | 17 +- .../builder/test/hardware_loader_test.go | 21 +- .../test/includes_finder_with_gcc_test.go | 79 ++-- .../test/includes_finder_with_regexp_test.go | 13 +- .../test/includes_to_include_folders_test.go | 117 ++--- .../builder/test/libraries_loader_test.go | 56 +-- .../load_vid_pid_specific_properties_test.go | 27 +- .../test/merge_sketch_with_bootloader_test.go | 72 ++-- .../test/platform_keys_rewrite_loader_test.go | 5 +- .../builder/test/prototypes_adder_test.go | 406 +++++++++--------- .../test/setup_build_properties_test.go | 63 +-- .../builder/test/sketch_loader_test.go | 35 +- .../builder/test/sketch_source_merger_test.go | 5 +- .../test/store_build_options_map_test.go | 19 +- .../test/target_board_resolver_test.go | 42 +- .../builder/test/tools_loader_test.go | 15 +- .../try_build_of_problematic_sketch_test.go | 25 +- src/arduino.cc/builder/tools_loader.go | 2 +- src/arduino.cc/builder/types/context.go | 39 ++ ...out_build_path_if_build_options_changed.go | 2 +- 38 files changed, 806 insertions(+), 732 deletions(-) diff --git a/src/arduino.cc/builder/constants/constants.go b/src/arduino.cc/builder/constants/constants.go index 078ac08d..d10f09f7 100644 --- a/src/arduino.cc/builder/constants/constants.go +++ b/src/arduino.cc/builder/constants/constants.go @@ -66,6 +66,7 @@ const BUILD_PROPERTIES_RUNTIME_OS = "runtime.os" const BUILD_PROPERTIES_RUNTIME_PLATFORM_PATH = "runtime.platform.path" const BUILD_PROPERTIES_RUNTIME_TOOLS_PREFIX = "runtime.tools." const BUILD_PROPERTIES_RUNTIME_TOOLS_SUFFIX = ".path" +const BUILD_PROPERTIES_RUNTIME_IDE_VERSION = "runtime.ide.version" const BUILD_PROPERTIES_SOFTWARE = "software" const BUILD_PROPERTIES_SOURCE_FILE = "source_file" const BUILD_PROPERTIES_SOURCE_PATH = "build.source.path" @@ -81,8 +82,6 @@ const CTX_BUILD_OPTIONS_JSON = "buildOptionsJson" const CTX_BUILD_OPTIONS_PREVIOUS_JSON = "buildOptionsPreviousJson" const CTX_BUILD_PATH = "buildPath" const CTX_BUILD_PROPERTIES = "buildProperties" -const CTX_BUILD_PROPERTIES_RUNTIME_IDE_VERSION = "runtime.ide.version" -const CTX_BUILT_IN_LIBRARIES_FOLDERS = "builtInLibrariesFolders" const CTX_COLLECTED_CTAGS = "collectedCTags" const CTX_COLLECTED_SOURCE_FILES_QUEUE = "collectedSourceFilesQueue" const CTX_CORE_BUILD_PATH = "coreBuildPath" @@ -90,15 +89,12 @@ const CTX_CTAGS_OF_PREPROC_SOURCE = "ctagsOfPreprocSource" const CTX_CTAGS_OF_SOURCE = "ctagsOfSource" const CTX_CTAGS_OUTPUT = "ctagsOutput" const CTX_CTAGS_TEMP_FILE_PATH = "ctagsTempFilePath" -const CTX_CUSTOM_BUILD_PROPERTIES = "customBuildProperties" const CTX_DEBUG_LEVEL = "debugLevel" const CTX_DEBUG_PREPROCESSOR = "debugPreprocessor" const CTX_FILE_PATH_TO_READ = "filePathToRead" const CTX_FOLDERS_WITH_SOURCES_QUEUE = "foldersWithSourcesQueue" -const CTX_FQBN = "fqbn" const CTX_GCC_MINUS_E_SOURCE = "gccMinusESource" const CTX_GCC_MINUS_M_OUTPUT = "gccMinusMOutput" -const CTX_HARDWARE_FOLDERS = "hardwareFolders" const CTX_HARDWARE = "hardware" const CTX_HARDWARE_REWRITE_RESULTS = "hardwareRewriteResults" const CTX_HEADER_TO_LIBRARIES = "headerToLibraries" @@ -108,7 +104,6 @@ const CTX_INCLUDE_SECTION = "includeSection" const CTX_INCLUDES = "includes" const CTX_INCLUDES_JUST_FOUND = "includesJustFound" const CTX_LIBRARIES_BUILD_PATH = "librariesBuildPath" -const CTX_LIBRARIES_FOLDERS = "librariesFolders" const CTX_LIBRARIES = "libraries" const CTX_LIBRARY_RESOLUTION_RESULTS = "libraryResolutionResults" const CTX_LINE_OFFSET = "lineOffset" @@ -117,19 +112,16 @@ const CTX_LOGGER = "logger" const CTX_OBJECT_FILES_CORE = "objectFilesCore" const CTX_OBJECT_FILES_LIBRARIES = "objectFilesLibraries" const CTX_OBJECT_FILES_SKETCH = "objectFilesSketch" -const CTX_OTHER_LIBRARIES_FOLDERS = "otherLibrariesFolders" const CTX_PLATFORM_KEYS_REWRITE = "platformKeysRewrite" const CTX_PREPROC_PATH = "preprocPath" const CTX_PROTOTYPE_SECTION = "prototypeSection" const CTX_PROTOTYPES = "prototypes" const CTX_SKETCH_BUILD_PATH = "sketchBuildPath" -const CTX_SKETCH_LOCATION = "sketchLocation" const CTX_SKETCH = "sketch" const CTX_SOURCE = "source" const CTX_TARGET_BOARD = "targetBoard" const CTX_TARGET_PACKAGE = "targetPackage" const CTX_TARGET_PLATFORM = "targetPlatform" -const CTX_TOOLS_FOLDERS = "toolsFolders" const CTX_TOOLS = "tools" const CTX_VERBOSE = "verbose" const CTX_VIDPID = "VIDPID" diff --git a/src/arduino.cc/builder/create_build_options_map.go b/src/arduino.cc/builder/create_build_options_map.go index e9634157..965ca3a3 100644 --- a/src/arduino.cc/builder/create_build_options_map.go +++ b/src/arduino.cc/builder/create_build_options_map.go @@ -34,43 +34,12 @@ import ( "arduino.cc/builder/types" "arduino.cc/builder/utils" "encoding/json" - "reflect" - "strings" ) type CreateBuildOptionsMap struct{} func (s *CreateBuildOptionsMap) Run(context map[string]interface{}, ctx *types.Context) error { - buildOptions := make(map[string]string) - - buildOptionsMapKeys := []string{ - constants.CTX_HARDWARE_FOLDERS, - constants.CTX_TOOLS_FOLDERS, - constants.CTX_BUILT_IN_LIBRARIES_FOLDERS, - constants.CTX_OTHER_LIBRARIES_FOLDERS, - constants.CTX_FQBN, - constants.CTX_SKETCH_LOCATION, - constants.CTX_BUILD_PROPERTIES_RUNTIME_IDE_VERSION, - constants.CTX_CUSTOM_BUILD_PROPERTIES, - } - - for _, key := range buildOptionsMapKeys { - if utils.MapHas(context, key) { - originalValue := context[key] - value := constants.EMPTY_STRING - kindOfValue := reflect.TypeOf(originalValue).Kind() - if kindOfValue == reflect.Slice { - value = strings.Join(originalValue.([]string), ",") - } else if kindOfValue == reflect.String { - value = originalValue.(string) - } else { - return utils.Errorf(context, constants.MSG_UNHANDLED_TYPE_IN_CONTEXT, kindOfValue.String(), key) - } - - buildOptions[key] = value - } - } - + buildOptions := ctx.ExtractBuildOptions() context[constants.CTX_BUILD_OPTIONS] = buildOptions bytes, err := json.MarshalIndent(buildOptions, "", " ") diff --git a/src/arduino.cc/builder/fail_if_buildpath_equals_sketchpath.go b/src/arduino.cc/builder/fail_if_buildpath_equals_sketchpath.go index 42be68f0..fdf75844 100644 --- a/src/arduino.cc/builder/fail_if_buildpath_equals_sketchpath.go +++ b/src/arduino.cc/builder/fail_if_buildpath_equals_sketchpath.go @@ -39,7 +39,7 @@ import ( type FailIfBuildPathEqualsSketchPath struct{} func (s *FailIfBuildPathEqualsSketchPath) Run(context map[string]interface{}, ctx *types.Context) error { - if !utils.MapHas(context, constants.CTX_BUILD_PATH) || !utils.MapHas(context, constants.CTX_SKETCH_LOCATION) { + if !utils.MapHas(context, constants.CTX_BUILD_PATH) || ctx.SketchLocation == "" { return nil } @@ -48,7 +48,7 @@ func (s *FailIfBuildPathEqualsSketchPath) Run(context map[string]interface{}, ct return utils.WrapError(err) } - sketchPath, err := filepath.Abs(context[constants.CTX_SKETCH_LOCATION].(string)) + sketchPath, err := filepath.Abs(ctx.SketchLocation) if err != nil { return utils.WrapError(err) } diff --git a/src/arduino.cc/builder/generate_buildpath_if_missing.go b/src/arduino.cc/builder/generate_buildpath_if_missing.go index 44904ca7..fea4e076 100644 --- a/src/arduino.cc/builder/generate_buildpath_if_missing.go +++ b/src/arduino.cc/builder/generate_buildpath_if_missing.go @@ -46,8 +46,7 @@ func (s *GenerateBuildPathIfMissing) Run(context map[string]interface{}, ctx *ty return nil } - sketchLocation := context[constants.CTX_SKETCH_LOCATION].(string) - md5sum := utils.MD5Sum([]byte(sketchLocation)) + md5sum := utils.MD5Sum([]byte(ctx.SketchLocation)) buildPath := filepath.Join(os.TempDir(), "arduino-sketch-"+strings.ToUpper(md5sum)) _, err := os.Stat(buildPath) diff --git a/src/arduino.cc/builder/hardware_loader.go b/src/arduino.cc/builder/hardware_loader.go index f99caaf3..d49ca400 100644 --- a/src/arduino.cc/builder/hardware_loader.go +++ b/src/arduino.cc/builder/hardware_loader.go @@ -48,7 +48,7 @@ func (s *HardwareLoader) Run(context map[string]interface{}, ctx *types.Context) packages.Packages = make(map[string]*types.Package) packages.Properties = make(map[string]string) - folders := context[constants.CTX_HARDWARE_FOLDERS].([]string) + folders := ctx.HardwareFolders folders, err := utils.AbsolutizePaths(folders) if err != nil { return utils.WrapError(err) diff --git a/src/arduino.cc/builder/libraries_loader.go b/src/arduino.cc/builder/libraries_loader.go index 07850f6e..37fe7699 100644 --- a/src/arduino.cc/builder/libraries_loader.go +++ b/src/arduino.cc/builder/libraries_loader.go @@ -43,16 +43,12 @@ import ( type LibrariesLoader struct{} func (s *LibrariesLoader) Run(context map[string]interface{}, ctx *types.Context) error { - sortedLibrariesFolders := []string{} - - builtInLibrariesFolders := []string{} - if utils.MapHas(context, constants.CTX_BUILT_IN_LIBRARIES_FOLDERS) { - builtInLibrariesFolders = context[constants.CTX_BUILT_IN_LIBRARIES_FOLDERS].([]string) - } + builtInLibrariesFolders := ctx.BuiltInLibrariesFolders builtInLibrariesFolders, err := utils.AbsolutizePaths(builtInLibrariesFolders) if err != nil { return utils.WrapError(err) } + sortedLibrariesFolders := []string{} sortedLibrariesFolders = utils.AppendIfNotPresent(sortedLibrariesFolders, builtInLibrariesFolders...) platform := context[constants.CTX_TARGET_PLATFORM].(*types.Platform) @@ -66,17 +62,14 @@ func (s *LibrariesLoader) Run(context map[string]interface{}, ctx *types.Context sortedLibrariesFolders = appendPathToLibrariesFolders(sortedLibrariesFolders, filepath.Join(platform.Folder, constants.FOLDER_LIBRARIES)) - librariesFolders := []string{} - if utils.MapHas(context, constants.CTX_OTHER_LIBRARIES_FOLDERS) { - librariesFolders = context[constants.CTX_OTHER_LIBRARIES_FOLDERS].([]string) - } + librariesFolders := ctx.OtherLibrariesFolders librariesFolders, err = utils.AbsolutizePaths(librariesFolders) if err != nil { return utils.WrapError(err) } sortedLibrariesFolders = utils.AppendIfNotPresent(sortedLibrariesFolders, librariesFolders...) - context[constants.CTX_LIBRARIES_FOLDERS] = sortedLibrariesFolders + ctx.LibrariesFolders = sortedLibrariesFolders var libraries []*types.Library for _, libraryFolder := range sortedLibrariesFolders { diff --git a/src/arduino.cc/builder/platform_keys_rewrite_loader.go b/src/arduino.cc/builder/platform_keys_rewrite_loader.go index d375ec22..8b597b2c 100644 --- a/src/arduino.cc/builder/platform_keys_rewrite_loader.go +++ b/src/arduino.cc/builder/platform_keys_rewrite_loader.go @@ -46,7 +46,7 @@ type PlatformKeysRewriteLoader struct{} func (s *PlatformKeysRewriteLoader) Run(context map[string]interface{}, ctx *types.Context) error { logger := context[constants.CTX_LOGGER].(i18n.Logger) - folders := context[constants.CTX_HARDWARE_FOLDERS].([]string) + folders := ctx.HardwareFolders platformKeysRewriteTxtPath, err := findPlatformKeysRewriteTxt(folders) if err != nil { diff --git a/src/arduino.cc/builder/set_custom_build_properties.go b/src/arduino.cc/builder/set_custom_build_properties.go index 29b390c4..ea6b6cc0 100644 --- a/src/arduino.cc/builder/set_custom_build_properties.go +++ b/src/arduino.cc/builder/set_custom_build_properties.go @@ -40,13 +40,9 @@ import ( type SetCustomBuildProperties struct{} func (s *SetCustomBuildProperties) Run(context map[string]interface{}, ctx *types.Context) error { - if !utils.MapHas(context, constants.CTX_CUSTOM_BUILD_PROPERTIES) { - return nil - } - logger := context[constants.CTX_LOGGER].(i18n.Logger) buildProperties := context[constants.CTX_BUILD_PROPERTIES].(props.PropertiesMap) - customBuildProperties, err := props.LoadFromSlice(context[constants.CTX_CUSTOM_BUILD_PROPERTIES].([]string), logger) + customBuildProperties, err := props.LoadFromSlice(ctx.CustomBuildProperties, logger) if err != nil { return utils.WrapError(err) } diff --git a/src/arduino.cc/builder/setup_build_properties.go b/src/arduino.cc/builder/setup_build_properties.go index 0cdc6425..035e1ac2 100644 --- a/src/arduino.cc/builder/setup_build_properties.go +++ b/src/arduino.cc/builder/setup_build_properties.go @@ -67,8 +67,8 @@ func (s *SetupBuildProperties) Run(context map[string]interface{}, ctx *types.Co buildProperties[constants.BUILD_PROPERTIES_BUILD_SYSTEM_PATH] = filepath.Join(actualPlatform.Folder, constants.FOLDER_SYSTEM) buildProperties[constants.BUILD_PROPERTIES_RUNTIME_PLATFORM_PATH] = targetPlatform.Folder buildProperties[constants.BUILD_PROPERTIES_RUNTIME_HARDWARE_PATH] = filepath.Join(targetPlatform.Folder, "..") - buildProperties[constants.CTX_BUILD_PROPERTIES_RUNTIME_IDE_VERSION] = context[constants.CTX_BUILD_PROPERTIES_RUNTIME_IDE_VERSION].(string) - buildProperties[constants.IDE_VERSION] = context[constants.CTX_BUILD_PROPERTIES_RUNTIME_IDE_VERSION].(string) + buildProperties[constants.BUILD_PROPERTIES_RUNTIME_IDE_VERSION] = ctx.ArduinoAPIVersion + buildProperties[constants.IDE_VERSION] = ctx.ArduinoAPIVersion buildProperties[constants.BUILD_PROPERTIES_RUNTIME_OS] = utils.PrettyOSName() variant := buildProperties[constants.BUILD_PROPERTIES_BUILD_VARIANT] @@ -96,8 +96,8 @@ func (s *SetupBuildProperties) Run(context map[string]interface{}, ctx *types.Co buildProperties[constants.BUILD_PROPERTIES_SOFTWARE] = DEFAULT_SOFTWARE } - if utils.MapHas(context, constants.CTX_SKETCH_LOCATION) { - sourcePath, err := filepath.Abs(context[constants.CTX_SKETCH_LOCATION].(string)) + if ctx.SketchLocation != "" { + sourcePath, err := filepath.Abs(ctx.SketchLocation) if err != nil { return err } diff --git a/src/arduino.cc/builder/sketch_loader.go b/src/arduino.cc/builder/sketch_loader.go index 214a2f13..32c4dc54 100644 --- a/src/arduino.cc/builder/sketch_loader.go +++ b/src/arduino.cc/builder/sketch_loader.go @@ -45,11 +45,11 @@ import ( type SketchLoader struct{} func (s *SketchLoader) Run(context map[string]interface{}, ctx *types.Context) error { - if !utils.MapHas(context, constants.CTX_SKETCH_LOCATION) { + if ctx.SketchLocation == "" { return nil } - sketchLocation := context[constants.CTX_SKETCH_LOCATION].(string) + sketchLocation := ctx.SketchLocation sketchLocation, err := filepath.Abs(sketchLocation) if err != nil { @@ -62,7 +62,8 @@ func (s *SketchLoader) Run(context map[string]interface{}, ctx *types.Context) e if mainSketchStat.IsDir() { sketchLocation = filepath.Join(sketchLocation, mainSketchStat.Name()+".ino") } - context[constants.CTX_SKETCH_LOCATION] = sketchLocation + + ctx.SketchLocation = sketchLocation allSketchFilePaths, err := collectAllSketchFiles(filepath.Dir(sketchLocation)) if err != nil { @@ -79,7 +80,7 @@ func (s *SketchLoader) Run(context map[string]interface{}, ctx *types.Context) e return utils.WrapError(err) } - context[constants.CTX_SKETCH_LOCATION] = sketchLocation + ctx.SketchLocation = sketchLocation context[constants.CTX_SKETCH] = sketch return nil diff --git a/src/arduino.cc/builder/target_board_resolver.go b/src/arduino.cc/builder/target_board_resolver.go index 4abf08f5..8bfff7c7 100644 --- a/src/arduino.cc/builder/target_board_resolver.go +++ b/src/arduino.cc/builder/target_board_resolver.go @@ -39,7 +39,7 @@ import ( type TargetBoardResolver struct{} func (s *TargetBoardResolver) Run(context map[string]interface{}, ctx *types.Context) error { - fqbn := context[constants.CTX_FQBN].(string) + fqbn := ctx.FQBN fqbnParts := strings.Split(fqbn, ":") targetPackageName := fqbnParts[0] diff --git a/src/arduino.cc/builder/test/add_build_board_property_if_missing_test.go b/src/arduino.cc/builder/test/add_build_board_property_if_missing_test.go index 1568f098..fc4aceca 100644 --- a/src/arduino.cc/builder/test/add_build_board_property_if_missing_test.go +++ b/src/arduino.cc/builder/test/add_build_board_property_if_missing_test.go @@ -40,9 +40,10 @@ import ( func TestAddBuildBoardPropertyIfMissing(t *testing.T) { context := make(map[string]interface{}) - ctx := &types.Context{} - context[constants.CTX_HARDWARE_FOLDERS] = []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware", "user_hardware"} - context[constants.CTX_FQBN] = "my_avr_platform:avr:mymega" + ctx := &types.Context{ + HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware", "user_hardware"}, + FQBN: "my_avr_platform:avr:mymega", + } commands := []types.Command{ &builder.SetupHumanLoggerIfMissing{}, @@ -68,9 +69,10 @@ func TestAddBuildBoardPropertyIfMissing(t *testing.T) { func TestAddBuildBoardPropertyIfMissingNotMissing(t *testing.T) { context := make(map[string]interface{}) - ctx := &types.Context{} - context[constants.CTX_HARDWARE_FOLDERS] = []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware", "user_hardware"} - context[constants.CTX_FQBN] = "my_avr_platform:avr:mymega:cpu=atmega2560" + ctx := &types.Context{ + HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware", "user_hardware"}, + FQBN: "my_avr_platform:avr:mymega:cpu=atmega2560", + } commands := []types.Command{ &builder.SetupHumanLoggerIfMissing{}, diff --git a/src/arduino.cc/builder/test/additional_sketch_files_copier_test.go b/src/arduino.cc/builder/test/additional_sketch_files_copier_test.go index 8ed037f8..c82e77aa 100644 --- a/src/arduino.cc/builder/test/additional_sketch_files_copier_test.go +++ b/src/arduino.cc/builder/test/additional_sketch_files_copier_test.go @@ -56,13 +56,13 @@ func (s ByFileInfoName) Less(i, j int) bool { func TestCopyOtherFiles(t *testing.T) { context := make(map[string]interface{}) - ctx := &types.Context{} + ctx := &types.Context{ + SketchLocation: filepath.Join("sketch1", "sketch.ino"), + } buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) - context[constants.CTX_SKETCH_LOCATION] = filepath.Join("sketch1", "sketch.ino") - commands := []types.Command{ &builder.SetupHumanLoggerIfMissing{}, &builder.AddAdditionalEntriesToContext{}, @@ -95,13 +95,13 @@ func TestCopyOtherFiles(t *testing.T) { func TestCopyOtherFilesOnlyIfChanged(t *testing.T) { context := make(map[string]interface{}) - ctx := &types.Context{} + ctx := &types.Context{ + SketchLocation: filepath.Join("sketch1", "sketch.ino"), + } buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) - context[constants.CTX_SKETCH_LOCATION] = filepath.Join("sketch1", "sketch.ino") - commands := []types.Command{ &builder.SetupHumanLoggerIfMissing{}, &builder.AddAdditionalEntriesToContext{}, @@ -121,7 +121,9 @@ func TestCopyOtherFilesOnlyIfChanged(t *testing.T) { context = make(map[string]interface{}) context[constants.CTX_BUILD_PATH] = buildPath - context[constants.CTX_SKETCH_LOCATION] = filepath.Join("sketch1", "sketch.ino") + ctx = &types.Context{ + SketchLocation: filepath.Join("sketch1", "sketch.ino"), + } for _, command := range commands { err := command.Run(context, ctx) diff --git a/src/arduino.cc/builder/test/builder_test.go b/src/arduino.cc/builder/test/builder_test.go index 98992181..6c834545 100644 --- a/src/arduino.cc/builder/test/builder_test.go +++ b/src/arduino.cc/builder/test/builder_test.go @@ -44,18 +44,19 @@ func TestBuilderEmptySketch(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) - ctx := &types.Context{} + ctx := &types.Context{ + HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, + ToolsFolders: []string{"downloaded_tools"}, + BuiltInLibrariesFolders: []string{"downloaded_libraries"}, + OtherLibrariesFolders: []string{"libraries"}, + SketchLocation: filepath.Join("sketch1", "sketch.ino"), + FQBN: "arduino:avr:uno", + ArduinoAPIVersion: "10600", + } buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) - context[constants.CTX_HARDWARE_FOLDERS] = []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"} - context[constants.CTX_TOOLS_FOLDERS] = []string{"downloaded_tools"} - context[constants.CTX_FQBN] = "arduino:avr:uno" - context[constants.CTX_SKETCH_LOCATION] = filepath.Join("sketch1", "sketch.ino") - context[constants.CTX_BUILT_IN_LIBRARIES_FOLDERS] = []string{"downloaded_libraries"} - context[constants.CTX_OTHER_LIBRARIES_FOLDERS] = []string{"libraries"} - context[constants.CTX_BUILD_PROPERTIES_RUNTIME_IDE_VERSION] = "10600" context[constants.CTX_VERBOSE] = true context[constants.CTX_DEBUG_LEVEL] = 10 @@ -79,18 +80,19 @@ func TestBuilderBridge(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) - ctx := &types.Context{} + ctx := &types.Context{ + HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, + ToolsFolders: []string{"downloaded_tools"}, + BuiltInLibrariesFolders: []string{"downloaded_libraries"}, + OtherLibrariesFolders: []string{"libraries"}, + SketchLocation: filepath.Join("downloaded_libraries", "Bridge", "examples", "Bridge", "Bridge.ino"), + FQBN: "arduino:avr:leonardo", + ArduinoAPIVersion: "10600", + } buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) - context[constants.CTX_HARDWARE_FOLDERS] = []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"} - context[constants.CTX_TOOLS_FOLDERS] = []string{"downloaded_tools"} - context[constants.CTX_FQBN] = "arduino:avr:leonardo" - context[constants.CTX_SKETCH_LOCATION] = filepath.Join("downloaded_libraries", "Bridge", "examples", "Bridge", "Bridge.ino") - context[constants.CTX_BUILT_IN_LIBRARIES_FOLDERS] = []string{"downloaded_libraries"} - context[constants.CTX_OTHER_LIBRARIES_FOLDERS] = []string{"libraries"} - context[constants.CTX_BUILD_PROPERTIES_RUNTIME_IDE_VERSION] = "10600" context[constants.CTX_VERBOSE] = true command := builder.Builder{} @@ -115,19 +117,19 @@ func TestBuilderSketchWithConfig(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) - ctx := &types.Context{} + ctx := &types.Context{ + HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, + ToolsFolders: []string{"downloaded_tools"}, + BuiltInLibrariesFolders: []string{"downloaded_libraries"}, + OtherLibrariesFolders: []string{"libraries"}, + SketchLocation: filepath.Join("sketch_with_config", "sketch_with_config.ino"), + FQBN: "arduino:avr:leonardo", + ArduinoAPIVersion: "10600", + } buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) - context[constants.CTX_HARDWARE_FOLDERS] = []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"} - context[constants.CTX_TOOLS_FOLDERS] = []string{"downloaded_tools"} - context[constants.CTX_FQBN] = "arduino:avr:leonardo" - context[constants.CTX_SKETCH_LOCATION] = filepath.Join("sketch_with_config", "sketch_with_config.ino") - context[constants.CTX_BUILT_IN_LIBRARIES_FOLDERS] = []string{"downloaded_libraries"} - context[constants.CTX_OTHER_LIBRARIES_FOLDERS] = []string{"libraries"} - context[constants.CTX_BUILD_PROPERTIES_RUNTIME_IDE_VERSION] = "10600" - command := builder.Builder{} err := command.Run(context, ctx) NoError(t, err) @@ -150,19 +152,19 @@ func TestBuilderBridgeTwice(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) - ctx := &types.Context{} + ctx := &types.Context{ + HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, + ToolsFolders: []string{"downloaded_tools"}, + BuiltInLibrariesFolders: []string{"downloaded_libraries"}, + OtherLibrariesFolders: []string{"libraries"}, + SketchLocation: filepath.Join("downloaded_libraries", "Bridge", "examples", "Bridge", "Bridge.ino"), + FQBN: "arduino:avr:leonardo", + ArduinoAPIVersion: "10600", + } buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) - context[constants.CTX_HARDWARE_FOLDERS] = []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"} - context[constants.CTX_TOOLS_FOLDERS] = []string{"downloaded_tools"} - context[constants.CTX_FQBN] = "arduino:avr:leonardo" - context[constants.CTX_SKETCH_LOCATION] = filepath.Join("downloaded_libraries", "Bridge", "examples", "Bridge", "Bridge.ino") - context[constants.CTX_BUILT_IN_LIBRARIES_FOLDERS] = []string{"downloaded_libraries"} - context[constants.CTX_OTHER_LIBRARIES_FOLDERS] = []string{"libraries"} - context[constants.CTX_BUILD_PROPERTIES_RUNTIME_IDE_VERSION] = "10600" - command := builder.Builder{} err := command.Run(context, ctx) NoError(t, err) @@ -189,18 +191,19 @@ func TestBuilderBridgeSAM(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) - ctx := &types.Context{} + ctx := &types.Context{ + HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, + ToolsFolders: []string{"downloaded_tools"}, + BuiltInLibrariesFolders: []string{"downloaded_libraries"}, + OtherLibrariesFolders: []string{"libraries"}, + SketchLocation: filepath.Join("downloaded_libraries", "Bridge", "examples", "Bridge", "Bridge.ino"), + FQBN: "arduino:sam:arduino_due_x_dbg", + ArduinoAPIVersion: "10600", + } buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) - context[constants.CTX_HARDWARE_FOLDERS] = []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"} - context[constants.CTX_TOOLS_FOLDERS] = []string{"downloaded_tools"} - context[constants.CTX_FQBN] = "arduino:sam:arduino_due_x_dbg" - context[constants.CTX_SKETCH_LOCATION] = filepath.Join("downloaded_libraries", "Bridge", "examples", "Bridge", "Bridge.ino") - context[constants.CTX_BUILT_IN_LIBRARIES_FOLDERS] = []string{"downloaded_libraries"} - context[constants.CTX_OTHER_LIBRARIES_FOLDERS] = []string{"libraries"} - context[constants.CTX_BUILD_PROPERTIES_RUNTIME_IDE_VERSION] = "10600" context[constants.CTX_WARNINGS_LEVEL] = "all" command := builder.Builder{} @@ -234,19 +237,19 @@ func TestBuilderBridgeRedBearLab(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) - ctx := &types.Context{} + ctx := &types.Context{ + HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware", "downloaded_board_manager_stuff"}, + ToolsFolders: []string{"downloaded_tools", "downloaded_board_manager_stuff"}, + BuiltInLibrariesFolders: []string{"downloaded_libraries"}, + OtherLibrariesFolders: []string{"libraries"}, + SketchLocation: filepath.Join("downloaded_libraries", "Bridge", "examples", "Bridge", "Bridge.ino"), + FQBN: "RedBearLab:avr:blend", + ArduinoAPIVersion: "10600", + } buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) - context[constants.CTX_HARDWARE_FOLDERS] = []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware", "downloaded_board_manager_stuff"} - context[constants.CTX_TOOLS_FOLDERS] = []string{"downloaded_tools", "downloaded_board_manager_stuff"} - context[constants.CTX_FQBN] = "RedBearLab:avr:blend" - context[constants.CTX_SKETCH_LOCATION] = filepath.Join("downloaded_libraries", "Bridge", "examples", "Bridge", "Bridge.ino") - context[constants.CTX_BUILT_IN_LIBRARIES_FOLDERS] = []string{"downloaded_libraries"} - context[constants.CTX_OTHER_LIBRARIES_FOLDERS] = []string{"libraries"} - context[constants.CTX_BUILD_PROPERTIES_RUNTIME_IDE_VERSION] = "10600" - command := builder.Builder{} err := command.Run(context, ctx) NoError(t, err) @@ -269,19 +272,19 @@ func TestBuilderSketchNoFunctions(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) - ctx := &types.Context{} + ctx := &types.Context{ + HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware", "downloaded_board_manager_stuff"}, + ToolsFolders: []string{"downloaded_tools", "downloaded_board_manager_stuff"}, + BuiltInLibrariesFolders: []string{"downloaded_libraries"}, + OtherLibrariesFolders: []string{"libraries"}, + SketchLocation: filepath.Join("sketch_no_functions", "main.ino"), + FQBN: "RedBearLab:avr:blend", + ArduinoAPIVersion: "10600", + } buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) - context[constants.CTX_HARDWARE_FOLDERS] = []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware", "downloaded_board_manager_stuff"} - context[constants.CTX_TOOLS_FOLDERS] = []string{"downloaded_tools", "downloaded_board_manager_stuff"} - context[constants.CTX_FQBN] = "RedBearLab:avr:blend" - context[constants.CTX_SKETCH_LOCATION] = filepath.Join("sketch_no_functions", "main.ino") - context[constants.CTX_BUILT_IN_LIBRARIES_FOLDERS] = []string{"downloaded_libraries"} - context[constants.CTX_OTHER_LIBRARIES_FOLDERS] = []string{"libraries"} - context[constants.CTX_BUILD_PROPERTIES_RUNTIME_IDE_VERSION] = "10600" - command := builder.Builder{} err := command.Run(context, ctx) require.Error(t, err) @@ -291,19 +294,19 @@ func TestBuilderSketchWithBackup(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) - ctx := &types.Context{} + ctx := &types.Context{ + HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware", "downloaded_board_manager_stuff"}, + ToolsFolders: []string{"downloaded_tools", "downloaded_board_manager_stuff"}, + BuiltInLibrariesFolders: []string{"downloaded_libraries"}, + OtherLibrariesFolders: []string{"libraries"}, + SketchLocation: filepath.Join("sketch_with_backup_files", "sketch.ino"), + FQBN: "arduino:avr:uno", + ArduinoAPIVersion: "10600", + } buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) - context[constants.CTX_HARDWARE_FOLDERS] = []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware", "downloaded_board_manager_stuff"} - context[constants.CTX_TOOLS_FOLDERS] = []string{"downloaded_tools", "downloaded_board_manager_stuff"} - context[constants.CTX_FQBN] = "arduino:avr:uno" - context[constants.CTX_SKETCH_LOCATION] = filepath.Join("sketch_with_backup_files", "sketch.ino") - context[constants.CTX_BUILT_IN_LIBRARIES_FOLDERS] = []string{"downloaded_libraries"} - context[constants.CTX_OTHER_LIBRARIES_FOLDERS] = []string{"libraries"} - context[constants.CTX_BUILD_PROPERTIES_RUNTIME_IDE_VERSION] = "10600" - command := builder.Builder{} err := command.Run(context, ctx) NoError(t, err) @@ -313,19 +316,19 @@ func TestBuilderSketchWithOldLib(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) - ctx := &types.Context{} + ctx := &types.Context{ + HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, + ToolsFolders: []string{"downloaded_tools"}, + BuiltInLibrariesFolders: []string{"downloaded_libraries"}, + OtherLibrariesFolders: []string{"libraries"}, + SketchLocation: filepath.Join("sketch_with_old_lib", "sketch.ino"), + FQBN: "arduino:avr:uno", + ArduinoAPIVersion: "10600", + } buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) - context[constants.CTX_HARDWARE_FOLDERS] = []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"} - context[constants.CTX_TOOLS_FOLDERS] = []string{"downloaded_tools"} - context[constants.CTX_FQBN] = "arduino:avr:uno" - context[constants.CTX_SKETCH_LOCATION] = filepath.Join("sketch_with_old_lib", "sketch.ino") - context[constants.CTX_BUILT_IN_LIBRARIES_FOLDERS] = []string{"downloaded_libraries"} - context[constants.CTX_OTHER_LIBRARIES_FOLDERS] = []string{"libraries"} - context[constants.CTX_BUILD_PROPERTIES_RUNTIME_IDE_VERSION] = "10600" - command := builder.Builder{} err := command.Run(context, ctx) NoError(t, err) @@ -335,19 +338,19 @@ func TestBuilderSketchWithSubfolders(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) - ctx := &types.Context{} + ctx := &types.Context{ + HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, + ToolsFolders: []string{"downloaded_tools"}, + BuiltInLibrariesFolders: []string{"downloaded_libraries"}, + OtherLibrariesFolders: []string{"libraries"}, + SketchLocation: filepath.Join("sketch_with_subfolders", "sketch_with_subfolders.ino"), + FQBN: "arduino:avr:uno", + ArduinoAPIVersion: "10600", + } buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) - context[constants.CTX_HARDWARE_FOLDERS] = []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"} - context[constants.CTX_TOOLS_FOLDERS] = []string{"downloaded_tools"} - context[constants.CTX_FQBN] = "arduino:avr:uno" - context[constants.CTX_SKETCH_LOCATION] = filepath.Join("sketch_with_subfolders", "sketch_with_subfolders.ino") - context[constants.CTX_BUILT_IN_LIBRARIES_FOLDERS] = []string{"downloaded_libraries"} - context[constants.CTX_OTHER_LIBRARIES_FOLDERS] = []string{"libraries"} - context[constants.CTX_BUILD_PROPERTIES_RUNTIME_IDE_VERSION] = "10600" - command := builder.Builder{} err := command.Run(context, ctx) NoError(t, err) @@ -357,21 +360,21 @@ func TestBuilderSketchBuildPathContainsUnusedPreviouslyCompiledLibrary(t *testin DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) - ctx := &types.Context{} + ctx := &types.Context{ + HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, + ToolsFolders: []string{"downloaded_tools"}, + BuiltInLibrariesFolders: []string{"downloaded_libraries"}, + OtherLibrariesFolders: []string{"libraries"}, + SketchLocation: filepath.Join("downloaded_libraries", "Bridge", "examples", "Bridge", "Bridge.ino"), + FQBN: "arduino:avr:leonardo", + ArduinoAPIVersion: "10600", + } buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) NoError(t, os.MkdirAll(filepath.Join(buildPath, constants.FOLDER_LIBRARIES, "SPI"), os.FileMode(0755))) - context[constants.CTX_HARDWARE_FOLDERS] = []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"} - context[constants.CTX_TOOLS_FOLDERS] = []string{"downloaded_tools"} - context[constants.CTX_FQBN] = "arduino:avr:leonardo" - context[constants.CTX_SKETCH_LOCATION] = filepath.Join("downloaded_libraries", "Bridge", "examples", "Bridge", "Bridge.ino") - context[constants.CTX_BUILT_IN_LIBRARIES_FOLDERS] = []string{"downloaded_libraries"} - context[constants.CTX_OTHER_LIBRARIES_FOLDERS] = []string{"libraries"} - context[constants.CTX_BUILD_PROPERTIES_RUNTIME_IDE_VERSION] = "10600" - command := builder.Builder{} err := command.Run(context, ctx) NoError(t, err) diff --git a/src/arduino.cc/builder/test/coan_runner_test.go b/src/arduino.cc/builder/test/coan_runner_test.go index 37a524b0..e7781b15 100644 --- a/src/arduino.cc/builder/test/coan_runner_test.go +++ b/src/arduino.cc/builder/test/coan_runner_test.go @@ -45,16 +45,17 @@ func TestCoanRunner(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) - ctx := &types.Context{} + ctx := &types.Context{ + HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, + ToolsFolders: []string{"downloaded_tools"}, + SketchLocation: filepath.Join("sketch2", "SketchWithIfDef.ino"), + FQBN: "arduino:avr:leonardo", + ArduinoAPIVersion: "10600", + } buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) - context[constants.CTX_HARDWARE_FOLDERS] = []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"} - context[constants.CTX_TOOLS_FOLDERS] = []string{"downloaded_tools"} - context[constants.CTX_FQBN] = "arduino:avr:leonardo" - context[constants.CTX_SKETCH_LOCATION] = filepath.Join("sketch2", "SketchWithIfDef.ino") - context[constants.CTX_BUILD_PROPERTIES_RUNTIME_IDE_VERSION] = "10600" context[constants.CTX_VERBOSE] = true commands := []types.Command{ diff --git a/src/arduino.cc/builder/test/create_build_options_map_test.go b/src/arduino.cc/builder/test/create_build_options_map_test.go index c7996249..4fc54a41 100644 --- a/src/arduino.cc/builder/test/create_build_options_map_test.go +++ b/src/arduino.cc/builder/test/create_build_options_map_test.go @@ -32,6 +32,7 @@ package test import ( "arduino.cc/builder" "arduino.cc/builder/constants" + "arduino.cc/builder/props" "arduino.cc/builder/types" "arduino.cc/builder/utils" "github.com/stretchr/testify/require" @@ -40,32 +41,37 @@ import ( func TestCreateBuildOptionsMap(t *testing.T) { context := make(map[string]interface{}) - ctx := &types.Context{} + ctx := &types.Context{ + HardwareFolders: []string{"hardware", "hardware2"}, + ToolsFolders: []string{"tools"}, + OtherLibrariesFolders: []string{"libraries"}, + SketchLocation: "sketchLocation", + FQBN: "fqbn", + ArduinoAPIVersion: "ideVersion", + } context[constants.CTX_BUILD_PATH] = "buildPath" - context[constants.CTX_HARDWARE_FOLDERS] = []string{"hardware", "hardware2"} - context[constants.CTX_TOOLS_FOLDERS] = []string{"tools"} - context[constants.CTX_OTHER_LIBRARIES_FOLDERS] = []string{"libraries"} - context[constants.CTX_FQBN] = "fqbn" - context[constants.CTX_SKETCH_LOCATION] = "sketchLocation" context[constants.CTX_VERBOSE] = true - context[constants.CTX_BUILD_PROPERTIES_RUNTIME_IDE_VERSION] = "ideVersion" context[constants.CTX_DEBUG_LEVEL] = 5 create := builder.CreateBuildOptionsMap{} err := create.Run(context, ctx) NoError(t, err) - buildOptions := context[constants.CTX_BUILD_OPTIONS].(map[string]string) - require.Equal(t, 6, len(utils.KeysOfMapOfString(buildOptions))) - require.Equal(t, "hardware,hardware2", buildOptions[constants.CTX_HARDWARE_FOLDERS]) - require.Equal(t, "tools", buildOptions[constants.CTX_TOOLS_FOLDERS]) - require.Equal(t, "libraries", buildOptions[constants.CTX_OTHER_LIBRARIES_FOLDERS]) - require.Equal(t, "fqbn", buildOptions[constants.CTX_FQBN]) - require.Equal(t, "sketchLocation", buildOptions[constants.CTX_SKETCH_LOCATION]) - require.Equal(t, "ideVersion", buildOptions[constants.CTX_BUILD_PROPERTIES_RUNTIME_IDE_VERSION]) + buildOptions := context[constants.CTX_BUILD_OPTIONS].(props.PropertiesMap) + require.Equal(t, 8, len(utils.KeysOfMapOfString(buildOptions))) + require.Equal(t, "hardware,hardware2", buildOptions["hardwareFolders"]) + require.Equal(t, "tools", buildOptions["toolsFolders"]) + require.Equal(t, "", buildOptions["builtInLibrariesFolders"]) + require.Equal(t, "", buildOptions["customBuildProperties"]) + require.Equal(t, "libraries", buildOptions["otherLibrariesFolders"]) + require.Equal(t, "fqbn", buildOptions["fqbn"]) + require.Equal(t, "sketchLocation", buildOptions["sketchLocation"]) + require.Equal(t, "ideVersion", buildOptions["runtime.ide.version"]) require.Equal(t, "{\n"+ + " \"builtInLibrariesFolders\": \"\",\n"+ + " \"customBuildProperties\": \"\",\n"+ " \"fqbn\": \"fqbn\",\n"+ " \"hardwareFolders\": \"hardware,hardware2\",\n"+ " \"otherLibrariesFolders\": \"libraries\",\n"+ diff --git a/src/arduino.cc/builder/test/ctags_runner_test.go b/src/arduino.cc/builder/test/ctags_runner_test.go index 1c601420..969d8f7b 100644 --- a/src/arduino.cc/builder/test/ctags_runner_test.go +++ b/src/arduino.cc/builder/test/ctags_runner_test.go @@ -44,20 +44,22 @@ import ( func TestCTagsRunner(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) + sketchLocation := Abs(t, filepath.Join("downloaded_libraries", "Bridge", "examples", "Bridge", "Bridge.ino")) + context := make(map[string]interface{}) - ctx := &types.Context{} + ctx := &types.Context{ + HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, + ToolsFolders: []string{"downloaded_tools"}, + BuiltInLibrariesFolders: []string{"downloaded_libraries"}, + OtherLibrariesFolders: []string{"libraries"}, + SketchLocation: sketchLocation, + FQBN: "arduino:avr:leonardo", + ArduinoAPIVersion: "10600", + } buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) - sketchLocation := Abs(t, filepath.Join("downloaded_libraries", "Bridge", "examples", "Bridge", "Bridge.ino")) - context[constants.CTX_HARDWARE_FOLDERS] = []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"} - context[constants.CTX_TOOLS_FOLDERS] = []string{"downloaded_tools"} - context[constants.CTX_FQBN] = "arduino:avr:leonardo" - context[constants.CTX_SKETCH_LOCATION] = sketchLocation - context[constants.CTX_BUILD_PROPERTIES_RUNTIME_IDE_VERSION] = "10600" - context[constants.CTX_BUILT_IN_LIBRARIES_FOLDERS] = []string{"downloaded_libraries"} - context[constants.CTX_OTHER_LIBRARIES_FOLDERS] = []string{"libraries"} context[constants.CTX_VERBOSE] = true commands := []types.Command{ @@ -95,20 +97,22 @@ func TestCTagsRunner(t *testing.T) { func TestCTagsRunnerSketchWithClass(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) + sketchLocation := Abs(t, filepath.Join("sketch_with_class", "sketch.ino")) + context := make(map[string]interface{}) - ctx := &types.Context{} + ctx := &types.Context{ + HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, + ToolsFolders: []string{"downloaded_tools"}, + BuiltInLibrariesFolders: []string{"downloaded_libraries"}, + OtherLibrariesFolders: []string{"libraries"}, + SketchLocation: sketchLocation, + FQBN: "arduino:avr:leonardo", + ArduinoAPIVersion: "10600", + } buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) - sketchLocation := Abs(t, filepath.Join("sketch_with_class", "sketch.ino")) - context[constants.CTX_HARDWARE_FOLDERS] = []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"} - context[constants.CTX_TOOLS_FOLDERS] = []string{"downloaded_tools"} - context[constants.CTX_FQBN] = "arduino:avr:leonardo" - context[constants.CTX_SKETCH_LOCATION] = sketchLocation - context[constants.CTX_BUILD_PROPERTIES_RUNTIME_IDE_VERSION] = "10600" - context[constants.CTX_BUILT_IN_LIBRARIES_FOLDERS] = []string{"downloaded_libraries"} - context[constants.CTX_OTHER_LIBRARIES_FOLDERS] = []string{"libraries"} context[constants.CTX_VERBOSE] = true commands := []types.Command{ @@ -144,20 +148,22 @@ func TestCTagsRunnerSketchWithClass(t *testing.T) { func TestCTagsRunnerSketchWithTypename(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) + sketchLocation := Abs(t, filepath.Join("sketch_with_typename", "sketch.ino")) + context := make(map[string]interface{}) - ctx := &types.Context{} + ctx := &types.Context{ + HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, + ToolsFolders: []string{"downloaded_tools"}, + BuiltInLibrariesFolders: []string{"downloaded_libraries"}, + OtherLibrariesFolders: []string{"libraries"}, + SketchLocation: sketchLocation, + FQBN: "arduino:avr:leonardo", + ArduinoAPIVersion: "10600", + } buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) - sketchLocation := Abs(t, filepath.Join("sketch_with_typename", "sketch.ino")) - context[constants.CTX_HARDWARE_FOLDERS] = []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"} - context[constants.CTX_TOOLS_FOLDERS] = []string{"downloaded_tools"} - context[constants.CTX_FQBN] = "arduino:avr:leonardo" - context[constants.CTX_SKETCH_LOCATION] = sketchLocation - context[constants.CTX_BUILD_PROPERTIES_RUNTIME_IDE_VERSION] = "10600" - context[constants.CTX_BUILT_IN_LIBRARIES_FOLDERS] = []string{"downloaded_libraries"} - context[constants.CTX_OTHER_LIBRARIES_FOLDERS] = []string{"libraries"} context[constants.CTX_VERBOSE] = true commands := []types.Command{ @@ -192,20 +198,22 @@ func TestCTagsRunnerSketchWithTypename(t *testing.T) { func TestCTagsRunnerSketchWithNamespace(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) + sketchLocation := Abs(t, filepath.Join("sketch_with_namespace", "sketch.ino")) + context := make(map[string]interface{}) - ctx := &types.Context{} + ctx := &types.Context{ + HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, + ToolsFolders: []string{"downloaded_tools"}, + BuiltInLibrariesFolders: []string{"downloaded_libraries"}, + OtherLibrariesFolders: []string{"libraries"}, + SketchLocation: sketchLocation, + FQBN: "arduino:avr:leonardo", + ArduinoAPIVersion: "10600", + } buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) - sketchLocation := Abs(t, filepath.Join("sketch_with_namespace", "sketch.ino")) - context[constants.CTX_HARDWARE_FOLDERS] = []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"} - context[constants.CTX_TOOLS_FOLDERS] = []string{"downloaded_tools"} - context[constants.CTX_FQBN] = "arduino:avr:leonardo" - context[constants.CTX_SKETCH_LOCATION] = sketchLocation - context[constants.CTX_BUILD_PROPERTIES_RUNTIME_IDE_VERSION] = "10600" - context[constants.CTX_BUILT_IN_LIBRARIES_FOLDERS] = []string{"downloaded_libraries"} - context[constants.CTX_OTHER_LIBRARIES_FOLDERS] = []string{"libraries"} context[constants.CTX_VERBOSE] = true commands := []types.Command{ @@ -239,20 +247,22 @@ func TestCTagsRunnerSketchWithNamespace(t *testing.T) { func TestCTagsRunnerSketchWithTemplates(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) + sketchLocation := Abs(t, filepath.Join("sketch_with_templates_and_shift", "template_and_shift.cpp")) + context := make(map[string]interface{}) - ctx := &types.Context{} + ctx := &types.Context{ + HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, + ToolsFolders: []string{"downloaded_tools"}, + BuiltInLibrariesFolders: []string{"downloaded_libraries"}, + OtherLibrariesFolders: []string{"libraries"}, + SketchLocation: sketchLocation, + FQBN: "arduino:avr:leonardo", + ArduinoAPIVersion: "10600", + } buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) - sketchLocation := Abs(t, filepath.Join("sketch_with_templates_and_shift", "template_and_shift.cpp")) - context[constants.CTX_HARDWARE_FOLDERS] = []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"} - context[constants.CTX_TOOLS_FOLDERS] = []string{"downloaded_tools"} - context[constants.CTX_FQBN] = "arduino:avr:leonardo" - context[constants.CTX_SKETCH_LOCATION] = sketchLocation - context[constants.CTX_BUILD_PROPERTIES_RUNTIME_IDE_VERSION] = "10600" - context[constants.CTX_BUILT_IN_LIBRARIES_FOLDERS] = []string{"downloaded_libraries"} - context[constants.CTX_OTHER_LIBRARIES_FOLDERS] = []string{"libraries"} context[constants.CTX_VERBOSE] = true commands := []types.Command{ diff --git a/src/arduino.cc/builder/test/fail_if_buildpath_equals_sketchpath_test.go b/src/arduino.cc/builder/test/fail_if_buildpath_equals_sketchpath_test.go index 2d6d7ba6..216742f0 100644 --- a/src/arduino.cc/builder/test/fail_if_buildpath_equals_sketchpath_test.go +++ b/src/arduino.cc/builder/test/fail_if_buildpath_equals_sketchpath_test.go @@ -39,10 +39,11 @@ import ( func TestFailIfBuildPathEqualsSketchPath(t *testing.T) { context := make(map[string]interface{}) - ctx := &types.Context{} + ctx := &types.Context{ + SketchLocation: "buildPath/sketch.ino", + } context[constants.CTX_BUILD_PATH] = "buildPath" - context[constants.CTX_SKETCH_LOCATION] = "buildPath/sketch.ino" command := builder.FailIfBuildPathEqualsSketchPath{} require.Error(t, command.Run(context, ctx)) @@ -50,10 +51,11 @@ func TestFailIfBuildPathEqualsSketchPath(t *testing.T) { func TestFailIfBuildPathEqualsSketchPathSketchPathDiffers(t *testing.T) { context := make(map[string]interface{}) - ctx := &types.Context{} + ctx := &types.Context{ + SketchLocation: "sketchPath/sketch.ino", + } context[constants.CTX_BUILD_PATH] = "buildPath" - context[constants.CTX_SKETCH_LOCATION] = "sketchPath/sketch.ino" command := builder.FailIfBuildPathEqualsSketchPath{} NoError(t, command.Run(context, ctx)) diff --git a/src/arduino.cc/builder/test/generate_buildpath_if_missing_test.go b/src/arduino.cc/builder/test/generate_buildpath_if_missing_test.go index f9c18a61..214a43c0 100644 --- a/src/arduino.cc/builder/test/generate_buildpath_if_missing_test.go +++ b/src/arduino.cc/builder/test/generate_buildpath_if_missing_test.go @@ -41,9 +41,9 @@ import ( func TestGenerateBuildPathIfMissing(t *testing.T) { context := make(map[string]interface{}) - ctx := &types.Context{} - - context[constants.CTX_SKETCH_LOCATION] = "test" + ctx := &types.Context{ + SketchLocation: "test", + } command := builder.GenerateBuildPathIfMissing{} err := command.Run(context, ctx) @@ -56,9 +56,10 @@ func TestGenerateBuildPathIfMissing(t *testing.T) { func TestGenerateBuildPathIfEmpty(t *testing.T) { context := make(map[string]interface{}) - ctx := &types.Context{} + ctx := &types.Context{ + SketchLocation: "test", + } - context[constants.CTX_SKETCH_LOCATION] = "test" context[constants.CTX_BUILD_PATH] = constants.EMPTY_STRING createBuildPathIfMissing := builder.GenerateBuildPathIfMissing{} @@ -85,9 +86,9 @@ func TestDontGenerateBuildPathIfPresent(t *testing.T) { func TestGenerateBuildPathAndEnsureItExists(t *testing.T) { context := make(map[string]interface{}) - ctx := &types.Context{} - - context[constants.CTX_SKETCH_LOCATION] = "test" + ctx := &types.Context{ + SketchLocation: "test", + } commands := []types.Command{ &builder.GenerateBuildPathIfMissing{}, diff --git a/src/arduino.cc/builder/test/hardware_loader_test.go b/src/arduino.cc/builder/test/hardware_loader_test.go index 88843fbb..5f091f88 100644 --- a/src/arduino.cc/builder/test/hardware_loader_test.go +++ b/src/arduino.cc/builder/test/hardware_loader_test.go @@ -42,8 +42,9 @@ import ( func TestLoadHardware(t *testing.T) { context := make(map[string]interface{}) - ctx := &types.Context{} - context[constants.CTX_HARDWARE_FOLDERS] = []string{"downloaded_hardware", filepath.Join("..", "hardware"), "hardware"} + ctx := &types.Context{ + HardwareFolders: []string{"downloaded_hardware", filepath.Join("..", "hardware"), "hardware"}, + } commands := []types.Command{ &builder.SetupHumanLoggerIfMissing{}, @@ -87,8 +88,9 @@ func TestLoadHardware(t *testing.T) { func TestLoadHardwareMixingUserHardwareFolder(t *testing.T) { context := make(map[string]interface{}) - ctx := &types.Context{} - context[constants.CTX_HARDWARE_FOLDERS] = []string{"downloaded_hardware", filepath.Join("..", "hardware"), "hardware", "user_hardware"} + ctx := &types.Context{ + HardwareFolders: []string{"downloaded_hardware", filepath.Join("..", "hardware"), "hardware", "user_hardware"}, + } commands := []types.Command{ &builder.SetupHumanLoggerIfMissing{}, @@ -158,8 +160,9 @@ func TestLoadHardwareMixingUserHardwareFolder(t *testing.T) { func TestLoadHardwareWithBoardManagerFolderStructure(t *testing.T) { context := make(map[string]interface{}) - ctx := &types.Context{} - context[constants.CTX_HARDWARE_FOLDERS] = []string{"downloaded_board_manager_stuff"} + ctx := &types.Context{ + HardwareFolders: []string{"downloaded_board_manager_stuff"}, + } commands := []types.Command{ &builder.SetupHumanLoggerIfMissing{}, @@ -207,9 +210,9 @@ func TestLoadHardwareWithBoardManagerFolderStructure(t *testing.T) { func TestLoadLotsOfHardware(t *testing.T) { context := make(map[string]interface{}) - ctx := &types.Context{} - - context[constants.CTX_HARDWARE_FOLDERS] = []string{"downloaded_board_manager_stuff", "downloaded_hardware", filepath.Join("..", "hardware"), "hardware", "user_hardware"} + ctx := &types.Context{ + HardwareFolders: []string{"downloaded_board_manager_stuff", "downloaded_hardware", filepath.Join("..", "hardware"), "hardware", "user_hardware"}, + } commands := []types.Command{ &builder.SetupHumanLoggerIfMissing{}, diff --git a/src/arduino.cc/builder/test/includes_finder_with_gcc_test.go b/src/arduino.cc/builder/test/includes_finder_with_gcc_test.go index d6954dd1..ac058ac8 100644 --- a/src/arduino.cc/builder/test/includes_finder_with_gcc_test.go +++ b/src/arduino.cc/builder/test/includes_finder_with_gcc_test.go @@ -45,16 +45,17 @@ func TestIncludesFinderWithGCC(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) - ctx := &types.Context{} + ctx := &types.Context{ + HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, + ToolsFolders: []string{"downloaded_tools"}, + SketchLocation: filepath.Join("sketch2", "SketchWithIfDef.ino"), + FQBN: "arduino:avr:leonardo", + ArduinoAPIVersion: "10600", + } buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) - context[constants.CTX_HARDWARE_FOLDERS] = []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"} - context[constants.CTX_TOOLS_FOLDERS] = []string{"downloaded_tools"} - context[constants.CTX_FQBN] = "arduino:avr:leonardo" - context[constants.CTX_SKETCH_LOCATION] = filepath.Join("sketch2", "SketchWithIfDef.ino") - context[constants.CTX_BUILD_PROPERTIES_RUNTIME_IDE_VERSION] = "10600" context[constants.CTX_VERBOSE] = true commands := []types.Command{ @@ -79,18 +80,19 @@ func TestIncludesFinderWithGCCSketchWithConfig(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) - ctx := &types.Context{} + ctx := &types.Context{ + HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, + ToolsFolders: []string{"downloaded_tools"}, + BuiltInLibrariesFolders: []string{"downloaded_libraries"}, + OtherLibrariesFolders: []string{"dependent_libraries", "libraries"}, + SketchLocation: filepath.Join("sketch_with_config", "sketch_with_config.ino"), + FQBN: "arduino:avr:leonardo", + ArduinoAPIVersion: "10600", + } buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) - context[constants.CTX_HARDWARE_FOLDERS] = []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"} - context[constants.CTX_TOOLS_FOLDERS] = []string{"downloaded_tools"} - context[constants.CTX_BUILT_IN_LIBRARIES_FOLDERS] = []string{"downloaded_libraries"} - context[constants.CTX_OTHER_LIBRARIES_FOLDERS] = []string{"dependent_libraries", "libraries"} - context[constants.CTX_FQBN] = "arduino:avr:leonardo" - context[constants.CTX_SKETCH_LOCATION] = filepath.Join("sketch_with_config", "sketch_with_config.ino") - context[constants.CTX_BUILD_PROPERTIES_RUNTIME_IDE_VERSION] = "10600" context[constants.CTX_VERBOSE] = true commands := []types.Command{ @@ -122,17 +124,18 @@ func TestIncludesFinderWithGCCSketchWithDependendLibraries(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) - ctx := &types.Context{} + ctx := &types.Context{ + HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, + ToolsFolders: []string{"downloaded_tools"}, + OtherLibrariesFolders: []string{"dependent_libraries"}, + SketchLocation: filepath.Join("sketch_with_dependend_libraries", "sketch.ino"), + FQBN: "arduino:avr:leonardo", + ArduinoAPIVersion: "10600", + } buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) - context[constants.CTX_HARDWARE_FOLDERS] = []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"} - context[constants.CTX_TOOLS_FOLDERS] = []string{"downloaded_tools"} - context[constants.CTX_OTHER_LIBRARIES_FOLDERS] = []string{"dependent_libraries"} - context[constants.CTX_FQBN] = "arduino:avr:leonardo" - context[constants.CTX_SKETCH_LOCATION] = filepath.Join("sketch_with_dependend_libraries", "sketch.ino") - context[constants.CTX_BUILD_PROPERTIES_RUNTIME_IDE_VERSION] = "10600" context[constants.CTX_VERBOSE] = true commands := []types.Command{ @@ -174,18 +177,19 @@ func TestIncludesFinderWithGCCSketchWithThatChecksIfSPIHasTransactions(t *testin DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) - ctx := &types.Context{} + ctx := &types.Context{ + HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, + ToolsFolders: []string{"downloaded_tools"}, + BuiltInLibrariesFolders: []string{"downloaded_libraries"}, + OtherLibrariesFolders: []string{"dependent_libraries", "libraries"}, + SketchLocation: filepath.Join("sketch_that_checks_if_SPI_has_transactions", "sketch.ino"), + FQBN: "arduino:avr:leonardo", + ArduinoAPIVersion: "10600", + } buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) - context[constants.CTX_HARDWARE_FOLDERS] = []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"} - context[constants.CTX_TOOLS_FOLDERS] = []string{"downloaded_tools"} - context[constants.CTX_BUILT_IN_LIBRARIES_FOLDERS] = []string{"downloaded_libraries"} - context[constants.CTX_OTHER_LIBRARIES_FOLDERS] = []string{"dependent_libraries", "libraries"} - context[constants.CTX_FQBN] = "arduino:avr:leonardo" - context[constants.CTX_SKETCH_LOCATION] = filepath.Join("sketch_that_checks_if_SPI_has_transactions", "sketch.ino") - context[constants.CTX_BUILD_PROPERTIES_RUNTIME_IDE_VERSION] = "10600" context[constants.CTX_VERBOSE] = true commands := []types.Command{ @@ -217,18 +221,19 @@ func TestIncludesFinderWithGCCSketchWithThatChecksIfSPIHasTransactionsAndInclude DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) - ctx := &types.Context{} + ctx := &types.Context{ + HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, + ToolsFolders: []string{"downloaded_tools"}, + BuiltInLibrariesFolders: []string{"downloaded_libraries"}, + OtherLibrariesFolders: []string{"dependent_libraries", "libraries"}, + SketchLocation: filepath.Join("sketch_that_checks_if_SPI_has_transactions_and_includes_missing_Ethernet", "sketch.ino"), + FQBN: "arduino:avr:leonardo", + ArduinoAPIVersion: "10600", + } buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) - context[constants.CTX_HARDWARE_FOLDERS] = []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"} - context[constants.CTX_TOOLS_FOLDERS] = []string{"downloaded_tools"} - context[constants.CTX_BUILT_IN_LIBRARIES_FOLDERS] = []string{"downloaded_libraries"} - context[constants.CTX_OTHER_LIBRARIES_FOLDERS] = []string{"dependent_libraries", "libraries"} - context[constants.CTX_FQBN] = "arduino:avr:leonardo" - context[constants.CTX_SKETCH_LOCATION] = filepath.Join("sketch_that_checks_if_SPI_has_transactions_and_includes_missing_Ethernet", "sketch.ino") - context[constants.CTX_BUILD_PROPERTIES_RUNTIME_IDE_VERSION] = "10600" context[constants.CTX_VERBOSE] = true commands := []types.Command{ diff --git a/src/arduino.cc/builder/test/includes_finder_with_regexp_test.go b/src/arduino.cc/builder/test/includes_finder_with_regexp_test.go index d572eca9..74b45e52 100644 --- a/src/arduino.cc/builder/test/includes_finder_with_regexp_test.go +++ b/src/arduino.cc/builder/test/includes_finder_with_regexp_test.go @@ -44,16 +44,17 @@ func TestIncludesFinderWithRegExpCoanOutput(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) - ctx := &types.Context{} + ctx := &types.Context{ + HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, + ToolsFolders: []string{"downloaded_tools"}, + SketchLocation: filepath.Join("sketch2", "SketchWithIfDef.ino"), + FQBN: "arduino:avr:leonardo", + ArduinoAPIVersion: "10600", + } buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) - context[constants.CTX_HARDWARE_FOLDERS] = []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"} - context[constants.CTX_TOOLS_FOLDERS] = []string{"downloaded_tools"} - context[constants.CTX_FQBN] = "arduino:avr:leonardo" - context[constants.CTX_SKETCH_LOCATION] = filepath.Join("sketch2", "SketchWithIfDef.ino") - context[constants.CTX_BUILD_PROPERTIES_RUNTIME_IDE_VERSION] = "10600" context[constants.CTX_VERBOSE] = true commands := []types.Command{ diff --git a/src/arduino.cc/builder/test/includes_to_include_folders_test.go b/src/arduino.cc/builder/test/includes_to_include_folders_test.go index 49108ba8..20fc73cf 100644 --- a/src/arduino.cc/builder/test/includes_to_include_folders_test.go +++ b/src/arduino.cc/builder/test/includes_to_include_folders_test.go @@ -44,18 +44,19 @@ func TestIncludesToIncludeFolders(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) - ctx := &types.Context{} + ctx := &types.Context{ + HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, + ToolsFolders: []string{"downloaded_tools"}, + BuiltInLibrariesFolders: []string{"downloaded_libraries"}, + OtherLibrariesFolders: []string{"libraries"}, + SketchLocation: filepath.Join("downloaded_libraries", "Bridge", "examples", "Bridge", "Bridge.ino"), + FQBN: "arduino:avr:leonardo", + ArduinoAPIVersion: "10600", + } buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) - context[constants.CTX_HARDWARE_FOLDERS] = []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"} - context[constants.CTX_TOOLS_FOLDERS] = []string{"downloaded_tools"} - context[constants.CTX_FQBN] = "arduino:avr:leonardo" - context[constants.CTX_SKETCH_LOCATION] = filepath.Join("downloaded_libraries", "Bridge", "examples", "Bridge", "Bridge.ino") - context[constants.CTX_BUILD_PROPERTIES_RUNTIME_IDE_VERSION] = "10600" - context[constants.CTX_BUILT_IN_LIBRARIES_FOLDERS] = []string{"downloaded_libraries"} - context[constants.CTX_OTHER_LIBRARIES_FOLDERS] = []string{"libraries"} context[constants.CTX_VERBOSE] = true commands := []types.Command{ @@ -86,18 +87,19 @@ func TestIncludesToIncludeFoldersSketchWithIfDef(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) - ctx := &types.Context{} + ctx := &types.Context{ + HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, + ToolsFolders: []string{"downloaded_tools"}, + BuiltInLibrariesFolders: []string{"downloaded_libraries"}, + OtherLibrariesFolders: []string{"libraries"}, + SketchLocation: filepath.Join("sketch2", "SketchWithIfDef.ino"), + FQBN: "arduino:avr:leonardo", + ArduinoAPIVersion: "10600", + } buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) - context[constants.CTX_HARDWARE_FOLDERS] = []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"} - context[constants.CTX_TOOLS_FOLDERS] = []string{"downloaded_tools"} - context[constants.CTX_FQBN] = "arduino:avr:leonardo" - context[constants.CTX_SKETCH_LOCATION] = filepath.Join("sketch2", "SketchWithIfDef.ino") - context[constants.CTX_BUILD_PROPERTIES_RUNTIME_IDE_VERSION] = "10600" - context[constants.CTX_BUILT_IN_LIBRARIES_FOLDERS] = []string{"downloaded_libraries"} - context[constants.CTX_OTHER_LIBRARIES_FOLDERS] = []string{"libraries"} context[constants.CTX_VERBOSE] = true commands := []types.Command{ @@ -126,18 +128,19 @@ func TestIncludesToIncludeFoldersIRremoteLibrary(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) - ctx := &types.Context{} + ctx := &types.Context{ + HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, + ToolsFolders: []string{"downloaded_tools"}, + BuiltInLibrariesFolders: []string{"downloaded_libraries"}, + OtherLibrariesFolders: []string{"libraries"}, + SketchLocation: filepath.Join("sketch9", "sketch.ino"), + FQBN: "arduino:avr:leonardo", + ArduinoAPIVersion: "10600", + } buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) - context[constants.CTX_HARDWARE_FOLDERS] = []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"} - context[constants.CTX_TOOLS_FOLDERS] = []string{"downloaded_tools"} - context[constants.CTX_FQBN] = "arduino:avr:leonardo" - context[constants.CTX_SKETCH_LOCATION] = filepath.Join("sketch9", "sketch.ino") - context[constants.CTX_BUILD_PROPERTIES_RUNTIME_IDE_VERSION] = "10600" - context[constants.CTX_BUILT_IN_LIBRARIES_FOLDERS] = []string{"downloaded_libraries"} - context[constants.CTX_OTHER_LIBRARIES_FOLDERS] = []string{"libraries"} context[constants.CTX_VERBOSE] = true commands := []types.Command{ @@ -171,18 +174,19 @@ func TestIncludesToIncludeFoldersANewLibrary(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) - ctx := &types.Context{} + ctx := &types.Context{ + HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, + ToolsFolders: []string{"downloaded_tools"}, + BuiltInLibrariesFolders: []string{"downloaded_libraries"}, + OtherLibrariesFolders: []string{"libraries"}, + SketchLocation: filepath.Join("sketch10", "sketch.ino"), + FQBN: "arduino:avr:leonardo", + ArduinoAPIVersion: "10600", + } buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) - context[constants.CTX_HARDWARE_FOLDERS] = []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"} - context[constants.CTX_TOOLS_FOLDERS] = []string{"downloaded_tools"} - context[constants.CTX_FQBN] = "arduino:avr:leonardo" - context[constants.CTX_SKETCH_LOCATION] = filepath.Join("sketch10", "sketch.ino") - context[constants.CTX_BUILD_PROPERTIES_RUNTIME_IDE_VERSION] = "10600" - context[constants.CTX_BUILT_IN_LIBRARIES_FOLDERS] = []string{"downloaded_libraries"} - context[constants.CTX_OTHER_LIBRARIES_FOLDERS] = []string{"libraries"} context[constants.CTX_VERBOSE] = true commands := []types.Command{ @@ -216,17 +220,18 @@ func TestIncludesToIncludeFoldersDuplicateLibs(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) - ctx := &types.Context{} + ctx := &types.Context{ + HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware", "user_hardware"}, + ToolsFolders: []string{"downloaded_tools"}, + BuiltInLibrariesFolders: []string{"downloaded_libraries"}, + SketchLocation: filepath.Join("user_hardware", "my_avr_platform", "avr", "libraries", "SPI", "examples", "BarometricPressureSensor", "BarometricPressureSensor.ino"), + FQBN: "my_avr_platform:avr:custom_yun", + ArduinoAPIVersion: "10600", + } buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) - context[constants.CTX_HARDWARE_FOLDERS] = []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware", "user_hardware"} - context[constants.CTX_TOOLS_FOLDERS] = []string{"downloaded_tools"} - context[constants.CTX_FQBN] = "my_avr_platform:avr:custom_yun" - context[constants.CTX_SKETCH_LOCATION] = filepath.Join("user_hardware", "my_avr_platform", "avr", "libraries", "SPI", "examples", "BarometricPressureSensor", "BarometricPressureSensor.ino") - context[constants.CTX_BUILD_PROPERTIES_RUNTIME_IDE_VERSION] = "10600" - context[constants.CTX_BUILT_IN_LIBRARIES_FOLDERS] = []string{"downloaded_libraries"} context[constants.CTX_VERBOSE] = true commands := []types.Command{ @@ -259,18 +264,19 @@ func TestIncludesToIncludeFoldersDuplicateLibsWithConflictingLibsOutsideOfPlatfo DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) - ctx := &types.Context{} + ctx := &types.Context{ + HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware", "user_hardware"}, + ToolsFolders: []string{"downloaded_tools"}, + BuiltInLibrariesFolders: []string{"downloaded_libraries"}, + OtherLibrariesFolders: []string{"libraries"}, + SketchLocation: filepath.Join("user_hardware", "my_avr_platform", "avr", "libraries", "SPI", "examples", "BarometricPressureSensor", "BarometricPressureSensor.ino"), + FQBN: "my_avr_platform:avr:custom_yun", + ArduinoAPIVersion: "10600", + } buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) - context[constants.CTX_HARDWARE_FOLDERS] = []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware", "user_hardware"} - context[constants.CTX_TOOLS_FOLDERS] = []string{"downloaded_tools"} - context[constants.CTX_FQBN] = "my_avr_platform:avr:custom_yun" - context[constants.CTX_SKETCH_LOCATION] = filepath.Join("user_hardware", "my_avr_platform", "avr", "libraries", "SPI", "examples", "BarometricPressureSensor", "BarometricPressureSensor.ino") - context[constants.CTX_BUILD_PROPERTIES_RUNTIME_IDE_VERSION] = "10600" - context[constants.CTX_BUILT_IN_LIBRARIES_FOLDERS] = []string{"downloaded_libraries"} - context[constants.CTX_OTHER_LIBRARIES_FOLDERS] = []string{"libraries"} context[constants.CTX_VERBOSE] = true commands := []types.Command{ @@ -303,18 +309,19 @@ func TestIncludesToIncludeFoldersDuplicateLibs2(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) - ctx := &types.Context{} + ctx := &types.Context{ + HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware", "downloaded_board_manager_stuff"}, + ToolsFolders: []string{"downloaded_tools", "downloaded_board_manager_stuff"}, + BuiltInLibrariesFolders: []string{"downloaded_libraries"}, + OtherLibrariesFolders: []string{"libraries"}, + SketchLocation: filepath.Join("sketch_usbhost", "sketch_usbhost.ino"), + FQBN: "arduino:samd:arduino_zero_native", + ArduinoAPIVersion: "10600", + } buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) - context[constants.CTX_HARDWARE_FOLDERS] = []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware", "downloaded_board_manager_stuff"} - context[constants.CTX_TOOLS_FOLDERS] = []string{"downloaded_tools", "downloaded_board_manager_stuff"} - context[constants.CTX_FQBN] = "arduino:samd:arduino_zero_native" - context[constants.CTX_SKETCH_LOCATION] = filepath.Join("sketch_usbhost", "sketch_usbhost.ino") - context[constants.CTX_BUILD_PROPERTIES_RUNTIME_IDE_VERSION] = "10600" - context[constants.CTX_BUILT_IN_LIBRARIES_FOLDERS] = []string{"downloaded_libraries"} - context[constants.CTX_OTHER_LIBRARIES_FOLDERS] = []string{"libraries"} context[constants.CTX_VERBOSE] = true commands := []types.Command{ diff --git a/src/arduino.cc/builder/test/libraries_loader_test.go b/src/arduino.cc/builder/test/libraries_loader_test.go index f42b3862..d865fa03 100644 --- a/src/arduino.cc/builder/test/libraries_loader_test.go +++ b/src/arduino.cc/builder/test/libraries_loader_test.go @@ -43,12 +43,12 @@ func TestLoadLibrariesAVR(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) - ctx := &types.Context{} - - context[constants.CTX_HARDWARE_FOLDERS] = []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"} - context[constants.CTX_FQBN] = "arduino:avr:leonardo" - context[constants.CTX_BUILT_IN_LIBRARIES_FOLDERS] = []string{"downloaded_libraries"} - context[constants.CTX_OTHER_LIBRARIES_FOLDERS] = []string{"libraries"} + ctx := &types.Context{ + HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, + BuiltInLibrariesFolders: []string{"downloaded_libraries"}, + OtherLibrariesFolders: []string{"libraries"}, + FQBN: "arduino:avr:leonardo", + } commands := []types.Command{ &builder.SetupHumanLoggerIfMissing{}, @@ -63,7 +63,7 @@ func TestLoadLibrariesAVR(t *testing.T) { NoError(t, err) } - librariesFolders := context[constants.CTX_LIBRARIES_FOLDERS].([]string) + librariesFolders := ctx.LibrariesFolders require.Equal(t, 3, len(librariesFolders)) require.Equal(t, Abs(t, filepath.Join("downloaded_libraries")), librariesFolders[0]) require.Equal(t, Abs(t, filepath.Join("downloaded_hardware", "arduino", "avr", "libraries")), librariesFolders[1]) @@ -154,12 +154,12 @@ func TestLoadLibrariesSAM(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) - ctx := &types.Context{} - - context[constants.CTX_HARDWARE_FOLDERS] = []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"} - context[constants.CTX_FQBN] = "arduino:sam:arduino_due_x_dbg" - context[constants.CTX_BUILT_IN_LIBRARIES_FOLDERS] = []string{"downloaded_libraries"} - context[constants.CTX_OTHER_LIBRARIES_FOLDERS] = []string{"libraries"} + ctx := &types.Context{ + HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, + BuiltInLibrariesFolders: []string{"downloaded_libraries"}, + OtherLibrariesFolders: []string{"libraries"}, + FQBN: "arduino:sam:arduino_due_x_dbg", + } commands := []types.Command{ &builder.SetupHumanLoggerIfMissing{}, @@ -174,7 +174,7 @@ func TestLoadLibrariesSAM(t *testing.T) { NoError(t, err) } - librariesFolders := context[constants.CTX_LIBRARIES_FOLDERS].([]string) + librariesFolders := ctx.LibrariesFolders require.Equal(t, 3, len(librariesFolders)) require.Equal(t, Abs(t, filepath.Join("downloaded_libraries")), librariesFolders[0]) require.Equal(t, Abs(t, filepath.Join("downloaded_hardware", "arduino", "sam", "libraries")), librariesFolders[1]) @@ -239,12 +239,12 @@ func TestLoadLibrariesAVRNoDuplicateLibrariesFolders(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) - ctx := &types.Context{} - - context[constants.CTX_HARDWARE_FOLDERS] = []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"} - context[constants.CTX_FQBN] = "arduino:avr:leonardo" - context[constants.CTX_BUILT_IN_LIBRARIES_FOLDERS] = []string{"downloaded_libraries"} - context[constants.CTX_OTHER_LIBRARIES_FOLDERS] = []string{"libraries", filepath.Join("downloaded_hardware", "arduino", "avr", "libraries")} + ctx := &types.Context{ + HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, + BuiltInLibrariesFolders: []string{"downloaded_libraries"}, + OtherLibrariesFolders: []string{"libraries", filepath.Join("downloaded_hardware", "arduino", "avr", "libraries")}, + FQBN: "arduino:avr:leonardo", + } commands := []types.Command{ &builder.SetupHumanLoggerIfMissing{}, @@ -259,7 +259,7 @@ func TestLoadLibrariesAVRNoDuplicateLibrariesFolders(t *testing.T) { NoError(t, err) } - librariesFolders := context[constants.CTX_LIBRARIES_FOLDERS].([]string) + librariesFolders := ctx.LibrariesFolders require.Equal(t, 3, len(librariesFolders)) require.Equal(t, Abs(t, filepath.Join("downloaded_libraries")), librariesFolders[0]) require.Equal(t, Abs(t, filepath.Join("downloaded_hardware", "arduino", "avr", "libraries")), librariesFolders[1]) @@ -270,12 +270,12 @@ func TestLoadLibrariesMyAVRPlatform(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) - ctx := &types.Context{} - - context[constants.CTX_HARDWARE_FOLDERS] = []string{filepath.Join("..", "hardware"), "hardware", "user_hardware", "downloaded_hardware"} - context[constants.CTX_FQBN] = "my_avr_platform:avr:custom_yun" - context[constants.CTX_BUILT_IN_LIBRARIES_FOLDERS] = []string{"downloaded_libraries"} - context[constants.CTX_OTHER_LIBRARIES_FOLDERS] = []string{"libraries", filepath.Join("downloaded_hardware", "arduino", "avr", "libraries")} + ctx := &types.Context{ + HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "user_hardware", "downloaded_hardware"}, + BuiltInLibrariesFolders: []string{"downloaded_libraries"}, + OtherLibrariesFolders: []string{"libraries", filepath.Join("downloaded_hardware", "arduino", "avr", "libraries")}, + FQBN: "my_avr_platform:avr:custom_yun", + } commands := []types.Command{ &builder.SetupHumanLoggerIfMissing{}, @@ -290,7 +290,7 @@ func TestLoadLibrariesMyAVRPlatform(t *testing.T) { NoError(t, err) } - librariesFolders := context[constants.CTX_LIBRARIES_FOLDERS].([]string) + librariesFolders := ctx.LibrariesFolders require.Equal(t, 4, len(librariesFolders)) require.Equal(t, Abs(t, filepath.Join("downloaded_libraries")), librariesFolders[0]) require.Equal(t, Abs(t, filepath.Join("downloaded_hardware", "arduino", "avr", "libraries")), librariesFolders[1]) diff --git a/src/arduino.cc/builder/test/load_vid_pid_specific_properties_test.go b/src/arduino.cc/builder/test/load_vid_pid_specific_properties_test.go index 24df54f2..aeb3c0a5 100644 --- a/src/arduino.cc/builder/test/load_vid_pid_specific_properties_test.go +++ b/src/arduino.cc/builder/test/load_vid_pid_specific_properties_test.go @@ -44,17 +44,17 @@ func TestLoadVIDPIDSpecificPropertiesWhenNoVIDPIDAreProvided(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) - ctx := &types.Context{} + ctx := &types.Context{ + HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, + ToolsFolders: []string{"downloaded_tools", "./tools_builtin"}, + SketchLocation: filepath.Join("sketch1", "sketch.ino"), + FQBN: "arduino:avr:micro", + ArduinoAPIVersion: "10600", + } buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) - context[constants.CTX_BUILD_PROPERTIES_RUNTIME_IDE_VERSION] = "10600" - context[constants.CTX_HARDWARE_FOLDERS] = []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"} - context[constants.CTX_TOOLS_FOLDERS] = []string{"downloaded_tools", "./tools_builtin"} - context[constants.CTX_FQBN] = "arduino:avr:micro" - context[constants.CTX_SKETCH_LOCATION] = filepath.Join("sketch1", "sketch.ino") - commands := []types.Command{ &builder.SetupHumanLoggerIfMissing{}, &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, @@ -76,16 +76,17 @@ func TestLoadVIDPIDSpecificProperties(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) - ctx := &types.Context{} + ctx := &types.Context{ + HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, + ToolsFolders: []string{"downloaded_tools", "./tools_builtin"}, + SketchLocation: filepath.Join("sketch1", "sketch.ino"), + FQBN: "arduino:avr:micro", + ArduinoAPIVersion: "10600", + } buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) - context[constants.CTX_BUILD_PROPERTIES_RUNTIME_IDE_VERSION] = "10600" - context[constants.CTX_HARDWARE_FOLDERS] = []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"} - context[constants.CTX_TOOLS_FOLDERS] = []string{"downloaded_tools", "./tools_builtin"} - context[constants.CTX_FQBN] = "arduino:avr:micro" - context[constants.CTX_SKETCH_LOCATION] = filepath.Join("sketch1", "sketch.ino") context[constants.CTX_VIDPID] = "0x2341_0x0237" commands := []types.Command{ diff --git a/src/arduino.cc/builder/test/merge_sketch_with_bootloader_test.go b/src/arduino.cc/builder/test/merge_sketch_with_bootloader_test.go index 992ddb76..a913ec48 100644 --- a/src/arduino.cc/builder/test/merge_sketch_with_bootloader_test.go +++ b/src/arduino.cc/builder/test/merge_sketch_with_bootloader_test.go @@ -47,19 +47,19 @@ func TestMergeSketchWithBootloader(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) - ctx := &types.Context{} + ctx := &types.Context{ + HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, + ToolsFolders: []string{"downloaded_tools"}, + BuiltInLibrariesFolders: []string{"downloaded_libraries"}, + OtherLibrariesFolders: []string{"libraries"}, + SketchLocation: filepath.Join("sketch1", "sketch.ino"), + FQBN: "arduino:avr:uno", + ArduinoAPIVersion: "10600", + } buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) - context[constants.CTX_HARDWARE_FOLDERS] = []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"} - context[constants.CTX_TOOLS_FOLDERS] = []string{"downloaded_tools"} - context[constants.CTX_FQBN] = "arduino:avr:uno" - context[constants.CTX_BUILT_IN_LIBRARIES_FOLDERS] = []string{"downloaded_libraries"} - context[constants.CTX_OTHER_LIBRARIES_FOLDERS] = []string{"libraries"} - context[constants.CTX_SKETCH_LOCATION] = filepath.Join("sketch1", "sketch.ino") - context[constants.CTX_BUILD_PROPERTIES_RUNTIME_IDE_VERSION] = "10600" - err := utils.EnsureFolderExists(filepath.Join(buildPath, "sketch")) NoError(t, err) @@ -91,19 +91,19 @@ func TestMergeSketchWithBootloaderSketchInBuildPath(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) - ctx := &types.Context{} + ctx := &types.Context{ + HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, + ToolsFolders: []string{"downloaded_tools"}, + BuiltInLibrariesFolders: []string{"downloaded_libraries"}, + OtherLibrariesFolders: []string{"libraries"}, + SketchLocation: filepath.Join("sketch1", "sketch.ino"), + FQBN: "arduino:avr:uno", + ArduinoAPIVersion: "10600", + } buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) - context[constants.CTX_HARDWARE_FOLDERS] = []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"} - context[constants.CTX_TOOLS_FOLDERS] = []string{"downloaded_tools"} - context[constants.CTX_FQBN] = "arduino:avr:uno" - context[constants.CTX_BUILT_IN_LIBRARIES_FOLDERS] = []string{"downloaded_libraries"} - context[constants.CTX_OTHER_LIBRARIES_FOLDERS] = []string{"libraries"} - context[constants.CTX_SKETCH_LOCATION] = filepath.Join("sketch1", "sketch.ino") - context[constants.CTX_BUILD_PROPERTIES_RUNTIME_IDE_VERSION] = "10600" - err := utils.EnsureFolderExists(filepath.Join(buildPath, "sketch")) NoError(t, err) @@ -135,19 +135,19 @@ func TestMergeSketchWithBootloaderWhenNoBootloaderAvailable(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) - ctx := &types.Context{} + ctx := &types.Context{ + HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, + ToolsFolders: []string{"downloaded_tools"}, + BuiltInLibrariesFolders: []string{"downloaded_libraries"}, + OtherLibrariesFolders: []string{"libraries"}, + SketchLocation: filepath.Join("sketch1", "sketch.ino"), + FQBN: "arduino:avr:uno", + ArduinoAPIVersion: "10600", + } buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) - context[constants.CTX_HARDWARE_FOLDERS] = []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"} - context[constants.CTX_TOOLS_FOLDERS] = []string{"downloaded_tools"} - context[constants.CTX_FQBN] = "arduino:avr:uno" - context[constants.CTX_BUILT_IN_LIBRARIES_FOLDERS] = []string{"downloaded_libraries"} - context[constants.CTX_OTHER_LIBRARIES_FOLDERS] = []string{"libraries"} - context[constants.CTX_SKETCH_LOCATION] = filepath.Join("sketch1", "sketch.ino") - context[constants.CTX_BUILD_PROPERTIES_RUNTIME_IDE_VERSION] = "10600" - commands := []types.Command{ &builder.SetupHumanLoggerIfMissing{}, &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, @@ -175,19 +175,19 @@ func TestMergeSketchWithBootloaderPathIsParameterized(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) - ctx := &types.Context{} + ctx := &types.Context{ + HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware", "user_hardware"}, + ToolsFolders: []string{"downloaded_tools"}, + BuiltInLibrariesFolders: []string{"downloaded_libraries"}, + OtherLibrariesFolders: []string{"libraries"}, + SketchLocation: filepath.Join("sketch1", "sketch.ino"), + FQBN: "my_avr_platform:avr:mymega:cpu=atmega2560", + ArduinoAPIVersion: "10600", + } buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) - context[constants.CTX_HARDWARE_FOLDERS] = []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware", "user_hardware"} - context[constants.CTX_TOOLS_FOLDERS] = []string{"downloaded_tools"} - context[constants.CTX_FQBN] = "my_avr_platform:avr:mymega:cpu=atmega2560" - context[constants.CTX_BUILT_IN_LIBRARIES_FOLDERS] = []string{"downloaded_libraries"} - context[constants.CTX_OTHER_LIBRARIES_FOLDERS] = []string{"libraries"} - context[constants.CTX_SKETCH_LOCATION] = filepath.Join("sketch1", "sketch.ino") - context[constants.CTX_BUILD_PROPERTIES_RUNTIME_IDE_VERSION] = "10600" - err := utils.EnsureFolderExists(filepath.Join(buildPath, "sketch")) NoError(t, err) diff --git a/src/arduino.cc/builder/test/platform_keys_rewrite_loader_test.go b/src/arduino.cc/builder/test/platform_keys_rewrite_loader_test.go index 76be0706..da0b1351 100644 --- a/src/arduino.cc/builder/test/platform_keys_rewrite_loader_test.go +++ b/src/arduino.cc/builder/test/platform_keys_rewrite_loader_test.go @@ -40,8 +40,9 @@ import ( func TestLoadPlatformKeysRewrite(t *testing.T) { context := make(map[string]interface{}) - ctx := &types.Context{} - context[constants.CTX_HARDWARE_FOLDERS] = []string{"downloaded_hardware", filepath.Join("..", "hardware"), "hardware"} + ctx := &types.Context{ + HardwareFolders: []string{"downloaded_hardware", filepath.Join("..", "hardware"), "hardware"}, + } commands := []types.Command{ &builder.SetupHumanLoggerIfMissing{}, diff --git a/src/arduino.cc/builder/test/prototypes_adder_test.go b/src/arduino.cc/builder/test/prototypes_adder_test.go index 576ac75f..aa8af4c8 100644 --- a/src/arduino.cc/builder/test/prototypes_adder_test.go +++ b/src/arduino.cc/builder/test/prototypes_adder_test.go @@ -44,22 +44,23 @@ import ( func TestPrototypesAdderBridgeExample(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) + sketchLocation := filepath.Join("downloaded_libraries", "Bridge", "examples", "Bridge", "Bridge.ino") + absoluteSketchLocation := strings.Replace(Abs(t, sketchLocation), "\\", "\\\\", -1) + context := make(map[string]interface{}) - ctx := &types.Context{} + ctx := &types.Context{ + HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, + ToolsFolders: []string{"downloaded_tools"}, + BuiltInLibrariesFolders: []string{"downloaded_libraries"}, + OtherLibrariesFolders: []string{"libraries"}, + SketchLocation: sketchLocation, + FQBN: "arduino:avr:leonardo", + ArduinoAPIVersion: "10600", + } buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) - sketchLocation := filepath.Join("downloaded_libraries", "Bridge", "examples", "Bridge", "Bridge.ino") - absoluteSketchLocation := strings.Replace(Abs(t, sketchLocation), "\\", "\\\\", -1) - - context[constants.CTX_HARDWARE_FOLDERS] = []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"} - context[constants.CTX_TOOLS_FOLDERS] = []string{"downloaded_tools"} - context[constants.CTX_FQBN] = "arduino:avr:leonardo" - context[constants.CTX_SKETCH_LOCATION] = sketchLocation - context[constants.CTX_BUILD_PROPERTIES_RUNTIME_IDE_VERSION] = "10600" - context[constants.CTX_BUILT_IN_LIBRARIES_FOLDERS] = []string{"downloaded_libraries"} - context[constants.CTX_OTHER_LIBRARIES_FOLDERS] = []string{"libraries"} context[constants.CTX_VERBOSE] = true context[constants.CTX_DEBUG_LEVEL] = 10 @@ -91,18 +92,19 @@ func TestPrototypesAdderSketchWithIfDef(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) - ctx := &types.Context{} + ctx := &types.Context{ + HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, + ToolsFolders: []string{"downloaded_tools"}, + BuiltInLibrariesFolders: []string{"downloaded_libraries"}, + OtherLibrariesFolders: []string{"libraries"}, + SketchLocation: filepath.Join("sketch2", "SketchWithIfDef.ino"), + FQBN: "arduino:avr:leonardo", + ArduinoAPIVersion: "10600", + } buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) - context[constants.CTX_HARDWARE_FOLDERS] = []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"} - context[constants.CTX_TOOLS_FOLDERS] = []string{"downloaded_tools"} - context[constants.CTX_FQBN] = "arduino:avr:leonardo" - context[constants.CTX_SKETCH_LOCATION] = filepath.Join("sketch2", "SketchWithIfDef.ino") - context[constants.CTX_BUILD_PROPERTIES_RUNTIME_IDE_VERSION] = "10600" - context[constants.CTX_BUILT_IN_LIBRARIES_FOLDERS] = []string{"downloaded_libraries"} - context[constants.CTX_OTHER_LIBRARIES_FOLDERS] = []string{"libraries"} context[constants.CTX_VERBOSE] = true commands := []types.Command{ @@ -133,18 +135,19 @@ func TestPrototypesAdderBaladuino(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) - ctx := &types.Context{} + ctx := &types.Context{ + HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, + ToolsFolders: []string{"downloaded_tools"}, + BuiltInLibrariesFolders: []string{"downloaded_libraries"}, + OtherLibrariesFolders: []string{"libraries"}, + SketchLocation: filepath.Join("sketch3", "Baladuino.ino"), + FQBN: "arduino:avr:leonardo", + ArduinoAPIVersion: "10600", + } buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) - context[constants.CTX_HARDWARE_FOLDERS] = []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"} - context[constants.CTX_TOOLS_FOLDERS] = []string{"downloaded_tools"} - context[constants.CTX_FQBN] = "arduino:avr:leonardo" - context[constants.CTX_SKETCH_LOCATION] = filepath.Join("sketch3", "Baladuino.ino") - context[constants.CTX_BUILD_PROPERTIES_RUNTIME_IDE_VERSION] = "10600" - context[constants.CTX_BUILT_IN_LIBRARIES_FOLDERS] = []string{"downloaded_libraries"} - context[constants.CTX_OTHER_LIBRARIES_FOLDERS] = []string{"libraries"} context[constants.CTX_VERBOSE] = true commands := []types.Command{ @@ -175,18 +178,19 @@ func TestPrototypesAdderCharWithEscapedDoubleQuote(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) - ctx := &types.Context{} + ctx := &types.Context{ + HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, + ToolsFolders: []string{"downloaded_tools"}, + BuiltInLibrariesFolders: []string{"downloaded_libraries"}, + OtherLibrariesFolders: []string{"libraries"}, + SketchLocation: filepath.Join("sketch4", "CharWithEscapedDoubleQuote.ino"), + FQBN: "arduino:avr:leonardo", + ArduinoAPIVersion: "10600", + } buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) - context[constants.CTX_HARDWARE_FOLDERS] = []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"} - context[constants.CTX_TOOLS_FOLDERS] = []string{"downloaded_tools"} - context[constants.CTX_FQBN] = "arduino:avr:leonardo" - context[constants.CTX_SKETCH_LOCATION] = filepath.Join("sketch4", "CharWithEscapedDoubleQuote.ino") - context[constants.CTX_BUILD_PROPERTIES_RUNTIME_IDE_VERSION] = "10600" - context[constants.CTX_BUILT_IN_LIBRARIES_FOLDERS] = []string{"downloaded_libraries"} - context[constants.CTX_OTHER_LIBRARIES_FOLDERS] = []string{"libraries"} context[constants.CTX_VERBOSE] = true commands := []types.Command{ @@ -217,18 +221,19 @@ func TestPrototypesAdderIncludeBetweenMultilineComment(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) - ctx := &types.Context{} + ctx := &types.Context{ + HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, + ToolsFolders: []string{"downloaded_tools"}, + BuiltInLibrariesFolders: []string{"downloaded_libraries"}, + OtherLibrariesFolders: []string{"libraries"}, + SketchLocation: filepath.Join("sketch5", "IncludeBetweenMultilineComment.ino"), + FQBN: "arduino:sam:arduino_due_x_dbg", + ArduinoAPIVersion: "10600", + } buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) - context[constants.CTX_HARDWARE_FOLDERS] = []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"} - context[constants.CTX_TOOLS_FOLDERS] = []string{"downloaded_tools"} - context[constants.CTX_FQBN] = "arduino:sam:arduino_due_x_dbg" - context[constants.CTX_SKETCH_LOCATION] = filepath.Join("sketch5", "IncludeBetweenMultilineComment.ino") - context[constants.CTX_BUILD_PROPERTIES_RUNTIME_IDE_VERSION] = "10600" - context[constants.CTX_BUILT_IN_LIBRARIES_FOLDERS] = []string{"downloaded_libraries"} - context[constants.CTX_OTHER_LIBRARIES_FOLDERS] = []string{"libraries"} context[constants.CTX_VERBOSE] = true commands := []types.Command{ @@ -259,18 +264,19 @@ func TestPrototypesAdderLineContinuations(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) - ctx := &types.Context{} + ctx := &types.Context{ + HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, + ToolsFolders: []string{"downloaded_tools"}, + BuiltInLibrariesFolders: []string{"downloaded_libraries"}, + OtherLibrariesFolders: []string{"libraries"}, + SketchLocation: filepath.Join("sketch6", "/LineContinuations.ino"), + FQBN: "arduino:avr:leonardo", + ArduinoAPIVersion: "10600", + } buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) - context[constants.CTX_HARDWARE_FOLDERS] = []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"} - context[constants.CTX_TOOLS_FOLDERS] = []string{"downloaded_tools"} - context[constants.CTX_FQBN] = "arduino:avr:leonardo" - context[constants.CTX_SKETCH_LOCATION] = filepath.Join("sketch6", "/LineContinuations.ino") - context[constants.CTX_BUILD_PROPERTIES_RUNTIME_IDE_VERSION] = "10600" - context[constants.CTX_BUILT_IN_LIBRARIES_FOLDERS] = []string{"downloaded_libraries"} - context[constants.CTX_OTHER_LIBRARIES_FOLDERS] = []string{"libraries"} context[constants.CTX_VERBOSE] = true commands := []types.Command{ @@ -301,18 +307,19 @@ func TestPrototypesAdderStringWithComment(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) - ctx := &types.Context{} + ctx := &types.Context{ + HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, + ToolsFolders: []string{"downloaded_tools"}, + BuiltInLibrariesFolders: []string{"downloaded_libraries"}, + OtherLibrariesFolders: []string{"libraries"}, + SketchLocation: filepath.Join("sketch7", "StringWithComment.ino"), + FQBN: "arduino:avr:leonardo", + ArduinoAPIVersion: "10600", + } buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) - context[constants.CTX_HARDWARE_FOLDERS] = []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"} - context[constants.CTX_TOOLS_FOLDERS] = []string{"downloaded_tools"} - context[constants.CTX_FQBN] = "arduino:avr:leonardo" - context[constants.CTX_SKETCH_LOCATION] = filepath.Join("sketch7", "StringWithComment.ino") - context[constants.CTX_BUILD_PROPERTIES_RUNTIME_IDE_VERSION] = "10600" - context[constants.CTX_BUILT_IN_LIBRARIES_FOLDERS] = []string{"downloaded_libraries"} - context[constants.CTX_OTHER_LIBRARIES_FOLDERS] = []string{"libraries"} context[constants.CTX_VERBOSE] = true commands := []types.Command{ @@ -343,18 +350,19 @@ func TestPrototypesAdderSketchWithStruct(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) - ctx := &types.Context{} + ctx := &types.Context{ + HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, + ToolsFolders: []string{"downloaded_tools"}, + BuiltInLibrariesFolders: []string{"downloaded_libraries"}, + OtherLibrariesFolders: []string{"libraries"}, + SketchLocation: filepath.Join("sketch8", "SketchWithStruct.ino"), + FQBN: "arduino:avr:leonardo", + ArduinoAPIVersion: "10600", + } buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) - context[constants.CTX_HARDWARE_FOLDERS] = []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"} - context[constants.CTX_TOOLS_FOLDERS] = []string{"downloaded_tools"} - context[constants.CTX_FQBN] = "arduino:avr:leonardo" - context[constants.CTX_SKETCH_LOCATION] = filepath.Join("sketch8", "SketchWithStruct.ino") - context[constants.CTX_BUILD_PROPERTIES_RUNTIME_IDE_VERSION] = "10600" - context[constants.CTX_BUILT_IN_LIBRARIES_FOLDERS] = []string{"downloaded_libraries"} - context[constants.CTX_OTHER_LIBRARIES_FOLDERS] = []string{"libraries"} context[constants.CTX_VERBOSE] = true commands := []types.Command{ @@ -389,22 +397,23 @@ func TestPrototypesAdderSketchWithStruct(t *testing.T) { func TestPrototypesAdderSketchWithConfig(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) + sketchLocation := filepath.Join("sketch_with_config", "sketch_with_config.ino") + absoluteSketchLocation := strings.Replace(Abs(t, sketchLocation), "\\", "\\\\", -1) + context := make(map[string]interface{}) - ctx := &types.Context{} + ctx := &types.Context{ + HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, + ToolsFolders: []string{"downloaded_tools"}, + BuiltInLibrariesFolders: []string{"downloaded_libraries"}, + OtherLibrariesFolders: []string{"libraries"}, + SketchLocation: sketchLocation, + FQBN: "arduino:avr:leonardo", + ArduinoAPIVersion: "10600", + } buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) - sketchLocation := filepath.Join("sketch_with_config", "sketch_with_config.ino") - absoluteSketchLocation := strings.Replace(Abs(t, sketchLocation), "\\", "\\\\", -1) - - context[constants.CTX_HARDWARE_FOLDERS] = []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"} - context[constants.CTX_TOOLS_FOLDERS] = []string{"downloaded_tools"} - context[constants.CTX_FQBN] = "arduino:avr:leonardo" - context[constants.CTX_SKETCH_LOCATION] = sketchLocation - context[constants.CTX_BUILD_PROPERTIES_RUNTIME_IDE_VERSION] = "10600" - context[constants.CTX_BUILT_IN_LIBRARIES_FOLDERS] = []string{"downloaded_libraries"} - context[constants.CTX_OTHER_LIBRARIES_FOLDERS] = []string{"libraries"} context[constants.CTX_VERBOSE] = true commands := []types.Command{ @@ -437,22 +446,23 @@ func TestPrototypesAdderSketchWithConfig(t *testing.T) { func TestPrototypesAdderSketchNoFunctionsTwoFiles(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) + sketchLocation := filepath.Join("sketch_no_functions_two_files", "main.ino") + absoluteSketchLocation := strings.Replace(Abs(t, sketchLocation), "\\", "\\\\", -1) + context := make(map[string]interface{}) - ctx := &types.Context{} + ctx := &types.Context{ + HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, + ToolsFolders: []string{"downloaded_tools"}, + BuiltInLibrariesFolders: []string{"downloaded_libraries"}, + OtherLibrariesFolders: []string{"libraries"}, + SketchLocation: filepath.Join("sketch_no_functions_two_files", "main.ino"), + FQBN: "arduino:avr:leonardo", + ArduinoAPIVersion: "10600", + } buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) - sketchLocation := filepath.Join("sketch_no_functions_two_files", "main.ino") - absoluteSketchLocation := strings.Replace(Abs(t, sketchLocation), "\\", "\\\\", -1) - - context[constants.CTX_HARDWARE_FOLDERS] = []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"} - context[constants.CTX_TOOLS_FOLDERS] = []string{"downloaded_tools"} - context[constants.CTX_FQBN] = "arduino:avr:leonardo" - context[constants.CTX_SKETCH_LOCATION] = filepath.Join("sketch_no_functions_two_files", "main.ino") - context[constants.CTX_BUILD_PROPERTIES_RUNTIME_IDE_VERSION] = "10600" - context[constants.CTX_BUILT_IN_LIBRARIES_FOLDERS] = []string{"downloaded_libraries"} - context[constants.CTX_OTHER_LIBRARIES_FOLDERS] = []string{"libraries"} context[constants.CTX_VERBOSE] = true commands := []types.Command{ @@ -483,7 +493,15 @@ func TestPrototypesAdderSketchNoFunctions(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) - ctx := &types.Context{} + ctx := &types.Context{ + HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, + ToolsFolders: []string{"downloaded_tools"}, + BuiltInLibrariesFolders: []string{"downloaded_libraries"}, + OtherLibrariesFolders: []string{"libraries"}, + SketchLocation: filepath.Join("sketch_no_functions", "main.ino"), + FQBN: "arduino:avr:leonardo", + ArduinoAPIVersion: "10600", + } buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) @@ -491,13 +509,6 @@ func TestPrototypesAdderSketchNoFunctions(t *testing.T) { sketchLocation := filepath.Join("sketch_no_functions", "main.ino") absoluteSketchLocation := strings.Replace(Abs(t, sketchLocation), "\\", "\\\\", -1) - context[constants.CTX_HARDWARE_FOLDERS] = []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"} - context[constants.CTX_TOOLS_FOLDERS] = []string{"downloaded_tools"} - context[constants.CTX_FQBN] = "arduino:avr:leonardo" - context[constants.CTX_SKETCH_LOCATION] = filepath.Join("sketch_no_functions", "main.ino") - context[constants.CTX_BUILD_PROPERTIES_RUNTIME_IDE_VERSION] = "10600" - context[constants.CTX_BUILT_IN_LIBRARIES_FOLDERS] = []string{"downloaded_libraries"} - context[constants.CTX_OTHER_LIBRARIES_FOLDERS] = []string{"libraries"} context[constants.CTX_VERBOSE] = true commands := []types.Command{ @@ -527,22 +538,23 @@ func TestPrototypesAdderSketchNoFunctions(t *testing.T) { func TestPrototypesAdderSketchWithDefaultArgs(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) + sketchLocation := filepath.Join("sketch_with_default_args", "sketch.ino") + absoluteSketchLocation := strings.Replace(Abs(t, sketchLocation), "\\", "\\\\", -1) + context := make(map[string]interface{}) - ctx := &types.Context{} + ctx := &types.Context{ + HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, + ToolsFolders: []string{"downloaded_tools"}, + BuiltInLibrariesFolders: []string{"downloaded_libraries"}, + OtherLibrariesFolders: []string{"libraries"}, + SketchLocation: sketchLocation, + FQBN: "arduino:avr:leonardo", + ArduinoAPIVersion: "10600", + } buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) - sketchLocation := filepath.Join("sketch_with_default_args", "sketch.ino") - absoluteSketchLocation := strings.Replace(Abs(t, sketchLocation), "\\", "\\\\", -1) - - context[constants.CTX_HARDWARE_FOLDERS] = []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"} - context[constants.CTX_TOOLS_FOLDERS] = []string{"downloaded_tools"} - context[constants.CTX_FQBN] = "arduino:avr:leonardo" - context[constants.CTX_SKETCH_LOCATION] = sketchLocation - context[constants.CTX_BUILD_PROPERTIES_RUNTIME_IDE_VERSION] = "10600" - context[constants.CTX_BUILT_IN_LIBRARIES_FOLDERS] = []string{"downloaded_libraries"} - context[constants.CTX_OTHER_LIBRARIES_FOLDERS] = []string{"libraries"} context[constants.CTX_VERBOSE] = true commands := []types.Command{ @@ -572,22 +584,23 @@ func TestPrototypesAdderSketchWithDefaultArgs(t *testing.T) { func TestPrototypesAdderSketchWithInlineFunction(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) + sketchLocation := filepath.Join("sketch_with_inline_function", "sketch.ino") + absoluteSketchLocation := strings.Replace(Abs(t, sketchLocation), "\\", "\\\\", -1) + context := make(map[string]interface{}) - ctx := &types.Context{} + ctx := &types.Context{ + HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, + ToolsFolders: []string{"downloaded_tools"}, + BuiltInLibrariesFolders: []string{"downloaded_libraries"}, + OtherLibrariesFolders: []string{"libraries"}, + SketchLocation: sketchLocation, + FQBN: "arduino:avr:leonardo", + ArduinoAPIVersion: "10600", + } buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) - sketchLocation := filepath.Join("sketch_with_inline_function", "sketch.ino") - absoluteSketchLocation := strings.Replace(Abs(t, sketchLocation), "\\", "\\\\", -1) - - context[constants.CTX_HARDWARE_FOLDERS] = []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"} - context[constants.CTX_TOOLS_FOLDERS] = []string{"downloaded_tools"} - context[constants.CTX_FQBN] = "arduino:avr:leonardo" - context[constants.CTX_SKETCH_LOCATION] = sketchLocation - context[constants.CTX_BUILD_PROPERTIES_RUNTIME_IDE_VERSION] = "10600" - context[constants.CTX_BUILT_IN_LIBRARIES_FOLDERS] = []string{"downloaded_libraries"} - context[constants.CTX_OTHER_LIBRARIES_FOLDERS] = []string{"libraries"} context[constants.CTX_VERBOSE] = true commands := []types.Command{ @@ -628,22 +641,23 @@ func TestPrototypesAdderSketchWithInlineFunction(t *testing.T) { func TestPrototypesAdderSketchWithFunctionSignatureInsideIFDEF(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) + sketchLocation := filepath.Join("sketch_with_function_signature_inside_ifdef", "sketch.ino") + absoluteSketchLocation := strings.Replace(Abs(t, sketchLocation), "\\", "\\\\", -1) + context := make(map[string]interface{}) - ctx := &types.Context{} + ctx := &types.Context{ + HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, + ToolsFolders: []string{"downloaded_tools"}, + BuiltInLibrariesFolders: []string{"downloaded_libraries"}, + OtherLibrariesFolders: []string{"libraries"}, + SketchLocation: sketchLocation, + FQBN: "arduino:avr:leonardo", + ArduinoAPIVersion: "10600", + } buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) - sketchLocation := filepath.Join("sketch_with_function_signature_inside_ifdef", "sketch.ino") - absoluteSketchLocation := strings.Replace(Abs(t, sketchLocation), "\\", "\\\\", -1) - - context[constants.CTX_HARDWARE_FOLDERS] = []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"} - context[constants.CTX_TOOLS_FOLDERS] = []string{"downloaded_tools"} - context[constants.CTX_FQBN] = "arduino:avr:leonardo" - context[constants.CTX_SKETCH_LOCATION] = sketchLocation - context[constants.CTX_BUILD_PROPERTIES_RUNTIME_IDE_VERSION] = "10600" - context[constants.CTX_BUILT_IN_LIBRARIES_FOLDERS] = []string{"downloaded_libraries"} - context[constants.CTX_OTHER_LIBRARIES_FOLDERS] = []string{"libraries"} context[constants.CTX_VERBOSE] = true commands := []types.Command{ @@ -673,22 +687,23 @@ func TestPrototypesAdderSketchWithFunctionSignatureInsideIFDEF(t *testing.T) { func TestPrototypesAdderSketchWithUSBCON(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) + sketchLocation := filepath.Join("sketch_with_usbcon", "sketch.ino") + absoluteSketchLocation := strings.Replace(Abs(t, sketchLocation), "\\", "\\\\", -1) + context := make(map[string]interface{}) - ctx := &types.Context{} + ctx := &types.Context{ + HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, + ToolsFolders: []string{"downloaded_tools"}, + OtherLibrariesFolders: []string{"libraries"}, + BuiltInLibrariesFolders: []string{"downloaded_libraries"}, + SketchLocation: sketchLocation, + FQBN: "arduino:avr:leonardo", + ArduinoAPIVersion: "10600", + } buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) - sketchLocation := filepath.Join("sketch_with_usbcon", "sketch.ino") - absoluteSketchLocation := strings.Replace(Abs(t, sketchLocation), "\\", "\\\\", -1) - - context[constants.CTX_HARDWARE_FOLDERS] = []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"} - context[constants.CTX_TOOLS_FOLDERS] = []string{"downloaded_tools"} - context[constants.CTX_FQBN] = "arduino:avr:leonardo" - context[constants.CTX_SKETCH_LOCATION] = sketchLocation - context[constants.CTX_BUILD_PROPERTIES_RUNTIME_IDE_VERSION] = "10600" - context[constants.CTX_BUILT_IN_LIBRARIES_FOLDERS] = []string{"downloaded_libraries"} - context[constants.CTX_OTHER_LIBRARIES_FOLDERS] = []string{"libraries"} context[constants.CTX_VERBOSE] = true commands := []types.Command{ @@ -718,21 +733,22 @@ func TestPrototypesAdderSketchWithUSBCON(t *testing.T) { func TestPrototypesAdderSketchWithTypename(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) + sketchLocation := filepath.Join("sketch_with_typename", "sketch.ino") + absoluteSketchLocation := strings.Replace(Abs(t, sketchLocation), "\\", "\\\\", -1) + context := make(map[string]interface{}) - ctx := &types.Context{} + ctx := &types.Context{ + HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, + LibrariesFolders: []string{"libraries", "downloaded_libraries"}, + ToolsFolders: []string{"downloaded_tools"}, + SketchLocation: sketchLocation, + FQBN: "arduino:avr:leonardo", + ArduinoAPIVersion: "10600", + } buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) - sketchLocation := filepath.Join("sketch_with_typename", "sketch.ino") - absoluteSketchLocation := strings.Replace(Abs(t, sketchLocation), "\\", "\\\\", -1) - - context[constants.CTX_HARDWARE_FOLDERS] = []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"} - context[constants.CTX_TOOLS_FOLDERS] = []string{"downloaded_tools"} - context[constants.CTX_FQBN] = "arduino:avr:leonardo" - context[constants.CTX_SKETCH_LOCATION] = sketchLocation - context[constants.CTX_BUILD_PROPERTIES_RUNTIME_IDE_VERSION] = "10600" - context[constants.CTX_LIBRARIES_FOLDERS] = []string{"libraries", "downloaded_libraries"} context[constants.CTX_VERBOSE] = true commands := []types.Command{ @@ -768,22 +784,23 @@ func TestPrototypesAdderSketchWithTypename(t *testing.T) { func TestPrototypesAdderSketchWithIfDef2(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) + sketchLocation := filepath.Join("sketch_with_ifdef", "sketch.ino") + absoluteSketchLocation := strings.Replace(Abs(t, sketchLocation), "\\", "\\\\", -1) + context := make(map[string]interface{}) - ctx := &types.Context{} + ctx := &types.Context{ + HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, + ToolsFolders: []string{"downloaded_tools"}, + BuiltInLibrariesFolders: []string{"downloaded_libraries"}, + OtherLibrariesFolders: []string{"libraries"}, + SketchLocation: sketchLocation, + FQBN: "arduino:avr:yun", + ArduinoAPIVersion: "10600", + } buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) - sketchLocation := filepath.Join("sketch_with_ifdef", "sketch.ino") - absoluteSketchLocation := strings.Replace(Abs(t, sketchLocation), "\\", "\\\\", -1) - - context[constants.CTX_HARDWARE_FOLDERS] = []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"} - context[constants.CTX_TOOLS_FOLDERS] = []string{"downloaded_tools"} - context[constants.CTX_FQBN] = "arduino:avr:yun" - context[constants.CTX_SKETCH_LOCATION] = sketchLocation - context[constants.CTX_BUILD_PROPERTIES_RUNTIME_IDE_VERSION] = "10600" - context[constants.CTX_BUILT_IN_LIBRARIES_FOLDERS] = []string{"downloaded_libraries"} - context[constants.CTX_OTHER_LIBRARIES_FOLDERS] = []string{"libraries"} context[constants.CTX_VERBOSE] = true commands := []types.Command{ @@ -816,22 +833,23 @@ func TestPrototypesAdderSketchWithIfDef2(t *testing.T) { func TestPrototypesAdderSketchWithIfDef2SAM(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) + sketchLocation := filepath.Join("sketch_with_ifdef", "sketch.ino") + absoluteSketchLocation := strings.Replace(Abs(t, sketchLocation), "\\", "\\\\", -1) + context := make(map[string]interface{}) - ctx := &types.Context{} + ctx := &types.Context{ + HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, + ToolsFolders: []string{"downloaded_tools"}, + BuiltInLibrariesFolders: []string{"downloaded_libraries"}, + OtherLibrariesFolders: []string{"libraries"}, + SketchLocation: sketchLocation, + FQBN: "arduino:sam:arduino_due_x_dbg", + ArduinoAPIVersion: "10600", + } buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) - sketchLocation := filepath.Join("sketch_with_ifdef", "sketch.ino") - absoluteSketchLocation := strings.Replace(Abs(t, sketchLocation), "\\", "\\\\", -1) - - context[constants.CTX_HARDWARE_FOLDERS] = []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"} - context[constants.CTX_TOOLS_FOLDERS] = []string{"downloaded_tools"} - context[constants.CTX_FQBN] = "arduino:sam:arduino_due_x_dbg" - context[constants.CTX_SKETCH_LOCATION] = sketchLocation - context[constants.CTX_BUILD_PROPERTIES_RUNTIME_IDE_VERSION] = "10600" - context[constants.CTX_BUILT_IN_LIBRARIES_FOLDERS] = []string{"downloaded_libraries"} - context[constants.CTX_OTHER_LIBRARIES_FOLDERS] = []string{"libraries"} context[constants.CTX_VERBOSE] = true commands := []types.Command{ @@ -864,22 +882,23 @@ func TestPrototypesAdderSketchWithIfDef2SAM(t *testing.T) { func TestPrototypesAdderSketchWithConst(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) + sketchLocation := filepath.Join("sketch_with_const", "sketch.ino") + absoluteSketchLocation := strings.Replace(Abs(t, sketchLocation), "\\", "\\\\", -1) + context := make(map[string]interface{}) - ctx := &types.Context{} + ctx := &types.Context{ + HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, + ToolsFolders: []string{"downloaded_tools"}, + BuiltInLibrariesFolders: []string{"downloaded_libraries"}, + OtherLibrariesFolders: []string{"libraries"}, + SketchLocation: sketchLocation, + FQBN: "arduino:avr:uno", + ArduinoAPIVersion: "10600", + } buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) - sketchLocation := filepath.Join("sketch_with_const", "sketch.ino") - absoluteSketchLocation := strings.Replace(Abs(t, sketchLocation), "\\", "\\\\", -1) - - context[constants.CTX_HARDWARE_FOLDERS] = []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"} - context[constants.CTX_TOOLS_FOLDERS] = []string{"downloaded_tools"} - context[constants.CTX_FQBN] = "arduino:avr:uno" - context[constants.CTX_SKETCH_LOCATION] = sketchLocation - context[constants.CTX_BUILD_PROPERTIES_RUNTIME_IDE_VERSION] = "10600" - context[constants.CTX_BUILT_IN_LIBRARIES_FOLDERS] = []string{"downloaded_libraries"} - context[constants.CTX_OTHER_LIBRARIES_FOLDERS] = []string{"libraries"} context[constants.CTX_VERBOSE] = true commands := []types.Command{ @@ -910,20 +929,19 @@ func TestPrototypesAdderSketchWithDosEol(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) - ctx := &types.Context{} + ctx := &types.Context{ + HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, + ToolsFolders: []string{"downloaded_tools"}, + BuiltInLibrariesFolders: []string{"downloaded_libraries"}, + OtherLibrariesFolders: []string{"libraries"}, + SketchLocation: filepath.Join("eol_processing", "sketch.ino"), + FQBN: "arduino:avr:uno", + ArduinoAPIVersion: "10600", + } buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) - sketchLocation := filepath.Join("eol_processing", "sketch.ino") - - context[constants.CTX_HARDWARE_FOLDERS] = []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"} - context[constants.CTX_TOOLS_FOLDERS] = []string{"downloaded_tools"} - context[constants.CTX_FQBN] = "arduino:avr:uno" - context[constants.CTX_SKETCH_LOCATION] = sketchLocation - context[constants.CTX_BUILD_PROPERTIES_RUNTIME_IDE_VERSION] = "10600" - context[constants.CTX_BUILT_IN_LIBRARIES_FOLDERS] = []string{"downloaded_libraries"} - context[constants.CTX_OTHER_LIBRARIES_FOLDERS] = []string{"libraries"} context[constants.CTX_VERBOSE] = true commands := []types.Command{ diff --git a/src/arduino.cc/builder/test/setup_build_properties_test.go b/src/arduino.cc/builder/test/setup_build_properties_test.go index cff97fd5..cf3bfea5 100644 --- a/src/arduino.cc/builder/test/setup_build_properties_test.go +++ b/src/arduino.cc/builder/test/setup_build_properties_test.go @@ -45,17 +45,17 @@ func TestSetupBuildProperties(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) - ctx := &types.Context{} + ctx := &types.Context{ + HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware", "user_hardware"}, + ToolsFolders: []string{"downloaded_tools", "./tools_builtin"}, + SketchLocation: filepath.Join("sketch1", "sketch.ino"), + FQBN: "arduino:avr:uno", + ArduinoAPIVersion: "10600", + } buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) - context[constants.CTX_BUILD_PROPERTIES_RUNTIME_IDE_VERSION] = "10600" - context[constants.CTX_HARDWARE_FOLDERS] = []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware", "user_hardware"} - context[constants.CTX_TOOLS_FOLDERS] = []string{"downloaded_tools", "./tools_builtin"} - context[constants.CTX_FQBN] = "arduino:avr:uno" - context[constants.CTX_SKETCH_LOCATION] = filepath.Join("sketch1", "sketch.ino") - commands := []types.Command{ &builder.SetupHumanLoggerIfMissing{}, &builder.AddAdditionalEntriesToContext{}, @@ -83,7 +83,7 @@ func TestSetupBuildProperties(t *testing.T) { require.Equal(t, Abs(t, "downloaded_hardware/arduino/avr"), buildProperties[constants.BUILD_PROPERTIES_RUNTIME_PLATFORM_PATH]) require.Equal(t, Abs(t, "downloaded_hardware/arduino"), buildProperties[constants.BUILD_PROPERTIES_RUNTIME_HARDWARE_PATH]) - require.Equal(t, "10600", buildProperties[constants.CTX_BUILD_PROPERTIES_RUNTIME_IDE_VERSION]) + require.Equal(t, "10600", buildProperties[constants.BUILD_PROPERTIES_RUNTIME_IDE_VERSION]) require.NotEmpty(t, buildProperties[constants.BUILD_PROPERTIES_RUNTIME_OS]) require.Equal(t, Abs(t, "./downloaded_tools/arm-none-eabi-gcc/4.8.3-2014q1"), buildProperties["runtime.tools.arm-none-eabi-gcc.path"]) @@ -108,18 +108,19 @@ func TestSetupBuildPropertiesWithSomeCustomOverrides(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) - ctx := &types.Context{} + ctx := &types.Context{ + HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, + ToolsFolders: []string{"downloaded_tools", "./tools_builtin"}, + SketchLocation: filepath.Join("sketch1", "sketch.ino"), + FQBN: "arduino:avr:uno", + ArduinoAPIVersion: "10600", + + CustomBuildProperties: []string{"name=fake name", "tools.avrdude.config.path=non existent path with space and a ="}, + } buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) - context[constants.CTX_BUILD_PROPERTIES_RUNTIME_IDE_VERSION] = "10600" - context[constants.CTX_HARDWARE_FOLDERS] = []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"} - context[constants.CTX_TOOLS_FOLDERS] = []string{"downloaded_tools", "./tools_builtin"} - context[constants.CTX_FQBN] = "arduino:avr:uno" - context[constants.CTX_SKETCH_LOCATION] = filepath.Join("sketch1", "sketch.ino") - context[constants.CTX_CUSTOM_BUILD_PROPERTIES] = []string{"name=fake name", "tools.avrdude.config.path=non existent path with space and a ="} - commands := []types.Command{ &builder.SetupHumanLoggerIfMissing{}, &builder.AddAdditionalEntriesToContext{}, @@ -150,17 +151,17 @@ func TestSetupBuildPropertiesUserHardware(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) - ctx := &types.Context{} + ctx := &types.Context{ + HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware", "user_hardware"}, + ToolsFolders: []string{"downloaded_tools", "./tools_builtin"}, + SketchLocation: filepath.Join("sketch1", "sketch.ino"), + FQBN: "my_avr_platform:avr:custom_yun", + ArduinoAPIVersion: "10600", + } buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) - context[constants.CTX_BUILD_PROPERTIES_RUNTIME_IDE_VERSION] = "10600" - context[constants.CTX_HARDWARE_FOLDERS] = []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware", "user_hardware"} - context[constants.CTX_TOOLS_FOLDERS] = []string{"downloaded_tools", "./tools_builtin"} - context[constants.CTX_FQBN] = "my_avr_platform:avr:custom_yun" - context[constants.CTX_SKETCH_LOCATION] = filepath.Join("sketch1", "sketch.ino") - commands := []types.Command{ &builder.SetupHumanLoggerIfMissing{}, &builder.AddAdditionalEntriesToContext{}, @@ -190,17 +191,17 @@ func TestSetupBuildPropertiesWithMissingPropsFromParentPlatformTxtFiles(t *testi DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) - ctx := &types.Context{} + ctx := &types.Context{ + HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware", "user_hardware"}, + ToolsFolders: []string{"downloaded_tools", "./tools_builtin"}, + SketchLocation: filepath.Join("sketch1", "sketch.ino"), + FQBN: "my_avr_platform:avr:custom_yun", + ArduinoAPIVersion: "10600", + } buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) - context[constants.CTX_BUILD_PROPERTIES_RUNTIME_IDE_VERSION] = "10600" - context[constants.CTX_HARDWARE_FOLDERS] = []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware", "user_hardware"} - context[constants.CTX_TOOLS_FOLDERS] = []string{"downloaded_tools", "./tools_builtin"} - context[constants.CTX_FQBN] = "my_avr_platform:avr:custom_yun" - context[constants.CTX_SKETCH_LOCATION] = filepath.Join("sketch1", "sketch.ino") - commands := []types.Command{ &builder.SetupHumanLoggerIfMissing{}, &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, @@ -227,7 +228,7 @@ func TestSetupBuildPropertiesWithMissingPropsFromParentPlatformTxtFiles(t *testi require.Equal(t, Abs(t, "user_hardware/my_avr_platform/avr"), buildProperties[constants.BUILD_PROPERTIES_RUNTIME_PLATFORM_PATH]) require.Equal(t, Abs(t, "user_hardware/my_avr_platform"), buildProperties[constants.BUILD_PROPERTIES_RUNTIME_HARDWARE_PATH]) - require.Equal(t, "10600", buildProperties[constants.CTX_BUILD_PROPERTIES_RUNTIME_IDE_VERSION]) + require.Equal(t, "10600", buildProperties[constants.BUILD_PROPERTIES_RUNTIME_IDE_VERSION]) require.NotEmpty(t, buildProperties[constants.BUILD_PROPERTIES_RUNTIME_OS]) require.Equal(t, Abs(t, "./downloaded_tools/arm-none-eabi-gcc/4.8.3-2014q1"), buildProperties["runtime.tools.arm-none-eabi-gcc.path"]) diff --git a/src/arduino.cc/builder/test/sketch_loader_test.go b/src/arduino.cc/builder/test/sketch_loader_test.go index dede18e9..a25eeb9e 100644 --- a/src/arduino.cc/builder/test/sketch_loader_test.go +++ b/src/arduino.cc/builder/test/sketch_loader_test.go @@ -40,8 +40,9 @@ import ( func TestLoadSketchWithFolder(t *testing.T) { context := make(map[string]interface{}) - ctx := &types.Context{} - context[constants.CTX_SKETCH_LOCATION] = "sketch1" + ctx := &types.Context{ + SketchLocation: "sketch1", + } loggerCommand := builder.SetupHumanLoggerIfMissing{} err := loggerCommand.Run(context, ctx) @@ -58,8 +59,9 @@ func TestLoadSketchWithFolder(t *testing.T) { func TestLoadSketchNonExistentPath(t *testing.T) { context := make(map[string]interface{}) - ctx := &types.Context{} - context[constants.CTX_SKETCH_LOCATION] = "asdasd78128123981723981273asdasd" + ctx := &types.Context{ + SketchLocation: "asdasd78128123981723981273asdasd", + } loggerCommand := builder.SetupHumanLoggerIfMissing{} err := loggerCommand.Run(context, ctx) @@ -76,8 +78,9 @@ func TestLoadSketchNonExistentPath(t *testing.T) { func TestLoadSketch(t *testing.T) { context := make(map[string]interface{}) - ctx := &types.Context{} - context[constants.CTX_SKETCH_LOCATION] = filepath.Join("sketch1", "sketch.ino") + ctx := &types.Context{ + SketchLocation: filepath.Join("sketch1", "sketch.ino"), + } commands := []types.Command{ &builder.SetupHumanLoggerIfMissing{}, @@ -106,8 +109,9 @@ func TestLoadSketch(t *testing.T) { func TestFailToLoadSketchFromFolder(t *testing.T) { context := make(map[string]interface{}) - ctx := &types.Context{} - context[constants.CTX_SKETCH_LOCATION] = "./sketch1" + ctx := &types.Context{ + SketchLocation: "./sketch1", + } loggerCommand := builder.SetupHumanLoggerIfMissing{} err := loggerCommand.Run(context, ctx) @@ -123,8 +127,9 @@ func TestFailToLoadSketchFromFolder(t *testing.T) { func TestLoadSketchFromFolder(t *testing.T) { context := make(map[string]interface{}) - ctx := &types.Context{} - context[constants.CTX_SKETCH_LOCATION] = "sketch_with_subfolders" + ctx := &types.Context{ + SketchLocation: "sketch_with_subfolders", + } commands := []types.Command{ &builder.SetupHumanLoggerIfMissing{}, @@ -150,8 +155,9 @@ func TestLoadSketchFromFolder(t *testing.T) { func TestLoadSketchWithBackup(t *testing.T) { context := make(map[string]interface{}) - ctx := &types.Context{} - context[constants.CTX_SKETCH_LOCATION] = filepath.Join("sketch_with_backup_files", "sketch.ino") + ctx := &types.Context{ + SketchLocation: filepath.Join("sketch_with_backup_files", "sketch.ino"), + } commands := []types.Command{ &builder.SetupHumanLoggerIfMissing{}, @@ -174,8 +180,9 @@ func TestLoadSketchWithBackup(t *testing.T) { func TestLoadSketchWithMacOSXGarbage(t *testing.T) { context := make(map[string]interface{}) - ctx := &types.Context{} - context[constants.CTX_SKETCH_LOCATION] = filepath.Join("sketch_with_macosx_garbage", "sketch.ino") + ctx := &types.Context{ + SketchLocation: filepath.Join("sketch_with_macosx_garbage", "sketch.ino"), + } commands := []types.Command{ &builder.SetupHumanLoggerIfMissing{}, diff --git a/src/arduino.cc/builder/test/sketch_source_merger_test.go b/src/arduino.cc/builder/test/sketch_source_merger_test.go index 91cd3dd9..60bed08d 100644 --- a/src/arduino.cc/builder/test/sketch_source_merger_test.go +++ b/src/arduino.cc/builder/test/sketch_source_merger_test.go @@ -42,8 +42,9 @@ import ( func TestMergeSketch(t *testing.T) { context := make(map[string]interface{}) - ctx := &types.Context{} - context[constants.CTX_SKETCH_LOCATION] = filepath.Join("sketch1", "sketch.ino") + ctx := &types.Context{ + SketchLocation: filepath.Join("sketch1", "sketch.ino"), + } commands := []types.Command{ &builder.SetupHumanLoggerIfMissing{}, diff --git a/src/arduino.cc/builder/test/store_build_options_map_test.go b/src/arduino.cc/builder/test/store_build_options_map_test.go index 1b492fa9..ddfd5333 100644 --- a/src/arduino.cc/builder/test/store_build_options_map_test.go +++ b/src/arduino.cc/builder/test/store_build_options_map_test.go @@ -42,19 +42,21 @@ import ( func TestStoreBuildOptionsMap(t *testing.T) { context := make(map[string]interface{}) - ctx := &types.Context{} + ctx := &types.Context{ + HardwareFolders: []string{"hardware"}, + ToolsFolders: []string{"tools"}, + BuiltInLibrariesFolders: []string{"built-in libraries"}, + OtherLibrariesFolders: []string{"libraries"}, + SketchLocation: "sketchLocation", + FQBN: "fqbn", + ArduinoAPIVersion: "ideVersion", + CustomBuildProperties: []string{"custom=prop"}, + } buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) - context[constants.CTX_HARDWARE_FOLDERS] = "hardware" - context[constants.CTX_TOOLS_FOLDERS] = "tools" - context[constants.CTX_BUILT_IN_LIBRARIES_FOLDERS] = "built-in libraries" - context[constants.CTX_OTHER_LIBRARIES_FOLDERS] = "libraries" - context[constants.CTX_FQBN] = "fqbn" - context[constants.CTX_SKETCH_LOCATION] = "sketchLocation" context[constants.CTX_VERBOSE] = true - context[constants.CTX_BUILD_PROPERTIES_RUNTIME_IDE_VERSION] = "ideVersion" context[constants.CTX_DEBUG_LEVEL] = 5 commands := []types.Command{ @@ -75,6 +77,7 @@ func TestStoreBuildOptionsMap(t *testing.T) { require.Equal(t, "{\n"+ " \"builtInLibrariesFolders\": \"built-in libraries\",\n"+ + " \"customBuildProperties\": \"custom=prop\",\n"+ " \"fqbn\": \"fqbn\",\n"+ " \"hardwareFolders\": \"hardware\",\n"+ " \"otherLibrariesFolders\": \"libraries\",\n"+ diff --git a/src/arduino.cc/builder/test/target_board_resolver_test.go b/src/arduino.cc/builder/test/target_board_resolver_test.go index 53fce48a..bbf96d23 100644 --- a/src/arduino.cc/builder/test/target_board_resolver_test.go +++ b/src/arduino.cc/builder/test/target_board_resolver_test.go @@ -40,9 +40,10 @@ import ( func TestTargetBoardResolverUno(t *testing.T) { context := make(map[string]interface{}) - ctx := &types.Context{} - context[constants.CTX_HARDWARE_FOLDERS] = []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"} - context[constants.CTX_FQBN] = "arduino:avr:uno" + ctx := &types.Context{ + HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, + FQBN: "arduino:avr:uno", + } commands := []types.Command{ &builder.SetupHumanLoggerIfMissing{}, @@ -66,9 +67,10 @@ func TestTargetBoardResolverUno(t *testing.T) { func TestTargetBoardResolverDue(t *testing.T) { context := make(map[string]interface{}) - ctx := &types.Context{} - context[constants.CTX_HARDWARE_FOLDERS] = []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"} - context[constants.CTX_FQBN] = "arduino:sam:arduino_due_x" + ctx := &types.Context{ + HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, + FQBN: "arduino:sam:arduino_due_x", + } commands := []types.Command{ &builder.SetupHumanLoggerIfMissing{}, @@ -92,9 +94,10 @@ func TestTargetBoardResolverDue(t *testing.T) { func TestTargetBoardResolverMega1280(t *testing.T) { context := make(map[string]interface{}) - ctx := &types.Context{} - context[constants.CTX_HARDWARE_FOLDERS] = []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"} - context[constants.CTX_FQBN] = "arduino:avr:mega:cpu=atmega1280" + ctx := &types.Context{ + HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, + FQBN: "arduino:avr:mega:cpu=atmega1280", + } commands := []types.Command{ &builder.SetupHumanLoggerIfMissing{}, @@ -119,9 +122,10 @@ func TestTargetBoardResolverMega1280(t *testing.T) { func TestTargetBoardResolverMega2560(t *testing.T) { context := make(map[string]interface{}) - ctx := &types.Context{} - context[constants.CTX_HARDWARE_FOLDERS] = []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"} - context[constants.CTX_FQBN] = "arduino:avr:mega:cpu=atmega2560" + ctx := &types.Context{ + HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, + FQBN: "arduino:avr:mega:cpu=atmega2560", + } commands := []types.Command{ &builder.SetupHumanLoggerIfMissing{}, @@ -146,9 +150,10 @@ func TestTargetBoardResolverMega2560(t *testing.T) { func TestTargetBoardResolverCustomYun(t *testing.T) { context := make(map[string]interface{}) - ctx := &types.Context{} - context[constants.CTX_HARDWARE_FOLDERS] = []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware", "user_hardware"} - context[constants.CTX_FQBN] = "my_avr_platform:avr:custom_yun" + ctx := &types.Context{ + HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware", "user_hardware"}, + FQBN: "my_avr_platform:avr:custom_yun", + } commands := []types.Command{ &builder.SetupHumanLoggerIfMissing{}, @@ -173,9 +178,10 @@ func TestTargetBoardResolverCustomYun(t *testing.T) { func TestTargetBoardResolverCustomCore(t *testing.T) { context := make(map[string]interface{}) - ctx := &types.Context{} - context[constants.CTX_HARDWARE_FOLDERS] = []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware", "user_hardware"} - context[constants.CTX_FQBN] = "watterott:avr:attiny841:core=spencekonde,info=info" + ctx := &types.Context{ + HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware", "user_hardware"}, + FQBN: "watterott:avr:attiny841:core=spencekonde,info=info", + } commands := []types.Command{ &builder.SetupHumanLoggerIfMissing{}, diff --git a/src/arduino.cc/builder/test/tools_loader_test.go b/src/arduino.cc/builder/test/tools_loader_test.go index cf268b64..49e07d86 100644 --- a/src/arduino.cc/builder/test/tools_loader_test.go +++ b/src/arduino.cc/builder/test/tools_loader_test.go @@ -57,8 +57,9 @@ func TestLoadTools(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) - ctx := &types.Context{} - context[constants.CTX_TOOLS_FOLDERS] = []string{"downloaded_tools", "tools_builtin"} + ctx := &types.Context{ + ToolsFolders: []string{"downloaded_tools", "tools_builtin"}, + } loader := builder.ToolsLoader{} err := loader.Run(context, ctx) @@ -95,8 +96,9 @@ func TestLoadToolsWithBoardManagerFolderStructure(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) - ctx := &types.Context{} - context[constants.CTX_TOOLS_FOLDERS] = []string{"downloaded_board_manager_stuff"} + ctx := &types.Context{ + ToolsFolders: []string{"downloaded_board_manager_stuff"}, + } loader := builder.ToolsLoader{} err := loader.Run(context, ctx) @@ -121,8 +123,9 @@ func TestLoadLotsOfTools(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) - ctx := &types.Context{} - context[constants.CTX_TOOLS_FOLDERS] = []string{"downloaded_tools", "tools_builtin", "downloaded_board_manager_stuff"} + ctx := &types.Context{ + ToolsFolders: []string{"downloaded_tools", "tools_builtin", "downloaded_board_manager_stuff"}, + } loader := builder.ToolsLoader{} err := loader.Run(context, ctx) diff --git a/src/arduino.cc/builder/test/try_build_of_problematic_sketch_test.go b/src/arduino.cc/builder/test/try_build_of_problematic_sketch_test.go index 0786f035..d0237c7e 100644 --- a/src/arduino.cc/builder/test/try_build_of_problematic_sketch_test.go +++ b/src/arduino.cc/builder/test/try_build_of_problematic_sketch_test.go @@ -119,7 +119,7 @@ func TestTryBuild019(t *testing.T) { func TestTryBuild020(t *testing.T) { context, ctx := makeDefaultContext(t) - context[constants.CTX_OTHER_LIBRARIES_FOLDERS] = []string{"dependent_libraries", "libraries"} + ctx.OtherLibrariesFolders = []string{"dependent_libraries", "libraries"} tryPreprocessWithContext(t, context, ctx, "sketch_with_dependend_libraries", "sketch.ino") } @@ -129,7 +129,7 @@ func TestTryBuild021(t *testing.T) { func TestTryBuild022(t *testing.T) { context, ctx := makeDefaultContext(t) - context[constants.CTX_FQBN] = "arduino:samd:arduino_zero_native" + ctx.FQBN = "arduino:samd:arduino_zero_native" tryBuildWithContext(t, context, ctx, "sketch_usbhost", "sketch_usbhost.ino") } @@ -188,7 +188,7 @@ func TestTryBuild035(t *testing.T) { func TestTryBuild036(t *testing.T) { context, ctx := makeDefaultContext(t) - context[constants.CTX_FQBN] = "arduino:samd:arduino_zero_native" + ctx.FQBN = "arduino:samd:arduino_zero_native" tryBuildWithContext(t, context, ctx, "sketch11", "sketch_fastleds.ino") } @@ -204,16 +204,17 @@ func makeDefaultContext(t *testing.T) (map[string]interface{}, *types.Context) { DownloadCoresAndToolsAndLibraries(t) context := make(map[string]interface{}) - ctx := &types.Context{} + ctx := &types.Context{ + HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware", "downloaded_board_manager_stuff"}, + ToolsFolders: []string{"downloaded_tools", "downloaded_board_manager_stuff"}, + BuiltInLibrariesFolders: []string{"downloaded_libraries"}, + OtherLibrariesFolders: []string{"libraries"}, + FQBN: "arduino:avr:leonardo", + ArduinoAPIVersion: "10607", + } buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) - context[constants.CTX_HARDWARE_FOLDERS] = []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware", "downloaded_board_manager_stuff"} - context[constants.CTX_TOOLS_FOLDERS] = []string{"downloaded_tools", "downloaded_board_manager_stuff"} - context[constants.CTX_BUILT_IN_LIBRARIES_FOLDERS] = []string{"downloaded_libraries"} - context[constants.CTX_FQBN] = "arduino:avr:leonardo" - context[constants.CTX_BUILD_PROPERTIES_RUNTIME_IDE_VERSION] = "10607" - context[constants.CTX_OTHER_LIBRARIES_FOLDERS] = []string{"libraries"} context[constants.CTX_VERBOSE] = true context[constants.CTX_DEBUG_PREPROCESSOR] = true @@ -227,7 +228,7 @@ func tryBuild(t *testing.T, sketchPath ...string) { func tryBuildWithContext(t *testing.T, context map[string]interface{}, ctx *types.Context, sketchPath ...string) { sketchLocation := filepath.Join(sketchPath...) - context[constants.CTX_SKETCH_LOCATION] = sketchLocation + ctx.SketchLocation = sketchLocation err := builder.RunBuilder(context, ctx) NoError(t, err, "Build error for "+sketchLocation) @@ -240,7 +241,7 @@ func tryPreprocess(t *testing.T, sketchPath ...string) { func tryPreprocessWithContext(t *testing.T, context map[string]interface{}, ctx *types.Context, sketchPath ...string) { sketchLocation := filepath.Join(sketchPath...) - context[constants.CTX_SKETCH_LOCATION] = sketchLocation + ctx.SketchLocation = sketchLocation err := builder.RunPreprocess(context, ctx) NoError(t, err, "Build error for "+sketchLocation) diff --git a/src/arduino.cc/builder/tools_loader.go b/src/arduino.cc/builder/tools_loader.go index 999b7e07..317ef023 100644 --- a/src/arduino.cc/builder/tools_loader.go +++ b/src/arduino.cc/builder/tools_loader.go @@ -42,7 +42,7 @@ import ( type ToolsLoader struct{} func (s *ToolsLoader) Run(context map[string]interface{}, ctx *types.Context) error { - folders := context[constants.CTX_TOOLS_FOLDERS].([]string) + folders := ctx.ToolsFolders tools := []*types.Tool{} diff --git a/src/arduino.cc/builder/types/context.go b/src/arduino.cc/builder/types/context.go index afe2453e..89267d7b 100644 --- a/src/arduino.cc/builder/types/context.go +++ b/src/arduino.cc/builder/types/context.go @@ -1,10 +1,49 @@ package types +import "strings" +import "arduino.cc/builder/props" + // Context structure type Context struct { + // Build options + HardwareFolders []string + ToolsFolders []string + LibrariesFolders []string + BuiltInLibrariesFolders []string + OtherLibrariesFolders []string + SketchLocation string + ArduinoAPIVersion string + FQBN string + + // Contents of a custom build properties file (line by line) + CustomBuildProperties []string // For now it is used in conjunction with the old map[string]string, but // it will be slowly populated with all the fields currently used in the // map in the next commits. // When the migration will be completed the old map will be removed. } + +func (ctx *Context) ExtractBuildOptions() props.PropertiesMap { + opts := make(props.PropertiesMap) + opts["hardwareFolders"] = strings.Join(ctx.HardwareFolders, ",") + opts["toolsFolders"] = strings.Join(ctx.ToolsFolders, ",") + opts["builtInLibrariesFolders"] = strings.Join(ctx.BuiltInLibrariesFolders, ",") + opts["otherLibrariesFolders"] = strings.Join(ctx.OtherLibrariesFolders, ",") + opts["sketchLocation"] = ctx.SketchLocation + opts["fqbn"] = ctx.FQBN + opts["runtime.ide.version"] = ctx.ArduinoAPIVersion + opts["customBuildProperties"] = strings.Join(ctx.CustomBuildProperties, ",") + return opts +} + +func (ctx *Context) InjectBuildOptions(opts props.PropertiesMap) { + ctx.HardwareFolders = strings.Split(opts["hardwareFolders"], ",") + ctx.ToolsFolders = strings.Split(opts["toolsFolders"], ",") + ctx.BuiltInLibrariesFolders = strings.Split(opts["builtInLibrariesFolders"], ",") + ctx.OtherLibrariesFolders = strings.Split(opts["otherLibrariesFolders"], ",") + ctx.SketchLocation = opts["sketchLocation"] + ctx.FQBN = opts["fqbn"] + ctx.ArduinoAPIVersion = opts["runtime.ide.version"] + ctx.CustomBuildProperties = strings.Split(opts["customBuildProperties"], ",") +} diff --git a/src/arduino.cc/builder/wipeout_build_path_if_build_options_changed.go b/src/arduino.cc/builder/wipeout_build_path_if_build_options_changed.go index 56fb44d9..5e73a697 100644 --- a/src/arduino.cc/builder/wipeout_build_path_if_build_options_changed.go +++ b/src/arduino.cc/builder/wipeout_build_path_if_build_options_changed.go @@ -54,7 +54,7 @@ func (s *WipeoutBuildPathIfBuildOptionsChanged) Run(context map[string]interface return nil } - re := regexp.MustCompile("(?m)^.*" + constants.CTX_SKETCH_LOCATION + ".*$[\r\n]+") + re := regexp.MustCompile("(?m)^.*" + ctx.SketchLocation + ".*$[\r\n]+") buildOptionsJson = re.ReplaceAllString(buildOptionsJson, "") previousBuildOptionsJson = re.ReplaceAllString(previousBuildOptionsJson, "") From 559454cb8b45f812fa6e9e66f969fc303d5d3ca0 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Fri, 1 Apr 2016 22:43:49 +0200 Subject: [PATCH 03/25] Refactored logger in context. I don't know if logger should be part of the Context, anyway I kept it in the structure to maximize compatibility. Default logging level has been lowered from 5 to 0, so the initialization step could be completely removed. Logging subroutines have been adjusted accordingly. Signed-off-by: Cristian Maglie --- main.go | 8 +- .../add_additional_entries_to_context.go | 13 +- .../add_build_board_property_if_missing.go | 3 +- .../builder/additional_sketch_files_copier.go | 11 +- src/arduino.cc/builder/builder.go | 26 ++-- src/arduino.cc/builder/builder_utils/utils.go | 58 ++++---- src/arduino.cc/builder/coan_runner.go | 9 +- ..._source_files_from_folders_with_sources.go | 7 +- src/arduino.cc/builder/constants/constants.go | 2 - .../builder/container_add_prototypes.go | 6 +- .../builder/container_build_options.go | 6 +- .../builder/container_find_includes.go | 21 +-- .../container_merge_copy_sketch_files.go | 6 +- src/arduino.cc/builder/container_setup.go | 6 +- .../builder/create_build_options_map.go | 4 +- src/arduino.cc/builder/ctags/ctags_parser.go | 21 ++- src/arduino.cc/builder/ctags/ctags_runner.go | 8 +- .../builder/ctags_target_file_saver.go | 5 +- .../builder/ensure_buildpath_exists.go | 3 +- .../fail_if_buildpath_equals_sketchpath.go | 7 +- .../fail_if_imported_library_is_wrong.go | 8 +- src/arduino.cc/builder/gcc_preproc_runner.go | 14 +- .../builder/gcc_preproc_source_saver.go | 5 +- .../builder/generate_buildpath_if_missing.go | 6 +- src/arduino.cc/builder/hardware_loader.go | 36 ++--- src/arduino.cc/builder/i18n/errors.go | 20 +++ .../builder/includes_finder_with_gcc.go | 7 +- .../builder/includes_to_include_folders.go | 3 +- src/arduino.cc/builder/libraries_loader.go | 20 +-- .../builder/load_previous_build_options.go | 6 +- .../load_vid_pid_specific_properties.go | 3 +- .../builder/merge_sketch_with_bootloader.go | 6 +- src/arduino.cc/builder/phases/core_builder.go | 12 +- .../builder/phases/libraries_builder.go | 18 +-- src/arduino.cc/builder/phases/linker.go | 6 +- .../builder/phases/sketch_builder.go | 6 +- .../builder/platform_keys_rewrite_loader.go | 8 +- .../print_used_and_not_used_libraries.go | 6 +- .../print_used_libraries_if_verbose.go | 3 +- src/arduino.cc/builder/props/properties.go | 11 +- .../builder/read_file_and_store_in_context.go | 4 +- src/arduino.cc/builder/recipe_runner.go | 9 +- .../builder/set_custom_build_properties.go | 5 +- .../builder/setup_human_logger_if_missing.go | 47 ------- src/arduino.cc/builder/sketch_loader.go | 19 +-- src/arduino.cc/builder/sketch_saver.go | 5 +- .../builder/target_board_resolver.go | 11 +- .../add_additional_entries_to_context_test.go | 2 - ...dd_build_board_property_if_missing_test.go | 2 - .../additional_sketch_files_copier_test.go | 2 - src/arduino.cc/builder/test/builder_test.go | 2 +- .../builder/test/coan_runner_test.go | 1 - ...ce_files_from_folders_with_sources_test.go | 3 - .../test/create_build_options_map_test.go | 2 +- .../builder/test/ctags_runner_test.go | 5 - .../builder/test/hardware_loader_test.go | 4 - .../builder/test/helper_tools_downloader.go | 124 +++++++++--------- .../test/includes_finder_with_gcc_test.go | 5 - .../test/includes_finder_with_regexp_test.go | 1 - .../test/includes_to_include_folders_test.go | 7 - .../builder/test/libraries_loader_test.go | 4 - .../load_vid_pid_specific_properties_test.go | 2 - .../test/merge_sketch_with_bootloader_test.go | 4 - .../test/platform_keys_rewrite_loader_test.go | 1 - .../builder/test/prototypes_adder_test.go | 22 +--- .../builder/test/recipe_runner_test.go | 1 - .../test/rewrite_hardware_keys_test.go | 2 - .../test/setup_build_properties_test.go | 4 - .../setup_human_logger_if_missing_test.go | 52 -------- .../builder/test/sketch_loader_test.go | 22 +--- .../builder/test/sketch_source_merger_test.go | 1 - .../test/store_build_options_map_test.go | 2 +- .../test/target_board_resolver_test.go | 6 - ...uild_path_if_build_options_changed_test.go | 3 - src/arduino.cc/builder/tools_loader.go | 25 ++-- src/arduino.cc/builder/types/context.go | 16 +++ .../unused_compiled_libraries_remover.go | 5 +- src/arduino.cc/builder/utils/utils.go | 48 +------ .../warn_about_arch_incompatible_libraries.go | 6 +- .../builder/warn_about_platform_rewrites.go | 7 +- ...out_build_path_if_build_options_changed.go | 4 +- 81 files changed, 365 insertions(+), 566 deletions(-) create mode 100644 src/arduino.cc/builder/i18n/errors.go delete mode 100644 src/arduino.cc/builder/setup_human_logger_if_missing.go delete mode 100644 src/arduino.cc/builder/test/setup_human_logger_if_missing_test.go diff --git a/main.go b/main.go index 662b726d..af8246ef 100644 --- a/main.go +++ b/main.go @@ -308,7 +308,7 @@ func main() { } if *debugLevelFlag > -1 { - context[constants.CTX_DEBUG_LEVEL] = *debugLevelFlag + ctx.DebugLevel = *debugLevelFlag } if *quietFlag { @@ -335,11 +335,11 @@ func main() { exitCode := 0 if err != nil { - err = utils.WrapError(err) + err = i18n.WrapError(err) fmt.Fprintln(os.Stderr, err) - if utils.DebugLevel(context) >= 10 { + if ctx.DebugLevel >= 10 { fmt.Fprintln(os.Stderr, err.(*errors.Error).ErrorStack()) } @@ -398,7 +398,7 @@ func printError(err error, printStackTrace bool) { } func printCompleteError(err error) { - err = utils.WrapError(err) + err = i18n.WrapError(err) fmt.Fprintln(os.Stderr, err.(*errors.Error).ErrorStack()) } diff --git a/src/arduino.cc/builder/add_additional_entries_to_context.go b/src/arduino.cc/builder/add_additional_entries_to_context.go index f2926adb..ffe7aaff 100644 --- a/src/arduino.cc/builder/add_additional_entries_to_context.go +++ b/src/arduino.cc/builder/add_additional_entries_to_context.go @@ -31,6 +31,7 @@ package builder import ( "arduino.cc/builder/constants" + "arduino.cc/builder/i18n" "arduino.cc/builder/types" "arduino.cc/builder/utils" "path/filepath" @@ -43,19 +44,19 @@ func (s *AddAdditionalEntriesToContext) Run(context map[string]interface{}, ctx buildPath := context[constants.CTX_BUILD_PATH].(string) preprocPath, err := filepath.Abs(filepath.Join(buildPath, constants.FOLDER_PREPROC)) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } sketchBuildPath, err := filepath.Abs(filepath.Join(buildPath, constants.FOLDER_SKETCH)) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } librariesBuildPath, err := filepath.Abs(filepath.Join(buildPath, constants.FOLDER_LIBRARIES)) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } coreBuildPath, err := filepath.Abs(filepath.Join(buildPath, constants.FOLDER_CORE)) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } context[constants.CTX_PREPROC_PATH] = preprocPath @@ -72,10 +73,6 @@ func (s *AddAdditionalEntriesToContext) Run(context map[string]interface{}, ctx context[constants.CTX_VERBOSE] = false } - if !utils.MapHas(context, constants.CTX_DEBUG_LEVEL) { - context[constants.CTX_DEBUG_LEVEL] = DEFAULT_DEBUG_LEVEL - } - sourceFiles := &types.UniqueStringQueue{} context[constants.CTX_COLLECTED_SOURCE_FILES_QUEUE] = sourceFiles foldersWithSources := &types.UniqueSourceFolderQueue{} diff --git a/src/arduino.cc/builder/add_build_board_property_if_missing.go b/src/arduino.cc/builder/add_build_board_property_if_missing.go index 9384fd92..9bb7f218 100644 --- a/src/arduino.cc/builder/add_build_board_property_if_missing.go +++ b/src/arduino.cc/builder/add_build_board_property_if_missing.go @@ -31,7 +31,6 @@ package builder import ( "arduino.cc/builder/constants" - "arduino.cc/builder/i18n" "arduino.cc/builder/types" "os" "strings" @@ -41,7 +40,7 @@ type AddBuildBoardPropertyIfMissing struct{} func (s *AddBuildBoardPropertyIfMissing) Run(context map[string]interface{}, ctx *types.Context) error { packages := context[constants.CTX_HARDWARE].(*types.Packages) - logger := context[constants.CTX_LOGGER].(i18n.Logger) + logger := ctx.GetLogger() for _, aPackage := range packages.Packages { for _, platform := range aPackage.Platforms { diff --git a/src/arduino.cc/builder/additional_sketch_files_copier.go b/src/arduino.cc/builder/additional_sketch_files_copier.go index a40c9205..5156e940 100644 --- a/src/arduino.cc/builder/additional_sketch_files_copier.go +++ b/src/arduino.cc/builder/additional_sketch_files_copier.go @@ -31,6 +31,7 @@ package builder import ( "arduino.cc/builder/constants" + "arduino.cc/builder/i18n" "arduino.cc/builder/types" "arduino.cc/builder/utils" "bytes" @@ -46,7 +47,7 @@ func (s *AdditionalSketchFilesCopier) Run(context map[string]interface{}, ctx *t err := utils.EnsureFolderExists(sketchBuildPath) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } sketchBasePath := filepath.Dir(sketch.MainFile.Name) @@ -54,24 +55,24 @@ func (s *AdditionalSketchFilesCopier) Run(context map[string]interface{}, ctx *t for _, file := range sketch.AdditionalFiles { relativePath, err := filepath.Rel(sketchBasePath, file.Name) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } targetFilePath := filepath.Join(sketchBuildPath, relativePath) err = utils.EnsureFolderExists(filepath.Dir(targetFilePath)) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } bytes, err := ioutil.ReadFile(file.Name) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } if targetFileChanged(bytes, targetFilePath) { err := utils.WriteFileBytes(targetFilePath, bytes) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } } } diff --git a/src/arduino.cc/builder/builder.go b/src/arduino.cc/builder/builder.go index eab85491..4c7b6124 100644 --- a/src/arduino.cc/builder/builder.go +++ b/src/arduino.cc/builder/builder.go @@ -31,9 +31,9 @@ package builder import ( "arduino.cc/builder/constants" + "arduino.cc/builder/i18n" "arduino.cc/builder/phases" "arduino.cc/builder/types" - "arduino.cc/builder/utils" "os" "reflect" "strconv" @@ -68,8 +68,6 @@ type Builder struct{} func (s *Builder) Run(context map[string]interface{}, ctx *types.Context) error { commands := []types.Command{ - &SetupHumanLoggerIfMissing{}, - &GenerateBuildPathIfMissing{}, &EnsureBuildPathExists{}, @@ -135,8 +133,6 @@ type Preprocess struct{} func (s *Preprocess) Run(context map[string]interface{}, ctx *types.Context) error { commands := []types.Command{ - &SetupHumanLoggerIfMissing{}, - &GenerateBuildPathIfMissing{}, &EnsureBuildPathExists{}, @@ -164,8 +160,6 @@ type ParseHardwareAndDumpBuildProperties struct{} func (s *ParseHardwareAndDumpBuildProperties) Run(context map[string]interface{}, ctx *types.Context) error { commands := []types.Command{ - &SetupHumanLoggerIfMissing{}, - &GenerateBuildPathIfMissing{}, &ContainerSetupHardwareToolsLibsSketchAndProps{}, @@ -182,34 +176,34 @@ func runCommands(context map[string]interface{}, ctx *types.Context, commands [] progress := float32(0) for _, command := range commands { - PrintRingNameIfDebug(context, command) - printProgressIfProgressEnabledAndMachineLogger(progressEnabled, context, progress) + PrintRingNameIfDebug(ctx, command) + printProgressIfProgressEnabledAndMachineLogger(progressEnabled, ctx, progress) err := command.Run(context, ctx) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } progress += progressForEachCommand } - printProgressIfProgressEnabledAndMachineLogger(progressEnabled, context, 100) + printProgressIfProgressEnabledAndMachineLogger(progressEnabled, ctx, 100) return nil } -func printProgressIfProgressEnabledAndMachineLogger(progressEnabled bool, context map[string]interface{}, progress float32) { +func printProgressIfProgressEnabledAndMachineLogger(progressEnabled bool, ctx *types.Context, progress float32) { if !progressEnabled { return } - log := utils.Logger(context) + log := ctx.GetLogger() if log.Name() == "machine" { log.Println(constants.LOG_LEVEL_INFO, constants.MSG_PROGRESS, strconv.FormatFloat(float64(progress), 'f', 2, 32)) } } -func PrintRingNameIfDebug(context map[string]interface{}, command types.Command) { - if utils.DebugLevel(context) >= 10 { - utils.Logger(context).Fprintln(os.Stdout, constants.LOG_LEVEL_DEBUG, constants.MSG_RUNNING_COMMAND, strconv.FormatInt(time.Now().Unix(), 10), reflect.Indirect(reflect.ValueOf(command)).Type().Name()) +func PrintRingNameIfDebug(ctx *types.Context, command types.Command) { + if ctx.DebugLevel >= 10 { + ctx.GetLogger().Fprintln(os.Stdout, constants.LOG_LEVEL_DEBUG, constants.MSG_RUNNING_COMMAND, strconv.FormatInt(time.Now().Unix(), 10), reflect.Indirect(reflect.ValueOf(command)).Type().Name()) } } diff --git a/src/arduino.cc/builder/builder_utils/utils.go b/src/arduino.cc/builder/builder_utils/utils.go index 9d0dc06d..af5aabdc 100644 --- a/src/arduino.cc/builder/builder_utils/utils.go +++ b/src/arduino.cc/builder/builder_utils/utils.go @@ -45,18 +45,18 @@ import ( func CompileFilesRecursive(objectFiles []string, sourcePath string, buildPath string, buildProperties props.PropertiesMap, includes []string, verbose bool, warningsLevel string, logger i18n.Logger) ([]string, error) { objectFiles, err := CompileFiles(objectFiles, sourcePath, false, buildPath, buildProperties, includes, verbose, warningsLevel, logger) if err != nil { - return nil, utils.WrapError(err) + return nil, i18n.WrapError(err) } folders, err := utils.ReadDirFiltered(sourcePath, utils.FilterDirs) if err != nil { - return nil, utils.WrapError(err) + return nil, i18n.WrapError(err) } for _, folder := range folders { objectFiles, err = CompileFilesRecursive(objectFiles, filepath.Join(sourcePath, folder.Name()), filepath.Join(buildPath, folder.Name()), buildProperties, includes, verbose, warningsLevel, logger) if err != nil { - return nil, utils.WrapError(err) + return nil, i18n.WrapError(err) } } @@ -66,15 +66,15 @@ func CompileFilesRecursive(objectFiles []string, sourcePath string, buildPath st func CompileFiles(objectFiles []string, sourcePath string, recurse bool, buildPath string, buildProperties props.PropertiesMap, includes []string, verbose bool, warningsLevel string, logger i18n.Logger) ([]string, error) { objectFiles, err := compileFilesWithExtensionWithRecipe(objectFiles, sourcePath, recurse, buildPath, buildProperties, includes, ".S", constants.RECIPE_S_PATTERN, verbose, warningsLevel, logger) if err != nil { - return nil, utils.WrapError(err) + return nil, i18n.WrapError(err) } objectFiles, err = compileFilesWithExtensionWithRecipe(objectFiles, sourcePath, recurse, buildPath, buildProperties, includes, ".c", constants.RECIPE_C_PATTERN, verbose, warningsLevel, logger) if err != nil { - return nil, utils.WrapError(err) + return nil, i18n.WrapError(err) } objectFiles, err = compileFilesWithExtensionWithRecipe(objectFiles, sourcePath, recurse, buildPath, buildProperties, includes, ".cpp", constants.RECIPE_CPP_PATTERN, verbose, warningsLevel, logger) if err != nil { - return nil, utils.WrapError(err) + return nil, i18n.WrapError(err) } return objectFiles, nil } @@ -82,7 +82,7 @@ func CompileFiles(objectFiles []string, sourcePath string, recurse bool, buildPa func compileFilesWithExtensionWithRecipe(objectFiles []string, sourcePath string, recurse bool, buildPath string, buildProperties props.PropertiesMap, includes []string, extension string, recipe string, verbose bool, warningsLevel string, logger i18n.Logger) ([]string, error) { sources, err := findFilesInFolder(sourcePath, extension, recurse) if err != nil { - return nil, utils.WrapError(err) + return nil, i18n.WrapError(err) } return compileFilesWithRecipe(objectFiles, sourcePath, sources, buildPath, buildProperties, includes, recipe, verbose, warningsLevel, logger) } @@ -90,7 +90,7 @@ func compileFilesWithExtensionWithRecipe(objectFiles []string, sourcePath string func findFilesInFolder(sourcePath string, extension string, recurse bool) ([]string, error) { files, err := utils.ReadDirFiltered(sourcePath, utils.FilterFilesWithExtension(extension)) if err != nil { - return nil, utils.WrapError(err) + return nil, i18n.WrapError(err) } var sources []string for _, file := range files { @@ -100,13 +100,13 @@ func findFilesInFolder(sourcePath string, extension string, recurse bool) ([]str if recurse { folders, err := utils.ReadDirFiltered(sourcePath, utils.FilterDirs) if err != nil { - return nil, utils.WrapError(err) + return nil, i18n.WrapError(err) } for _, folder := range folders { otherSources, err := findFilesInFolder(filepath.Join(sourcePath, folder.Name()), extension, recurse) if err != nil { - return nil, utils.WrapError(err) + return nil, i18n.WrapError(err) } sources = append(sources, otherSources...) } @@ -119,7 +119,7 @@ func compileFilesWithRecipe(objectFiles []string, sourcePath string, sources []s for _, source := range sources { objectFile, err := compileFileWithRecipe(sourcePath, source, buildPath, buildProperties, includes, recipe, verbose, warningsLevel, logger) if err != nil { - return nil, utils.WrapError(err) + return nil, i18n.WrapError(err) } objectFiles = append(objectFiles, objectFile) @@ -134,24 +134,24 @@ func compileFileWithRecipe(sourcePath string, source string, buildPath string, b properties[constants.BUILD_PROPERTIES_SOURCE_FILE] = source relativeSource, err := filepath.Rel(sourcePath, source) if err != nil { - return "", utils.WrapError(err) + return "", i18n.WrapError(err) } properties[constants.BUILD_PROPERTIES_OBJECT_FILE] = filepath.Join(buildPath, relativeSource+".o") err = utils.EnsureFolderExists(filepath.Dir(properties[constants.BUILD_PROPERTIES_OBJECT_FILE])) if err != nil { - return "", utils.WrapError(err) + return "", i18n.WrapError(err) } objIsUpToDate, err := ObjFileIsUpToDate(properties[constants.BUILD_PROPERTIES_SOURCE_FILE], properties[constants.BUILD_PROPERTIES_OBJECT_FILE], filepath.Join(buildPath, relativeSource+".d")) if err != nil { - return "", utils.WrapError(err) + return "", i18n.WrapError(err) } if !objIsUpToDate { _, err = ExecRecipe(properties, recipe, false, verbose, verbose, logger) if err != nil { - return "", utils.WrapError(err) + return "", i18n.WrapError(err) } } else if verbose { logger.Println(constants.LOG_LEVEL_INFO, constants.MSG_USING_PREVIOUS_COMPILED_FILE, properties[constants.BUILD_PROPERTIES_OBJECT_FILE]) @@ -167,7 +167,7 @@ func ObjFileIsUpToDate(sourceFile, objectFile, dependencyFile string) (bool, err sourceFileStat, err := os.Stat(sourceFile) if err != nil { - return false, utils.WrapError(err) + return false, i18n.WrapError(err) } objectFileStat, err := os.Stat(objectFile) @@ -175,7 +175,7 @@ func ObjFileIsUpToDate(sourceFile, objectFile, dependencyFile string) (bool, err if os.IsNotExist(err) { return false, nil } else { - return false, utils.WrapError(err) + return false, i18n.WrapError(err) } } @@ -184,7 +184,7 @@ func ObjFileIsUpToDate(sourceFile, objectFile, dependencyFile string) (bool, err if os.IsNotExist(err) { return false, nil } else { - return false, utils.WrapError(err) + return false, i18n.WrapError(err) } } @@ -197,7 +197,7 @@ func ObjFileIsUpToDate(sourceFile, objectFile, dependencyFile string) (bool, err rows, err := utils.ReadFileToRows(dependencyFile) if err != nil { - return false, utils.WrapError(err) + return false, i18n.WrapError(err) } rows = utils.Map(rows, removeEndingBackSlash) @@ -222,7 +222,7 @@ func ObjFileIsUpToDate(sourceFile, objectFile, dependencyFile string) (bool, err for _, row := range rows { depStat, err := os.Stat(row) if err != nil && !os.IsNotExist(err) { - return false, utils.WrapError(err) + return false, i18n.WrapError(err) } if os.IsNotExist(err) { return false, nil @@ -260,7 +260,7 @@ func ArchiveCompiledFiles(buildPath string, archiveFile string, objectFiles []st if _, err := os.Stat(archiveFilePath); err == nil { err = os.Remove(archiveFilePath) if err != nil { - return "", utils.WrapError(err) + return "", i18n.WrapError(err) } } @@ -272,7 +272,7 @@ func ArchiveCompiledFiles(buildPath string, archiveFile string, objectFiles []st _, err := ExecRecipe(properties, constants.RECIPE_AR_PATTERN, false, verbose, verbose, logger) if err != nil { - return "", utils.WrapError(err) + return "", i18n.WrapError(err) } } @@ -282,7 +282,7 @@ func ArchiveCompiledFiles(buildPath string, archiveFile string, objectFiles []st func ExecRecipe(properties props.PropertiesMap, recipe string, removeUnsetProperties bool, echoCommandLine bool, echoOutput bool, logger i18n.Logger) ([]byte, error) { command, err := PrepareCommandForRecipe(properties, recipe, removeUnsetProperties, echoCommandLine, echoOutput, logger) if err != nil { - return nil, utils.WrapError(err) + return nil, i18n.WrapError(err) } if echoOutput { @@ -293,17 +293,17 @@ func ExecRecipe(properties props.PropertiesMap, recipe string, removeUnsetProper if echoOutput { err := command.Run() - return nil, utils.WrapError(err) + return nil, i18n.WrapError(err) } bytes, err := command.Output() - return bytes, utils.WrapError(err) + return bytes, i18n.WrapError(err) } func PrepareCommandForRecipe(properties props.PropertiesMap, recipe string, removeUnsetProperties bool, echoCommandLine bool, echoOutput bool, logger i18n.Logger) (*exec.Cmd, error) { pattern := properties[recipe] if pattern == constants.EMPTY_STRING { - return nil, utils.ErrorfWithLogger(logger, constants.MSG_PATTERN_MISSING, recipe) + return nil, i18n.ErrorfWithLogger(logger, constants.MSG_PATTERN_MISSING, recipe) } var err error @@ -311,13 +311,13 @@ func PrepareCommandForRecipe(properties props.PropertiesMap, recipe string, remo if removeUnsetProperties { commandLine, err = props.DeleteUnexpandedPropsFromString(commandLine) if err != nil { - return nil, utils.WrapError(err) + return nil, i18n.WrapError(err) } } command, err := utils.PrepareCommand(commandLine, logger) if err != nil { - return nil, utils.WrapError(err) + return nil, i18n.WrapError(err) } if echoCommandLine { @@ -330,7 +330,7 @@ func PrepareCommandForRecipe(properties props.PropertiesMap, recipe string, remo func ExecRecipeCollectStdErr(properties props.PropertiesMap, recipe string, removeUnsetProperties bool, echoCommandLine bool, echoOutput bool, logger i18n.Logger) (string, error) { command, err := PrepareCommandForRecipe(properties, recipe, removeUnsetProperties, echoCommandLine, echoOutput, logger) if err != nil { - return "", utils.WrapError(err) + return "", i18n.WrapError(err) } buffer := &bytes.Buffer{} diff --git a/src/arduino.cc/builder/coan_runner.go b/src/arduino.cc/builder/coan_runner.go index b29d9178..3c71747a 100644 --- a/src/arduino.cc/builder/coan_runner.go +++ b/src/arduino.cc/builder/coan_runner.go @@ -52,13 +52,13 @@ func (s *CoanRunner) Run(context map[string]interface{}, ctx *types.Context) err preprocPath := context[constants.CTX_PREPROC_PATH].(string) err := utils.EnsureFolderExists(preprocPath) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } coanTargetFileName := filepath.Join(preprocPath, constants.FILE_COAN_TARGET) err = utils.WriteFile(coanTargetFileName, source) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } buildProperties := context[constants.CTX_BUILD_PROPERTIES].(props.PropertiesMap) @@ -66,12 +66,13 @@ func (s *CoanRunner) Run(context map[string]interface{}, ctx *types.Context) err properties.Merge(buildProperties.SubTree(constants.BUILD_PROPERTIES_TOOLS_KEY).SubTree(constants.COAN)) properties[constants.BUILD_PROPERTIES_SOURCE_FILE] = coanTargetFileName + logger := ctx.GetLogger() + pattern := properties[constants.BUILD_PROPERTIES_PATTERN] if pattern == constants.EMPTY_STRING { - return utils.Errorf(context, constants.MSG_PATTERN_MISSING, constants.COAN) + return i18n.ErrorfWithLogger(logger, constants.MSG_PATTERN_MISSING, constants.COAN) } - logger := context[constants.CTX_LOGGER].(i18n.Logger) commandLine := properties.ExpandPropsInString(pattern) command, err := utils.PrepareCommandFilteredArgs(commandLine, filterAllowedArg, logger) diff --git a/src/arduino.cc/builder/collect_all_source_files_from_folders_with_sources.go b/src/arduino.cc/builder/collect_all_source_files_from_folders_with_sources.go index 834aa912..a2e20a34 100644 --- a/src/arduino.cc/builder/collect_all_source_files_from_folders_with_sources.go +++ b/src/arduino.cc/builder/collect_all_source_files_from_folders_with_sources.go @@ -32,6 +32,7 @@ package builder import ( "arduino.cc/builder/constants" "arduino.cc/builder/gohasissues" + "arduino.cc/builder/i18n" "arduino.cc/builder/types" "arduino.cc/builder/utils" "io/ioutil" @@ -56,7 +57,7 @@ func (s *CollectAllSourceFilesFromFoldersWithSources) Run(context map[string]int err = collectByReadDir(&filePaths, sourceFolder.Folder) } if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } } @@ -75,7 +76,7 @@ func collectByWalk(filePaths *[]string, folder string) error { } walkFunc := utils.CollectAllReadableFiles(filePaths, checkExtensionFunc) err := gohasissues.Walk(folder, walkFunc) - return utils.WrapError(err) + return i18n.WrapError(err) } func collectByReadDir(filePaths *[]string, folder string) error { @@ -85,7 +86,7 @@ func collectByReadDir(filePaths *[]string, folder string) error { files, err := ioutil.ReadDir(folder) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } for _, file := range files { ext := strings.ToLower(filepath.Ext(file.Name())) diff --git a/src/arduino.cc/builder/constants/constants.go b/src/arduino.cc/builder/constants/constants.go index d10f09f7..29173fac 100644 --- a/src/arduino.cc/builder/constants/constants.go +++ b/src/arduino.cc/builder/constants/constants.go @@ -89,7 +89,6 @@ const CTX_CTAGS_OF_PREPROC_SOURCE = "ctagsOfPreprocSource" const CTX_CTAGS_OF_SOURCE = "ctagsOfSource" const CTX_CTAGS_OUTPUT = "ctagsOutput" const CTX_CTAGS_TEMP_FILE_PATH = "ctagsTempFilePath" -const CTX_DEBUG_LEVEL = "debugLevel" const CTX_DEBUG_PREPROCESSOR = "debugPreprocessor" const CTX_FILE_PATH_TO_READ = "filePathToRead" const CTX_FOLDERS_WITH_SOURCES_QUEUE = "foldersWithSourcesQueue" @@ -108,7 +107,6 @@ const CTX_LIBRARIES = "libraries" const CTX_LIBRARY_RESOLUTION_RESULTS = "libraryResolutionResults" const CTX_LINE_OFFSET = "lineOffset" const CTX_LINE_WHERE_TO_INSERT_PROTOTYPES = "lineWhereToInsertPrototypes" -const CTX_LOGGER = "logger" const CTX_OBJECT_FILES_CORE = "objectFilesCore" const CTX_OBJECT_FILES_LIBRARIES = "objectFilesLibraries" const CTX_OBJECT_FILES_SKETCH = "objectFilesSketch" diff --git a/src/arduino.cc/builder/container_add_prototypes.go b/src/arduino.cc/builder/container_add_prototypes.go index 8c22dabe..16bd884f 100644 --- a/src/arduino.cc/builder/container_add_prototypes.go +++ b/src/arduino.cc/builder/container_add_prototypes.go @@ -32,8 +32,8 @@ package builder import ( "arduino.cc/builder/constants" "arduino.cc/builder/ctags" + "arduino.cc/builder/i18n" "arduino.cc/builder/types" - "arduino.cc/builder/utils" ) type ContainerAddPrototypes struct{} @@ -52,10 +52,10 @@ func (s *ContainerAddPrototypes) Run(context map[string]interface{}, ctx *types. } for _, command := range commands { - PrintRingNameIfDebug(context, command) + PrintRingNameIfDebug(ctx, command) err := command.Run(context, ctx) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } } diff --git a/src/arduino.cc/builder/container_build_options.go b/src/arduino.cc/builder/container_build_options.go index 3ca87d6b..d7407206 100644 --- a/src/arduino.cc/builder/container_build_options.go +++ b/src/arduino.cc/builder/container_build_options.go @@ -30,8 +30,8 @@ package builder import ( + "arduino.cc/builder/i18n" "arduino.cc/builder/types" - "arduino.cc/builder/utils" ) type ContainerBuildOptions struct{} @@ -45,10 +45,10 @@ func (s *ContainerBuildOptions) Run(context map[string]interface{}, ctx *types.C } for _, command := range commands { - PrintRingNameIfDebug(context, command) + PrintRingNameIfDebug(ctx, command) err := command.Run(context, ctx) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } } diff --git a/src/arduino.cc/builder/container_find_includes.go b/src/arduino.cc/builder/container_find_includes.go index ca70f821..067d768d 100644 --- a/src/arduino.cc/builder/container_find_includes.go +++ b/src/arduino.cc/builder/container_find_includes.go @@ -31,6 +31,7 @@ package builder import ( "arduino.cc/builder/constants" + "arduino.cc/builder/i18n" "arduino.cc/builder/types" "arduino.cc/builder/utils" "path/filepath" @@ -41,14 +42,14 @@ type ContainerFindIncludes struct{} func (s *ContainerFindIncludes) Run(context map[string]interface{}, ctx *types.Context) error { err := runCommand(context, ctx, &IncludesToIncludeFolders{}) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } sketchBuildPath := context[constants.CTX_SKETCH_BUILD_PATH].(string) sketch := context[constants.CTX_SKETCH].(*types.Sketch) err = findIncludesUntilDone(context, ctx, filepath.Join(sketchBuildPath, filepath.Base(sketch.MainFile.Name)+".cpp")) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } foldersWithSources := context[constants.CTX_FOLDERS_WITH_SOURCES_QUEUE].(*types.UniqueSourceFolderQueue) @@ -64,7 +65,7 @@ func (s *ContainerFindIncludes) Run(context map[string]interface{}, ctx *types.C err = runCommand(context, ctx, &CollectAllSourceFilesFromFoldersWithSources{}) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } sourceFilePaths := context[constants.CTX_COLLECTED_SOURCE_FILES_QUEUE].(*types.UniqueStringQueue) @@ -72,27 +73,27 @@ func (s *ContainerFindIncludes) Run(context map[string]interface{}, ctx *types.C for !sourceFilePaths.Empty() { err = findIncludesUntilDone(context, ctx, sourceFilePaths.Pop().(string)) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } err := runCommand(context, ctx, &CollectAllSourceFilesFromFoldersWithSources{}) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } } err = runCommand(context, ctx, &FailIfImportedLibraryIsWrong{}) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } return nil } func runCommand(context map[string]interface{}, ctx *types.Context, command types.Command) error { - PrintRingNameIfDebug(context, command) + PrintRingNameIfDebug(ctx, command) err := command.Run(context, ctx) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } return nil } @@ -110,14 +111,14 @@ func findIncludesUntilDone(context map[string]interface{}, ctx *types.Context, s for _, command := range commands { err := runCommand(context, ctx, command) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } } if len(context[constants.CTX_INCLUDES_JUST_FOUND].([]string)) == 0 { done = true } else if len(context[constants.CTX_IMPORTED_LIBRARIES].([]*types.Library)) == len(importedLibraries) { err := runCommand(context, ctx, &GCCPreprocRunner{TargetFileName: constants.FILE_CTAGS_TARGET_FOR_GCC_MINUS_E}) - return utils.WrapError(err) + return i18n.WrapError(err) } importedLibraries = context[constants.CTX_IMPORTED_LIBRARIES].([]*types.Library) context[constants.CTX_INCLUDES_JUST_FOUND] = []string{} diff --git a/src/arduino.cc/builder/container_merge_copy_sketch_files.go b/src/arduino.cc/builder/container_merge_copy_sketch_files.go index 0dcb890b..3f6d2500 100644 --- a/src/arduino.cc/builder/container_merge_copy_sketch_files.go +++ b/src/arduino.cc/builder/container_merge_copy_sketch_files.go @@ -30,8 +30,8 @@ package builder import ( + "arduino.cc/builder/i18n" "arduino.cc/builder/types" - "arduino.cc/builder/utils" ) type ContainerMergeCopySketchFiles struct{} @@ -44,10 +44,10 @@ func (s *ContainerMergeCopySketchFiles) Run(context map[string]interface{}, ctx } for _, command := range commands { - PrintRingNameIfDebug(context, command) + PrintRingNameIfDebug(ctx, command) err := command.Run(context, ctx) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } } diff --git a/src/arduino.cc/builder/container_setup.go b/src/arduino.cc/builder/container_setup.go index a0315e6a..8fe2435c 100644 --- a/src/arduino.cc/builder/container_setup.go +++ b/src/arduino.cc/builder/container_setup.go @@ -30,8 +30,8 @@ package builder import ( + "arduino.cc/builder/i18n" "arduino.cc/builder/types" - "arduino.cc/builder/utils" ) type ContainerSetupHardwareToolsLibsSketchAndProps struct{} @@ -55,10 +55,10 @@ func (s *ContainerSetupHardwareToolsLibsSketchAndProps) Run(context map[string]i } for _, command := range commands { - PrintRingNameIfDebug(context, command) + PrintRingNameIfDebug(ctx, command) err := command.Run(context, ctx) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } } diff --git a/src/arduino.cc/builder/create_build_options_map.go b/src/arduino.cc/builder/create_build_options_map.go index 965ca3a3..f603a688 100644 --- a/src/arduino.cc/builder/create_build_options_map.go +++ b/src/arduino.cc/builder/create_build_options_map.go @@ -31,8 +31,8 @@ package builder import ( "arduino.cc/builder/constants" + "arduino.cc/builder/i18n" "arduino.cc/builder/types" - "arduino.cc/builder/utils" "encoding/json" ) @@ -44,7 +44,7 @@ func (s *CreateBuildOptionsMap) Run(context map[string]interface{}, ctx *types.C bytes, err := json.MarshalIndent(buildOptions, "", " ") if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } context[constants.CTX_BUILD_OPTIONS_JSON] = string(bytes) diff --git a/src/arduino.cc/builder/ctags/ctags_parser.go b/src/arduino.cc/builder/ctags/ctags_parser.go index 2d1c7603..3834bc53 100644 --- a/src/arduino.cc/builder/ctags/ctags_parser.go +++ b/src/arduino.cc/builder/ctags/ctags_parser.go @@ -32,7 +32,6 @@ package ctags import ( "arduino.cc/builder/constants" "arduino.cc/builder/types" - "arduino.cc/builder/utils" "bufio" "os" "reflect" @@ -67,12 +66,12 @@ func (s *CTagsParser) Run(context map[string]interface{}, ctx *types.Context) er tags = append(tags, parseTag(row)) } - skipTagsWhere(tags, tagIsUnknown, context) - skipTagsWhere(tags, tagIsUnhandled, context) + skipTagsWhere(tags, tagIsUnknown, ctx) + skipTagsWhere(tags, tagIsUnhandled, ctx) addPrototypes(tags) - removeDefinedProtypes(tags, context) + removeDefinedProtypes(tags, ctx) removeDuplicate(tags) - skipTagsWhere(tags, prototypeAndCodeDontMatch, context) + skipTagsWhere(tags, prototypeAndCodeDontMatch, ctx) context[constants.CTX_CTAGS_OF_PREPROC_SOURCE] = tags @@ -109,7 +108,7 @@ func addPrototype(tag *types.CTag) { tag.PrototypeModifiers = strings.TrimSpace(tag.PrototypeModifiers) } -func removeDefinedProtypes(tags []*types.CTag, context map[string]interface{}) { +func removeDefinedProtypes(tags []*types.CTag, ctx *types.Context) { definedPrototypes := make(map[string]bool) for _, tag := range tags { if tag.Kind == KIND_PROTOTYPE { @@ -119,8 +118,8 @@ func removeDefinedProtypes(tags []*types.CTag, context map[string]interface{}) { for _, tag := range tags { if definedPrototypes[tag.Prototype] { - if utils.DebugLevel(context) >= 10 { - utils.Logger(context).Fprintln(os.Stdout, constants.LOG_LEVEL_DEBUG, constants.MSG_SKIPPING_TAG_ALREADY_DEFINED, tag.FunctionName) + if ctx.DebugLevel >= 10 { + ctx.GetLogger().Fprintln(os.Stdout, constants.LOG_LEVEL_DEBUG, constants.MSG_SKIPPING_TAG_ALREADY_DEFINED, tag.FunctionName) } tag.SkipMe = true } @@ -141,12 +140,12 @@ func removeDuplicate(tags []*types.CTag) { type skipFuncType func(tag *types.CTag) bool -func skipTagsWhere(tags []*types.CTag, skipFunc skipFuncType, context map[string]interface{}) { +func skipTagsWhere(tags []*types.CTag, skipFunc skipFuncType, ctx *types.Context) { for _, tag := range tags { if !tag.SkipMe { skip := skipFunc(tag) - if skip && utils.DebugLevel(context) >= 10 { - utils.Logger(context).Fprintln(os.Stdout, constants.LOG_LEVEL_DEBUG, constants.MSG_SKIPPING_TAG_WITH_REASON, tag.FunctionName, runtime.FuncForPC(reflect.ValueOf(skipFunc).Pointer()).Name()) + if skip && ctx.DebugLevel >= 10 { + ctx.GetLogger().Fprintln(os.Stdout, constants.LOG_LEVEL_DEBUG, constants.MSG_SKIPPING_TAG_WITH_REASON, tag.FunctionName, runtime.FuncForPC(reflect.ValueOf(skipFunc).Pointer()).Name()) } tag.SkipMe = skip } diff --git a/src/arduino.cc/builder/ctags/ctags_runner.go b/src/arduino.cc/builder/ctags/ctags_runner.go index 542decab..592329f8 100644 --- a/src/arduino.cc/builder/ctags/ctags_runner.go +++ b/src/arduino.cc/builder/ctags/ctags_runner.go @@ -43,7 +43,7 @@ type CTagsRunner struct{} func (s *CTagsRunner) Run(context map[string]interface{}, ctx *types.Context) error { buildProperties := context[constants.CTX_BUILD_PROPERTIES].(props.PropertiesMap) ctagsTargetFilePath := context[constants.CTX_CTAGS_TEMP_FILE_PATH].(string) - logger := context[constants.CTX_LOGGER].(i18n.Logger) + logger := ctx.GetLogger() properties := buildProperties.Clone() properties.Merge(buildProperties.SubTree(constants.BUILD_PROPERTIES_TOOLS_KEY).SubTree(constants.CTAGS)) @@ -51,13 +51,13 @@ func (s *CTagsRunner) Run(context map[string]interface{}, ctx *types.Context) er pattern := properties[constants.BUILD_PROPERTIES_PATTERN] if pattern == constants.EMPTY_STRING { - return utils.Errorf(context, constants.MSG_PATTERN_MISSING, constants.CTAGS) + return i18n.ErrorfWithLogger(logger, constants.MSG_PATTERN_MISSING, constants.CTAGS) } commandLine := properties.ExpandPropsInString(pattern) command, err := utils.PrepareCommand(commandLine, logger) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } verbose := context[constants.CTX_VERBOSE].(bool) @@ -67,7 +67,7 @@ func (s *CTagsRunner) Run(context map[string]interface{}, ctx *types.Context) er sourceBytes, err := command.Output() if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } context[constants.CTX_CTAGS_OUTPUT] = string(sourceBytes) diff --git a/src/arduino.cc/builder/ctags_target_file_saver.go b/src/arduino.cc/builder/ctags_target_file_saver.go index 32c0e16e..d7c24918 100644 --- a/src/arduino.cc/builder/ctags_target_file_saver.go +++ b/src/arduino.cc/builder/ctags_target_file_saver.go @@ -31,6 +31,7 @@ package builder import ( "arduino.cc/builder/constants" + "arduino.cc/builder/i18n" "arduino.cc/builder/types" "arduino.cc/builder/utils" "path/filepath" @@ -47,13 +48,13 @@ func (s *CTagsTargetFileSaver) Run(context map[string]interface{}, ctx *types.Co preprocPath := context[constants.CTX_PREPROC_PATH].(string) err := utils.EnsureFolderExists(preprocPath) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } ctagsTargetFilePath := filepath.Join(preprocPath, s.TargetFileName) err = utils.WriteFile(ctagsTargetFilePath, source) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } context[constants.CTX_CTAGS_TEMP_FILE_PATH] = ctagsTargetFilePath diff --git a/src/arduino.cc/builder/ensure_buildpath_exists.go b/src/arduino.cc/builder/ensure_buildpath_exists.go index 884bdcfe..fe191c2b 100644 --- a/src/arduino.cc/builder/ensure_buildpath_exists.go +++ b/src/arduino.cc/builder/ensure_buildpath_exists.go @@ -31,6 +31,7 @@ package builder import ( "arduino.cc/builder/constants" + "arduino.cc/builder/i18n" "arduino.cc/builder/types" "arduino.cc/builder/utils" ) @@ -42,7 +43,7 @@ func (s *EnsureBuildPathExists) Run(context map[string]interface{}, ctx *types.C err := utils.EnsureFolderExists(buildPath) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } return nil diff --git a/src/arduino.cc/builder/fail_if_buildpath_equals_sketchpath.go b/src/arduino.cc/builder/fail_if_buildpath_equals_sketchpath.go index fdf75844..ecae0085 100644 --- a/src/arduino.cc/builder/fail_if_buildpath_equals_sketchpath.go +++ b/src/arduino.cc/builder/fail_if_buildpath_equals_sketchpath.go @@ -31,6 +31,7 @@ package builder import ( "arduino.cc/builder/constants" + "arduino.cc/builder/i18n" "arduino.cc/builder/types" "arduino.cc/builder/utils" "path/filepath" @@ -45,17 +46,17 @@ func (s *FailIfBuildPathEqualsSketchPath) Run(context map[string]interface{}, ct buildPath, err := filepath.Abs(context[constants.CTX_BUILD_PATH].(string)) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } sketchPath, err := filepath.Abs(ctx.SketchLocation) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } sketchPath = filepath.Dir(sketchPath) if buildPath == sketchPath { - return utils.Errorf(context, constants.MSG_SKETCH_CANT_BE_IN_BUILDPATH) + return i18n.ErrorfWithLogger(ctx.GetLogger(), constants.MSG_SKETCH_CANT_BE_IN_BUILDPATH) } return nil diff --git a/src/arduino.cc/builder/fail_if_imported_library_is_wrong.go b/src/arduino.cc/builder/fail_if_imported_library_is_wrong.go index 090ae00b..57d412a1 100644 --- a/src/arduino.cc/builder/fail_if_imported_library_is_wrong.go +++ b/src/arduino.cc/builder/fail_if_imported_library_is_wrong.go @@ -45,22 +45,22 @@ func (s *FailIfImportedLibraryIsWrong) Run(context map[string]interface{}, ctx * return nil } - logger := context[constants.CTX_LOGGER].(i18n.Logger) + logger := ctx.GetLogger() importedLibraries := context[constants.CTX_IMPORTED_LIBRARIES].([]*types.Library) for _, library := range importedLibraries { if !library.IsLegacy { if stat, err := os.Stat(filepath.Join(library.Folder, constants.LIBRARY_FOLDER_ARCH)); err == nil && stat.IsDir() { - return utils.ErrorfWithLogger(logger, constants.MSG_ARCH_FOLDER_NOT_SUPPORTED) + return i18n.ErrorfWithLogger(logger, constants.MSG_ARCH_FOLDER_NOT_SUPPORTED) } for _, propName := range LIBRARY_MANDATORY_PROPERTIES { if _, ok := library.Properties[propName]; !ok { - return utils.ErrorfWithLogger(logger, constants.MSG_PROP_IN_LIBRARY, propName, library.Folder) + return i18n.ErrorfWithLogger(logger, constants.MSG_PROP_IN_LIBRARY, propName, library.Folder) } } if library.Layout == types.LIBRARY_RECURSIVE { if stat, err := os.Stat(filepath.Join(library.Folder, constants.LIBRARY_FOLDER_UTILITY)); err == nil && stat.IsDir() { - return utils.ErrorfWithLogger(logger, constants.MSG_LIBRARY_CAN_USE_SRC_AND_UTILITY_FOLDERS, library.Folder) + return i18n.ErrorfWithLogger(logger, constants.MSG_LIBRARY_CAN_USE_SRC_AND_UTILITY_FOLDERS, library.Folder) } } } diff --git a/src/arduino.cc/builder/gcc_preproc_runner.go b/src/arduino.cc/builder/gcc_preproc_runner.go index d4dd7352..c6d36346 100644 --- a/src/arduino.cc/builder/gcc_preproc_runner.go +++ b/src/arduino.cc/builder/gcc_preproc_runner.go @@ -49,7 +49,7 @@ func (s *GCCPreprocRunner) Run(context map[string]interface{}, ctx *types.Contex sketch := context[constants.CTX_SKETCH].(*types.Sketch) properties, targetFilePath, err := prepareGCCPreprocRecipeProperties(context, filepath.Join(sketchBuildPath, filepath.Base(sketch.MainFile.Name)+".cpp"), s.TargetFileName) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } if properties[constants.RECIPE_PREPROC_MACROS] == constants.EMPTY_STRING { @@ -58,10 +58,10 @@ func (s *GCCPreprocRunner) Run(context map[string]interface{}, ctx *types.Contex } verbose := context[constants.CTX_VERBOSE].(bool) - logger := context[constants.CTX_LOGGER].(i18n.Logger) + logger := ctx.GetLogger() _, err = builder_utils.ExecRecipe(properties, constants.RECIPE_PREPROC_MACROS, true, verbose, false, logger) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } context[constants.CTX_FILE_PATH_TO_READ] = targetFilePath @@ -77,11 +77,11 @@ type GCCPreprocRunnerForDiscoveringIncludes struct { func (s *GCCPreprocRunnerForDiscoveringIncludes) Run(context map[string]interface{}, ctx *types.Context) error { properties, _, err := prepareGCCPreprocRecipeProperties(context, s.SourceFilePath, s.TargetFilePath) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } verbose := context[constants.CTX_VERBOSE].(bool) - logger := context[constants.CTX_LOGGER].(i18n.Logger) + logger := ctx.GetLogger() if properties[constants.RECIPE_PREPROC_MACROS] == constants.EMPTY_STRING { //generate PREPROC_MACROS from RECIPE_CPP_PATTERN @@ -90,7 +90,7 @@ func (s *GCCPreprocRunnerForDiscoveringIncludes) Run(context map[string]interfac stderr, err := builder_utils.ExecRecipeCollectStdErr(properties, constants.RECIPE_PREPROC_MACROS, true, verbose, false, logger) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } context[constants.CTX_GCC_MINUS_E_SOURCE] = string(stderr) @@ -103,7 +103,7 @@ func prepareGCCPreprocRecipeProperties(context map[string]interface{}, sourceFil preprocPath := context[constants.CTX_PREPROC_PATH].(string) err := utils.EnsureFolderExists(preprocPath) if err != nil { - return nil, "", utils.WrapError(err) + return nil, "", i18n.WrapError(err) } targetFilePath = filepath.Join(preprocPath, targetFilePath) } diff --git a/src/arduino.cc/builder/gcc_preproc_source_saver.go b/src/arduino.cc/builder/gcc_preproc_source_saver.go index 43d8e494..8eff3aec 100644 --- a/src/arduino.cc/builder/gcc_preproc_source_saver.go +++ b/src/arduino.cc/builder/gcc_preproc_source_saver.go @@ -31,6 +31,7 @@ package builder import ( "arduino.cc/builder/constants" + "arduino.cc/builder/i18n" "arduino.cc/builder/utils" "path/filepath" ) @@ -41,11 +42,11 @@ func (s *GCCPreprocSourceSaver) Run(context map[string]interface{}) error { preprocPath := context[constants.CTX_PREPROC_PATH].(string) err := utils.EnsureFolderExists(preprocPath) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } source := context[constants.CTX_SOURCE].(string) err = utils.WriteFile(filepath.Join(preprocPath, constants.FILE_GCC_PREPROC_TARGET), source) - return utils.WrapError(err) + return i18n.WrapError(err) } diff --git a/src/arduino.cc/builder/generate_buildpath_if_missing.go b/src/arduino.cc/builder/generate_buildpath_if_missing.go index fea4e076..10cf60b8 100644 --- a/src/arduino.cc/builder/generate_buildpath_if_missing.go +++ b/src/arduino.cc/builder/generate_buildpath_if_missing.go @@ -51,11 +51,11 @@ func (s *GenerateBuildPathIfMissing) Run(context map[string]interface{}, ctx *ty buildPath := filepath.Join(os.TempDir(), "arduino-sketch-"+strings.ToUpper(md5sum)) _, err := os.Stat(buildPath) if err != nil && !os.IsNotExist(err) { - return utils.WrapError(err) + return i18n.WrapError(err) } - if utils.DebugLevel(context) > 5 { - logger := context[constants.CTX_LOGGER].(i18n.Logger) + if ctx.DebugLevel > 5 { + logger := ctx.GetLogger() logger.Fprintln(os.Stdout, constants.LOG_LEVEL_WARN, constants.MSG_SETTING_BUILD_PATH, buildPath) } diff --git a/src/arduino.cc/builder/hardware_loader.go b/src/arduino.cc/builder/hardware_loader.go index d49ca400..a1efc319 100644 --- a/src/arduino.cc/builder/hardware_loader.go +++ b/src/arduino.cc/builder/hardware_loader.go @@ -42,7 +42,7 @@ import ( type HardwareLoader struct{} func (s *HardwareLoader) Run(context map[string]interface{}, ctx *types.Context) error { - logger := context[constants.CTX_LOGGER].(i18n.Logger) + logger := ctx.GetLogger() packages := &types.Packages{} packages.Packages = make(map[string]*types.Package) @@ -51,27 +51,27 @@ func (s *HardwareLoader) Run(context map[string]interface{}, ctx *types.Context) folders := ctx.HardwareFolders folders, err := utils.AbsolutizePaths(folders) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } for _, folder := range folders { stat, err := os.Stat(folder) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } if !stat.IsDir() { - return utils.Errorf(context, constants.MSG_MUST_BE_A_FOLDER, folder) + return i18n.ErrorfWithLogger(logger, constants.MSG_MUST_BE_A_FOLDER, folder) } hardwarePlatformTxt, err := props.SafeLoad(filepath.Join(folder, constants.FILE_PLATFORM_TXT), logger) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } packages.Properties.Merge(hardwarePlatformTxt) subfolders, err := utils.ReadDirFiltered(folder, utils.FilterDirs) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } subfolders = utils.FilterOutFoldersByNames(subfolders, constants.FOLDER_TOOLS) @@ -86,7 +86,7 @@ func (s *HardwareLoader) Run(context map[string]interface{}, ctx *types.Context) targetPackage := getOrCreatePackage(packages, packageId) err = loadPackage(targetPackage, subfolderPath, logger) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } packages.Packages[packageId] = targetPackage } @@ -113,13 +113,13 @@ func getOrCreatePackage(packages *types.Packages, packageId string) *types.Packa func loadPackage(targetPackage *types.Package, folder string, logger i18n.Logger) error { packagePlatformTxt, err := props.SafeLoad(filepath.Join(folder, constants.FILE_PLATFORM_TXT), logger) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } targetPackage.Properties.Merge(packagePlatformTxt) subfolders, err := utils.ReadDirFiltered(folder, utils.FilterDirs) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } subfolders = utils.FilterOutFoldersByNames(subfolders, constants.FOLDER_TOOLS) @@ -133,7 +133,7 @@ func loadPackage(targetPackage *types.Package, folder string, logger i18n.Logger if err != nil && os.IsNotExist(err) { theOnlySubfolder, err := utils.TheOnlySubfolderOf(subfolderPath) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } if theOnlySubfolder != constants.EMPTY_STRING { @@ -144,7 +144,7 @@ func loadPackage(targetPackage *types.Package, folder string, logger i18n.Logger platform := getOrCreatePlatform(platforms, platformId) err = loadPlatform(platform, targetPackage.PackageId, subfolderPath, logger) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } platforms[platformId] = platform } @@ -169,7 +169,7 @@ func getOrCreatePlatform(platforms map[string]*types.Platform, platformId string func loadPlatform(targetPlatform *types.Platform, packageId string, folder string, logger i18n.Logger) error { _, err := os.Stat(filepath.Join(folder, constants.FILE_BOARDS_TXT)) if err != nil && !os.IsNotExist(err) { - return utils.WrapError(err) + return i18n.WrapError(err) } if os.IsNotExist(err) { @@ -180,19 +180,19 @@ func loadPlatform(targetPlatform *types.Platform, packageId string, folder strin err = loadBoards(targetPlatform.Boards, packageId, targetPlatform.PlatformId, folder, logger) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } assignDefaultBoardToPlatform(targetPlatform) platformTxt, err := props.SafeLoad(filepath.Join(folder, constants.FILE_PLATFORM_TXT), logger) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } localPlatformProperties, err := props.SafeLoad(filepath.Join(folder, constants.FILE_PLATFORM_LOCAL_TXT), logger) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } targetPlatform.Properties = targetPlatform.Properties.Clone() @@ -201,7 +201,7 @@ func loadPlatform(targetPlatform *types.Platform, packageId string, folder strin programmersProperties, err := props.SafeLoad(filepath.Join(folder, constants.FILE_PROGRAMMERS_TXT), logger) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } targetPlatform.Programmers = props.MergeMapsOfProperties(make(map[string]props.PropertiesMap), targetPlatform.Programmers, programmersProperties.FirstLevelOf()) @@ -221,12 +221,12 @@ func assignDefaultBoardToPlatform(targetPlatform *types.Platform) { func loadBoards(boards map[string]*types.Board, packageId string, platformId string, folder string, logger i18n.Logger) error { properties, err := props.Load(filepath.Join(folder, constants.FILE_BOARDS_TXT), logger) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } localProperties, err := props.SafeLoad(filepath.Join(folder, constants.FILE_BOARDS_LOCAL_TXT), logger) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } properties = properties.Merge(localProperties) diff --git a/src/arduino.cc/builder/i18n/errors.go b/src/arduino.cc/builder/i18n/errors.go new file mode 100644 index 00000000..604fa1e8 --- /dev/null +++ b/src/arduino.cc/builder/i18n/errors.go @@ -0,0 +1,20 @@ +package i18n + +import "arduino.cc/builder/constants" +import "github.com/go-errors/errors" +import "os" + +func ErrorfWithLogger(logger Logger, format string, a ...interface{}) *errors.Error { + if logger.Name() == "machine" { + logger.Fprintln(os.Stderr, constants.LOG_LEVEL_ERROR, format, a...) + return errors.Errorf("") + } + return errors.Errorf(Format(format, a...)) +} + +func WrapError(err error) error { + if err == nil { + return nil + } + return errors.Wrap(err, 0) +} diff --git a/src/arduino.cc/builder/includes_finder_with_gcc.go b/src/arduino.cc/builder/includes_finder_with_gcc.go index 55648e76..741f739b 100644 --- a/src/arduino.cc/builder/includes_finder_with_gcc.go +++ b/src/arduino.cc/builder/includes_finder_with_gcc.go @@ -34,6 +34,7 @@ import ( "arduino.cc/builder/constants" "arduino.cc/builder/i18n" "arduino.cc/builder/props" + "arduino.cc/builder/types" "arduino.cc/builder/utils" "strings" ) @@ -42,13 +43,13 @@ type IncludesFinderWithGCC struct { SourceFile string } -func (s *IncludesFinderWithGCC) Run(context map[string]interface{}) error { +func (s *IncludesFinderWithGCC) Run(context map[string]interface{}, ctx *types.Context) error { buildProperties := make(props.PropertiesMap) if p, ok := context[constants.CTX_BUILD_PROPERTIES]; ok { buildProperties = p.(props.PropertiesMap).Clone() } verbose := context[constants.CTX_VERBOSE].(bool) - logger := context[constants.CTX_LOGGER].(i18n.Logger) + logger := ctx.GetLogger() includesParams := constants.EMPTY_STRING if utils.MapHas(context, constants.CTX_INCLUDE_FOLDERS) { @@ -69,7 +70,7 @@ func (s *IncludesFinderWithGCC) Run(context map[string]interface{}) error { output, err := builder_utils.ExecRecipe(properties, constants.RECIPE_PREPROC_INCLUDES, true, verbose, false, logger) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } context[constants.CTX_GCC_MINUS_M_OUTPUT] = string(output) diff --git a/src/arduino.cc/builder/includes_to_include_folders.go b/src/arduino.cc/builder/includes_to_include_folders.go index e5c21205..308f5140 100644 --- a/src/arduino.cc/builder/includes_to_include_folders.go +++ b/src/arduino.cc/builder/includes_to_include_folders.go @@ -31,6 +31,7 @@ package builder import ( "arduino.cc/builder/constants" + "arduino.cc/builder/i18n" "arduino.cc/builder/props" "arduino.cc/builder/types" "arduino.cc/builder/utils" @@ -60,7 +61,7 @@ func (s *IncludesToIncludeFolders) Run(context map[string]interface{}, ctx *type } newlyImportedLibraries, err := resolveLibraries(includes, headerToLibraries, importedLibraries, []*types.Platform{actualPlatform, platform}, libraryResolutionResults) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } foldersWithSources := context[constants.CTX_FOLDERS_WITH_SOURCES_QUEUE].(*types.UniqueSourceFolderQueue) diff --git a/src/arduino.cc/builder/libraries_loader.go b/src/arduino.cc/builder/libraries_loader.go index 37fe7699..f444b0f8 100644 --- a/src/arduino.cc/builder/libraries_loader.go +++ b/src/arduino.cc/builder/libraries_loader.go @@ -46,14 +46,14 @@ func (s *LibrariesLoader) Run(context map[string]interface{}, ctx *types.Context builtInLibrariesFolders := ctx.BuiltInLibrariesFolders builtInLibrariesFolders, err := utils.AbsolutizePaths(builtInLibrariesFolders) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } sortedLibrariesFolders := []string{} sortedLibrariesFolders = utils.AppendIfNotPresent(sortedLibrariesFolders, builtInLibrariesFolders...) platform := context[constants.CTX_TARGET_PLATFORM].(*types.Platform) - debugLevel := utils.DebugLevel(context) - logger := context[constants.CTX_LOGGER].(i18n.Logger) + debugLevel := ctx.DebugLevel + logger := ctx.GetLogger() actualPlatform := context[constants.CTX_ACTUAL_PLATFORM].(*types.Platform) if actualPlatform != platform { @@ -65,7 +65,7 @@ func (s *LibrariesLoader) Run(context map[string]interface{}, ctx *types.Context librariesFolders := ctx.OtherLibrariesFolders librariesFolders, err = utils.AbsolutizePaths(librariesFolders) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } sortedLibrariesFolders = utils.AppendIfNotPresent(sortedLibrariesFolders, librariesFolders...) @@ -75,12 +75,12 @@ func (s *LibrariesLoader) Run(context map[string]interface{}, ctx *types.Context for _, libraryFolder := range sortedLibrariesFolders { subFolders, err := utils.ReadDirFiltered(libraryFolder, utils.FilterDirs) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } for _, subFolder := range subFolders { library, err := makeLibrary(filepath.Join(libraryFolder, subFolder.Name()), debugLevel, logger) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } libraries = append(libraries, library) } @@ -92,7 +92,7 @@ func (s *LibrariesLoader) Run(context map[string]interface{}, ctx *types.Context for _, library := range libraries { headers, err := utils.ReadDirFiltered(library.SrcFolder, utils.FilterFilesWithExtension(".h")) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } for _, header := range headers { headerFileName := header.Name() @@ -115,7 +115,7 @@ func makeLibrary(libraryFolder string, debugLevel int, logger i18n.Logger) (*typ func makeNewLibrary(libraryFolder string, debugLevel int, logger i18n.Logger) (*types.Library, error) { properties, err := props.Load(filepath.Join(libraryFolder, constants.LIBRARY_PROPERTIES), logger) if err != nil { - return nil, utils.WrapError(err) + return nil, i18n.WrapError(err) } if properties[constants.LIBRARY_MAINTAINER] == constants.EMPTY_STRING && properties[constants.LIBRARY_EMAIL] != constants.EMPTY_STRING { @@ -139,10 +139,10 @@ func makeNewLibrary(libraryFolder string, debugLevel int, logger i18n.Logger) (* subFolders, err := utils.ReadDirFiltered(libraryFolder, utils.FilterDirs) if err != nil { - return nil, utils.WrapError(err) + return nil, i18n.WrapError(err) } - if debugLevel > 0 { + if debugLevel >= 0 { for _, subFolder := range subFolders { if utils.IsSCCSOrHiddenFile(subFolder) { if !utils.IsSCCSFile(subFolder) && utils.IsHiddenFile(subFolder) { diff --git a/src/arduino.cc/builder/load_previous_build_options.go b/src/arduino.cc/builder/load_previous_build_options.go index 18b79dfc..26f29682 100644 --- a/src/arduino.cc/builder/load_previous_build_options.go +++ b/src/arduino.cc/builder/load_previous_build_options.go @@ -31,8 +31,8 @@ package builder import ( "arduino.cc/builder/constants" + "arduino.cc/builder/i18n" "arduino.cc/builder/types" - "arduino.cc/builder/utils" "io/ioutil" "os" "path/filepath" @@ -50,12 +50,12 @@ func (s *LoadPreviousBuildOptionsMap) Run(context map[string]interface{}, ctx *t if os.IsNotExist(err) { return nil } - return utils.WrapError(err) + return i18n.WrapError(err) } bytes, err := ioutil.ReadFile(buildOptionsFile) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } context[constants.CTX_BUILD_OPTIONS_PREVIOUS_JSON] = string(bytes) diff --git a/src/arduino.cc/builder/load_vid_pid_specific_properties.go b/src/arduino.cc/builder/load_vid_pid_specific_properties.go index c7533847..32fb336b 100644 --- a/src/arduino.cc/builder/load_vid_pid_specific_properties.go +++ b/src/arduino.cc/builder/load_vid_pid_specific_properties.go @@ -31,6 +31,7 @@ package builder import ( "arduino.cc/builder/constants" + "arduino.cc/builder/i18n" "arduino.cc/builder/props" "arduino.cc/builder/types" "arduino.cc/builder/utils" @@ -54,7 +55,7 @@ func (s *LoadVIDPIDSpecificProperties) Run(context map[string]interface{}, ctx * buildProperties := context[constants.CTX_BUILD_PROPERTIES].(props.PropertiesMap) VIDPIDIndex, err := findVIDPIDIndex(buildProperties, vid, pid) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } if VIDPIDIndex < 0 { return nil diff --git a/src/arduino.cc/builder/merge_sketch_with_bootloader.go b/src/arduino.cc/builder/merge_sketch_with_bootloader.go index fd2a4773..588cc315 100644 --- a/src/arduino.cc/builder/merge_sketch_with_bootloader.go +++ b/src/arduino.cc/builder/merge_sketch_with_bootloader.go @@ -51,7 +51,7 @@ func (s *MergeSketchWithBootloader) Run(context map[string]interface{}, ctx *typ buildPath := context[constants.CTX_BUILD_PATH].(string) sketch := context[constants.CTX_SKETCH].(*types.Sketch) sketchFileName := filepath.Base(sketch.MainFile.Name) - logger := context[constants.CTX_LOGGER].(i18n.Logger) + logger := ctx.GetLogger() sketchInBuildPath := filepath.Join(buildPath, sketchFileName+".hex") sketchInSubfolder := filepath.Join(buildPath, constants.FOLDER_SKETCH, sketchFileName+".hex") @@ -131,13 +131,13 @@ func extractActualBootloader(bootloader []string) []string { func merge(builtSketchPath, bootloaderPath, mergedSketchPath string) error { sketch, err := utils.ReadFileToRows(builtSketchPath) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } sketch = sketch[:len(sketch)-2] bootloader, err := utils.ReadFileToRows(bootloaderPath) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } realBootloader := extractActualBootloader(bootloader) diff --git a/src/arduino.cc/builder/phases/core_builder.go b/src/arduino.cc/builder/phases/core_builder.go index a6c2ceea..d81d0b16 100644 --- a/src/arduino.cc/builder/phases/core_builder.go +++ b/src/arduino.cc/builder/phases/core_builder.go @@ -45,16 +45,16 @@ func (s *CoreBuilder) Run(context map[string]interface{}, ctx *types.Context) er buildProperties := context[constants.CTX_BUILD_PROPERTIES].(props.PropertiesMap) verbose := context[constants.CTX_VERBOSE].(bool) warningsLevel := context[constants.CTX_WARNINGS_LEVEL].(string) - logger := context[constants.CTX_LOGGER].(i18n.Logger) + logger := ctx.GetLogger() err := utils.EnsureFolderExists(coreBuildPath) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } archiveFile, objectFiles, err := compileCore(coreBuildPath, buildProperties, verbose, warningsLevel, logger) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } context[constants.CTX_ARCHIVE_FILE_PATH_CORE] = archiveFile @@ -80,18 +80,18 @@ func compileCore(buildPath string, buildProperties props.PropertiesMap, verbose if variantFolder != constants.EMPTY_STRING { variantObjectFiles, err = builder_utils.CompileFiles(variantObjectFiles, variantFolder, true, buildPath, buildProperties, includes, verbose, warningsLevel, logger) if err != nil { - return "", nil, utils.WrapError(err) + return "", nil, i18n.WrapError(err) } } coreObjectFiles, err := builder_utils.CompileFiles([]string{}, coreFolder, true, buildPath, buildProperties, includes, verbose, warningsLevel, logger) if err != nil { - return "", nil, utils.WrapError(err) + return "", nil, i18n.WrapError(err) } archiveFile, err := builder_utils.ArchiveCompiledFiles(buildPath, "core.a", coreObjectFiles, buildProperties, verbose, logger) if err != nil { - return "", nil, utils.WrapError(err) + return "", nil, i18n.WrapError(err) } return archiveFile, variantObjectFiles, nil diff --git a/src/arduino.cc/builder/phases/libraries_builder.go b/src/arduino.cc/builder/phases/libraries_builder.go index 07baf8bc..f74fdaac 100644 --- a/src/arduino.cc/builder/phases/libraries_builder.go +++ b/src/arduino.cc/builder/phases/libraries_builder.go @@ -50,16 +50,16 @@ func (s *LibrariesBuilder) Run(context map[string]interface{}, ctx *types.Contex libraries := context[constants.CTX_IMPORTED_LIBRARIES].([]*types.Library) verbose := context[constants.CTX_VERBOSE].(bool) warningsLevel := context[constants.CTX_WARNINGS_LEVEL].(string) - logger := context[constants.CTX_LOGGER].(i18n.Logger) + logger := ctx.GetLogger() err := utils.EnsureFolderExists(librariesBuildPath) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } objectFiles, err := compileLibraries(libraries, librariesBuildPath, buildProperties, includes, verbose, warningsLevel, logger) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } context[constants.CTX_OBJECT_FILES_LIBRARIES] = objectFiles @@ -72,7 +72,7 @@ func compileLibraries(libraries []*types.Library, buildPath string, buildPropert for _, library := range libraries { libraryObjectFiles, err := compileLibrary(library, buildPath, buildProperties, includes, verbose, warningsLevel, logger) if err != nil { - return nil, utils.WrapError(err) + return nil, i18n.WrapError(err) } objectFiles = append(objectFiles, libraryObjectFiles...) } @@ -86,19 +86,19 @@ func compileLibrary(library *types.Library, buildPath string, buildProperties pr err := utils.EnsureFolderExists(libraryBuildPath) if err != nil { - return nil, utils.WrapError(err) + return nil, i18n.WrapError(err) } objectFiles := []string{} if library.Layout == types.LIBRARY_RECURSIVE { objectFiles, err = builder_utils.CompileFilesRecursive(objectFiles, library.SrcFolder, libraryBuildPath, buildProperties, includes, verbose, warningsLevel, logger) if err != nil { - return nil, utils.WrapError(err) + return nil, i18n.WrapError(err) } if library.DotALinkage { archiveFile, err := builder_utils.ArchiveCompiledFiles(libraryBuildPath, library.Name+".a", objectFiles, buildProperties, verbose, logger) if err != nil { - return nil, utils.WrapError(err) + return nil, i18n.WrapError(err) } objectFiles = []string{archiveFile} } @@ -110,14 +110,14 @@ func compileLibrary(library *types.Library, buildPath string, buildProperties pr } objectFiles, err = builder_utils.CompileFiles(objectFiles, library.SrcFolder, false, libraryBuildPath, buildProperties, includes, verbose, warningsLevel, logger) if err != nil { - return nil, utils.WrapError(err) + return nil, i18n.WrapError(err) } if utilitySourcePathErr == nil { utilityBuildPath := filepath.Join(libraryBuildPath, constants.LIBRARY_FOLDER_UTILITY) objectFiles, err = builder_utils.CompileFiles(objectFiles, utilitySourcePath, false, utilityBuildPath, buildProperties, includes, verbose, warningsLevel, logger) if err != nil { - return nil, utils.WrapError(err) + return nil, i18n.WrapError(err) } } } diff --git a/src/arduino.cc/builder/phases/linker.go b/src/arduino.cc/builder/phases/linker.go index e1a832f0..b6b32036 100644 --- a/src/arduino.cc/builder/phases/linker.go +++ b/src/arduino.cc/builder/phases/linker.go @@ -56,17 +56,17 @@ func (s *Linker) Run(context map[string]interface{}, ctx *types.Context) error { buildPath := context[constants.CTX_BUILD_PATH].(string) coreDotARelPath, err := filepath.Rel(buildPath, coreArchiveFilePath) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } buildProperties := context[constants.CTX_BUILD_PROPERTIES].(props.PropertiesMap) verbose := context[constants.CTX_VERBOSE].(bool) warningsLevel := context[constants.CTX_WARNINGS_LEVEL].(string) - logger := context[constants.CTX_LOGGER].(i18n.Logger) + logger := ctx.GetLogger() err = link(objectFiles, coreDotARelPath, coreArchiveFilePath, buildProperties, verbose, warningsLevel, logger) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } return nil diff --git a/src/arduino.cc/builder/phases/sketch_builder.go b/src/arduino.cc/builder/phases/sketch_builder.go index a5f19d65..b1392a7b 100644 --- a/src/arduino.cc/builder/phases/sketch_builder.go +++ b/src/arduino.cc/builder/phases/sketch_builder.go @@ -47,17 +47,17 @@ func (s *SketchBuilder) Run(context map[string]interface{}, ctx *types.Context) includes = utils.Map(includes, utils.WrapWithHyphenI) verbose := context[constants.CTX_VERBOSE].(bool) warningsLevel := context[constants.CTX_WARNINGS_LEVEL].(string) - logger := context[constants.CTX_LOGGER].(i18n.Logger) + logger := ctx.GetLogger() err := utils.EnsureFolderExists(sketchBuildPath) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } var objectFiles []string objectFiles, err = builder_utils.CompileFiles(objectFiles, sketchBuildPath, true, sketchBuildPath, buildProperties, includes, verbose, warningsLevel, logger) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } context[constants.CTX_OBJECT_FILES_SKETCH] = objectFiles diff --git a/src/arduino.cc/builder/platform_keys_rewrite_loader.go b/src/arduino.cc/builder/platform_keys_rewrite_loader.go index 8b597b2c..3eba6f75 100644 --- a/src/arduino.cc/builder/platform_keys_rewrite_loader.go +++ b/src/arduino.cc/builder/platform_keys_rewrite_loader.go @@ -45,12 +45,12 @@ import ( type PlatformKeysRewriteLoader struct{} func (s *PlatformKeysRewriteLoader) Run(context map[string]interface{}, ctx *types.Context) error { - logger := context[constants.CTX_LOGGER].(i18n.Logger) + logger := ctx.GetLogger() folders := ctx.HardwareFolders platformKeysRewriteTxtPath, err := findPlatformKeysRewriteTxt(folders) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } if platformKeysRewriteTxtPath == constants.EMPTY_STRING { return nil @@ -68,7 +68,7 @@ func (s *PlatformKeysRewriteLoader) Run(context map[string]interface{}, ctx *typ if keyParts[0] == constants.PLATFORM_REWRITE_OLD { index, err := strconv.Atoi(keyParts[1]) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } rewriteKey := strings.Join(keyParts[2:], ".") oldValue := txt[key] @@ -92,7 +92,7 @@ func findPlatformKeysRewriteTxt(folders []string) (string, error) { return txtPath, nil } if !os.IsNotExist(err) { - return constants.EMPTY_STRING, utils.WrapError(err) + return constants.EMPTY_STRING, i18n.WrapError(err) } } diff --git a/src/arduino.cc/builder/print_used_and_not_used_libraries.go b/src/arduino.cc/builder/print_used_and_not_used_libraries.go index 28c9f99a..212eebae 100644 --- a/src/arduino.cc/builder/print_used_and_not_used_libraries.go +++ b/src/arduino.cc/builder/print_used_and_not_used_libraries.go @@ -31,9 +31,7 @@ package builder import ( "arduino.cc/builder/constants" - "arduino.cc/builder/i18n" "arduino.cc/builder/types" - "arduino.cc/builder/utils" "os" "time" ) @@ -41,11 +39,11 @@ import ( type PrintUsedAndNotUsedLibraries struct{} func (s *PrintUsedAndNotUsedLibraries) Run(context map[string]interface{}, ctx *types.Context) error { - if utils.DebugLevel(context) <= 0 { + if ctx.DebugLevel < 0 { return nil } - logger := context[constants.CTX_LOGGER].(i18n.Logger) + logger := ctx.GetLogger() libraryResolutionResults := context[constants.CTX_LIBRARY_RESOLUTION_RESULTS].(map[string]types.LibraryResolutionResult) for header, libResResult := range libraryResolutionResults { diff --git a/src/arduino.cc/builder/print_used_libraries_if_verbose.go b/src/arduino.cc/builder/print_used_libraries_if_verbose.go index c67a0e74..2d9cf2f6 100644 --- a/src/arduino.cc/builder/print_used_libraries_if_verbose.go +++ b/src/arduino.cc/builder/print_used_libraries_if_verbose.go @@ -31,7 +31,6 @@ package builder import ( "arduino.cc/builder/constants" - "arduino.cc/builder/i18n" "arduino.cc/builder/types" "arduino.cc/builder/utils" "time" @@ -41,7 +40,7 @@ type PrintUsedLibrariesIfVerbose struct{} func (s *PrintUsedLibrariesIfVerbose) Run(context map[string]interface{}, ctx *types.Context) error { verbose := context[constants.CTX_VERBOSE].(bool) - logger := context[constants.CTX_LOGGER].(i18n.Logger) + logger := ctx.GetLogger() if !verbose || !utils.MapHas(context, constants.CTX_IMPORTED_LIBRARIES) { return nil diff --git a/src/arduino.cc/builder/props/properties.go b/src/arduino.cc/builder/props/properties.go index 68ef4861..e1132f3e 100644 --- a/src/arduino.cc/builder/props/properties.go +++ b/src/arduino.cc/builder/props/properties.go @@ -32,7 +32,6 @@ package props import ( "arduino.cc/builder/constants" "arduino.cc/builder/i18n" - "arduino.cc/builder/utils" "github.com/go-errors/errors" "io/ioutil" "os" @@ -61,7 +60,7 @@ func init() { func Load(filepath string, logger i18n.Logger) (PropertiesMap, error) { bytes, err := ioutil.ReadFile(filepath) if err != nil { - return nil, utils.WrapError(err) + return nil, err } text := string(bytes) @@ -73,7 +72,7 @@ func Load(filepath string, logger i18n.Logger) (PropertiesMap, error) { for _, line := range strings.Split(text, "\n") { err := properties.loadSingleLine(line) if err != nil { - return nil, utils.ErrorfWithLogger(logger, constants.MSG_WRONG_PROPERTIES_FILE, line, filepath) + return nil, i18n.ErrorfWithLogger(logger, constants.MSG_WRONG_PROPERTIES_FILE, line, filepath) } } @@ -86,7 +85,7 @@ func LoadFromSlice(lines []string, logger i18n.Logger) (PropertiesMap, error) { for _, line := range lines { err := properties.loadSingleLine(line) if err != nil { - return nil, utils.ErrorfWithLogger(logger, constants.MSG_WRONG_PROPERTIES, line) + return nil, i18n.ErrorfWithLogger(logger, constants.MSG_WRONG_PROPERTIES, line) } } @@ -119,7 +118,7 @@ func SafeLoad(filepath string, logger i18n.Logger) (PropertiesMap, error) { properties, err := Load(filepath, logger) if err != nil { - return nil, utils.WrapError(err) + return nil, i18n.WrapError(err) } return properties, nil } @@ -183,7 +182,7 @@ func MergeMapsOfProperties(target map[string]PropertiesMap, sources ...map[strin func DeleteUnexpandedPropsFromString(str string) (string, error) { rxp, err := regexp.Compile("\\{.+?\\}") if err != nil { - return constants.EMPTY_STRING, utils.WrapError(err) + return constants.EMPTY_STRING, i18n.WrapError(err) } return rxp.ReplaceAllString(str, constants.EMPTY_STRING), nil diff --git a/src/arduino.cc/builder/read_file_and_store_in_context.go b/src/arduino.cc/builder/read_file_and_store_in_context.go index d3071837..444a7dc4 100644 --- a/src/arduino.cc/builder/read_file_and_store_in_context.go +++ b/src/arduino.cc/builder/read_file_and_store_in_context.go @@ -31,8 +31,8 @@ package builder import ( "arduino.cc/builder/constants" + "arduino.cc/builder/i18n" "arduino.cc/builder/types" - "arduino.cc/builder/utils" "io/ioutil" ) @@ -43,7 +43,7 @@ type ReadFileAndStoreInContext struct { func (s *ReadFileAndStoreInContext) Run(context map[string]interface{}, ctx *types.Context) error { bytes, err := ioutil.ReadFile(context[constants.CTX_FILE_PATH_TO_READ].(string)) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } context[s.TargetField] = string(bytes) diff --git a/src/arduino.cc/builder/recipe_runner.go b/src/arduino.cc/builder/recipe_runner.go index 9f965741..5844fd9d 100644 --- a/src/arduino.cc/builder/recipe_runner.go +++ b/src/arduino.cc/builder/recipe_runner.go @@ -35,7 +35,6 @@ import ( "arduino.cc/builder/i18n" "arduino.cc/builder/props" "arduino.cc/builder/types" - "arduino.cc/builder/utils" "os" "sort" "strings" @@ -47,8 +46,8 @@ type RecipeByPrefixSuffixRunner struct { } func (s *RecipeByPrefixSuffixRunner) Run(context map[string]interface{}, ctx *types.Context) error { - logger := context[constants.CTX_LOGGER].(i18n.Logger) - if utils.DebugLevel(context) >= 10 { + logger := ctx.GetLogger() + if ctx.DebugLevel >= 10 { logger.Fprintln(os.Stdout, constants.LOG_LEVEL_DEBUG, constants.MSG_LOOKING_FOR_RECIPES, s.Prefix, s.Suffix) } @@ -62,12 +61,12 @@ func (s *RecipeByPrefixSuffixRunner) Run(context map[string]interface{}, ctx *ty properties := buildProperties.Clone() for _, recipe := range recipes { - if utils.DebugLevel(context) >= 10 { + if ctx.DebugLevel >= 10 { logger.Fprintln(os.Stdout, constants.LOG_LEVEL_DEBUG, constants.MSG_RUNNING_RECIPE, recipe) } _, err := builder_utils.ExecRecipe(properties, recipe, false, verbose, verbose, logger) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } } diff --git a/src/arduino.cc/builder/set_custom_build_properties.go b/src/arduino.cc/builder/set_custom_build_properties.go index ea6b6cc0..fd48cf00 100644 --- a/src/arduino.cc/builder/set_custom_build_properties.go +++ b/src/arduino.cc/builder/set_custom_build_properties.go @@ -34,17 +34,16 @@ import ( "arduino.cc/builder/i18n" "arduino.cc/builder/props" "arduino.cc/builder/types" - "arduino.cc/builder/utils" ) type SetCustomBuildProperties struct{} func (s *SetCustomBuildProperties) Run(context map[string]interface{}, ctx *types.Context) error { - logger := context[constants.CTX_LOGGER].(i18n.Logger) + logger := ctx.GetLogger() buildProperties := context[constants.CTX_BUILD_PROPERTIES].(props.PropertiesMap) customBuildProperties, err := props.LoadFromSlice(ctx.CustomBuildProperties, logger) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } for key, value := range customBuildProperties { diff --git a/src/arduino.cc/builder/setup_human_logger_if_missing.go b/src/arduino.cc/builder/setup_human_logger_if_missing.go deleted file mode 100644 index b19ea136..00000000 --- a/src/arduino.cc/builder/setup_human_logger_if_missing.go +++ /dev/null @@ -1,47 +0,0 @@ -/* - * This file is part of Arduino Builder. - * - * Arduino Builder is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - * As a special exception, you may use this file as part of a free software - * library without restriction. Specifically, if other files instantiate - * templates or use macros or inline functions from this file, or you compile - * this file and link it with other files to produce an executable, this - * file does not by itself cause the resulting executable to be covered by - * the GNU General Public License. This exception does not however - * invalidate any other reasons why the executable file might be covered by - * the GNU General Public License. - * - * Copyright 2015 Arduino LLC (http://www.arduino.cc/) - */ - -package builder - -import ( - "arduino.cc/builder/constants" - "arduino.cc/builder/i18n" - "arduino.cc/builder/types" - "arduino.cc/builder/utils" -) - -type SetupHumanLoggerIfMissing struct{} - -func (s *SetupHumanLoggerIfMissing) Run(context map[string]interface{}, ctx *types.Context) error { - if !utils.MapHas(context, constants.CTX_LOGGER) { - context[constants.CTX_LOGGER] = i18n.HumanLogger{} - } - - return nil -} diff --git a/src/arduino.cc/builder/sketch_loader.go b/src/arduino.cc/builder/sketch_loader.go index 32c4dc54..1857078a 100644 --- a/src/arduino.cc/builder/sketch_loader.go +++ b/src/arduino.cc/builder/sketch_loader.go @@ -53,11 +53,11 @@ func (s *SketchLoader) Run(context map[string]interface{}, ctx *types.Context) e sketchLocation, err := filepath.Abs(sketchLocation) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } mainSketchStat, err := os.Stat(sketchLocation) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } if mainSketchStat.IsDir() { sketchLocation = filepath.Join(sketchLocation, mainSketchStat.Name()+".ino") @@ -67,17 +67,18 @@ func (s *SketchLoader) Run(context map[string]interface{}, ctx *types.Context) e allSketchFilePaths, err := collectAllSketchFiles(filepath.Dir(sketchLocation)) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } + logger := ctx.GetLogger() + if !utils.SliceContains(allSketchFilePaths, sketchLocation) { - return utils.Errorf(context, constants.MSG_CANT_FIND_SKETCH_IN_PATH, sketchLocation, filepath.Dir(sketchLocation)) + return i18n.ErrorfWithLogger(logger, constants.MSG_CANT_FIND_SKETCH_IN_PATH, sketchLocation, filepath.Dir(sketchLocation)) } - logger := context[constants.CTX_LOGGER].(i18n.Logger) sketch, err := makeSketch(sketchLocation, allSketchFilePaths, logger) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } ctx.SketchLocation = sketchLocation @@ -95,7 +96,7 @@ func collectAllSketchFiles(from string) ([]string, error) { } walkFunc := utils.CollectAllReadableFiles(&filePaths, checkExtensionFunc) err := gohasissues.Walk(from, walkFunc) - return filePaths, utils.WrapError(err) + return filePaths, i18n.WrapError(err) } func makeSketch(sketchLocation string, allSketchFilePaths []string, logger i18n.Logger) (*types.Sketch, error) { @@ -103,7 +104,7 @@ func makeSketch(sketchLocation string, allSketchFilePaths []string, logger i18n. for _, sketchFilePath := range allSketchFilePaths { source, err := ioutil.ReadFile(sketchFilePath) if err != nil { - return nil, utils.WrapError(err) + return nil, i18n.WrapError(err) } sketchFilesMap[sketchFilePath] = types.SketchFile{Name: sketchFilePath, Source: string(source)} } @@ -123,7 +124,7 @@ func makeSketch(sketchLocation string, allSketchFilePaths []string, logger i18n. } else if ADDITIONAL_FILE_VALID_EXTENSIONS[ext] { additionalFiles = append(additionalFiles, sketchFile) } else { - return nil, utils.ErrorfWithLogger(logger, constants.MSG_UNKNOWN_SKETCH_EXT, sketchFile.Name) + return nil, i18n.ErrorfWithLogger(logger, constants.MSG_UNKNOWN_SKETCH_EXT, sketchFile.Name) } } diff --git a/src/arduino.cc/builder/sketch_saver.go b/src/arduino.cc/builder/sketch_saver.go index 2344df64..5ac36c75 100644 --- a/src/arduino.cc/builder/sketch_saver.go +++ b/src/arduino.cc/builder/sketch_saver.go @@ -31,6 +31,7 @@ package builder import ( "arduino.cc/builder/constants" + "arduino.cc/builder/i18n" "arduino.cc/builder/types" "arduino.cc/builder/utils" "path/filepath" @@ -45,9 +46,9 @@ func (s *SketchSaver) Run(context map[string]interface{}, ctx *types.Context) er err := utils.EnsureFolderExists(sketchBuildPath) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } err = utils.WriteFile(filepath.Join(sketchBuildPath, filepath.Base(sketch.MainFile.Name)+".cpp"), source) - return utils.WrapError(err) + return i18n.WrapError(err) } diff --git a/src/arduino.cc/builder/target_board_resolver.go b/src/arduino.cc/builder/target_board_resolver.go index 8bfff7c7..ee93b46d 100644 --- a/src/arduino.cc/builder/target_board_resolver.go +++ b/src/arduino.cc/builder/target_board_resolver.go @@ -31,6 +31,7 @@ package builder import ( "arduino.cc/builder/constants" + "arduino.cc/builder/i18n" "arduino.cc/builder/types" "arduino.cc/builder/utils" "strings" @@ -48,19 +49,21 @@ func (s *TargetBoardResolver) Run(context map[string]interface{}, ctx *types.Con packages := context[constants.CTX_HARDWARE].(*types.Packages) + logger := ctx.GetLogger() + targetPackage := packages.Packages[targetPackageName] if targetPackage == nil { - return utils.Errorf(context, constants.MSG_PACKAGE_UNKNOWN, targetPackageName) + return i18n.ErrorfWithLogger(logger, constants.MSG_PACKAGE_UNKNOWN, targetPackageName) } targetPlatform := targetPackage.Platforms[targetPlatformName] if targetPlatform == nil { - return utils.Errorf(context, constants.MSG_PLATFORM_UNKNOWN, targetPlatformName, targetPackageName) + return i18n.ErrorfWithLogger(logger, constants.MSG_PLATFORM_UNKNOWN, targetPlatformName, targetPackageName) } targetBoard := targetPlatform.Boards[targetBoardName] if targetBoard == nil { - return utils.Errorf(context, constants.MSG_BOARD_UNKNOWN, targetBoardName, targetPlatformName, targetPackageName) + return i18n.ErrorfWithLogger(logger, constants.MSG_BOARD_UNKNOWN, targetBoardName, targetPlatformName, targetPackageName) } context[constants.CTX_TARGET_PACKAGE] = targetPackage @@ -81,7 +84,7 @@ func (s *TargetBoardResolver) Run(context map[string]interface{}, ctx *types.Con if len(coreParts) > 1 { core = coreParts[1] if packages.Packages[coreParts[0]] == nil { - return utils.Errorf(context, constants.MSG_MISSING_CORE_FOR_BOARD, coreParts[0]) + return i18n.ErrorfWithLogger(logger, constants.MSG_MISSING_CORE_FOR_BOARD, coreParts[0]) } corePlatform = packages.Packages[coreParts[0]].Platforms[targetPlatform.PlatformId] diff --git a/src/arduino.cc/builder/test/add_additional_entries_to_context_test.go b/src/arduino.cc/builder/test/add_additional_entries_to_context_test.go index e1ef1ddf..3edcd1a5 100644 --- a/src/arduino.cc/builder/test/add_additional_entries_to_context_test.go +++ b/src/arduino.cc/builder/test/add_additional_entries_to_context_test.go @@ -52,7 +52,6 @@ func TestAddAdditionalEntriesToContextNoBuildPath(t *testing.T) { require.NotNil(t, context[constants.CTX_WARNINGS_LEVEL]) require.NotNil(t, context[constants.CTX_VERBOSE]) - require.NotNil(t, context[constants.CTX_DEBUG_LEVEL]) require.True(t, context[constants.CTX_COLLECTED_SOURCE_FILES_QUEUE].(*types.UniqueStringQueue).Empty()) require.True(t, context[constants.CTX_FOLDERS_WITH_SOURCES_QUEUE].(*types.UniqueSourceFolderQueue).Empty()) @@ -76,7 +75,6 @@ func TestAddAdditionalEntriesToContextWithBuildPath(t *testing.T) { require.NotNil(t, context[constants.CTX_WARNINGS_LEVEL]) require.NotNil(t, context[constants.CTX_VERBOSE]) - require.NotNil(t, context[constants.CTX_DEBUG_LEVEL]) require.True(t, context[constants.CTX_COLLECTED_SOURCE_FILES_QUEUE].(*types.UniqueStringQueue).Empty()) require.True(t, context[constants.CTX_FOLDERS_WITH_SOURCES_QUEUE].(*types.UniqueSourceFolderQueue).Empty()) diff --git a/src/arduino.cc/builder/test/add_build_board_property_if_missing_test.go b/src/arduino.cc/builder/test/add_build_board_property_if_missing_test.go index fc4aceca..15d72e47 100644 --- a/src/arduino.cc/builder/test/add_build_board_property_if_missing_test.go +++ b/src/arduino.cc/builder/test/add_build_board_property_if_missing_test.go @@ -46,7 +46,6 @@ func TestAddBuildBoardPropertyIfMissing(t *testing.T) { } commands := []types.Command{ - &builder.SetupHumanLoggerIfMissing{}, &builder.HardwareLoader{}, &builder.TargetBoardResolver{}, &builder.AddBuildBoardPropertyIfMissing{}, @@ -75,7 +74,6 @@ func TestAddBuildBoardPropertyIfMissingNotMissing(t *testing.T) { } commands := []types.Command{ - &builder.SetupHumanLoggerIfMissing{}, &builder.HardwareLoader{}, &builder.TargetBoardResolver{}, &builder.AddBuildBoardPropertyIfMissing{}, diff --git a/src/arduino.cc/builder/test/additional_sketch_files_copier_test.go b/src/arduino.cc/builder/test/additional_sketch_files_copier_test.go index c82e77aa..583ebc1f 100644 --- a/src/arduino.cc/builder/test/additional_sketch_files_copier_test.go +++ b/src/arduino.cc/builder/test/additional_sketch_files_copier_test.go @@ -64,7 +64,6 @@ func TestCopyOtherFiles(t *testing.T) { defer os.RemoveAll(buildPath) commands := []types.Command{ - &builder.SetupHumanLoggerIfMissing{}, &builder.AddAdditionalEntriesToContext{}, &builder.SketchLoader{}, &builder.AdditionalSketchFilesCopier{}, @@ -103,7 +102,6 @@ func TestCopyOtherFilesOnlyIfChanged(t *testing.T) { defer os.RemoveAll(buildPath) commands := []types.Command{ - &builder.SetupHumanLoggerIfMissing{}, &builder.AddAdditionalEntriesToContext{}, &builder.SketchLoader{}, &builder.AdditionalSketchFilesCopier{}, diff --git a/src/arduino.cc/builder/test/builder_test.go b/src/arduino.cc/builder/test/builder_test.go index 6c834545..e3612d93 100644 --- a/src/arduino.cc/builder/test/builder_test.go +++ b/src/arduino.cc/builder/test/builder_test.go @@ -58,7 +58,7 @@ func TestBuilderEmptySketch(t *testing.T) { defer os.RemoveAll(buildPath) context[constants.CTX_VERBOSE] = true - context[constants.CTX_DEBUG_LEVEL] = 10 + ctx.DebugLevel = 10 command := builder.Builder{} err := command.Run(context, ctx) diff --git a/src/arduino.cc/builder/test/coan_runner_test.go b/src/arduino.cc/builder/test/coan_runner_test.go index e7781b15..9ddd7ef7 100644 --- a/src/arduino.cc/builder/test/coan_runner_test.go +++ b/src/arduino.cc/builder/test/coan_runner_test.go @@ -59,7 +59,6 @@ func TestCoanRunner(t *testing.T) { context[constants.CTX_VERBOSE] = true commands := []types.Command{ - &builder.SetupHumanLoggerIfMissing{}, &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, &builder.SketchSourceMerger{}, &builder.CoanRunner{}, diff --git a/src/arduino.cc/builder/test/collect_all_source_files_from_folders_with_sources_test.go b/src/arduino.cc/builder/test/collect_all_source_files_from_folders_with_sources_test.go index 305c3fe4..ceb19fb0 100644 --- a/src/arduino.cc/builder/test/collect_all_source_files_from_folders_with_sources_test.go +++ b/src/arduino.cc/builder/test/collect_all_source_files_from_folders_with_sources_test.go @@ -50,7 +50,6 @@ func TestCollectAllSourceFilesFromFoldersWithSources(t *testing.T) { context[constants.CTX_FOLDERS_WITH_SOURCES_QUEUE] = foldersWithSources commands := []types.Command{ - &builder.SetupHumanLoggerIfMissing{}, &builder.CollectAllSourceFilesFromFoldersWithSources{}, } @@ -78,7 +77,6 @@ func TestCollectAllSourceFilesFromFoldersWithSourcesOfLibrary(t *testing.T) { context[constants.CTX_FOLDERS_WITH_SOURCES_QUEUE] = foldersWithSources commands := []types.Command{ - &builder.SetupHumanLoggerIfMissing{}, &builder.CollectAllSourceFilesFromFoldersWithSources{}, } @@ -116,7 +114,6 @@ func TestCollectAllSourceFilesFromFoldersWithSourcesOfOldLibrary(t *testing.T) { context[constants.CTX_FOLDERS_WITH_SOURCES_QUEUE] = foldersWithSources commands := []types.Command{ - &builder.SetupHumanLoggerIfMissing{}, &builder.CollectAllSourceFilesFromFoldersWithSources{}, } diff --git a/src/arduino.cc/builder/test/create_build_options_map_test.go b/src/arduino.cc/builder/test/create_build_options_map_test.go index 4fc54a41..35b43040 100644 --- a/src/arduino.cc/builder/test/create_build_options_map_test.go +++ b/src/arduino.cc/builder/test/create_build_options_map_test.go @@ -52,7 +52,7 @@ func TestCreateBuildOptionsMap(t *testing.T) { context[constants.CTX_BUILD_PATH] = "buildPath" context[constants.CTX_VERBOSE] = true - context[constants.CTX_DEBUG_LEVEL] = 5 + ctx.DebugLevel = 5 create := builder.CreateBuildOptionsMap{} err := create.Run(context, ctx) diff --git a/src/arduino.cc/builder/test/ctags_runner_test.go b/src/arduino.cc/builder/test/ctags_runner_test.go index 969d8f7b..10a722c9 100644 --- a/src/arduino.cc/builder/test/ctags_runner_test.go +++ b/src/arduino.cc/builder/test/ctags_runner_test.go @@ -63,7 +63,6 @@ func TestCTagsRunner(t *testing.T) { context[constants.CTX_VERBOSE] = true commands := []types.Command{ - &builder.SetupHumanLoggerIfMissing{}, &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, @@ -116,7 +115,6 @@ func TestCTagsRunnerSketchWithClass(t *testing.T) { context[constants.CTX_VERBOSE] = true commands := []types.Command{ - &builder.SetupHumanLoggerIfMissing{}, &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, @@ -167,7 +165,6 @@ func TestCTagsRunnerSketchWithTypename(t *testing.T) { context[constants.CTX_VERBOSE] = true commands := []types.Command{ - &builder.SetupHumanLoggerIfMissing{}, &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, @@ -217,7 +214,6 @@ func TestCTagsRunnerSketchWithNamespace(t *testing.T) { context[constants.CTX_VERBOSE] = true commands := []types.Command{ - &builder.SetupHumanLoggerIfMissing{}, &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, @@ -266,7 +262,6 @@ func TestCTagsRunnerSketchWithTemplates(t *testing.T) { context[constants.CTX_VERBOSE] = true commands := []types.Command{ - &builder.SetupHumanLoggerIfMissing{}, &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, diff --git a/src/arduino.cc/builder/test/hardware_loader_test.go b/src/arduino.cc/builder/test/hardware_loader_test.go index 5f091f88..7b890ecb 100644 --- a/src/arduino.cc/builder/test/hardware_loader_test.go +++ b/src/arduino.cc/builder/test/hardware_loader_test.go @@ -47,7 +47,6 @@ func TestLoadHardware(t *testing.T) { } commands := []types.Command{ - &builder.SetupHumanLoggerIfMissing{}, &builder.HardwareLoader{}, } @@ -93,7 +92,6 @@ func TestLoadHardwareMixingUserHardwareFolder(t *testing.T) { } commands := []types.Command{ - &builder.SetupHumanLoggerIfMissing{}, &builder.AddAdditionalEntriesToContext{}, &builder.HardwareLoader{}, &builder.PlatformKeysRewriteLoader{}, @@ -165,7 +163,6 @@ func TestLoadHardwareWithBoardManagerFolderStructure(t *testing.T) { } commands := []types.Command{ - &builder.SetupHumanLoggerIfMissing{}, &builder.HardwareLoader{}, } @@ -215,7 +212,6 @@ func TestLoadLotsOfHardware(t *testing.T) { } commands := []types.Command{ - &builder.SetupHumanLoggerIfMissing{}, &builder.HardwareLoader{}, } diff --git a/src/arduino.cc/builder/test/helper_tools_downloader.go b/src/arduino.cc/builder/test/helper_tools_downloader.go index 0517951e..cd606290 100644 --- a/src/arduino.cc/builder/test/helper_tools_downloader.go +++ b/src/arduino.cc/builder/test/helper_tools_downloader.go @@ -237,11 +237,11 @@ func downloadCores(cores []Core, index map[string]interface{}) error { for _, core := range cores { url, err := findCoreUrl(index, core) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } err = downloadAndUnpackCore(core, url, HARDWARE_FOLDER) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } } return nil @@ -251,11 +251,11 @@ func downloadBoardManagerCores(cores []Core, index map[string]interface{}) error for _, core := range cores { url, err := findCoreUrl(index, core) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } err = downloadAndUnpackBoardManagerCore(core, url, BOARD_MANAGER_FOLDER) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } } return nil @@ -288,11 +288,11 @@ func downloadTools(tools []Tool, index map[string]interface{}) error { for _, tool := range tools { url, err := findToolUrl(index, tool, host) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } err = downloadAndUnpackTool(tool, url, TOOLS_FOLDER, true) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } } @@ -308,7 +308,7 @@ func downloadToolsMultipleVersions(tools []Tool, index map[string]interface{}) e if err == nil { err = os.RemoveAll(filepath.Join(TOOLS_FOLDER, tool.Name)) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } } } @@ -317,11 +317,11 @@ func downloadToolsMultipleVersions(tools []Tool, index map[string]interface{}) e for _, tool := range tools { url, err := findToolUrl(index, tool, host) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } err = downloadAndUnpackTool(tool, url, TOOLS_FOLDER, false) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } } @@ -334,11 +334,11 @@ func downloadBoardsManagerTools(tools []Tool, index map[string]interface{}) erro for _, tool := range tools { url, err := findToolUrl(index, tool, host) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } err = downloadAndUnpackBoardsManagerTool(tool, url, BOARD_MANAGER_FOLDER) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } } @@ -363,7 +363,7 @@ func allCoresAlreadyDownloadedAndUnpacked(targetPath string, cores []Core) (bool for _, core := range cores { alreadyDownloaded, err := coreAlreadyDownloadedAndUnpacked(targetPath, core) if err != nil { - return false, utils.WrapError(err) + return false, i18n.WrapError(err) } if !alreadyDownloaded { return false, nil @@ -381,12 +381,12 @@ func coreAlreadyDownloadedAndUnpacked(targetPath string, core Core) (bool, error } platform, err := props.Load(filepath.Join(corePath, "platform.txt"), i18n.HumanLogger{}) if err != nil { - return false, utils.WrapError(err) + return false, i18n.WrapError(err) } if core.Version != platform["version"] { err := os.RemoveAll(corePath) - return false, utils.WrapError(err) + return false, i18n.WrapError(err) } return true, nil @@ -445,7 +445,7 @@ func libraryAlreadyDownloadedAndUnpacked(targetPath string, library Library) boo func downloadAndUnpackCore(core Core, url string, targetPath string) error { alreadyDownloaded, err := coreAlreadyDownloadedAndUnpacked(targetPath, core) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } if alreadyDownloaded { return nil @@ -453,12 +453,12 @@ func downloadAndUnpackCore(core Core, url string, targetPath string) error { targetPath, err = filepath.Abs(targetPath) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } unpackFolder, files, err := downloadAndUnpack(url) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } defer os.RemoveAll(unpackFolder) @@ -466,28 +466,28 @@ func downloadAndUnpackCore(core Core, url string, targetPath string) error { if err == nil { err = os.RemoveAll(filepath.Join(targetPath, core.Maintainer, core.Arch)) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } } if len(files) == 1 && files[0].IsDir() { err = utils.EnsureFolderExists(filepath.Join(targetPath, core.Maintainer)) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } err = copyRecursive(filepath.Join(unpackFolder, files[0].Name()), filepath.Join(targetPath, core.Maintainer, core.Arch)) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } } else { err = utils.EnsureFolderExists(filepath.Join(targetPath, core.Maintainer, core.Arch)) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } for _, file := range files { err = copyRecursive(filepath.Join(unpackFolder, file.Name()), filepath.Join(targetPath, core.Maintainer, core.Arch, file.Name())) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } } } @@ -502,12 +502,12 @@ func downloadAndUnpackBoardManagerCore(core Core, url string, targetPath string) targetPath, err := filepath.Abs(targetPath) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } unpackFolder, files, err := downloadAndUnpack(url) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } defer os.RemoveAll(unpackFolder) @@ -515,28 +515,28 @@ func downloadAndUnpackBoardManagerCore(core Core, url string, targetPath string) if err == nil { err = os.RemoveAll(filepath.Join(targetPath, core.Maintainer, "hardware", core.Arch)) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } } if len(files) == 1 && files[0].IsDir() { err = utils.EnsureFolderExists(filepath.Join(targetPath, core.Maintainer, "hardware", core.Arch)) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } err = copyRecursive(filepath.Join(unpackFolder, files[0].Name()), filepath.Join(targetPath, core.Maintainer, "hardware", core.Arch, core.Version)) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } } else { err = utils.EnsureFolderExists(filepath.Join(targetPath, core.Maintainer, "hardware", core.Arch, core.Version)) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } for _, file := range files { err = copyRecursive(filepath.Join(unpackFolder, file.Name()), filepath.Join(targetPath, core.Maintainer, "hardware", core.Arch, core.Version, file.Name())) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } } } @@ -551,33 +551,33 @@ func downloadAndUnpackBoardsManagerTool(tool Tool, url string, targetPath string targetPath, err := filepath.Abs(targetPath) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } unpackFolder, files, err := downloadAndUnpack(url) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } defer os.RemoveAll(unpackFolder) if len(files) == 1 && files[0].IsDir() { err = utils.EnsureFolderExists(filepath.Join(targetPath, tool.Package, constants.FOLDER_TOOLS, tool.Name)) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } err = copyRecursive(filepath.Join(unpackFolder, files[0].Name()), filepath.Join(targetPath, tool.Package, constants.FOLDER_TOOLS, tool.Name, tool.Version)) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } } else { err = utils.EnsureFolderExists(filepath.Join(targetPath, tool.Package, constants.FOLDER_TOOLS, tool.Name, tool.Version)) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } for _, file := range files { err = copyRecursive(filepath.Join(unpackFolder, file.Name()), filepath.Join(targetPath, tool.Package, constants.FOLDER_TOOLS, tool.Name, tool.Version, file.Name())) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } } } @@ -592,12 +592,12 @@ func downloadAndUnpackTool(tool Tool, url string, targetPath string, deleteIfMis targetPath, err := filepath.Abs(targetPath) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } unpackFolder, files, err := downloadAndUnpack(url) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } defer os.RemoveAll(unpackFolder) @@ -606,7 +606,7 @@ func downloadAndUnpackTool(tool Tool, url string, targetPath string, deleteIfMis if err == nil { err = os.RemoveAll(filepath.Join(targetPath, tool.Name)) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } } } @@ -614,21 +614,21 @@ func downloadAndUnpackTool(tool Tool, url string, targetPath string, deleteIfMis if len(files) == 1 && files[0].IsDir() { err = utils.EnsureFolderExists(filepath.Join(targetPath, tool.Name)) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } err = copyRecursive(filepath.Join(unpackFolder, files[0].Name()), filepath.Join(targetPath, tool.Name, tool.Version)) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } } else { err = utils.EnsureFolderExists(filepath.Join(targetPath, tool.Name, tool.Version)) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } for _, file := range files { err = copyRecursive(filepath.Join(unpackFolder, file.Name()), filepath.Join(targetPath, tool.Name, tool.Version, file.Name())) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } } } @@ -641,7 +641,7 @@ func downloadAndUnpack(url string) (string, []os.FileInfo, error) { unpackFolder, err := ioutil.TempDir(constants.EMPTY_STRING, "arduino-builder-tool") if err != nil { - return constants.EMPTY_STRING, nil, utils.WrapError(err) + return constants.EMPTY_STRING, nil, i18n.WrapError(err) } urlParts := strings.Split(url, "/") @@ -650,12 +650,12 @@ func downloadAndUnpack(url string) (string, []os.FileInfo, error) { res, err := http.Get(url) if err != nil { - return constants.EMPTY_STRING, nil, utils.WrapError(err) + return constants.EMPTY_STRING, nil, i18n.WrapError(err) } bytes, err := ioutil.ReadAll(res.Body) if err != nil { - return constants.EMPTY_STRING, nil, utils.WrapError(err) + return constants.EMPTY_STRING, nil, i18n.WrapError(err) } res.Body.Close() @@ -664,7 +664,7 @@ func downloadAndUnpack(url string) (string, []os.FileInfo, error) { cmd := buildUnpackCmd(archiveFilePath) out, err := cmd.CombinedOutput() if err != nil { - return constants.EMPTY_STRING, nil, utils.WrapError(err) + return constants.EMPTY_STRING, nil, i18n.WrapError(err) } if len(out) > 0 { fmt.Println(string(out)) @@ -674,7 +674,7 @@ func downloadAndUnpack(url string) (string, []os.FileInfo, error) { files, err := gohasissues.ReadDir(unpackFolder) if err != nil { - return constants.EMPTY_STRING, nil, utils.WrapError(err) + return constants.EMPTY_STRING, nil, i18n.WrapError(err) } return unpackFolder, files, nil @@ -746,11 +746,11 @@ func downloadLibraries(libraries []Library, index map[string]interface{}) error for _, library := range libraries { url, err := findLibraryUrl(index, library) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } err = downloadAndUnpackLibrary(library, url, LIBRARIES_FOLDER) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } } @@ -779,12 +779,12 @@ func downloadAndUnpackLibrary(library Library, url string, targetPath string) er targetPath, err := filepath.Abs(targetPath) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } unpackFolder, files, err := downloadAndUnpack(url) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } defer os.RemoveAll(unpackFolder) @@ -792,13 +792,13 @@ func downloadAndUnpackLibrary(library Library, url string, targetPath string) er if err == nil { err = os.RemoveAll(filepath.Join(targetPath, strings.Replace(library.Name, " ", "_", -1))) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } } err = copyRecursive(filepath.Join(unpackFolder, files[0].Name()), filepath.Join(targetPath, strings.Replace(library.Name, " ", "_", -1))) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } return nil @@ -812,42 +812,42 @@ func copyRecursive(from, to string) error { rel, err := filepath.Rel(from, currentPath) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } targetPath := filepath.Join(to, rel) if info.IsDir() { err := os.MkdirAll(targetPath, info.Mode()) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } } else if info.Mode().IsRegular() { fromFile, err := os.Open(currentPath) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } defer fromFile.Close() targetFile, err := os.Create(targetPath) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } defer targetFile.Close() _, err = io.Copy(targetFile, fromFile) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } err = os.Chmod(targetPath, info.Mode()) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } } else if info.Mode()&os.ModeSymlink == os.ModeSymlink { linkedFile, err := os.Readlink(currentPath) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } fromFile := filepath.Join(filepath.Dir(targetPath), linkedFile) err = os.Symlink(fromFile, targetPath) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } } else { return errors.Errorf("unable to copy file " + currentPath) @@ -856,5 +856,5 @@ func copyRecursive(from, to string) error { return nil } err := gohasissues.Walk(from, copyFunc) - return utils.WrapError(err) + return i18n.WrapError(err) } diff --git a/src/arduino.cc/builder/test/includes_finder_with_gcc_test.go b/src/arduino.cc/builder/test/includes_finder_with_gcc_test.go index ac058ac8..29312ca8 100644 --- a/src/arduino.cc/builder/test/includes_finder_with_gcc_test.go +++ b/src/arduino.cc/builder/test/includes_finder_with_gcc_test.go @@ -59,7 +59,6 @@ func TestIncludesFinderWithGCC(t *testing.T) { context[constants.CTX_VERBOSE] = true commands := []types.Command{ - &builder.SetupHumanLoggerIfMissing{}, &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, @@ -96,7 +95,6 @@ func TestIncludesFinderWithGCCSketchWithConfig(t *testing.T) { context[constants.CTX_VERBOSE] = true commands := []types.Command{ - &builder.SetupHumanLoggerIfMissing{}, &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, @@ -139,7 +137,6 @@ func TestIncludesFinderWithGCCSketchWithDependendLibraries(t *testing.T) { context[constants.CTX_VERBOSE] = true commands := []types.Command{ - &builder.SetupHumanLoggerIfMissing{}, &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, @@ -193,7 +190,6 @@ func TestIncludesFinderWithGCCSketchWithThatChecksIfSPIHasTransactions(t *testin context[constants.CTX_VERBOSE] = true commands := []types.Command{ - &builder.SetupHumanLoggerIfMissing{}, &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, @@ -237,7 +233,6 @@ func TestIncludesFinderWithGCCSketchWithThatChecksIfSPIHasTransactionsAndInclude context[constants.CTX_VERBOSE] = true commands := []types.Command{ - &builder.SetupHumanLoggerIfMissing{}, &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, diff --git a/src/arduino.cc/builder/test/includes_finder_with_regexp_test.go b/src/arduino.cc/builder/test/includes_finder_with_regexp_test.go index 74b45e52..1b40826e 100644 --- a/src/arduino.cc/builder/test/includes_finder_with_regexp_test.go +++ b/src/arduino.cc/builder/test/includes_finder_with_regexp_test.go @@ -58,7 +58,6 @@ func TestIncludesFinderWithRegExpCoanOutput(t *testing.T) { context[constants.CTX_VERBOSE] = true commands := []types.Command{ - &builder.SetupHumanLoggerIfMissing{}, &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, diff --git a/src/arduino.cc/builder/test/includes_to_include_folders_test.go b/src/arduino.cc/builder/test/includes_to_include_folders_test.go index 20fc73cf..3b2ebd92 100644 --- a/src/arduino.cc/builder/test/includes_to_include_folders_test.go +++ b/src/arduino.cc/builder/test/includes_to_include_folders_test.go @@ -60,7 +60,6 @@ func TestIncludesToIncludeFolders(t *testing.T) { context[constants.CTX_VERBOSE] = true commands := []types.Command{ - &builder.SetupHumanLoggerIfMissing{}, &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, @@ -103,7 +102,6 @@ func TestIncludesToIncludeFoldersSketchWithIfDef(t *testing.T) { context[constants.CTX_VERBOSE] = true commands := []types.Command{ - &builder.SetupHumanLoggerIfMissing{}, &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, @@ -144,7 +142,6 @@ func TestIncludesToIncludeFoldersIRremoteLibrary(t *testing.T) { context[constants.CTX_VERBOSE] = true commands := []types.Command{ - &builder.SetupHumanLoggerIfMissing{}, &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, @@ -190,7 +187,6 @@ func TestIncludesToIncludeFoldersANewLibrary(t *testing.T) { context[constants.CTX_VERBOSE] = true commands := []types.Command{ - &builder.SetupHumanLoggerIfMissing{}, &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, @@ -235,7 +231,6 @@ func TestIncludesToIncludeFoldersDuplicateLibs(t *testing.T) { context[constants.CTX_VERBOSE] = true commands := []types.Command{ - &builder.SetupHumanLoggerIfMissing{}, &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, @@ -280,7 +275,6 @@ func TestIncludesToIncludeFoldersDuplicateLibsWithConflictingLibsOutsideOfPlatfo context[constants.CTX_VERBOSE] = true commands := []types.Command{ - &builder.SetupHumanLoggerIfMissing{}, &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, @@ -325,7 +319,6 @@ func TestIncludesToIncludeFoldersDuplicateLibs2(t *testing.T) { context[constants.CTX_VERBOSE] = true commands := []types.Command{ - &builder.SetupHumanLoggerIfMissing{}, &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, diff --git a/src/arduino.cc/builder/test/libraries_loader_test.go b/src/arduino.cc/builder/test/libraries_loader_test.go index d865fa03..79a97e25 100644 --- a/src/arduino.cc/builder/test/libraries_loader_test.go +++ b/src/arduino.cc/builder/test/libraries_loader_test.go @@ -51,7 +51,6 @@ func TestLoadLibrariesAVR(t *testing.T) { } commands := []types.Command{ - &builder.SetupHumanLoggerIfMissing{}, &builder.AddAdditionalEntriesToContext{}, &builder.HardwareLoader{}, &builder.TargetBoardResolver{}, @@ -162,7 +161,6 @@ func TestLoadLibrariesSAM(t *testing.T) { } commands := []types.Command{ - &builder.SetupHumanLoggerIfMissing{}, &builder.AddAdditionalEntriesToContext{}, &builder.HardwareLoader{}, &builder.TargetBoardResolver{}, @@ -247,7 +245,6 @@ func TestLoadLibrariesAVRNoDuplicateLibrariesFolders(t *testing.T) { } commands := []types.Command{ - &builder.SetupHumanLoggerIfMissing{}, &builder.AddAdditionalEntriesToContext{}, &builder.HardwareLoader{}, &builder.TargetBoardResolver{}, @@ -278,7 +275,6 @@ func TestLoadLibrariesMyAVRPlatform(t *testing.T) { } commands := []types.Command{ - &builder.SetupHumanLoggerIfMissing{}, &builder.AddAdditionalEntriesToContext{}, &builder.HardwareLoader{}, &builder.TargetBoardResolver{}, diff --git a/src/arduino.cc/builder/test/load_vid_pid_specific_properties_test.go b/src/arduino.cc/builder/test/load_vid_pid_specific_properties_test.go index aeb3c0a5..96fa9b2a 100644 --- a/src/arduino.cc/builder/test/load_vid_pid_specific_properties_test.go +++ b/src/arduino.cc/builder/test/load_vid_pid_specific_properties_test.go @@ -56,7 +56,6 @@ func TestLoadVIDPIDSpecificPropertiesWhenNoVIDPIDAreProvided(t *testing.T) { defer os.RemoveAll(buildPath) commands := []types.Command{ - &builder.SetupHumanLoggerIfMissing{}, &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, } @@ -90,7 +89,6 @@ func TestLoadVIDPIDSpecificProperties(t *testing.T) { context[constants.CTX_VIDPID] = "0x2341_0x0237" commands := []types.Command{ - &builder.SetupHumanLoggerIfMissing{}, &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, } diff --git a/src/arduino.cc/builder/test/merge_sketch_with_bootloader_test.go b/src/arduino.cc/builder/test/merge_sketch_with_bootloader_test.go index a913ec48..1a41ae39 100644 --- a/src/arduino.cc/builder/test/merge_sketch_with_bootloader_test.go +++ b/src/arduino.cc/builder/test/merge_sketch_with_bootloader_test.go @@ -69,7 +69,6 @@ func TestMergeSketchWithBootloader(t *testing.T) { NoError(t, err) commands := []types.Command{ - &builder.SetupHumanLoggerIfMissing{}, &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, &builder.MergeSketchWithBootloader{}, } @@ -113,7 +112,6 @@ func TestMergeSketchWithBootloaderSketchInBuildPath(t *testing.T) { NoError(t, err) commands := []types.Command{ - &builder.SetupHumanLoggerIfMissing{}, &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, &builder.MergeSketchWithBootloader{}, } @@ -149,7 +147,6 @@ func TestMergeSketchWithBootloaderWhenNoBootloaderAvailable(t *testing.T) { defer os.RemoveAll(buildPath) commands := []types.Command{ - &builder.SetupHumanLoggerIfMissing{}, &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, } @@ -197,7 +194,6 @@ func TestMergeSketchWithBootloaderPathIsParameterized(t *testing.T) { NoError(t, err) commands := []types.Command{ - &builder.SetupHumanLoggerIfMissing{}, &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, &builder.MergeSketchWithBootloader{}, } diff --git a/src/arduino.cc/builder/test/platform_keys_rewrite_loader_test.go b/src/arduino.cc/builder/test/platform_keys_rewrite_loader_test.go index da0b1351..cb0d770e 100644 --- a/src/arduino.cc/builder/test/platform_keys_rewrite_loader_test.go +++ b/src/arduino.cc/builder/test/platform_keys_rewrite_loader_test.go @@ -45,7 +45,6 @@ func TestLoadPlatformKeysRewrite(t *testing.T) { } commands := []types.Command{ - &builder.SetupHumanLoggerIfMissing{}, &builder.PlatformKeysRewriteLoader{}, } diff --git a/src/arduino.cc/builder/test/prototypes_adder_test.go b/src/arduino.cc/builder/test/prototypes_adder_test.go index aa8af4c8..9cff0114 100644 --- a/src/arduino.cc/builder/test/prototypes_adder_test.go +++ b/src/arduino.cc/builder/test/prototypes_adder_test.go @@ -62,10 +62,9 @@ func TestPrototypesAdderBridgeExample(t *testing.T) { defer os.RemoveAll(buildPath) context[constants.CTX_VERBOSE] = true - context[constants.CTX_DEBUG_LEVEL] = 10 + ctx.DebugLevel = 10 commands := []types.Command{ - &builder.SetupHumanLoggerIfMissing{}, &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, @@ -108,7 +107,6 @@ func TestPrototypesAdderSketchWithIfDef(t *testing.T) { context[constants.CTX_VERBOSE] = true commands := []types.Command{ - &builder.SetupHumanLoggerIfMissing{}, &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, @@ -151,7 +149,6 @@ func TestPrototypesAdderBaladuino(t *testing.T) { context[constants.CTX_VERBOSE] = true commands := []types.Command{ - &builder.SetupHumanLoggerIfMissing{}, &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, @@ -194,7 +191,6 @@ func TestPrototypesAdderCharWithEscapedDoubleQuote(t *testing.T) { context[constants.CTX_VERBOSE] = true commands := []types.Command{ - &builder.SetupHumanLoggerIfMissing{}, &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, @@ -237,7 +233,6 @@ func TestPrototypesAdderIncludeBetweenMultilineComment(t *testing.T) { context[constants.CTX_VERBOSE] = true commands := []types.Command{ - &builder.SetupHumanLoggerIfMissing{}, &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, @@ -280,7 +275,6 @@ func TestPrototypesAdderLineContinuations(t *testing.T) { context[constants.CTX_VERBOSE] = true commands := []types.Command{ - &builder.SetupHumanLoggerIfMissing{}, &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, @@ -323,7 +317,6 @@ func TestPrototypesAdderStringWithComment(t *testing.T) { context[constants.CTX_VERBOSE] = true commands := []types.Command{ - &builder.SetupHumanLoggerIfMissing{}, &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, @@ -366,7 +359,6 @@ func TestPrototypesAdderSketchWithStruct(t *testing.T) { context[constants.CTX_VERBOSE] = true commands := []types.Command{ - &builder.SetupHumanLoggerIfMissing{}, &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, @@ -417,7 +409,6 @@ func TestPrototypesAdderSketchWithConfig(t *testing.T) { context[constants.CTX_VERBOSE] = true commands := []types.Command{ - &builder.SetupHumanLoggerIfMissing{}, &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, @@ -466,7 +457,6 @@ func TestPrototypesAdderSketchNoFunctionsTwoFiles(t *testing.T) { context[constants.CTX_VERBOSE] = true commands := []types.Command{ - &builder.SetupHumanLoggerIfMissing{}, &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, @@ -512,7 +502,6 @@ func TestPrototypesAdderSketchNoFunctions(t *testing.T) { context[constants.CTX_VERBOSE] = true commands := []types.Command{ - &builder.SetupHumanLoggerIfMissing{}, &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, @@ -558,7 +547,6 @@ func TestPrototypesAdderSketchWithDefaultArgs(t *testing.T) { context[constants.CTX_VERBOSE] = true commands := []types.Command{ - &builder.SetupHumanLoggerIfMissing{}, &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, @@ -604,7 +592,6 @@ func TestPrototypesAdderSketchWithInlineFunction(t *testing.T) { context[constants.CTX_VERBOSE] = true commands := []types.Command{ - &builder.SetupHumanLoggerIfMissing{}, &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, @@ -661,7 +648,6 @@ func TestPrototypesAdderSketchWithFunctionSignatureInsideIFDEF(t *testing.T) { context[constants.CTX_VERBOSE] = true commands := []types.Command{ - &builder.SetupHumanLoggerIfMissing{}, &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, @@ -707,7 +693,6 @@ func TestPrototypesAdderSketchWithUSBCON(t *testing.T) { context[constants.CTX_VERBOSE] = true commands := []types.Command{ - &builder.SetupHumanLoggerIfMissing{}, &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, @@ -752,7 +737,6 @@ func TestPrototypesAdderSketchWithTypename(t *testing.T) { context[constants.CTX_VERBOSE] = true commands := []types.Command{ - &builder.SetupHumanLoggerIfMissing{}, &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, @@ -804,7 +788,6 @@ func TestPrototypesAdderSketchWithIfDef2(t *testing.T) { context[constants.CTX_VERBOSE] = true commands := []types.Command{ - &builder.SetupHumanLoggerIfMissing{}, &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, @@ -853,7 +836,6 @@ func TestPrototypesAdderSketchWithIfDef2SAM(t *testing.T) { context[constants.CTX_VERBOSE] = true commands := []types.Command{ - &builder.SetupHumanLoggerIfMissing{}, &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, @@ -902,7 +884,6 @@ func TestPrototypesAdderSketchWithConst(t *testing.T) { context[constants.CTX_VERBOSE] = true commands := []types.Command{ - &builder.SetupHumanLoggerIfMissing{}, &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, @@ -945,7 +926,6 @@ func TestPrototypesAdderSketchWithDosEol(t *testing.T) { context[constants.CTX_VERBOSE] = true commands := []types.Command{ - &builder.SetupHumanLoggerIfMissing{}, &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, diff --git a/src/arduino.cc/builder/test/recipe_runner_test.go b/src/arduino.cc/builder/test/recipe_runner_test.go index 052dafff..33764a6f 100644 --- a/src/arduino.cc/builder/test/recipe_runner_test.go +++ b/src/arduino.cc/builder/test/recipe_runner_test.go @@ -51,7 +51,6 @@ func TestRecipeRunner(t *testing.T) { buildProperties["recipe.hooks.prebuild.1.pattern"] = "echo" commands := []types.Command{ - &builder.SetupHumanLoggerIfMissing{}, &builder.AddAdditionalEntriesToContext{}, &builder.RecipeByPrefixSuffixRunner{Prefix: constants.HOOKS_PREBUILD, Suffix: constants.HOOKS_PATTERN_SUFFIX}, } diff --git a/src/arduino.cc/builder/test/rewrite_hardware_keys_test.go b/src/arduino.cc/builder/test/rewrite_hardware_keys_test.go index 40b8f6d3..0edd81ad 100644 --- a/src/arduino.cc/builder/test/rewrite_hardware_keys_test.go +++ b/src/arduino.cc/builder/test/rewrite_hardware_keys_test.go @@ -60,7 +60,6 @@ func TestRewriteHardwareKeys(t *testing.T) { context[constants.CTX_PLATFORM_KEYS_REWRITE] = platformKeysRewrite commands := []types.Command{ - &builder.SetupHumanLoggerIfMissing{}, &builder.AddAdditionalEntriesToContext{}, &builder.RewriteHardwareKeys{}, } @@ -98,7 +97,6 @@ func TestRewriteHardwareKeysWithRewritingDisabled(t *testing.T) { context[constants.CTX_PLATFORM_KEYS_REWRITE] = platformKeysRewrite commands := []types.Command{ - &builder.SetupHumanLoggerIfMissing{}, &builder.AddAdditionalEntriesToContext{}, &builder.RewriteHardwareKeys{}, } diff --git a/src/arduino.cc/builder/test/setup_build_properties_test.go b/src/arduino.cc/builder/test/setup_build_properties_test.go index cf3bfea5..6146f32d 100644 --- a/src/arduino.cc/builder/test/setup_build_properties_test.go +++ b/src/arduino.cc/builder/test/setup_build_properties_test.go @@ -57,7 +57,6 @@ func TestSetupBuildProperties(t *testing.T) { defer os.RemoveAll(buildPath) commands := []types.Command{ - &builder.SetupHumanLoggerIfMissing{}, &builder.AddAdditionalEntriesToContext{}, &builder.HardwareLoader{}, &builder.ToolsLoader{}, @@ -122,7 +121,6 @@ func TestSetupBuildPropertiesWithSomeCustomOverrides(t *testing.T) { defer os.RemoveAll(buildPath) commands := []types.Command{ - &builder.SetupHumanLoggerIfMissing{}, &builder.AddAdditionalEntriesToContext{}, &builder.HardwareLoader{}, &builder.ToolsLoader{}, @@ -163,7 +161,6 @@ func TestSetupBuildPropertiesUserHardware(t *testing.T) { defer os.RemoveAll(buildPath) commands := []types.Command{ - &builder.SetupHumanLoggerIfMissing{}, &builder.AddAdditionalEntriesToContext{}, &builder.HardwareLoader{}, &builder.ToolsLoader{}, @@ -203,7 +200,6 @@ func TestSetupBuildPropertiesWithMissingPropsFromParentPlatformTxtFiles(t *testi defer os.RemoveAll(buildPath) commands := []types.Command{ - &builder.SetupHumanLoggerIfMissing{}, &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, } diff --git a/src/arduino.cc/builder/test/setup_human_logger_if_missing_test.go b/src/arduino.cc/builder/test/setup_human_logger_if_missing_test.go deleted file mode 100644 index c00fdb46..00000000 --- a/src/arduino.cc/builder/test/setup_human_logger_if_missing_test.go +++ /dev/null @@ -1,52 +0,0 @@ -/* - * This file is part of Arduino Builder. - * - * Arduino Builder is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - * As a special exception, you may use this file as part of a free software - * library without restriction. Specifically, if other files instantiate - * templates or use macros or inline functions from this file, or you compile - * this file and link it with other files to produce an executable, this - * file does not by itself cause the resulting executable to be covered by - * the GNU General Public License. This exception does not however - * invalidate any other reasons why the executable file might be covered by - * the GNU General Public License. - * - * Copyright 2015 Arduino LLC (http://www.arduino.cc/) - */ - -package test - -import ( - "arduino.cc/builder" - "arduino.cc/builder/constants" - "arduino.cc/builder/i18n" - "arduino.cc/builder/types" - "github.com/stretchr/testify/require" - "reflect" - "testing" -) - -func TestSetupHumanLogger(t *testing.T) { - context := make(map[string]interface{}) - ctx := &types.Context{} - - command := &builder.SetupHumanLoggerIfMissing{} - err := command.Run(context, ctx) - NoError(t, err) - - logger := context[constants.CTX_LOGGER].(i18n.Logger) - require.Equal(t, "HumanLogger", reflect.TypeOf(logger).Name()) -} diff --git a/src/arduino.cc/builder/test/sketch_loader_test.go b/src/arduino.cc/builder/test/sketch_loader_test.go index a25eeb9e..c471f052 100644 --- a/src/arduino.cc/builder/test/sketch_loader_test.go +++ b/src/arduino.cc/builder/test/sketch_loader_test.go @@ -44,12 +44,8 @@ func TestLoadSketchWithFolder(t *testing.T) { SketchLocation: "sketch1", } - loggerCommand := builder.SetupHumanLoggerIfMissing{} - err := loggerCommand.Run(context, ctx) - NoError(t, err) - loader := builder.SketchLoader{} - err = loader.Run(context, ctx) + err := loader.Run(context, ctx) require.Error(t, err) @@ -63,12 +59,8 @@ func TestLoadSketchNonExistentPath(t *testing.T) { SketchLocation: "asdasd78128123981723981273asdasd", } - loggerCommand := builder.SetupHumanLoggerIfMissing{} - err := loggerCommand.Run(context, ctx) - NoError(t, err) - loader := builder.SketchLoader{} - err = loader.Run(context, ctx) + err := loader.Run(context, ctx) require.Error(t, err) @@ -83,7 +75,6 @@ func TestLoadSketch(t *testing.T) { } commands := []types.Command{ - &builder.SetupHumanLoggerIfMissing{}, &builder.SketchLoader{}, } @@ -113,12 +104,8 @@ func TestFailToLoadSketchFromFolder(t *testing.T) { SketchLocation: "./sketch1", } - loggerCommand := builder.SetupHumanLoggerIfMissing{} - err := loggerCommand.Run(context, ctx) - NoError(t, err) - loader := builder.SketchLoader{} - err = loader.Run(context, ctx) + err := loader.Run(context, ctx) require.Error(t, err) sketch := context[constants.CTX_SKETCH] @@ -132,7 +119,6 @@ func TestLoadSketchFromFolder(t *testing.T) { } commands := []types.Command{ - &builder.SetupHumanLoggerIfMissing{}, &builder.SketchLoader{}, } @@ -160,7 +146,6 @@ func TestLoadSketchWithBackup(t *testing.T) { } commands := []types.Command{ - &builder.SetupHumanLoggerIfMissing{}, &builder.SketchLoader{}, } @@ -185,7 +170,6 @@ func TestLoadSketchWithMacOSXGarbage(t *testing.T) { } commands := []types.Command{ - &builder.SetupHumanLoggerIfMissing{}, &builder.SketchLoader{}, } diff --git a/src/arduino.cc/builder/test/sketch_source_merger_test.go b/src/arduino.cc/builder/test/sketch_source_merger_test.go index 60bed08d..e7adfcdc 100644 --- a/src/arduino.cc/builder/test/sketch_source_merger_test.go +++ b/src/arduino.cc/builder/test/sketch_source_merger_test.go @@ -47,7 +47,6 @@ func TestMergeSketch(t *testing.T) { } commands := []types.Command{ - &builder.SetupHumanLoggerIfMissing{}, &builder.SketchLoader{}, &builder.SketchSourceMerger{}, } diff --git a/src/arduino.cc/builder/test/store_build_options_map_test.go b/src/arduino.cc/builder/test/store_build_options_map_test.go index ddfd5333..7b807d70 100644 --- a/src/arduino.cc/builder/test/store_build_options_map_test.go +++ b/src/arduino.cc/builder/test/store_build_options_map_test.go @@ -57,7 +57,7 @@ func TestStoreBuildOptionsMap(t *testing.T) { defer os.RemoveAll(buildPath) context[constants.CTX_VERBOSE] = true - context[constants.CTX_DEBUG_LEVEL] = 5 + ctx.DebugLevel = 5 commands := []types.Command{ &builder.CreateBuildOptionsMap{}, diff --git a/src/arduino.cc/builder/test/target_board_resolver_test.go b/src/arduino.cc/builder/test/target_board_resolver_test.go index bbf96d23..fd39c08a 100644 --- a/src/arduino.cc/builder/test/target_board_resolver_test.go +++ b/src/arduino.cc/builder/test/target_board_resolver_test.go @@ -46,7 +46,6 @@ func TestTargetBoardResolverUno(t *testing.T) { } commands := []types.Command{ - &builder.SetupHumanLoggerIfMissing{}, &builder.HardwareLoader{}, &builder.TargetBoardResolver{}, } @@ -73,7 +72,6 @@ func TestTargetBoardResolverDue(t *testing.T) { } commands := []types.Command{ - &builder.SetupHumanLoggerIfMissing{}, &builder.HardwareLoader{}, &builder.TargetBoardResolver{}, } @@ -100,7 +98,6 @@ func TestTargetBoardResolverMega1280(t *testing.T) { } commands := []types.Command{ - &builder.SetupHumanLoggerIfMissing{}, &builder.HardwareLoader{}, &builder.TargetBoardResolver{}, } @@ -128,7 +125,6 @@ func TestTargetBoardResolverMega2560(t *testing.T) { } commands := []types.Command{ - &builder.SetupHumanLoggerIfMissing{}, &builder.HardwareLoader{}, &builder.TargetBoardResolver{}, } @@ -156,7 +152,6 @@ func TestTargetBoardResolverCustomYun(t *testing.T) { } commands := []types.Command{ - &builder.SetupHumanLoggerIfMissing{}, &builder.HardwareLoader{}, &builder.TargetBoardResolver{}, } @@ -184,7 +179,6 @@ func TestTargetBoardResolverCustomCore(t *testing.T) { } commands := []types.Command{ - &builder.SetupHumanLoggerIfMissing{}, &builder.HardwareLoader{}, &builder.TargetBoardResolver{}, } diff --git a/src/arduino.cc/builder/test/wipeout_build_path_if_build_options_changed_test.go b/src/arduino.cc/builder/test/wipeout_build_path_if_build_options_changed_test.go index ed2c22cb..57cbcd8b 100644 --- a/src/arduino.cc/builder/test/wipeout_build_path_if_build_options_changed_test.go +++ b/src/arduino.cc/builder/test/wipeout_build_path_if_build_options_changed_test.go @@ -54,7 +54,6 @@ func TestWipeoutBuildPathIfBuildOptionsChanged(t *testing.T) { utils.TouchFile(filepath.Join(buildPath, "should_be_deleted.txt")) commands := []types.Command{ - &builder.SetupHumanLoggerIfMissing{}, &builder.WipeoutBuildPathIfBuildOptionsChanged{}, } @@ -86,7 +85,6 @@ func TestWipeoutBuildPathIfBuildOptionsChangedNoPreviousBuildOptions(t *testing. utils.TouchFile(filepath.Join(buildPath, "should_not_be_deleted.txt")) commands := []types.Command{ - &builder.SetupHumanLoggerIfMissing{}, &builder.WipeoutBuildPathIfBuildOptionsChanged{}, } @@ -119,7 +117,6 @@ func TestWipeoutBuildPathIfBuildOptionsChangedBuildOptionsMatch(t *testing.T) { utils.TouchFile(filepath.Join(buildPath, "should_not_be_deleted.txt")) commands := []types.Command{ - &builder.SetupHumanLoggerIfMissing{}, &builder.WipeoutBuildPathIfBuildOptionsChanged{}, } diff --git a/src/arduino.cc/builder/tools_loader.go b/src/arduino.cc/builder/tools_loader.go index 317ef023..c76891b3 100644 --- a/src/arduino.cc/builder/tools_loader.go +++ b/src/arduino.cc/builder/tools_loader.go @@ -32,6 +32,7 @@ package builder import ( "arduino.cc/builder/constants" "arduino.cc/builder/gohasissues" + "arduino.cc/builder/i18n" "arduino.cc/builder/types" "arduino.cc/builder/utils" "os" @@ -49,23 +50,23 @@ func (s *ToolsLoader) Run(context map[string]interface{}, ctx *types.Context) er for _, folder := range folders { builtinToolsVersionsFile, err := findBuiltinToolsVersionsFile(folder) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } if builtinToolsVersionsFile != constants.EMPTY_STRING { err = loadToolsFrom(&tools, builtinToolsVersionsFile) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } } else { subfolders, err := collectAllToolsFolders(folder) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } for _, subfolder := range subfolders { err = loadToolsFromFolderStructure(&tools, subfolder) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } } } @@ -89,7 +90,7 @@ func collectAllToolsFolders(from string) ([]string, error) { rel, err := filepath.Rel(from, currentPath) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } depth := len(strings.Split(rel, string(os.PathSeparator))) @@ -107,7 +108,7 @@ func collectAllToolsFolders(from string) ([]string, error) { folders = append(folders, from) } - return folders, utils.WrapError(err) + return folders, i18n.WrapError(err) } func toolsSliceContains(tools *[]*types.Tool, name, version string) bool { @@ -122,12 +123,12 @@ func toolsSliceContains(tools *[]*types.Tool, name, version string) bool { func loadToolsFrom(tools *[]*types.Tool, builtinToolsVersionsFilePath string) error { rows, err := utils.ReadFileToRows(builtinToolsVersionsFilePath) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } folder, err := filepath.Abs(filepath.Dir(builtinToolsVersionsFilePath)) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } for _, row := range rows { @@ -161,23 +162,23 @@ func findBuiltinToolsVersionsFile(folder string) (string, error) { return nil } err := gohasissues.Walk(folder, findBuiltInToolsVersionsTxt) - return builtinToolsVersionsFilePath, utils.WrapError(err) + return builtinToolsVersionsFilePath, i18n.WrapError(err) } func loadToolsFromFolderStructure(tools *[]*types.Tool, folder string) error { toolsNames, err := utils.ReadDirFiltered(folder, utils.FilterDirs) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } for _, toolName := range toolsNames { toolVersions, err := utils.ReadDirFiltered(filepath.Join(folder, toolName.Name()), utils.FilterDirs) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } for _, toolVersion := range toolVersions { toolFolder, err := filepath.Abs(filepath.Join(folder, toolName.Name(), toolVersion.Name())) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } if !toolsSliceContains(tools, toolName.Name(), toolVersion.Name()) { *tools = append(*tools, &types.Tool{Name: toolName.Name(), Version: toolVersion.Name(), Folder: toolFolder}) diff --git a/src/arduino.cc/builder/types/context.go b/src/arduino.cc/builder/types/context.go index 89267d7b..4b61e2d6 100644 --- a/src/arduino.cc/builder/types/context.go +++ b/src/arduino.cc/builder/types/context.go @@ -1,6 +1,7 @@ package types import "strings" +import "arduino.cc/builder/i18n" import "arduino.cc/builder/props" // Context structure @@ -18,6 +19,10 @@ type Context struct { // Contents of a custom build properties file (line by line) CustomBuildProperties []string + // Logging + logger i18n.Logger + DebugLevel int + // For now it is used in conjunction with the old map[string]string, but // it will be slowly populated with all the fields currently used in the // map in the next commits. @@ -47,3 +52,14 @@ func (ctx *Context) InjectBuildOptions(opts props.PropertiesMap) { ctx.ArduinoAPIVersion = opts["runtime.ide.version"] ctx.CustomBuildProperties = strings.Split(opts["customBuildProperties"], ",") } + +func (ctx *Context) GetLogger() i18n.Logger { + if ctx.logger == nil { + return &i18n.HumanLogger{} + } + return ctx.logger +} + +func (ctx *Context) SetLogger(l i18n.Logger) { + ctx.logger = l +} diff --git a/src/arduino.cc/builder/unused_compiled_libraries_remover.go b/src/arduino.cc/builder/unused_compiled_libraries_remover.go index 1bdb984f..90ef004a 100644 --- a/src/arduino.cc/builder/unused_compiled_libraries_remover.go +++ b/src/arduino.cc/builder/unused_compiled_libraries_remover.go @@ -31,6 +31,7 @@ package builder import ( "arduino.cc/builder/constants" + "arduino.cc/builder/i18n" "arduino.cc/builder/types" "arduino.cc/builder/utils" "io/ioutil" @@ -53,14 +54,14 @@ func (s *UnusedCompiledLibrariesRemover) Run(context map[string]interface{}, ctx files, err := ioutil.ReadDir(librariesBuildPath) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } for _, file := range files { if file.IsDir() { if !utils.SliceContains(libraryNames, file.Name()) { err := os.RemoveAll(filepath.Join(librariesBuildPath, file.Name())) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } } } diff --git a/src/arduino.cc/builder/utils/utils.go b/src/arduino.cc/builder/utils/utils.go index 068d212c..5924859e 100644 --- a/src/arduino.cc/builder/utils/utils.go +++ b/src/arduino.cc/builder/utils/utils.go @@ -35,12 +35,10 @@ import ( "arduino.cc/builder/i18n" "crypto/md5" "encoding/hex" - "github.com/go-errors/errors" "io/ioutil" "os" "os/exec" "path/filepath" - "reflect" "runtime" "strings" ) @@ -126,7 +124,7 @@ func ParseCommandLine(input string, logger i18n.Logger) ([]string, error) { } if escapingChar != constants.EMPTY_STRING { - return nil, ErrorfWithLogger(logger, constants.MSG_INVALID_QUOTING, escapingChar) + return nil, i18n.ErrorfWithLogger(logger, constants.MSG_INVALID_QUOTING, escapingChar) } return parts, nil @@ -137,7 +135,7 @@ type filterFiles func([]os.FileInfo) []os.FileInfo func ReadDirFiltered(folder string, fn filterFiles) ([]os.FileInfo, error) { files, err := gohasissues.ReadDir(folder) if err != nil { - return nil, WrapError(err) + return nil, i18n.WrapError(err) } return fn(files), nil } @@ -234,7 +232,7 @@ type argFilterFunc func(int, string, []string) bool func PrepareCommandFilteredArgs(pattern string, filter argFilterFunc, logger i18n.Logger) (*exec.Cmd, error) { parts, err := ParseCommandLine(pattern, logger) if err != nil { - return nil, WrapError(err) + return nil, i18n.WrapError(err) } command := parts[0] parts = parts[1:] @@ -256,33 +254,6 @@ func PrepareCommand(pattern string, logger i18n.Logger) (*exec.Cmd, error) { return PrepareCommandFilteredArgs(pattern, filterEmptyArg, logger) } -func WrapError(err error) error { - if err == nil { - return nil - } - return errors.Wrap(err, 0) -} - -func Logger(context map[string]interface{}) i18n.Logger { - if MapHas(context, constants.CTX_LOGGER) { - return context[constants.CTX_LOGGER].(i18n.Logger) - } - return i18n.HumanLogger{} -} - -func Errorf(context map[string]interface{}, format string, a ...interface{}) *errors.Error { - log := Logger(context) - return ErrorfWithLogger(log, format, a...) -} - -func ErrorfWithLogger(log i18n.Logger, format string, a ...interface{}) *errors.Error { - if log.Name() == "machine" { - log.Fprintln(os.Stderr, constants.LOG_LEVEL_ERROR, format, a...) - return errors.Errorf(constants.EMPTY_STRING) - } - return errors.Errorf(i18n.Format(format, a...)) -} - func MapHas(aMap map[string]interface{}, key string) bool { _, ok := aMap[key] return ok @@ -293,13 +264,6 @@ func MapStringStringHas(aMap map[string]string, key string) bool { return ok } -func DebugLevel(context map[string]interface{}) int { - if MapHas(context, constants.CTX_DEBUG_LEVEL) && reflect.TypeOf(context[constants.CTX_DEBUG_LEVEL]).Kind() == reflect.Int { - return context[constants.CTX_DEBUG_LEVEL].(int) - } - return 0 -} - func SliceToMapStringBool(keys []string, value bool) map[string]bool { aMap := make(map[string]bool) for _, key := range keys { @@ -312,7 +276,7 @@ func AbsolutizePaths(files []string) ([]string, error) { for idx, file := range files { absFile, err := filepath.Abs(file) if err != nil { - return nil, WrapError(err) + return nil, i18n.WrapError(err) } files[idx] = absFile } @@ -323,7 +287,7 @@ func AbsolutizePaths(files []string) ([]string, error) { func ReadFileToRows(file string) ([]string, error) { bytes, err := ioutil.ReadFile(file) if err != nil { - return nil, WrapError(err) + return nil, i18n.WrapError(err) } txt := string(bytes) txt = strings.Replace(txt, "\r\n", "\n", -1) @@ -334,7 +298,7 @@ func ReadFileToRows(file string) ([]string, error) { func TheOnlySubfolderOf(folder string) (string, error) { subfolders, err := ReadDirFiltered(folder, FilterDirs) if err != nil { - return constants.EMPTY_STRING, WrapError(err) + return constants.EMPTY_STRING, i18n.WrapError(err) } if len(subfolders) != 1 { diff --git a/src/arduino.cc/builder/warn_about_arch_incompatible_libraries.go b/src/arduino.cc/builder/warn_about_arch_incompatible_libraries.go index d6bf457e..902c995a 100644 --- a/src/arduino.cc/builder/warn_about_arch_incompatible_libraries.go +++ b/src/arduino.cc/builder/warn_about_arch_incompatible_libraries.go @@ -31,10 +31,8 @@ package builder import ( "arduino.cc/builder/constants" - "arduino.cc/builder/i18n" "arduino.cc/builder/props" "arduino.cc/builder/types" - "arduino.cc/builder/utils" "os" "strings" ) @@ -42,13 +40,13 @@ import ( type WarnAboutArchIncompatibleLibraries struct{} func (s *WarnAboutArchIncompatibleLibraries) Run(context map[string]interface{}, ctx *types.Context) error { - if utils.DebugLevel(context) <= 0 { + if ctx.DebugLevel < 0 { return nil } targetPlatform := context[constants.CTX_TARGET_PLATFORM].(*types.Platform) buildProperties := context[constants.CTX_BUILD_PROPERTIES].(props.PropertiesMap) - logger := context[constants.CTX_LOGGER].(i18n.Logger) + logger := ctx.GetLogger() archs := []string{} archs = append(archs, targetPlatform.PlatformId) diff --git a/src/arduino.cc/builder/warn_about_platform_rewrites.go b/src/arduino.cc/builder/warn_about_platform_rewrites.go index cea8f49a..a4085602 100644 --- a/src/arduino.cc/builder/warn_about_platform_rewrites.go +++ b/src/arduino.cc/builder/warn_about_platform_rewrites.go @@ -31,21 +31,18 @@ package builder import ( "arduino.cc/builder/constants" - "arduino.cc/builder/i18n" "arduino.cc/builder/types" - "arduino.cc/builder/utils" "os" ) type WarnAboutPlatformRewrites struct{} func (s *WarnAboutPlatformRewrites) Run(context map[string]interface{}, ctx *types.Context) error { - warn := utils.DebugLevel(context) > 0 - if !warn { + if ctx.DebugLevel < 0 { return nil } - logger := context[constants.CTX_LOGGER].(i18n.Logger) + logger := ctx.GetLogger() hardwareRewriteResults := context[constants.CTX_HARDWARE_REWRITE_RESULTS].(map[*types.Platform][]types.PlatforKeyRewrite) targetPlatform := context[constants.CTX_TARGET_PLATFORM].(*types.Platform) actualPlatform := context[constants.CTX_ACTUAL_PLATFORM].(*types.Platform) diff --git a/src/arduino.cc/builder/wipeout_build_path_if_build_options_changed.go b/src/arduino.cc/builder/wipeout_build_path_if_build_options_changed.go index 5e73a697..c7e7121d 100644 --- a/src/arduino.cc/builder/wipeout_build_path_if_build_options_changed.go +++ b/src/arduino.cc/builder/wipeout_build_path_if_build_options_changed.go @@ -48,7 +48,7 @@ func (s *WipeoutBuildPathIfBuildOptionsChanged) Run(context map[string]interface } buildOptionsJson := context[constants.CTX_BUILD_OPTIONS_JSON].(string) previousBuildOptionsJson := context[constants.CTX_BUILD_OPTIONS_PREVIOUS_JSON].(string) - logger := context[constants.CTX_LOGGER].(i18n.Logger) + logger := ctx.GetLogger() if buildOptionsJson == previousBuildOptionsJson { return nil @@ -68,7 +68,7 @@ func (s *WipeoutBuildPathIfBuildOptionsChanged) Run(context map[string]interface buildPath := context[constants.CTX_BUILD_PATH].(string) files, err := gohasissues.ReadDir(buildPath) if err != nil { - return utils.WrapError(err) + return i18n.WrapError(err) } for _, file := range files { os.RemoveAll(filepath.Join(buildPath, file.Name())) From 48c018058143e11b1ef60719a62020d4f0909aac Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Fri, 1 Apr 2016 23:16:47 +0200 Subject: [PATCH 04/25] Migrated verbosity parameters into Context Signed-off-by: Cristian Maglie --- .../add_additional_entries_to_context.go | 4 -- src/arduino.cc/builder/coan_runner.go | 2 +- src/arduino.cc/builder/constants/constants.go | 2 - src/arduino.cc/builder/ctags/ctags_runner.go | 2 +- src/arduino.cc/builder/gcc_preproc_runner.go | 4 +- .../builder/includes_finder_with_gcc.go | 2 +- .../builder/includes_to_include_folders.go | 2 +- src/arduino.cc/builder/phases/core_builder.go | 2 +- .../builder/phases/libraries_builder.go | 2 +- src/arduino.cc/builder/phases/linker.go | 2 +- .../builder/phases/sketch_builder.go | 2 +- .../print_used_libraries_if_verbose.go | 2 +- src/arduino.cc/builder/prototypes_adder.go | 2 +- src/arduino.cc/builder/recipe_runner.go | 2 +- .../add_additional_entries_to_context_test.go | 2 - src/arduino.cc/builder/test/builder_test.go | 5 +- .../builder/test/coan_runner_test.go | 3 +- .../test/create_build_options_map_test.go | 2 +- .../builder/test/ctags_runner_test.go | 15 ++--- .../test/includes_finder_with_gcc_test.go | 15 ++--- .../test/includes_finder_with_regexp_test.go | 3 +- .../test/includes_to_include_folders_test.go | 21 +++---- .../builder/test/prototypes_adder_test.go | 59 +++++++------------ .../test/store_build_options_map_test.go | 5 +- .../try_build_of_problematic_sketch_test.go | 6 +- src/arduino.cc/builder/types/context.go | 4 ++ 26 files changed, 63 insertions(+), 109 deletions(-) diff --git a/src/arduino.cc/builder/add_additional_entries_to_context.go b/src/arduino.cc/builder/add_additional_entries_to_context.go index ffe7aaff..70f7515b 100644 --- a/src/arduino.cc/builder/add_additional_entries_to_context.go +++ b/src/arduino.cc/builder/add_additional_entries_to_context.go @@ -69,10 +69,6 @@ func (s *AddAdditionalEntriesToContext) Run(context map[string]interface{}, ctx context[constants.CTX_WARNINGS_LEVEL] = DEFAULT_WARNINGS_LEVEL } - if !utils.MapHas(context, constants.CTX_VERBOSE) { - context[constants.CTX_VERBOSE] = false - } - sourceFiles := &types.UniqueStringQueue{} context[constants.CTX_COLLECTED_SOURCE_FILES_QUEUE] = sourceFiles foldersWithSources := &types.UniqueSourceFolderQueue{} diff --git a/src/arduino.cc/builder/coan_runner.go b/src/arduino.cc/builder/coan_runner.go index 3c71747a..a5738a06 100644 --- a/src/arduino.cc/builder/coan_runner.go +++ b/src/arduino.cc/builder/coan_runner.go @@ -47,7 +47,7 @@ type CoanRunner struct{} func (s *CoanRunner) Run(context map[string]interface{}, ctx *types.Context) error { source := context[constants.CTX_SOURCE].(string) source += "\n" - verbose := context[constants.CTX_VERBOSE].(bool) + verbose := ctx.Verbose preprocPath := context[constants.CTX_PREPROC_PATH].(string) err := utils.EnsureFolderExists(preprocPath) diff --git a/src/arduino.cc/builder/constants/constants.go b/src/arduino.cc/builder/constants/constants.go index 29173fac..2d4b86e8 100644 --- a/src/arduino.cc/builder/constants/constants.go +++ b/src/arduino.cc/builder/constants/constants.go @@ -89,7 +89,6 @@ const CTX_CTAGS_OF_PREPROC_SOURCE = "ctagsOfPreprocSource" const CTX_CTAGS_OF_SOURCE = "ctagsOfSource" const CTX_CTAGS_OUTPUT = "ctagsOutput" const CTX_CTAGS_TEMP_FILE_PATH = "ctagsTempFilePath" -const CTX_DEBUG_PREPROCESSOR = "debugPreprocessor" const CTX_FILE_PATH_TO_READ = "filePathToRead" const CTX_FOLDERS_WITH_SOURCES_QUEUE = "foldersWithSourcesQueue" const CTX_GCC_MINUS_E_SOURCE = "gccMinusESource" @@ -121,7 +120,6 @@ const CTX_TARGET_BOARD = "targetBoard" const CTX_TARGET_PACKAGE = "targetPackage" const CTX_TARGET_PLATFORM = "targetPlatform" const CTX_TOOLS = "tools" -const CTX_VERBOSE = "verbose" const CTX_VIDPID = "VIDPID" const CTX_WARNINGS_LEVEL = "warningLevel" const EMPTY_STRING = "" diff --git a/src/arduino.cc/builder/ctags/ctags_runner.go b/src/arduino.cc/builder/ctags/ctags_runner.go index 592329f8..54375a14 100644 --- a/src/arduino.cc/builder/ctags/ctags_runner.go +++ b/src/arduino.cc/builder/ctags/ctags_runner.go @@ -60,7 +60,7 @@ func (s *CTagsRunner) Run(context map[string]interface{}, ctx *types.Context) er return i18n.WrapError(err) } - verbose := context[constants.CTX_VERBOSE].(bool) + verbose := ctx.Verbose if verbose { fmt.Println(commandLine) } diff --git a/src/arduino.cc/builder/gcc_preproc_runner.go b/src/arduino.cc/builder/gcc_preproc_runner.go index c6d36346..aef30cbf 100644 --- a/src/arduino.cc/builder/gcc_preproc_runner.go +++ b/src/arduino.cc/builder/gcc_preproc_runner.go @@ -57,7 +57,7 @@ func (s *GCCPreprocRunner) Run(context map[string]interface{}, ctx *types.Contex properties[constants.RECIPE_PREPROC_MACROS] = GeneratePreprocPatternFromCompile(properties[constants.RECIPE_CPP_PATTERN]) } - verbose := context[constants.CTX_VERBOSE].(bool) + verbose := ctx.Verbose logger := ctx.GetLogger() _, err = builder_utils.ExecRecipe(properties, constants.RECIPE_PREPROC_MACROS, true, verbose, false, logger) if err != nil { @@ -80,7 +80,7 @@ func (s *GCCPreprocRunnerForDiscoveringIncludes) Run(context map[string]interfac return i18n.WrapError(err) } - verbose := context[constants.CTX_VERBOSE].(bool) + verbose := ctx.Verbose logger := ctx.GetLogger() if properties[constants.RECIPE_PREPROC_MACROS] == constants.EMPTY_STRING { diff --git a/src/arduino.cc/builder/includes_finder_with_gcc.go b/src/arduino.cc/builder/includes_finder_with_gcc.go index 741f739b..0a02423e 100644 --- a/src/arduino.cc/builder/includes_finder_with_gcc.go +++ b/src/arduino.cc/builder/includes_finder_with_gcc.go @@ -48,7 +48,7 @@ func (s *IncludesFinderWithGCC) Run(context map[string]interface{}, ctx *types.C if p, ok := context[constants.CTX_BUILD_PROPERTIES]; ok { buildProperties = p.(props.PropertiesMap).Clone() } - verbose := context[constants.CTX_VERBOSE].(bool) + verbose := ctx.Verbose logger := ctx.GetLogger() includesParams := constants.EMPTY_STRING diff --git a/src/arduino.cc/builder/includes_to_include_folders.go b/src/arduino.cc/builder/includes_to_include_folders.go index 308f5140..ea159512 100644 --- a/src/arduino.cc/builder/includes_to_include_folders.go +++ b/src/arduino.cc/builder/includes_to_include_folders.go @@ -79,7 +79,7 @@ func (s *IncludesToIncludeFolders) Run(context map[string]interface{}, ctx *type context[constants.CTX_IMPORTED_LIBRARIES] = importedLibraries buildProperties := context[constants.CTX_BUILD_PROPERTIES].(props.PropertiesMap) - verbose := context[constants.CTX_VERBOSE].(bool) + verbose := ctx.Verbose includeFolders := resolveIncludeFolders(newlyImportedLibraries, buildProperties, verbose) context[constants.CTX_INCLUDE_FOLDERS] = includeFolders diff --git a/src/arduino.cc/builder/phases/core_builder.go b/src/arduino.cc/builder/phases/core_builder.go index d81d0b16..7217f136 100644 --- a/src/arduino.cc/builder/phases/core_builder.go +++ b/src/arduino.cc/builder/phases/core_builder.go @@ -43,7 +43,7 @@ type CoreBuilder struct{} func (s *CoreBuilder) Run(context map[string]interface{}, ctx *types.Context) error { coreBuildPath := context[constants.CTX_CORE_BUILD_PATH].(string) buildProperties := context[constants.CTX_BUILD_PROPERTIES].(props.PropertiesMap) - verbose := context[constants.CTX_VERBOSE].(bool) + verbose := ctx.Verbose warningsLevel := context[constants.CTX_WARNINGS_LEVEL].(string) logger := ctx.GetLogger() diff --git a/src/arduino.cc/builder/phases/libraries_builder.go b/src/arduino.cc/builder/phases/libraries_builder.go index f74fdaac..5cc8dc21 100644 --- a/src/arduino.cc/builder/phases/libraries_builder.go +++ b/src/arduino.cc/builder/phases/libraries_builder.go @@ -48,7 +48,7 @@ func (s *LibrariesBuilder) Run(context map[string]interface{}, ctx *types.Contex includes := context[constants.CTX_INCLUDE_FOLDERS].([]string) includes = utils.Map(includes, utils.WrapWithHyphenI) libraries := context[constants.CTX_IMPORTED_LIBRARIES].([]*types.Library) - verbose := context[constants.CTX_VERBOSE].(bool) + verbose := ctx.Verbose warningsLevel := context[constants.CTX_WARNINGS_LEVEL].(string) logger := ctx.GetLogger() diff --git a/src/arduino.cc/builder/phases/linker.go b/src/arduino.cc/builder/phases/linker.go index b6b32036..2508d27c 100644 --- a/src/arduino.cc/builder/phases/linker.go +++ b/src/arduino.cc/builder/phases/linker.go @@ -60,7 +60,7 @@ func (s *Linker) Run(context map[string]interface{}, ctx *types.Context) error { } buildProperties := context[constants.CTX_BUILD_PROPERTIES].(props.PropertiesMap) - verbose := context[constants.CTX_VERBOSE].(bool) + verbose := ctx.Verbose warningsLevel := context[constants.CTX_WARNINGS_LEVEL].(string) logger := ctx.GetLogger() diff --git a/src/arduino.cc/builder/phases/sketch_builder.go b/src/arduino.cc/builder/phases/sketch_builder.go index b1392a7b..0de2b5a4 100644 --- a/src/arduino.cc/builder/phases/sketch_builder.go +++ b/src/arduino.cc/builder/phases/sketch_builder.go @@ -45,7 +45,7 @@ func (s *SketchBuilder) Run(context map[string]interface{}, ctx *types.Context) buildProperties := context[constants.CTX_BUILD_PROPERTIES].(props.PropertiesMap) includes := context[constants.CTX_INCLUDE_FOLDERS].([]string) includes = utils.Map(includes, utils.WrapWithHyphenI) - verbose := context[constants.CTX_VERBOSE].(bool) + verbose := ctx.Verbose warningsLevel := context[constants.CTX_WARNINGS_LEVEL].(string) logger := ctx.GetLogger() diff --git a/src/arduino.cc/builder/print_used_libraries_if_verbose.go b/src/arduino.cc/builder/print_used_libraries_if_verbose.go index 2d9cf2f6..a9f64715 100644 --- a/src/arduino.cc/builder/print_used_libraries_if_verbose.go +++ b/src/arduino.cc/builder/print_used_libraries_if_verbose.go @@ -39,7 +39,7 @@ import ( type PrintUsedLibrariesIfVerbose struct{} func (s *PrintUsedLibrariesIfVerbose) Run(context map[string]interface{}, ctx *types.Context) error { - verbose := context[constants.CTX_VERBOSE].(bool) + verbose := ctx.Verbose logger := ctx.GetLogger() if !verbose || !utils.MapHas(context, constants.CTX_IMPORTED_LIBRARIES) { diff --git a/src/arduino.cc/builder/prototypes_adder.go b/src/arduino.cc/builder/prototypes_adder.go index f339cc1f..17c0db50 100644 --- a/src/arduino.cc/builder/prototypes_adder.go +++ b/src/arduino.cc/builder/prototypes_adder.go @@ -41,7 +41,7 @@ import ( type PrototypesAdder struct{} func (s *PrototypesAdder) Run(context map[string]interface{}, ctx *types.Context) error { - debugOutput := context[constants.CTX_DEBUG_PREPROCESSOR] != nil + debugOutput := ctx.DebugPreprocessor source := context[constants.CTX_SOURCE].(string) source = strings.Replace(source, "\r\n", "\n", -1) diff --git a/src/arduino.cc/builder/recipe_runner.go b/src/arduino.cc/builder/recipe_runner.go index 5844fd9d..01fb23a8 100644 --- a/src/arduino.cc/builder/recipe_runner.go +++ b/src/arduino.cc/builder/recipe_runner.go @@ -55,7 +55,7 @@ func (s *RecipeByPrefixSuffixRunner) Run(context map[string]interface{}, ctx *ty if p, ok := context[constants.CTX_BUILD_PROPERTIES]; ok { buildProperties = p.(props.PropertiesMap).Clone() } - verbose := context[constants.CTX_VERBOSE].(bool) + verbose := ctx.Verbose recipes := findRecipes(buildProperties, s.Prefix, s.Suffix) diff --git a/src/arduino.cc/builder/test/add_additional_entries_to_context_test.go b/src/arduino.cc/builder/test/add_additional_entries_to_context_test.go index 3edcd1a5..b58c4a8c 100644 --- a/src/arduino.cc/builder/test/add_additional_entries_to_context_test.go +++ b/src/arduino.cc/builder/test/add_additional_entries_to_context_test.go @@ -51,7 +51,6 @@ func TestAddAdditionalEntriesToContextNoBuildPath(t *testing.T) { require.Nil(t, context[constants.CTX_CORE_BUILD_PATH]) require.NotNil(t, context[constants.CTX_WARNINGS_LEVEL]) - require.NotNil(t, context[constants.CTX_VERBOSE]) require.True(t, context[constants.CTX_COLLECTED_SOURCE_FILES_QUEUE].(*types.UniqueStringQueue).Empty()) require.True(t, context[constants.CTX_FOLDERS_WITH_SOURCES_QUEUE].(*types.UniqueSourceFolderQueue).Empty()) @@ -74,7 +73,6 @@ func TestAddAdditionalEntriesToContextWithBuildPath(t *testing.T) { require.Equal(t, Abs(t, filepath.Join("folder", constants.FOLDER_CORE)), context[constants.CTX_CORE_BUILD_PATH]) require.NotNil(t, context[constants.CTX_WARNINGS_LEVEL]) - require.NotNil(t, context[constants.CTX_VERBOSE]) require.True(t, context[constants.CTX_COLLECTED_SOURCE_FILES_QUEUE].(*types.UniqueStringQueue).Empty()) require.True(t, context[constants.CTX_FOLDERS_WITH_SOURCES_QUEUE].(*types.UniqueSourceFolderQueue).Empty()) diff --git a/src/arduino.cc/builder/test/builder_test.go b/src/arduino.cc/builder/test/builder_test.go index e3612d93..3a7decac 100644 --- a/src/arduino.cc/builder/test/builder_test.go +++ b/src/arduino.cc/builder/test/builder_test.go @@ -52,12 +52,12 @@ func TestBuilderEmptySketch(t *testing.T) { SketchLocation: filepath.Join("sketch1", "sketch.ino"), FQBN: "arduino:avr:uno", ArduinoAPIVersion: "10600", + Verbose: true, } buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) - context[constants.CTX_VERBOSE] = true ctx.DebugLevel = 10 command := builder.Builder{} @@ -88,13 +88,12 @@ func TestBuilderBridge(t *testing.T) { SketchLocation: filepath.Join("downloaded_libraries", "Bridge", "examples", "Bridge", "Bridge.ino"), FQBN: "arduino:avr:leonardo", ArduinoAPIVersion: "10600", + Verbose: true, } buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) - context[constants.CTX_VERBOSE] = true - command := builder.Builder{} err := command.Run(context, ctx) NoError(t, err) diff --git a/src/arduino.cc/builder/test/coan_runner_test.go b/src/arduino.cc/builder/test/coan_runner_test.go index 9ddd7ef7..fbda1e44 100644 --- a/src/arduino.cc/builder/test/coan_runner_test.go +++ b/src/arduino.cc/builder/test/coan_runner_test.go @@ -51,13 +51,12 @@ func TestCoanRunner(t *testing.T) { SketchLocation: filepath.Join("sketch2", "SketchWithIfDef.ino"), FQBN: "arduino:avr:leonardo", ArduinoAPIVersion: "10600", + Verbose: true, } buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) - context[constants.CTX_VERBOSE] = true - commands := []types.Command{ &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, &builder.SketchSourceMerger{}, diff --git a/src/arduino.cc/builder/test/create_build_options_map_test.go b/src/arduino.cc/builder/test/create_build_options_map_test.go index 35b43040..cd57b0c2 100644 --- a/src/arduino.cc/builder/test/create_build_options_map_test.go +++ b/src/arduino.cc/builder/test/create_build_options_map_test.go @@ -48,10 +48,10 @@ func TestCreateBuildOptionsMap(t *testing.T) { SketchLocation: "sketchLocation", FQBN: "fqbn", ArduinoAPIVersion: "ideVersion", + Verbose: true, } context[constants.CTX_BUILD_PATH] = "buildPath" - context[constants.CTX_VERBOSE] = true ctx.DebugLevel = 5 create := builder.CreateBuildOptionsMap{} diff --git a/src/arduino.cc/builder/test/ctags_runner_test.go b/src/arduino.cc/builder/test/ctags_runner_test.go index 10a722c9..9d096c65 100644 --- a/src/arduino.cc/builder/test/ctags_runner_test.go +++ b/src/arduino.cc/builder/test/ctags_runner_test.go @@ -55,13 +55,12 @@ func TestCTagsRunner(t *testing.T) { SketchLocation: sketchLocation, FQBN: "arduino:avr:leonardo", ArduinoAPIVersion: "10600", + Verbose: true, } buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) - context[constants.CTX_VERBOSE] = true - commands := []types.Command{ &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, @@ -107,13 +106,12 @@ func TestCTagsRunnerSketchWithClass(t *testing.T) { SketchLocation: sketchLocation, FQBN: "arduino:avr:leonardo", ArduinoAPIVersion: "10600", + Verbose: true, } buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) - context[constants.CTX_VERBOSE] = true - commands := []types.Command{ &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, @@ -157,13 +155,12 @@ func TestCTagsRunnerSketchWithTypename(t *testing.T) { SketchLocation: sketchLocation, FQBN: "arduino:avr:leonardo", ArduinoAPIVersion: "10600", + Verbose: true, } buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) - context[constants.CTX_VERBOSE] = true - commands := []types.Command{ &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, @@ -206,13 +203,12 @@ func TestCTagsRunnerSketchWithNamespace(t *testing.T) { SketchLocation: sketchLocation, FQBN: "arduino:avr:leonardo", ArduinoAPIVersion: "10600", + Verbose: true, } buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) - context[constants.CTX_VERBOSE] = true - commands := []types.Command{ &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, @@ -254,13 +250,12 @@ func TestCTagsRunnerSketchWithTemplates(t *testing.T) { SketchLocation: sketchLocation, FQBN: "arduino:avr:leonardo", ArduinoAPIVersion: "10600", + Verbose: true, } buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) - context[constants.CTX_VERBOSE] = true - commands := []types.Command{ &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, diff --git a/src/arduino.cc/builder/test/includes_finder_with_gcc_test.go b/src/arduino.cc/builder/test/includes_finder_with_gcc_test.go index 29312ca8..5135ba93 100644 --- a/src/arduino.cc/builder/test/includes_finder_with_gcc_test.go +++ b/src/arduino.cc/builder/test/includes_finder_with_gcc_test.go @@ -51,13 +51,12 @@ func TestIncludesFinderWithGCC(t *testing.T) { SketchLocation: filepath.Join("sketch2", "SketchWithIfDef.ino"), FQBN: "arduino:avr:leonardo", ArduinoAPIVersion: "10600", + Verbose: true, } buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) - context[constants.CTX_VERBOSE] = true - commands := []types.Command{ &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, @@ -87,13 +86,12 @@ func TestIncludesFinderWithGCCSketchWithConfig(t *testing.T) { SketchLocation: filepath.Join("sketch_with_config", "sketch_with_config.ino"), FQBN: "arduino:avr:leonardo", ArduinoAPIVersion: "10600", + Verbose: true, } buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) - context[constants.CTX_VERBOSE] = true - commands := []types.Command{ &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, @@ -129,13 +127,12 @@ func TestIncludesFinderWithGCCSketchWithDependendLibraries(t *testing.T) { SketchLocation: filepath.Join("sketch_with_dependend_libraries", "sketch.ino"), FQBN: "arduino:avr:leonardo", ArduinoAPIVersion: "10600", + Verbose: true, } buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) - context[constants.CTX_VERBOSE] = true - commands := []types.Command{ &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, @@ -182,13 +179,12 @@ func TestIncludesFinderWithGCCSketchWithThatChecksIfSPIHasTransactions(t *testin SketchLocation: filepath.Join("sketch_that_checks_if_SPI_has_transactions", "sketch.ino"), FQBN: "arduino:avr:leonardo", ArduinoAPIVersion: "10600", + Verbose: true, } buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) - context[constants.CTX_VERBOSE] = true - commands := []types.Command{ &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, @@ -225,13 +221,12 @@ func TestIncludesFinderWithGCCSketchWithThatChecksIfSPIHasTransactionsAndInclude SketchLocation: filepath.Join("sketch_that_checks_if_SPI_has_transactions_and_includes_missing_Ethernet", "sketch.ino"), FQBN: "arduino:avr:leonardo", ArduinoAPIVersion: "10600", + Verbose: true, } buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) - context[constants.CTX_VERBOSE] = true - commands := []types.Command{ &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, diff --git a/src/arduino.cc/builder/test/includes_finder_with_regexp_test.go b/src/arduino.cc/builder/test/includes_finder_with_regexp_test.go index 1b40826e..55f13a8e 100644 --- a/src/arduino.cc/builder/test/includes_finder_with_regexp_test.go +++ b/src/arduino.cc/builder/test/includes_finder_with_regexp_test.go @@ -50,13 +50,12 @@ func TestIncludesFinderWithRegExpCoanOutput(t *testing.T) { SketchLocation: filepath.Join("sketch2", "SketchWithIfDef.ino"), FQBN: "arduino:avr:leonardo", ArduinoAPIVersion: "10600", + Verbose: true, } buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) - context[constants.CTX_VERBOSE] = true - commands := []types.Command{ &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, diff --git a/src/arduino.cc/builder/test/includes_to_include_folders_test.go b/src/arduino.cc/builder/test/includes_to_include_folders_test.go index 3b2ebd92..ddb05732 100644 --- a/src/arduino.cc/builder/test/includes_to_include_folders_test.go +++ b/src/arduino.cc/builder/test/includes_to_include_folders_test.go @@ -52,13 +52,12 @@ func TestIncludesToIncludeFolders(t *testing.T) { SketchLocation: filepath.Join("downloaded_libraries", "Bridge", "examples", "Bridge", "Bridge.ino"), FQBN: "arduino:avr:leonardo", ArduinoAPIVersion: "10600", + Verbose: true, } buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) - context[constants.CTX_VERBOSE] = true - commands := []types.Command{ &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, @@ -94,13 +93,12 @@ func TestIncludesToIncludeFoldersSketchWithIfDef(t *testing.T) { SketchLocation: filepath.Join("sketch2", "SketchWithIfDef.ino"), FQBN: "arduino:avr:leonardo", ArduinoAPIVersion: "10600", + Verbose: true, } buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) - context[constants.CTX_VERBOSE] = true - commands := []types.Command{ &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, @@ -134,13 +132,12 @@ func TestIncludesToIncludeFoldersIRremoteLibrary(t *testing.T) { SketchLocation: filepath.Join("sketch9", "sketch.ino"), FQBN: "arduino:avr:leonardo", ArduinoAPIVersion: "10600", + Verbose: true, } buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) - context[constants.CTX_VERBOSE] = true - commands := []types.Command{ &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, @@ -179,13 +176,12 @@ func TestIncludesToIncludeFoldersANewLibrary(t *testing.T) { SketchLocation: filepath.Join("sketch10", "sketch.ino"), FQBN: "arduino:avr:leonardo", ArduinoAPIVersion: "10600", + Verbose: true, } buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) - context[constants.CTX_VERBOSE] = true - commands := []types.Command{ &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, @@ -223,13 +219,12 @@ func TestIncludesToIncludeFoldersDuplicateLibs(t *testing.T) { SketchLocation: filepath.Join("user_hardware", "my_avr_platform", "avr", "libraries", "SPI", "examples", "BarometricPressureSensor", "BarometricPressureSensor.ino"), FQBN: "my_avr_platform:avr:custom_yun", ArduinoAPIVersion: "10600", + Verbose: true, } buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) - context[constants.CTX_VERBOSE] = true - commands := []types.Command{ &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, @@ -267,13 +262,12 @@ func TestIncludesToIncludeFoldersDuplicateLibsWithConflictingLibsOutsideOfPlatfo SketchLocation: filepath.Join("user_hardware", "my_avr_platform", "avr", "libraries", "SPI", "examples", "BarometricPressureSensor", "BarometricPressureSensor.ino"), FQBN: "my_avr_platform:avr:custom_yun", ArduinoAPIVersion: "10600", + Verbose: true, } buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) - context[constants.CTX_VERBOSE] = true - commands := []types.Command{ &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, @@ -311,13 +305,12 @@ func TestIncludesToIncludeFoldersDuplicateLibs2(t *testing.T) { SketchLocation: filepath.Join("sketch_usbhost", "sketch_usbhost.ino"), FQBN: "arduino:samd:arduino_zero_native", ArduinoAPIVersion: "10600", + Verbose: true, } buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) - context[constants.CTX_VERBOSE] = true - commands := []types.Command{ &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, diff --git a/src/arduino.cc/builder/test/prototypes_adder_test.go b/src/arduino.cc/builder/test/prototypes_adder_test.go index 9cff0114..c7b27352 100644 --- a/src/arduino.cc/builder/test/prototypes_adder_test.go +++ b/src/arduino.cc/builder/test/prototypes_adder_test.go @@ -56,12 +56,12 @@ func TestPrototypesAdderBridgeExample(t *testing.T) { SketchLocation: sketchLocation, FQBN: "arduino:avr:leonardo", ArduinoAPIVersion: "10600", + Verbose: true, } buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) - context[constants.CTX_VERBOSE] = true ctx.DebugLevel = 10 commands := []types.Command{ @@ -99,13 +99,12 @@ func TestPrototypesAdderSketchWithIfDef(t *testing.T) { SketchLocation: filepath.Join("sketch2", "SketchWithIfDef.ino"), FQBN: "arduino:avr:leonardo", ArduinoAPIVersion: "10600", + Verbose: true, } buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) - context[constants.CTX_VERBOSE] = true - commands := []types.Command{ &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, @@ -141,13 +140,12 @@ func TestPrototypesAdderBaladuino(t *testing.T) { SketchLocation: filepath.Join("sketch3", "Baladuino.ino"), FQBN: "arduino:avr:leonardo", ArduinoAPIVersion: "10600", + Verbose: true, } buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) - context[constants.CTX_VERBOSE] = true - commands := []types.Command{ &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, @@ -183,13 +181,12 @@ func TestPrototypesAdderCharWithEscapedDoubleQuote(t *testing.T) { SketchLocation: filepath.Join("sketch4", "CharWithEscapedDoubleQuote.ino"), FQBN: "arduino:avr:leonardo", ArduinoAPIVersion: "10600", + Verbose: true, } buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) - context[constants.CTX_VERBOSE] = true - commands := []types.Command{ &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, @@ -225,13 +222,12 @@ func TestPrototypesAdderIncludeBetweenMultilineComment(t *testing.T) { SketchLocation: filepath.Join("sketch5", "IncludeBetweenMultilineComment.ino"), FQBN: "arduino:sam:arduino_due_x_dbg", ArduinoAPIVersion: "10600", + Verbose: true, } buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) - context[constants.CTX_VERBOSE] = true - commands := []types.Command{ &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, @@ -267,13 +263,12 @@ func TestPrototypesAdderLineContinuations(t *testing.T) { SketchLocation: filepath.Join("sketch6", "/LineContinuations.ino"), FQBN: "arduino:avr:leonardo", ArduinoAPIVersion: "10600", + Verbose: true, } buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) - context[constants.CTX_VERBOSE] = true - commands := []types.Command{ &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, @@ -309,13 +304,12 @@ func TestPrototypesAdderStringWithComment(t *testing.T) { SketchLocation: filepath.Join("sketch7", "StringWithComment.ino"), FQBN: "arduino:avr:leonardo", ArduinoAPIVersion: "10600", + Verbose: true, } buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) - context[constants.CTX_VERBOSE] = true - commands := []types.Command{ &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, @@ -351,13 +345,12 @@ func TestPrototypesAdderSketchWithStruct(t *testing.T) { SketchLocation: filepath.Join("sketch8", "SketchWithStruct.ino"), FQBN: "arduino:avr:leonardo", ArduinoAPIVersion: "10600", + Verbose: true, } buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) - context[constants.CTX_VERBOSE] = true - commands := []types.Command{ &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, @@ -401,13 +394,12 @@ func TestPrototypesAdderSketchWithConfig(t *testing.T) { SketchLocation: sketchLocation, FQBN: "arduino:avr:leonardo", ArduinoAPIVersion: "10600", + Verbose: true, } buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) - context[constants.CTX_VERBOSE] = true - commands := []types.Command{ &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, @@ -449,13 +441,12 @@ func TestPrototypesAdderSketchNoFunctionsTwoFiles(t *testing.T) { SketchLocation: filepath.Join("sketch_no_functions_two_files", "main.ino"), FQBN: "arduino:avr:leonardo", ArduinoAPIVersion: "10600", + Verbose: true, } buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) - context[constants.CTX_VERBOSE] = true - commands := []types.Command{ &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, @@ -491,6 +482,7 @@ func TestPrototypesAdderSketchNoFunctions(t *testing.T) { SketchLocation: filepath.Join("sketch_no_functions", "main.ino"), FQBN: "arduino:avr:leonardo", ArduinoAPIVersion: "10600", + Verbose: true, } buildPath := SetupBuildPath(t, context) @@ -499,8 +491,6 @@ func TestPrototypesAdderSketchNoFunctions(t *testing.T) { sketchLocation := filepath.Join("sketch_no_functions", "main.ino") absoluteSketchLocation := strings.Replace(Abs(t, sketchLocation), "\\", "\\\\", -1) - context[constants.CTX_VERBOSE] = true - commands := []types.Command{ &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, @@ -539,13 +529,12 @@ func TestPrototypesAdderSketchWithDefaultArgs(t *testing.T) { SketchLocation: sketchLocation, FQBN: "arduino:avr:leonardo", ArduinoAPIVersion: "10600", + Verbose: true, } buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) - context[constants.CTX_VERBOSE] = true - commands := []types.Command{ &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, @@ -584,13 +573,12 @@ func TestPrototypesAdderSketchWithInlineFunction(t *testing.T) { SketchLocation: sketchLocation, FQBN: "arduino:avr:leonardo", ArduinoAPIVersion: "10600", + Verbose: true, } buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) - context[constants.CTX_VERBOSE] = true - commands := []types.Command{ &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, @@ -640,13 +628,12 @@ func TestPrototypesAdderSketchWithFunctionSignatureInsideIFDEF(t *testing.T) { SketchLocation: sketchLocation, FQBN: "arduino:avr:leonardo", ArduinoAPIVersion: "10600", + Verbose: true, } buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) - context[constants.CTX_VERBOSE] = true - commands := []types.Command{ &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, @@ -685,13 +672,12 @@ func TestPrototypesAdderSketchWithUSBCON(t *testing.T) { SketchLocation: sketchLocation, FQBN: "arduino:avr:leonardo", ArduinoAPIVersion: "10600", + Verbose: true, } buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) - context[constants.CTX_VERBOSE] = true - commands := []types.Command{ &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, @@ -729,13 +715,12 @@ func TestPrototypesAdderSketchWithTypename(t *testing.T) { SketchLocation: sketchLocation, FQBN: "arduino:avr:leonardo", ArduinoAPIVersion: "10600", + Verbose: true, } buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) - context[constants.CTX_VERBOSE] = true - commands := []types.Command{ &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, @@ -780,13 +765,12 @@ func TestPrototypesAdderSketchWithIfDef2(t *testing.T) { SketchLocation: sketchLocation, FQBN: "arduino:avr:yun", ArduinoAPIVersion: "10600", + Verbose: true, } buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) - context[constants.CTX_VERBOSE] = true - commands := []types.Command{ &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, @@ -828,13 +812,12 @@ func TestPrototypesAdderSketchWithIfDef2SAM(t *testing.T) { SketchLocation: sketchLocation, FQBN: "arduino:sam:arduino_due_x_dbg", ArduinoAPIVersion: "10600", + Verbose: true, } buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) - context[constants.CTX_VERBOSE] = true - commands := []types.Command{ &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, @@ -876,13 +859,12 @@ func TestPrototypesAdderSketchWithConst(t *testing.T) { SketchLocation: sketchLocation, FQBN: "arduino:avr:uno", ArduinoAPIVersion: "10600", + Verbose: true, } buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) - context[constants.CTX_VERBOSE] = true - commands := []types.Command{ &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, @@ -918,13 +900,12 @@ func TestPrototypesAdderSketchWithDosEol(t *testing.T) { SketchLocation: filepath.Join("eol_processing", "sketch.ino"), FQBN: "arduino:avr:uno", ArduinoAPIVersion: "10600", + Verbose: true, } buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) - context[constants.CTX_VERBOSE] = true - commands := []types.Command{ &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, diff --git a/src/arduino.cc/builder/test/store_build_options_map_test.go b/src/arduino.cc/builder/test/store_build_options_map_test.go index 7b807d70..29cbfbc0 100644 --- a/src/arduino.cc/builder/test/store_build_options_map_test.go +++ b/src/arduino.cc/builder/test/store_build_options_map_test.go @@ -51,14 +51,13 @@ func TestStoreBuildOptionsMap(t *testing.T) { FQBN: "fqbn", ArduinoAPIVersion: "ideVersion", CustomBuildProperties: []string{"custom=prop"}, + Verbose: true, + DebugLevel: 5, } buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) - context[constants.CTX_VERBOSE] = true - ctx.DebugLevel = 5 - commands := []types.Command{ &builder.CreateBuildOptionsMap{}, &builder.StoreBuildOptionsMap{}, diff --git a/src/arduino.cc/builder/test/try_build_of_problematic_sketch_test.go b/src/arduino.cc/builder/test/try_build_of_problematic_sketch_test.go index d0237c7e..d5c2e69a 100644 --- a/src/arduino.cc/builder/test/try_build_of_problematic_sketch_test.go +++ b/src/arduino.cc/builder/test/try_build_of_problematic_sketch_test.go @@ -32,7 +32,6 @@ package test import ( "arduino.cc/builder" - "arduino.cc/builder/constants" "arduino.cc/builder/types" "os" "path/filepath" @@ -211,13 +210,12 @@ func makeDefaultContext(t *testing.T) (map[string]interface{}, *types.Context) { OtherLibrariesFolders: []string{"libraries"}, FQBN: "arduino:avr:leonardo", ArduinoAPIVersion: "10607", + Verbose: true, + DebugPreprocessor: true, } buildPath := SetupBuildPath(t, context) defer os.RemoveAll(buildPath) - context[constants.CTX_VERBOSE] = true - context[constants.CTX_DEBUG_PREPROCESSOR] = true - return context, ctx } diff --git a/src/arduino.cc/builder/types/context.go b/src/arduino.cc/builder/types/context.go index 4b61e2d6..0ceac68a 100644 --- a/src/arduino.cc/builder/types/context.go +++ b/src/arduino.cc/builder/types/context.go @@ -16,6 +16,10 @@ type Context struct { ArduinoAPIVersion string FQBN string + // Verbosity settings + Verbose bool + DebugPreprocessor bool + // Contents of a custom build properties file (line by line) CustomBuildProperties []string From 9a1f215a7ca9d161f33e666c78274e9e3f56d635 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Sat, 2 Apr 2016 00:56:04 +0200 Subject: [PATCH 05/25] Moving include detection into Context struct Removed also utils.AddStringsToStringsSet(..) because passing through maps for removing duplicated elements doesn't guarantee to preserve the list order. Signed-off-by: Cristian Maglie --- src/arduino.cc/builder/constants/constants.go | 3 -- .../builder/external_include_replacer.go | 6 ++-- .../builder/gcc_minus_m_output_parser.go | 10 ++---- .../builder/includes_finder_with_regexp.go | 10 +----- .../builder/includes_to_include_folders.go | 10 ++---- src/arduino.cc/builder/libraries_loader.go | 4 +-- .../test/external_include_replacer_test.go | 11 +++--- .../test/gcc_minus_m_output_parser_test.go | 19 ++++++----- .../test/includes_finder_with_gcc_test.go | 16 +++------ .../test/includes_finder_with_regexp_test.go | 34 ++++++------------- .../builder/test/libraries_loader_test.go | 8 ++--- src/arduino.cc/builder/types/context.go | 5 +++ src/arduino.cc/builder/utils/utils.go | 26 -------------- 13 files changed, 52 insertions(+), 110 deletions(-) diff --git a/src/arduino.cc/builder/constants/constants.go b/src/arduino.cc/builder/constants/constants.go index 2d4b86e8..28893e8e 100644 --- a/src/arduino.cc/builder/constants/constants.go +++ b/src/arduino.cc/builder/constants/constants.go @@ -95,14 +95,11 @@ const CTX_GCC_MINUS_E_SOURCE = "gccMinusESource" const CTX_GCC_MINUS_M_OUTPUT = "gccMinusMOutput" const CTX_HARDWARE = "hardware" const CTX_HARDWARE_REWRITE_RESULTS = "hardwareRewriteResults" -const CTX_HEADER_TO_LIBRARIES = "headerToLibraries" const CTX_IMPORTED_LIBRARIES = "importedLibraries" const CTX_INCLUDE_FOLDERS = "includeFolders" const CTX_INCLUDE_SECTION = "includeSection" -const CTX_INCLUDES = "includes" const CTX_INCLUDES_JUST_FOUND = "includesJustFound" const CTX_LIBRARIES_BUILD_PATH = "librariesBuildPath" -const CTX_LIBRARIES = "libraries" const CTX_LIBRARY_RESOLUTION_RESULTS = "libraryResolutionResults" const CTX_LINE_OFFSET = "lineOffset" const CTX_LINE_WHERE_TO_INSERT_PROTOTYPES = "lineWhereToInsertPrototypes" diff --git a/src/arduino.cc/builder/external_include_replacer.go b/src/arduino.cc/builder/external_include_replacer.go index 0e6ca0b8..7bf3db14 100644 --- a/src/arduino.cc/builder/external_include_replacer.go +++ b/src/arduino.cc/builder/external_include_replacer.go @@ -30,7 +30,7 @@ package builder import ( - "arduino.cc/builder/constants" + "arduino.cc/builder/types" "path/filepath" "strings" ) @@ -42,9 +42,9 @@ type ExternalIncludeReplacer struct { To string } -func (s *ExternalIncludeReplacer) Run(context map[string]interface{}) error { +func (s *ExternalIncludeReplacer) Run(context map[string]interface{}, ctx *types.Context) error { source := context[s.SourceKey].(string) - nonAbsoluteIncludes := findNonAbsoluteIncludes(context[constants.CTX_INCLUDES].([]string)) + nonAbsoluteIncludes := findNonAbsoluteIncludes(ctx.Includes) for _, include := range nonAbsoluteIncludes { source = strings.Replace(source, s.From+"<"+include+">", s.To+"<"+include+">", -1) diff --git a/src/arduino.cc/builder/gcc_minus_m_output_parser.go b/src/arduino.cc/builder/gcc_minus_m_output_parser.go index 757181ca..3bf84b6a 100644 --- a/src/arduino.cc/builder/gcc_minus_m_output_parser.go +++ b/src/arduino.cc/builder/gcc_minus_m_output_parser.go @@ -31,13 +31,14 @@ package builder import ( "arduino.cc/builder/constants" + "arduino.cc/builder/types" "arduino.cc/builder/utils" "strings" ) type GCCMinusMOutputParser struct{} -func (s *GCCMinusMOutputParser) Run(context map[string]interface{}) error { +func (s *GCCMinusMOutputParser) Run(context map[string]interface{}, ctx *types.Context) error { output := context[constants.CTX_GCC_MINUS_M_OUTPUT].(string) rows := strings.Split(output, "\n") @@ -55,12 +56,7 @@ func (s *GCCMinusMOutputParser) Run(context map[string]interface{}) error { } } - if !utils.MapHas(context, constants.CTX_INCLUDES) { - context[constants.CTX_INCLUDES] = includes - return nil - } - - context[constants.CTX_INCLUDES] = utils.AddStringsToStringsSet(context[constants.CTX_INCLUDES].([]string), includes) + ctx.Includes = utils.AppendIfNotPresent(ctx.Includes, includes...) return nil } diff --git a/src/arduino.cc/builder/includes_finder_with_regexp.go b/src/arduino.cc/builder/includes_finder_with_regexp.go index 80e306e1..ffab6854 100644 --- a/src/arduino.cc/builder/includes_finder_with_regexp.go +++ b/src/arduino.cc/builder/includes_finder_with_regexp.go @@ -51,7 +51,6 @@ func (s *IncludesFinderWithRegExp) Run(context map[string]interface{}, ctx *type for _, match := range matches { includes = append(includes, strings.TrimSpace(match[1])) } - if len(includes) == 0 { include := findIncludesForOldCompilers(source) if include != "" { @@ -60,14 +59,7 @@ func (s *IncludesFinderWithRegExp) Run(context map[string]interface{}, ctx *type } context[constants.CTX_INCLUDES_JUST_FOUND] = includes - - if !utils.MapHas(context, constants.CTX_INCLUDES) { - context[constants.CTX_INCLUDES] = includes - return nil - } - - context[constants.CTX_INCLUDES] = utils.AddStringsToStringsSet(context[constants.CTX_INCLUDES].([]string), includes) - + ctx.Includes = utils.AppendIfNotPresent(ctx.Includes, includes...) return nil } diff --git a/src/arduino.cc/builder/includes_to_include_folders.go b/src/arduino.cc/builder/includes_to_include_folders.go index ea159512..e95ed75f 100644 --- a/src/arduino.cc/builder/includes_to_include_folders.go +++ b/src/arduino.cc/builder/includes_to_include_folders.go @@ -42,14 +42,8 @@ import ( type IncludesToIncludeFolders struct{} func (s *IncludesToIncludeFolders) Run(context map[string]interface{}, ctx *types.Context) error { - includes := []string{} - if utils.MapHas(context, constants.CTX_INCLUDES) { - includes = context[constants.CTX_INCLUDES].([]string) - } - headerToLibraries := make(map[string][]*types.Library) - if utils.MapHas(context, constants.CTX_HEADER_TO_LIBRARIES) { - headerToLibraries = context[constants.CTX_HEADER_TO_LIBRARIES].(map[string][]*types.Library) - } + includes := ctx.Includes + headerToLibraries := ctx.HeaderToLibraries platform := context[constants.CTX_TARGET_PLATFORM].(*types.Platform) actualPlatform := context[constants.CTX_ACTUAL_PLATFORM].(*types.Platform) diff --git a/src/arduino.cc/builder/libraries_loader.go b/src/arduino.cc/builder/libraries_loader.go index f444b0f8..1e6c7bad 100644 --- a/src/arduino.cc/builder/libraries_loader.go +++ b/src/arduino.cc/builder/libraries_loader.go @@ -86,7 +86,7 @@ func (s *LibrariesLoader) Run(context map[string]interface{}, ctx *types.Context } } - context[constants.CTX_LIBRARIES] = libraries + ctx.Libraries = libraries headerToLibraries := make(map[string][]*types.Library) for _, library := range libraries { @@ -100,7 +100,7 @@ func (s *LibrariesLoader) Run(context map[string]interface{}, ctx *types.Context } } - context[constants.CTX_HEADER_TO_LIBRARIES] = headerToLibraries + ctx.HeaderToLibraries = headerToLibraries return nil } diff --git a/src/arduino.cc/builder/test/external_include_replacer_test.go b/src/arduino.cc/builder/test/external_include_replacer_test.go index ad8a5250..2301a07b 100644 --- a/src/arduino.cc/builder/test/external_include_replacer_test.go +++ b/src/arduino.cc/builder/test/external_include_replacer_test.go @@ -32,6 +32,7 @@ package test import ( "arduino.cc/builder" "arduino.cc/builder/constants" + "arduino.cc/builder/types" "github.com/stretchr/testify/require" "testing" ) @@ -72,11 +73,12 @@ var sourceWithPragmas = "#line 1 \"sketch_with_config.ino\"\n" + func TestExternalIncludeReplacerIncludeToPragma(t *testing.T) { context := make(map[string]interface{}) + ctx := &types.Context{} context[constants.CTX_SOURCE] = sourceWithIncludes - context[constants.CTX_INCLUDES] = []string{"/tmp/test184599776/sketch/config.h", "/tmp/test184599776/sketch/includes/de bug.h", "Bridge.h"} + ctx.Includes = []string{"/tmp/test184599776/sketch/config.h", "/tmp/test184599776/sketch/includes/de bug.h", "Bridge.h"} replacer := builder.ExternalIncludeReplacer{SourceKey: constants.CTX_SOURCE, TargetKey: constants.CTX_GCC_MINUS_E_SOURCE, From: "#include ", To: "#pragma ___MY_INCLUDE___ "} - err := replacer.Run(context) + err := replacer.Run(context, ctx) NoError(t, err) require.Equal(t, sourceWithIncludes, context[constants.CTX_SOURCE].(string)) @@ -85,11 +87,12 @@ func TestExternalIncludeReplacerIncludeToPragma(t *testing.T) { func TestExternalIncludeReplacerPragmaToInclude(t *testing.T) { context := make(map[string]interface{}) + ctx := &types.Context{} context[constants.CTX_GCC_MINUS_E_SOURCE] = sourceWithPragmas - context[constants.CTX_INCLUDES] = []string{"/tmp/test184599776/sketch/config.h", "/tmp/test184599776/sketch/includes/de bug.h", "Bridge.h"} + ctx.Includes = []string{"/tmp/test184599776/sketch/config.h", "/tmp/test184599776/sketch/includes/de bug.h", "Bridge.h"} replacer := builder.ExternalIncludeReplacer{SourceKey: constants.CTX_GCC_MINUS_E_SOURCE, TargetKey: constants.CTX_GCC_MINUS_E_SOURCE, From: "#pragma ___MY_INCLUDE___ ", To: "#include "} - err := replacer.Run(context) + err := replacer.Run(context, ctx) NoError(t, err) require.Nil(t, context[constants.CTX_SOURCE]) diff --git a/src/arduino.cc/builder/test/gcc_minus_m_output_parser_test.go b/src/arduino.cc/builder/test/gcc_minus_m_output_parser_test.go index 17917709..066136dc 100644 --- a/src/arduino.cc/builder/test/gcc_minus_m_output_parser_test.go +++ b/src/arduino.cc/builder/test/gcc_minus_m_output_parser_test.go @@ -32,12 +32,14 @@ package test import ( "arduino.cc/builder" "arduino.cc/builder/constants" + "arduino.cc/builder/types" "github.com/stretchr/testify/require" "testing" ) func TestGCCMinusMOutputParser(t *testing.T) { context := make(map[string]interface{}) + ctx := &types.Context{} output := "sketch_with_config.o: sketch_with_config.ino config.h de\\ bug.h Bridge.h\n" + "\n" + @@ -50,11 +52,10 @@ func TestGCCMinusMOutputParser(t *testing.T) { context[constants.CTX_GCC_MINUS_M_OUTPUT] = output parser := builder.GCCMinusMOutputParser{} - err := parser.Run(context) + err := parser.Run(context, ctx) NoError(t, err) - require.NotNil(t, context[constants.CTX_INCLUDES]) - includes := context[constants.CTX_INCLUDES].([]string) + includes := ctx.Includes require.Equal(t, 3, len(includes)) require.Equal(t, "config.h", includes[0]) require.Equal(t, "de bug.h", includes[1]) @@ -63,22 +64,23 @@ func TestGCCMinusMOutputParser(t *testing.T) { func TestGCCMinusMOutputParserEmptyOutput(t *testing.T) { context := make(map[string]interface{}) + ctx := &types.Context{} output := "sketch.ino.o: /tmp/test699709208/sketch/sketch.ino.cpp" context[constants.CTX_GCC_MINUS_M_OUTPUT] = output parser := builder.GCCMinusMOutputParser{} - err := parser.Run(context) + err := parser.Run(context, ctx) NoError(t, err) - require.NotNil(t, context[constants.CTX_INCLUDES]) - includes := context[constants.CTX_INCLUDES].([]string) + includes := ctx.Includes require.Equal(t, 0, len(includes)) } func TestGCCMinusMOutputParserFirstLineOnMultipleLines(t *testing.T) { context := make(map[string]interface{}) + ctx := &types.Context{} output := "sketch_with_config.ino.o: \\\n" + " /tmp/test097286304/sketch/sketch_with_config.ino.cpp \\\n" + @@ -94,11 +96,10 @@ func TestGCCMinusMOutputParserFirstLineOnMultipleLines(t *testing.T) { context[constants.CTX_GCC_MINUS_M_OUTPUT] = output parser := builder.GCCMinusMOutputParser{} - err := parser.Run(context) + err := parser.Run(context, ctx) NoError(t, err) - require.NotNil(t, context[constants.CTX_INCLUDES]) - includes := context[constants.CTX_INCLUDES].([]string) + includes := ctx.Includes require.Equal(t, 3, len(includes)) require.Equal(t, "/tmp/test097286304/sketch/config.h", includes[0]) require.Equal(t, "/tmp/test097286304/sketch/includes/de bug.h", includes[1]) diff --git a/src/arduino.cc/builder/test/includes_finder_with_gcc_test.go b/src/arduino.cc/builder/test/includes_finder_with_gcc_test.go index 5135ba93..3ba30929 100644 --- a/src/arduino.cc/builder/test/includes_finder_with_gcc_test.go +++ b/src/arduino.cc/builder/test/includes_finder_with_gcc_test.go @@ -58,7 +58,6 @@ func TestIncludesFinderWithGCC(t *testing.T) { defer os.RemoveAll(buildPath) commands := []types.Command{ - &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, &builder.ContainerMergeCopySketchFiles{}, @@ -70,8 +69,7 @@ func TestIncludesFinderWithGCC(t *testing.T) { err := command.Run(context, ctx) NoError(t, err) } - - require.Nil(t, context[constants.CTX_INCLUDES]) + require.Nil(t, ctx.Includes) } func TestIncludesFinderWithGCCSketchWithConfig(t *testing.T) { @@ -106,8 +104,7 @@ func TestIncludesFinderWithGCCSketchWithConfig(t *testing.T) { NoError(t, err) } - require.NotNil(t, context[constants.CTX_INCLUDES]) - includes := context[constants.CTX_INCLUDES].([]string) + includes := ctx.Includes require.Equal(t, 1, len(includes)) require.True(t, utils.SliceContains(includes, "Bridge.h")) @@ -147,8 +144,7 @@ func TestIncludesFinderWithGCCSketchWithDependendLibraries(t *testing.T) { NoError(t, err) } - require.NotNil(t, context[constants.CTX_INCLUDES]) - includes := context[constants.CTX_INCLUDES].([]string) + includes := ctx.Includes require.Equal(t, 4, len(includes)) sort.Strings(includes) @@ -199,8 +195,7 @@ func TestIncludesFinderWithGCCSketchWithThatChecksIfSPIHasTransactions(t *testin NoError(t, err) } - require.NotNil(t, context[constants.CTX_INCLUDES]) - includes := context[constants.CTX_INCLUDES].([]string) + includes := ctx.Includes require.Equal(t, 1, len(includes)) require.Equal(t, "SPI.h", includes[0]) @@ -243,8 +238,7 @@ func TestIncludesFinderWithGCCSketchWithThatChecksIfSPIHasTransactionsAndInclude err := command.Run(context, ctx) require.Error(t, err) - require.NotNil(t, context[constants.CTX_INCLUDES]) - includes := context[constants.CTX_INCLUDES].([]string) + includes := ctx.Includes require.Equal(t, 2, len(includes)) sort.Strings(includes) require.Equal(t, "Inexistent.h", includes[0]) diff --git a/src/arduino.cc/builder/test/includes_finder_with_regexp_test.go b/src/arduino.cc/builder/test/includes_finder_with_regexp_test.go index 55f13a8e..150d48be 100644 --- a/src/arduino.cc/builder/test/includes_finder_with_regexp_test.go +++ b/src/arduino.cc/builder/test/includes_finder_with_regexp_test.go @@ -57,7 +57,6 @@ func TestIncludesFinderWithRegExpCoanOutput(t *testing.T) { defer os.RemoveAll(buildPath) commands := []types.Command{ - &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, &builder.ContainerMergeCopySketchFiles{}, @@ -72,8 +71,7 @@ func TestIncludesFinderWithRegExpCoanOutput(t *testing.T) { NoError(t, err) } - require.NotNil(t, context[constants.CTX_INCLUDES]) - includes := context[constants.CTX_INCLUDES].([]string) + includes := ctx.Includes require.Equal(t, 3, len(includes)) require.Equal(t, "Arduino.h", includes[0]) require.Equal(t, "empty_1.h", includes[1]) @@ -94,8 +92,7 @@ func TestIncludesFinderWithRegExp(t *testing.T) { err := parser.Run(context, ctx) NoError(t, err) - require.NotNil(t, context[constants.CTX_INCLUDES]) - includes := context[constants.CTX_INCLUDES].([]string) + includes := ctx.Includes require.Equal(t, 1, len(includes)) require.Equal(t, "SPI.h", includes[0]) } @@ -112,16 +109,15 @@ func TestIncludesFinderWithRegExpEmptyOutput(t *testing.T) { err := parser.Run(context, ctx) NoError(t, err) - require.NotNil(t, context[constants.CTX_INCLUDES]) - includes := context[constants.CTX_INCLUDES].([]string) + includes := ctx.Includes require.Equal(t, 0, len(includes)) } func TestIncludesFinderWithRegExpPreviousIncludes(t *testing.T) { context := make(map[string]interface{}) - ctx := &types.Context{} - - context[constants.CTX_INCLUDES] = []string{"test.h"} + ctx := &types.Context{ + Includes: []string{"test.h"}, + } output := "/some/path/sketch.ino:1:17: fatal error: SPI.h: No such file or directory\n" + "#include \n" + @@ -134,8 +130,7 @@ func TestIncludesFinderWithRegExpPreviousIncludes(t *testing.T) { err := parser.Run(context, ctx) NoError(t, err) - require.NotNil(t, context[constants.CTX_INCLUDES]) - includes := context[constants.CTX_INCLUDES].([]string) + includes := ctx.Includes require.Equal(t, 2, len(includes)) sort.Strings(includes) require.Equal(t, "SPI.h", includes[0]) @@ -146,8 +141,6 @@ func TestIncludesFinderWithRegExpPaddedIncludes(t *testing.T) { context := make(map[string]interface{}) ctx := &types.Context{} - context[constants.CTX_INCLUDES] = []string{} - output := "/some/path/sketch.ino:1:33: fatal error: Wire.h: No such file or directory\n" + " # include \n" + " ^\n" + @@ -158,8 +151,7 @@ func TestIncludesFinderWithRegExpPaddedIncludes(t *testing.T) { err := parser.Run(context, ctx) NoError(t, err) - require.NotNil(t, context[constants.CTX_INCLUDES]) - includes := context[constants.CTX_INCLUDES].([]string) + includes := ctx.Includes require.Equal(t, 1, len(includes)) sort.Strings(includes) require.Equal(t, "Wire.h", includes[0]) @@ -169,8 +161,6 @@ func TestIncludesFinderWithRegExpPaddedIncludes2(t *testing.T) { context := make(map[string]interface{}) ctx := &types.Context{} - context[constants.CTX_INCLUDES] = []string{} - output := "/some/path/sketch.ino:1:33: fatal error: Wire.h: No such file or directory\n" + " #\t\t\tinclude \n" + " ^\n" + @@ -181,8 +171,7 @@ func TestIncludesFinderWithRegExpPaddedIncludes2(t *testing.T) { err := parser.Run(context, ctx) NoError(t, err) - require.NotNil(t, context[constants.CTX_INCLUDES]) - includes := context[constants.CTX_INCLUDES].([]string) + includes := ctx.Includes require.Equal(t, 1, len(includes)) sort.Strings(includes) require.Equal(t, "Wire.h", includes[0]) @@ -192,8 +181,6 @@ func TestIncludesFinderWithRegExpPaddedIncludes3(t *testing.T) { context := make(map[string]interface{}) ctx := &types.Context{} - context[constants.CTX_INCLUDES] = []string{} - output := "/some/path/sketch.ino:1:33: fatal error: SPI.h: No such file or directory\n" + "compilation terminated.\n" @@ -203,8 +190,7 @@ func TestIncludesFinderWithRegExpPaddedIncludes3(t *testing.T) { err := parser.Run(context, ctx) NoError(t, err) - require.NotNil(t, context[constants.CTX_INCLUDES]) - includes := context[constants.CTX_INCLUDES].([]string) + includes := ctx.Includes require.Equal(t, 1, len(includes)) sort.Strings(includes) require.Equal(t, "SPI.h", includes[0]) diff --git a/src/arduino.cc/builder/test/libraries_loader_test.go b/src/arduino.cc/builder/test/libraries_loader_test.go index 79a97e25..cc2857a4 100644 --- a/src/arduino.cc/builder/test/libraries_loader_test.go +++ b/src/arduino.cc/builder/test/libraries_loader_test.go @@ -68,7 +68,7 @@ func TestLoadLibrariesAVR(t *testing.T) { require.Equal(t, Abs(t, filepath.Join("downloaded_hardware", "arduino", "avr", "libraries")), librariesFolders[1]) require.Equal(t, Abs(t, filepath.Join("libraries")), librariesFolders[2]) - libraries := context[constants.CTX_LIBRARIES].([]*types.Library) + libraries := ctx.Libraries require.Equal(t, 20, len(libraries)) sort.Sort(ByLibraryName(libraries)) @@ -131,7 +131,7 @@ func TestLoadLibrariesAVR(t *testing.T) { idx++ require.Equal(t, "Wire", libraries[idx].Name) - headerToLibraries := context[constants.CTX_HEADER_TO_LIBRARIES].(map[string][]*types.Library) + headerToLibraries := ctx.HeaderToLibraries require.Equal(t, 2, len(headerToLibraries["Audio.h"])) require.Equal(t, "Audio", headerToLibraries["Audio.h"][0].Name) require.Equal(t, "FakeAudio", headerToLibraries["Audio.h"][1].Name) @@ -178,7 +178,7 @@ func TestLoadLibrariesSAM(t *testing.T) { require.Equal(t, Abs(t, filepath.Join("downloaded_hardware", "arduino", "sam", "libraries")), librariesFolders[1]) require.Equal(t, Abs(t, filepath.Join("libraries")), librariesFolders[2]) - libraries := context[constants.CTX_LIBRARIES].([]*types.Library) + libraries := ctx.Libraries require.Equal(t, 18, len(libraries)) sort.Sort(ByLibraryName(libraries)) @@ -218,7 +218,7 @@ func TestLoadLibrariesSAM(t *testing.T) { idx++ require.Equal(t, "Wire", libraries[idx].Name) - headerToLibraries := context[constants.CTX_HEADER_TO_LIBRARIES].(map[string][]*types.Library) + headerToLibraries := ctx.HeaderToLibraries require.Equal(t, 2, len(headerToLibraries["Audio.h"])) libraries = headerToLibraries["Audio.h"] diff --git a/src/arduino.cc/builder/types/context.go b/src/arduino.cc/builder/types/context.go index 0ceac68a..43dde582 100644 --- a/src/arduino.cc/builder/types/context.go +++ b/src/arduino.cc/builder/types/context.go @@ -16,6 +16,11 @@ type Context struct { ArduinoAPIVersion string FQBN string + // Libraries handling + Includes []string + Libraries []*Library + HeaderToLibraries map[string][]*Library + // Verbosity settings Verbose bool DebugPreprocessor bool diff --git a/src/arduino.cc/builder/utils/utils.go b/src/arduino.cc/builder/utils/utils.go index 5924859e..16a11d18 100644 --- a/src/arduino.cc/builder/utils/utils.go +++ b/src/arduino.cc/builder/utils/utils.go @@ -59,23 +59,6 @@ func KeysOfMapOfString(input map[string]string) []string { return keys } -func KeysOfMapOfStringBool(input map[string]bool) []string { - var keys []string - for key, _ := range input { - keys = append(keys, key) - } - return keys -} - -func MergeMapsOfStringBool(target map[string]bool, sources ...map[string]bool) map[string]bool { - for _, source := range sources { - for key, value := range source { - target[key] = value - } - } - return target -} - func PrettyOSName() string { switch osName := runtime.GOOS; osName { case "darwin": @@ -356,15 +339,6 @@ func AppendIfNotPresent(target []string, elements ...string) []string { return target } -func AddStringsToStringsSet(accumulator []string, stringsToAdd []string) []string { - previousStringsSet := SliceToMapStringBool(accumulator, true) - stringsSetToAdd := SliceToMapStringBool(stringsToAdd, true) - - newStringsSet := MergeMapsOfStringBool(previousStringsSet, stringsSetToAdd) - - return KeysOfMapOfStringBool(newStringsSet) -} - func EnsureFolderExists(folder string) error { return os.MkdirAll(folder, os.FileMode(0755)) } From d5ae87c292214bff0d27526c4c172d84ed87e5b1 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Sun, 3 Apr 2016 01:38:21 +0200 Subject: [PATCH 06/25] Refactored a bunch of ctags related context variables Signed-off-by: Cristian Maglie --- .../collect_ctags_from_sketch_files.go | 4 +- ...ototypes_from_source_and_preproc_source.go | 13 +- src/arduino.cc/builder/constants/constants.go | 8 -- src/arduino.cc/builder/ctags/ctags_parser.go | 4 +- src/arduino.cc/builder/ctags/ctags_runner.go | 4 +- .../builder/ctags/ctags_to_prototypes.go | 9 +- .../builder/ctags_target_file_saver.go | 2 +- src/arduino.cc/builder/prototypes_adder.go | 11 +- .../builder/test/ctags_parser_test.go | 57 ++++---- .../builder/test/ctags_runner_test.go | 10 +- .../builder/test/ctags_to_prototypes_test.go | 135 ++++++++---------- src/arduino.cc/builder/test/helper.go | 10 -- .../builder/test/prototypes_adder_test.go | 24 ++-- src/arduino.cc/builder/types/context.go | 10 ++ 14 files changed, 136 insertions(+), 165 deletions(-) diff --git a/src/arduino.cc/builder/collect_ctags_from_sketch_files.go b/src/arduino.cc/builder/collect_ctags_from_sketch_files.go index 34c79863..c5e0d592 100644 --- a/src/arduino.cc/builder/collect_ctags_from_sketch_files.go +++ b/src/arduino.cc/builder/collect_ctags_from_sketch_files.go @@ -42,7 +42,7 @@ func (s *CollectCTagsFromSketchFiles) Run(context map[string]interface{}, ctx *t sketch := context[constants.CTX_SKETCH].(*types.Sketch) sketchFileNames := collectSketchFileNamesFrom(sketch) - allCtags := context[constants.CTX_CTAGS_OF_PREPROC_SOURCE].([]*types.CTag) + allCtags := ctx.CTagsOfPreprocessedSource ctagsOfSketch := []*types.CTag{} for _, ctag := range allCtags { if utils.SliceContains(sketchFileNames, strings.Replace(ctag.Filename, "\\\\", "\\", -1)) { @@ -50,7 +50,7 @@ func (s *CollectCTagsFromSketchFiles) Run(context map[string]interface{}, ctx *t } } - context[constants.CTX_COLLECTED_CTAGS] = ctagsOfSketch + ctx.CTagsCollected = ctagsOfSketch return nil } diff --git a/src/arduino.cc/builder/compare_prototypes_from_source_and_preproc_source.go b/src/arduino.cc/builder/compare_prototypes_from_source_and_preproc_source.go index 7139da2d..902725d7 100644 --- a/src/arduino.cc/builder/compare_prototypes_from_source_and_preproc_source.go +++ b/src/arduino.cc/builder/compare_prototypes_from_source_and_preproc_source.go @@ -29,16 +29,13 @@ package builder -import ( - "arduino.cc/builder/constants" - "arduino.cc/builder/types" -) +import "arduino.cc/builder/types" type ComparePrototypesFromSourceAndPreprocSource struct{} -func (s *ComparePrototypesFromSourceAndPreprocSource) Run(context map[string]interface{}) error { - ctagsOfSource := context[constants.CTX_CTAGS_OF_SOURCE].([]*types.CTag) - ctagsOfPreprocSource := context[constants.CTX_CTAGS_OF_PREPROC_SOURCE].([]*types.CTag) +func (s *ComparePrototypesFromSourceAndPreprocSource) Run(context map[string]interface{}, ctx *types.Context) error { + ctagsOfSource := ctx.CTagsOfSource + ctagsOfPreprocSource := ctx.CTagsOfPreprocessedSource actualCTags := []*types.CTag{} for _, ctagOfPreprocSource := range ctagsOfPreprocSource { @@ -47,7 +44,7 @@ func (s *ComparePrototypesFromSourceAndPreprocSource) Run(context map[string]int } } - context[constants.CTX_COLLECTED_CTAGS] = actualCTags + ctx.CTagsCollected = actualCTags return nil } diff --git a/src/arduino.cc/builder/constants/constants.go b/src/arduino.cc/builder/constants/constants.go index 28893e8e..6bdc0e26 100644 --- a/src/arduino.cc/builder/constants/constants.go +++ b/src/arduino.cc/builder/constants/constants.go @@ -82,13 +82,8 @@ const CTX_BUILD_OPTIONS_JSON = "buildOptionsJson" const CTX_BUILD_OPTIONS_PREVIOUS_JSON = "buildOptionsPreviousJson" const CTX_BUILD_PATH = "buildPath" const CTX_BUILD_PROPERTIES = "buildProperties" -const CTX_COLLECTED_CTAGS = "collectedCTags" const CTX_COLLECTED_SOURCE_FILES_QUEUE = "collectedSourceFilesQueue" const CTX_CORE_BUILD_PATH = "coreBuildPath" -const CTX_CTAGS_OF_PREPROC_SOURCE = "ctagsOfPreprocSource" -const CTX_CTAGS_OF_SOURCE = "ctagsOfSource" -const CTX_CTAGS_OUTPUT = "ctagsOutput" -const CTX_CTAGS_TEMP_FILE_PATH = "ctagsTempFilePath" const CTX_FILE_PATH_TO_READ = "filePathToRead" const CTX_FOLDERS_WITH_SOURCES_QUEUE = "foldersWithSourcesQueue" const CTX_GCC_MINUS_E_SOURCE = "gccMinusESource" @@ -102,14 +97,11 @@ const CTX_INCLUDES_JUST_FOUND = "includesJustFound" const CTX_LIBRARIES_BUILD_PATH = "librariesBuildPath" const CTX_LIBRARY_RESOLUTION_RESULTS = "libraryResolutionResults" const CTX_LINE_OFFSET = "lineOffset" -const CTX_LINE_WHERE_TO_INSERT_PROTOTYPES = "lineWhereToInsertPrototypes" const CTX_OBJECT_FILES_CORE = "objectFilesCore" const CTX_OBJECT_FILES_LIBRARIES = "objectFilesLibraries" const CTX_OBJECT_FILES_SKETCH = "objectFilesSketch" const CTX_PLATFORM_KEYS_REWRITE = "platformKeysRewrite" const CTX_PREPROC_PATH = "preprocPath" -const CTX_PROTOTYPE_SECTION = "prototypeSection" -const CTX_PROTOTYPES = "prototypes" const CTX_SKETCH_BUILD_PATH = "sketchBuildPath" const CTX_SKETCH = "sketch" const CTX_SOURCE = "source" diff --git a/src/arduino.cc/builder/ctags/ctags_parser.go b/src/arduino.cc/builder/ctags/ctags_parser.go index 3834bc53..31245b27 100644 --- a/src/arduino.cc/builder/ctags/ctags_parser.go +++ b/src/arduino.cc/builder/ctags/ctags_parser.go @@ -57,7 +57,7 @@ var KNOWN_TAG_KINDS = map[string]bool{ type CTagsParser struct{} func (s *CTagsParser) Run(context map[string]interface{}, ctx *types.Context) error { - rows := strings.Split(context[constants.CTX_CTAGS_OUTPUT].(string), "\n") + rows := strings.Split(ctx.CTagsOutput, "\n") rows = removeEmpty(rows) @@ -73,7 +73,7 @@ func (s *CTagsParser) Run(context map[string]interface{}, ctx *types.Context) er removeDuplicate(tags) skipTagsWhere(tags, prototypeAndCodeDontMatch, ctx) - context[constants.CTX_CTAGS_OF_PREPROC_SOURCE] = tags + ctx.CTagsOfPreprocessedSource = tags return nil } diff --git a/src/arduino.cc/builder/ctags/ctags_runner.go b/src/arduino.cc/builder/ctags/ctags_runner.go index 54375a14..81301a85 100644 --- a/src/arduino.cc/builder/ctags/ctags_runner.go +++ b/src/arduino.cc/builder/ctags/ctags_runner.go @@ -42,7 +42,7 @@ type CTagsRunner struct{} func (s *CTagsRunner) Run(context map[string]interface{}, ctx *types.Context) error { buildProperties := context[constants.CTX_BUILD_PROPERTIES].(props.PropertiesMap) - ctagsTargetFilePath := context[constants.CTX_CTAGS_TEMP_FILE_PATH].(string) + ctagsTargetFilePath := ctx.CTagsTargetFile logger := ctx.GetLogger() properties := buildProperties.Clone() @@ -70,7 +70,7 @@ func (s *CTagsRunner) Run(context map[string]interface{}, ctx *types.Context) er return i18n.WrapError(err) } - context[constants.CTX_CTAGS_OUTPUT] = string(sourceBytes) + ctx.CTagsOutput = string(sourceBytes) return nil } diff --git a/src/arduino.cc/builder/ctags/ctags_to_prototypes.go b/src/arduino.cc/builder/ctags/ctags_to_prototypes.go index c9f81e75..f4ff4abe 100644 --- a/src/arduino.cc/builder/ctags/ctags_to_prototypes.go +++ b/src/arduino.cc/builder/ctags/ctags_to_prototypes.go @@ -30,7 +30,6 @@ package ctags import ( - "arduino.cc/builder/constants" "arduino.cc/builder/types" "strings" ) @@ -38,16 +37,14 @@ import ( type CTagsToPrototypes struct{} func (s *CTagsToPrototypes) Run(context map[string]interface{}, ctx *types.Context) error { - tags := context[constants.CTX_COLLECTED_CTAGS].([]*types.CTag) + tags := ctx.CTagsCollected lineWhereToInsertPrototypes := findLineWhereToInsertPrototypes(tags) if lineWhereToInsertPrototypes != -1 { - context[constants.CTX_LINE_WHERE_TO_INSERT_PROTOTYPES] = lineWhereToInsertPrototypes + ctx.PrototypesLineWhereToInsert = lineWhereToInsertPrototypes } - prototypes := toPrototypes(tags) - context[constants.CTX_PROTOTYPES] = prototypes - + ctx.Prototypes = toPrototypes(tags) return nil } diff --git a/src/arduino.cc/builder/ctags_target_file_saver.go b/src/arduino.cc/builder/ctags_target_file_saver.go index d7c24918..eb2ca5c6 100644 --- a/src/arduino.cc/builder/ctags_target_file_saver.go +++ b/src/arduino.cc/builder/ctags_target_file_saver.go @@ -57,7 +57,7 @@ func (s *CTagsTargetFileSaver) Run(context map[string]interface{}, ctx *types.Co return i18n.WrapError(err) } - context[constants.CTX_CTAGS_TEMP_FILE_PATH] = ctagsTargetFilePath + ctx.CTagsTargetFile = ctagsTargetFilePath return nil } diff --git a/src/arduino.cc/builder/prototypes_adder.go b/src/arduino.cc/builder/prototypes_adder.go index 17c0db50..8cb34fb7 100644 --- a/src/arduino.cc/builder/prototypes_adder.go +++ b/src/arduino.cc/builder/prototypes_adder.go @@ -32,7 +32,6 @@ package builder import ( "arduino.cc/builder/constants" "arduino.cc/builder/types" - "arduino.cc/builder/utils" "fmt" "strconv" "strings" @@ -49,19 +48,15 @@ func (s *PrototypesAdder) Run(context map[string]interface{}, ctx *types.Context sourceRows := strings.Split(source, "\n") - if !utils.MapHas(context, constants.CTX_LINE_WHERE_TO_INSERT_PROTOTYPES) { - return nil - } - - firstFunctionLine := context[constants.CTX_LINE_WHERE_TO_INSERT_PROTOTYPES].(int) + firstFunctionLine := ctx.PrototypesLineWhereToInsert if isFirstFunctionOutsideOfSource(firstFunctionLine, sourceRows) { return nil } insertionLine := firstFunctionLine + context[constants.CTX_LINE_OFFSET].(int) - 1 firstFunctionChar := len(strings.Join(sourceRows[:insertionLine], "\n")) + 1 - prototypeSection := composePrototypeSection(firstFunctionLine, context[constants.CTX_PROTOTYPES].([]*types.Prototype)) - context[constants.CTX_PROTOTYPE_SECTION] = prototypeSection + prototypeSection := composePrototypeSection(firstFunctionLine, ctx.Prototypes) + ctx.PrototypesSection = prototypeSection source = source[:firstFunctionChar] + prototypeSection + source[firstFunctionChar:] if debugOutput { diff --git a/src/arduino.cc/builder/test/ctags_parser_test.go b/src/arduino.cc/builder/test/ctags_parser_test.go index f17cee19..bec07c9a 100644 --- a/src/arduino.cc/builder/test/ctags_parser_test.go +++ b/src/arduino.cc/builder/test/ctags_parser_test.go @@ -30,7 +30,6 @@ package test import ( - "arduino.cc/builder/constants" "arduino.cc/builder/ctags" "arduino.cc/builder/types" "github.com/stretchr/testify/require" @@ -46,12 +45,12 @@ func TestCTagsParserShouldListPrototypes(t *testing.T) { bytes, err := ioutil.ReadFile(filepath.Join("ctags_output", "TestCTagsParserShouldListPrototypes.txt")) NoError(t, err) - context[constants.CTX_CTAGS_OUTPUT] = string(bytes) + ctx.CTagsOutput = string(bytes) ctagsParser := ctags.CTagsParser{} ctagsParser.Run(context, ctx) - tags := context[constants.CTX_CTAGS_OF_PREPROC_SOURCE].([]*types.CTag) + tags := ctx.CTagsOfPreprocessedSource require.Equal(t, 8, len(tags)) idx := 0 @@ -95,12 +94,12 @@ func TestCTagsParserShouldListTemplates(t *testing.T) { bytes, err := ioutil.ReadFile(filepath.Join("ctags_output", "TestCTagsParserShouldListTemplates.txt")) NoError(t, err) - context[constants.CTX_CTAGS_OUTPUT] = string(bytes) + ctx.CTagsOutput = string(bytes) ctagsParser := ctags.CTagsParser{} ctagsParser.Run(context, ctx) - tags := context[constants.CTX_CTAGS_OF_PREPROC_SOURCE].([]*types.CTag) + tags := ctx.CTagsOfPreprocessedSource require.Equal(t, 3, len(tags)) idx := 0 @@ -124,12 +123,12 @@ func TestCTagsParserShouldListTemplates2(t *testing.T) { bytes, err := ioutil.ReadFile(filepath.Join("ctags_output", "TestCTagsParserShouldListTemplates2.txt")) NoError(t, err) - context[constants.CTX_CTAGS_OUTPUT] = string(bytes) + ctx.CTagsOutput = string(bytes) ctagsParser := ctags.CTagsParser{} ctagsParser.Run(context, ctx) - tags := context[constants.CTX_CTAGS_OF_PREPROC_SOURCE].([]*types.CTag) + tags := ctx.CTagsOfPreprocessedSource require.Equal(t, 4, len(tags)) idx := 0 @@ -155,12 +154,12 @@ func TestCTagsParserShouldDealWithClasses(t *testing.T) { bytes, err := ioutil.ReadFile(filepath.Join("ctags_output", "TestCTagsParserShouldDealWithClasses.txt")) NoError(t, err) - context[constants.CTX_CTAGS_OUTPUT] = string(bytes) + ctx.CTagsOutput = string(bytes) ctagsParser := ctags.CTagsParser{} ctagsParser.Run(context, ctx) - tags := context[constants.CTX_CTAGS_OF_PREPROC_SOURCE].([]*types.CTag) + tags := ctx.CTagsOfPreprocessedSource require.Equal(t, 2, len(tags)) idx := 0 @@ -178,12 +177,12 @@ func TestCTagsParserShouldDealWithStructs(t *testing.T) { bytes, err := ioutil.ReadFile(filepath.Join("ctags_output", "TestCTagsParserShouldDealWithStructs.txt")) NoError(t, err) - context[constants.CTX_CTAGS_OUTPUT] = string(bytes) + ctx.CTagsOutput = string(bytes) ctagsParser := ctags.CTagsParser{} ctagsParser.Run(context, ctx) - tags := context[constants.CTX_CTAGS_OF_PREPROC_SOURCE].([]*types.CTag) + tags := ctx.CTagsOfPreprocessedSource require.Equal(t, 5, len(tags)) idx := 0 @@ -211,12 +210,12 @@ func TestCTagsParserShouldDealWithMacros(t *testing.T) { bytes, err := ioutil.ReadFile(filepath.Join("ctags_output", "TestCTagsParserShouldDealWithMacros.txt")) NoError(t, err) - context[constants.CTX_CTAGS_OUTPUT] = string(bytes) + ctx.CTagsOutput = string(bytes) ctagsParser := ctags.CTagsParser{} ctagsParser.Run(context, ctx) - tags := context[constants.CTX_CTAGS_OF_PREPROC_SOURCE].([]*types.CTag) + tags := ctx.CTagsOfPreprocessedSource require.Equal(t, 8, len(tags)) idx := 0 @@ -252,12 +251,12 @@ func TestCTagsParserShouldDealFunctionWithDifferentSignatures(t *testing.T) { bytes, err := ioutil.ReadFile(filepath.Join("ctags_output", "TestCTagsParserShouldDealFunctionWithDifferentSignatures.txt")) NoError(t, err) - context[constants.CTX_CTAGS_OUTPUT] = string(bytes) + ctx.CTagsOutput = string(bytes) ctagsParser := ctags.CTagsParser{} ctagsParser.Run(context, ctx) - tags := context[constants.CTX_CTAGS_OF_PREPROC_SOURCE].([]*types.CTag) + tags := ctx.CTagsOfPreprocessedSource require.Equal(t, 3, len(tags)) idx := 0 @@ -278,12 +277,12 @@ func TestCTagsParserClassMembersAreFilteredOut(t *testing.T) { bytes, err := ioutil.ReadFile(filepath.Join("ctags_output", "TestCTagsParserClassMembersAreFilteredOut.txt")) NoError(t, err) - context[constants.CTX_CTAGS_OUTPUT] = string(bytes) + ctx.CTagsOutput = string(bytes) ctagsParser := ctags.CTagsParser{} ctagsParser.Run(context, ctx) - tags := context[constants.CTX_CTAGS_OF_PREPROC_SOURCE].([]*types.CTag) + tags := ctx.CTagsOfPreprocessedSource require.Equal(t, 5, len(tags)) idx := 0 @@ -313,12 +312,12 @@ func TestCTagsParserStructWithFunctions(t *testing.T) { bytes, err := ioutil.ReadFile(filepath.Join("ctags_output", "TestCTagsParserStructWithFunctions.txt")) NoError(t, err) - context[constants.CTX_CTAGS_OUTPUT] = string(bytes) + ctx.CTagsOutput = string(bytes) ctagsParser := ctags.CTagsParser{} ctagsParser.Run(context, ctx) - tags := context[constants.CTX_CTAGS_OF_PREPROC_SOURCE].([]*types.CTag) + tags := ctx.CTagsOfPreprocessedSource require.Equal(t, 8, len(tags)) idx := 0 @@ -356,12 +355,12 @@ func TestCTagsParserDefaultArguments(t *testing.T) { bytes, err := ioutil.ReadFile(filepath.Join("ctags_output", "TestCTagsParserDefaultArguments.txt")) NoError(t, err) - context[constants.CTX_CTAGS_OUTPUT] = string(bytes) + ctx.CTagsOutput = string(bytes) ctagsParser := ctags.CTagsParser{} ctagsParser.Run(context, ctx) - tags := context[constants.CTX_CTAGS_OF_PREPROC_SOURCE].([]*types.CTag) + tags := ctx.CTagsOfPreprocessedSource require.Equal(t, 3, len(tags)) idx := 0 @@ -383,12 +382,12 @@ func TestCTagsParserNamespace(t *testing.T) { bytes, err := ioutil.ReadFile(filepath.Join("ctags_output", "TestCTagsParserNamespace.txt")) NoError(t, err) - context[constants.CTX_CTAGS_OUTPUT] = string(bytes) + ctx.CTagsOutput = string(bytes) ctagsParser := ctags.CTagsParser{} ctagsParser.Run(context, ctx) - tags := context[constants.CTX_CTAGS_OF_PREPROC_SOURCE].([]*types.CTag) + tags := ctx.CTagsOfPreprocessedSource require.Equal(t, 3, len(tags)) idx := 0 @@ -410,12 +409,12 @@ func TestCTagsParserStatic(t *testing.T) { bytes, err := ioutil.ReadFile(filepath.Join("ctags_output", "TestCTagsParserStatic.txt")) NoError(t, err) - context[constants.CTX_CTAGS_OUTPUT] = string(bytes) + ctx.CTagsOutput = string(bytes) ctagsParser := ctags.CTagsParser{} ctagsParser.Run(context, ctx) - tags := context[constants.CTX_CTAGS_OF_PREPROC_SOURCE].([]*types.CTag) + tags := ctx.CTagsOfPreprocessedSource require.Equal(t, 3, len(tags)) idx := 0 @@ -436,12 +435,12 @@ func TestCTagsParserFunctionPointer(t *testing.T) { bytes, err := ioutil.ReadFile(filepath.Join("ctags_output", "TestCTagsParserFunctionPointer.txt")) NoError(t, err) - context[constants.CTX_CTAGS_OUTPUT] = string(bytes) + ctx.CTagsOutput = string(bytes) ctagsParser := ctags.CTagsParser{} ctagsParser.Run(context, ctx) - tags := context[constants.CTX_CTAGS_OF_PREPROC_SOURCE].([]*types.CTag) + tags := ctx.CTagsOfPreprocessedSource require.Equal(t, 4, len(tags)) idx := 0 @@ -465,12 +464,12 @@ func TestCTagsParserFunctionPointers(t *testing.T) { bytes, err := ioutil.ReadFile(filepath.Join("ctags_output", "TestCTagsParserFunctionPointers.txt")) NoError(t, err) - context[constants.CTX_CTAGS_OUTPUT] = string(bytes) + ctx.CTagsOutput = string(bytes) ctagsParser := ctags.CTagsParser{} ctagsParser.Run(context, ctx) - tags := context[constants.CTX_CTAGS_OF_PREPROC_SOURCE].([]*types.CTag) + tags := ctx.CTagsOfPreprocessedSource require.Equal(t, 5, len(tags)) idx := 0 diff --git a/src/arduino.cc/builder/test/ctags_runner_test.go b/src/arduino.cc/builder/test/ctags_runner_test.go index 9d096c65..0bdf205a 100644 --- a/src/arduino.cc/builder/test/ctags_runner_test.go +++ b/src/arduino.cc/builder/test/ctags_runner_test.go @@ -89,7 +89,7 @@ func TestCTagsRunner(t *testing.T) { "analogCommand " + sketchLocation + " /^void analogCommand(BridgeClient client) {$/;\" kind:function line:109 signature:(BridgeClient client) returntype:void\n" + "modeCommand " + sketchLocation + " /^void modeCommand(BridgeClient client) {$/;\" kind:function line:149 signature:(BridgeClient client) returntype:void\n" - require.Equal(t, expectedOutput, strings.Replace(context[constants.CTX_CTAGS_OUTPUT].(string), "\r\n", "\n", -1)) + require.Equal(t, expectedOutput, strings.Replace(ctx.CTagsOutput, "\r\n", "\n", -1)) } func TestCTagsRunnerSketchWithClass(t *testing.T) { @@ -138,7 +138,7 @@ func TestCTagsRunnerSketchWithClass(t *testing.T) { "setup\t" + sketchLocation + "\t/^void setup() {$/;\"\tkind:function\tline:13\tsignature:()\treturntype:void\n" + "loop\t" + sketchLocation + "\t/^void loop() {$/;\"\tkind:function\tline:17\tsignature:()\treturntype:void\n" - require.Equal(t, expectedOutput, strings.Replace(context[constants.CTX_CTAGS_OUTPUT].(string), "\r\n", "\n", -1)) + require.Equal(t, expectedOutput, strings.Replace(ctx.CTagsOutput, "\r\n", "\n", -1)) } func TestCTagsRunnerSketchWithTypename(t *testing.T) { @@ -186,7 +186,7 @@ func TestCTagsRunnerSketchWithTypename(t *testing.T) { "loop\t" + sketchLocation + "\t/^void loop() {}$/;\"\tkind:function\tline:10\tsignature:()\treturntype:void\n" + "func\t" + sketchLocation + "\t/^typename Foo::Bar func(){$/;\"\tkind:function\tline:12\tsignature:()\treturntype:Foo::Bar\n" - require.Equal(t, expectedOutput, strings.Replace(context[constants.CTX_CTAGS_OUTPUT].(string), "\r\n", "\n", -1)) + require.Equal(t, expectedOutput, strings.Replace(ctx.CTagsOutput, "\r\n", "\n", -1)) } func TestCTagsRunnerSketchWithNamespace(t *testing.T) { @@ -233,7 +233,7 @@ func TestCTagsRunnerSketchWithNamespace(t *testing.T) { "setup\t" + sketchLocation + "\t/^void setup() {}$/;\"\tkind:function\tline:7\tsignature:()\treturntype:void\n" + "loop\t" + sketchLocation + "\t/^void loop() {}$/;\"\tkind:function\tline:8\tsignature:()\treturntype:void\n" - require.Equal(t, expectedOutput, strings.Replace(context[constants.CTX_CTAGS_OUTPUT].(string), "\r\n", "\n", -1)) + require.Equal(t, expectedOutput, strings.Replace(ctx.CTagsOutput, "\r\n", "\n", -1)) } func TestCTagsRunnerSketchWithTemplates(t *testing.T) { @@ -281,5 +281,5 @@ func TestCTagsRunnerSketchWithTemplates(t *testing.T) { "aVar\t" + sketchLocation + "\t/^c< 1<<8 > aVar;$/;\"\tkind:variable\tline:16\n" + "func\t" + sketchLocation + "\t/^template func( c< 1< & aParam) {$/;\"\tkind:function\tline:18\tsignature:( c< 1< & aParam)\treturntype:template\n" - require.Equal(t, expectedOutput, strings.Replace(context[constants.CTX_CTAGS_OUTPUT].(string), "\r\n", "\n", -1)) + require.Equal(t, expectedOutput, strings.Replace(ctx.CTagsOutput, "\r\n", "\n", -1)) } diff --git a/src/arduino.cc/builder/test/ctags_to_prototypes_test.go b/src/arduino.cc/builder/test/ctags_to_prototypes_test.go index 7e30cd00..bf50e261 100644 --- a/src/arduino.cc/builder/test/ctags_to_prototypes_test.go +++ b/src/arduino.cc/builder/test/ctags_to_prototypes_test.go @@ -30,7 +30,6 @@ package test import ( - "arduino.cc/builder/constants" "arduino.cc/builder/ctags" "arduino.cc/builder/types" "github.com/stretchr/testify/require" @@ -39,6 +38,13 @@ import ( "testing" ) +type CollectCtagsFromPreprocSource struct{} + +func (*CollectCtagsFromPreprocSource) Run(context map[string]interface{}, ctx *types.Context) error { + ctx.CTagsCollected = ctx.CTagsOfPreprocessedSource + return nil +} + func TestCTagsToPrototypesShouldListPrototypes(t *testing.T) { context := make(map[string]interface{}) ctx := &types.Context{} @@ -46,11 +52,11 @@ func TestCTagsToPrototypesShouldListPrototypes(t *testing.T) { bytes, err := ioutil.ReadFile(filepath.Join("ctags_output", "TestCTagsParserShouldListPrototypes.txt")) NoError(t, err) - context[constants.CTX_CTAGS_OUTPUT] = string(bytes) + ctx.CTagsOutput = string(bytes) commands := []types.Command{ &ctags.CTagsParser{}, - &CopyContextKeys{From: constants.CTX_CTAGS_OF_PREPROC_SOURCE, To: constants.CTX_COLLECTED_CTAGS}, + &CollectCtagsFromPreprocSource{}, &ctags.CTagsToPrototypes{}, } @@ -59,7 +65,7 @@ func TestCTagsToPrototypesShouldListPrototypes(t *testing.T) { NoError(t, err) } - prototypes := context[constants.CTX_PROTOTYPES].([]*types.Prototype) + prototypes := ctx.Prototypes require.Equal(t, 5, len(prototypes)) require.Equal(t, "void setup();", prototypes[0].Prototype) @@ -69,8 +75,7 @@ func TestCTagsToPrototypesShouldListPrototypes(t *testing.T) { require.Equal(t, "void analogCommand(YunClient client);", prototypes[3].Prototype) require.Equal(t, "void modeCommand(YunClient client);", prototypes[4].Prototype) - prototypeLine := context[constants.CTX_LINE_WHERE_TO_INSERT_PROTOTYPES].(int) - require.Equal(t, 33, prototypeLine) + require.Equal(t, 33, ctx.PrototypesLineWhereToInsert) } func TestCTagsToPrototypesShouldListTemplates(t *testing.T) { @@ -80,11 +85,11 @@ func TestCTagsToPrototypesShouldListTemplates(t *testing.T) { bytes, err := ioutil.ReadFile(filepath.Join("ctags_output", "TestCTagsParserShouldListTemplates.txt")) NoError(t, err) - context[constants.CTX_CTAGS_OUTPUT] = string(bytes) + ctx.CTagsOutput = string(bytes) commands := []types.Command{ &ctags.CTagsParser{}, - &CopyContextKeys{From: constants.CTX_CTAGS_OF_PREPROC_SOURCE, To: constants.CTX_COLLECTED_CTAGS}, + &CollectCtagsFromPreprocSource{}, &ctags.CTagsToPrototypes{}, } @@ -93,7 +98,7 @@ func TestCTagsToPrototypesShouldListTemplates(t *testing.T) { NoError(t, err) } - prototypes := context[constants.CTX_PROTOTYPES].([]*types.Prototype) + prototypes := ctx.Prototypes require.Equal(t, 3, len(prototypes)) require.Equal(t, "template T minimum (T a, T b);", prototypes[0].Prototype) @@ -101,8 +106,7 @@ func TestCTagsToPrototypesShouldListTemplates(t *testing.T) { require.Equal(t, "void setup();", prototypes[1].Prototype) require.Equal(t, "void loop();", prototypes[2].Prototype) - prototypeLine := context[constants.CTX_LINE_WHERE_TO_INSERT_PROTOTYPES].(int) - require.Equal(t, 2, prototypeLine) + require.Equal(t, 2, ctx.PrototypesLineWhereToInsert) } func TestCTagsToPrototypesShouldListTemplates2(t *testing.T) { @@ -112,11 +116,11 @@ func TestCTagsToPrototypesShouldListTemplates2(t *testing.T) { bytes, err := ioutil.ReadFile(filepath.Join("ctags_output", "TestCTagsParserShouldListTemplates2.txt")) NoError(t, err) - context[constants.CTX_CTAGS_OUTPUT] = string(bytes) + ctx.CTagsOutput = string(bytes) commands := []types.Command{ &ctags.CTagsParser{}, - &CopyContextKeys{From: constants.CTX_CTAGS_OF_PREPROC_SOURCE, To: constants.CTX_COLLECTED_CTAGS}, + &CollectCtagsFromPreprocSource{}, &ctags.CTagsToPrototypes{}, } @@ -125,7 +129,7 @@ func TestCTagsToPrototypesShouldListTemplates2(t *testing.T) { NoError(t, err) } - prototypes := context[constants.CTX_PROTOTYPES].([]*types.Prototype) + prototypes := ctx.Prototypes require.Equal(t, 4, len(prototypes)) require.Equal(t, "void setup();", prototypes[0].Prototype) @@ -134,8 +138,7 @@ func TestCTagsToPrototypesShouldListTemplates2(t *testing.T) { require.Equal(t, "template int SRAM_writeAnything(int ee, const T& value);", prototypes[2].Prototype) require.Equal(t, "template int SRAM_readAnything(int ee, T& value);", prototypes[3].Prototype) - prototypeLine := context[constants.CTX_LINE_WHERE_TO_INSERT_PROTOTYPES].(int) - require.Equal(t, 1, prototypeLine) + require.Equal(t, 1, ctx.PrototypesLineWhereToInsert) } func TestCTagsToPrototypesShouldDealWithClasses(t *testing.T) { @@ -145,11 +148,11 @@ func TestCTagsToPrototypesShouldDealWithClasses(t *testing.T) { bytes, err := ioutil.ReadFile(filepath.Join("ctags_output", "TestCTagsParserShouldDealWithClasses.txt")) NoError(t, err) - context[constants.CTX_CTAGS_OUTPUT] = string(bytes) + ctx.CTagsOutput = string(bytes) commands := []types.Command{ &ctags.CTagsParser{}, - &CopyContextKeys{From: constants.CTX_CTAGS_OF_PREPROC_SOURCE, To: constants.CTX_COLLECTED_CTAGS}, + &CollectCtagsFromPreprocSource{}, &ctags.CTagsToPrototypes{}, } @@ -158,12 +161,11 @@ func TestCTagsToPrototypesShouldDealWithClasses(t *testing.T) { NoError(t, err) } - prototypes := context[constants.CTX_PROTOTYPES].([]*types.Prototype) + prototypes := ctx.Prototypes require.Equal(t, 0, len(prototypes)) - prototypeLine := context[constants.CTX_LINE_WHERE_TO_INSERT_PROTOTYPES].(int) - require.Equal(t, 8, prototypeLine) + require.Equal(t, 8, ctx.PrototypesLineWhereToInsert) } func TestCTagsToPrototypesShouldDealWithStructs(t *testing.T) { @@ -173,11 +175,11 @@ func TestCTagsToPrototypesShouldDealWithStructs(t *testing.T) { bytes, err := ioutil.ReadFile(filepath.Join("ctags_output", "TestCTagsParserShouldDealWithStructs.txt")) NoError(t, err) - context[constants.CTX_CTAGS_OUTPUT] = string(bytes) + ctx.CTagsOutput = string(bytes) commands := []types.Command{ &ctags.CTagsParser{}, - &CopyContextKeys{From: constants.CTX_CTAGS_OF_PREPROC_SOURCE, To: constants.CTX_COLLECTED_CTAGS}, + &CollectCtagsFromPreprocSource{}, &ctags.CTagsToPrototypes{}, } @@ -186,7 +188,7 @@ func TestCTagsToPrototypesShouldDealWithStructs(t *testing.T) { NoError(t, err) } - prototypes := context[constants.CTX_PROTOTYPES].([]*types.Prototype) + prototypes := ctx.Prototypes require.Equal(t, 3, len(prototypes)) require.Equal(t, "void setup();", prototypes[0].Prototype) @@ -194,8 +196,7 @@ func TestCTagsToPrototypesShouldDealWithStructs(t *testing.T) { require.Equal(t, "void loop();", prototypes[1].Prototype) require.Equal(t, "void dostuff(A_NEW_TYPE * bar);", prototypes[2].Prototype) - prototypeLine := context[constants.CTX_LINE_WHERE_TO_INSERT_PROTOTYPES].(int) - require.Equal(t, 9, prototypeLine) + require.Equal(t, 9, ctx.PrototypesLineWhereToInsert) } func TestCTagsToPrototypesShouldDealWithMacros(t *testing.T) { @@ -205,11 +206,11 @@ func TestCTagsToPrototypesShouldDealWithMacros(t *testing.T) { bytes, err := ioutil.ReadFile(filepath.Join("ctags_output", "TestCTagsParserShouldDealWithMacros.txt")) NoError(t, err) - context[constants.CTX_CTAGS_OUTPUT] = string(bytes) + ctx.CTagsOutput = string(bytes) commands := []types.Command{ &ctags.CTagsParser{}, - &CopyContextKeys{From: constants.CTX_CTAGS_OF_PREPROC_SOURCE, To: constants.CTX_COLLECTED_CTAGS}, + &CollectCtagsFromPreprocSource{}, &ctags.CTagsToPrototypes{}, } @@ -218,7 +219,7 @@ func TestCTagsToPrototypesShouldDealWithMacros(t *testing.T) { NoError(t, err) } - prototypes := context[constants.CTX_PROTOTYPES].([]*types.Prototype) + prototypes := ctx.Prototypes require.Equal(t, 5, len(prototypes)) require.Equal(t, "void setup();", prototypes[0].Prototype) @@ -228,8 +229,7 @@ func TestCTagsToPrototypesShouldDealWithMacros(t *testing.T) { require.Equal(t, "void disabledIsDefined();", prototypes[3].Prototype) require.Equal(t, "int useMyType(MyType type);", prototypes[4].Prototype) - prototypeLine := context[constants.CTX_LINE_WHERE_TO_INSERT_PROTOTYPES].(int) - require.Equal(t, 18, prototypeLine) + require.Equal(t, 18, ctx.PrototypesLineWhereToInsert) } func TestCTagsToPrototypesShouldDealFunctionWithDifferentSignatures(t *testing.T) { @@ -239,11 +239,11 @@ func TestCTagsToPrototypesShouldDealFunctionWithDifferentSignatures(t *testing.T bytes, err := ioutil.ReadFile(filepath.Join("ctags_output", "TestCTagsParserShouldDealFunctionWithDifferentSignatures.txt")) NoError(t, err) - context[constants.CTX_CTAGS_OUTPUT] = string(bytes) + ctx.CTagsOutput = string(bytes) commands := []types.Command{ &ctags.CTagsParser{}, - &CopyContextKeys{From: constants.CTX_CTAGS_OF_PREPROC_SOURCE, To: constants.CTX_COLLECTED_CTAGS}, + &CollectCtagsFromPreprocSource{}, &ctags.CTagsToPrototypes{}, } @@ -252,14 +252,13 @@ func TestCTagsToPrototypesShouldDealFunctionWithDifferentSignatures(t *testing.T NoError(t, err) } - prototypes := context[constants.CTX_PROTOTYPES].([]*types.Prototype) + prototypes := ctx.Prototypes require.Equal(t, 1, len(prototypes)) require.Equal(t, "boolean getBytes( byte addr, int amount );", prototypes[0].Prototype) require.Equal(t, "/tmp/test260613593/preproc/ctags_target.cpp", prototypes[0].File) - prototypeLine := context[constants.CTX_LINE_WHERE_TO_INSERT_PROTOTYPES].(int) - require.Equal(t, 5031, prototypeLine) + require.Equal(t, 5031, ctx.PrototypesLineWhereToInsert) } func TestCTagsToPrototypesClassMembersAreFilteredOut(t *testing.T) { @@ -269,11 +268,11 @@ func TestCTagsToPrototypesClassMembersAreFilteredOut(t *testing.T) { bytes, err := ioutil.ReadFile(filepath.Join("ctags_output", "TestCTagsParserClassMembersAreFilteredOut.txt")) NoError(t, err) - context[constants.CTX_CTAGS_OUTPUT] = string(bytes) + ctx.CTagsOutput = string(bytes) commands := []types.Command{ &ctags.CTagsParser{}, - &CopyContextKeys{From: constants.CTX_CTAGS_OF_PREPROC_SOURCE, To: constants.CTX_COLLECTED_CTAGS}, + &CollectCtagsFromPreprocSource{}, &ctags.CTagsToPrototypes{}, } @@ -282,15 +281,14 @@ func TestCTagsToPrototypesClassMembersAreFilteredOut(t *testing.T) { NoError(t, err) } - prototypes := context[constants.CTX_PROTOTYPES].([]*types.Prototype) + prototypes := ctx.Prototypes require.Equal(t, 2, len(prototypes)) require.Equal(t, "void setup();", prototypes[0].Prototype) require.Equal(t, "/tmp/test834438754/preproc/ctags_target.cpp", prototypes[0].File) require.Equal(t, "void loop();", prototypes[1].Prototype) - prototypeLine := context[constants.CTX_LINE_WHERE_TO_INSERT_PROTOTYPES].(int) - require.Equal(t, 14, prototypeLine) + require.Equal(t, 14, ctx.PrototypesLineWhereToInsert) } func TestCTagsToPrototypesStructWithFunctions(t *testing.T) { @@ -300,11 +298,11 @@ func TestCTagsToPrototypesStructWithFunctions(t *testing.T) { bytes, err := ioutil.ReadFile(filepath.Join("ctags_output", "TestCTagsParserStructWithFunctions.txt")) NoError(t, err) - context[constants.CTX_CTAGS_OUTPUT] = string(bytes) + ctx.CTagsOutput = string(bytes) commands := []types.Command{ &ctags.CTagsParser{}, - &CopyContextKeys{From: constants.CTX_CTAGS_OF_PREPROC_SOURCE, To: constants.CTX_COLLECTED_CTAGS}, + &CollectCtagsFromPreprocSource{}, &ctags.CTagsToPrototypes{}, } @@ -313,15 +311,14 @@ func TestCTagsToPrototypesStructWithFunctions(t *testing.T) { NoError(t, err) } - prototypes := context[constants.CTX_PROTOTYPES].([]*types.Prototype) + prototypes := ctx.Prototypes require.Equal(t, 2, len(prototypes)) require.Equal(t, "void setup();", prototypes[0].Prototype) require.Equal(t, "/tmp/build7315640391316178285.tmp/preproc/ctags_target.cpp", prototypes[0].File) require.Equal(t, "void loop();", prototypes[1].Prototype) - prototypeLine := context[constants.CTX_LINE_WHERE_TO_INSERT_PROTOTYPES].(int) - require.Equal(t, 16, prototypeLine) + require.Equal(t, 16, ctx.PrototypesLineWhereToInsert) } func TestCTagsToPrototypesDefaultArguments(t *testing.T) { @@ -331,11 +328,11 @@ func TestCTagsToPrototypesDefaultArguments(t *testing.T) { bytes, err := ioutil.ReadFile(filepath.Join("ctags_output", "TestCTagsParserDefaultArguments.txt")) NoError(t, err) - context[constants.CTX_CTAGS_OUTPUT] = string(bytes) + ctx.CTagsOutput = string(bytes) commands := []types.Command{ &ctags.CTagsParser{}, - &CopyContextKeys{From: constants.CTX_CTAGS_OF_PREPROC_SOURCE, To: constants.CTX_COLLECTED_CTAGS}, + &CollectCtagsFromPreprocSource{}, &ctags.CTagsToPrototypes{}, } @@ -344,7 +341,7 @@ func TestCTagsToPrototypesDefaultArguments(t *testing.T) { NoError(t, err) } - prototypes := context[constants.CTX_PROTOTYPES].([]*types.Prototype) + prototypes := ctx.Prototypes require.Equal(t, 3, len(prototypes)) require.Equal(t, "void test(int x = 1);", prototypes[0].Prototype) @@ -352,8 +349,7 @@ func TestCTagsToPrototypesDefaultArguments(t *testing.T) { require.Equal(t, "/tmp/test179252494/preproc/ctags_target.cpp", prototypes[1].File) require.Equal(t, "void loop();", prototypes[2].Prototype) - prototypeLine := context[constants.CTX_LINE_WHERE_TO_INSERT_PROTOTYPES].(int) - require.Equal(t, 2, prototypeLine) + require.Equal(t, 2, ctx.PrototypesLineWhereToInsert) } func TestCTagsToPrototypesNamespace(t *testing.T) { @@ -363,11 +359,11 @@ func TestCTagsToPrototypesNamespace(t *testing.T) { bytes, err := ioutil.ReadFile(filepath.Join("ctags_output", "TestCTagsParserNamespace.txt")) NoError(t, err) - context[constants.CTX_CTAGS_OUTPUT] = string(bytes) + ctx.CTagsOutput = string(bytes) commands := []types.Command{ &ctags.CTagsParser{}, - &CopyContextKeys{From: constants.CTX_CTAGS_OF_PREPROC_SOURCE, To: constants.CTX_COLLECTED_CTAGS}, + &CollectCtagsFromPreprocSource{}, &ctags.CTagsToPrototypes{}, } @@ -376,15 +372,14 @@ func TestCTagsToPrototypesNamespace(t *testing.T) { NoError(t, err) } - prototypes := context[constants.CTX_PROTOTYPES].([]*types.Prototype) + prototypes := ctx.Prototypes require.Equal(t, 2, len(prototypes)) require.Equal(t, "void setup();", prototypes[0].Prototype) require.Equal(t, "/tmp/test030883150/preproc/ctags_target.cpp", prototypes[0].File) require.Equal(t, "void loop();", prototypes[1].Prototype) - prototypeLine := context[constants.CTX_LINE_WHERE_TO_INSERT_PROTOTYPES].(int) - require.Equal(t, 8, prototypeLine) + require.Equal(t, 8, ctx.PrototypesLineWhereToInsert) } func TestCTagsToPrototypesStatic(t *testing.T) { @@ -394,11 +389,11 @@ func TestCTagsToPrototypesStatic(t *testing.T) { bytes, err := ioutil.ReadFile(filepath.Join("ctags_output", "TestCTagsParserStatic.txt")) NoError(t, err) - context[constants.CTX_CTAGS_OUTPUT] = string(bytes) + ctx.CTagsOutput = string(bytes) commands := []types.Command{ &ctags.CTagsParser{}, - &CopyContextKeys{From: constants.CTX_CTAGS_OF_PREPROC_SOURCE, To: constants.CTX_COLLECTED_CTAGS}, + &CollectCtagsFromPreprocSource{}, &ctags.CTagsToPrototypes{}, } @@ -407,7 +402,7 @@ func TestCTagsToPrototypesStatic(t *testing.T) { NoError(t, err) } - prototypes := context[constants.CTX_PROTOTYPES].([]*types.Prototype) + prototypes := ctx.Prototypes require.Equal(t, 3, len(prototypes)) require.Equal(t, "void setup();", prototypes[0].Prototype) @@ -416,8 +411,7 @@ func TestCTagsToPrototypesStatic(t *testing.T) { require.Equal(t, "void doStuff();", prototypes[2].Prototype) require.Equal(t, "static", prototypes[2].Modifiers) - prototypeLine := context[constants.CTX_LINE_WHERE_TO_INSERT_PROTOTYPES].(int) - require.Equal(t, 2, prototypeLine) + require.Equal(t, 2, ctx.PrototypesLineWhereToInsert) } func TestCTagsToPrototypesFunctionPointer(t *testing.T) { @@ -427,11 +421,11 @@ func TestCTagsToPrototypesFunctionPointer(t *testing.T) { bytes, err := ioutil.ReadFile(filepath.Join("ctags_output", "TestCTagsParserFunctionPointer.txt")) NoError(t, err) - context[constants.CTX_CTAGS_OUTPUT] = string(bytes) + ctx.CTagsOutput = string(bytes) commands := []types.Command{ &ctags.CTagsParser{}, - &CopyContextKeys{From: constants.CTX_CTAGS_OF_PREPROC_SOURCE, To: constants.CTX_COLLECTED_CTAGS}, + &CollectCtagsFromPreprocSource{}, &ctags.CTagsToPrototypes{}, } @@ -440,7 +434,7 @@ func TestCTagsToPrototypesFunctionPointer(t *testing.T) { NoError(t, err) } - prototypes := context[constants.CTX_PROTOTYPES].([]*types.Prototype) + prototypes := ctx.Prototypes require.Equal(t, 3, len(prototypes)) require.Equal(t, "void t1Callback();", prototypes[0].Prototype) @@ -448,8 +442,7 @@ func TestCTagsToPrototypesFunctionPointer(t *testing.T) { require.Equal(t, "void setup();", prototypes[1].Prototype) require.Equal(t, "void loop();", prototypes[2].Prototype) - prototypeLine := context[constants.CTX_LINE_WHERE_TO_INSERT_PROTOTYPES].(int) - require.Equal(t, 2, prototypeLine) + require.Equal(t, 2, ctx.PrototypesLineWhereToInsert) } func TestCTagsToPrototypesFunctionPointers(t *testing.T) { @@ -459,11 +452,11 @@ func TestCTagsToPrototypesFunctionPointers(t *testing.T) { bytes, err := ioutil.ReadFile(filepath.Join("ctags_output", "TestCTagsParserFunctionPointers.txt")) NoError(t, err) - context[constants.CTX_CTAGS_OUTPUT] = string(bytes) + ctx.CTagsOutput = string(bytes) commands := []types.Command{ &ctags.CTagsParser{}, - &CopyContextKeys{From: constants.CTX_CTAGS_OF_PREPROC_SOURCE, To: constants.CTX_COLLECTED_CTAGS}, + &CollectCtagsFromPreprocSource{}, &ctags.CTagsToPrototypes{}, } @@ -472,13 +465,11 @@ func TestCTagsToPrototypesFunctionPointers(t *testing.T) { NoError(t, err) } - prototypes := context[constants.CTX_PROTOTYPES].([]*types.Prototype) - + prototypes := ctx.Prototypes require.Equal(t, 2, len(prototypes)) require.Equal(t, "void setup();", prototypes[0].Prototype) require.Equal(t, "/tmp/test907446433/preproc/ctags_target.cpp", prototypes[0].File) require.Equal(t, "void loop();", prototypes[1].Prototype) - prototypeLine := context[constants.CTX_LINE_WHERE_TO_INSERT_PROTOTYPES].(int) - require.Equal(t, 2, prototypeLine) + require.Equal(t, 2, ctx.PrototypesLineWhereToInsert) } diff --git a/src/arduino.cc/builder/test/helper.go b/src/arduino.cc/builder/test/helper.go index 62a3455b..50560b27 100644 --- a/src/arduino.cc/builder/test/helper.go +++ b/src/arduino.cc/builder/test/helper.go @@ -95,13 +95,3 @@ func (s ByLibraryName) Swap(i, j int) { func (s ByLibraryName) Less(i, j int) bool { return s[i].Name < s[j].Name } - -type CopyContextKeys struct { - From string - To string -} - -func (s *CopyContextKeys) Run(context map[string]interface{}, ctx *types.Context) error { - context[s.To] = context[s.From] - return nil -} diff --git a/src/arduino.cc/builder/test/prototypes_adder_test.go b/src/arduino.cc/builder/test/prototypes_adder_test.go index c7b27352..3bd07901 100644 --- a/src/arduino.cc/builder/test/prototypes_adder_test.go +++ b/src/arduino.cc/builder/test/prototypes_adder_test.go @@ -84,7 +84,7 @@ func TestPrototypesAdderBridgeExample(t *testing.T) { } require.Equal(t, "#include \n#line 1 \""+absoluteSketchLocation+"\"\n", context[constants.CTX_INCLUDE_SECTION].(string)) - require.Equal(t, "#line 33 \""+absoluteSketchLocation+"\"\nvoid setup();\n#line 46 \""+absoluteSketchLocation+"\"\nvoid loop();\n#line 62 \""+absoluteSketchLocation+"\"\nvoid process(BridgeClient client);\n#line 82 \""+absoluteSketchLocation+"\"\nvoid digitalCommand(BridgeClient client);\n#line 109 \""+absoluteSketchLocation+"\"\nvoid analogCommand(BridgeClient client);\n#line 149 \""+absoluteSketchLocation+"\"\nvoid modeCommand(BridgeClient client);\n#line 33 \""+absoluteSketchLocation+"\"\n", context[constants.CTX_PROTOTYPE_SECTION].(string)) + require.Equal(t, "#line 33 \""+absoluteSketchLocation+"\"\nvoid setup();\n#line 46 \""+absoluteSketchLocation+"\"\nvoid loop();\n#line 62 \""+absoluteSketchLocation+"\"\nvoid process(BridgeClient client);\n#line 82 \""+absoluteSketchLocation+"\"\nvoid digitalCommand(BridgeClient client);\n#line 109 \""+absoluteSketchLocation+"\"\nvoid analogCommand(BridgeClient client);\n#line 149 \""+absoluteSketchLocation+"\"\nvoid modeCommand(BridgeClient client);\n#line 33 \""+absoluteSketchLocation+"\"\n", ctx.PrototypesSection) } func TestPrototypesAdderSketchWithIfDef(t *testing.T) { @@ -420,7 +420,7 @@ func TestPrototypesAdderSketchWithConfig(t *testing.T) { } require.Equal(t, "#include \n#line 1 \""+absoluteSketchLocation+"\"\n", context[constants.CTX_INCLUDE_SECTION].(string)) - require.Equal(t, "#line 13 \""+absoluteSketchLocation+"\"\nvoid setup();\n#line 17 \""+absoluteSketchLocation+"\"\nvoid loop();\n#line 13 \""+absoluteSketchLocation+"\"\n", context[constants.CTX_PROTOTYPE_SECTION].(string)) + require.Equal(t, "#line 13 \""+absoluteSketchLocation+"\"\nvoid setup();\n#line 17 \""+absoluteSketchLocation+"\"\nvoid loop();\n#line 13 \""+absoluteSketchLocation+"\"\n", ctx.PrototypesSection) preprocessed := LoadAndInterpolate(t, filepath.Join("sketch_with_config", "sketch_with_config.preprocessed.txt"), context) require.Equal(t, preprocessed, strings.Replace(context[constants.CTX_SOURCE].(string), "\r\n", "\n", -1)) @@ -467,7 +467,7 @@ func TestPrototypesAdderSketchNoFunctionsTwoFiles(t *testing.T) { } require.Equal(t, "#include \n#line 1 \""+absoluteSketchLocation+"\"\n", context[constants.CTX_INCLUDE_SECTION].(string)) - require.Nil(t, context[constants.CTX_PROTOTYPE_SECTION]) + require.Equal(t, "", ctx.PrototypesSection) } func TestPrototypesAdderSketchNoFunctions(t *testing.T) { @@ -511,7 +511,7 @@ func TestPrototypesAdderSketchNoFunctions(t *testing.T) { } require.Equal(t, "#include \n#line 1 \""+absoluteSketchLocation+"\"\n", context[constants.CTX_INCLUDE_SECTION].(string)) - require.Nil(t, context[constants.CTX_PROTOTYPE_SECTION]) + require.Equal(t, "", ctx.PrototypesSection) } func TestPrototypesAdderSketchWithDefaultArgs(t *testing.T) { @@ -555,7 +555,7 @@ func TestPrototypesAdderSketchWithDefaultArgs(t *testing.T) { } require.Equal(t, "#include \n#line 1 \""+absoluteSketchLocation+"\"\n", context[constants.CTX_INCLUDE_SECTION].(string)) - require.Equal(t, "#line 4 \""+absoluteSketchLocation+"\"\nvoid setup();\n#line 7 \""+absoluteSketchLocation+"\"\nvoid loop();\n#line 1 \""+absoluteSketchLocation+"\"\n", context[constants.CTX_PROTOTYPE_SECTION].(string)) + require.Equal(t, "#line 4 \""+absoluteSketchLocation+"\"\nvoid setup();\n#line 7 \""+absoluteSketchLocation+"\"\nvoid loop();\n#line 1 \""+absoluteSketchLocation+"\"\n", ctx.PrototypesSection) } func TestPrototypesAdderSketchWithInlineFunction(t *testing.T) { @@ -601,7 +601,7 @@ func TestPrototypesAdderSketchWithInlineFunction(t *testing.T) { require.Equal(t, "#include \n#line 1 \""+absoluteSketchLocation+"\"\n", context[constants.CTX_INCLUDE_SECTION].(string)) expected := "#line 1 \"" + absoluteSketchLocation + "\"\nvoid setup();\n#line 2 \"" + absoluteSketchLocation + "\"\nvoid loop();\n#line 4 \"" + absoluteSketchLocation + "\"\nshort unsigned int testInt();\n#line 8 \"" + absoluteSketchLocation + "\"\nstatic int8_t testInline();\n#line 12 \"" + absoluteSketchLocation + "\"\n__attribute__((always_inline)) uint8_t testAttribute();\n#line 1 \"" + absoluteSketchLocation + "\"\n" - obtained := context[constants.CTX_PROTOTYPE_SECTION].(string) + obtained := ctx.PrototypesSection // ctags based preprocessing removes "inline" but this is still OK // TODO: remove this exception when moving to a more powerful parser expected = strings.Replace(expected, "static inline int8_t testInline();", "static int8_t testInline();", -1) @@ -654,7 +654,7 @@ func TestPrototypesAdderSketchWithFunctionSignatureInsideIFDEF(t *testing.T) { } require.Equal(t, "#include \n#line 1 \""+absoluteSketchLocation+"\"\n", context[constants.CTX_INCLUDE_SECTION].(string)) - require.Equal(t, "#line 1 \""+absoluteSketchLocation+"\"\nvoid setup();\n#line 3 \""+absoluteSketchLocation+"\"\nvoid loop();\n#line 15 \""+absoluteSketchLocation+"\"\nint8_t adalight();\n#line 1 \""+absoluteSketchLocation+"\"\n", context[constants.CTX_PROTOTYPE_SECTION].(string)) + require.Equal(t, "#line 1 \""+absoluteSketchLocation+"\"\nvoid setup();\n#line 3 \""+absoluteSketchLocation+"\"\nvoid loop();\n#line 15 \""+absoluteSketchLocation+"\"\nint8_t adalight();\n#line 1 \""+absoluteSketchLocation+"\"\n", ctx.PrototypesSection) } func TestPrototypesAdderSketchWithUSBCON(t *testing.T) { @@ -698,7 +698,7 @@ func TestPrototypesAdderSketchWithUSBCON(t *testing.T) { } require.Equal(t, "#include \n#line 1 \""+absoluteSketchLocation+"\"\n", context[constants.CTX_INCLUDE_SECTION].(string)) - require.Equal(t, "#line 5 \""+absoluteSketchLocation+"\"\nvoid ciao();\n#line 10 \""+absoluteSketchLocation+"\"\nvoid setup();\n#line 15 \""+absoluteSketchLocation+"\"\nvoid loop();\n#line 5 \""+absoluteSketchLocation+"\"\n", context[constants.CTX_PROTOTYPE_SECTION].(string)) + require.Equal(t, "#line 5 \""+absoluteSketchLocation+"\"\nvoid ciao();\n#line 10 \""+absoluteSketchLocation+"\"\nvoid setup();\n#line 15 \""+absoluteSketchLocation+"\"\nvoid loop();\n#line 5 \""+absoluteSketchLocation+"\"\n", ctx.PrototypesSection) } func TestPrototypesAdderSketchWithTypename(t *testing.T) { @@ -742,7 +742,7 @@ func TestPrototypesAdderSketchWithTypename(t *testing.T) { require.Equal(t, "#include \n#line 1 \""+absoluteSketchLocation+"\"\n", context[constants.CTX_INCLUDE_SECTION].(string)) expected := "#line 6 \"" + absoluteSketchLocation + "\"\nvoid setup();\n#line 10 \"" + absoluteSketchLocation + "\"\nvoid loop();\n#line 12 \"" + absoluteSketchLocation + "\"\ntypename Foo::Bar func();\n#line 6 \"" + absoluteSketchLocation + "\"\n" - obtained := context[constants.CTX_PROTOTYPE_SECTION].(string) + obtained := ctx.PrototypesSection // ctags based preprocessing ignores line with typename // TODO: remove this exception when moving to a more powerful parser expected = strings.Replace(expected, "#line 12 \""+absoluteSketchLocation+"\"\ntypename Foo::Bar func();\n", "", -1) @@ -791,7 +791,7 @@ func TestPrototypesAdderSketchWithIfDef2(t *testing.T) { } require.Equal(t, "#include \n#line 1 \""+absoluteSketchLocation+"\"\n", context[constants.CTX_INCLUDE_SECTION].(string)) - require.Equal(t, "#line 5 \""+absoluteSketchLocation+"\"\nvoid elseBranch();\n#line 9 \""+absoluteSketchLocation+"\"\nvoid f1();\n#line 10 \""+absoluteSketchLocation+"\"\nvoid f2();\n#line 12 \""+absoluteSketchLocation+"\"\nvoid setup();\n#line 14 \""+absoluteSketchLocation+"\"\nvoid loop();\n#line 5 \""+absoluteSketchLocation+"\"\n", context[constants.CTX_PROTOTYPE_SECTION].(string)) + require.Equal(t, "#line 5 \""+absoluteSketchLocation+"\"\nvoid elseBranch();\n#line 9 \""+absoluteSketchLocation+"\"\nvoid f1();\n#line 10 \""+absoluteSketchLocation+"\"\nvoid f2();\n#line 12 \""+absoluteSketchLocation+"\"\nvoid setup();\n#line 14 \""+absoluteSketchLocation+"\"\nvoid loop();\n#line 5 \""+absoluteSketchLocation+"\"\n", ctx.PrototypesSection) expectedSource := LoadAndInterpolate(t, filepath.Join("sketch_with_ifdef", "sketch.preprocessed.txt"), context) require.Equal(t, expectedSource, strings.Replace(context[constants.CTX_SOURCE].(string), "\r\n", "\n", -1)) @@ -838,7 +838,7 @@ func TestPrototypesAdderSketchWithIfDef2SAM(t *testing.T) { } require.Equal(t, "#include \n#line 1 \""+absoluteSketchLocation+"\"\n", context[constants.CTX_INCLUDE_SECTION].(string)) - require.Equal(t, "#line 2 \""+absoluteSketchLocation+"\"\nvoid ifBranch();\n#line 9 \""+absoluteSketchLocation+"\"\nvoid f1();\n#line 10 \""+absoluteSketchLocation+"\"\nvoid f2();\n#line 12 \""+absoluteSketchLocation+"\"\nvoid setup();\n#line 14 \""+absoluteSketchLocation+"\"\nvoid loop();\n#line 2 \""+absoluteSketchLocation+"\"\n", context[constants.CTX_PROTOTYPE_SECTION].(string)) + require.Equal(t, "#line 2 \""+absoluteSketchLocation+"\"\nvoid ifBranch();\n#line 9 \""+absoluteSketchLocation+"\"\nvoid f1();\n#line 10 \""+absoluteSketchLocation+"\"\nvoid f2();\n#line 12 \""+absoluteSketchLocation+"\"\nvoid setup();\n#line 14 \""+absoluteSketchLocation+"\"\nvoid loop();\n#line 2 \""+absoluteSketchLocation+"\"\n", ctx.PrototypesSection) expectedSource := LoadAndInterpolate(t, filepath.Join("sketch_with_ifdef", "sketch.preprocessed.SAM.txt"), context) require.Equal(t, expectedSource, strings.Replace(context[constants.CTX_SOURCE].(string), "\r\n", "\n", -1)) @@ -885,7 +885,7 @@ func TestPrototypesAdderSketchWithConst(t *testing.T) { } require.Equal(t, "#include \n#line 1 \""+absoluteSketchLocation+"\"\n", context[constants.CTX_INCLUDE_SECTION].(string)) - require.Equal(t, "#line 1 \""+absoluteSketchLocation+"\"\nvoid setup();\n#line 2 \""+absoluteSketchLocation+"\"\nvoid loop();\n#line 4 \""+absoluteSketchLocation+"\"\nconst __FlashStringHelper* test();\n#line 6 \""+absoluteSketchLocation+"\"\nconst int test3();\n#line 8 \""+absoluteSketchLocation+"\"\nvolatile __FlashStringHelper* test2();\n#line 10 \""+absoluteSketchLocation+"\"\nvolatile int test4();\n#line 1 \""+absoluteSketchLocation+"\"\n", context[constants.CTX_PROTOTYPE_SECTION].(string)) + require.Equal(t, "#line 1 \""+absoluteSketchLocation+"\"\nvoid setup();\n#line 2 \""+absoluteSketchLocation+"\"\nvoid loop();\n#line 4 \""+absoluteSketchLocation+"\"\nconst __FlashStringHelper* test();\n#line 6 \""+absoluteSketchLocation+"\"\nconst int test3();\n#line 8 \""+absoluteSketchLocation+"\"\nvolatile __FlashStringHelper* test2();\n#line 10 \""+absoluteSketchLocation+"\"\nvolatile int test4();\n#line 1 \""+absoluteSketchLocation+"\"\n", ctx.PrototypesSection) } func TestPrototypesAdderSketchWithDosEol(t *testing.T) { diff --git a/src/arduino.cc/builder/types/context.go b/src/arduino.cc/builder/types/context.go index 43dde582..311c36b2 100644 --- a/src/arduino.cc/builder/types/context.go +++ b/src/arduino.cc/builder/types/context.go @@ -21,6 +21,16 @@ type Context struct { Libraries []*Library HeaderToLibraries map[string][]*Library + // C++ Parsing + CTagsOutput string + CTagsTargetFile string + CTagsOfSource []*CTag + CTagsOfPreprocessedSource []*CTag + CTagsCollected []*CTag + PrototypesSection string + PrototypesLineWhereToInsert int + Prototypes []*Prototype + // Verbosity settings Verbose bool DebugPreprocessor bool From fa317a69dd7931961a329badfa32e140da884648 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Wed, 13 Apr 2016 16:33:29 +0200 Subject: [PATCH 07/25] Added buildOptions refactoring to main.go main.go has been moved into module arduino.cc/arduino-builder Signed-off-by: Cristian Maglie --- .gitignore | 2 +- README.md | 2 +- fmt_fix_vet | 6 +- .../arduino.cc/arduino-builder/main.go | 121 ++++++++---------- 4 files changed, 60 insertions(+), 71 deletions(-) rename main.go => src/arduino.cc/arduino-builder/main.go (80%) diff --git a/.gitignore b/.gitignore index e26379ab..0df12e54 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,7 @@ bin src/github.com src/golang.org -arduino-builder +./arduino-builder # Created by .ignore support plugin (hsz.mobi) ### Go template diff --git a/README.md b/README.md index 453fb958..779f3725 100644 --- a/README.md +++ b/README.md @@ -69,7 +69,7 @@ go get github.com/stretchr/testify go get github.com/jstemmer/go-junit-report go get golang.org/x/codereview/patch go get golang.org/x/tools/cmd/vet -go build +go build arduino.cc/arduino-builder ``` ### TDD diff --git a/fmt_fix_vet b/fmt_fix_vet index ffd5c649..219e0c5b 100755 --- a/fmt_fix_vet +++ b/fmt_fix_vet @@ -1,8 +1,8 @@ #!/bin/bash -x go fmt ./src/arduino.cc/builder/... -go fmt main.go +go fmt ./src/arduino.cc/arduino-builder/... go fix ./src/arduino.cc/builder/... -go fix main.go +go fix ./src/arduino.cc/arduino-builder/... go vet ./src/arduino.cc/builder/... -go vet main.go +go vet ./src/arduino.cc/arduino-builder/... diff --git a/main.go b/src/arduino.cc/arduino-builder/main.go similarity index 80% rename from main.go rename to src/arduino.cc/arduino-builder/main.go index af8246ef..75fb87f6 100644 --- a/main.go +++ b/src/arduino.cc/arduino-builder/main.go @@ -44,6 +44,8 @@ import ( "arduino.cc/builder/constants" "arduino.cc/builder/gohasissues" "arduino.cc/builder/i18n" + "arduino.cc/builder/props" + "arduino.cc/builder/types" "arduino.cc/builder/utils" "github.com/go-errors/errors" ) @@ -170,85 +172,77 @@ func main() { } context := make(map[string]interface{}) + ctx := &types.Context{} - buildOptions := make(map[string]string) if *buildOptionsFileFlag != "" { + buildOptions := make(props.PropertiesMap) if _, err := os.Stat(*buildOptionsFileFlag); err == nil { data, err := ioutil.ReadFile(*buildOptionsFileFlag) if err != nil { printCompleteError(err) - defer os.Exit(1) - return } err = json.Unmarshal(data, &buildOptions) if err != nil { printCompleteError(err) - defer os.Exit(1) - return } } + ctx.InjectBuildOptions(buildOptions) } - var err error - printStackTrace := false - err, printStackTrace = setContextSliceKeyOrLoadItFromOptions(context, hardwareFoldersFlag, buildOptions, constants.CTX_HARDWARE_FOLDERS, FLAG_HARDWARE, true) - if err != nil { - printError(err, printStackTrace) - defer os.Exit(1) - return + // FLAG_HARDWARE + if hardwareFolders, err := toSliceOfUnquoted(hardwareFoldersFlag); err != nil { + printCompleteError(err) + } else if len(hardwareFolders) > 0 { + ctx.HardwareFolders = hardwareFolders } - - err, printStackTrace = setContextSliceKeyOrLoadItFromOptions(context, toolsFoldersFlag, buildOptions, constants.CTX_TOOLS_FOLDERS, FLAG_TOOLS, true) - if err != nil { - printError(err, printStackTrace) - defer os.Exit(1) - return + if len(ctx.HardwareFolders) == 0 { + printErrorMessageAndFlagUsage(errors.New("Parameter '" + FLAG_HARDWARE + "' is mandatory")) } - err, printStackTrace = setContextSliceKeyOrLoadItFromOptions(context, librariesFoldersFlag, buildOptions, constants.CTX_OTHER_LIBRARIES_FOLDERS, FLAG_LIBRARIES, false) - if err != nil { - printError(err, printStackTrace) - defer os.Exit(1) - return + // FLAG_TOOLS + if toolsFolders, err := toSliceOfUnquoted(toolsFoldersFlag); err != nil { + printCompleteError(err) + } else if len(toolsFolders) > 0 { + ctx.ToolsFolders = toolsFolders } - - err, printStackTrace = setContextSliceKeyOrLoadItFromOptions(context, librariesBuiltInFoldersFlag, buildOptions, constants.CTX_BUILT_IN_LIBRARIES_FOLDERS, FLAG_BUILT_IN_LIBRARIES, false) - if err != nil { - printError(err, printStackTrace) - defer os.Exit(1) - return + if len(ctx.ToolsFolders) == 0 { + printErrorMessageAndFlagUsage(errors.New("Parameter '" + FLAG_TOOLS + "' is mandatory")) } - err, printStackTrace = setContextSliceKeyOrLoadItFromOptions(context, customBuildPropertiesFlag, buildOptions, constants.CTX_CUSTOM_BUILD_PROPERTIES, FLAG_PREFS, false) - if err != nil { - printError(err, printStackTrace) - defer os.Exit(1) - return + // FLAG_LIBRARIES + if librariesFolders, err := toSliceOfUnquoted(librariesFoldersFlag); err != nil { + printCompleteError(err) + } else if len(librariesFolders) > 0 { + ctx.OtherLibrariesFolders = librariesFolders } - fqbn, err := gohasissues.Unquote(*fqbnFlag) - if err != nil { + // FLAG_BUILT_IN_LIBRARIES + if librariesBuiltInFolders, err := toSliceOfUnquoted(librariesBuiltInFoldersFlag); err != nil { printCompleteError(err) - defer os.Exit(1) - return + } else if len(librariesBuiltInFolders) > 0 { + ctx.BuiltInLibrariesFolders = librariesBuiltInFolders } - if fqbn == "" { - fqbn = buildOptions[constants.CTX_FQBN] + // FLAG_PREFS + if customBuildProperties, err := toSliceOfUnquoted(customBuildPropertiesFlag); err != nil { + printCompleteError(err) + } else if len(customBuildProperties) > 0 { + ctx.CustomBuildProperties = customBuildProperties } - if fqbn == "" { + // FLAG_FQBN + if fqbn, err := gohasissues.Unquote(*fqbnFlag); err != nil { + printCompleteError(err) + } else if fqbn != "" { + ctx.FQBN = fqbn + } + if ctx.FQBN == "" { printErrorMessageAndFlagUsage(errors.New("Parameter '" + FLAG_FQBN + "' is mandatory")) - defer os.Exit(1) - return } - context[constants.CTX_FQBN] = fqbn buildPath, err := gohasissues.Unquote(*buildPathFlag) if err != nil { printCompleteError(err) - defer os.Exit(1) - return } if buildPath != "" { @@ -262,8 +256,6 @@ func main() { err = utils.EnsureFolderExists(buildPath) if err != nil { printCompleteError(err) - defer os.Exit(1) - return } } context[constants.CTX_BUILD_PATH] = buildPath @@ -277,10 +269,8 @@ func main() { sketchLocation, err := gohasissues.Unquote(sketchLocation) if err != nil { printCompleteError(err) - defer os.Exit(1) - return } - context[constants.CTX_SKETCH_LOCATION] = sketchLocation + ctx.SketchLocation = sketchLocation } if *verboseFlag && *quietFlag { @@ -288,20 +278,17 @@ func main() { *quietFlag = false } - context[constants.CTX_VERBOSE] = *verboseFlag + ctx.Verbose = *verboseFlag - coreAPIVersion := "" - if utils.MapStringStringHas(buildOptions, constants.CTX_BUILD_PROPERTIES_RUNTIME_IDE_VERSION) { - coreAPIVersion = buildOptions[constants.CTX_BUILD_PROPERTIES_RUNTIME_IDE_VERSION] - } else { - // if deprecated 'ideVersionFlag' has been used... + // FLAG_IDE_VERSION + if ctx.ArduinoAPIVersion == "" { + // if deprecated "--ideVersionFlag" has been used... if *coreAPIVersionFlag == "10600" && *ideVersionFlag != "10600" { - coreAPIVersion = *ideVersionFlag + ctx.ArduinoAPIVersion = *ideVersionFlag } else { - coreAPIVersion = *coreAPIVersionFlag + ctx.ArduinoAPIVersion = *coreAPIVersionFlag } } - context[constants.CTX_BUILD_PROPERTIES_RUNTIME_IDE_VERSION] = coreAPIVersion if *warningsLevelFlag != "" { context[constants.CTX_WARNINGS_LEVEL] = *warningsLevelFlag @@ -312,17 +299,17 @@ func main() { } if *quietFlag { - context[constants.CTX_LOGGER] = i18n.NoopLogger{} + ctx.SetLogger(i18n.NoopLogger{}) } else if *loggerFlag == FLAG_LOGGER_MACHINE { - context[constants.CTX_LOGGER] = i18n.MachineLogger{} + ctx.SetLogger(i18n.MachineLogger{}) } else { - context[constants.CTX_LOGGER] = i18n.HumanLogger{} + ctx.SetLogger(i18n.HumanLogger{}) } if *dumpPrefsFlag { - err = builder.RunParseHardwareAndDumpBuildProperties(context) + err = builder.RunParseHardwareAndDumpBuildProperties(context, ctx) } else if *preprocessFlag { - err = builder.RunPreprocess(context) + err = builder.RunPreprocess(context, ctx) } else { if flag.NArg() == 0 { fmt.Fprintln(os.Stderr, "Last parameter must be the sketch to compile") @@ -330,7 +317,7 @@ func main() { defer os.Exit(1) return } - err = builder.RunBuilder(context) + err = builder.RunBuilder(context, ctx) } exitCode := 0 @@ -400,9 +387,11 @@ func printError(err error, printStackTrace bool) { func printCompleteError(err error) { err = i18n.WrapError(err) fmt.Fprintln(os.Stderr, err.(*errors.Error).ErrorStack()) + os.Exit(1) } func printErrorMessageAndFlagUsage(err error) { fmt.Fprintln(os.Stderr, err) flag.Usage() + os.Exit(1) } From a7e0694a8c31832585add4e0bafafa1604665fb8 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Wed, 13 Apr 2016 16:35:30 +0200 Subject: [PATCH 08/25] Slightly simplified usage of os.Exit(..) Signed-off-by: Cristian Maglie --- src/arduino.cc/arduino-builder/main.go | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/arduino.cc/arduino-builder/main.go b/src/arduino.cc/arduino-builder/main.go index 75fb87f6..6fd9efbb 100644 --- a/src/arduino.cc/arduino-builder/main.go +++ b/src/arduino.cc/arduino-builder/main.go @@ -167,7 +167,6 @@ func main() { fmt.Println("See https://www.arduino.cc/ and https://github.com/arduino/arduino-builder/graphs/contributors") fmt.Println("This is free software; see the source for copying conditions. There is NO") fmt.Println("warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.") - defer os.Exit(0) return } @@ -249,8 +248,7 @@ func main() { _, err := os.Stat(buildPath) if err != nil { fmt.Fprintln(os.Stderr, err) - defer os.Exit(1) - return + os.Exit(1) } err = utils.EnsureFolderExists(buildPath) @@ -314,13 +312,11 @@ func main() { if flag.NArg() == 0 { fmt.Fprintln(os.Stderr, "Last parameter must be the sketch to compile") flag.Usage() - defer os.Exit(1) - return + os.Exit(1) } err = builder.RunBuilder(context, ctx) } - exitCode := 0 if err != nil { err = i18n.WrapError(err) @@ -330,10 +326,8 @@ func main() { fmt.Fprintln(os.Stderr, err.(*errors.Error).ErrorStack()) } - exitCode = toExitCode(err) + os.Exit(toExitCode(err)) } - - defer os.Exit(exitCode) } func setContextSliceKeyOrLoadItFromOptions(context map[string]interface{}, cliFlag []string, buildOptions map[string]string, contextKey string, paramName string, mandatory bool) (error, bool) { From ef3d04add4da196a0bf88bcc2ed3609c992112b5 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Thu, 14 Apr 2016 00:24:56 +0200 Subject: [PATCH 09/25] Added some build paths to Context. Signed-off-by: Cristian Maglie --- src/arduino.cc/arduino-builder/main.go | 4 +- .../add_additional_entries_to_context.go | 12 +++--- .../builder/additional_sketch_files_copier.go | 2 +- src/arduino.cc/builder/coan_runner.go | 2 +- src/arduino.cc/builder/constants/constants.go | 5 --- .../builder/container_find_includes.go | 4 +- .../builder/ctags_target_file_saver.go | 3 +- .../builder/ensure_buildpath_exists.go | 5 +-- .../fail_if_buildpath_equals_sketchpath.go | 5 +-- src/arduino.cc/builder/gcc_preproc_runner.go | 10 ++--- .../builder/gcc_preproc_source_saver.go | 5 ++- .../builder/generate_buildpath_if_missing.go | 4 +- .../builder/load_previous_build_options.go | 4 +- .../builder/merge_sketch_with_bootloader.go | 2 +- src/arduino.cc/builder/phases/core_builder.go | 2 +- .../builder/phases/libraries_builder.go | 2 +- src/arduino.cc/builder/phases/linker.go | 2 +- .../builder/phases/sketch_builder.go | 2 +- .../builder/setup_build_properties.go | 4 +- src/arduino.cc/builder/sketch_saver.go | 2 +- .../builder/store_build_options_map.go | 2 +- .../add_additional_entries_to_context_test.go | 19 +++++---- .../additional_sketch_files_copier_test.go | 6 +-- src/arduino.cc/builder/test/builder_test.go | 22 +++++----- .../builder/test/coan_runner_test.go | 2 +- .../test/create_build_options_map_test.go | 5 +-- .../builder/test/ctags_runner_test.go | 10 ++--- ...ail_if_buildpath_equals_sketchpath_test.go | 7 +--- .../generate_buildpath_if_missing_test.go | 14 +++---- src/arduino.cc/builder/test/helper.go | 4 +- .../test/includes_finder_with_gcc_test.go | 10 ++--- .../test/includes_finder_with_regexp_test.go | 2 +- .../test/includes_to_include_folders_test.go | 14 +++---- .../load_previous_build_options_map_test.go | 4 +- .../load_vid_pid_specific_properties_test.go | 4 +- .../test/merge_sketch_with_bootloader_test.go | 8 ++-- .../builder/test/prototypes_adder_test.go | 40 +++++++++---------- .../test/setup_build_properties_test.go | 8 ++-- .../test/store_build_options_map_test.go | 2 +- .../try_build_of_problematic_sketch_test.go | 2 +- .../unused_compiled_libraries_remover_test.go | 6 +-- ...uild_path_if_build_options_changed_test.go | 6 +-- src/arduino.cc/builder/types/context.go | 6 +++ .../unused_compiled_libraries_remover.go | 2 +- ...out_build_path_if_build_options_changed.go | 2 +- 45 files changed, 137 insertions(+), 151 deletions(-) diff --git a/src/arduino.cc/arduino-builder/main.go b/src/arduino.cc/arduino-builder/main.go index 6fd9efbb..d928d4f4 100644 --- a/src/arduino.cc/arduino-builder/main.go +++ b/src/arduino.cc/arduino-builder/main.go @@ -239,11 +239,11 @@ func main() { printErrorMessageAndFlagUsage(errors.New("Parameter '" + FLAG_FQBN + "' is mandatory")) } + // FLAG_BUILD_PATH buildPath, err := gohasissues.Unquote(*buildPathFlag) if err != nil { printCompleteError(err) } - if buildPath != "" { _, err := os.Stat(buildPath) if err != nil { @@ -256,7 +256,7 @@ func main() { printCompleteError(err) } } - context[constants.CTX_BUILD_PATH] = buildPath + ctx.BuildPath = buildPath if *vidPidFlag != "" { context[constants.CTX_VIDPID] = *vidPidFlag diff --git a/src/arduino.cc/builder/add_additional_entries_to_context.go b/src/arduino.cc/builder/add_additional_entries_to_context.go index 70f7515b..4d13eed7 100644 --- a/src/arduino.cc/builder/add_additional_entries_to_context.go +++ b/src/arduino.cc/builder/add_additional_entries_to_context.go @@ -40,8 +40,8 @@ import ( type AddAdditionalEntriesToContext struct{} func (s *AddAdditionalEntriesToContext) Run(context map[string]interface{}, ctx *types.Context) error { - if utils.MapHas(context, constants.CTX_BUILD_PATH) { - buildPath := context[constants.CTX_BUILD_PATH].(string) + if ctx.BuildPath != "" { + buildPath := ctx.BuildPath preprocPath, err := filepath.Abs(filepath.Join(buildPath, constants.FOLDER_PREPROC)) if err != nil { return i18n.WrapError(err) @@ -59,10 +59,10 @@ func (s *AddAdditionalEntriesToContext) Run(context map[string]interface{}, ctx return i18n.WrapError(err) } - context[constants.CTX_PREPROC_PATH] = preprocPath - context[constants.CTX_SKETCH_BUILD_PATH] = sketchBuildPath - context[constants.CTX_LIBRARIES_BUILD_PATH] = librariesBuildPath - context[constants.CTX_CORE_BUILD_PATH] = coreBuildPath + ctx.PreprocPath = preprocPath + ctx.SketchBuildPath = sketchBuildPath + ctx.LibrariesBuildPath = librariesBuildPath + ctx.CoreBuildPath = coreBuildPath } if !utils.MapHas(context, constants.CTX_WARNINGS_LEVEL) { diff --git a/src/arduino.cc/builder/additional_sketch_files_copier.go b/src/arduino.cc/builder/additional_sketch_files_copier.go index 5156e940..3e1090ff 100644 --- a/src/arduino.cc/builder/additional_sketch_files_copier.go +++ b/src/arduino.cc/builder/additional_sketch_files_copier.go @@ -43,7 +43,7 @@ type AdditionalSketchFilesCopier struct{} func (s *AdditionalSketchFilesCopier) Run(context map[string]interface{}, ctx *types.Context) error { sketch := context[constants.CTX_SKETCH].(*types.Sketch) - sketchBuildPath := context[constants.CTX_SKETCH_BUILD_PATH].(string) + sketchBuildPath := ctx.SketchBuildPath err := utils.EnsureFolderExists(sketchBuildPath) if err != nil { diff --git a/src/arduino.cc/builder/coan_runner.go b/src/arduino.cc/builder/coan_runner.go index a5738a06..037f64be 100644 --- a/src/arduino.cc/builder/coan_runner.go +++ b/src/arduino.cc/builder/coan_runner.go @@ -49,7 +49,7 @@ func (s *CoanRunner) Run(context map[string]interface{}, ctx *types.Context) err source += "\n" verbose := ctx.Verbose - preprocPath := context[constants.CTX_PREPROC_PATH].(string) + preprocPath := ctx.PreprocPath err := utils.EnsureFolderExists(preprocPath) if err != nil { return i18n.WrapError(err) diff --git a/src/arduino.cc/builder/constants/constants.go b/src/arduino.cc/builder/constants/constants.go index 6bdc0e26..aed90cc1 100644 --- a/src/arduino.cc/builder/constants/constants.go +++ b/src/arduino.cc/builder/constants/constants.go @@ -80,10 +80,8 @@ const CTX_BUILD_CORE = "buildCore" const CTX_BUILD_OPTIONS = "buildOptions" const CTX_BUILD_OPTIONS_JSON = "buildOptionsJson" const CTX_BUILD_OPTIONS_PREVIOUS_JSON = "buildOptionsPreviousJson" -const CTX_BUILD_PATH = "buildPath" const CTX_BUILD_PROPERTIES = "buildProperties" const CTX_COLLECTED_SOURCE_FILES_QUEUE = "collectedSourceFilesQueue" -const CTX_CORE_BUILD_PATH = "coreBuildPath" const CTX_FILE_PATH_TO_READ = "filePathToRead" const CTX_FOLDERS_WITH_SOURCES_QUEUE = "foldersWithSourcesQueue" const CTX_GCC_MINUS_E_SOURCE = "gccMinusESource" @@ -94,15 +92,12 @@ const CTX_IMPORTED_LIBRARIES = "importedLibraries" const CTX_INCLUDE_FOLDERS = "includeFolders" const CTX_INCLUDE_SECTION = "includeSection" const CTX_INCLUDES_JUST_FOUND = "includesJustFound" -const CTX_LIBRARIES_BUILD_PATH = "librariesBuildPath" const CTX_LIBRARY_RESOLUTION_RESULTS = "libraryResolutionResults" const CTX_LINE_OFFSET = "lineOffset" const CTX_OBJECT_FILES_CORE = "objectFilesCore" const CTX_OBJECT_FILES_LIBRARIES = "objectFilesLibraries" const CTX_OBJECT_FILES_SKETCH = "objectFilesSketch" const CTX_PLATFORM_KEYS_REWRITE = "platformKeysRewrite" -const CTX_PREPROC_PATH = "preprocPath" -const CTX_SKETCH_BUILD_PATH = "sketchBuildPath" const CTX_SKETCH = "sketch" const CTX_SOURCE = "source" const CTX_TARGET_BOARD = "targetBoard" diff --git a/src/arduino.cc/builder/container_find_includes.go b/src/arduino.cc/builder/container_find_includes.go index 067d768d..a8fb515c 100644 --- a/src/arduino.cc/builder/container_find_includes.go +++ b/src/arduino.cc/builder/container_find_includes.go @@ -45,7 +45,7 @@ func (s *ContainerFindIncludes) Run(context map[string]interface{}, ctx *types.C return i18n.WrapError(err) } - sketchBuildPath := context[constants.CTX_SKETCH_BUILD_PATH].(string) + sketchBuildPath := ctx.SketchBuildPath sketch := context[constants.CTX_SKETCH].(*types.Sketch) err = findIncludesUntilDone(context, ctx, filepath.Join(sketchBuildPath, filepath.Base(sketch.MainFile.Name)+".cpp")) if err != nil { @@ -53,7 +53,7 @@ func (s *ContainerFindIncludes) Run(context map[string]interface{}, ctx *types.C } foldersWithSources := context[constants.CTX_FOLDERS_WITH_SOURCES_QUEUE].(*types.UniqueSourceFolderQueue) - foldersWithSources.Push(types.SourceFolder{Folder: context[constants.CTX_SKETCH_BUILD_PATH].(string), Recurse: true}) + foldersWithSources.Push(types.SourceFolder{Folder: ctx.SketchBuildPath, Recurse: true}) if utils.MapHas(context, constants.CTX_IMPORTED_LIBRARIES) { for _, library := range context[constants.CTX_IMPORTED_LIBRARIES].([]*types.Library) { sourceFolders := types.LibraryToSourceFolder(library) diff --git a/src/arduino.cc/builder/ctags_target_file_saver.go b/src/arduino.cc/builder/ctags_target_file_saver.go index eb2ca5c6..08752776 100644 --- a/src/arduino.cc/builder/ctags_target_file_saver.go +++ b/src/arduino.cc/builder/ctags_target_file_saver.go @@ -30,7 +30,6 @@ package builder import ( - "arduino.cc/builder/constants" "arduino.cc/builder/i18n" "arduino.cc/builder/types" "arduino.cc/builder/utils" @@ -45,7 +44,7 @@ type CTagsTargetFileSaver struct { func (s *CTagsTargetFileSaver) Run(context map[string]interface{}, ctx *types.Context) error { source := context[s.SourceField].(string) - preprocPath := context[constants.CTX_PREPROC_PATH].(string) + preprocPath := ctx.PreprocPath err := utils.EnsureFolderExists(preprocPath) if err != nil { return i18n.WrapError(err) diff --git a/src/arduino.cc/builder/ensure_buildpath_exists.go b/src/arduino.cc/builder/ensure_buildpath_exists.go index fe191c2b..1b26bd70 100644 --- a/src/arduino.cc/builder/ensure_buildpath_exists.go +++ b/src/arduino.cc/builder/ensure_buildpath_exists.go @@ -30,7 +30,6 @@ package builder import ( - "arduino.cc/builder/constants" "arduino.cc/builder/i18n" "arduino.cc/builder/types" "arduino.cc/builder/utils" @@ -39,9 +38,7 @@ import ( type EnsureBuildPathExists struct{} func (s *EnsureBuildPathExists) Run(context map[string]interface{}, ctx *types.Context) error { - buildPath := context[constants.CTX_BUILD_PATH].(string) - - err := utils.EnsureFolderExists(buildPath) + err := utils.EnsureFolderExists(ctx.BuildPath) if err != nil { return i18n.WrapError(err) } diff --git a/src/arduino.cc/builder/fail_if_buildpath_equals_sketchpath.go b/src/arduino.cc/builder/fail_if_buildpath_equals_sketchpath.go index ecae0085..11f2bdf0 100644 --- a/src/arduino.cc/builder/fail_if_buildpath_equals_sketchpath.go +++ b/src/arduino.cc/builder/fail_if_buildpath_equals_sketchpath.go @@ -33,18 +33,17 @@ import ( "arduino.cc/builder/constants" "arduino.cc/builder/i18n" "arduino.cc/builder/types" - "arduino.cc/builder/utils" "path/filepath" ) type FailIfBuildPathEqualsSketchPath struct{} func (s *FailIfBuildPathEqualsSketchPath) Run(context map[string]interface{}, ctx *types.Context) error { - if !utils.MapHas(context, constants.CTX_BUILD_PATH) || ctx.SketchLocation == "" { + if ctx.BuildPath == "" || ctx.SketchLocation == "" { return nil } - buildPath, err := filepath.Abs(context[constants.CTX_BUILD_PATH].(string)) + buildPath, err := filepath.Abs(ctx.BuildPath) if err != nil { return i18n.WrapError(err) } diff --git a/src/arduino.cc/builder/gcc_preproc_runner.go b/src/arduino.cc/builder/gcc_preproc_runner.go index aef30cbf..69d7b5c9 100644 --- a/src/arduino.cc/builder/gcc_preproc_runner.go +++ b/src/arduino.cc/builder/gcc_preproc_runner.go @@ -45,9 +45,9 @@ type GCCPreprocRunner struct { } func (s *GCCPreprocRunner) Run(context map[string]interface{}, ctx *types.Context) error { - sketchBuildPath := context[constants.CTX_SKETCH_BUILD_PATH].(string) + sketchBuildPath := ctx.SketchBuildPath sketch := context[constants.CTX_SKETCH].(*types.Sketch) - properties, targetFilePath, err := prepareGCCPreprocRecipeProperties(context, filepath.Join(sketchBuildPath, filepath.Base(sketch.MainFile.Name)+".cpp"), s.TargetFileName) + properties, targetFilePath, err := prepareGCCPreprocRecipeProperties(context, ctx, filepath.Join(sketchBuildPath, filepath.Base(sketch.MainFile.Name)+".cpp"), s.TargetFileName) if err != nil { return i18n.WrapError(err) } @@ -75,7 +75,7 @@ type GCCPreprocRunnerForDiscoveringIncludes struct { } func (s *GCCPreprocRunnerForDiscoveringIncludes) Run(context map[string]interface{}, ctx *types.Context) error { - properties, _, err := prepareGCCPreprocRecipeProperties(context, s.SourceFilePath, s.TargetFilePath) + properties, _, err := prepareGCCPreprocRecipeProperties(context, ctx, s.SourceFilePath, s.TargetFilePath) if err != nil { return i18n.WrapError(err) } @@ -98,9 +98,9 @@ func (s *GCCPreprocRunnerForDiscoveringIncludes) Run(context map[string]interfac return nil } -func prepareGCCPreprocRecipeProperties(context map[string]interface{}, sourceFilePath string, targetFilePath string) (props.PropertiesMap, string, error) { +func prepareGCCPreprocRecipeProperties(context map[string]interface{}, ctx *types.Context, sourceFilePath string, targetFilePath string) (props.PropertiesMap, string, error) { if targetFilePath != utils.NULLFile() { - preprocPath := context[constants.CTX_PREPROC_PATH].(string) + preprocPath := ctx.PreprocPath err := utils.EnsureFolderExists(preprocPath) if err != nil { return nil, "", i18n.WrapError(err) diff --git a/src/arduino.cc/builder/gcc_preproc_source_saver.go b/src/arduino.cc/builder/gcc_preproc_source_saver.go index 8eff3aec..ab678762 100644 --- a/src/arduino.cc/builder/gcc_preproc_source_saver.go +++ b/src/arduino.cc/builder/gcc_preproc_source_saver.go @@ -32,14 +32,15 @@ package builder import ( "arduino.cc/builder/constants" "arduino.cc/builder/i18n" + "arduino.cc/builder/types" "arduino.cc/builder/utils" "path/filepath" ) type GCCPreprocSourceSaver struct{} -func (s *GCCPreprocSourceSaver) Run(context map[string]interface{}) error { - preprocPath := context[constants.CTX_PREPROC_PATH].(string) +func (s *GCCPreprocSourceSaver) Run(context map[string]interface{}, ctx *types.Context) error { + preprocPath := ctx.PreprocPath err := utils.EnsureFolderExists(preprocPath) if err != nil { return i18n.WrapError(err) diff --git a/src/arduino.cc/builder/generate_buildpath_if_missing.go b/src/arduino.cc/builder/generate_buildpath_if_missing.go index 10cf60b8..965643bf 100644 --- a/src/arduino.cc/builder/generate_buildpath_if_missing.go +++ b/src/arduino.cc/builder/generate_buildpath_if_missing.go @@ -42,7 +42,7 @@ import ( type GenerateBuildPathIfMissing struct{} func (s *GenerateBuildPathIfMissing) Run(context map[string]interface{}, ctx *types.Context) error { - if utils.MapHas(context, constants.CTX_BUILD_PATH) && context[constants.CTX_BUILD_PATH].(string) != constants.EMPTY_STRING { + if ctx.BuildPath != "" { return nil } @@ -59,7 +59,7 @@ func (s *GenerateBuildPathIfMissing) Run(context map[string]interface{}, ctx *ty logger.Fprintln(os.Stdout, constants.LOG_LEVEL_WARN, constants.MSG_SETTING_BUILD_PATH, buildPath) } - context[constants.CTX_BUILD_PATH] = buildPath + ctx.BuildPath = buildPath return nil } diff --git a/src/arduino.cc/builder/load_previous_build_options.go b/src/arduino.cc/builder/load_previous_build_options.go index 26f29682..1db8e8c3 100644 --- a/src/arduino.cc/builder/load_previous_build_options.go +++ b/src/arduino.cc/builder/load_previous_build_options.go @@ -41,9 +41,7 @@ import ( type LoadPreviousBuildOptionsMap struct{} func (s *LoadPreviousBuildOptionsMap) Run(context map[string]interface{}, ctx *types.Context) error { - buildPath := context[constants.CTX_BUILD_PATH].(string) - - buildOptionsFile := filepath.Join(buildPath, constants.BUILD_OPTIONS_FILE) + buildOptionsFile := filepath.Join(ctx.BuildPath, constants.BUILD_OPTIONS_FILE) _, err := os.Stat(buildOptionsFile) if err != nil { diff --git a/src/arduino.cc/builder/merge_sketch_with_bootloader.go b/src/arduino.cc/builder/merge_sketch_with_bootloader.go index 588cc315..dbd711e5 100644 --- a/src/arduino.cc/builder/merge_sketch_with_bootloader.go +++ b/src/arduino.cc/builder/merge_sketch_with_bootloader.go @@ -48,7 +48,7 @@ func (s *MergeSketchWithBootloader) Run(context map[string]interface{}, ctx *typ return nil } - buildPath := context[constants.CTX_BUILD_PATH].(string) + buildPath := ctx.BuildPath sketch := context[constants.CTX_SKETCH].(*types.Sketch) sketchFileName := filepath.Base(sketch.MainFile.Name) logger := ctx.GetLogger() diff --git a/src/arduino.cc/builder/phases/core_builder.go b/src/arduino.cc/builder/phases/core_builder.go index 7217f136..8f5520f3 100644 --- a/src/arduino.cc/builder/phases/core_builder.go +++ b/src/arduino.cc/builder/phases/core_builder.go @@ -41,7 +41,7 @@ import ( type CoreBuilder struct{} func (s *CoreBuilder) Run(context map[string]interface{}, ctx *types.Context) error { - coreBuildPath := context[constants.CTX_CORE_BUILD_PATH].(string) + coreBuildPath := ctx.CoreBuildPath buildProperties := context[constants.CTX_BUILD_PROPERTIES].(props.PropertiesMap) verbose := ctx.Verbose warningsLevel := context[constants.CTX_WARNINGS_LEVEL].(string) diff --git a/src/arduino.cc/builder/phases/libraries_builder.go b/src/arduino.cc/builder/phases/libraries_builder.go index 5cc8dc21..c700fbd9 100644 --- a/src/arduino.cc/builder/phases/libraries_builder.go +++ b/src/arduino.cc/builder/phases/libraries_builder.go @@ -43,7 +43,7 @@ import ( type LibrariesBuilder struct{} func (s *LibrariesBuilder) Run(context map[string]interface{}, ctx *types.Context) error { - librariesBuildPath := context[constants.CTX_LIBRARIES_BUILD_PATH].(string) + librariesBuildPath := ctx.LibrariesBuildPath buildProperties := context[constants.CTX_BUILD_PROPERTIES].(props.PropertiesMap) includes := context[constants.CTX_INCLUDE_FOLDERS].([]string) includes = utils.Map(includes, utils.WrapWithHyphenI) diff --git a/src/arduino.cc/builder/phases/linker.go b/src/arduino.cc/builder/phases/linker.go index 2508d27c..707dd543 100644 --- a/src/arduino.cc/builder/phases/linker.go +++ b/src/arduino.cc/builder/phases/linker.go @@ -53,7 +53,7 @@ func (s *Linker) Run(context map[string]interface{}, ctx *types.Context) error { objectFiles = append(objectFiles, objectFilesCore...) coreArchiveFilePath := context[constants.CTX_ARCHIVE_FILE_PATH_CORE].(string) - buildPath := context[constants.CTX_BUILD_PATH].(string) + buildPath := ctx.BuildPath coreDotARelPath, err := filepath.Rel(buildPath, coreArchiveFilePath) if err != nil { return i18n.WrapError(err) diff --git a/src/arduino.cc/builder/phases/sketch_builder.go b/src/arduino.cc/builder/phases/sketch_builder.go index 0de2b5a4..17b29632 100644 --- a/src/arduino.cc/builder/phases/sketch_builder.go +++ b/src/arduino.cc/builder/phases/sketch_builder.go @@ -41,7 +41,7 @@ import ( type SketchBuilder struct{} func (s *SketchBuilder) Run(context map[string]interface{}, ctx *types.Context) error { - sketchBuildPath := context[constants.CTX_SKETCH_BUILD_PATH].(string) + sketchBuildPath := ctx.SketchBuildPath buildProperties := context[constants.CTX_BUILD_PROPERTIES].(props.PropertiesMap) includes := context[constants.CTX_INCLUDE_FOLDERS].([]string) includes = utils.Map(includes, utils.WrapWithHyphenI) diff --git a/src/arduino.cc/builder/setup_build_properties.go b/src/arduino.cc/builder/setup_build_properties.go index 035e1ac2..e026decd 100644 --- a/src/arduino.cc/builder/setup_build_properties.go +++ b/src/arduino.cc/builder/setup_build_properties.go @@ -54,8 +54,8 @@ func (s *SetupBuildProperties) Run(context map[string]interface{}, ctx *types.Co buildProperties.Merge(targetPlatform.Properties) buildProperties.Merge(targetBoard.Properties) - if utils.MapHas(context, constants.CTX_BUILD_PATH) { - buildProperties[constants.BUILD_PROPERTIES_BUILD_PATH] = context[constants.CTX_BUILD_PATH].(string) + if ctx.BuildPath != "" { + buildProperties[constants.BUILD_PROPERTIES_BUILD_PATH] = ctx.BuildPath } if utils.MapHas(context, constants.CTX_SKETCH) { buildProperties[constants.BUILD_PROPERTIES_BUILD_PROJECT_NAME] = filepath.Base(context[constants.CTX_SKETCH].(*types.Sketch).MainFile.Name) diff --git a/src/arduino.cc/builder/sketch_saver.go b/src/arduino.cc/builder/sketch_saver.go index 5ac36c75..1df4faa6 100644 --- a/src/arduino.cc/builder/sketch_saver.go +++ b/src/arduino.cc/builder/sketch_saver.go @@ -41,7 +41,7 @@ type SketchSaver struct{} func (s *SketchSaver) Run(context map[string]interface{}, ctx *types.Context) error { sketch := context[constants.CTX_SKETCH].(*types.Sketch) - sketchBuildPath := context[constants.CTX_SKETCH_BUILD_PATH].(string) + sketchBuildPath := ctx.SketchBuildPath source := context[constants.CTX_SOURCE].(string) err := utils.EnsureFolderExists(sketchBuildPath) diff --git a/src/arduino.cc/builder/store_build_options_map.go b/src/arduino.cc/builder/store_build_options_map.go index b85355ab..20aca86f 100644 --- a/src/arduino.cc/builder/store_build_options_map.go +++ b/src/arduino.cc/builder/store_build_options_map.go @@ -39,7 +39,7 @@ import ( type StoreBuildOptionsMap struct{} func (s *StoreBuildOptionsMap) Run(context map[string]interface{}, ctx *types.Context) error { - buildPath := context[constants.CTX_BUILD_PATH].(string) + buildPath := ctx.BuildPath buildOptionsJson := context[constants.CTX_BUILD_OPTIONS_JSON].(string) utils.WriteFile(filepath.Join(buildPath, constants.BUILD_OPTIONS_FILE), buildOptionsJson) diff --git a/src/arduino.cc/builder/test/add_additional_entries_to_context_test.go b/src/arduino.cc/builder/test/add_additional_entries_to_context_test.go index b58c4a8c..efc31b79 100644 --- a/src/arduino.cc/builder/test/add_additional_entries_to_context_test.go +++ b/src/arduino.cc/builder/test/add_additional_entries_to_context_test.go @@ -45,10 +45,10 @@ func TestAddAdditionalEntriesToContextNoBuildPath(t *testing.T) { command := builder.AddAdditionalEntriesToContext{} NoError(t, command.Run(context, ctx)) - require.Nil(t, context[constants.CTX_PREPROC_PATH]) - require.Nil(t, context[constants.CTX_SKETCH_BUILD_PATH]) - require.Nil(t, context[constants.CTX_LIBRARIES_BUILD_PATH]) - require.Nil(t, context[constants.CTX_CORE_BUILD_PATH]) + require.Empty(t, ctx.PreprocPath) + require.Empty(t, ctx.SketchBuildPath) + require.Empty(t, ctx.LibrariesBuildPath) + require.Empty(t, ctx.CoreBuildPath) require.NotNil(t, context[constants.CTX_WARNINGS_LEVEL]) @@ -61,16 +61,15 @@ func TestAddAdditionalEntriesToContextNoBuildPath(t *testing.T) { func TestAddAdditionalEntriesToContextWithBuildPath(t *testing.T) { context := make(map[string]interface{}) ctx := &types.Context{} - - context[constants.CTX_BUILD_PATH] = "folder" + ctx.BuildPath = "folder" command := builder.AddAdditionalEntriesToContext{} NoError(t, command.Run(context, ctx)) - require.Equal(t, Abs(t, filepath.Join("folder", constants.FOLDER_PREPROC)), context[constants.CTX_PREPROC_PATH]) - require.Equal(t, Abs(t, filepath.Join("folder", constants.FOLDER_SKETCH)), context[constants.CTX_SKETCH_BUILD_PATH]) - require.Equal(t, Abs(t, filepath.Join("folder", constants.FOLDER_LIBRARIES)), context[constants.CTX_LIBRARIES_BUILD_PATH]) - require.Equal(t, Abs(t, filepath.Join("folder", constants.FOLDER_CORE)), context[constants.CTX_CORE_BUILD_PATH]) + require.Equal(t, Abs(t, filepath.Join("folder", constants.FOLDER_PREPROC)), ctx.PreprocPath) + require.Equal(t, Abs(t, filepath.Join("folder", constants.FOLDER_SKETCH)), ctx.SketchBuildPath) + require.Equal(t, Abs(t, filepath.Join("folder", constants.FOLDER_LIBRARIES)), ctx.LibrariesBuildPath) + require.Equal(t, Abs(t, filepath.Join("folder", constants.FOLDER_CORE)), ctx.CoreBuildPath) require.NotNil(t, context[constants.CTX_WARNINGS_LEVEL]) diff --git a/src/arduino.cc/builder/test/additional_sketch_files_copier_test.go b/src/arduino.cc/builder/test/additional_sketch_files_copier_test.go index 583ebc1f..fe2b68bc 100644 --- a/src/arduino.cc/builder/test/additional_sketch_files_copier_test.go +++ b/src/arduino.cc/builder/test/additional_sketch_files_copier_test.go @@ -60,7 +60,7 @@ func TestCopyOtherFiles(t *testing.T) { SketchLocation: filepath.Join("sketch1", "sketch.ino"), } - buildPath := SetupBuildPath(t, context) + buildPath := SetupBuildPath(t, ctx) defer os.RemoveAll(buildPath) commands := []types.Command{ @@ -98,7 +98,7 @@ func TestCopyOtherFilesOnlyIfChanged(t *testing.T) { SketchLocation: filepath.Join("sketch1", "sketch.ino"), } - buildPath := SetupBuildPath(t, context) + buildPath := SetupBuildPath(t, ctx) defer os.RemoveAll(buildPath) commands := []types.Command{ @@ -118,9 +118,9 @@ func TestCopyOtherFilesOnlyIfChanged(t *testing.T) { time.Sleep(2 * time.Second) context = make(map[string]interface{}) - context[constants.CTX_BUILD_PATH] = buildPath ctx = &types.Context{ SketchLocation: filepath.Join("sketch1", "sketch.ino"), + BuildPath: buildPath, } for _, command := range commands { diff --git a/src/arduino.cc/builder/test/builder_test.go b/src/arduino.cc/builder/test/builder_test.go index 3a7decac..3ffce9a0 100644 --- a/src/arduino.cc/builder/test/builder_test.go +++ b/src/arduino.cc/builder/test/builder_test.go @@ -55,7 +55,7 @@ func TestBuilderEmptySketch(t *testing.T) { Verbose: true, } - buildPath := SetupBuildPath(t, context) + buildPath := SetupBuildPath(t, ctx) defer os.RemoveAll(buildPath) ctx.DebugLevel = 10 @@ -91,7 +91,7 @@ func TestBuilderBridge(t *testing.T) { Verbose: true, } - buildPath := SetupBuildPath(t, context) + buildPath := SetupBuildPath(t, ctx) defer os.RemoveAll(buildPath) command := builder.Builder{} @@ -126,7 +126,7 @@ func TestBuilderSketchWithConfig(t *testing.T) { ArduinoAPIVersion: "10600", } - buildPath := SetupBuildPath(t, context) + buildPath := SetupBuildPath(t, ctx) defer os.RemoveAll(buildPath) command := builder.Builder{} @@ -161,7 +161,7 @@ func TestBuilderBridgeTwice(t *testing.T) { ArduinoAPIVersion: "10600", } - buildPath := SetupBuildPath(t, context) + buildPath := SetupBuildPath(t, ctx) defer os.RemoveAll(buildPath) command := builder.Builder{} @@ -200,7 +200,7 @@ func TestBuilderBridgeSAM(t *testing.T) { ArduinoAPIVersion: "10600", } - buildPath := SetupBuildPath(t, context) + buildPath := SetupBuildPath(t, ctx) defer os.RemoveAll(buildPath) context[constants.CTX_WARNINGS_LEVEL] = "all" @@ -246,7 +246,7 @@ func TestBuilderBridgeRedBearLab(t *testing.T) { ArduinoAPIVersion: "10600", } - buildPath := SetupBuildPath(t, context) + buildPath := SetupBuildPath(t, ctx) defer os.RemoveAll(buildPath) command := builder.Builder{} @@ -281,7 +281,7 @@ func TestBuilderSketchNoFunctions(t *testing.T) { ArduinoAPIVersion: "10600", } - buildPath := SetupBuildPath(t, context) + buildPath := SetupBuildPath(t, ctx) defer os.RemoveAll(buildPath) command := builder.Builder{} @@ -303,7 +303,7 @@ func TestBuilderSketchWithBackup(t *testing.T) { ArduinoAPIVersion: "10600", } - buildPath := SetupBuildPath(t, context) + buildPath := SetupBuildPath(t, ctx) defer os.RemoveAll(buildPath) command := builder.Builder{} @@ -325,7 +325,7 @@ func TestBuilderSketchWithOldLib(t *testing.T) { ArduinoAPIVersion: "10600", } - buildPath := SetupBuildPath(t, context) + buildPath := SetupBuildPath(t, ctx) defer os.RemoveAll(buildPath) command := builder.Builder{} @@ -347,7 +347,7 @@ func TestBuilderSketchWithSubfolders(t *testing.T) { ArduinoAPIVersion: "10600", } - buildPath := SetupBuildPath(t, context) + buildPath := SetupBuildPath(t, ctx) defer os.RemoveAll(buildPath) command := builder.Builder{} @@ -369,7 +369,7 @@ func TestBuilderSketchBuildPathContainsUnusedPreviouslyCompiledLibrary(t *testin ArduinoAPIVersion: "10600", } - buildPath := SetupBuildPath(t, context) + buildPath := SetupBuildPath(t, ctx) defer os.RemoveAll(buildPath) NoError(t, os.MkdirAll(filepath.Join(buildPath, constants.FOLDER_LIBRARIES, "SPI"), os.FileMode(0755))) diff --git a/src/arduino.cc/builder/test/coan_runner_test.go b/src/arduino.cc/builder/test/coan_runner_test.go index fbda1e44..89f58ec8 100644 --- a/src/arduino.cc/builder/test/coan_runner_test.go +++ b/src/arduino.cc/builder/test/coan_runner_test.go @@ -54,7 +54,7 @@ func TestCoanRunner(t *testing.T) { Verbose: true, } - buildPath := SetupBuildPath(t, context) + buildPath := SetupBuildPath(t, ctx) defer os.RemoveAll(buildPath) commands := []types.Command{ diff --git a/src/arduino.cc/builder/test/create_build_options_map_test.go b/src/arduino.cc/builder/test/create_build_options_map_test.go index cd57b0c2..5316ab73 100644 --- a/src/arduino.cc/builder/test/create_build_options_map_test.go +++ b/src/arduino.cc/builder/test/create_build_options_map_test.go @@ -49,11 +49,10 @@ func TestCreateBuildOptionsMap(t *testing.T) { FQBN: "fqbn", ArduinoAPIVersion: "ideVersion", Verbose: true, + BuildPath: "buildPath", + DebugLevel: 5, } - context[constants.CTX_BUILD_PATH] = "buildPath" - ctx.DebugLevel = 5 - create := builder.CreateBuildOptionsMap{} err := create.Run(context, ctx) NoError(t, err) diff --git a/src/arduino.cc/builder/test/ctags_runner_test.go b/src/arduino.cc/builder/test/ctags_runner_test.go index 0bdf205a..0f133d43 100644 --- a/src/arduino.cc/builder/test/ctags_runner_test.go +++ b/src/arduino.cc/builder/test/ctags_runner_test.go @@ -58,7 +58,7 @@ func TestCTagsRunner(t *testing.T) { Verbose: true, } - buildPath := SetupBuildPath(t, context) + buildPath := SetupBuildPath(t, ctx) defer os.RemoveAll(buildPath) commands := []types.Command{ @@ -109,7 +109,7 @@ func TestCTagsRunnerSketchWithClass(t *testing.T) { Verbose: true, } - buildPath := SetupBuildPath(t, context) + buildPath := SetupBuildPath(t, ctx) defer os.RemoveAll(buildPath) commands := []types.Command{ @@ -158,7 +158,7 @@ func TestCTagsRunnerSketchWithTypename(t *testing.T) { Verbose: true, } - buildPath := SetupBuildPath(t, context) + buildPath := SetupBuildPath(t, ctx) defer os.RemoveAll(buildPath) commands := []types.Command{ @@ -206,7 +206,7 @@ func TestCTagsRunnerSketchWithNamespace(t *testing.T) { Verbose: true, } - buildPath := SetupBuildPath(t, context) + buildPath := SetupBuildPath(t, ctx) defer os.RemoveAll(buildPath) commands := []types.Command{ @@ -253,7 +253,7 @@ func TestCTagsRunnerSketchWithTemplates(t *testing.T) { Verbose: true, } - buildPath := SetupBuildPath(t, context) + buildPath := SetupBuildPath(t, ctx) defer os.RemoveAll(buildPath) commands := []types.Command{ diff --git a/src/arduino.cc/builder/test/fail_if_buildpath_equals_sketchpath_test.go b/src/arduino.cc/builder/test/fail_if_buildpath_equals_sketchpath_test.go index 216742f0..676700f9 100644 --- a/src/arduino.cc/builder/test/fail_if_buildpath_equals_sketchpath_test.go +++ b/src/arduino.cc/builder/test/fail_if_buildpath_equals_sketchpath_test.go @@ -31,7 +31,6 @@ package test import ( "arduino.cc/builder" - "arduino.cc/builder/constants" "arduino.cc/builder/types" "github.com/stretchr/testify/require" "testing" @@ -41,10 +40,9 @@ func TestFailIfBuildPathEqualsSketchPath(t *testing.T) { context := make(map[string]interface{}) ctx := &types.Context{ SketchLocation: "buildPath/sketch.ino", + BuildPath: "buildPath", } - context[constants.CTX_BUILD_PATH] = "buildPath" - command := builder.FailIfBuildPathEqualsSketchPath{} require.Error(t, command.Run(context, ctx)) } @@ -53,10 +51,9 @@ func TestFailIfBuildPathEqualsSketchPathSketchPathDiffers(t *testing.T) { context := make(map[string]interface{}) ctx := &types.Context{ SketchLocation: "sketchPath/sketch.ino", + BuildPath: "buildPath", } - context[constants.CTX_BUILD_PATH] = "buildPath" - command := builder.FailIfBuildPathEqualsSketchPath{} NoError(t, command.Run(context, ctx)) } diff --git a/src/arduino.cc/builder/test/generate_buildpath_if_missing_test.go b/src/arduino.cc/builder/test/generate_buildpath_if_missing_test.go index 214a43c0..b0e98d94 100644 --- a/src/arduino.cc/builder/test/generate_buildpath_if_missing_test.go +++ b/src/arduino.cc/builder/test/generate_buildpath_if_missing_test.go @@ -31,7 +31,6 @@ package test import ( "arduino.cc/builder" - "arduino.cc/builder/constants" "arduino.cc/builder/types" "github.com/stretchr/testify/require" "os" @@ -49,7 +48,7 @@ func TestGenerateBuildPathIfMissing(t *testing.T) { err := command.Run(context, ctx) NoError(t, err) - require.Equal(t, filepath.Join(os.TempDir(), "arduino-sketch-098F6BCD4621D373CADE4E832627B4F6"), context[constants.CTX_BUILD_PATH]) + require.Equal(t, filepath.Join(os.TempDir(), "arduino-sketch-098F6BCD4621D373CADE4E832627B4F6"), ctx.BuildPath) _, err = os.Stat(filepath.Join(os.TempDir(), "arduino-sketch-098F6BCD4621D373CADE4E832627B4F6")) require.True(t, os.IsNotExist(err)) } @@ -60,13 +59,11 @@ func TestGenerateBuildPathIfEmpty(t *testing.T) { SketchLocation: "test", } - context[constants.CTX_BUILD_PATH] = constants.EMPTY_STRING - createBuildPathIfMissing := builder.GenerateBuildPathIfMissing{} err := createBuildPathIfMissing.Run(context, ctx) NoError(t, err) - require.Equal(t, filepath.Join(os.TempDir(), "arduino-sketch-098F6BCD4621D373CADE4E832627B4F6"), context[constants.CTX_BUILD_PATH]) + require.Equal(t, filepath.Join(os.TempDir(), "arduino-sketch-098F6BCD4621D373CADE4E832627B4F6"), ctx.BuildPath) _, err = os.Stat(filepath.Join(os.TempDir(), "arduino-sketch-098F6BCD4621D373CADE4E832627B4F6")) require.True(t, os.IsNotExist(err)) } @@ -74,14 +71,13 @@ func TestGenerateBuildPathIfEmpty(t *testing.T) { func TestDontGenerateBuildPathIfPresent(t *testing.T) { context := make(map[string]interface{}) ctx := &types.Context{} - - context[constants.CTX_BUILD_PATH] = "test" + ctx.BuildPath = "test" createBuildPathIfMissing := builder.GenerateBuildPathIfMissing{} err := createBuildPathIfMissing.Run(context, ctx) NoError(t, err) - require.Equal(t, "test", context[constants.CTX_BUILD_PATH]) + require.Equal(t, "test", ctx.BuildPath) } func TestGenerateBuildPathAndEnsureItExists(t *testing.T) { @@ -102,7 +98,7 @@ func TestGenerateBuildPathAndEnsureItExists(t *testing.T) { defer os.RemoveAll(filepath.Join(os.TempDir(), "arduino-sketch-098F6BCD4621D373CADE4E832627B4F6")) - require.Equal(t, filepath.Join(os.TempDir(), "arduino-sketch-098F6BCD4621D373CADE4E832627B4F6"), context[constants.CTX_BUILD_PATH]) + require.Equal(t, filepath.Join(os.TempDir(), "arduino-sketch-098F6BCD4621D373CADE4E832627B4F6"), ctx.BuildPath) _, err := os.Stat(filepath.Join(os.TempDir(), "arduino-sketch-098F6BCD4621D373CADE4E832627B4F6")) NoError(t, err) } diff --git a/src/arduino.cc/builder/test/helper.go b/src/arduino.cc/builder/test/helper.go index 50560b27..e2a3955e 100644 --- a/src/arduino.cc/builder/test/helper.go +++ b/src/arduino.cc/builder/test/helper.go @@ -77,10 +77,10 @@ func NoError(t *testing.T, err error, msgAndArgs ...interface{}) { } } -func SetupBuildPath(t *testing.T, context map[string]interface{}) string { +func SetupBuildPath(t *testing.T, ctx *types.Context) string { buildPath, err := ioutil.TempDir(constants.EMPTY_STRING, "test") NoError(t, err) - context[constants.CTX_BUILD_PATH] = buildPath + ctx.BuildPath = buildPath return buildPath } diff --git a/src/arduino.cc/builder/test/includes_finder_with_gcc_test.go b/src/arduino.cc/builder/test/includes_finder_with_gcc_test.go index 3ba30929..2c806afe 100644 --- a/src/arduino.cc/builder/test/includes_finder_with_gcc_test.go +++ b/src/arduino.cc/builder/test/includes_finder_with_gcc_test.go @@ -54,7 +54,7 @@ func TestIncludesFinderWithGCC(t *testing.T) { Verbose: true, } - buildPath := SetupBuildPath(t, context) + buildPath := SetupBuildPath(t, ctx) defer os.RemoveAll(buildPath) commands := []types.Command{ @@ -87,7 +87,7 @@ func TestIncludesFinderWithGCCSketchWithConfig(t *testing.T) { Verbose: true, } - buildPath := SetupBuildPath(t, context) + buildPath := SetupBuildPath(t, ctx) defer os.RemoveAll(buildPath) commands := []types.Command{ @@ -127,7 +127,7 @@ func TestIncludesFinderWithGCCSketchWithDependendLibraries(t *testing.T) { Verbose: true, } - buildPath := SetupBuildPath(t, context) + buildPath := SetupBuildPath(t, ctx) defer os.RemoveAll(buildPath) commands := []types.Command{ @@ -178,7 +178,7 @@ func TestIncludesFinderWithGCCSketchWithThatChecksIfSPIHasTransactions(t *testin Verbose: true, } - buildPath := SetupBuildPath(t, context) + buildPath := SetupBuildPath(t, ctx) defer os.RemoveAll(buildPath) commands := []types.Command{ @@ -219,7 +219,7 @@ func TestIncludesFinderWithGCCSketchWithThatChecksIfSPIHasTransactionsAndInclude Verbose: true, } - buildPath := SetupBuildPath(t, context) + buildPath := SetupBuildPath(t, ctx) defer os.RemoveAll(buildPath) commands := []types.Command{ diff --git a/src/arduino.cc/builder/test/includes_finder_with_regexp_test.go b/src/arduino.cc/builder/test/includes_finder_with_regexp_test.go index 150d48be..e1a5c384 100644 --- a/src/arduino.cc/builder/test/includes_finder_with_regexp_test.go +++ b/src/arduino.cc/builder/test/includes_finder_with_regexp_test.go @@ -53,7 +53,7 @@ func TestIncludesFinderWithRegExpCoanOutput(t *testing.T) { Verbose: true, } - buildPath := SetupBuildPath(t, context) + buildPath := SetupBuildPath(t, ctx) defer os.RemoveAll(buildPath) commands := []types.Command{ diff --git a/src/arduino.cc/builder/test/includes_to_include_folders_test.go b/src/arduino.cc/builder/test/includes_to_include_folders_test.go index ddb05732..04b4bf71 100644 --- a/src/arduino.cc/builder/test/includes_to_include_folders_test.go +++ b/src/arduino.cc/builder/test/includes_to_include_folders_test.go @@ -55,7 +55,7 @@ func TestIncludesToIncludeFolders(t *testing.T) { Verbose: true, } - buildPath := SetupBuildPath(t, context) + buildPath := SetupBuildPath(t, ctx) defer os.RemoveAll(buildPath) commands := []types.Command{ @@ -96,7 +96,7 @@ func TestIncludesToIncludeFoldersSketchWithIfDef(t *testing.T) { Verbose: true, } - buildPath := SetupBuildPath(t, context) + buildPath := SetupBuildPath(t, ctx) defer os.RemoveAll(buildPath) commands := []types.Command{ @@ -135,7 +135,7 @@ func TestIncludesToIncludeFoldersIRremoteLibrary(t *testing.T) { Verbose: true, } - buildPath := SetupBuildPath(t, context) + buildPath := SetupBuildPath(t, ctx) defer os.RemoveAll(buildPath) commands := []types.Command{ @@ -179,7 +179,7 @@ func TestIncludesToIncludeFoldersANewLibrary(t *testing.T) { Verbose: true, } - buildPath := SetupBuildPath(t, context) + buildPath := SetupBuildPath(t, ctx) defer os.RemoveAll(buildPath) commands := []types.Command{ @@ -222,7 +222,7 @@ func TestIncludesToIncludeFoldersDuplicateLibs(t *testing.T) { Verbose: true, } - buildPath := SetupBuildPath(t, context) + buildPath := SetupBuildPath(t, ctx) defer os.RemoveAll(buildPath) commands := []types.Command{ @@ -265,7 +265,7 @@ func TestIncludesToIncludeFoldersDuplicateLibsWithConflictingLibsOutsideOfPlatfo Verbose: true, } - buildPath := SetupBuildPath(t, context) + buildPath := SetupBuildPath(t, ctx) defer os.RemoveAll(buildPath) commands := []types.Command{ @@ -308,7 +308,7 @@ func TestIncludesToIncludeFoldersDuplicateLibs2(t *testing.T) { Verbose: true, } - buildPath := SetupBuildPath(t, context) + buildPath := SetupBuildPath(t, ctx) defer os.RemoveAll(buildPath) commands := []types.Command{ diff --git a/src/arduino.cc/builder/test/load_previous_build_options_map_test.go b/src/arduino.cc/builder/test/load_previous_build_options_map_test.go index bc035872..295724a8 100644 --- a/src/arduino.cc/builder/test/load_previous_build_options_map_test.go +++ b/src/arduino.cc/builder/test/load_previous_build_options_map_test.go @@ -44,7 +44,7 @@ func TestLoadPreviousBuildOptionsMap(t *testing.T) { context := make(map[string]interface{}) ctx := &types.Context{} - buildPath := SetupBuildPath(t, context) + buildPath := SetupBuildPath(t, ctx) defer os.RemoveAll(buildPath) err := utils.WriteFile(filepath.Join(buildPath, constants.BUILD_OPTIONS_FILE), "test") @@ -61,7 +61,7 @@ func TestLoadPreviousBuildOptionsMapMissingFile(t *testing.T) { context := make(map[string]interface{}) ctx := &types.Context{} - buildPath := SetupBuildPath(t, context) + buildPath := SetupBuildPath(t, ctx) defer os.RemoveAll(buildPath) command := builder.LoadPreviousBuildOptionsMap{} diff --git a/src/arduino.cc/builder/test/load_vid_pid_specific_properties_test.go b/src/arduino.cc/builder/test/load_vid_pid_specific_properties_test.go index 96fa9b2a..01c519d4 100644 --- a/src/arduino.cc/builder/test/load_vid_pid_specific_properties_test.go +++ b/src/arduino.cc/builder/test/load_vid_pid_specific_properties_test.go @@ -52,7 +52,7 @@ func TestLoadVIDPIDSpecificPropertiesWhenNoVIDPIDAreProvided(t *testing.T) { ArduinoAPIVersion: "10600", } - buildPath := SetupBuildPath(t, context) + buildPath := SetupBuildPath(t, ctx) defer os.RemoveAll(buildPath) commands := []types.Command{ @@ -83,7 +83,7 @@ func TestLoadVIDPIDSpecificProperties(t *testing.T) { ArduinoAPIVersion: "10600", } - buildPath := SetupBuildPath(t, context) + buildPath := SetupBuildPath(t, ctx) defer os.RemoveAll(buildPath) context[constants.CTX_VIDPID] = "0x2341_0x0237" diff --git a/src/arduino.cc/builder/test/merge_sketch_with_bootloader_test.go b/src/arduino.cc/builder/test/merge_sketch_with_bootloader_test.go index 1a41ae39..ddc203fe 100644 --- a/src/arduino.cc/builder/test/merge_sketch_with_bootloader_test.go +++ b/src/arduino.cc/builder/test/merge_sketch_with_bootloader_test.go @@ -57,7 +57,7 @@ func TestMergeSketchWithBootloader(t *testing.T) { ArduinoAPIVersion: "10600", } - buildPath := SetupBuildPath(t, context) + buildPath := SetupBuildPath(t, ctx) defer os.RemoveAll(buildPath) err := utils.EnsureFolderExists(filepath.Join(buildPath, "sketch")) @@ -100,7 +100,7 @@ func TestMergeSketchWithBootloaderSketchInBuildPath(t *testing.T) { ArduinoAPIVersion: "10600", } - buildPath := SetupBuildPath(t, context) + buildPath := SetupBuildPath(t, ctx) defer os.RemoveAll(buildPath) err := utils.EnsureFolderExists(filepath.Join(buildPath, "sketch")) @@ -143,7 +143,7 @@ func TestMergeSketchWithBootloaderWhenNoBootloaderAvailable(t *testing.T) { ArduinoAPIVersion: "10600", } - buildPath := SetupBuildPath(t, context) + buildPath := SetupBuildPath(t, ctx) defer os.RemoveAll(buildPath) commands := []types.Command{ @@ -182,7 +182,7 @@ func TestMergeSketchWithBootloaderPathIsParameterized(t *testing.T) { ArduinoAPIVersion: "10600", } - buildPath := SetupBuildPath(t, context) + buildPath := SetupBuildPath(t, ctx) defer os.RemoveAll(buildPath) err := utils.EnsureFolderExists(filepath.Join(buildPath, "sketch")) diff --git a/src/arduino.cc/builder/test/prototypes_adder_test.go b/src/arduino.cc/builder/test/prototypes_adder_test.go index 3bd07901..2ed46b5d 100644 --- a/src/arduino.cc/builder/test/prototypes_adder_test.go +++ b/src/arduino.cc/builder/test/prototypes_adder_test.go @@ -59,7 +59,7 @@ func TestPrototypesAdderBridgeExample(t *testing.T) { Verbose: true, } - buildPath := SetupBuildPath(t, context) + buildPath := SetupBuildPath(t, ctx) defer os.RemoveAll(buildPath) ctx.DebugLevel = 10 @@ -102,7 +102,7 @@ func TestPrototypesAdderSketchWithIfDef(t *testing.T) { Verbose: true, } - buildPath := SetupBuildPath(t, context) + buildPath := SetupBuildPath(t, ctx) defer os.RemoveAll(buildPath) commands := []types.Command{ @@ -143,7 +143,7 @@ func TestPrototypesAdderBaladuino(t *testing.T) { Verbose: true, } - buildPath := SetupBuildPath(t, context) + buildPath := SetupBuildPath(t, ctx) defer os.RemoveAll(buildPath) commands := []types.Command{ @@ -184,7 +184,7 @@ func TestPrototypesAdderCharWithEscapedDoubleQuote(t *testing.T) { Verbose: true, } - buildPath := SetupBuildPath(t, context) + buildPath := SetupBuildPath(t, ctx) defer os.RemoveAll(buildPath) commands := []types.Command{ @@ -225,7 +225,7 @@ func TestPrototypesAdderIncludeBetweenMultilineComment(t *testing.T) { Verbose: true, } - buildPath := SetupBuildPath(t, context) + buildPath := SetupBuildPath(t, ctx) defer os.RemoveAll(buildPath) commands := []types.Command{ @@ -266,7 +266,7 @@ func TestPrototypesAdderLineContinuations(t *testing.T) { Verbose: true, } - buildPath := SetupBuildPath(t, context) + buildPath := SetupBuildPath(t, ctx) defer os.RemoveAll(buildPath) commands := []types.Command{ @@ -307,7 +307,7 @@ func TestPrototypesAdderStringWithComment(t *testing.T) { Verbose: true, } - buildPath := SetupBuildPath(t, context) + buildPath := SetupBuildPath(t, ctx) defer os.RemoveAll(buildPath) commands := []types.Command{ @@ -348,7 +348,7 @@ func TestPrototypesAdderSketchWithStruct(t *testing.T) { Verbose: true, } - buildPath := SetupBuildPath(t, context) + buildPath := SetupBuildPath(t, ctx) defer os.RemoveAll(buildPath) commands := []types.Command{ @@ -397,7 +397,7 @@ func TestPrototypesAdderSketchWithConfig(t *testing.T) { Verbose: true, } - buildPath := SetupBuildPath(t, context) + buildPath := SetupBuildPath(t, ctx) defer os.RemoveAll(buildPath) commands := []types.Command{ @@ -444,7 +444,7 @@ func TestPrototypesAdderSketchNoFunctionsTwoFiles(t *testing.T) { Verbose: true, } - buildPath := SetupBuildPath(t, context) + buildPath := SetupBuildPath(t, ctx) defer os.RemoveAll(buildPath) commands := []types.Command{ @@ -485,7 +485,7 @@ func TestPrototypesAdderSketchNoFunctions(t *testing.T) { Verbose: true, } - buildPath := SetupBuildPath(t, context) + buildPath := SetupBuildPath(t, ctx) defer os.RemoveAll(buildPath) sketchLocation := filepath.Join("sketch_no_functions", "main.ino") @@ -532,7 +532,7 @@ func TestPrototypesAdderSketchWithDefaultArgs(t *testing.T) { Verbose: true, } - buildPath := SetupBuildPath(t, context) + buildPath := SetupBuildPath(t, ctx) defer os.RemoveAll(buildPath) commands := []types.Command{ @@ -576,7 +576,7 @@ func TestPrototypesAdderSketchWithInlineFunction(t *testing.T) { Verbose: true, } - buildPath := SetupBuildPath(t, context) + buildPath := SetupBuildPath(t, ctx) defer os.RemoveAll(buildPath) commands := []types.Command{ @@ -631,7 +631,7 @@ func TestPrototypesAdderSketchWithFunctionSignatureInsideIFDEF(t *testing.T) { Verbose: true, } - buildPath := SetupBuildPath(t, context) + buildPath := SetupBuildPath(t, ctx) defer os.RemoveAll(buildPath) commands := []types.Command{ @@ -675,7 +675,7 @@ func TestPrototypesAdderSketchWithUSBCON(t *testing.T) { Verbose: true, } - buildPath := SetupBuildPath(t, context) + buildPath := SetupBuildPath(t, ctx) defer os.RemoveAll(buildPath) commands := []types.Command{ @@ -718,7 +718,7 @@ func TestPrototypesAdderSketchWithTypename(t *testing.T) { Verbose: true, } - buildPath := SetupBuildPath(t, context) + buildPath := SetupBuildPath(t, ctx) defer os.RemoveAll(buildPath) commands := []types.Command{ @@ -768,7 +768,7 @@ func TestPrototypesAdderSketchWithIfDef2(t *testing.T) { Verbose: true, } - buildPath := SetupBuildPath(t, context) + buildPath := SetupBuildPath(t, ctx) defer os.RemoveAll(buildPath) commands := []types.Command{ @@ -815,7 +815,7 @@ func TestPrototypesAdderSketchWithIfDef2SAM(t *testing.T) { Verbose: true, } - buildPath := SetupBuildPath(t, context) + buildPath := SetupBuildPath(t, ctx) defer os.RemoveAll(buildPath) commands := []types.Command{ @@ -862,7 +862,7 @@ func TestPrototypesAdderSketchWithConst(t *testing.T) { Verbose: true, } - buildPath := SetupBuildPath(t, context) + buildPath := SetupBuildPath(t, ctx) defer os.RemoveAll(buildPath) commands := []types.Command{ @@ -903,7 +903,7 @@ func TestPrototypesAdderSketchWithDosEol(t *testing.T) { Verbose: true, } - buildPath := SetupBuildPath(t, context) + buildPath := SetupBuildPath(t, ctx) defer os.RemoveAll(buildPath) commands := []types.Command{ diff --git a/src/arduino.cc/builder/test/setup_build_properties_test.go b/src/arduino.cc/builder/test/setup_build_properties_test.go index 6146f32d..614b82cd 100644 --- a/src/arduino.cc/builder/test/setup_build_properties_test.go +++ b/src/arduino.cc/builder/test/setup_build_properties_test.go @@ -53,7 +53,7 @@ func TestSetupBuildProperties(t *testing.T) { ArduinoAPIVersion: "10600", } - buildPath := SetupBuildPath(t, context) + buildPath := SetupBuildPath(t, ctx) defer os.RemoveAll(buildPath) commands := []types.Command{ @@ -117,7 +117,7 @@ func TestSetupBuildPropertiesWithSomeCustomOverrides(t *testing.T) { CustomBuildProperties: []string{"name=fake name", "tools.avrdude.config.path=non existent path with space and a ="}, } - buildPath := SetupBuildPath(t, context) + buildPath := SetupBuildPath(t, ctx) defer os.RemoveAll(buildPath) commands := []types.Command{ @@ -157,7 +157,7 @@ func TestSetupBuildPropertiesUserHardware(t *testing.T) { ArduinoAPIVersion: "10600", } - buildPath := SetupBuildPath(t, context) + buildPath := SetupBuildPath(t, ctx) defer os.RemoveAll(buildPath) commands := []types.Command{ @@ -196,7 +196,7 @@ func TestSetupBuildPropertiesWithMissingPropsFromParentPlatformTxtFiles(t *testi ArduinoAPIVersion: "10600", } - buildPath := SetupBuildPath(t, context) + buildPath := SetupBuildPath(t, ctx) defer os.RemoveAll(buildPath) commands := []types.Command{ diff --git a/src/arduino.cc/builder/test/store_build_options_map_test.go b/src/arduino.cc/builder/test/store_build_options_map_test.go index 29cbfbc0..c6816b90 100644 --- a/src/arduino.cc/builder/test/store_build_options_map_test.go +++ b/src/arduino.cc/builder/test/store_build_options_map_test.go @@ -55,7 +55,7 @@ func TestStoreBuildOptionsMap(t *testing.T) { DebugLevel: 5, } - buildPath := SetupBuildPath(t, context) + buildPath := SetupBuildPath(t, ctx) defer os.RemoveAll(buildPath) commands := []types.Command{ diff --git a/src/arduino.cc/builder/test/try_build_of_problematic_sketch_test.go b/src/arduino.cc/builder/test/try_build_of_problematic_sketch_test.go index d5c2e69a..181dac59 100644 --- a/src/arduino.cc/builder/test/try_build_of_problematic_sketch_test.go +++ b/src/arduino.cc/builder/test/try_build_of_problematic_sketch_test.go @@ -213,7 +213,7 @@ func makeDefaultContext(t *testing.T) (map[string]interface{}, *types.Context) { Verbose: true, DebugPreprocessor: true, } - buildPath := SetupBuildPath(t, context) + buildPath := SetupBuildPath(t, ctx) defer os.RemoveAll(buildPath) return context, ctx diff --git a/src/arduino.cc/builder/test/unused_compiled_libraries_remover_test.go b/src/arduino.cc/builder/test/unused_compiled_libraries_remover_test.go index 78fd8f66..8e51391f 100644 --- a/src/arduino.cc/builder/test/unused_compiled_libraries_remover_test.go +++ b/src/arduino.cc/builder/test/unused_compiled_libraries_remover_test.go @@ -51,7 +51,7 @@ func TestUnusedCompiledLibrariesRemover(t *testing.T) { context := make(map[string]interface{}) ctx := &types.Context{} - context[constants.CTX_LIBRARIES_BUILD_PATH] = temp + ctx.LibrariesBuildPath = temp context[constants.CTX_IMPORTED_LIBRARIES] = []*types.Library{&types.Library{Name: "Bridge"}} cmd := builder.UnusedCompiledLibrariesRemover{} @@ -70,7 +70,7 @@ func TestUnusedCompiledLibrariesRemover(t *testing.T) { func TestUnusedCompiledLibrariesRemoverLibDoesNotExist(t *testing.T) { context := make(map[string]interface{}) ctx := &types.Context{} - context[constants.CTX_LIBRARIES_BUILD_PATH] = filepath.Join(os.TempDir(), "test") + ctx.LibrariesBuildPath = filepath.Join(os.TempDir(), "test") context[constants.CTX_IMPORTED_LIBRARIES] = []*types.Library{&types.Library{Name: "Bridge"}} cmd := builder.UnusedCompiledLibrariesRemover{} @@ -89,7 +89,7 @@ func TestUnusedCompiledLibrariesRemoverNoUsedLibraries(t *testing.T) { context := make(map[string]interface{}) ctx := &types.Context{} - context[constants.CTX_LIBRARIES_BUILD_PATH] = temp + ctx.LibrariesBuildPath = temp context[constants.CTX_IMPORTED_LIBRARIES] = []*types.Library{} cmd := builder.UnusedCompiledLibrariesRemover{} diff --git a/src/arduino.cc/builder/test/wipeout_build_path_if_build_options_changed_test.go b/src/arduino.cc/builder/test/wipeout_build_path_if_build_options_changed_test.go index 57cbcd8b..1fcdb3e7 100644 --- a/src/arduino.cc/builder/test/wipeout_build_path_if_build_options_changed_test.go +++ b/src/arduino.cc/builder/test/wipeout_build_path_if_build_options_changed_test.go @@ -45,7 +45,7 @@ func TestWipeoutBuildPathIfBuildOptionsChanged(t *testing.T) { context := make(map[string]interface{}) ctx := &types.Context{} - buildPath := SetupBuildPath(t, context) + buildPath := SetupBuildPath(t, ctx) defer os.RemoveAll(buildPath) context[constants.CTX_BUILD_OPTIONS_PREVIOUS_JSON] = "old" @@ -77,7 +77,7 @@ func TestWipeoutBuildPathIfBuildOptionsChangedNoPreviousBuildOptions(t *testing. context := make(map[string]interface{}) ctx := &types.Context{} - buildPath := SetupBuildPath(t, context) + buildPath := SetupBuildPath(t, ctx) defer os.RemoveAll(buildPath) context[constants.CTX_BUILD_OPTIONS_JSON] = "new" @@ -108,7 +108,7 @@ func TestWipeoutBuildPathIfBuildOptionsChangedBuildOptionsMatch(t *testing.T) { context := make(map[string]interface{}) ctx := &types.Context{} - buildPath := SetupBuildPath(t, context) + buildPath := SetupBuildPath(t, ctx) defer os.RemoveAll(buildPath) context[constants.CTX_BUILD_OPTIONS_PREVIOUS_JSON] = "options" diff --git a/src/arduino.cc/builder/types/context.go b/src/arduino.cc/builder/types/context.go index 311c36b2..aa3abea2 100644 --- a/src/arduino.cc/builder/types/context.go +++ b/src/arduino.cc/builder/types/context.go @@ -16,6 +16,12 @@ type Context struct { ArduinoAPIVersion string FQBN string + BuildPath string + SketchBuildPath string + CoreBuildPath string + LibrariesBuildPath string + PreprocPath string + // Libraries handling Includes []string Libraries []*Library diff --git a/src/arduino.cc/builder/unused_compiled_libraries_remover.go b/src/arduino.cc/builder/unused_compiled_libraries_remover.go index 90ef004a..c830c96d 100644 --- a/src/arduino.cc/builder/unused_compiled_libraries_remover.go +++ b/src/arduino.cc/builder/unused_compiled_libraries_remover.go @@ -42,7 +42,7 @@ import ( type UnusedCompiledLibrariesRemover struct{} func (s *UnusedCompiledLibrariesRemover) Run(context map[string]interface{}, ctx *types.Context) error { - librariesBuildPath := context[constants.CTX_LIBRARIES_BUILD_PATH].(string) + librariesBuildPath := ctx.LibrariesBuildPath libraries := context[constants.CTX_IMPORTED_LIBRARIES].([]*types.Library) _, err := os.Stat(librariesBuildPath) diff --git a/src/arduino.cc/builder/wipeout_build_path_if_build_options_changed.go b/src/arduino.cc/builder/wipeout_build_path_if_build_options_changed.go index c7e7121d..fb9edc1b 100644 --- a/src/arduino.cc/builder/wipeout_build_path_if_build_options_changed.go +++ b/src/arduino.cc/builder/wipeout_build_path_if_build_options_changed.go @@ -65,7 +65,7 @@ func (s *WipeoutBuildPathIfBuildOptionsChanged) Run(context map[string]interface logger.Println(constants.LOG_LEVEL_INFO, constants.MSG_BUILD_OPTIONS_CHANGED) - buildPath := context[constants.CTX_BUILD_PATH].(string) + buildPath := ctx.BuildPath files, err := gohasissues.ReadDir(buildPath) if err != nil { return i18n.WrapError(err) From ab56609e738d4db872d87da86a77638d018f50c3 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Thu, 14 Apr 2016 00:34:13 +0200 Subject: [PATCH 10/25] Moved WarningsLevel into Context Signed-off-by: Cristian Maglie --- src/arduino.cc/arduino-builder/main.go | 2 +- src/arduino.cc/builder/add_additional_entries_to_context.go | 5 ++--- src/arduino.cc/builder/constants/constants.go | 1 - src/arduino.cc/builder/phases/core_builder.go | 2 +- src/arduino.cc/builder/phases/libraries_builder.go | 2 +- src/arduino.cc/builder/phases/linker.go | 2 +- src/arduino.cc/builder/phases/sketch_builder.go | 2 +- .../builder/test/add_additional_entries_to_context_test.go | 4 ++-- src/arduino.cc/builder/test/builder_test.go | 2 +- src/arduino.cc/builder/types/context.go | 2 ++ 10 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/arduino.cc/arduino-builder/main.go b/src/arduino.cc/arduino-builder/main.go index d928d4f4..2b7f348d 100644 --- a/src/arduino.cc/arduino-builder/main.go +++ b/src/arduino.cc/arduino-builder/main.go @@ -289,7 +289,7 @@ func main() { } if *warningsLevelFlag != "" { - context[constants.CTX_WARNINGS_LEVEL] = *warningsLevelFlag + ctx.WarningsLevel = *warningsLevelFlag } if *debugLevelFlag > -1 { diff --git a/src/arduino.cc/builder/add_additional_entries_to_context.go b/src/arduino.cc/builder/add_additional_entries_to_context.go index 4d13eed7..0b90e297 100644 --- a/src/arduino.cc/builder/add_additional_entries_to_context.go +++ b/src/arduino.cc/builder/add_additional_entries_to_context.go @@ -33,7 +33,6 @@ import ( "arduino.cc/builder/constants" "arduino.cc/builder/i18n" "arduino.cc/builder/types" - "arduino.cc/builder/utils" "path/filepath" ) @@ -65,8 +64,8 @@ func (s *AddAdditionalEntriesToContext) Run(context map[string]interface{}, ctx ctx.CoreBuildPath = coreBuildPath } - if !utils.MapHas(context, constants.CTX_WARNINGS_LEVEL) { - context[constants.CTX_WARNINGS_LEVEL] = DEFAULT_WARNINGS_LEVEL + if ctx.WarningsLevel == "" { + ctx.WarningsLevel = DEFAULT_WARNINGS_LEVEL } sourceFiles := &types.UniqueStringQueue{} diff --git a/src/arduino.cc/builder/constants/constants.go b/src/arduino.cc/builder/constants/constants.go index aed90cc1..2e1933e0 100644 --- a/src/arduino.cc/builder/constants/constants.go +++ b/src/arduino.cc/builder/constants/constants.go @@ -105,7 +105,6 @@ const CTX_TARGET_PACKAGE = "targetPackage" const CTX_TARGET_PLATFORM = "targetPlatform" const CTX_TOOLS = "tools" const CTX_VIDPID = "VIDPID" -const CTX_WARNINGS_LEVEL = "warningLevel" const EMPTY_STRING = "" const FILE_BOARDS_LOCAL_TXT = "boards.local.txt" const FILE_BOARDS_TXT = "boards.txt" diff --git a/src/arduino.cc/builder/phases/core_builder.go b/src/arduino.cc/builder/phases/core_builder.go index 8f5520f3..4324ff37 100644 --- a/src/arduino.cc/builder/phases/core_builder.go +++ b/src/arduino.cc/builder/phases/core_builder.go @@ -44,7 +44,7 @@ func (s *CoreBuilder) Run(context map[string]interface{}, ctx *types.Context) er coreBuildPath := ctx.CoreBuildPath buildProperties := context[constants.CTX_BUILD_PROPERTIES].(props.PropertiesMap) verbose := ctx.Verbose - warningsLevel := context[constants.CTX_WARNINGS_LEVEL].(string) + warningsLevel := ctx.WarningsLevel logger := ctx.GetLogger() err := utils.EnsureFolderExists(coreBuildPath) diff --git a/src/arduino.cc/builder/phases/libraries_builder.go b/src/arduino.cc/builder/phases/libraries_builder.go index c700fbd9..816d7875 100644 --- a/src/arduino.cc/builder/phases/libraries_builder.go +++ b/src/arduino.cc/builder/phases/libraries_builder.go @@ -49,7 +49,7 @@ func (s *LibrariesBuilder) Run(context map[string]interface{}, ctx *types.Contex includes = utils.Map(includes, utils.WrapWithHyphenI) libraries := context[constants.CTX_IMPORTED_LIBRARIES].([]*types.Library) verbose := ctx.Verbose - warningsLevel := context[constants.CTX_WARNINGS_LEVEL].(string) + warningsLevel := ctx.WarningsLevel logger := ctx.GetLogger() err := utils.EnsureFolderExists(librariesBuildPath) diff --git a/src/arduino.cc/builder/phases/linker.go b/src/arduino.cc/builder/phases/linker.go index 707dd543..c2724f82 100644 --- a/src/arduino.cc/builder/phases/linker.go +++ b/src/arduino.cc/builder/phases/linker.go @@ -61,7 +61,7 @@ func (s *Linker) Run(context map[string]interface{}, ctx *types.Context) error { buildProperties := context[constants.CTX_BUILD_PROPERTIES].(props.PropertiesMap) verbose := ctx.Verbose - warningsLevel := context[constants.CTX_WARNINGS_LEVEL].(string) + warningsLevel := ctx.WarningsLevel logger := ctx.GetLogger() err = link(objectFiles, coreDotARelPath, coreArchiveFilePath, buildProperties, verbose, warningsLevel, logger) diff --git a/src/arduino.cc/builder/phases/sketch_builder.go b/src/arduino.cc/builder/phases/sketch_builder.go index 17b29632..df7019e5 100644 --- a/src/arduino.cc/builder/phases/sketch_builder.go +++ b/src/arduino.cc/builder/phases/sketch_builder.go @@ -46,7 +46,7 @@ func (s *SketchBuilder) Run(context map[string]interface{}, ctx *types.Context) includes := context[constants.CTX_INCLUDE_FOLDERS].([]string) includes = utils.Map(includes, utils.WrapWithHyphenI) verbose := ctx.Verbose - warningsLevel := context[constants.CTX_WARNINGS_LEVEL].(string) + warningsLevel := ctx.WarningsLevel logger := ctx.GetLogger() err := utils.EnsureFolderExists(sketchBuildPath) diff --git a/src/arduino.cc/builder/test/add_additional_entries_to_context_test.go b/src/arduino.cc/builder/test/add_additional_entries_to_context_test.go index efc31b79..36676a77 100644 --- a/src/arduino.cc/builder/test/add_additional_entries_to_context_test.go +++ b/src/arduino.cc/builder/test/add_additional_entries_to_context_test.go @@ -50,7 +50,7 @@ func TestAddAdditionalEntriesToContextNoBuildPath(t *testing.T) { require.Empty(t, ctx.LibrariesBuildPath) require.Empty(t, ctx.CoreBuildPath) - require.NotNil(t, context[constants.CTX_WARNINGS_LEVEL]) + require.NotNil(t, ctx.WarningsLevel) require.True(t, context[constants.CTX_COLLECTED_SOURCE_FILES_QUEUE].(*types.UniqueStringQueue).Empty()) require.True(t, context[constants.CTX_FOLDERS_WITH_SOURCES_QUEUE].(*types.UniqueSourceFolderQueue).Empty()) @@ -71,7 +71,7 @@ func TestAddAdditionalEntriesToContextWithBuildPath(t *testing.T) { require.Equal(t, Abs(t, filepath.Join("folder", constants.FOLDER_LIBRARIES)), ctx.LibrariesBuildPath) require.Equal(t, Abs(t, filepath.Join("folder", constants.FOLDER_CORE)), ctx.CoreBuildPath) - require.NotNil(t, context[constants.CTX_WARNINGS_LEVEL]) + require.NotNil(t, ctx.WarningsLevel) require.True(t, context[constants.CTX_COLLECTED_SOURCE_FILES_QUEUE].(*types.UniqueStringQueue).Empty()) require.True(t, context[constants.CTX_FOLDERS_WITH_SOURCES_QUEUE].(*types.UniqueSourceFolderQueue).Empty()) diff --git a/src/arduino.cc/builder/test/builder_test.go b/src/arduino.cc/builder/test/builder_test.go index 3ffce9a0..1f20c716 100644 --- a/src/arduino.cc/builder/test/builder_test.go +++ b/src/arduino.cc/builder/test/builder_test.go @@ -203,7 +203,7 @@ func TestBuilderBridgeSAM(t *testing.T) { buildPath := SetupBuildPath(t, ctx) defer os.RemoveAll(buildPath) - context[constants.CTX_WARNINGS_LEVEL] = "all" + ctx.WarningsLevel = "all" command := builder.Builder{} err := command.Run(context, ctx) diff --git a/src/arduino.cc/builder/types/context.go b/src/arduino.cc/builder/types/context.go index aa3abea2..ec6011b9 100644 --- a/src/arduino.cc/builder/types/context.go +++ b/src/arduino.cc/builder/types/context.go @@ -22,6 +22,8 @@ type Context struct { LibrariesBuildPath string PreprocPath string + WarningsLevel string + // Libraries handling Includes []string Libraries []*Library From 96a5ca52cd9a9b1e8029f9d01c19b28dd68f2488 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Thu, 14 Apr 2016 18:10:30 +0200 Subject: [PATCH 11/25] Moved BuildOptionsJSON into Context structure Signed-off-by: Cristian Maglie --- src/arduino.cc/builder/constants/constants.go | 3 --- .../builder/create_build_options_map.go | 5 +---- .../builder/load_previous_build_options.go | 2 +- .../builder/store_build_options_map.go | 6 +----- .../test/create_build_options_map_test.go | 16 +--------------- .../test/load_previous_build_options_map_test.go | 4 ++-- ...t_build_path_if_build_options_changed_test.go | 11 +++++------ src/arduino.cc/builder/types/context.go | 4 ++++ ...ipeout_build_path_if_build_options_changed.go | 7 +++---- 9 files changed, 18 insertions(+), 40 deletions(-) diff --git a/src/arduino.cc/builder/constants/constants.go b/src/arduino.cc/builder/constants/constants.go index 2e1933e0..944896f3 100644 --- a/src/arduino.cc/builder/constants/constants.go +++ b/src/arduino.cc/builder/constants/constants.go @@ -77,9 +77,6 @@ const CTAGS = "ctags" const CTX_ACTUAL_PLATFORM = "actualPlatform" const CTX_ARCHIVE_FILE_PATH_CORE = "archiveFileCore" const CTX_BUILD_CORE = "buildCore" -const CTX_BUILD_OPTIONS = "buildOptions" -const CTX_BUILD_OPTIONS_JSON = "buildOptionsJson" -const CTX_BUILD_OPTIONS_PREVIOUS_JSON = "buildOptionsPreviousJson" const CTX_BUILD_PROPERTIES = "buildProperties" const CTX_COLLECTED_SOURCE_FILES_QUEUE = "collectedSourceFilesQueue" const CTX_FILE_PATH_TO_READ = "filePathToRead" diff --git a/src/arduino.cc/builder/create_build_options_map.go b/src/arduino.cc/builder/create_build_options_map.go index f603a688..2b3a0f72 100644 --- a/src/arduino.cc/builder/create_build_options_map.go +++ b/src/arduino.cc/builder/create_build_options_map.go @@ -30,7 +30,6 @@ package builder import ( - "arduino.cc/builder/constants" "arduino.cc/builder/i18n" "arduino.cc/builder/types" "encoding/json" @@ -40,14 +39,12 @@ type CreateBuildOptionsMap struct{} func (s *CreateBuildOptionsMap) Run(context map[string]interface{}, ctx *types.Context) error { buildOptions := ctx.ExtractBuildOptions() - context[constants.CTX_BUILD_OPTIONS] = buildOptions - bytes, err := json.MarshalIndent(buildOptions, "", " ") if err != nil { return i18n.WrapError(err) } - context[constants.CTX_BUILD_OPTIONS_JSON] = string(bytes) + ctx.BuildOptionsJson = string(bytes) return nil } diff --git a/src/arduino.cc/builder/load_previous_build_options.go b/src/arduino.cc/builder/load_previous_build_options.go index 1db8e8c3..d341cfdb 100644 --- a/src/arduino.cc/builder/load_previous_build_options.go +++ b/src/arduino.cc/builder/load_previous_build_options.go @@ -56,7 +56,7 @@ func (s *LoadPreviousBuildOptionsMap) Run(context map[string]interface{}, ctx *t return i18n.WrapError(err) } - context[constants.CTX_BUILD_OPTIONS_PREVIOUS_JSON] = string(bytes) + ctx.BuildOptionsJsonPrevious = string(bytes) return nil } diff --git a/src/arduino.cc/builder/store_build_options_map.go b/src/arduino.cc/builder/store_build_options_map.go index 20aca86f..3044999e 100644 --- a/src/arduino.cc/builder/store_build_options_map.go +++ b/src/arduino.cc/builder/store_build_options_map.go @@ -39,10 +39,6 @@ import ( type StoreBuildOptionsMap struct{} func (s *StoreBuildOptionsMap) Run(context map[string]interface{}, ctx *types.Context) error { - buildPath := ctx.BuildPath - buildOptionsJson := context[constants.CTX_BUILD_OPTIONS_JSON].(string) - - utils.WriteFile(filepath.Join(buildPath, constants.BUILD_OPTIONS_FILE), buildOptionsJson) - + utils.WriteFile(filepath.Join(ctx.BuildPath, constants.BUILD_OPTIONS_FILE), ctx.BuildOptionsJson) return nil } diff --git a/src/arduino.cc/builder/test/create_build_options_map_test.go b/src/arduino.cc/builder/test/create_build_options_map_test.go index 5316ab73..3ef78c5a 100644 --- a/src/arduino.cc/builder/test/create_build_options_map_test.go +++ b/src/arduino.cc/builder/test/create_build_options_map_test.go @@ -31,10 +31,7 @@ package test import ( "arduino.cc/builder" - "arduino.cc/builder/constants" - "arduino.cc/builder/props" "arduino.cc/builder/types" - "arduino.cc/builder/utils" "github.com/stretchr/testify/require" "testing" ) @@ -57,17 +54,6 @@ func TestCreateBuildOptionsMap(t *testing.T) { err := create.Run(context, ctx) NoError(t, err) - buildOptions := context[constants.CTX_BUILD_OPTIONS].(props.PropertiesMap) - require.Equal(t, 8, len(utils.KeysOfMapOfString(buildOptions))) - require.Equal(t, "hardware,hardware2", buildOptions["hardwareFolders"]) - require.Equal(t, "tools", buildOptions["toolsFolders"]) - require.Equal(t, "", buildOptions["builtInLibrariesFolders"]) - require.Equal(t, "", buildOptions["customBuildProperties"]) - require.Equal(t, "libraries", buildOptions["otherLibrariesFolders"]) - require.Equal(t, "fqbn", buildOptions["fqbn"]) - require.Equal(t, "sketchLocation", buildOptions["sketchLocation"]) - require.Equal(t, "ideVersion", buildOptions["runtime.ide.version"]) - require.Equal(t, "{\n"+ " \"builtInLibrariesFolders\": \"\",\n"+ " \"customBuildProperties\": \"\",\n"+ @@ -77,5 +63,5 @@ func TestCreateBuildOptionsMap(t *testing.T) { " \"runtime.ide.version\": \"ideVersion\",\n"+ " \"sketchLocation\": \"sketchLocation\",\n"+ " \"toolsFolders\": \"tools\"\n"+ - "}", context[constants.CTX_BUILD_OPTIONS_JSON].(string)) + "}", ctx.BuildOptionsJson) } diff --git a/src/arduino.cc/builder/test/load_previous_build_options_map_test.go b/src/arduino.cc/builder/test/load_previous_build_options_map_test.go index 295724a8..d3bfa7db 100644 --- a/src/arduino.cc/builder/test/load_previous_build_options_map_test.go +++ b/src/arduino.cc/builder/test/load_previous_build_options_map_test.go @@ -54,7 +54,7 @@ func TestLoadPreviousBuildOptionsMap(t *testing.T) { err = command.Run(context, ctx) NoError(t, err) - require.Equal(t, "test", context[constants.CTX_BUILD_OPTIONS_PREVIOUS_JSON]) + require.Equal(t, "test", ctx.BuildOptionsJsonPrevious) } func TestLoadPreviousBuildOptionsMapMissingFile(t *testing.T) { @@ -68,5 +68,5 @@ func TestLoadPreviousBuildOptionsMapMissingFile(t *testing.T) { err := command.Run(context, ctx) NoError(t, err) - require.False(t, utils.MapHas(context, constants.CTX_BUILD_OPTIONS_PREVIOUS_JSON)) + require.Empty(t, ctx.BuildOptionsJsonPrevious) } diff --git a/src/arduino.cc/builder/test/wipeout_build_path_if_build_options_changed_test.go b/src/arduino.cc/builder/test/wipeout_build_path_if_build_options_changed_test.go index 1fcdb3e7..699cf40e 100644 --- a/src/arduino.cc/builder/test/wipeout_build_path_if_build_options_changed_test.go +++ b/src/arduino.cc/builder/test/wipeout_build_path_if_build_options_changed_test.go @@ -31,7 +31,6 @@ package test import ( "arduino.cc/builder" - "arduino.cc/builder/constants" "arduino.cc/builder/gohasissues" "arduino.cc/builder/types" "arduino.cc/builder/utils" @@ -48,8 +47,8 @@ func TestWipeoutBuildPathIfBuildOptionsChanged(t *testing.T) { buildPath := SetupBuildPath(t, ctx) defer os.RemoveAll(buildPath) - context[constants.CTX_BUILD_OPTIONS_PREVIOUS_JSON] = "old" - context[constants.CTX_BUILD_OPTIONS_JSON] = "new" + ctx.BuildOptionsJsonPrevious = "old" + ctx.BuildOptionsJson = "new" utils.TouchFile(filepath.Join(buildPath, "should_be_deleted.txt")) @@ -80,7 +79,7 @@ func TestWipeoutBuildPathIfBuildOptionsChangedNoPreviousBuildOptions(t *testing. buildPath := SetupBuildPath(t, ctx) defer os.RemoveAll(buildPath) - context[constants.CTX_BUILD_OPTIONS_JSON] = "new" + ctx.BuildOptionsJson = "new" utils.TouchFile(filepath.Join(buildPath, "should_not_be_deleted.txt")) @@ -111,8 +110,8 @@ func TestWipeoutBuildPathIfBuildOptionsChangedBuildOptionsMatch(t *testing.T) { buildPath := SetupBuildPath(t, ctx) defer os.RemoveAll(buildPath) - context[constants.CTX_BUILD_OPTIONS_PREVIOUS_JSON] = "options" - context[constants.CTX_BUILD_OPTIONS_JSON] = "options" + ctx.BuildOptionsJsonPrevious = "options" + ctx.BuildOptionsJson = "options" utils.TouchFile(filepath.Join(buildPath, "should_not_be_deleted.txt")) diff --git a/src/arduino.cc/builder/types/context.go b/src/arduino.cc/builder/types/context.go index ec6011b9..2ef3a238 100644 --- a/src/arduino.cc/builder/types/context.go +++ b/src/arduino.cc/builder/types/context.go @@ -16,6 +16,10 @@ type Context struct { ArduinoAPIVersion string FQBN string + // Build options are serialized here + BuildOptionsJson string + BuildOptionsJsonPrevious string + BuildPath string SketchBuildPath string CoreBuildPath string diff --git a/src/arduino.cc/builder/wipeout_build_path_if_build_options_changed.go b/src/arduino.cc/builder/wipeout_build_path_if_build_options_changed.go index fb9edc1b..c3613aa2 100644 --- a/src/arduino.cc/builder/wipeout_build_path_if_build_options_changed.go +++ b/src/arduino.cc/builder/wipeout_build_path_if_build_options_changed.go @@ -34,7 +34,6 @@ import ( "arduino.cc/builder/gohasissues" "arduino.cc/builder/i18n" "arduino.cc/builder/types" - "arduino.cc/builder/utils" "os" "path/filepath" "regexp" @@ -43,11 +42,11 @@ import ( type WipeoutBuildPathIfBuildOptionsChanged struct{} func (s *WipeoutBuildPathIfBuildOptionsChanged) Run(context map[string]interface{}, ctx *types.Context) error { - if !utils.MapHas(context, constants.CTX_BUILD_OPTIONS_PREVIOUS_JSON) { + if ctx.BuildOptionsJsonPrevious == "" { return nil } - buildOptionsJson := context[constants.CTX_BUILD_OPTIONS_JSON].(string) - previousBuildOptionsJson := context[constants.CTX_BUILD_OPTIONS_PREVIOUS_JSON].(string) + buildOptionsJson := ctx.BuildOptionsJson + previousBuildOptionsJson := ctx.BuildOptionsJsonPrevious logger := ctx.GetLogger() if buildOptionsJson == previousBuildOptionsJson { From c68454f41de61e2688338c056a9e4794b7506ada Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Thu, 14 Apr 2016 18:55:34 +0200 Subject: [PATCH 12/25] SourceFile collectors data are now in Context Signed-off-by: Cristian Maglie --- .../add_additional_entries_to_context.go | 8 ++--- ..._source_files_from_folders_with_sources.go | 5 ++-- src/arduino.cc/builder/constants/constants.go | 4 --- .../builder/container_find_includes.go | 14 ++++----- .../fail_if_imported_library_is_wrong.go | 6 ++-- .../builder/includes_to_include_folders.go | 11 +++---- .../builder/phases/libraries_builder.go | 2 +- .../print_used_and_not_used_libraries.go | 2 +- .../print_used_libraries_if_verbose.go | 7 ++--- .../add_additional_entries_to_context_test.go | 12 ++++---- ...ce_files_from_folders_with_sources_test.go | 13 ++++----- .../test/includes_finder_with_gcc_test.go | 9 +++--- .../test/includes_to_include_folders_test.go | 29 +++++++++---------- .../unused_compiled_libraries_remover_test.go | 7 ++--- src/arduino.cc/builder/types/context.go | 11 +++++-- .../unused_compiled_libraries_remover.go | 4 +-- .../warn_about_arch_incompatible_libraries.go | 3 +- 17 files changed, 65 insertions(+), 82 deletions(-) diff --git a/src/arduino.cc/builder/add_additional_entries_to_context.go b/src/arduino.cc/builder/add_additional_entries_to_context.go index 0b90e297..938a6f1f 100644 --- a/src/arduino.cc/builder/add_additional_entries_to_context.go +++ b/src/arduino.cc/builder/add_additional_entries_to_context.go @@ -68,12 +68,10 @@ func (s *AddAdditionalEntriesToContext) Run(context map[string]interface{}, ctx ctx.WarningsLevel = DEFAULT_WARNINGS_LEVEL } - sourceFiles := &types.UniqueStringQueue{} - context[constants.CTX_COLLECTED_SOURCE_FILES_QUEUE] = sourceFiles - foldersWithSources := &types.UniqueSourceFolderQueue{} - context[constants.CTX_FOLDERS_WITH_SOURCES_QUEUE] = foldersWithSources + ctx.CollectedSourceFiles = &types.UniqueStringQueue{} + ctx.FoldersWithSourceFiles = &types.UniqueSourceFolderQueue{} - context[constants.CTX_LIBRARY_RESOLUTION_RESULTS] = make(map[string]types.LibraryResolutionResult) + ctx.LibrariesResolutionResults = make(map[string]types.LibraryResolutionResult) context[constants.CTX_HARDWARE_REWRITE_RESULTS] = make(map[*types.Platform][]types.PlatforKeyRewrite) return nil diff --git a/src/arduino.cc/builder/collect_all_source_files_from_folders_with_sources.go b/src/arduino.cc/builder/collect_all_source_files_from_folders_with_sources.go index a2e20a34..4caaea1d 100644 --- a/src/arduino.cc/builder/collect_all_source_files_from_folders_with_sources.go +++ b/src/arduino.cc/builder/collect_all_source_files_from_folders_with_sources.go @@ -30,7 +30,6 @@ package builder import ( - "arduino.cc/builder/constants" "arduino.cc/builder/gohasissues" "arduino.cc/builder/i18n" "arduino.cc/builder/types" @@ -44,8 +43,8 @@ import ( type CollectAllSourceFilesFromFoldersWithSources struct{} func (s *CollectAllSourceFilesFromFoldersWithSources) Run(context map[string]interface{}, ctx *types.Context) error { - foldersWithSources := context[constants.CTX_FOLDERS_WITH_SOURCES_QUEUE].(*types.UniqueSourceFolderQueue) - sourceFiles := context[constants.CTX_COLLECTED_SOURCE_FILES_QUEUE].(*types.UniqueStringQueue) + foldersWithSources := ctx.FoldersWithSourceFiles + sourceFiles := ctx.CollectedSourceFiles filePaths := []string{} for !foldersWithSources.Empty() { diff --git a/src/arduino.cc/builder/constants/constants.go b/src/arduino.cc/builder/constants/constants.go index 944896f3..d5ce1df6 100644 --- a/src/arduino.cc/builder/constants/constants.go +++ b/src/arduino.cc/builder/constants/constants.go @@ -78,18 +78,14 @@ const CTX_ACTUAL_PLATFORM = "actualPlatform" const CTX_ARCHIVE_FILE_PATH_CORE = "archiveFileCore" const CTX_BUILD_CORE = "buildCore" const CTX_BUILD_PROPERTIES = "buildProperties" -const CTX_COLLECTED_SOURCE_FILES_QUEUE = "collectedSourceFilesQueue" const CTX_FILE_PATH_TO_READ = "filePathToRead" -const CTX_FOLDERS_WITH_SOURCES_QUEUE = "foldersWithSourcesQueue" const CTX_GCC_MINUS_E_SOURCE = "gccMinusESource" const CTX_GCC_MINUS_M_OUTPUT = "gccMinusMOutput" const CTX_HARDWARE = "hardware" const CTX_HARDWARE_REWRITE_RESULTS = "hardwareRewriteResults" -const CTX_IMPORTED_LIBRARIES = "importedLibraries" const CTX_INCLUDE_FOLDERS = "includeFolders" const CTX_INCLUDE_SECTION = "includeSection" const CTX_INCLUDES_JUST_FOUND = "includesJustFound" -const CTX_LIBRARY_RESOLUTION_RESULTS = "libraryResolutionResults" const CTX_LINE_OFFSET = "lineOffset" const CTX_OBJECT_FILES_CORE = "objectFilesCore" const CTX_OBJECT_FILES_LIBRARIES = "objectFilesLibraries" diff --git a/src/arduino.cc/builder/container_find_includes.go b/src/arduino.cc/builder/container_find_includes.go index a8fb515c..3e351fed 100644 --- a/src/arduino.cc/builder/container_find_includes.go +++ b/src/arduino.cc/builder/container_find_includes.go @@ -52,10 +52,10 @@ func (s *ContainerFindIncludes) Run(context map[string]interface{}, ctx *types.C return i18n.WrapError(err) } - foldersWithSources := context[constants.CTX_FOLDERS_WITH_SOURCES_QUEUE].(*types.UniqueSourceFolderQueue) + foldersWithSources := ctx.FoldersWithSourceFiles foldersWithSources.Push(types.SourceFolder{Folder: ctx.SketchBuildPath, Recurse: true}) - if utils.MapHas(context, constants.CTX_IMPORTED_LIBRARIES) { - for _, library := range context[constants.CTX_IMPORTED_LIBRARIES].([]*types.Library) { + if len(ctx.ImportedLibraries) > 0 { + for _, library := range ctx.ImportedLibraries { sourceFolders := types.LibraryToSourceFolder(library) for _, sourceFolder := range sourceFolders { foldersWithSources.Push(sourceFolder) @@ -68,7 +68,7 @@ func (s *ContainerFindIncludes) Run(context map[string]interface{}, ctx *types.C return i18n.WrapError(err) } - sourceFilePaths := context[constants.CTX_COLLECTED_SOURCE_FILES_QUEUE].(*types.UniqueStringQueue) + sourceFilePaths := ctx.CollectedSourceFiles for !sourceFilePaths.Empty() { err = findIncludesUntilDone(context, ctx, sourceFilePaths.Pop().(string)) @@ -100,7 +100,7 @@ func runCommand(context map[string]interface{}, ctx *types.Context, command type func findIncludesUntilDone(context map[string]interface{}, ctx *types.Context, sourceFilePath string) error { targetFilePath := utils.NULLFile() - importedLibraries := context[constants.CTX_IMPORTED_LIBRARIES].([]*types.Library) + importedLibraries := ctx.ImportedLibraries done := false for !done { commands := []types.Command{ @@ -116,11 +116,11 @@ func findIncludesUntilDone(context map[string]interface{}, ctx *types.Context, s } if len(context[constants.CTX_INCLUDES_JUST_FOUND].([]string)) == 0 { done = true - } else if len(context[constants.CTX_IMPORTED_LIBRARIES].([]*types.Library)) == len(importedLibraries) { + } else if len(ctx.ImportedLibraries) == len(importedLibraries) { err := runCommand(context, ctx, &GCCPreprocRunner{TargetFileName: constants.FILE_CTAGS_TARGET_FOR_GCC_MINUS_E}) return i18n.WrapError(err) } - importedLibraries = context[constants.CTX_IMPORTED_LIBRARIES].([]*types.Library) + importedLibraries = ctx.ImportedLibraries context[constants.CTX_INCLUDES_JUST_FOUND] = []string{} } return nil diff --git a/src/arduino.cc/builder/fail_if_imported_library_is_wrong.go b/src/arduino.cc/builder/fail_if_imported_library_is_wrong.go index 57d412a1..f0481e69 100644 --- a/src/arduino.cc/builder/fail_if_imported_library_is_wrong.go +++ b/src/arduino.cc/builder/fail_if_imported_library_is_wrong.go @@ -33,7 +33,6 @@ import ( "arduino.cc/builder/constants" "arduino.cc/builder/i18n" "arduino.cc/builder/types" - "arduino.cc/builder/utils" "os" "path/filepath" ) @@ -41,14 +40,13 @@ import ( type FailIfImportedLibraryIsWrong struct{} func (s *FailIfImportedLibraryIsWrong) Run(context map[string]interface{}, ctx *types.Context) error { - if !utils.MapHas(context, constants.CTX_IMPORTED_LIBRARIES) { + if len(ctx.ImportedLibraries) == 0 { return nil } logger := ctx.GetLogger() - importedLibraries := context[constants.CTX_IMPORTED_LIBRARIES].([]*types.Library) - for _, library := range importedLibraries { + for _, library := range ctx.ImportedLibraries { if !library.IsLegacy { if stat, err := os.Stat(filepath.Join(library.Folder, constants.LIBRARY_FOLDER_ARCH)); err == nil && stat.IsDir() { return i18n.ErrorfWithLogger(logger, constants.MSG_ARCH_FOLDER_NOT_SUPPORTED) diff --git a/src/arduino.cc/builder/includes_to_include_folders.go b/src/arduino.cc/builder/includes_to_include_folders.go index e95ed75f..7f293137 100644 --- a/src/arduino.cc/builder/includes_to_include_folders.go +++ b/src/arduino.cc/builder/includes_to_include_folders.go @@ -47,18 +47,15 @@ func (s *IncludesToIncludeFolders) Run(context map[string]interface{}, ctx *type platform := context[constants.CTX_TARGET_PLATFORM].(*types.Platform) actualPlatform := context[constants.CTX_ACTUAL_PLATFORM].(*types.Platform) - libraryResolutionResults := context[constants.CTX_LIBRARY_RESOLUTION_RESULTS].(map[string]types.LibraryResolutionResult) + libraryResolutionResults := ctx.LibrariesResolutionResults + importedLibraries := ctx.ImportedLibraries - importedLibraries := []*types.Library{} - if utils.MapHas(context, constants.CTX_IMPORTED_LIBRARIES) { - importedLibraries = context[constants.CTX_IMPORTED_LIBRARIES].([]*types.Library) - } newlyImportedLibraries, err := resolveLibraries(includes, headerToLibraries, importedLibraries, []*types.Platform{actualPlatform, platform}, libraryResolutionResults) if err != nil { return i18n.WrapError(err) } - foldersWithSources := context[constants.CTX_FOLDERS_WITH_SOURCES_QUEUE].(*types.UniqueSourceFolderQueue) + foldersWithSources := ctx.FoldersWithSourceFiles for _, newlyImportedLibrary := range newlyImportedLibraries { if !sliceContainsLibrary(importedLibraries, newlyImportedLibrary) { @@ -70,7 +67,7 @@ func (s *IncludesToIncludeFolders) Run(context map[string]interface{}, ctx *type } } - context[constants.CTX_IMPORTED_LIBRARIES] = importedLibraries + ctx.ImportedLibraries = importedLibraries buildProperties := context[constants.CTX_BUILD_PROPERTIES].(props.PropertiesMap) verbose := ctx.Verbose diff --git a/src/arduino.cc/builder/phases/libraries_builder.go b/src/arduino.cc/builder/phases/libraries_builder.go index 816d7875..ea2ce968 100644 --- a/src/arduino.cc/builder/phases/libraries_builder.go +++ b/src/arduino.cc/builder/phases/libraries_builder.go @@ -47,7 +47,7 @@ func (s *LibrariesBuilder) Run(context map[string]interface{}, ctx *types.Contex buildProperties := context[constants.CTX_BUILD_PROPERTIES].(props.PropertiesMap) includes := context[constants.CTX_INCLUDE_FOLDERS].([]string) includes = utils.Map(includes, utils.WrapWithHyphenI) - libraries := context[constants.CTX_IMPORTED_LIBRARIES].([]*types.Library) + libraries := ctx.ImportedLibraries verbose := ctx.Verbose warningsLevel := ctx.WarningsLevel logger := ctx.GetLogger() diff --git a/src/arduino.cc/builder/print_used_and_not_used_libraries.go b/src/arduino.cc/builder/print_used_and_not_used_libraries.go index 212eebae..1a552a84 100644 --- a/src/arduino.cc/builder/print_used_and_not_used_libraries.go +++ b/src/arduino.cc/builder/print_used_and_not_used_libraries.go @@ -44,7 +44,7 @@ func (s *PrintUsedAndNotUsedLibraries) Run(context map[string]interface{}, ctx * } logger := ctx.GetLogger() - libraryResolutionResults := context[constants.CTX_LIBRARY_RESOLUTION_RESULTS].(map[string]types.LibraryResolutionResult) + libraryResolutionResults := ctx.LibrariesResolutionResults for header, libResResult := range libraryResolutionResults { if !libResResult.IsLibraryFromPlatform { diff --git a/src/arduino.cc/builder/print_used_libraries_if_verbose.go b/src/arduino.cc/builder/print_used_libraries_if_verbose.go index a9f64715..369a2cc6 100644 --- a/src/arduino.cc/builder/print_used_libraries_if_verbose.go +++ b/src/arduino.cc/builder/print_used_libraries_if_verbose.go @@ -32,7 +32,6 @@ package builder import ( "arduino.cc/builder/constants" "arduino.cc/builder/types" - "arduino.cc/builder/utils" "time" ) @@ -42,13 +41,11 @@ func (s *PrintUsedLibrariesIfVerbose) Run(context map[string]interface{}, ctx *t verbose := ctx.Verbose logger := ctx.GetLogger() - if !verbose || !utils.MapHas(context, constants.CTX_IMPORTED_LIBRARIES) { + if !verbose || len(ctx.ImportedLibraries) == 0 { return nil } - importedLibraries := context[constants.CTX_IMPORTED_LIBRARIES].([]*types.Library) - - for _, library := range importedLibraries { + for _, library := range ctx.ImportedLibraries { legacy := constants.EMPTY_STRING if library.IsLegacy { legacy = constants.MSG_LIB_LEGACY diff --git a/src/arduino.cc/builder/test/add_additional_entries_to_context_test.go b/src/arduino.cc/builder/test/add_additional_entries_to_context_test.go index 36676a77..a300f3ae 100644 --- a/src/arduino.cc/builder/test/add_additional_entries_to_context_test.go +++ b/src/arduino.cc/builder/test/add_additional_entries_to_context_test.go @@ -52,10 +52,10 @@ func TestAddAdditionalEntriesToContextNoBuildPath(t *testing.T) { require.NotNil(t, ctx.WarningsLevel) - require.True(t, context[constants.CTX_COLLECTED_SOURCE_FILES_QUEUE].(*types.UniqueStringQueue).Empty()) - require.True(t, context[constants.CTX_FOLDERS_WITH_SOURCES_QUEUE].(*types.UniqueSourceFolderQueue).Empty()) + require.True(t, ctx.CollectedSourceFiles.Empty()) + require.True(t, ctx.FoldersWithSourceFiles.Empty()) - require.Equal(t, 0, len(context[constants.CTX_LIBRARY_RESOLUTION_RESULTS].(map[string]types.LibraryResolutionResult))) + require.Equal(t, 0, len(ctx.LibrariesResolutionResults)) } func TestAddAdditionalEntriesToContextWithBuildPath(t *testing.T) { @@ -73,8 +73,8 @@ func TestAddAdditionalEntriesToContextWithBuildPath(t *testing.T) { require.NotNil(t, ctx.WarningsLevel) - require.True(t, context[constants.CTX_COLLECTED_SOURCE_FILES_QUEUE].(*types.UniqueStringQueue).Empty()) - require.True(t, context[constants.CTX_FOLDERS_WITH_SOURCES_QUEUE].(*types.UniqueSourceFolderQueue).Empty()) + require.True(t, ctx.CollectedSourceFiles.Empty()) + require.True(t, ctx.FoldersWithSourceFiles.Empty()) - require.Equal(t, 0, len(context[constants.CTX_LIBRARY_RESOLUTION_RESULTS].(map[string]types.LibraryResolutionResult))) + require.Equal(t, 0, len(ctx.LibrariesResolutionResults)) } diff --git a/src/arduino.cc/builder/test/collect_all_source_files_from_folders_with_sources_test.go b/src/arduino.cc/builder/test/collect_all_source_files_from_folders_with_sources_test.go index ceb19fb0..2a868bc9 100644 --- a/src/arduino.cc/builder/test/collect_all_source_files_from_folders_with_sources_test.go +++ b/src/arduino.cc/builder/test/collect_all_source_files_from_folders_with_sources_test.go @@ -31,7 +31,6 @@ package test import ( "arduino.cc/builder" - "arduino.cc/builder/constants" "arduino.cc/builder/types" "github.com/stretchr/testify/require" "path/filepath" @@ -44,10 +43,10 @@ func TestCollectAllSourceFilesFromFoldersWithSources(t *testing.T) { ctx := &types.Context{} sourceFiles := &types.UniqueStringQueue{} - context[constants.CTX_COLLECTED_SOURCE_FILES_QUEUE] = sourceFiles + ctx.CollectedSourceFiles = sourceFiles foldersWithSources := &types.UniqueSourceFolderQueue{} foldersWithSources.Push(types.SourceFolder{Folder: Abs(t, "sketch_with_config"), Recurse: true}) - context[constants.CTX_FOLDERS_WITH_SOURCES_QUEUE] = foldersWithSources + ctx.FoldersWithSourceFiles = foldersWithSources commands := []types.Command{ &builder.CollectAllSourceFilesFromFoldersWithSources{}, @@ -71,10 +70,10 @@ func TestCollectAllSourceFilesFromFoldersWithSourcesOfLibrary(t *testing.T) { ctx := &types.Context{} sourceFiles := &types.UniqueStringQueue{} - context[constants.CTX_COLLECTED_SOURCE_FILES_QUEUE] = sourceFiles + ctx.CollectedSourceFiles = sourceFiles foldersWithSources := &types.UniqueSourceFolderQueue{} foldersWithSources.Push(types.SourceFolder{Folder: Abs(t, filepath.Join("downloaded_libraries", "Bridge")), Recurse: true}) - context[constants.CTX_FOLDERS_WITH_SOURCES_QUEUE] = foldersWithSources + ctx.FoldersWithSourceFiles = foldersWithSources commands := []types.Command{ &builder.CollectAllSourceFilesFromFoldersWithSources{}, @@ -106,12 +105,12 @@ func TestCollectAllSourceFilesFromFoldersWithSourcesOfOldLibrary(t *testing.T) { ctx := &types.Context{} sourceFiles := &types.UniqueStringQueue{} - context[constants.CTX_COLLECTED_SOURCE_FILES_QUEUE] = sourceFiles + ctx.CollectedSourceFiles = sourceFiles foldersWithSources := &types.UniqueSourceFolderQueue{} foldersWithSources.Push(types.SourceFolder{Folder: Abs(t, filepath.Join("libraries", "ShouldNotRecurseWithOldLibs")), Recurse: false}) foldersWithSources.Push(types.SourceFolder{Folder: Abs(t, filepath.Join("libraries", "ShouldNotRecurseWithOldLibs", "utility")), Recurse: false}) foldersWithSources.Push(types.SourceFolder{Folder: Abs(t, "non existent folder"), Recurse: false}) - context[constants.CTX_FOLDERS_WITH_SOURCES_QUEUE] = foldersWithSources + ctx.FoldersWithSourceFiles = foldersWithSources commands := []types.Command{ &builder.CollectAllSourceFilesFromFoldersWithSources{}, diff --git a/src/arduino.cc/builder/test/includes_finder_with_gcc_test.go b/src/arduino.cc/builder/test/includes_finder_with_gcc_test.go index 2c806afe..16b7a694 100644 --- a/src/arduino.cc/builder/test/includes_finder_with_gcc_test.go +++ b/src/arduino.cc/builder/test/includes_finder_with_gcc_test.go @@ -31,7 +31,6 @@ package test import ( "arduino.cc/builder" - "arduino.cc/builder/constants" "arduino.cc/builder/types" "arduino.cc/builder/utils" "github.com/stretchr/testify/require" @@ -108,7 +107,7 @@ func TestIncludesFinderWithGCCSketchWithConfig(t *testing.T) { require.Equal(t, 1, len(includes)) require.True(t, utils.SliceContains(includes, "Bridge.h")) - importedLibraries := context[constants.CTX_IMPORTED_LIBRARIES].([]*types.Library) + importedLibraries := ctx.ImportedLibraries require.Equal(t, 1, len(importedLibraries)) require.Equal(t, "Bridge", importedLibraries[0].Name) } @@ -153,7 +152,7 @@ func TestIncludesFinderWithGCCSketchWithDependendLibraries(t *testing.T) { require.Equal(t, "library3.h", includes[2]) require.Equal(t, "library4.h", includes[3]) - importedLibraries := context[constants.CTX_IMPORTED_LIBRARIES].([]*types.Library) + importedLibraries := ctx.ImportedLibraries require.Equal(t, 4, len(importedLibraries)) sort.Sort(ByLibraryName(importedLibraries)) @@ -199,7 +198,7 @@ func TestIncludesFinderWithGCCSketchWithThatChecksIfSPIHasTransactions(t *testin require.Equal(t, 1, len(includes)) require.Equal(t, "SPI.h", includes[0]) - importedLibraries := context[constants.CTX_IMPORTED_LIBRARIES].([]*types.Library) + importedLibraries := ctx.ImportedLibraries require.Equal(t, 1, len(importedLibraries)) require.Equal(t, "SPI", importedLibraries[0].Name) } @@ -244,7 +243,7 @@ func TestIncludesFinderWithGCCSketchWithThatChecksIfSPIHasTransactionsAndInclude require.Equal(t, "Inexistent.h", includes[0]) require.Equal(t, "SPI.h", includes[1]) - importedLibraries := context[constants.CTX_IMPORTED_LIBRARIES].([]*types.Library) + importedLibraries := ctx.ImportedLibraries require.Equal(t, 1, len(importedLibraries)) require.Equal(t, "SPI", importedLibraries[0].Name) } diff --git a/src/arduino.cc/builder/test/includes_to_include_folders_test.go b/src/arduino.cc/builder/test/includes_to_include_folders_test.go index 04b4bf71..eb15ac37 100644 --- a/src/arduino.cc/builder/test/includes_to_include_folders_test.go +++ b/src/arduino.cc/builder/test/includes_to_include_folders_test.go @@ -31,7 +31,6 @@ package test import ( "arduino.cc/builder" - "arduino.cc/builder/constants" "arduino.cc/builder/types" "github.com/stretchr/testify/require" "os" @@ -72,11 +71,11 @@ func TestIncludesToIncludeFolders(t *testing.T) { NoError(t, err) } - importedLibraries := context[constants.CTX_IMPORTED_LIBRARIES].([]*types.Library) + importedLibraries := ctx.ImportedLibraries require.Equal(t, 1, len(importedLibraries)) require.Equal(t, "Bridge", importedLibraries[0].Name) - libraryResolutionResults := context[constants.CTX_LIBRARY_RESOLUTION_RESULTS].(map[string]types.LibraryResolutionResult) + libraryResolutionResults := ctx.LibrariesResolutionResults require.NotNil(t, libraryResolutionResults) require.False(t, libraryResolutionResults["Bridge.h"].IsLibraryFromPlatform) } @@ -113,10 +112,10 @@ func TestIncludesToIncludeFoldersSketchWithIfDef(t *testing.T) { NoError(t, err) } - importedLibraries := context[constants.CTX_IMPORTED_LIBRARIES].([]*types.Library) + importedLibraries := ctx.ImportedLibraries require.Equal(t, 0, len(importedLibraries)) - libraryResolutionResults := context[constants.CTX_LIBRARY_RESOLUTION_RESULTS].(map[string]types.LibraryResolutionResult) + libraryResolutionResults := ctx.LibrariesResolutionResults require.NotNil(t, libraryResolutionResults) } @@ -152,13 +151,13 @@ func TestIncludesToIncludeFoldersIRremoteLibrary(t *testing.T) { NoError(t, err) } - importedLibraries := context[constants.CTX_IMPORTED_LIBRARIES].([]*types.Library) + importedLibraries := ctx.ImportedLibraries sort.Sort(ByLibraryName(importedLibraries)) require.Equal(t, 2, len(importedLibraries)) require.Equal(t, "Bridge", importedLibraries[0].Name) require.Equal(t, "IRremote", importedLibraries[1].Name) - libraryResolutionResults := context[constants.CTX_LIBRARY_RESOLUTION_RESULTS].(map[string]types.LibraryResolutionResult) + libraryResolutionResults := ctx.LibrariesResolutionResults require.NotNil(t, libraryResolutionResults) require.False(t, libraryResolutionResults["Bridge.h"].IsLibraryFromPlatform) require.False(t, libraryResolutionResults["IRremote.h"].IsLibraryFromPlatform) @@ -196,13 +195,13 @@ func TestIncludesToIncludeFoldersANewLibrary(t *testing.T) { NoError(t, err) } - importedLibraries := context[constants.CTX_IMPORTED_LIBRARIES].([]*types.Library) + importedLibraries := ctx.ImportedLibraries sort.Sort(ByLibraryName(importedLibraries)) require.Equal(t, 2, len(importedLibraries)) require.Equal(t, "ANewLibrary-master", importedLibraries[0].Name) require.Equal(t, "IRremote", importedLibraries[1].Name) - libraryResolutionResults := context[constants.CTX_LIBRARY_RESOLUTION_RESULTS].(map[string]types.LibraryResolutionResult) + libraryResolutionResults := ctx.LibrariesResolutionResults require.NotNil(t, libraryResolutionResults) require.False(t, libraryResolutionResults["anewlibrary.h"].IsLibraryFromPlatform) require.False(t, libraryResolutionResults["IRremote.h"].IsLibraryFromPlatform) @@ -239,13 +238,13 @@ func TestIncludesToIncludeFoldersDuplicateLibs(t *testing.T) { NoError(t, err) } - importedLibraries := context[constants.CTX_IMPORTED_LIBRARIES].([]*types.Library) + importedLibraries := ctx.ImportedLibraries sort.Sort(ByLibraryName(importedLibraries)) require.Equal(t, 1, len(importedLibraries)) require.Equal(t, "SPI", importedLibraries[0].Name) require.Equal(t, Abs(t, filepath.Join("user_hardware", "my_avr_platform", "avr", "libraries", "SPI")), importedLibraries[0].SrcFolder) - libraryResolutionResults := context[constants.CTX_LIBRARY_RESOLUTION_RESULTS].(map[string]types.LibraryResolutionResult) + libraryResolutionResults := ctx.LibrariesResolutionResults require.NotNil(t, libraryResolutionResults) require.True(t, libraryResolutionResults["SPI.h"].IsLibraryFromPlatform) } @@ -282,13 +281,13 @@ func TestIncludesToIncludeFoldersDuplicateLibsWithConflictingLibsOutsideOfPlatfo NoError(t, err) } - importedLibraries := context[constants.CTX_IMPORTED_LIBRARIES].([]*types.Library) + importedLibraries := ctx.ImportedLibraries sort.Sort(ByLibraryName(importedLibraries)) require.Equal(t, 1, len(importedLibraries)) require.Equal(t, "SPI", importedLibraries[0].Name) require.Equal(t, Abs(t, filepath.Join("libraries", "SPI")), importedLibraries[0].SrcFolder) - libraryResolutionResults := context[constants.CTX_LIBRARY_RESOLUTION_RESULTS].(map[string]types.LibraryResolutionResult) + libraryResolutionResults := ctx.LibrariesResolutionResults require.NotNil(t, libraryResolutionResults) require.False(t, libraryResolutionResults["SPI.h"].IsLibraryFromPlatform) } @@ -325,13 +324,13 @@ func TestIncludesToIncludeFoldersDuplicateLibs2(t *testing.T) { NoError(t, err) } - importedLibraries := context[constants.CTX_IMPORTED_LIBRARIES].([]*types.Library) + importedLibraries := ctx.ImportedLibraries sort.Sort(ByLibraryName(importedLibraries)) require.Equal(t, 1, len(importedLibraries)) require.Equal(t, "USBHost", importedLibraries[0].Name) require.Equal(t, Abs(t, filepath.Join("libraries", "USBHost", "src")), importedLibraries[0].SrcFolder) - libraryResolutionResults := context[constants.CTX_LIBRARY_RESOLUTION_RESULTS].(map[string]types.LibraryResolutionResult) + libraryResolutionResults := ctx.LibrariesResolutionResults require.NotNil(t, libraryResolutionResults) require.False(t, libraryResolutionResults["Usb.h"].IsLibraryFromPlatform) } diff --git a/src/arduino.cc/builder/test/unused_compiled_libraries_remover_test.go b/src/arduino.cc/builder/test/unused_compiled_libraries_remover_test.go index 8e51391f..68feb838 100644 --- a/src/arduino.cc/builder/test/unused_compiled_libraries_remover_test.go +++ b/src/arduino.cc/builder/test/unused_compiled_libraries_remover_test.go @@ -31,7 +31,6 @@ package test import ( "arduino.cc/builder" - "arduino.cc/builder/constants" "arduino.cc/builder/types" "github.com/stretchr/testify/require" "io/ioutil" @@ -52,7 +51,7 @@ func TestUnusedCompiledLibrariesRemover(t *testing.T) { context := make(map[string]interface{}) ctx := &types.Context{} ctx.LibrariesBuildPath = temp - context[constants.CTX_IMPORTED_LIBRARIES] = []*types.Library{&types.Library{Name: "Bridge"}} + ctx.ImportedLibraries = []*types.Library{&types.Library{Name: "Bridge"}} cmd := builder.UnusedCompiledLibrariesRemover{} err = cmd.Run(context, ctx) @@ -71,7 +70,7 @@ func TestUnusedCompiledLibrariesRemoverLibDoesNotExist(t *testing.T) { context := make(map[string]interface{}) ctx := &types.Context{} ctx.LibrariesBuildPath = filepath.Join(os.TempDir(), "test") - context[constants.CTX_IMPORTED_LIBRARIES] = []*types.Library{&types.Library{Name: "Bridge"}} + ctx.ImportedLibraries = []*types.Library{&types.Library{Name: "Bridge"}} cmd := builder.UnusedCompiledLibrariesRemover{} err := cmd.Run(context, ctx) @@ -90,7 +89,7 @@ func TestUnusedCompiledLibrariesRemoverNoUsedLibraries(t *testing.T) { context := make(map[string]interface{}) ctx := &types.Context{} ctx.LibrariesBuildPath = temp - context[constants.CTX_IMPORTED_LIBRARIES] = []*types.Library{} + ctx.ImportedLibraries = []*types.Library{} cmd := builder.UnusedCompiledLibrariesRemover{} err = cmd.Run(context, ctx) diff --git a/src/arduino.cc/builder/types/context.go b/src/arduino.cc/builder/types/context.go index 2ef3a238..e0f5d0d6 100644 --- a/src/arduino.cc/builder/types/context.go +++ b/src/arduino.cc/builder/types/context.go @@ -26,12 +26,17 @@ type Context struct { LibrariesBuildPath string PreprocPath string + CollectedSourceFiles *UniqueStringQueue + FoldersWithSourceFiles *UniqueSourceFolderQueue + WarningsLevel string // Libraries handling - Includes []string - Libraries []*Library - HeaderToLibraries map[string][]*Library + Includes []string + Libraries []*Library + HeaderToLibraries map[string][]*Library + ImportedLibraries []*Library + LibrariesResolutionResults map[string]LibraryResolutionResult // C++ Parsing CTagsOutput string diff --git a/src/arduino.cc/builder/unused_compiled_libraries_remover.go b/src/arduino.cc/builder/unused_compiled_libraries_remover.go index c830c96d..bbd3b5d9 100644 --- a/src/arduino.cc/builder/unused_compiled_libraries_remover.go +++ b/src/arduino.cc/builder/unused_compiled_libraries_remover.go @@ -30,7 +30,6 @@ package builder import ( - "arduino.cc/builder/constants" "arduino.cc/builder/i18n" "arduino.cc/builder/types" "arduino.cc/builder/utils" @@ -43,14 +42,13 @@ type UnusedCompiledLibrariesRemover struct{} func (s *UnusedCompiledLibrariesRemover) Run(context map[string]interface{}, ctx *types.Context) error { librariesBuildPath := ctx.LibrariesBuildPath - libraries := context[constants.CTX_IMPORTED_LIBRARIES].([]*types.Library) _, err := os.Stat(librariesBuildPath) if err != nil && os.IsNotExist(err) { return nil } - libraryNames := toLibraryNames(libraries) + libraryNames := toLibraryNames(ctx.ImportedLibraries) files, err := ioutil.ReadDir(librariesBuildPath) if err != nil { diff --git a/src/arduino.cc/builder/warn_about_arch_incompatible_libraries.go b/src/arduino.cc/builder/warn_about_arch_incompatible_libraries.go index 902c995a..38500db7 100644 --- a/src/arduino.cc/builder/warn_about_arch_incompatible_libraries.go +++ b/src/arduino.cc/builder/warn_about_arch_incompatible_libraries.go @@ -58,8 +58,7 @@ func (s *WarnAboutArchIncompatibleLibraries) Run(context map[string]interface{}, } } - importedLibraries := context[constants.CTX_IMPORTED_LIBRARIES].([]*types.Library) - for _, importedLibrary := range importedLibraries { + for _, importedLibrary := range ctx.ImportedLibraries { if !importedLibrary.SupportsArchitectures(archs) { logger.Fprintln(os.Stdout, constants.LOG_LEVEL_WARN, constants.MSG_LIBRARY_INCOMPATIBLE_ARCH, importedLibrary.Name, importedLibrary.Archs, archs) } From 57203ac986ee94ae50d9675c453b198a24c87672 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Thu, 14 Apr 2016 19:09:38 +0200 Subject: [PATCH 13/25] Moved Target* fields in Context Signed-off-by: Cristian Maglie --- ...operties_from_parent_platform_txt_files.go | 2 +- src/arduino.cc/builder/constants/constants.go | 4 --- .../builder/includes_to_include_folders.go | 4 +-- src/arduino.cc/builder/libraries_loader.go | 4 +-- .../builder/setup_build_properties.go | 6 ++-- .../builder/target_board_resolver.go | 8 ++--- ...dd_build_board_property_if_missing_test.go | 12 +++---- .../test/target_board_resolver_test.go | 36 +++++++++---------- src/arduino.cc/builder/types/context.go | 5 +++ .../warn_about_arch_incompatible_libraries.go | 2 +- .../builder/warn_about_platform_rewrites.go | 4 +-- 11 files changed, 44 insertions(+), 43 deletions(-) diff --git a/src/arduino.cc/builder/add_missing_build_properties_from_parent_platform_txt_files.go b/src/arduino.cc/builder/add_missing_build_properties_from_parent_platform_txt_files.go index ec531049..501b0d23 100644 --- a/src/arduino.cc/builder/add_missing_build_properties_from_parent_platform_txt_files.go +++ b/src/arduino.cc/builder/add_missing_build_properties_from_parent_platform_txt_files.go @@ -39,7 +39,7 @@ type AddMissingBuildPropertiesFromParentPlatformTxtFiles struct{} func (s *AddMissingBuildPropertiesFromParentPlatformTxtFiles) Run(context map[string]interface{}, ctx *types.Context) error { packages := context[constants.CTX_HARDWARE].(*types.Packages) - targetPackage := context[constants.CTX_TARGET_PACKAGE].(*types.Package) + targetPackage := ctx.TargetPackage buildProperties := context[constants.CTX_BUILD_PROPERTIES].(props.PropertiesMap) newBuildProperties := packages.Properties.Clone() diff --git a/src/arduino.cc/builder/constants/constants.go b/src/arduino.cc/builder/constants/constants.go index d5ce1df6..e213d1b4 100644 --- a/src/arduino.cc/builder/constants/constants.go +++ b/src/arduino.cc/builder/constants/constants.go @@ -74,7 +74,6 @@ const BUILD_PROPERTIES_TOOLS_KEY = "tools" const BUILD_PROPERTIES_VID = "vid" const COAN = "coan" const CTAGS = "ctags" -const CTX_ACTUAL_PLATFORM = "actualPlatform" const CTX_ARCHIVE_FILE_PATH_CORE = "archiveFileCore" const CTX_BUILD_CORE = "buildCore" const CTX_BUILD_PROPERTIES = "buildProperties" @@ -93,9 +92,6 @@ const CTX_OBJECT_FILES_SKETCH = "objectFilesSketch" const CTX_PLATFORM_KEYS_REWRITE = "platformKeysRewrite" const CTX_SKETCH = "sketch" const CTX_SOURCE = "source" -const CTX_TARGET_BOARD = "targetBoard" -const CTX_TARGET_PACKAGE = "targetPackage" -const CTX_TARGET_PLATFORM = "targetPlatform" const CTX_TOOLS = "tools" const CTX_VIDPID = "VIDPID" const EMPTY_STRING = "" diff --git a/src/arduino.cc/builder/includes_to_include_folders.go b/src/arduino.cc/builder/includes_to_include_folders.go index 7f293137..b80ebd90 100644 --- a/src/arduino.cc/builder/includes_to_include_folders.go +++ b/src/arduino.cc/builder/includes_to_include_folders.go @@ -45,8 +45,8 @@ func (s *IncludesToIncludeFolders) Run(context map[string]interface{}, ctx *type includes := ctx.Includes headerToLibraries := ctx.HeaderToLibraries - platform := context[constants.CTX_TARGET_PLATFORM].(*types.Platform) - actualPlatform := context[constants.CTX_ACTUAL_PLATFORM].(*types.Platform) + platform := ctx.TargetPlatform + actualPlatform := ctx.ActualPlatform libraryResolutionResults := ctx.LibrariesResolutionResults importedLibraries := ctx.ImportedLibraries diff --git a/src/arduino.cc/builder/libraries_loader.go b/src/arduino.cc/builder/libraries_loader.go index 1e6c7bad..32291923 100644 --- a/src/arduino.cc/builder/libraries_loader.go +++ b/src/arduino.cc/builder/libraries_loader.go @@ -51,11 +51,11 @@ func (s *LibrariesLoader) Run(context map[string]interface{}, ctx *types.Context sortedLibrariesFolders := []string{} sortedLibrariesFolders = utils.AppendIfNotPresent(sortedLibrariesFolders, builtInLibrariesFolders...) - platform := context[constants.CTX_TARGET_PLATFORM].(*types.Platform) + platform := ctx.TargetPlatform debugLevel := ctx.DebugLevel logger := ctx.GetLogger() - actualPlatform := context[constants.CTX_ACTUAL_PLATFORM].(*types.Platform) + actualPlatform := ctx.ActualPlatform if actualPlatform != platform { sortedLibrariesFolders = appendPathToLibrariesFolders(sortedLibrariesFolders, filepath.Join(actualPlatform.Folder, constants.FOLDER_LIBRARIES)) } diff --git a/src/arduino.cc/builder/setup_build_properties.go b/src/arduino.cc/builder/setup_build_properties.go index e026decd..7ceba057 100644 --- a/src/arduino.cc/builder/setup_build_properties.go +++ b/src/arduino.cc/builder/setup_build_properties.go @@ -45,9 +45,9 @@ type SetupBuildProperties struct{} func (s *SetupBuildProperties) Run(context map[string]interface{}, ctx *types.Context) error { packages := context[constants.CTX_HARDWARE].(*types.Packages) - targetPlatform := context[constants.CTX_TARGET_PLATFORM].(*types.Platform) - actualPlatform := context[constants.CTX_ACTUAL_PLATFORM].(*types.Platform) - targetBoard := context[constants.CTX_TARGET_BOARD].(*types.Board) + targetPlatform := ctx.TargetPlatform + actualPlatform := ctx.ActualPlatform + targetBoard := ctx.TargetBoard buildProperties := make(props.PropertiesMap) buildProperties.Merge(actualPlatform.Properties) diff --git a/src/arduino.cc/builder/target_board_resolver.go b/src/arduino.cc/builder/target_board_resolver.go index ee93b46d..1a730b9b 100644 --- a/src/arduino.cc/builder/target_board_resolver.go +++ b/src/arduino.cc/builder/target_board_resolver.go @@ -66,9 +66,9 @@ func (s *TargetBoardResolver) Run(context map[string]interface{}, ctx *types.Con return i18n.ErrorfWithLogger(logger, constants.MSG_BOARD_UNKNOWN, targetBoardName, targetPlatformName, targetPackageName) } - context[constants.CTX_TARGET_PACKAGE] = targetPackage - context[constants.CTX_TARGET_PLATFORM] = targetPlatform - context[constants.CTX_TARGET_BOARD] = targetBoard + ctx.TargetPackage = targetPackage + ctx.TargetPlatform = targetPlatform + ctx.TargetBoard = targetBoard if len(fqbnParts) > 3 { addAdditionalPropertiesToTargetBoard(targetBoard, fqbnParts[3]) @@ -98,7 +98,7 @@ func (s *TargetBoardResolver) Run(context map[string]interface{}, ctx *types.Con } context[constants.CTX_BUILD_CORE] = core - context[constants.CTX_ACTUAL_PLATFORM] = actualPlatform + ctx.ActualPlatform = actualPlatform return nil } diff --git a/src/arduino.cc/builder/test/add_build_board_property_if_missing_test.go b/src/arduino.cc/builder/test/add_build_board_property_if_missing_test.go index 15d72e47..8aa03e63 100644 --- a/src/arduino.cc/builder/test/add_build_board_property_if_missing_test.go +++ b/src/arduino.cc/builder/test/add_build_board_property_if_missing_test.go @@ -56,11 +56,11 @@ func TestAddBuildBoardPropertyIfMissing(t *testing.T) { NoError(t, err) } - targetPackage := context[constants.CTX_TARGET_PACKAGE].(*types.Package) + targetPackage := ctx.TargetPackage require.Equal(t, "my_avr_platform", targetPackage.PackageId) - targetPlatform := context[constants.CTX_TARGET_PLATFORM].(*types.Platform) + targetPlatform := ctx.TargetPlatform require.Equal(t, "avr", targetPlatform.PlatformId) - targetBoard := context[constants.CTX_TARGET_BOARD].(*types.Board) + targetBoard := ctx.TargetBoard require.Equal(t, "mymega", targetBoard.BoardId) require.Equal(t, constants.EMPTY_STRING, targetBoard.Properties[constants.BUILD_PROPERTIES_BUILD_MCU]) require.Equal(t, "AVR_MYMEGA", targetBoard.Properties[constants.BUILD_PROPERTIES_BUILD_BOARD]) @@ -84,11 +84,11 @@ func TestAddBuildBoardPropertyIfMissingNotMissing(t *testing.T) { NoError(t, err) } - targetPackage := context[constants.CTX_TARGET_PACKAGE].(*types.Package) + targetPackage := ctx.TargetPackage require.Equal(t, "my_avr_platform", targetPackage.PackageId) - targetPlatform := context[constants.CTX_TARGET_PLATFORM].(*types.Platform) + targetPlatform := ctx.TargetPlatform require.Equal(t, "avr", targetPlatform.PlatformId) - targetBoard := context[constants.CTX_TARGET_BOARD].(*types.Board) + targetBoard := ctx.TargetBoard require.Equal(t, "mymega", targetBoard.BoardId) require.Equal(t, "atmega2560", targetBoard.Properties[constants.BUILD_PROPERTIES_BUILD_MCU]) require.Equal(t, "AVR_MEGA2560", targetBoard.Properties[constants.BUILD_PROPERTIES_BUILD_BOARD]) diff --git a/src/arduino.cc/builder/test/target_board_resolver_test.go b/src/arduino.cc/builder/test/target_board_resolver_test.go index fd39c08a..9d7b55ae 100644 --- a/src/arduino.cc/builder/test/target_board_resolver_test.go +++ b/src/arduino.cc/builder/test/target_board_resolver_test.go @@ -55,11 +55,11 @@ func TestTargetBoardResolverUno(t *testing.T) { NoError(t, err) } - targetPackage := context[constants.CTX_TARGET_PACKAGE].(*types.Package) + targetPackage := ctx.TargetPackage require.Equal(t, "arduino", targetPackage.PackageId) - targetPlatform := context[constants.CTX_TARGET_PLATFORM].(*types.Platform) + targetPlatform := ctx.TargetPlatform require.Equal(t, "avr", targetPlatform.PlatformId) - targetBoard := context[constants.CTX_TARGET_BOARD].(*types.Board) + targetBoard := ctx.TargetBoard require.Equal(t, "uno", targetBoard.BoardId) require.Equal(t, "atmega328p", targetBoard.Properties[constants.BUILD_PROPERTIES_BUILD_MCU]) } @@ -81,11 +81,11 @@ func TestTargetBoardResolverDue(t *testing.T) { NoError(t, err) } - targetPackage := context[constants.CTX_TARGET_PACKAGE].(*types.Package) + targetPackage := ctx.TargetPackage require.Equal(t, "arduino", targetPackage.PackageId) - targetPlatform := context[constants.CTX_TARGET_PLATFORM].(*types.Platform) + targetPlatform := ctx.TargetPlatform require.Equal(t, "sam", targetPlatform.PlatformId) - targetBoard := context[constants.CTX_TARGET_BOARD].(*types.Board) + targetBoard := ctx.TargetBoard require.Equal(t, "arduino_due_x", targetBoard.BoardId) require.Equal(t, "cortex-m3", targetBoard.Properties[constants.BUILD_PROPERTIES_BUILD_MCU]) } @@ -107,11 +107,11 @@ func TestTargetBoardResolverMega1280(t *testing.T) { NoError(t, err) } - targetPackage := context[constants.CTX_TARGET_PACKAGE].(*types.Package) + targetPackage := ctx.TargetPackage require.Equal(t, "arduino", targetPackage.PackageId) - targetPlatform := context[constants.CTX_TARGET_PLATFORM].(*types.Platform) + targetPlatform := ctx.TargetPlatform require.Equal(t, "avr", targetPlatform.PlatformId) - targetBoard := context[constants.CTX_TARGET_BOARD].(*types.Board) + targetBoard := ctx.TargetBoard require.Equal(t, "mega", targetBoard.BoardId) require.Equal(t, "atmega1280", targetBoard.Properties[constants.BUILD_PROPERTIES_BUILD_MCU]) require.Equal(t, "AVR_MEGA", targetBoard.Properties[constants.BUILD_PROPERTIES_BUILD_BOARD]) @@ -134,11 +134,11 @@ func TestTargetBoardResolverMega2560(t *testing.T) { NoError(t, err) } - targetPackage := context[constants.CTX_TARGET_PACKAGE].(*types.Package) + targetPackage := ctx.TargetPackage require.Equal(t, "arduino", targetPackage.PackageId) - targetPlatform := context[constants.CTX_TARGET_PLATFORM].(*types.Platform) + targetPlatform := ctx.TargetPlatform require.Equal(t, "avr", targetPlatform.PlatformId) - targetBoard := context[constants.CTX_TARGET_BOARD].(*types.Board) + targetBoard := ctx.TargetBoard require.Equal(t, "mega", targetBoard.BoardId) require.Equal(t, "atmega2560", targetBoard.Properties[constants.BUILD_PROPERTIES_BUILD_MCU]) require.Equal(t, "AVR_MEGA2560", targetBoard.Properties[constants.BUILD_PROPERTIES_BUILD_BOARD]) @@ -161,11 +161,11 @@ func TestTargetBoardResolverCustomYun(t *testing.T) { NoError(t, err) } - targetPackage := context[constants.CTX_TARGET_PACKAGE].(*types.Package) + targetPackage := ctx.TargetPackage require.Equal(t, "my_avr_platform", targetPackage.PackageId) - targetPlatform := context[constants.CTX_TARGET_PLATFORM].(*types.Platform) + targetPlatform := ctx.TargetPlatform require.Equal(t, "avr", targetPlatform.PlatformId) - targetBoard := context[constants.CTX_TARGET_BOARD].(*types.Board) + targetBoard := ctx.TargetBoard require.Equal(t, "custom_yun", targetBoard.BoardId) require.Equal(t, "atmega32u4", targetBoard.Properties[constants.BUILD_PROPERTIES_BUILD_MCU]) require.Equal(t, "AVR_YUN", targetBoard.Properties[constants.BUILD_PROPERTIES_BUILD_BOARD]) @@ -188,11 +188,11 @@ func TestTargetBoardResolverCustomCore(t *testing.T) { NoError(t, err) } - targetPackage := context[constants.CTX_TARGET_PACKAGE].(*types.Package) + targetPackage := ctx.TargetPackage require.Equal(t, "watterott", targetPackage.PackageId) - targetPlatform := context[constants.CTX_TARGET_PLATFORM].(*types.Platform) + targetPlatform := ctx.TargetPlatform require.Equal(t, "avr", targetPlatform.PlatformId) - targetBoard := context[constants.CTX_TARGET_BOARD].(*types.Board) + targetBoard := ctx.TargetBoard require.Equal(t, "attiny841", targetBoard.BoardId) require.Equal(t, "tiny841", context[constants.CTX_BUILD_CORE].(string)) require.Equal(t, "tiny14", targetBoard.Properties[constants.BUILD_PROPERTIES_BUILD_VARIANT]) diff --git a/src/arduino.cc/builder/types/context.go b/src/arduino.cc/builder/types/context.go index e0f5d0d6..9b990d10 100644 --- a/src/arduino.cc/builder/types/context.go +++ b/src/arduino.cc/builder/types/context.go @@ -20,6 +20,11 @@ type Context struct { BuildOptionsJson string BuildOptionsJsonPrevious string + TargetBoard *Board + TargetPackage *Package + TargetPlatform *Platform + ActualPlatform *Platform + BuildPath string SketchBuildPath string CoreBuildPath string diff --git a/src/arduino.cc/builder/warn_about_arch_incompatible_libraries.go b/src/arduino.cc/builder/warn_about_arch_incompatible_libraries.go index 38500db7..afb67889 100644 --- a/src/arduino.cc/builder/warn_about_arch_incompatible_libraries.go +++ b/src/arduino.cc/builder/warn_about_arch_incompatible_libraries.go @@ -44,7 +44,7 @@ func (s *WarnAboutArchIncompatibleLibraries) Run(context map[string]interface{}, return nil } - targetPlatform := context[constants.CTX_TARGET_PLATFORM].(*types.Platform) + targetPlatform := ctx.TargetPlatform buildProperties := context[constants.CTX_BUILD_PROPERTIES].(props.PropertiesMap) logger := ctx.GetLogger() diff --git a/src/arduino.cc/builder/warn_about_platform_rewrites.go b/src/arduino.cc/builder/warn_about_platform_rewrites.go index a4085602..74ff67b1 100644 --- a/src/arduino.cc/builder/warn_about_platform_rewrites.go +++ b/src/arduino.cc/builder/warn_about_platform_rewrites.go @@ -44,8 +44,8 @@ func (s *WarnAboutPlatformRewrites) Run(context map[string]interface{}, ctx *typ logger := ctx.GetLogger() hardwareRewriteResults := context[constants.CTX_HARDWARE_REWRITE_RESULTS].(map[*types.Platform][]types.PlatforKeyRewrite) - targetPlatform := context[constants.CTX_TARGET_PLATFORM].(*types.Platform) - actualPlatform := context[constants.CTX_ACTUAL_PLATFORM].(*types.Platform) + targetPlatform := ctx.TargetPlatform + actualPlatform := ctx.ActualPlatform platforms := []*types.Platform{targetPlatform} if actualPlatform != targetPlatform { From 310f2e22b0c96c073adf1b6c1b287db8cef29d96 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Fri, 15 Apr 2016 15:37:45 +0200 Subject: [PATCH 14/25] BuildProperties are now part of Context Signed-off-by: Cristian Maglie --- ...ng_build_properties_from_parent_platform_txt_files.go | 5 ++--- src/arduino.cc/builder/coan_runner.go | 3 +-- src/arduino.cc/builder/constants/constants.go | 1 - src/arduino.cc/builder/ctags/ctags_runner.go | 3 +-- src/arduino.cc/builder/dump_build_properties.go | 4 +--- src/arduino.cc/builder/gcc_preproc_runner.go | 6 +----- src/arduino.cc/builder/includes_finder_with_gcc.go | 6 +----- src/arduino.cc/builder/includes_to_include_folders.go | 2 +- .../builder/load_vid_pid_specific_properties.go | 2 +- src/arduino.cc/builder/merge_sketch_with_bootloader.go | 3 +-- src/arduino.cc/builder/phases/core_builder.go | 2 +- src/arduino.cc/builder/phases/libraries_builder.go | 2 +- src/arduino.cc/builder/phases/linker.go | 2 +- src/arduino.cc/builder/phases/sketch_builder.go | 3 +-- src/arduino.cc/builder/recipe_runner.go | 6 +----- src/arduino.cc/builder/set_custom_build_properties.go | 3 +-- src/arduino.cc/builder/setup_build_properties.go | 2 +- .../test/load_vid_pid_specific_properties_test.go | 5 ++--- .../builder/test/merge_sketch_with_bootloader_test.go | 3 +-- src/arduino.cc/builder/test/recipe_runner_test.go | 2 +- .../builder/test/setup_build_properties_test.go | 9 ++++----- src/arduino.cc/builder/types/context.go | 1 + .../builder/warn_about_arch_incompatible_libraries.go | 3 +-- 23 files changed, 27 insertions(+), 51 deletions(-) diff --git a/src/arduino.cc/builder/add_missing_build_properties_from_parent_platform_txt_files.go b/src/arduino.cc/builder/add_missing_build_properties_from_parent_platform_txt_files.go index 501b0d23..8fbf130e 100644 --- a/src/arduino.cc/builder/add_missing_build_properties_from_parent_platform_txt_files.go +++ b/src/arduino.cc/builder/add_missing_build_properties_from_parent_platform_txt_files.go @@ -31,7 +31,6 @@ package builder import ( "arduino.cc/builder/constants" - "arduino.cc/builder/props" "arduino.cc/builder/types" ) @@ -40,13 +39,13 @@ type AddMissingBuildPropertiesFromParentPlatformTxtFiles struct{} func (s *AddMissingBuildPropertiesFromParentPlatformTxtFiles) Run(context map[string]interface{}, ctx *types.Context) error { packages := context[constants.CTX_HARDWARE].(*types.Packages) targetPackage := ctx.TargetPackage - buildProperties := context[constants.CTX_BUILD_PROPERTIES].(props.PropertiesMap) + buildProperties := ctx.BuildProperties newBuildProperties := packages.Properties.Clone() newBuildProperties.Merge(targetPackage.Properties) newBuildProperties.Merge(buildProperties) - context[constants.CTX_BUILD_PROPERTIES] = newBuildProperties + ctx.BuildProperties = newBuildProperties return nil } diff --git a/src/arduino.cc/builder/coan_runner.go b/src/arduino.cc/builder/coan_runner.go index 037f64be..d03da589 100644 --- a/src/arduino.cc/builder/coan_runner.go +++ b/src/arduino.cc/builder/coan_runner.go @@ -32,7 +32,6 @@ package builder import ( "arduino.cc/builder/constants" "arduino.cc/builder/i18n" - "arduino.cc/builder/props" "arduino.cc/builder/types" "arduino.cc/builder/utils" "fmt" @@ -61,7 +60,7 @@ func (s *CoanRunner) Run(context map[string]interface{}, ctx *types.Context) err return i18n.WrapError(err) } - buildProperties := context[constants.CTX_BUILD_PROPERTIES].(props.PropertiesMap) + buildProperties := ctx.BuildProperties properties := buildProperties.Clone() properties.Merge(buildProperties.SubTree(constants.BUILD_PROPERTIES_TOOLS_KEY).SubTree(constants.COAN)) properties[constants.BUILD_PROPERTIES_SOURCE_FILE] = coanTargetFileName diff --git a/src/arduino.cc/builder/constants/constants.go b/src/arduino.cc/builder/constants/constants.go index e213d1b4..b672ed9d 100644 --- a/src/arduino.cc/builder/constants/constants.go +++ b/src/arduino.cc/builder/constants/constants.go @@ -76,7 +76,6 @@ const COAN = "coan" const CTAGS = "ctags" const CTX_ARCHIVE_FILE_PATH_CORE = "archiveFileCore" const CTX_BUILD_CORE = "buildCore" -const CTX_BUILD_PROPERTIES = "buildProperties" const CTX_FILE_PATH_TO_READ = "filePathToRead" const CTX_GCC_MINUS_E_SOURCE = "gccMinusESource" const CTX_GCC_MINUS_M_OUTPUT = "gccMinusMOutput" diff --git a/src/arduino.cc/builder/ctags/ctags_runner.go b/src/arduino.cc/builder/ctags/ctags_runner.go index 81301a85..8c9a6178 100644 --- a/src/arduino.cc/builder/ctags/ctags_runner.go +++ b/src/arduino.cc/builder/ctags/ctags_runner.go @@ -32,7 +32,6 @@ package ctags import ( "arduino.cc/builder/constants" "arduino.cc/builder/i18n" - "arduino.cc/builder/props" "arduino.cc/builder/types" "arduino.cc/builder/utils" "fmt" @@ -41,7 +40,7 @@ import ( type CTagsRunner struct{} func (s *CTagsRunner) Run(context map[string]interface{}, ctx *types.Context) error { - buildProperties := context[constants.CTX_BUILD_PROPERTIES].(props.PropertiesMap) + buildProperties := ctx.BuildProperties ctagsTargetFilePath := ctx.CTagsTargetFile logger := ctx.GetLogger() diff --git a/src/arduino.cc/builder/dump_build_properties.go b/src/arduino.cc/builder/dump_build_properties.go index b48d05ba..06dedc99 100644 --- a/src/arduino.cc/builder/dump_build_properties.go +++ b/src/arduino.cc/builder/dump_build_properties.go @@ -30,8 +30,6 @@ package builder import ( - "arduino.cc/builder/constants" - "arduino.cc/builder/props" "arduino.cc/builder/types" "arduino.cc/builder/utils" "fmt" @@ -41,7 +39,7 @@ import ( type DumpBuildProperties struct{} func (s *DumpBuildProperties) Run(context map[string]interface{}, ctx *types.Context) error { - buildProperties := context[constants.CTX_BUILD_PROPERTIES].(props.PropertiesMap) + buildProperties := ctx.BuildProperties keys := utils.KeysOfMapOfString(buildProperties) sort.Strings(keys) diff --git a/src/arduino.cc/builder/gcc_preproc_runner.go b/src/arduino.cc/builder/gcc_preproc_runner.go index 69d7b5c9..f8167cd7 100644 --- a/src/arduino.cc/builder/gcc_preproc_runner.go +++ b/src/arduino.cc/builder/gcc_preproc_runner.go @@ -108,11 +108,7 @@ func prepareGCCPreprocRecipeProperties(context map[string]interface{}, ctx *type targetFilePath = filepath.Join(preprocPath, targetFilePath) } - properties := make(props.PropertiesMap) - if p, ok := context[constants.CTX_BUILD_PROPERTIES]; ok { - properties = p.(props.PropertiesMap).Clone() - } - + properties := ctx.BuildProperties properties[constants.BUILD_PROPERTIES_SOURCE_FILE] = sourceFilePath properties[constants.BUILD_PROPERTIES_PREPROCESSED_FILE_PATH] = targetFilePath diff --git a/src/arduino.cc/builder/includes_finder_with_gcc.go b/src/arduino.cc/builder/includes_finder_with_gcc.go index 0a02423e..f8bfd7a8 100644 --- a/src/arduino.cc/builder/includes_finder_with_gcc.go +++ b/src/arduino.cc/builder/includes_finder_with_gcc.go @@ -33,7 +33,6 @@ import ( "arduino.cc/builder/builder_utils" "arduino.cc/builder/constants" "arduino.cc/builder/i18n" - "arduino.cc/builder/props" "arduino.cc/builder/types" "arduino.cc/builder/utils" "strings" @@ -44,10 +43,7 @@ type IncludesFinderWithGCC struct { } func (s *IncludesFinderWithGCC) Run(context map[string]interface{}, ctx *types.Context) error { - buildProperties := make(props.PropertiesMap) - if p, ok := context[constants.CTX_BUILD_PROPERTIES]; ok { - buildProperties = p.(props.PropertiesMap).Clone() - } + buildProperties := ctx.BuildProperties verbose := ctx.Verbose logger := ctx.GetLogger() diff --git a/src/arduino.cc/builder/includes_to_include_folders.go b/src/arduino.cc/builder/includes_to_include_folders.go index b80ebd90..344fb357 100644 --- a/src/arduino.cc/builder/includes_to_include_folders.go +++ b/src/arduino.cc/builder/includes_to_include_folders.go @@ -69,7 +69,7 @@ func (s *IncludesToIncludeFolders) Run(context map[string]interface{}, ctx *type ctx.ImportedLibraries = importedLibraries - buildProperties := context[constants.CTX_BUILD_PROPERTIES].(props.PropertiesMap) + buildProperties := ctx.BuildProperties verbose := ctx.Verbose includeFolders := resolveIncludeFolders(newlyImportedLibraries, buildProperties, verbose) context[constants.CTX_INCLUDE_FOLDERS] = includeFolders diff --git a/src/arduino.cc/builder/load_vid_pid_specific_properties.go b/src/arduino.cc/builder/load_vid_pid_specific_properties.go index 32fb336b..1cb13ee1 100644 --- a/src/arduino.cc/builder/load_vid_pid_specific_properties.go +++ b/src/arduino.cc/builder/load_vid_pid_specific_properties.go @@ -52,7 +52,7 @@ func (s *LoadVIDPIDSpecificProperties) Run(context map[string]interface{}, ctx * vid := vidPidParts[0] pid := vidPidParts[1] - buildProperties := context[constants.CTX_BUILD_PROPERTIES].(props.PropertiesMap) + buildProperties := ctx.BuildProperties VIDPIDIndex, err := findVIDPIDIndex(buildProperties, vid, pid) if err != nil { return i18n.WrapError(err) diff --git a/src/arduino.cc/builder/merge_sketch_with_bootloader.go b/src/arduino.cc/builder/merge_sketch_with_bootloader.go index dbd711e5..e4266e25 100644 --- a/src/arduino.cc/builder/merge_sketch_with_bootloader.go +++ b/src/arduino.cc/builder/merge_sketch_with_bootloader.go @@ -32,7 +32,6 @@ package builder import ( "arduino.cc/builder/constants" "arduino.cc/builder/i18n" - "arduino.cc/builder/props" "arduino.cc/builder/types" "arduino.cc/builder/utils" "os" @@ -43,7 +42,7 @@ import ( type MergeSketchWithBootloader struct{} func (s *MergeSketchWithBootloader) Run(context map[string]interface{}, ctx *types.Context) error { - buildProperties := context[constants.CTX_BUILD_PROPERTIES].(props.PropertiesMap) + buildProperties := ctx.BuildProperties if !utils.MapStringStringHas(buildProperties, constants.BUILD_PROPERTIES_BOOTLOADER_NOBLINK) && !utils.MapStringStringHas(buildProperties, constants.BUILD_PROPERTIES_BOOTLOADER_FILE) { return nil } diff --git a/src/arduino.cc/builder/phases/core_builder.go b/src/arduino.cc/builder/phases/core_builder.go index 4324ff37..df62ff05 100644 --- a/src/arduino.cc/builder/phases/core_builder.go +++ b/src/arduino.cc/builder/phases/core_builder.go @@ -42,7 +42,7 @@ type CoreBuilder struct{} func (s *CoreBuilder) Run(context map[string]interface{}, ctx *types.Context) error { coreBuildPath := ctx.CoreBuildPath - buildProperties := context[constants.CTX_BUILD_PROPERTIES].(props.PropertiesMap) + buildProperties := ctx.BuildProperties verbose := ctx.Verbose warningsLevel := ctx.WarningsLevel logger := ctx.GetLogger() diff --git a/src/arduino.cc/builder/phases/libraries_builder.go b/src/arduino.cc/builder/phases/libraries_builder.go index ea2ce968..da9b7361 100644 --- a/src/arduino.cc/builder/phases/libraries_builder.go +++ b/src/arduino.cc/builder/phases/libraries_builder.go @@ -44,7 +44,7 @@ type LibrariesBuilder struct{} func (s *LibrariesBuilder) Run(context map[string]interface{}, ctx *types.Context) error { librariesBuildPath := ctx.LibrariesBuildPath - buildProperties := context[constants.CTX_BUILD_PROPERTIES].(props.PropertiesMap) + buildProperties := ctx.BuildProperties includes := context[constants.CTX_INCLUDE_FOLDERS].([]string) includes = utils.Map(includes, utils.WrapWithHyphenI) libraries := ctx.ImportedLibraries diff --git a/src/arduino.cc/builder/phases/linker.go b/src/arduino.cc/builder/phases/linker.go index c2724f82..651ea2d3 100644 --- a/src/arduino.cc/builder/phases/linker.go +++ b/src/arduino.cc/builder/phases/linker.go @@ -59,7 +59,7 @@ func (s *Linker) Run(context map[string]interface{}, ctx *types.Context) error { return i18n.WrapError(err) } - buildProperties := context[constants.CTX_BUILD_PROPERTIES].(props.PropertiesMap) + buildProperties := ctx.BuildProperties verbose := ctx.Verbose warningsLevel := ctx.WarningsLevel logger := ctx.GetLogger() diff --git a/src/arduino.cc/builder/phases/sketch_builder.go b/src/arduino.cc/builder/phases/sketch_builder.go index df7019e5..d0f086cf 100644 --- a/src/arduino.cc/builder/phases/sketch_builder.go +++ b/src/arduino.cc/builder/phases/sketch_builder.go @@ -33,7 +33,6 @@ import ( "arduino.cc/builder/builder_utils" "arduino.cc/builder/constants" "arduino.cc/builder/i18n" - "arduino.cc/builder/props" "arduino.cc/builder/types" "arduino.cc/builder/utils" ) @@ -42,7 +41,7 @@ type SketchBuilder struct{} func (s *SketchBuilder) Run(context map[string]interface{}, ctx *types.Context) error { sketchBuildPath := ctx.SketchBuildPath - buildProperties := context[constants.CTX_BUILD_PROPERTIES].(props.PropertiesMap) + buildProperties := ctx.BuildProperties includes := context[constants.CTX_INCLUDE_FOLDERS].([]string) includes = utils.Map(includes, utils.WrapWithHyphenI) verbose := ctx.Verbose diff --git a/src/arduino.cc/builder/recipe_runner.go b/src/arduino.cc/builder/recipe_runner.go index 01fb23a8..34b91727 100644 --- a/src/arduino.cc/builder/recipe_runner.go +++ b/src/arduino.cc/builder/recipe_runner.go @@ -33,7 +33,6 @@ import ( "arduino.cc/builder/builder_utils" "arduino.cc/builder/constants" "arduino.cc/builder/i18n" - "arduino.cc/builder/props" "arduino.cc/builder/types" "os" "sort" @@ -51,10 +50,7 @@ func (s *RecipeByPrefixSuffixRunner) Run(context map[string]interface{}, ctx *ty logger.Fprintln(os.Stdout, constants.LOG_LEVEL_DEBUG, constants.MSG_LOOKING_FOR_RECIPES, s.Prefix, s.Suffix) } - buildProperties := make(props.PropertiesMap) - if p, ok := context[constants.CTX_BUILD_PROPERTIES]; ok { - buildProperties = p.(props.PropertiesMap).Clone() - } + buildProperties := ctx.BuildProperties verbose := ctx.Verbose recipes := findRecipes(buildProperties, s.Prefix, s.Suffix) diff --git a/src/arduino.cc/builder/set_custom_build_properties.go b/src/arduino.cc/builder/set_custom_build_properties.go index fd48cf00..c761a028 100644 --- a/src/arduino.cc/builder/set_custom_build_properties.go +++ b/src/arduino.cc/builder/set_custom_build_properties.go @@ -30,7 +30,6 @@ package builder import ( - "arduino.cc/builder/constants" "arduino.cc/builder/i18n" "arduino.cc/builder/props" "arduino.cc/builder/types" @@ -40,7 +39,7 @@ type SetCustomBuildProperties struct{} func (s *SetCustomBuildProperties) Run(context map[string]interface{}, ctx *types.Context) error { logger := ctx.GetLogger() - buildProperties := context[constants.CTX_BUILD_PROPERTIES].(props.PropertiesMap) + buildProperties := ctx.BuildProperties customBuildProperties, err := props.LoadFromSlice(ctx.CustomBuildProperties, logger) if err != nil { return i18n.WrapError(err) diff --git a/src/arduino.cc/builder/setup_build_properties.go b/src/arduino.cc/builder/setup_build_properties.go index 7ceba057..d05647e7 100644 --- a/src/arduino.cc/builder/setup_build_properties.go +++ b/src/arduino.cc/builder/setup_build_properties.go @@ -111,7 +111,7 @@ func (s *SetupBuildProperties) Run(context map[string]interface{}, ctx *types.Co buildProperties[constants.BUILD_PROPERTIES_EXTRA_TIME_ZONE] = strconv.Itoa(utils.TimezoneOffset()) buildProperties[constants.BUILD_PROPERTIES_EXTRA_TIME_DST] = strconv.Itoa(utils.DaylightSavingsOffset(now)) - context[constants.CTX_BUILD_PROPERTIES] = buildProperties + ctx.BuildProperties = buildProperties return nil } diff --git a/src/arduino.cc/builder/test/load_vid_pid_specific_properties_test.go b/src/arduino.cc/builder/test/load_vid_pid_specific_properties_test.go index 01c519d4..42d9d532 100644 --- a/src/arduino.cc/builder/test/load_vid_pid_specific_properties_test.go +++ b/src/arduino.cc/builder/test/load_vid_pid_specific_properties_test.go @@ -32,7 +32,6 @@ package test import ( "arduino.cc/builder" "arduino.cc/builder/constants" - "arduino.cc/builder/props" "arduino.cc/builder/types" "github.com/stretchr/testify/require" "os" @@ -64,7 +63,7 @@ func TestLoadVIDPIDSpecificPropertiesWhenNoVIDPIDAreProvided(t *testing.T) { NoError(t, err) } - buildProperties := context[constants.CTX_BUILD_PROPERTIES].(props.PropertiesMap) + buildProperties := ctx.BuildProperties require.Equal(t, "0x0037", buildProperties["pid.0"]) require.Equal(t, "\"Genuino Micro\"", buildProperties["vid.4.build.usb_product"]) @@ -97,7 +96,7 @@ func TestLoadVIDPIDSpecificProperties(t *testing.T) { NoError(t, err) } - buildProperties := context[constants.CTX_BUILD_PROPERTIES].(props.PropertiesMap) + buildProperties := ctx.BuildProperties require.Equal(t, "0x0037", buildProperties["pid.0"]) require.Equal(t, "\"Genuino Micro\"", buildProperties["vid.4.build.usb_product"]) diff --git a/src/arduino.cc/builder/test/merge_sketch_with_bootloader_test.go b/src/arduino.cc/builder/test/merge_sketch_with_bootloader_test.go index ddc203fe..f4bbe136 100644 --- a/src/arduino.cc/builder/test/merge_sketch_with_bootloader_test.go +++ b/src/arduino.cc/builder/test/merge_sketch_with_bootloader_test.go @@ -32,7 +32,6 @@ package test import ( "arduino.cc/builder" "arduino.cc/builder/constants" - "arduino.cc/builder/props" "arduino.cc/builder/types" "arduino.cc/builder/utils" "github.com/stretchr/testify/require" @@ -155,7 +154,7 @@ func TestMergeSketchWithBootloaderWhenNoBootloaderAvailable(t *testing.T) { NoError(t, err) } - buildProperties := context[constants.CTX_BUILD_PROPERTIES].(props.PropertiesMap) + buildProperties := ctx.BuildProperties delete(buildProperties, constants.BUILD_PROPERTIES_BOOTLOADER_NOBLINK) delete(buildProperties, constants.BUILD_PROPERTIES_BOOTLOADER_FILE) diff --git a/src/arduino.cc/builder/test/recipe_runner_test.go b/src/arduino.cc/builder/test/recipe_runner_test.go index 33764a6f..61898ca5 100644 --- a/src/arduino.cc/builder/test/recipe_runner_test.go +++ b/src/arduino.cc/builder/test/recipe_runner_test.go @@ -46,7 +46,7 @@ func TestRecipeRunner(t *testing.T) { context := make(map[string]interface{}) ctx := &types.Context{} buildProperties := make(props.PropertiesMap) - context[constants.CTX_BUILD_PROPERTIES] = buildProperties + ctx.BuildProperties = buildProperties buildProperties["recipe.hooks.prebuild.1.pattern"] = "echo" diff --git a/src/arduino.cc/builder/test/setup_build_properties_test.go b/src/arduino.cc/builder/test/setup_build_properties_test.go index 614b82cd..a1cc752f 100644 --- a/src/arduino.cc/builder/test/setup_build_properties_test.go +++ b/src/arduino.cc/builder/test/setup_build_properties_test.go @@ -32,7 +32,6 @@ package test import ( "arduino.cc/builder" "arduino.cc/builder/constants" - "arduino.cc/builder/props" "arduino.cc/builder/types" "arduino.cc/builder/utils" "github.com/stretchr/testify/require" @@ -70,7 +69,7 @@ func TestSetupBuildProperties(t *testing.T) { NoError(t, err) } - buildProperties := context[constants.CTX_BUILD_PROPERTIES].(props.PropertiesMap) + buildProperties := ctx.BuildProperties require.Equal(t, "ARDUINO", buildProperties[constants.BUILD_PROPERTIES_SOFTWARE]) @@ -135,7 +134,7 @@ func TestSetupBuildPropertiesWithSomeCustomOverrides(t *testing.T) { NoError(t, err) } - buildProperties := context[constants.CTX_BUILD_PROPERTIES].(props.PropertiesMap) + buildProperties := ctx.BuildProperties require.Equal(t, "ARDUINO", buildProperties[constants.BUILD_PROPERTIES_SOFTWARE]) @@ -174,7 +173,7 @@ func TestSetupBuildPropertiesUserHardware(t *testing.T) { NoError(t, err) } - buildProperties := context[constants.CTX_BUILD_PROPERTIES].(props.PropertiesMap) + buildProperties := ctx.BuildProperties require.Equal(t, "ARDUINO", buildProperties[constants.BUILD_PROPERTIES_SOFTWARE]) @@ -208,7 +207,7 @@ func TestSetupBuildPropertiesWithMissingPropsFromParentPlatformTxtFiles(t *testi NoError(t, err) } - buildProperties := context[constants.CTX_BUILD_PROPERTIES].(props.PropertiesMap) + buildProperties := ctx.BuildProperties require.Equal(t, "ARDUINO", buildProperties[constants.BUILD_PROPERTIES_SOFTWARE]) diff --git a/src/arduino.cc/builder/types/context.go b/src/arduino.cc/builder/types/context.go index 9b990d10..097c4342 100644 --- a/src/arduino.cc/builder/types/context.go +++ b/src/arduino.cc/builder/types/context.go @@ -25,6 +25,7 @@ type Context struct { TargetPlatform *Platform ActualPlatform *Platform + BuildProperties props.PropertiesMap BuildPath string SketchBuildPath string CoreBuildPath string diff --git a/src/arduino.cc/builder/warn_about_arch_incompatible_libraries.go b/src/arduino.cc/builder/warn_about_arch_incompatible_libraries.go index afb67889..4f7ca7db 100644 --- a/src/arduino.cc/builder/warn_about_arch_incompatible_libraries.go +++ b/src/arduino.cc/builder/warn_about_arch_incompatible_libraries.go @@ -31,7 +31,6 @@ package builder import ( "arduino.cc/builder/constants" - "arduino.cc/builder/props" "arduino.cc/builder/types" "os" "strings" @@ -45,7 +44,7 @@ func (s *WarnAboutArchIncompatibleLibraries) Run(context map[string]interface{}, } targetPlatform := ctx.TargetPlatform - buildProperties := context[constants.CTX_BUILD_PROPERTIES].(props.PropertiesMap) + buildProperties := ctx.BuildProperties logger := ctx.GetLogger() archs := []string{} From 377bebefbf09a404d77bc326c710f7e2e1c643ae Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Fri, 15 Apr 2016 16:07:30 +0200 Subject: [PATCH 15/25] IncludeFolders now in Context Signed-off-by: Cristian Maglie --- src/arduino.cc/builder/constants/constants.go | 1 - src/arduino.cc/builder/gcc_preproc_runner.go | 2 +- src/arduino.cc/builder/includes_finder_with_gcc.go | 8 ++------ src/arduino.cc/builder/includes_to_include_folders.go | 6 +----- src/arduino.cc/builder/phases/libraries_builder.go | 2 +- src/arduino.cc/builder/phases/sketch_builder.go | 2 +- src/arduino.cc/builder/types/context.go | 1 + 7 files changed, 7 insertions(+), 15 deletions(-) diff --git a/src/arduino.cc/builder/constants/constants.go b/src/arduino.cc/builder/constants/constants.go index b672ed9d..03dfef5a 100644 --- a/src/arduino.cc/builder/constants/constants.go +++ b/src/arduino.cc/builder/constants/constants.go @@ -81,7 +81,6 @@ const CTX_GCC_MINUS_E_SOURCE = "gccMinusESource" const CTX_GCC_MINUS_M_OUTPUT = "gccMinusMOutput" const CTX_HARDWARE = "hardware" const CTX_HARDWARE_REWRITE_RESULTS = "hardwareRewriteResults" -const CTX_INCLUDE_FOLDERS = "includeFolders" const CTX_INCLUDE_SECTION = "includeSection" const CTX_INCLUDES_JUST_FOUND = "includesJustFound" const CTX_LINE_OFFSET = "lineOffset" diff --git a/src/arduino.cc/builder/gcc_preproc_runner.go b/src/arduino.cc/builder/gcc_preproc_runner.go index f8167cd7..6727a0e5 100644 --- a/src/arduino.cc/builder/gcc_preproc_runner.go +++ b/src/arduino.cc/builder/gcc_preproc_runner.go @@ -112,7 +112,7 @@ func prepareGCCPreprocRecipeProperties(context map[string]interface{}, ctx *type properties[constants.BUILD_PROPERTIES_SOURCE_FILE] = sourceFilePath properties[constants.BUILD_PROPERTIES_PREPROCESSED_FILE_PATH] = targetFilePath - includes := context[constants.CTX_INCLUDE_FOLDERS].([]string) + includes := ctx.IncludeFolders includes = utils.Map(includes, utils.WrapWithHyphenI) properties[constants.BUILD_PROPERTIES_INCLUDES] = strings.Join(includes, constants.SPACE) builder_utils.RemoveHyphenMDDFlagFromGCCCommandLine(properties) diff --git a/src/arduino.cc/builder/includes_finder_with_gcc.go b/src/arduino.cc/builder/includes_finder_with_gcc.go index f8bfd7a8..abdc678a 100644 --- a/src/arduino.cc/builder/includes_finder_with_gcc.go +++ b/src/arduino.cc/builder/includes_finder_with_gcc.go @@ -47,12 +47,8 @@ func (s *IncludesFinderWithGCC) Run(context map[string]interface{}, ctx *types.C verbose := ctx.Verbose logger := ctx.GetLogger() - includesParams := constants.EMPTY_STRING - if utils.MapHas(context, constants.CTX_INCLUDE_FOLDERS) { - includes := context[constants.CTX_INCLUDE_FOLDERS].([]string) - includes = utils.Map(includes, utils.WrapWithHyphenI) - includesParams = strings.Join(includes, " ") - } + includes := utils.Map(ctx.IncludeFolders, utils.WrapWithHyphenI) + includesParams := strings.Join(includes, " ") properties := buildProperties.Clone() properties[constants.BUILD_PROPERTIES_SOURCE_FILE] = s.SourceFile diff --git a/src/arduino.cc/builder/includes_to_include_folders.go b/src/arduino.cc/builder/includes_to_include_folders.go index 344fb357..cd93337d 100644 --- a/src/arduino.cc/builder/includes_to_include_folders.go +++ b/src/arduino.cc/builder/includes_to_include_folders.go @@ -68,11 +68,7 @@ func (s *IncludesToIncludeFolders) Run(context map[string]interface{}, ctx *type } ctx.ImportedLibraries = importedLibraries - - buildProperties := ctx.BuildProperties - verbose := ctx.Verbose - includeFolders := resolveIncludeFolders(newlyImportedLibraries, buildProperties, verbose) - context[constants.CTX_INCLUDE_FOLDERS] = includeFolders + ctx.IncludeFolders = resolveIncludeFolders(newlyImportedLibraries, ctx.BuildProperties, ctx.Verbose) return nil } diff --git a/src/arduino.cc/builder/phases/libraries_builder.go b/src/arduino.cc/builder/phases/libraries_builder.go index da9b7361..fe3704c1 100644 --- a/src/arduino.cc/builder/phases/libraries_builder.go +++ b/src/arduino.cc/builder/phases/libraries_builder.go @@ -45,7 +45,7 @@ type LibrariesBuilder struct{} func (s *LibrariesBuilder) Run(context map[string]interface{}, ctx *types.Context) error { librariesBuildPath := ctx.LibrariesBuildPath buildProperties := ctx.BuildProperties - includes := context[constants.CTX_INCLUDE_FOLDERS].([]string) + includes := ctx.IncludeFolders includes = utils.Map(includes, utils.WrapWithHyphenI) libraries := ctx.ImportedLibraries verbose := ctx.Verbose diff --git a/src/arduino.cc/builder/phases/sketch_builder.go b/src/arduino.cc/builder/phases/sketch_builder.go index d0f086cf..da4a70b1 100644 --- a/src/arduino.cc/builder/phases/sketch_builder.go +++ b/src/arduino.cc/builder/phases/sketch_builder.go @@ -42,7 +42,7 @@ type SketchBuilder struct{} func (s *SketchBuilder) Run(context map[string]interface{}, ctx *types.Context) error { sketchBuildPath := ctx.SketchBuildPath buildProperties := ctx.BuildProperties - includes := context[constants.CTX_INCLUDE_FOLDERS].([]string) + includes := ctx.IncludeFolders includes = utils.Map(includes, utils.WrapWithHyphenI) verbose := ctx.Verbose warningsLevel := ctx.WarningsLevel diff --git a/src/arduino.cc/builder/types/context.go b/src/arduino.cc/builder/types/context.go index 097c4342..08d3501c 100644 --- a/src/arduino.cc/builder/types/context.go +++ b/src/arduino.cc/builder/types/context.go @@ -43,6 +43,7 @@ type Context struct { HeaderToLibraries map[string][]*Library ImportedLibraries []*Library LibrariesResolutionResults map[string]LibraryResolutionResult + IncludeFolders []string // C++ Parsing CTagsOutput string From a9fd1c674ee5f9d1b6f6376654e16be542d8e1d5 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Fri, 15 Apr 2016 17:36:26 +0200 Subject: [PATCH 16/25] Moved Sketch in Context Signed-off-by: Cristian Maglie --- .../builder/additional_sketch_files_copier.go | 3 +-- .../collect_ctags_from_sketch_files.go | 4 +--- src/arduino.cc/builder/constants/constants.go | 1 - .../builder/container_find_includes.go | 2 +- src/arduino.cc/builder/gcc_preproc_runner.go | 2 +- .../builder/merge_sketch_with_bootloader.go | 2 +- .../builder/setup_build_properties.go | 4 ++-- src/arduino.cc/builder/sketch_loader.go | 2 +- src/arduino.cc/builder/sketch_saver.go | 2 +- .../builder/sketch_source_merger.go | 2 +- .../builder/test/coan_runner_test.go | 2 +- src/arduino.cc/builder/test/helper.go | 3 ++- .../builder/test/prototypes_adder_test.go | 20 +++++++++--------- .../builder/test/sketch_loader_test.go | 21 +++++++------------ .../builder/test/sketch_source_merger_test.go | 2 +- src/arduino.cc/builder/types/context.go | 2 ++ 16 files changed, 33 insertions(+), 41 deletions(-) diff --git a/src/arduino.cc/builder/additional_sketch_files_copier.go b/src/arduino.cc/builder/additional_sketch_files_copier.go index 3e1090ff..d362ceb7 100644 --- a/src/arduino.cc/builder/additional_sketch_files_copier.go +++ b/src/arduino.cc/builder/additional_sketch_files_copier.go @@ -30,7 +30,6 @@ package builder import ( - "arduino.cc/builder/constants" "arduino.cc/builder/i18n" "arduino.cc/builder/types" "arduino.cc/builder/utils" @@ -42,7 +41,7 @@ import ( type AdditionalSketchFilesCopier struct{} func (s *AdditionalSketchFilesCopier) Run(context map[string]interface{}, ctx *types.Context) error { - sketch := context[constants.CTX_SKETCH].(*types.Sketch) + sketch := ctx.Sketch sketchBuildPath := ctx.SketchBuildPath err := utils.EnsureFolderExists(sketchBuildPath) diff --git a/src/arduino.cc/builder/collect_ctags_from_sketch_files.go b/src/arduino.cc/builder/collect_ctags_from_sketch_files.go index c5e0d592..45721b9e 100644 --- a/src/arduino.cc/builder/collect_ctags_from_sketch_files.go +++ b/src/arduino.cc/builder/collect_ctags_from_sketch_files.go @@ -30,7 +30,6 @@ package builder import ( - "arduino.cc/builder/constants" "arduino.cc/builder/types" "arduino.cc/builder/utils" "strings" @@ -39,8 +38,7 @@ import ( type CollectCTagsFromSketchFiles struct{} func (s *CollectCTagsFromSketchFiles) Run(context map[string]interface{}, ctx *types.Context) error { - sketch := context[constants.CTX_SKETCH].(*types.Sketch) - sketchFileNames := collectSketchFileNamesFrom(sketch) + sketchFileNames := collectSketchFileNamesFrom(ctx.Sketch) allCtags := ctx.CTagsOfPreprocessedSource ctagsOfSketch := []*types.CTag{} diff --git a/src/arduino.cc/builder/constants/constants.go b/src/arduino.cc/builder/constants/constants.go index 03dfef5a..15b8fc94 100644 --- a/src/arduino.cc/builder/constants/constants.go +++ b/src/arduino.cc/builder/constants/constants.go @@ -88,7 +88,6 @@ const CTX_OBJECT_FILES_CORE = "objectFilesCore" const CTX_OBJECT_FILES_LIBRARIES = "objectFilesLibraries" const CTX_OBJECT_FILES_SKETCH = "objectFilesSketch" const CTX_PLATFORM_KEYS_REWRITE = "platformKeysRewrite" -const CTX_SKETCH = "sketch" const CTX_SOURCE = "source" const CTX_TOOLS = "tools" const CTX_VIDPID = "VIDPID" diff --git a/src/arduino.cc/builder/container_find_includes.go b/src/arduino.cc/builder/container_find_includes.go index 3e351fed..fa5cf337 100644 --- a/src/arduino.cc/builder/container_find_includes.go +++ b/src/arduino.cc/builder/container_find_includes.go @@ -46,7 +46,7 @@ func (s *ContainerFindIncludes) Run(context map[string]interface{}, ctx *types.C } sketchBuildPath := ctx.SketchBuildPath - sketch := context[constants.CTX_SKETCH].(*types.Sketch) + sketch := ctx.Sketch err = findIncludesUntilDone(context, ctx, filepath.Join(sketchBuildPath, filepath.Base(sketch.MainFile.Name)+".cpp")) if err != nil { return i18n.WrapError(err) diff --git a/src/arduino.cc/builder/gcc_preproc_runner.go b/src/arduino.cc/builder/gcc_preproc_runner.go index 6727a0e5..284fa4f6 100644 --- a/src/arduino.cc/builder/gcc_preproc_runner.go +++ b/src/arduino.cc/builder/gcc_preproc_runner.go @@ -46,7 +46,7 @@ type GCCPreprocRunner struct { func (s *GCCPreprocRunner) Run(context map[string]interface{}, ctx *types.Context) error { sketchBuildPath := ctx.SketchBuildPath - sketch := context[constants.CTX_SKETCH].(*types.Sketch) + sketch := ctx.Sketch properties, targetFilePath, err := prepareGCCPreprocRecipeProperties(context, ctx, filepath.Join(sketchBuildPath, filepath.Base(sketch.MainFile.Name)+".cpp"), s.TargetFileName) if err != nil { return i18n.WrapError(err) diff --git a/src/arduino.cc/builder/merge_sketch_with_bootloader.go b/src/arduino.cc/builder/merge_sketch_with_bootloader.go index e4266e25..a822c2f1 100644 --- a/src/arduino.cc/builder/merge_sketch_with_bootloader.go +++ b/src/arduino.cc/builder/merge_sketch_with_bootloader.go @@ -48,7 +48,7 @@ func (s *MergeSketchWithBootloader) Run(context map[string]interface{}, ctx *typ } buildPath := ctx.BuildPath - sketch := context[constants.CTX_SKETCH].(*types.Sketch) + sketch := ctx.Sketch sketchFileName := filepath.Base(sketch.MainFile.Name) logger := ctx.GetLogger() diff --git a/src/arduino.cc/builder/setup_build_properties.go b/src/arduino.cc/builder/setup_build_properties.go index d05647e7..2ea6127f 100644 --- a/src/arduino.cc/builder/setup_build_properties.go +++ b/src/arduino.cc/builder/setup_build_properties.go @@ -57,8 +57,8 @@ func (s *SetupBuildProperties) Run(context map[string]interface{}, ctx *types.Co if ctx.BuildPath != "" { buildProperties[constants.BUILD_PROPERTIES_BUILD_PATH] = ctx.BuildPath } - if utils.MapHas(context, constants.CTX_SKETCH) { - buildProperties[constants.BUILD_PROPERTIES_BUILD_PROJECT_NAME] = filepath.Base(context[constants.CTX_SKETCH].(*types.Sketch).MainFile.Name) + if ctx.Sketch != nil { + buildProperties[constants.BUILD_PROPERTIES_BUILD_PROJECT_NAME] = filepath.Base(ctx.Sketch.MainFile.Name) } buildProperties[constants.BUILD_PROPERTIES_BUILD_ARCH] = strings.ToUpper(targetPlatform.PlatformId) diff --git a/src/arduino.cc/builder/sketch_loader.go b/src/arduino.cc/builder/sketch_loader.go index 1857078a..ced41d30 100644 --- a/src/arduino.cc/builder/sketch_loader.go +++ b/src/arduino.cc/builder/sketch_loader.go @@ -82,7 +82,7 @@ func (s *SketchLoader) Run(context map[string]interface{}, ctx *types.Context) e } ctx.SketchLocation = sketchLocation - context[constants.CTX_SKETCH] = sketch + ctx.Sketch = sketch return nil } diff --git a/src/arduino.cc/builder/sketch_saver.go b/src/arduino.cc/builder/sketch_saver.go index 1df4faa6..ced8259d 100644 --- a/src/arduino.cc/builder/sketch_saver.go +++ b/src/arduino.cc/builder/sketch_saver.go @@ -40,7 +40,7 @@ import ( type SketchSaver struct{} func (s *SketchSaver) Run(context map[string]interface{}, ctx *types.Context) error { - sketch := context[constants.CTX_SKETCH].(*types.Sketch) + sketch := ctx.Sketch sketchBuildPath := ctx.SketchBuildPath source := context[constants.CTX_SOURCE].(string) diff --git a/src/arduino.cc/builder/sketch_source_merger.go b/src/arduino.cc/builder/sketch_source_merger.go index 5835c7a7..1b20a4b1 100644 --- a/src/arduino.cc/builder/sketch_source_merger.go +++ b/src/arduino.cc/builder/sketch_source_merger.go @@ -40,7 +40,7 @@ import ( type SketchSourceMerger struct{} func (s *SketchSourceMerger) Run(context map[string]interface{}, ctx *types.Context) error { - sketch := context[constants.CTX_SKETCH].(*types.Sketch) + sketch := ctx.Sketch lineOffset := 0 includeSection := "" diff --git a/src/arduino.cc/builder/test/coan_runner_test.go b/src/arduino.cc/builder/test/coan_runner_test.go index 89f58ec8..9f45724f 100644 --- a/src/arduino.cc/builder/test/coan_runner_test.go +++ b/src/arduino.cc/builder/test/coan_runner_test.go @@ -68,7 +68,7 @@ func TestCoanRunner(t *testing.T) { NoError(t, err) } - expectedSource := LoadAndInterpolate(t, filepath.Join("sketch2", "SketchWithIfDef.resolved.directives.txt"), context) + expectedSource := LoadAndInterpolate(t, filepath.Join("sketch2", "SketchWithIfDef.resolved.directives.txt"), context, ctx) require.Equal(t, expectedSource, strings.Replace(context[constants.CTX_SOURCE].(string), "\r\n", "\n", -1)) } diff --git a/src/arduino.cc/builder/test/helper.go b/src/arduino.cc/builder/test/helper.go index e2a3955e..3f74e310 100644 --- a/src/arduino.cc/builder/test/helper.go +++ b/src/arduino.cc/builder/test/helper.go @@ -44,7 +44,7 @@ import ( "text/template" ) -func LoadAndInterpolate(t *testing.T, filename string, context map[string]interface{}) string { +func LoadAndInterpolate(t *testing.T, filename string, context map[string]interface{}, ctx *types.Context) string { funcsMap := template.FuncMap{ "EscapeBackSlashes": func(s string) string { return strings.Replace(s, "\\", "\\\\", -1) @@ -55,6 +55,7 @@ func LoadAndInterpolate(t *testing.T, filename string, context map[string]interf NoError(t, err) var buf bytes.Buffer + context["sketch"] = ctx.Sketch err = tpl.Execute(&buf, context) NoError(t, err) diff --git a/src/arduino.cc/builder/test/prototypes_adder_test.go b/src/arduino.cc/builder/test/prototypes_adder_test.go index 2ed46b5d..6720029c 100644 --- a/src/arduino.cc/builder/test/prototypes_adder_test.go +++ b/src/arduino.cc/builder/test/prototypes_adder_test.go @@ -124,7 +124,7 @@ func TestPrototypesAdderSketchWithIfDef(t *testing.T) { NoError(t, err) } - preprocessed := LoadAndInterpolate(t, filepath.Join("sketch2", "SketchWithIfDef.preprocessed.txt"), context) + preprocessed := LoadAndInterpolate(t, filepath.Join("sketch2", "SketchWithIfDef.preprocessed.txt"), context, ctx) require.Equal(t, preprocessed, strings.Replace(context[constants.CTX_SOURCE].(string), "\r\n", "\n", -1)) } @@ -165,7 +165,7 @@ func TestPrototypesAdderBaladuino(t *testing.T) { NoError(t, err) } - preprocessed := LoadAndInterpolate(t, filepath.Join("sketch3", "Baladuino.preprocessed.txt"), context) + preprocessed := LoadAndInterpolate(t, filepath.Join("sketch3", "Baladuino.preprocessed.txt"), context, ctx) require.Equal(t, preprocessed, strings.Replace(context[constants.CTX_SOURCE].(string), "\r\n", "\n", -1)) } @@ -206,7 +206,7 @@ func TestPrototypesAdderCharWithEscapedDoubleQuote(t *testing.T) { NoError(t, err) } - preprocessed := LoadAndInterpolate(t, filepath.Join("sketch4", "CharWithEscapedDoubleQuote.preprocessed.txt"), context) + preprocessed := LoadAndInterpolate(t, filepath.Join("sketch4", "CharWithEscapedDoubleQuote.preprocessed.txt"), context, ctx) require.Equal(t, preprocessed, strings.Replace(context[constants.CTX_SOURCE].(string), "\r\n", "\n", -1)) } @@ -247,7 +247,7 @@ func TestPrototypesAdderIncludeBetweenMultilineComment(t *testing.T) { NoError(t, err) } - preprocessed := LoadAndInterpolate(t, filepath.Join("sketch5", "IncludeBetweenMultilineComment.preprocessed.txt"), context) + preprocessed := LoadAndInterpolate(t, filepath.Join("sketch5", "IncludeBetweenMultilineComment.preprocessed.txt"), context, ctx) require.Equal(t, preprocessed, strings.Replace(context[constants.CTX_SOURCE].(string), "\r\n", "\n", -1)) } @@ -288,7 +288,7 @@ func TestPrototypesAdderLineContinuations(t *testing.T) { NoError(t, err) } - preprocessed := LoadAndInterpolate(t, filepath.Join("sketch6", "LineContinuations.preprocessed.txt"), context) + preprocessed := LoadAndInterpolate(t, filepath.Join("sketch6", "LineContinuations.preprocessed.txt"), context, ctx) require.Equal(t, preprocessed, strings.Replace(context[constants.CTX_SOURCE].(string), "\r\n", "\n", -1)) } @@ -329,7 +329,7 @@ func TestPrototypesAdderStringWithComment(t *testing.T) { NoError(t, err) } - preprocessed := LoadAndInterpolate(t, filepath.Join("sketch7", "StringWithComment.preprocessed.txt"), context) + preprocessed := LoadAndInterpolate(t, filepath.Join("sketch7", "StringWithComment.preprocessed.txt"), context, ctx) require.Equal(t, preprocessed, strings.Replace(context[constants.CTX_SOURCE].(string), "\r\n", "\n", -1)) } @@ -370,7 +370,7 @@ func TestPrototypesAdderSketchWithStruct(t *testing.T) { NoError(t, err) } - preprocessed := LoadAndInterpolate(t, filepath.Join("sketch8", "SketchWithStruct.preprocessed.txt"), context) + preprocessed := LoadAndInterpolate(t, filepath.Join("sketch8", "SketchWithStruct.preprocessed.txt"), context, ctx) obtained := strings.Replace(context[constants.CTX_SOURCE].(string), "\r\n", "\n", -1) // ctags based preprocessing removes the space after "dostuff", but this is still OK // TODO: remove this exception when moving to a more powerful parser @@ -422,7 +422,7 @@ func TestPrototypesAdderSketchWithConfig(t *testing.T) { require.Equal(t, "#include \n#line 1 \""+absoluteSketchLocation+"\"\n", context[constants.CTX_INCLUDE_SECTION].(string)) require.Equal(t, "#line 13 \""+absoluteSketchLocation+"\"\nvoid setup();\n#line 17 \""+absoluteSketchLocation+"\"\nvoid loop();\n#line 13 \""+absoluteSketchLocation+"\"\n", ctx.PrototypesSection) - preprocessed := LoadAndInterpolate(t, filepath.Join("sketch_with_config", "sketch_with_config.preprocessed.txt"), context) + preprocessed := LoadAndInterpolate(t, filepath.Join("sketch_with_config", "sketch_with_config.preprocessed.txt"), context, ctx) require.Equal(t, preprocessed, strings.Replace(context[constants.CTX_SOURCE].(string), "\r\n", "\n", -1)) } @@ -793,7 +793,7 @@ func TestPrototypesAdderSketchWithIfDef2(t *testing.T) { require.Equal(t, "#include \n#line 1 \""+absoluteSketchLocation+"\"\n", context[constants.CTX_INCLUDE_SECTION].(string)) require.Equal(t, "#line 5 \""+absoluteSketchLocation+"\"\nvoid elseBranch();\n#line 9 \""+absoluteSketchLocation+"\"\nvoid f1();\n#line 10 \""+absoluteSketchLocation+"\"\nvoid f2();\n#line 12 \""+absoluteSketchLocation+"\"\nvoid setup();\n#line 14 \""+absoluteSketchLocation+"\"\nvoid loop();\n#line 5 \""+absoluteSketchLocation+"\"\n", ctx.PrototypesSection) - expectedSource := LoadAndInterpolate(t, filepath.Join("sketch_with_ifdef", "sketch.preprocessed.txt"), context) + expectedSource := LoadAndInterpolate(t, filepath.Join("sketch_with_ifdef", "sketch.preprocessed.txt"), context, ctx) require.Equal(t, expectedSource, strings.Replace(context[constants.CTX_SOURCE].(string), "\r\n", "\n", -1)) } @@ -840,7 +840,7 @@ func TestPrototypesAdderSketchWithIfDef2SAM(t *testing.T) { require.Equal(t, "#include \n#line 1 \""+absoluteSketchLocation+"\"\n", context[constants.CTX_INCLUDE_SECTION].(string)) require.Equal(t, "#line 2 \""+absoluteSketchLocation+"\"\nvoid ifBranch();\n#line 9 \""+absoluteSketchLocation+"\"\nvoid f1();\n#line 10 \""+absoluteSketchLocation+"\"\nvoid f2();\n#line 12 \""+absoluteSketchLocation+"\"\nvoid setup();\n#line 14 \""+absoluteSketchLocation+"\"\nvoid loop();\n#line 2 \""+absoluteSketchLocation+"\"\n", ctx.PrototypesSection) - expectedSource := LoadAndInterpolate(t, filepath.Join("sketch_with_ifdef", "sketch.preprocessed.SAM.txt"), context) + expectedSource := LoadAndInterpolate(t, filepath.Join("sketch_with_ifdef", "sketch.preprocessed.SAM.txt"), context, ctx) require.Equal(t, expectedSource, strings.Replace(context[constants.CTX_SOURCE].(string), "\r\n", "\n", -1)) } diff --git a/src/arduino.cc/builder/test/sketch_loader_test.go b/src/arduino.cc/builder/test/sketch_loader_test.go index c471f052..05373411 100644 --- a/src/arduino.cc/builder/test/sketch_loader_test.go +++ b/src/arduino.cc/builder/test/sketch_loader_test.go @@ -31,7 +31,6 @@ package test import ( "arduino.cc/builder" - "arduino.cc/builder/constants" "arduino.cc/builder/types" "github.com/stretchr/testify/require" "path/filepath" @@ -48,9 +47,7 @@ func TestLoadSketchWithFolder(t *testing.T) { err := loader.Run(context, ctx) require.Error(t, err) - - sketch := context[constants.CTX_SKETCH] - require.Nil(t, sketch) + require.Nil(t, ctx.Sketch) } func TestLoadSketchNonExistentPath(t *testing.T) { @@ -63,9 +60,7 @@ func TestLoadSketchNonExistentPath(t *testing.T) { err := loader.Run(context, ctx) require.Error(t, err) - - sketch := context[constants.CTX_SKETCH] - require.Nil(t, sketch) + require.Nil(t, ctx.Sketch) } func TestLoadSketch(t *testing.T) { @@ -83,7 +78,7 @@ func TestLoadSketch(t *testing.T) { NoError(t, err) } - sketch := context[constants.CTX_SKETCH].(*types.Sketch) + sketch := ctx.Sketch require.NotNil(t, sketch) require.Contains(t, sketch.MainFile.Name, "sketch.ino") @@ -107,9 +102,7 @@ func TestFailToLoadSketchFromFolder(t *testing.T) { loader := builder.SketchLoader{} err := loader.Run(context, ctx) require.Error(t, err) - - sketch := context[constants.CTX_SKETCH] - require.Nil(t, sketch) + require.Nil(t, ctx.Sketch) } func TestLoadSketchFromFolder(t *testing.T) { @@ -127,7 +120,7 @@ func TestLoadSketchFromFolder(t *testing.T) { NoError(t, err) } - sketch := context[constants.CTX_SKETCH].(*types.Sketch) + sketch := ctx.Sketch require.NotNil(t, sketch) require.Contains(t, sketch.MainFile.Name, "sketch_with_subfolders.ino") @@ -154,7 +147,7 @@ func TestLoadSketchWithBackup(t *testing.T) { NoError(t, err) } - sketch := context[constants.CTX_SKETCH].(*types.Sketch) + sketch := ctx.Sketch require.NotNil(t, sketch) require.Contains(t, sketch.MainFile.Name, "sketch.ino") @@ -178,7 +171,7 @@ func TestLoadSketchWithMacOSXGarbage(t *testing.T) { NoError(t, err) } - sketch := context[constants.CTX_SKETCH].(*types.Sketch) + sketch := ctx.Sketch require.NotNil(t, sketch) require.Contains(t, sketch.MainFile.Name, "sketch.ino") diff --git a/src/arduino.cc/builder/test/sketch_source_merger_test.go b/src/arduino.cc/builder/test/sketch_source_merger_test.go index e7adfcdc..e3f79011 100644 --- a/src/arduino.cc/builder/test/sketch_source_merger_test.go +++ b/src/arduino.cc/builder/test/sketch_source_merger_test.go @@ -58,6 +58,6 @@ func TestMergeSketch(t *testing.T) { source := context[constants.CTX_SOURCE].(string) - expected_source := LoadAndInterpolate(t, filepath.Join("sketch1", "merged_sketch.txt"), context) + expected_source := LoadAndInterpolate(t, filepath.Join("sketch1", "merged_sketch.txt"), context, ctx) require.Equal(t, expected_source, strings.Replace(source, "\r\n", "\n", -1)) } diff --git a/src/arduino.cc/builder/types/context.go b/src/arduino.cc/builder/types/context.go index 08d3501c..37eab214 100644 --- a/src/arduino.cc/builder/types/context.go +++ b/src/arduino.cc/builder/types/context.go @@ -35,6 +35,8 @@ type Context struct { CollectedSourceFiles *UniqueStringQueue FoldersWithSourceFiles *UniqueSourceFolderQueue + Sketch *Sketch + WarningsLevel string // Libraries handling From 7520e666aec586df9274fe2100573bc9dd1bc1b1 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Fri, 15 Apr 2016 18:56:43 +0200 Subject: [PATCH 17/25] Removed no more used "coan" tools Signed-off-by: Cristian Maglie --- src/arduino.cc/builder/coan_runner.go | 91 ------------------- src/arduino.cc/builder/constants/constants.go | 2 - .../builder/test/coan_runner_test.go | 74 --------------- .../builder/test/hardware/platform.txt | 5 - .../builder/test/helper_tools_downloader.go | 7 -- .../test/includes_finder_with_regexp_test.go | 64 +++---------- .../test/setup_build_properties_test.go | 4 - 7 files changed, 12 insertions(+), 235 deletions(-) delete mode 100644 src/arduino.cc/builder/coan_runner.go delete mode 100644 src/arduino.cc/builder/test/coan_runner_test.go diff --git a/src/arduino.cc/builder/coan_runner.go b/src/arduino.cc/builder/coan_runner.go deleted file mode 100644 index d03da589..00000000 --- a/src/arduino.cc/builder/coan_runner.go +++ /dev/null @@ -1,91 +0,0 @@ -/* - * This file is part of Arduino Builder. - * - * Arduino Builder is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - * As a special exception, you may use this file as part of a free software - * library without restriction. Specifically, if other files instantiate - * templates or use macros or inline functions from this file, or you compile - * this file and link it with other files to produce an executable, this - * file does not by itself cause the resulting executable to be covered by - * the GNU General Public License. This exception does not however - * invalidate any other reasons why the executable file might be covered by - * the GNU General Public License. - * - * Copyright 2015 Arduino LLC (http://www.arduino.cc/) - */ - -package builder - -import ( - "arduino.cc/builder/constants" - "arduino.cc/builder/i18n" - "arduino.cc/builder/types" - "arduino.cc/builder/utils" - "fmt" - "path/filepath" - "regexp" -) - -var ALLOWED_ARG = regexp.MustCompile("^source$|\\-E$|\\-m$|\\-P$|\\-kb$|\\-D.*") - -type CoanRunner struct{} - -func (s *CoanRunner) Run(context map[string]interface{}, ctx *types.Context) error { - source := context[constants.CTX_SOURCE].(string) - source += "\n" - verbose := ctx.Verbose - - preprocPath := ctx.PreprocPath - err := utils.EnsureFolderExists(preprocPath) - if err != nil { - return i18n.WrapError(err) - } - - coanTargetFileName := filepath.Join(preprocPath, constants.FILE_COAN_TARGET) - err = utils.WriteFile(coanTargetFileName, source) - if err != nil { - return i18n.WrapError(err) - } - - buildProperties := ctx.BuildProperties - properties := buildProperties.Clone() - properties.Merge(buildProperties.SubTree(constants.BUILD_PROPERTIES_TOOLS_KEY).SubTree(constants.COAN)) - properties[constants.BUILD_PROPERTIES_SOURCE_FILE] = coanTargetFileName - - logger := ctx.GetLogger() - - pattern := properties[constants.BUILD_PROPERTIES_PATTERN] - if pattern == constants.EMPTY_STRING { - return i18n.ErrorfWithLogger(logger, constants.MSG_PATTERN_MISSING, constants.COAN) - } - - commandLine := properties.ExpandPropsInString(pattern) - command, err := utils.PrepareCommandFilteredArgs(commandLine, filterAllowedArg, logger) - - if verbose { - fmt.Println(commandLine) - } - - sourceBytes, _ := command.Output() - - context[constants.CTX_SOURCE] = string(sourceBytes) - - return nil -} - -func filterAllowedArg(idx int, part string, parts []string) bool { - return idx == len(parts)-1 || ALLOWED_ARG.MatchString(part) -} diff --git a/src/arduino.cc/builder/constants/constants.go b/src/arduino.cc/builder/constants/constants.go index 15b8fc94..eac2c69f 100644 --- a/src/arduino.cc/builder/constants/constants.go +++ b/src/arduino.cc/builder/constants/constants.go @@ -72,7 +72,6 @@ const BUILD_PROPERTIES_SOURCE_FILE = "source_file" const BUILD_PROPERTIES_SOURCE_PATH = "build.source.path" const BUILD_PROPERTIES_TOOLS_KEY = "tools" const BUILD_PROPERTIES_VID = "vid" -const COAN = "coan" const CTAGS = "ctags" const CTX_ARCHIVE_FILE_PATH_CORE = "archiveFileCore" const CTX_BUILD_CORE = "buildCore" @@ -95,7 +94,6 @@ const EMPTY_STRING = "" const FILE_BOARDS_LOCAL_TXT = "boards.local.txt" const FILE_BOARDS_TXT = "boards.txt" const FILE_BUILTIN_TOOLS_VERSIONS_TXT = "builtin_tools_versions.txt" -const FILE_COAN_TARGET = "coan_target.cpp" const FILE_CTAGS_TARGET = "ctags_target.cpp" const FILE_CTAGS_TARGET_FOR_GCC_MINUS_E = "ctags_target_for_gcc_minus_e.cpp" const FILE_GCC_PREPROC_TARGET = "gcc_preproc_target.cpp" diff --git a/src/arduino.cc/builder/test/coan_runner_test.go b/src/arduino.cc/builder/test/coan_runner_test.go deleted file mode 100644 index 9f45724f..00000000 --- a/src/arduino.cc/builder/test/coan_runner_test.go +++ /dev/null @@ -1,74 +0,0 @@ -/* - * This file is part of Arduino Builder. - * - * Arduino Builder is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - * As a special exception, you may use this file as part of a free software - * library without restriction. Specifically, if other files instantiate - * templates or use macros or inline functions from this file, or you compile - * this file and link it with other files to produce an executable, this - * file does not by itself cause the resulting executable to be covered by - * the GNU General Public License. This exception does not however - * invalidate any other reasons why the executable file might be covered by - * the GNU General Public License. - * - * Copyright 2015 Arduino LLC (http://www.arduino.cc/) - * Copyright 2015 Matthijs Kooijman - */ - -package test - -import ( - "arduino.cc/builder" - "arduino.cc/builder/constants" - "arduino.cc/builder/types" - "github.com/stretchr/testify/require" - "os" - "path/filepath" - "strings" - "testing" -) - -func TestCoanRunner(t *testing.T) { - DownloadCoresAndToolsAndLibraries(t) - - context := make(map[string]interface{}) - ctx := &types.Context{ - HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, - ToolsFolders: []string{"downloaded_tools"}, - SketchLocation: filepath.Join("sketch2", "SketchWithIfDef.ino"), - FQBN: "arduino:avr:leonardo", - ArduinoAPIVersion: "10600", - Verbose: true, - } - - buildPath := SetupBuildPath(t, ctx) - defer os.RemoveAll(buildPath) - - commands := []types.Command{ - &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, - &builder.SketchSourceMerger{}, - &builder.CoanRunner{}, - } - - for _, command := range commands { - err := command.Run(context, ctx) - NoError(t, err) - } - - expectedSource := LoadAndInterpolate(t, filepath.Join("sketch2", "SketchWithIfDef.resolved.directives.txt"), context, ctx) - require.Equal(t, expectedSource, strings.Replace(context[constants.CTX_SOURCE].(string), "\r\n", "\n", -1)) - -} diff --git a/src/arduino.cc/builder/test/hardware/platform.txt b/src/arduino.cc/builder/test/hardware/platform.txt index 25054c03..8b137891 100644 --- a/src/arduino.cc/builder/test/hardware/platform.txt +++ b/src/arduino.cc/builder/test/hardware/platform.txt @@ -1,6 +1 @@ -# coan -# ------------------------------ -tools.coan.path={runtime.tools.coan.path} -tools.coan.cmd.path={path}/coan -tools.coan.pattern="{cmd.path}" source -m -E -P -kb {compiler.c.flags} -mmcu={build.mcu} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.c.extra_flags} {build.extra_flags} "{source_file}" diff --git a/src/arduino.cc/builder/test/helper_tools_downloader.go b/src/arduino.cc/builder/test/helper_tools_downloader.go index cd606290..e2f1f2fe 100644 --- a/src/arduino.cc/builder/test/helper_tools_downloader.go +++ b/src/arduino.cc/builder/test/helper_tools_downloader.go @@ -105,13 +105,6 @@ func DownloadCoresAndToolsAndLibraries(t *testing.T) { Tool{Name: "avrdude", Version: "6.0.1-arduino5"}, Tool{Name: "avr-gcc", Version: "4.8.1-arduino5"}, Tool{Name: "arm-none-eabi-gcc", Version: "4.8.3-2014q1"}, - Tool{Name: "coan", Version: "5.2", OsUrls: []OsUrl{ - OsUrl{Os: "i686-pc-linux-gnu", Url: "http://downloads.arduino.cc/tools/coan-5.2-i686-pc-linux-gnu.tar.bz2"}, - OsUrl{Os: "x86_64-pc-linux-gnu", Url: "http://downloads.arduino.cc/tools/coan-5.2-x86_64-pc-linux-gnu.tar.bz2"}, - OsUrl{Os: "i686-mingw32", Url: "http://downloads.arduino.cc/tools/coan-5.2-i686-mingw32.zip"}, - OsUrl{Os: "x86_64-apple-darwin", Url: "http://downloads.arduino.cc/tools/coan-5.2-x86_64-apple-darwin.zip"}, - OsUrl{Os: "arm-linux-gnueabihf", Url: "http://downloads.arduino.cc/tools/coan-5.2-arm-linux-gnueabihf.tar.bz2"}, - }}, Tool{Name: "ctags", Version: "5.8-arduino10", OsUrls: []OsUrl{ OsUrl{Os: "i686-pc-linux-gnu", Url: "http://downloads.arduino.cc/tools/ctags-5.8-arduino10-i686-pc-linux-gnu.tar.bz2"}, diff --git a/src/arduino.cc/builder/test/includes_finder_with_regexp_test.go b/src/arduino.cc/builder/test/includes_finder_with_regexp_test.go index e1a5c384..d20d6d03 100644 --- a/src/arduino.cc/builder/test/includes_finder_with_regexp_test.go +++ b/src/arduino.cc/builder/test/includes_finder_with_regexp_test.go @@ -34,50 +34,10 @@ import ( "arduino.cc/builder/constants" "arduino.cc/builder/types" "github.com/stretchr/testify/require" - "os" - "path/filepath" "sort" "testing" ) -func TestIncludesFinderWithRegExpCoanOutput(t *testing.T) { - DownloadCoresAndToolsAndLibraries(t) - - context := make(map[string]interface{}) - ctx := &types.Context{ - HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, - ToolsFolders: []string{"downloaded_tools"}, - SketchLocation: filepath.Join("sketch2", "SketchWithIfDef.ino"), - FQBN: "arduino:avr:leonardo", - ArduinoAPIVersion: "10600", - Verbose: true, - } - - buildPath := SetupBuildPath(t, ctx) - defer os.RemoveAll(buildPath) - - commands := []types.Command{ - &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, - - &builder.ContainerMergeCopySketchFiles{}, - - &builder.CoanRunner{}, - - &builder.IncludesFinderWithRegExp{ContextField: constants.CTX_SOURCE}, - } - - for _, command := range commands { - err := command.Run(context, ctx) - NoError(t, err) - } - - includes := ctx.Includes - require.Equal(t, 3, len(includes)) - require.Equal(t, "Arduino.h", includes[0]) - require.Equal(t, "empty_1.h", includes[1]) - require.Equal(t, "empty_2.h", includes[2]) -} - func TestIncludesFinderWithRegExp(t *testing.T) { context := make(map[string]interface{}) ctx := &types.Context{} @@ -86,9 +46,9 @@ func TestIncludesFinderWithRegExp(t *testing.T) { "#include \n" + "^\n" + "compilation terminated." - context["source"] = output + context[constants.CTX_SOURCE] = output - parser := builder.IncludesFinderWithRegExp{ContextField: "source"} + parser := builder.IncludesFinderWithRegExp{ContextField: constants.CTX_SOURCE} err := parser.Run(context, ctx) NoError(t, err) @@ -103,9 +63,9 @@ func TestIncludesFinderWithRegExpEmptyOutput(t *testing.T) { output := "" - context["source"] = output + context[constants.CTX_SOURCE] = output - parser := builder.IncludesFinderWithRegExp{ContextField: "source"} + parser := builder.IncludesFinderWithRegExp{ContextField: constants.CTX_SOURCE} err := parser.Run(context, ctx) NoError(t, err) @@ -124,9 +84,9 @@ func TestIncludesFinderWithRegExpPreviousIncludes(t *testing.T) { "^\n" + "compilation terminated." - context["source"] = output + context[constants.CTX_SOURCE] = output - parser := builder.IncludesFinderWithRegExp{ContextField: "source"} + parser := builder.IncludesFinderWithRegExp{ContextField: constants.CTX_SOURCE} err := parser.Run(context, ctx) NoError(t, err) @@ -145,9 +105,9 @@ func TestIncludesFinderWithRegExpPaddedIncludes(t *testing.T) { " # include \n" + " ^\n" + "compilation terminated.\n" - context["source"] = output + context[constants.CTX_SOURCE] = output - parser := builder.IncludesFinderWithRegExp{ContextField: "source"} + parser := builder.IncludesFinderWithRegExp{ContextField: constants.CTX_SOURCE} err := parser.Run(context, ctx) NoError(t, err) @@ -165,9 +125,9 @@ func TestIncludesFinderWithRegExpPaddedIncludes2(t *testing.T) { " #\t\t\tinclude \n" + " ^\n" + "compilation terminated.\n" - context["source"] = output + context[constants.CTX_SOURCE] = output - parser := builder.IncludesFinderWithRegExp{ContextField: "source"} + parser := builder.IncludesFinderWithRegExp{ContextField: constants.CTX_SOURCE} err := parser.Run(context, ctx) NoError(t, err) @@ -184,9 +144,9 @@ func TestIncludesFinderWithRegExpPaddedIncludes3(t *testing.T) { output := "/some/path/sketch.ino:1:33: fatal error: SPI.h: No such file or directory\n" + "compilation terminated.\n" - context["source"] = output + context[constants.CTX_SOURCE] = output - parser := builder.IncludesFinderWithRegExp{ContextField: "source"} + parser := builder.IncludesFinderWithRegExp{ContextField: constants.CTX_SOURCE} err := parser.Run(context, ctx) NoError(t, err) diff --git a/src/arduino.cc/builder/test/setup_build_properties_test.go b/src/arduino.cc/builder/test/setup_build_properties_test.go index a1cc752f..06ac9972 100644 --- a/src/arduino.cc/builder/test/setup_build_properties_test.go +++ b/src/arduino.cc/builder/test/setup_build_properties_test.go @@ -217,10 +217,6 @@ func TestSetupBuildPropertiesWithMissingPropsFromParentPlatformTxtFiles(t *testi require.Equal(t, "\"{compiler.path}{compiler.c.cmd}\" {compiler.c.flags} -mmcu={build.mcu} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.c.extra_flags} {build.extra_flags} {includes} \"{source_file}\" -o \"{object_file}\"", buildProperties["recipe.c.o.pattern"]) require.Equal(t, "{path}/etc/avrdude.conf", buildProperties["tools.avrdude.config.path"]) - coanProps := buildProperties.SubTree(constants.BUILD_PROPERTIES_TOOLS_KEY).SubTree(constants.COAN) - require.Equal(t, "{path}/coan", coanProps["cmd.path"]) - require.Equal(t, "\"{cmd.path}\" source -m -E -P -kb {compiler.c.flags} -mmcu={build.mcu} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.c.extra_flags} {build.extra_flags} \"{source_file}\"", coanProps[constants.BUILD_PROPERTIES_PATTERN]) - require.Equal(t, Abs(t, "user_hardware/my_avr_platform/avr"), buildProperties[constants.BUILD_PROPERTIES_RUNTIME_PLATFORM_PATH]) require.Equal(t, Abs(t, "user_hardware/my_avr_platform"), buildProperties[constants.BUILD_PROPERTIES_RUNTIME_HARDWARE_PATH]) require.Equal(t, "10600", buildProperties[constants.BUILD_PROPERTIES_RUNTIME_IDE_VERSION]) From 67a198ff2ebecb7323155d864f5f03d3ff8f483c Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Fri, 15 Apr 2016 19:59:34 +0200 Subject: [PATCH 18/25] Moved Source and SourceGccMinusE into Context Some helper "Command" now accepts directly the address of the target string to work on instead of the key of the context map that contains the string. Those "arguments" are, I guess, legacy from old preprocessing and library discovery and IMHO they can be removed with a bit of refactoring. Anyway, I've intentionally limited the scope of this commit and left further optimization for the future. Signed-off-by: Cristian Maglie --- src/arduino.cc/builder/constants/constants.go | 2 -- .../builder/container_add_prototypes.go | 4 +-- .../builder/container_find_includes.go | 2 +- .../builder/ctags_target_file_saver.go | 4 +-- .../builder/external_include_replacer.go | 12 ++++----- src/arduino.cc/builder/gcc_preproc_runner.go | 2 +- .../builder/gcc_preproc_source_saver.go | 4 +-- .../builder/includes_finder_with_regexp.go | 4 +-- .../builder/print_preprocessed_source.go | 6 +---- src/arduino.cc/builder/prototypes_adder.go | 4 +-- .../builder/read_file_and_store_in_context.go | 4 +-- src/arduino.cc/builder/sketch_saver.go | 4 +-- .../builder/sketch_source_merger.go | 2 +- .../builder/test/ctags_runner_test.go | 10 ++++---- .../test/external_include_replacer_test.go | 17 ++++++------- .../test/includes_finder_with_regexp_test.go | 25 +++++++++---------- .../builder/test/prototypes_adder_test.go | 20 +++++++-------- .../read_file_and_store_in_context_test.go | 4 +-- .../builder/test/sketch_source_merger_test.go | 3 +-- src/arduino.cc/builder/types/context.go | 4 ++- 20 files changed, 63 insertions(+), 74 deletions(-) diff --git a/src/arduino.cc/builder/constants/constants.go b/src/arduino.cc/builder/constants/constants.go index eac2c69f..25d38d4d 100644 --- a/src/arduino.cc/builder/constants/constants.go +++ b/src/arduino.cc/builder/constants/constants.go @@ -76,7 +76,6 @@ const CTAGS = "ctags" const CTX_ARCHIVE_FILE_PATH_CORE = "archiveFileCore" const CTX_BUILD_CORE = "buildCore" const CTX_FILE_PATH_TO_READ = "filePathToRead" -const CTX_GCC_MINUS_E_SOURCE = "gccMinusESource" const CTX_GCC_MINUS_M_OUTPUT = "gccMinusMOutput" const CTX_HARDWARE = "hardware" const CTX_HARDWARE_REWRITE_RESULTS = "hardwareRewriteResults" @@ -87,7 +86,6 @@ const CTX_OBJECT_FILES_CORE = "objectFilesCore" const CTX_OBJECT_FILES_LIBRARIES = "objectFilesLibraries" const CTX_OBJECT_FILES_SKETCH = "objectFilesSketch" const CTX_PLATFORM_KEYS_REWRITE = "platformKeysRewrite" -const CTX_SOURCE = "source" const CTX_TOOLS = "tools" const CTX_VIDPID = "VIDPID" const EMPTY_STRING = "" diff --git a/src/arduino.cc/builder/container_add_prototypes.go b/src/arduino.cc/builder/container_add_prototypes.go index 16bd884f..af633469 100644 --- a/src/arduino.cc/builder/container_add_prototypes.go +++ b/src/arduino.cc/builder/container_add_prototypes.go @@ -41,8 +41,8 @@ type ContainerAddPrototypes struct{} func (s *ContainerAddPrototypes) Run(context map[string]interface{}, ctx *types.Context) error { commands := []types.Command{ &GCCPreprocRunner{TargetFileName: constants.FILE_CTAGS_TARGET_FOR_GCC_MINUS_E}, - &ReadFileAndStoreInContext{TargetField: constants.CTX_GCC_MINUS_E_SOURCE}, - &CTagsTargetFileSaver{SourceField: constants.CTX_GCC_MINUS_E_SOURCE, TargetFileName: constants.FILE_CTAGS_TARGET_FOR_GCC_MINUS_E}, + &ReadFileAndStoreInContext{Target: &ctx.SourceGccMinusE}, + &CTagsTargetFileSaver{Source: &ctx.SourceGccMinusE, TargetFileName: constants.FILE_CTAGS_TARGET_FOR_GCC_MINUS_E}, &ctags.CTagsRunner{}, &ctags.CTagsParser{}, &CollectCTagsFromSketchFiles{}, diff --git a/src/arduino.cc/builder/container_find_includes.go b/src/arduino.cc/builder/container_find_includes.go index fa5cf337..fafd3d0e 100644 --- a/src/arduino.cc/builder/container_find_includes.go +++ b/src/arduino.cc/builder/container_find_includes.go @@ -105,7 +105,7 @@ func findIncludesUntilDone(context map[string]interface{}, ctx *types.Context, s for !done { commands := []types.Command{ &GCCPreprocRunnerForDiscoveringIncludes{SourceFilePath: sourceFilePath, TargetFilePath: targetFilePath}, - &IncludesFinderWithRegExp{ContextField: constants.CTX_GCC_MINUS_E_SOURCE}, + &IncludesFinderWithRegExp{Source: &ctx.SourceGccMinusE}, &IncludesToIncludeFolders{}, } for _, command := range commands { diff --git a/src/arduino.cc/builder/ctags_target_file_saver.go b/src/arduino.cc/builder/ctags_target_file_saver.go index 08752776..e4d84bc2 100644 --- a/src/arduino.cc/builder/ctags_target_file_saver.go +++ b/src/arduino.cc/builder/ctags_target_file_saver.go @@ -37,12 +37,12 @@ import ( ) type CTagsTargetFileSaver struct { - SourceField string + Source *string TargetFileName string } func (s *CTagsTargetFileSaver) Run(context map[string]interface{}, ctx *types.Context) error { - source := context[s.SourceField].(string) + source := *s.Source preprocPath := ctx.PreprocPath err := utils.EnsureFolderExists(preprocPath) diff --git a/src/arduino.cc/builder/external_include_replacer.go b/src/arduino.cc/builder/external_include_replacer.go index 7bf3db14..e69a1197 100644 --- a/src/arduino.cc/builder/external_include_replacer.go +++ b/src/arduino.cc/builder/external_include_replacer.go @@ -36,14 +36,14 @@ import ( ) type ExternalIncludeReplacer struct { - SourceKey string - TargetKey string - From string - To string + Source *string + Target *string + From string + To string } func (s *ExternalIncludeReplacer) Run(context map[string]interface{}, ctx *types.Context) error { - source := context[s.SourceKey].(string) + source := *s.Source nonAbsoluteIncludes := findNonAbsoluteIncludes(ctx.Includes) for _, include := range nonAbsoluteIncludes { @@ -51,7 +51,7 @@ func (s *ExternalIncludeReplacer) Run(context map[string]interface{}, ctx *types source = strings.Replace(source, s.From+"\""+include+"\"", s.To+"\""+include+"\"", -1) } - context[s.TargetKey] = source + *s.Target = source return nil } diff --git a/src/arduino.cc/builder/gcc_preproc_runner.go b/src/arduino.cc/builder/gcc_preproc_runner.go index 284fa4f6..bf3f999c 100644 --- a/src/arduino.cc/builder/gcc_preproc_runner.go +++ b/src/arduino.cc/builder/gcc_preproc_runner.go @@ -93,7 +93,7 @@ func (s *GCCPreprocRunnerForDiscoveringIncludes) Run(context map[string]interfac return i18n.WrapError(err) } - context[constants.CTX_GCC_MINUS_E_SOURCE] = string(stderr) + ctx.SourceGccMinusE = string(stderr) return nil } diff --git a/src/arduino.cc/builder/gcc_preproc_source_saver.go b/src/arduino.cc/builder/gcc_preproc_source_saver.go index ab678762..671835a5 100644 --- a/src/arduino.cc/builder/gcc_preproc_source_saver.go +++ b/src/arduino.cc/builder/gcc_preproc_source_saver.go @@ -46,8 +46,6 @@ func (s *GCCPreprocSourceSaver) Run(context map[string]interface{}, ctx *types.C return i18n.WrapError(err) } - source := context[constants.CTX_SOURCE].(string) - - err = utils.WriteFile(filepath.Join(preprocPath, constants.FILE_GCC_PREPROC_TARGET), source) + err = utils.WriteFile(filepath.Join(preprocPath, constants.FILE_GCC_PREPROC_TARGET), ctx.Source) return i18n.WrapError(err) } diff --git a/src/arduino.cc/builder/includes_finder_with_regexp.go b/src/arduino.cc/builder/includes_finder_with_regexp.go index ffab6854..cc6c0286 100644 --- a/src/arduino.cc/builder/includes_finder_with_regexp.go +++ b/src/arduino.cc/builder/includes_finder_with_regexp.go @@ -40,11 +40,11 @@ import ( var INCLUDE_REGEXP = regexp.MustCompile("(?ms)^\\s*#[ \t]*include\\s*[<\"](\\S+)[\">]") type IncludesFinderWithRegExp struct { - ContextField string + Source *string } func (s *IncludesFinderWithRegExp) Run(context map[string]interface{}, ctx *types.Context) error { - source := context[s.ContextField].(string) + source := *s.Source matches := INCLUDE_REGEXP.FindAllStringSubmatch(source, -1) includes := []string{} diff --git a/src/arduino.cc/builder/print_preprocessed_source.go b/src/arduino.cc/builder/print_preprocessed_source.go index 48173118..ce2bd5e8 100644 --- a/src/arduino.cc/builder/print_preprocessed_source.go +++ b/src/arduino.cc/builder/print_preprocessed_source.go @@ -30,7 +30,6 @@ package builder import ( - "arduino.cc/builder/constants" "arduino.cc/builder/types" "fmt" ) @@ -38,9 +37,6 @@ import ( type PrintPreprocessedSource struct{} func (s *PrintPreprocessedSource) Run(context map[string]interface{}, ctx *types.Context) error { - source := context[constants.CTX_GCC_MINUS_E_SOURCE].(string) - - fmt.Println(source) - + fmt.Println(ctx.SourceGccMinusE) return nil } diff --git a/src/arduino.cc/builder/prototypes_adder.go b/src/arduino.cc/builder/prototypes_adder.go index 8cb34fb7..0c689396 100644 --- a/src/arduino.cc/builder/prototypes_adder.go +++ b/src/arduino.cc/builder/prototypes_adder.go @@ -41,7 +41,7 @@ type PrototypesAdder struct{} func (s *PrototypesAdder) Run(context map[string]interface{}, ctx *types.Context) error { debugOutput := ctx.DebugPreprocessor - source := context[constants.CTX_SOURCE].(string) + source := ctx.Source source = strings.Replace(source, "\r\n", "\n", -1) source = strings.Replace(source, "\r", "\n", -1) @@ -74,7 +74,7 @@ func (s *PrototypesAdder) Run(context map[string]interface{}, ctx *types.Context } fmt.Println("#END OF PREPROCESSED SOURCE") } - context[constants.CTX_SOURCE] = source + ctx.Source = source return nil } diff --git a/src/arduino.cc/builder/read_file_and_store_in_context.go b/src/arduino.cc/builder/read_file_and_store_in_context.go index 444a7dc4..f15495df 100644 --- a/src/arduino.cc/builder/read_file_and_store_in_context.go +++ b/src/arduino.cc/builder/read_file_and_store_in_context.go @@ -37,7 +37,7 @@ import ( ) type ReadFileAndStoreInContext struct { - TargetField string + Target *string } func (s *ReadFileAndStoreInContext) Run(context map[string]interface{}, ctx *types.Context) error { @@ -46,7 +46,7 @@ func (s *ReadFileAndStoreInContext) Run(context map[string]interface{}, ctx *typ return i18n.WrapError(err) } - context[s.TargetField] = string(bytes) + *s.Target = string(bytes) return nil } diff --git a/src/arduino.cc/builder/sketch_saver.go b/src/arduino.cc/builder/sketch_saver.go index ced8259d..9f6e4827 100644 --- a/src/arduino.cc/builder/sketch_saver.go +++ b/src/arduino.cc/builder/sketch_saver.go @@ -30,7 +30,6 @@ package builder import ( - "arduino.cc/builder/constants" "arduino.cc/builder/i18n" "arduino.cc/builder/types" "arduino.cc/builder/utils" @@ -42,13 +41,12 @@ type SketchSaver struct{} func (s *SketchSaver) Run(context map[string]interface{}, ctx *types.Context) error { sketch := ctx.Sketch sketchBuildPath := ctx.SketchBuildPath - source := context[constants.CTX_SOURCE].(string) err := utils.EnsureFolderExists(sketchBuildPath) if err != nil { return i18n.WrapError(err) } - err = utils.WriteFile(filepath.Join(sketchBuildPath, filepath.Base(sketch.MainFile.Name)+".cpp"), source) + err = utils.WriteFile(filepath.Join(sketchBuildPath, filepath.Base(sketch.MainFile.Name)+".cpp"), ctx.Source) return i18n.WrapError(err) } diff --git a/src/arduino.cc/builder/sketch_source_merger.go b/src/arduino.cc/builder/sketch_source_merger.go index 1b20a4b1..288c30c8 100644 --- a/src/arduino.cc/builder/sketch_source_merger.go +++ b/src/arduino.cc/builder/sketch_source_merger.go @@ -60,7 +60,7 @@ func (s *SketchSourceMerger) Run(context map[string]interface{}, ctx *types.Cont } context[constants.CTX_LINE_OFFSET] = lineOffset - context[constants.CTX_SOURCE] = source + ctx.Source = source return nil } diff --git a/src/arduino.cc/builder/test/ctags_runner_test.go b/src/arduino.cc/builder/test/ctags_runner_test.go index 0f133d43..7e188c71 100644 --- a/src/arduino.cc/builder/test/ctags_runner_test.go +++ b/src/arduino.cc/builder/test/ctags_runner_test.go @@ -71,7 +71,7 @@ func TestCTagsRunner(t *testing.T) { &builder.PrintUsedLibrariesIfVerbose{}, &builder.WarnAboutArchIncompatibleLibraries{}, - &builder.CTagsTargetFileSaver{SourceField: constants.CTX_SOURCE, TargetFileName: constants.FILE_CTAGS_TARGET}, + &builder.CTagsTargetFileSaver{Source: &ctx.Source, TargetFileName: constants.FILE_CTAGS_TARGET}, &ctags.CTagsRunner{}, } @@ -122,7 +122,7 @@ func TestCTagsRunnerSketchWithClass(t *testing.T) { &builder.PrintUsedLibrariesIfVerbose{}, &builder.WarnAboutArchIncompatibleLibraries{}, - &builder.CTagsTargetFileSaver{SourceField: constants.CTX_SOURCE, TargetFileName: constants.FILE_CTAGS_TARGET}, + &builder.CTagsTargetFileSaver{Source: &ctx.Source, TargetFileName: constants.FILE_CTAGS_TARGET}, &ctags.CTagsRunner{}, } @@ -171,7 +171,7 @@ func TestCTagsRunnerSketchWithTypename(t *testing.T) { &builder.PrintUsedLibrariesIfVerbose{}, &builder.WarnAboutArchIncompatibleLibraries{}, - &builder.CTagsTargetFileSaver{SourceField: constants.CTX_SOURCE, TargetFileName: constants.FILE_CTAGS_TARGET}, + &builder.CTagsTargetFileSaver{Source: &ctx.Source, TargetFileName: constants.FILE_CTAGS_TARGET}, &ctags.CTagsRunner{}, } @@ -219,7 +219,7 @@ func TestCTagsRunnerSketchWithNamespace(t *testing.T) { &builder.PrintUsedLibrariesIfVerbose{}, &builder.WarnAboutArchIncompatibleLibraries{}, - &builder.CTagsTargetFileSaver{SourceField: constants.CTX_SOURCE, TargetFileName: constants.FILE_CTAGS_TARGET}, + &builder.CTagsTargetFileSaver{Source: &ctx.Source, TargetFileName: constants.FILE_CTAGS_TARGET}, &ctags.CTagsRunner{}, } @@ -266,7 +266,7 @@ func TestCTagsRunnerSketchWithTemplates(t *testing.T) { &builder.PrintUsedLibrariesIfVerbose{}, &builder.WarnAboutArchIncompatibleLibraries{}, - &builder.CTagsTargetFileSaver{SourceField: constants.CTX_SOURCE, TargetFileName: constants.FILE_CTAGS_TARGET}, + &builder.CTagsTargetFileSaver{Source: &ctx.Source, TargetFileName: constants.FILE_CTAGS_TARGET}, &ctags.CTagsRunner{}, } diff --git a/src/arduino.cc/builder/test/external_include_replacer_test.go b/src/arduino.cc/builder/test/external_include_replacer_test.go index 2301a07b..b1e65b2b 100644 --- a/src/arduino.cc/builder/test/external_include_replacer_test.go +++ b/src/arduino.cc/builder/test/external_include_replacer_test.go @@ -31,7 +31,6 @@ package test import ( "arduino.cc/builder" - "arduino.cc/builder/constants" "arduino.cc/builder/types" "github.com/stretchr/testify/require" "testing" @@ -74,27 +73,27 @@ var sourceWithPragmas = "#line 1 \"sketch_with_config.ino\"\n" + func TestExternalIncludeReplacerIncludeToPragma(t *testing.T) { context := make(map[string]interface{}) ctx := &types.Context{} - context[constants.CTX_SOURCE] = sourceWithIncludes + ctx.Source = sourceWithIncludes ctx.Includes = []string{"/tmp/test184599776/sketch/config.h", "/tmp/test184599776/sketch/includes/de bug.h", "Bridge.h"} - replacer := builder.ExternalIncludeReplacer{SourceKey: constants.CTX_SOURCE, TargetKey: constants.CTX_GCC_MINUS_E_SOURCE, From: "#include ", To: "#pragma ___MY_INCLUDE___ "} + replacer := builder.ExternalIncludeReplacer{Source: &ctx.Source, Target: &ctx.SourceGccMinusE, From: "#include ", To: "#pragma ___MY_INCLUDE___ "} err := replacer.Run(context, ctx) NoError(t, err) - require.Equal(t, sourceWithIncludes, context[constants.CTX_SOURCE].(string)) - require.Equal(t, sourceWithPragmas, context[constants.CTX_GCC_MINUS_E_SOURCE].(string)) + require.Equal(t, sourceWithIncludes, ctx.Source) + require.Equal(t, sourceWithPragmas, ctx.SourceGccMinusE) } func TestExternalIncludeReplacerPragmaToInclude(t *testing.T) { context := make(map[string]interface{}) ctx := &types.Context{} - context[constants.CTX_GCC_MINUS_E_SOURCE] = sourceWithPragmas + ctx.SourceGccMinusE = sourceWithPragmas ctx.Includes = []string{"/tmp/test184599776/sketch/config.h", "/tmp/test184599776/sketch/includes/de bug.h", "Bridge.h"} - replacer := builder.ExternalIncludeReplacer{SourceKey: constants.CTX_GCC_MINUS_E_SOURCE, TargetKey: constants.CTX_GCC_MINUS_E_SOURCE, From: "#pragma ___MY_INCLUDE___ ", To: "#include "} + replacer := builder.ExternalIncludeReplacer{Source: &ctx.SourceGccMinusE, Target: &ctx.SourceGccMinusE, From: "#pragma ___MY_INCLUDE___ ", To: "#include "} err := replacer.Run(context, ctx) NoError(t, err) - require.Nil(t, context[constants.CTX_SOURCE]) - require.Equal(t, sourceWithIncludes, context[constants.CTX_GCC_MINUS_E_SOURCE].(string)) + require.Empty(t, ctx.Source) + require.Equal(t, sourceWithIncludes, ctx.SourceGccMinusE) } diff --git a/src/arduino.cc/builder/test/includes_finder_with_regexp_test.go b/src/arduino.cc/builder/test/includes_finder_with_regexp_test.go index d20d6d03..0766beda 100644 --- a/src/arduino.cc/builder/test/includes_finder_with_regexp_test.go +++ b/src/arduino.cc/builder/test/includes_finder_with_regexp_test.go @@ -31,7 +31,6 @@ package test import ( "arduino.cc/builder" - "arduino.cc/builder/constants" "arduino.cc/builder/types" "github.com/stretchr/testify/require" "sort" @@ -46,9 +45,9 @@ func TestIncludesFinderWithRegExp(t *testing.T) { "#include \n" + "^\n" + "compilation terminated." - context[constants.CTX_SOURCE] = output + ctx.Source = output - parser := builder.IncludesFinderWithRegExp{ContextField: constants.CTX_SOURCE} + parser := builder.IncludesFinderWithRegExp{Source: &ctx.Source} err := parser.Run(context, ctx) NoError(t, err) @@ -63,9 +62,9 @@ func TestIncludesFinderWithRegExpEmptyOutput(t *testing.T) { output := "" - context[constants.CTX_SOURCE] = output + ctx.Source = output - parser := builder.IncludesFinderWithRegExp{ContextField: constants.CTX_SOURCE} + parser := builder.IncludesFinderWithRegExp{Source: &ctx.Source} err := parser.Run(context, ctx) NoError(t, err) @@ -84,9 +83,9 @@ func TestIncludesFinderWithRegExpPreviousIncludes(t *testing.T) { "^\n" + "compilation terminated." - context[constants.CTX_SOURCE] = output + ctx.Source = output - parser := builder.IncludesFinderWithRegExp{ContextField: constants.CTX_SOURCE} + parser := builder.IncludesFinderWithRegExp{Source: &ctx.Source} err := parser.Run(context, ctx) NoError(t, err) @@ -105,9 +104,9 @@ func TestIncludesFinderWithRegExpPaddedIncludes(t *testing.T) { " # include \n" + " ^\n" + "compilation terminated.\n" - context[constants.CTX_SOURCE] = output + ctx.Source = output - parser := builder.IncludesFinderWithRegExp{ContextField: constants.CTX_SOURCE} + parser := builder.IncludesFinderWithRegExp{Source: &ctx.Source} err := parser.Run(context, ctx) NoError(t, err) @@ -125,9 +124,9 @@ func TestIncludesFinderWithRegExpPaddedIncludes2(t *testing.T) { " #\t\t\tinclude \n" + " ^\n" + "compilation terminated.\n" - context[constants.CTX_SOURCE] = output + ctx.Source = output - parser := builder.IncludesFinderWithRegExp{ContextField: constants.CTX_SOURCE} + parser := builder.IncludesFinderWithRegExp{Source: &ctx.Source} err := parser.Run(context, ctx) NoError(t, err) @@ -144,9 +143,9 @@ func TestIncludesFinderWithRegExpPaddedIncludes3(t *testing.T) { output := "/some/path/sketch.ino:1:33: fatal error: SPI.h: No such file or directory\n" + "compilation terminated.\n" - context[constants.CTX_SOURCE] = output + ctx.Source = output - parser := builder.IncludesFinderWithRegExp{ContextField: constants.CTX_SOURCE} + parser := builder.IncludesFinderWithRegExp{Source: &ctx.Source} err := parser.Run(context, ctx) NoError(t, err) diff --git a/src/arduino.cc/builder/test/prototypes_adder_test.go b/src/arduino.cc/builder/test/prototypes_adder_test.go index 6720029c..441afd3f 100644 --- a/src/arduino.cc/builder/test/prototypes_adder_test.go +++ b/src/arduino.cc/builder/test/prototypes_adder_test.go @@ -125,7 +125,7 @@ func TestPrototypesAdderSketchWithIfDef(t *testing.T) { } preprocessed := LoadAndInterpolate(t, filepath.Join("sketch2", "SketchWithIfDef.preprocessed.txt"), context, ctx) - require.Equal(t, preprocessed, strings.Replace(context[constants.CTX_SOURCE].(string), "\r\n", "\n", -1)) + require.Equal(t, preprocessed, strings.Replace(ctx.Source, "\r\n", "\n", -1)) } func TestPrototypesAdderBaladuino(t *testing.T) { @@ -166,7 +166,7 @@ func TestPrototypesAdderBaladuino(t *testing.T) { } preprocessed := LoadAndInterpolate(t, filepath.Join("sketch3", "Baladuino.preprocessed.txt"), context, ctx) - require.Equal(t, preprocessed, strings.Replace(context[constants.CTX_SOURCE].(string), "\r\n", "\n", -1)) + require.Equal(t, preprocessed, strings.Replace(ctx.Source, "\r\n", "\n", -1)) } func TestPrototypesAdderCharWithEscapedDoubleQuote(t *testing.T) { @@ -207,7 +207,7 @@ func TestPrototypesAdderCharWithEscapedDoubleQuote(t *testing.T) { } preprocessed := LoadAndInterpolate(t, filepath.Join("sketch4", "CharWithEscapedDoubleQuote.preprocessed.txt"), context, ctx) - require.Equal(t, preprocessed, strings.Replace(context[constants.CTX_SOURCE].(string), "\r\n", "\n", -1)) + require.Equal(t, preprocessed, strings.Replace(ctx.Source, "\r\n", "\n", -1)) } func TestPrototypesAdderIncludeBetweenMultilineComment(t *testing.T) { @@ -248,7 +248,7 @@ func TestPrototypesAdderIncludeBetweenMultilineComment(t *testing.T) { } preprocessed := LoadAndInterpolate(t, filepath.Join("sketch5", "IncludeBetweenMultilineComment.preprocessed.txt"), context, ctx) - require.Equal(t, preprocessed, strings.Replace(context[constants.CTX_SOURCE].(string), "\r\n", "\n", -1)) + require.Equal(t, preprocessed, strings.Replace(ctx.Source, "\r\n", "\n", -1)) } func TestPrototypesAdderLineContinuations(t *testing.T) { @@ -289,7 +289,7 @@ func TestPrototypesAdderLineContinuations(t *testing.T) { } preprocessed := LoadAndInterpolate(t, filepath.Join("sketch6", "LineContinuations.preprocessed.txt"), context, ctx) - require.Equal(t, preprocessed, strings.Replace(context[constants.CTX_SOURCE].(string), "\r\n", "\n", -1)) + require.Equal(t, preprocessed, strings.Replace(ctx.Source, "\r\n", "\n", -1)) } func TestPrototypesAdderStringWithComment(t *testing.T) { @@ -330,7 +330,7 @@ func TestPrototypesAdderStringWithComment(t *testing.T) { } preprocessed := LoadAndInterpolate(t, filepath.Join("sketch7", "StringWithComment.preprocessed.txt"), context, ctx) - require.Equal(t, preprocessed, strings.Replace(context[constants.CTX_SOURCE].(string), "\r\n", "\n", -1)) + require.Equal(t, preprocessed, strings.Replace(ctx.Source, "\r\n", "\n", -1)) } func TestPrototypesAdderSketchWithStruct(t *testing.T) { @@ -371,7 +371,7 @@ func TestPrototypesAdderSketchWithStruct(t *testing.T) { } preprocessed := LoadAndInterpolate(t, filepath.Join("sketch8", "SketchWithStruct.preprocessed.txt"), context, ctx) - obtained := strings.Replace(context[constants.CTX_SOURCE].(string), "\r\n", "\n", -1) + obtained := strings.Replace(ctx.Source, "\r\n", "\n", -1) // ctags based preprocessing removes the space after "dostuff", but this is still OK // TODO: remove this exception when moving to a more powerful parser preprocessed = strings.Replace(preprocessed, "void dostuff (A_NEW_TYPE * bar);", "void dostuff(A_NEW_TYPE * bar);", 1) @@ -423,7 +423,7 @@ func TestPrototypesAdderSketchWithConfig(t *testing.T) { require.Equal(t, "#line 13 \""+absoluteSketchLocation+"\"\nvoid setup();\n#line 17 \""+absoluteSketchLocation+"\"\nvoid loop();\n#line 13 \""+absoluteSketchLocation+"\"\n", ctx.PrototypesSection) preprocessed := LoadAndInterpolate(t, filepath.Join("sketch_with_config", "sketch_with_config.preprocessed.txt"), context, ctx) - require.Equal(t, preprocessed, strings.Replace(context[constants.CTX_SOURCE].(string), "\r\n", "\n", -1)) + require.Equal(t, preprocessed, strings.Replace(ctx.Source, "\r\n", "\n", -1)) } func TestPrototypesAdderSketchNoFunctionsTwoFiles(t *testing.T) { @@ -794,7 +794,7 @@ func TestPrototypesAdderSketchWithIfDef2(t *testing.T) { require.Equal(t, "#line 5 \""+absoluteSketchLocation+"\"\nvoid elseBranch();\n#line 9 \""+absoluteSketchLocation+"\"\nvoid f1();\n#line 10 \""+absoluteSketchLocation+"\"\nvoid f2();\n#line 12 \""+absoluteSketchLocation+"\"\nvoid setup();\n#line 14 \""+absoluteSketchLocation+"\"\nvoid loop();\n#line 5 \""+absoluteSketchLocation+"\"\n", ctx.PrototypesSection) expectedSource := LoadAndInterpolate(t, filepath.Join("sketch_with_ifdef", "sketch.preprocessed.txt"), context, ctx) - require.Equal(t, expectedSource, strings.Replace(context[constants.CTX_SOURCE].(string), "\r\n", "\n", -1)) + require.Equal(t, expectedSource, strings.Replace(ctx.Source, "\r\n", "\n", -1)) } func TestPrototypesAdderSketchWithIfDef2SAM(t *testing.T) { @@ -841,7 +841,7 @@ func TestPrototypesAdderSketchWithIfDef2SAM(t *testing.T) { require.Equal(t, "#line 2 \""+absoluteSketchLocation+"\"\nvoid ifBranch();\n#line 9 \""+absoluteSketchLocation+"\"\nvoid f1();\n#line 10 \""+absoluteSketchLocation+"\"\nvoid f2();\n#line 12 \""+absoluteSketchLocation+"\"\nvoid setup();\n#line 14 \""+absoluteSketchLocation+"\"\nvoid loop();\n#line 2 \""+absoluteSketchLocation+"\"\n", ctx.PrototypesSection) expectedSource := LoadAndInterpolate(t, filepath.Join("sketch_with_ifdef", "sketch.preprocessed.SAM.txt"), context, ctx) - require.Equal(t, expectedSource, strings.Replace(context[constants.CTX_SOURCE].(string), "\r\n", "\n", -1)) + require.Equal(t, expectedSource, strings.Replace(ctx.Source, "\r\n", "\n", -1)) } func TestPrototypesAdderSketchWithConst(t *testing.T) { diff --git a/src/arduino.cc/builder/test/read_file_and_store_in_context_test.go b/src/arduino.cc/builder/test/read_file_and_store_in_context_test.go index bc949780..1a1d269c 100644 --- a/src/arduino.cc/builder/test/read_file_and_store_in_context_test.go +++ b/src/arduino.cc/builder/test/read_file_and_store_in_context_test.go @@ -51,9 +51,9 @@ func TestReadFileAndStoreInContext(t *testing.T) { ctx := &types.Context{} context[constants.CTX_FILE_PATH_TO_READ] = file.Name() - command := &builder.ReadFileAndStoreInContext{TargetField: constants.CTX_GCC_MINUS_E_SOURCE} + command := &builder.ReadFileAndStoreInContext{Target: &ctx.SourceGccMinusE} err = command.Run(context, ctx) NoError(t, err) - require.Equal(t, "test test\nciao", context[constants.CTX_GCC_MINUS_E_SOURCE].(string)) + require.Equal(t, "test test\nciao", ctx.SourceGccMinusE) } diff --git a/src/arduino.cc/builder/test/sketch_source_merger_test.go b/src/arduino.cc/builder/test/sketch_source_merger_test.go index e3f79011..c6adc880 100644 --- a/src/arduino.cc/builder/test/sketch_source_merger_test.go +++ b/src/arduino.cc/builder/test/sketch_source_merger_test.go @@ -32,7 +32,6 @@ package test import ( "arduino.cc/builder" - "arduino.cc/builder/constants" "arduino.cc/builder/types" "github.com/stretchr/testify/require" "path/filepath" @@ -56,7 +55,7 @@ func TestMergeSketch(t *testing.T) { NoError(t, err) } - source := context[constants.CTX_SOURCE].(string) + source := ctx.Source expected_source := LoadAndInterpolate(t, filepath.Join("sketch1", "merged_sketch.txt"), context, ctx) require.Equal(t, expected_source, strings.Replace(source, "\r\n", "\n", -1)) diff --git a/src/arduino.cc/builder/types/context.go b/src/arduino.cc/builder/types/context.go index 37eab214..316a2a5f 100644 --- a/src/arduino.cc/builder/types/context.go +++ b/src/arduino.cc/builder/types/context.go @@ -35,7 +35,9 @@ type Context struct { CollectedSourceFiles *UniqueStringQueue FoldersWithSourceFiles *UniqueSourceFolderQueue - Sketch *Sketch + Sketch *Sketch + Source string + SourceGccMinusE string WarningsLevel string From 6784cbfa2dc64530ce0ae35876421c1b5567d2ce Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Fri, 15 Apr 2016 20:20:23 +0200 Subject: [PATCH 19/25] Moved Tools, Hardware and USBVidPid in Context Probably a better name for the Packages structure is Hardware, something to see later. Signed-off-by: Cristian Maglie --- src/arduino.cc/arduino-builder/main.go | 4 ++-- .../builder/add_build_board_property_if_missing.go | 2 +- ...ing_build_properties_from_parent_platform_txt_files.go | 3 +-- src/arduino.cc/builder/constants/constants.go | 3 --- src/arduino.cc/builder/hardware_loader.go | 2 +- .../builder/load_vid_pid_specific_properties.go | 5 ++--- src/arduino.cc/builder/rewrite_hardware_keys.go | 2 +- src/arduino.cc/builder/setup_build_properties.go | 4 ++-- src/arduino.cc/builder/target_board_resolver.go | 2 +- src/arduino.cc/builder/test/hardware_loader_test.go | 8 ++++---- .../builder/test/load_vid_pid_specific_properties_test.go | 3 +-- src/arduino.cc/builder/test/rewrite_hardware_keys_test.go | 4 ++-- src/arduino.cc/builder/test/tools_loader_test.go | 7 +++---- src/arduino.cc/builder/tools_loader.go | 2 +- src/arduino.cc/builder/types/context.go | 3 +++ 15 files changed, 25 insertions(+), 29 deletions(-) diff --git a/src/arduino.cc/arduino-builder/main.go b/src/arduino.cc/arduino-builder/main.go index 2b7f348d..d3fa879d 100644 --- a/src/arduino.cc/arduino-builder/main.go +++ b/src/arduino.cc/arduino-builder/main.go @@ -41,7 +41,6 @@ import ( "syscall" "arduino.cc/builder" - "arduino.cc/builder/constants" "arduino.cc/builder/gohasissues" "arduino.cc/builder/i18n" "arduino.cc/builder/props" @@ -258,8 +257,9 @@ func main() { } ctx.BuildPath = buildPath + // FLAG_VID_PID if *vidPidFlag != "" { - context[constants.CTX_VIDPID] = *vidPidFlag + ctx.USBVidPid = *vidPidFlag } if flag.NArg() > 0 { diff --git a/src/arduino.cc/builder/add_build_board_property_if_missing.go b/src/arduino.cc/builder/add_build_board_property_if_missing.go index 9bb7f218..8bb0bebe 100644 --- a/src/arduino.cc/builder/add_build_board_property_if_missing.go +++ b/src/arduino.cc/builder/add_build_board_property_if_missing.go @@ -39,7 +39,7 @@ import ( type AddBuildBoardPropertyIfMissing struct{} func (s *AddBuildBoardPropertyIfMissing) Run(context map[string]interface{}, ctx *types.Context) error { - packages := context[constants.CTX_HARDWARE].(*types.Packages) + packages := ctx.Hardware logger := ctx.GetLogger() for _, aPackage := range packages.Packages { diff --git a/src/arduino.cc/builder/add_missing_build_properties_from_parent_platform_txt_files.go b/src/arduino.cc/builder/add_missing_build_properties_from_parent_platform_txt_files.go index 8fbf130e..8bf53d2f 100644 --- a/src/arduino.cc/builder/add_missing_build_properties_from_parent_platform_txt_files.go +++ b/src/arduino.cc/builder/add_missing_build_properties_from_parent_platform_txt_files.go @@ -30,14 +30,13 @@ package builder import ( - "arduino.cc/builder/constants" "arduino.cc/builder/types" ) type AddMissingBuildPropertiesFromParentPlatformTxtFiles struct{} func (s *AddMissingBuildPropertiesFromParentPlatformTxtFiles) Run(context map[string]interface{}, ctx *types.Context) error { - packages := context[constants.CTX_HARDWARE].(*types.Packages) + packages := ctx.Hardware targetPackage := ctx.TargetPackage buildProperties := ctx.BuildProperties diff --git a/src/arduino.cc/builder/constants/constants.go b/src/arduino.cc/builder/constants/constants.go index 25d38d4d..f14a0cc7 100644 --- a/src/arduino.cc/builder/constants/constants.go +++ b/src/arduino.cc/builder/constants/constants.go @@ -77,7 +77,6 @@ const CTX_ARCHIVE_FILE_PATH_CORE = "archiveFileCore" const CTX_BUILD_CORE = "buildCore" const CTX_FILE_PATH_TO_READ = "filePathToRead" const CTX_GCC_MINUS_M_OUTPUT = "gccMinusMOutput" -const CTX_HARDWARE = "hardware" const CTX_HARDWARE_REWRITE_RESULTS = "hardwareRewriteResults" const CTX_INCLUDE_SECTION = "includeSection" const CTX_INCLUDES_JUST_FOUND = "includesJustFound" @@ -86,8 +85,6 @@ const CTX_OBJECT_FILES_CORE = "objectFilesCore" const CTX_OBJECT_FILES_LIBRARIES = "objectFilesLibraries" const CTX_OBJECT_FILES_SKETCH = "objectFilesSketch" const CTX_PLATFORM_KEYS_REWRITE = "platformKeysRewrite" -const CTX_TOOLS = "tools" -const CTX_VIDPID = "VIDPID" const EMPTY_STRING = "" const FILE_BOARDS_LOCAL_TXT = "boards.local.txt" const FILE_BOARDS_TXT = "boards.txt" diff --git a/src/arduino.cc/builder/hardware_loader.go b/src/arduino.cc/builder/hardware_loader.go index a1efc319..2bea5f81 100644 --- a/src/arduino.cc/builder/hardware_loader.go +++ b/src/arduino.cc/builder/hardware_loader.go @@ -92,7 +92,7 @@ func (s *HardwareLoader) Run(context map[string]interface{}, ctx *types.Context) } } - context[constants.CTX_HARDWARE] = packages + ctx.Hardware = packages return nil } diff --git a/src/arduino.cc/builder/load_vid_pid_specific_properties.go b/src/arduino.cc/builder/load_vid_pid_specific_properties.go index 1cb13ee1..dd844922 100644 --- a/src/arduino.cc/builder/load_vid_pid_specific_properties.go +++ b/src/arduino.cc/builder/load_vid_pid_specific_properties.go @@ -34,7 +34,6 @@ import ( "arduino.cc/builder/i18n" "arduino.cc/builder/props" "arduino.cc/builder/types" - "arduino.cc/builder/utils" "strconv" "strings" ) @@ -42,11 +41,11 @@ import ( type LoadVIDPIDSpecificProperties struct{} func (s *LoadVIDPIDSpecificProperties) Run(context map[string]interface{}, ctx *types.Context) error { - if !utils.MapHas(context, constants.CTX_VIDPID) { + if ctx.USBVidPid == "" { return nil } - vidPid := context[constants.CTX_VIDPID].(string) + vidPid := ctx.USBVidPid vidPid = strings.ToLower(vidPid) vidPidParts := strings.Split(vidPid, "_") vid := vidPidParts[0] diff --git a/src/arduino.cc/builder/rewrite_hardware_keys.go b/src/arduino.cc/builder/rewrite_hardware_keys.go index 9cb6a113..650829b8 100644 --- a/src/arduino.cc/builder/rewrite_hardware_keys.go +++ b/src/arduino.cc/builder/rewrite_hardware_keys.go @@ -42,7 +42,7 @@ func (s *RewriteHardwareKeys) Run(context map[string]interface{}, ctx *types.Con return nil } - packages := context[constants.CTX_HARDWARE].(*types.Packages) + packages := ctx.Hardware platformKeysRewrite := context[constants.CTX_PLATFORM_KEYS_REWRITE].(types.PlatforKeysRewrite) hardwareRewriteResults := context[constants.CTX_HARDWARE_REWRITE_RESULTS].(map[*types.Platform][]types.PlatforKeyRewrite) diff --git a/src/arduino.cc/builder/setup_build_properties.go b/src/arduino.cc/builder/setup_build_properties.go index 2ea6127f..d3f777d3 100644 --- a/src/arduino.cc/builder/setup_build_properties.go +++ b/src/arduino.cc/builder/setup_build_properties.go @@ -43,7 +43,7 @@ import ( type SetupBuildProperties struct{} func (s *SetupBuildProperties) Run(context map[string]interface{}, ctx *types.Context) error { - packages := context[constants.CTX_HARDWARE].(*types.Packages) + packages := ctx.Hardware targetPlatform := ctx.TargetPlatform actualPlatform := ctx.ActualPlatform @@ -86,7 +86,7 @@ func (s *SetupBuildProperties) Run(context map[string]interface{}, ctx *types.Co buildProperties[constants.BUILD_PROPERTIES_BUILD_VARIANT_PATH] = filepath.Join(variantPlatform.Folder, constants.FOLDER_VARIANTS, variant) } - tools := context[constants.CTX_TOOLS].([]*types.Tool) + tools := ctx.Tools for _, tool := range tools { buildProperties[constants.BUILD_PROPERTIES_RUNTIME_TOOLS_PREFIX+tool.Name+constants.BUILD_PROPERTIES_RUNTIME_TOOLS_SUFFIX] = tool.Folder buildProperties[constants.BUILD_PROPERTIES_RUNTIME_TOOLS_PREFIX+tool.Name+"-"+tool.Version+constants.BUILD_PROPERTIES_RUNTIME_TOOLS_SUFFIX] = tool.Folder diff --git a/src/arduino.cc/builder/target_board_resolver.go b/src/arduino.cc/builder/target_board_resolver.go index 1a730b9b..c0a31db3 100644 --- a/src/arduino.cc/builder/target_board_resolver.go +++ b/src/arduino.cc/builder/target_board_resolver.go @@ -47,7 +47,7 @@ func (s *TargetBoardResolver) Run(context map[string]interface{}, ctx *types.Con targetPlatformName := fqbnParts[1] targetBoardName := fqbnParts[2] - packages := context[constants.CTX_HARDWARE].(*types.Packages) + packages := ctx.Hardware logger := ctx.GetLogger() diff --git a/src/arduino.cc/builder/test/hardware_loader_test.go b/src/arduino.cc/builder/test/hardware_loader_test.go index 7b890ecb..f6a3dbce 100644 --- a/src/arduino.cc/builder/test/hardware_loader_test.go +++ b/src/arduino.cc/builder/test/hardware_loader_test.go @@ -55,7 +55,7 @@ func TestLoadHardware(t *testing.T) { NoError(t, err) } - packages := context[constants.CTX_HARDWARE].(*types.Packages) + packages := ctx.Hardware require.Equal(t, 2, len(packages.Packages)) require.NotNil(t, packages.Packages["arduino"]) require.Equal(t, 2, len(packages.Packages["arduino"].Platforms)) @@ -103,7 +103,7 @@ func TestLoadHardwareMixingUserHardwareFolder(t *testing.T) { NoError(t, err) } - packages := context[constants.CTX_HARDWARE].(*types.Packages) + packages := ctx.Hardware if runtime.GOOS == "windows" { //a package is a symlink, and windows does not support them @@ -171,7 +171,7 @@ func TestLoadHardwareWithBoardManagerFolderStructure(t *testing.T) { NoError(t, err) } - packages := context[constants.CTX_HARDWARE].(*types.Packages) + packages := ctx.Hardware require.Equal(t, 3, len(packages.Packages)) require.NotNil(t, packages.Packages["arduino"]) require.Equal(t, 1, len(packages.Packages["arduino"].Platforms)) @@ -220,7 +220,7 @@ func TestLoadLotsOfHardware(t *testing.T) { NoError(t, err) } - packages := context[constants.CTX_HARDWARE].(*types.Packages) + packages := ctx.Hardware if runtime.GOOS == "windows" { //a package is a symlink, and windows does not support them diff --git a/src/arduino.cc/builder/test/load_vid_pid_specific_properties_test.go b/src/arduino.cc/builder/test/load_vid_pid_specific_properties_test.go index 42d9d532..f8830f87 100644 --- a/src/arduino.cc/builder/test/load_vid_pid_specific_properties_test.go +++ b/src/arduino.cc/builder/test/load_vid_pid_specific_properties_test.go @@ -31,7 +31,6 @@ package test import ( "arduino.cc/builder" - "arduino.cc/builder/constants" "arduino.cc/builder/types" "github.com/stretchr/testify/require" "os" @@ -85,7 +84,7 @@ func TestLoadVIDPIDSpecificProperties(t *testing.T) { buildPath := SetupBuildPath(t, ctx) defer os.RemoveAll(buildPath) - context[constants.CTX_VIDPID] = "0x2341_0x0237" + ctx.USBVidPid = "0x2341_0x0237" commands := []types.Command{ &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, diff --git a/src/arduino.cc/builder/test/rewrite_hardware_keys_test.go b/src/arduino.cc/builder/test/rewrite_hardware_keys_test.go index 0edd81ad..ab8a6ac4 100644 --- a/src/arduino.cc/builder/test/rewrite_hardware_keys_test.go +++ b/src/arduino.cc/builder/test/rewrite_hardware_keys_test.go @@ -53,7 +53,7 @@ func TestRewriteHardwareKeys(t *testing.T) { platform.Properties[constants.PLATFORM_NAME] = "A test platform" platform.Properties[constants.BUILD_PROPERTIES_COMPILER_PATH] = "{runtime.ide.path}/hardware/tools/avr/bin/" - context[constants.CTX_HARDWARE] = packages + ctx.Hardware = packages rewrite := types.PlatforKeyRewrite{Key: constants.BUILD_PROPERTIES_COMPILER_PATH, OldValue: "{runtime.ide.path}/hardware/tools/avr/bin/", NewValue: "{runtime.tools.avr-gcc.path}/bin/"} platformKeysRewrite := types.PlatforKeysRewrite{Rewrites: []types.PlatforKeyRewrite{rewrite}} @@ -89,7 +89,7 @@ func TestRewriteHardwareKeysWithRewritingDisabled(t *testing.T) { platform.Properties[constants.BUILD_PROPERTIES_COMPILER_PATH] = "{runtime.ide.path}/hardware/tools/avr/bin/" platform.Properties[constants.REWRITING] = constants.REWRITING_DISABLED - context[constants.CTX_HARDWARE] = packages + ctx.Hardware = packages rewrite := types.PlatforKeyRewrite{Key: constants.BUILD_PROPERTIES_COMPILER_PATH, OldValue: "{runtime.ide.path}/hardware/tools/avr/bin/", NewValue: "{runtime.tools.avr-gcc.path}/bin/"} platformKeysRewrite := types.PlatforKeysRewrite{Rewrites: []types.PlatforKeyRewrite{rewrite}} diff --git a/src/arduino.cc/builder/test/tools_loader_test.go b/src/arduino.cc/builder/test/tools_loader_test.go index 49e07d86..f9a83482 100644 --- a/src/arduino.cc/builder/test/tools_loader_test.go +++ b/src/arduino.cc/builder/test/tools_loader_test.go @@ -31,7 +31,6 @@ package test import ( "arduino.cc/builder" - "arduino.cc/builder/constants" "arduino.cc/builder/types" "github.com/stretchr/testify/require" "sort" @@ -65,7 +64,7 @@ func TestLoadTools(t *testing.T) { err := loader.Run(context, ctx) NoError(t, err) - tools := context[constants.CTX_TOOLS].([]*types.Tool) + tools := ctx.Tools require.Equal(t, 7, len(tools)) sort.Sort(ByToolIDAndVersion(tools)) @@ -104,7 +103,7 @@ func TestLoadToolsWithBoardManagerFolderStructure(t *testing.T) { err := loader.Run(context, ctx) NoError(t, err) - tools := context[constants.CTX_TOOLS].([]*types.Tool) + tools := ctx.Tools require.Equal(t, 3, len(tools)) sort.Sort(ByToolIDAndVersion(tools)) @@ -131,7 +130,7 @@ func TestLoadLotsOfTools(t *testing.T) { err := loader.Run(context, ctx) NoError(t, err) - tools := context[constants.CTX_TOOLS].([]*types.Tool) + tools := ctx.Tools require.Equal(t, 9, len(tools)) require.Equal(t, "arm-none-eabi-gcc", tools[0].Name) diff --git a/src/arduino.cc/builder/tools_loader.go b/src/arduino.cc/builder/tools_loader.go index c76891b3..a9b622c4 100644 --- a/src/arduino.cc/builder/tools_loader.go +++ b/src/arduino.cc/builder/tools_loader.go @@ -72,7 +72,7 @@ func (s *ToolsLoader) Run(context map[string]interface{}, ctx *types.Context) er } } - context[constants.CTX_TOOLS] = tools + ctx.Tools = tools return nil } diff --git a/src/arduino.cc/builder/types/context.go b/src/arduino.cc/builder/types/context.go index 316a2a5f..0d0177b9 100644 --- a/src/arduino.cc/builder/types/context.go +++ b/src/arduino.cc/builder/types/context.go @@ -20,10 +20,13 @@ type Context struct { BuildOptionsJson string BuildOptionsJsonPrevious string + Hardware *Packages + Tools []*Tool TargetBoard *Board TargetPackage *Package TargetPlatform *Platform ActualPlatform *Platform + USBVidPid string BuildProperties props.PropertiesMap BuildPath string From 169bcd96dc64e2c728fc9441a182c688876ec475 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Fri, 15 Apr 2016 20:26:15 +0200 Subject: [PATCH 20/25] Moved "gcc -M" output in Context It seems legacy, shall we remove it? eventually may turn out to be useful in the future? Signed-off-by: Cristian Maglie --- src/arduino.cc/builder/constants/constants.go | 1 - src/arduino.cc/builder/gcc_minus_m_output_parser.go | 2 +- src/arduino.cc/builder/includes_finder_with_gcc.go | 2 +- .../builder/test/gcc_minus_m_output_parser_test.go | 7 +++---- src/arduino.cc/builder/types/context.go | 1 + 5 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/arduino.cc/builder/constants/constants.go b/src/arduino.cc/builder/constants/constants.go index f14a0cc7..b66b920c 100644 --- a/src/arduino.cc/builder/constants/constants.go +++ b/src/arduino.cc/builder/constants/constants.go @@ -76,7 +76,6 @@ const CTAGS = "ctags" const CTX_ARCHIVE_FILE_PATH_CORE = "archiveFileCore" const CTX_BUILD_CORE = "buildCore" const CTX_FILE_PATH_TO_READ = "filePathToRead" -const CTX_GCC_MINUS_M_OUTPUT = "gccMinusMOutput" const CTX_HARDWARE_REWRITE_RESULTS = "hardwareRewriteResults" const CTX_INCLUDE_SECTION = "includeSection" const CTX_INCLUDES_JUST_FOUND = "includesJustFound" diff --git a/src/arduino.cc/builder/gcc_minus_m_output_parser.go b/src/arduino.cc/builder/gcc_minus_m_output_parser.go index 3bf84b6a..9ba82fa5 100644 --- a/src/arduino.cc/builder/gcc_minus_m_output_parser.go +++ b/src/arduino.cc/builder/gcc_minus_m_output_parser.go @@ -39,7 +39,7 @@ import ( type GCCMinusMOutputParser struct{} func (s *GCCMinusMOutputParser) Run(context map[string]interface{}, ctx *types.Context) error { - output := context[constants.CTX_GCC_MINUS_M_OUTPUT].(string) + output := ctx.OutputGccMinusM rows := strings.Split(output, "\n") includes := make([]string, 0) diff --git a/src/arduino.cc/builder/includes_finder_with_gcc.go b/src/arduino.cc/builder/includes_finder_with_gcc.go index abdc678a..59a2c322 100644 --- a/src/arduino.cc/builder/includes_finder_with_gcc.go +++ b/src/arduino.cc/builder/includes_finder_with_gcc.go @@ -65,7 +65,7 @@ func (s *IncludesFinderWithGCC) Run(context map[string]interface{}, ctx *types.C return i18n.WrapError(err) } - context[constants.CTX_GCC_MINUS_M_OUTPUT] = string(output) + ctx.OutputGccMinusM = string(output) return nil } diff --git a/src/arduino.cc/builder/test/gcc_minus_m_output_parser_test.go b/src/arduino.cc/builder/test/gcc_minus_m_output_parser_test.go index 066136dc..39cd8754 100644 --- a/src/arduino.cc/builder/test/gcc_minus_m_output_parser_test.go +++ b/src/arduino.cc/builder/test/gcc_minus_m_output_parser_test.go @@ -31,7 +31,6 @@ package test import ( "arduino.cc/builder" - "arduino.cc/builder/constants" "arduino.cc/builder/types" "github.com/stretchr/testify/require" "testing" @@ -49,7 +48,7 @@ func TestGCCMinusMOutputParser(t *testing.T) { "\n" + "Bridge.h:\n" - context[constants.CTX_GCC_MINUS_M_OUTPUT] = output + ctx.OutputGccMinusM = output parser := builder.GCCMinusMOutputParser{} err := parser.Run(context, ctx) @@ -68,7 +67,7 @@ func TestGCCMinusMOutputParserEmptyOutput(t *testing.T) { output := "sketch.ino.o: /tmp/test699709208/sketch/sketch.ino.cpp" - context[constants.CTX_GCC_MINUS_M_OUTPUT] = output + ctx.OutputGccMinusM = output parser := builder.GCCMinusMOutputParser{} err := parser.Run(context, ctx) @@ -93,7 +92,7 @@ func TestGCCMinusMOutputParserFirstLineOnMultipleLines(t *testing.T) { "\n" + "Bridge.h:\n" - context[constants.CTX_GCC_MINUS_M_OUTPUT] = output + ctx.OutputGccMinusM = output parser := builder.GCCMinusMOutputParser{} err := parser.Run(context, ctx) diff --git a/src/arduino.cc/builder/types/context.go b/src/arduino.cc/builder/types/context.go index 0d0177b9..cc8533d7 100644 --- a/src/arduino.cc/builder/types/context.go +++ b/src/arduino.cc/builder/types/context.go @@ -51,6 +51,7 @@ type Context struct { ImportedLibraries []*Library LibrariesResolutionResults map[string]LibraryResolutionResult IncludeFolders []string + OutputGccMinusM string // C++ Parsing CTagsOutput string From 1ff963283b1c8d2af54c791ae10f6b9d52a2807b Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Fri, 15 Apr 2016 21:04:08 +0200 Subject: [PATCH 21/25] Moved some paths into Context Signed-off-by: Cristian Maglie --- src/arduino.cc/builder/constants/constants.go | 5 ----- src/arduino.cc/builder/phases/core_builder.go | 4 ++-- .../builder/phases/libraries_builder.go | 2 +- src/arduino.cc/builder/phases/linker.go | 8 ++++---- src/arduino.cc/builder/phases/sketch_builder.go | 3 +-- .../builder/setup_build_properties.go | 2 +- src/arduino.cc/builder/target_board_resolver.go | 2 +- .../builder/test/target_board_resolver_test.go | 2 +- src/arduino.cc/builder/types/context.go | 17 +++++++++++------ 9 files changed, 22 insertions(+), 23 deletions(-) diff --git a/src/arduino.cc/builder/constants/constants.go b/src/arduino.cc/builder/constants/constants.go index b66b920c..553b9e40 100644 --- a/src/arduino.cc/builder/constants/constants.go +++ b/src/arduino.cc/builder/constants/constants.go @@ -73,16 +73,11 @@ const BUILD_PROPERTIES_SOURCE_PATH = "build.source.path" const BUILD_PROPERTIES_TOOLS_KEY = "tools" const BUILD_PROPERTIES_VID = "vid" const CTAGS = "ctags" -const CTX_ARCHIVE_FILE_PATH_CORE = "archiveFileCore" -const CTX_BUILD_CORE = "buildCore" const CTX_FILE_PATH_TO_READ = "filePathToRead" const CTX_HARDWARE_REWRITE_RESULTS = "hardwareRewriteResults" const CTX_INCLUDE_SECTION = "includeSection" const CTX_INCLUDES_JUST_FOUND = "includesJustFound" const CTX_LINE_OFFSET = "lineOffset" -const CTX_OBJECT_FILES_CORE = "objectFilesCore" -const CTX_OBJECT_FILES_LIBRARIES = "objectFilesLibraries" -const CTX_OBJECT_FILES_SKETCH = "objectFilesSketch" const CTX_PLATFORM_KEYS_REWRITE = "platformKeysRewrite" const EMPTY_STRING = "" const FILE_BOARDS_LOCAL_TXT = "boards.local.txt" diff --git a/src/arduino.cc/builder/phases/core_builder.go b/src/arduino.cc/builder/phases/core_builder.go index df62ff05..63d4f16d 100644 --- a/src/arduino.cc/builder/phases/core_builder.go +++ b/src/arduino.cc/builder/phases/core_builder.go @@ -57,8 +57,8 @@ func (s *CoreBuilder) Run(context map[string]interface{}, ctx *types.Context) er return i18n.WrapError(err) } - context[constants.CTX_ARCHIVE_FILE_PATH_CORE] = archiveFile - context[constants.CTX_OBJECT_FILES_CORE] = objectFiles + ctx.CoreArchiveFilePath = archiveFile + ctx.CoreObjectsFiles = objectFiles return nil } diff --git a/src/arduino.cc/builder/phases/libraries_builder.go b/src/arduino.cc/builder/phases/libraries_builder.go index fe3704c1..2aafe569 100644 --- a/src/arduino.cc/builder/phases/libraries_builder.go +++ b/src/arduino.cc/builder/phases/libraries_builder.go @@ -62,7 +62,7 @@ func (s *LibrariesBuilder) Run(context map[string]interface{}, ctx *types.Contex return i18n.WrapError(err) } - context[constants.CTX_OBJECT_FILES_LIBRARIES] = objectFiles + ctx.LibrariesObjectFiles = objectFiles return nil } diff --git a/src/arduino.cc/builder/phases/linker.go b/src/arduino.cc/builder/phases/linker.go index 651ea2d3..166b2b0d 100644 --- a/src/arduino.cc/builder/phases/linker.go +++ b/src/arduino.cc/builder/phases/linker.go @@ -43,16 +43,16 @@ import ( type Linker struct{} func (s *Linker) Run(context map[string]interface{}, ctx *types.Context) error { - objectFilesSketch := context[constants.CTX_OBJECT_FILES_SKETCH].([]string) - objectFilesLibraries := context[constants.CTX_OBJECT_FILES_LIBRARIES].([]string) - objectFilesCore := context[constants.CTX_OBJECT_FILES_CORE].([]string) + objectFilesSketch := ctx.SketchObjectFiles + objectFilesLibraries := ctx.LibrariesObjectFiles + objectFilesCore := ctx.CoreObjectsFiles var objectFiles []string objectFiles = append(objectFiles, objectFilesSketch...) objectFiles = append(objectFiles, objectFilesLibraries...) objectFiles = append(objectFiles, objectFilesCore...) - coreArchiveFilePath := context[constants.CTX_ARCHIVE_FILE_PATH_CORE].(string) + coreArchiveFilePath := ctx.CoreArchiveFilePath buildPath := ctx.BuildPath coreDotARelPath, err := filepath.Rel(buildPath, coreArchiveFilePath) if err != nil { diff --git a/src/arduino.cc/builder/phases/sketch_builder.go b/src/arduino.cc/builder/phases/sketch_builder.go index da4a70b1..35cdd65f 100644 --- a/src/arduino.cc/builder/phases/sketch_builder.go +++ b/src/arduino.cc/builder/phases/sketch_builder.go @@ -31,7 +31,6 @@ package phases import ( "arduino.cc/builder/builder_utils" - "arduino.cc/builder/constants" "arduino.cc/builder/i18n" "arduino.cc/builder/types" "arduino.cc/builder/utils" @@ -59,7 +58,7 @@ func (s *SketchBuilder) Run(context map[string]interface{}, ctx *types.Context) return i18n.WrapError(err) } - context[constants.CTX_OBJECT_FILES_SKETCH] = objectFiles + ctx.SketchObjectFiles = objectFiles return nil } diff --git a/src/arduino.cc/builder/setup_build_properties.go b/src/arduino.cc/builder/setup_build_properties.go index d3f777d3..c61241f9 100644 --- a/src/arduino.cc/builder/setup_build_properties.go +++ b/src/arduino.cc/builder/setup_build_properties.go @@ -62,7 +62,7 @@ func (s *SetupBuildProperties) Run(context map[string]interface{}, ctx *types.Co } buildProperties[constants.BUILD_PROPERTIES_BUILD_ARCH] = strings.ToUpper(targetPlatform.PlatformId) - buildProperties[constants.BUILD_PROPERTIES_BUILD_CORE] = context[constants.CTX_BUILD_CORE].(string) + buildProperties[constants.BUILD_PROPERTIES_BUILD_CORE] = ctx.BuildCore buildProperties[constants.BUILD_PROPERTIES_BUILD_CORE_PATH] = filepath.Join(actualPlatform.Folder, constants.FOLDER_CORES, buildProperties[constants.BUILD_PROPERTIES_BUILD_CORE]) buildProperties[constants.BUILD_PROPERTIES_BUILD_SYSTEM_PATH] = filepath.Join(actualPlatform.Folder, constants.FOLDER_SYSTEM) buildProperties[constants.BUILD_PROPERTIES_RUNTIME_PLATFORM_PATH] = targetPlatform.Folder diff --git a/src/arduino.cc/builder/target_board_resolver.go b/src/arduino.cc/builder/target_board_resolver.go index c0a31db3..30b69854 100644 --- a/src/arduino.cc/builder/target_board_resolver.go +++ b/src/arduino.cc/builder/target_board_resolver.go @@ -97,7 +97,7 @@ func (s *TargetBoardResolver) Run(context map[string]interface{}, ctx *types.Con actualPlatform = targetPlatform } - context[constants.CTX_BUILD_CORE] = core + ctx.BuildCore = core ctx.ActualPlatform = actualPlatform return nil diff --git a/src/arduino.cc/builder/test/target_board_resolver_test.go b/src/arduino.cc/builder/test/target_board_resolver_test.go index 9d7b55ae..fa673332 100644 --- a/src/arduino.cc/builder/test/target_board_resolver_test.go +++ b/src/arduino.cc/builder/test/target_board_resolver_test.go @@ -194,6 +194,6 @@ func TestTargetBoardResolverCustomCore(t *testing.T) { require.Equal(t, "avr", targetPlatform.PlatformId) targetBoard := ctx.TargetBoard require.Equal(t, "attiny841", targetBoard.BoardId) - require.Equal(t, "tiny841", context[constants.CTX_BUILD_CORE].(string)) + require.Equal(t, "tiny841", ctx.BuildCore) require.Equal(t, "tiny14", targetBoard.Properties[constants.BUILD_PROPERTIES_BUILD_VARIANT]) } diff --git a/src/arduino.cc/builder/types/context.go b/src/arduino.cc/builder/types/context.go index cc8533d7..ce78bf0b 100644 --- a/src/arduino.cc/builder/types/context.go +++ b/src/arduino.cc/builder/types/context.go @@ -28,12 +28,17 @@ type Context struct { ActualPlatform *Platform USBVidPid string - BuildProperties props.PropertiesMap - BuildPath string - SketchBuildPath string - CoreBuildPath string - LibrariesBuildPath string - PreprocPath string + BuildProperties props.PropertiesMap + BuildCore string + BuildPath string + SketchBuildPath string + CoreBuildPath string + CoreArchiveFilePath string + CoreObjectsFiles []string + LibrariesBuildPath string + LibrariesObjectFiles []string + PreprocPath string + SketchObjectFiles []string CollectedSourceFiles *UniqueStringQueue FoldersWithSourceFiles *UniqueSourceFolderQueue From 2161b9ee480ace55f9a123cc99462af51d0eca42 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Sat, 16 Apr 2016 10:06:52 +0200 Subject: [PATCH 22/25] Moved PlatformRewrite* structures in Context Probably these structures should be renamed to something more meaningful Signed-off-by: Cristian Maglie --- .../builder/add_additional_entries_to_context.go | 2 +- src/arduino.cc/builder/constants/constants.go | 2 -- src/arduino.cc/builder/platform_keys_rewrite_loader.go | 2 +- src/arduino.cc/builder/rewrite_hardware_keys.go | 7 +++---- .../builder/test/platform_keys_rewrite_loader_test.go | 2 +- src/arduino.cc/builder/test/rewrite_hardware_keys_test.go | 4 ++-- src/arduino.cc/builder/types/context.go | 3 +++ src/arduino.cc/builder/types/types.go | 4 ++++ src/arduino.cc/builder/warn_about_platform_rewrites.go | 2 +- 9 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/arduino.cc/builder/add_additional_entries_to_context.go b/src/arduino.cc/builder/add_additional_entries_to_context.go index 938a6f1f..b78d6f31 100644 --- a/src/arduino.cc/builder/add_additional_entries_to_context.go +++ b/src/arduino.cc/builder/add_additional_entries_to_context.go @@ -72,7 +72,7 @@ func (s *AddAdditionalEntriesToContext) Run(context map[string]interface{}, ctx ctx.FoldersWithSourceFiles = &types.UniqueSourceFolderQueue{} ctx.LibrariesResolutionResults = make(map[string]types.LibraryResolutionResult) - context[constants.CTX_HARDWARE_REWRITE_RESULTS] = make(map[*types.Platform][]types.PlatforKeyRewrite) + ctx.HardwareRewriteResults = make(map[*types.Platform][]types.PlatforKeyRewrite) return nil } diff --git a/src/arduino.cc/builder/constants/constants.go b/src/arduino.cc/builder/constants/constants.go index 553b9e40..8421e6be 100644 --- a/src/arduino.cc/builder/constants/constants.go +++ b/src/arduino.cc/builder/constants/constants.go @@ -74,11 +74,9 @@ const BUILD_PROPERTIES_TOOLS_KEY = "tools" const BUILD_PROPERTIES_VID = "vid" const CTAGS = "ctags" const CTX_FILE_PATH_TO_READ = "filePathToRead" -const CTX_HARDWARE_REWRITE_RESULTS = "hardwareRewriteResults" const CTX_INCLUDE_SECTION = "includeSection" const CTX_INCLUDES_JUST_FOUND = "includesJustFound" const CTX_LINE_OFFSET = "lineOffset" -const CTX_PLATFORM_KEYS_REWRITE = "platformKeysRewrite" const EMPTY_STRING = "" const FILE_BOARDS_LOCAL_TXT = "boards.local.txt" const FILE_BOARDS_TXT = "boards.txt" diff --git a/src/arduino.cc/builder/platform_keys_rewrite_loader.go b/src/arduino.cc/builder/platform_keys_rewrite_loader.go index 3eba6f75..0aa64e0c 100644 --- a/src/arduino.cc/builder/platform_keys_rewrite_loader.go +++ b/src/arduino.cc/builder/platform_keys_rewrite_loader.go @@ -79,7 +79,7 @@ func (s *PlatformKeysRewriteLoader) Run(context map[string]interface{}, ctx *typ } } - context[constants.CTX_PLATFORM_KEYS_REWRITE] = platformKeysRewrite + ctx.PlatformKeyRewrites = platformKeysRewrite return nil } diff --git a/src/arduino.cc/builder/rewrite_hardware_keys.go b/src/arduino.cc/builder/rewrite_hardware_keys.go index 650829b8..26781da1 100644 --- a/src/arduino.cc/builder/rewrite_hardware_keys.go +++ b/src/arduino.cc/builder/rewrite_hardware_keys.go @@ -32,19 +32,18 @@ package builder import ( "arduino.cc/builder/constants" "arduino.cc/builder/types" - "arduino.cc/builder/utils" ) type RewriteHardwareKeys struct{} func (s *RewriteHardwareKeys) Run(context map[string]interface{}, ctx *types.Context) error { - if !utils.MapHas(context, constants.CTX_PLATFORM_KEYS_REWRITE) { + if ctx.PlatformKeyRewrites.Empty() { return nil } packages := ctx.Hardware - platformKeysRewrite := context[constants.CTX_PLATFORM_KEYS_REWRITE].(types.PlatforKeysRewrite) - hardwareRewriteResults := context[constants.CTX_HARDWARE_REWRITE_RESULTS].(map[*types.Platform][]types.PlatforKeyRewrite) + platformKeysRewrite := ctx.PlatformKeyRewrites + hardwareRewriteResults := ctx.HardwareRewriteResults for _, aPackage := range packages.Packages { for _, platform := range aPackage.Platforms { diff --git a/src/arduino.cc/builder/test/platform_keys_rewrite_loader_test.go b/src/arduino.cc/builder/test/platform_keys_rewrite_loader_test.go index cb0d770e..ea16a8b3 100644 --- a/src/arduino.cc/builder/test/platform_keys_rewrite_loader_test.go +++ b/src/arduino.cc/builder/test/platform_keys_rewrite_loader_test.go @@ -53,7 +53,7 @@ func TestLoadPlatformKeysRewrite(t *testing.T) { NoError(t, err) } - platformKeysRewrite := context[constants.CTX_PLATFORM_KEYS_REWRITE].(types.PlatforKeysRewrite) + platformKeysRewrite := ctx.PlatformKeyRewrites require.Equal(t, 13, len(platformKeysRewrite.Rewrites)) require.Equal(t, constants.BUILD_PROPERTIES_COMPILER_PATH, platformKeysRewrite.Rewrites[0].Key) diff --git a/src/arduino.cc/builder/test/rewrite_hardware_keys_test.go b/src/arduino.cc/builder/test/rewrite_hardware_keys_test.go index ab8a6ac4..2d1a07f2 100644 --- a/src/arduino.cc/builder/test/rewrite_hardware_keys_test.go +++ b/src/arduino.cc/builder/test/rewrite_hardware_keys_test.go @@ -57,7 +57,7 @@ func TestRewriteHardwareKeys(t *testing.T) { rewrite := types.PlatforKeyRewrite{Key: constants.BUILD_PROPERTIES_COMPILER_PATH, OldValue: "{runtime.ide.path}/hardware/tools/avr/bin/", NewValue: "{runtime.tools.avr-gcc.path}/bin/"} platformKeysRewrite := types.PlatforKeysRewrite{Rewrites: []types.PlatforKeyRewrite{rewrite}} - context[constants.CTX_PLATFORM_KEYS_REWRITE] = platformKeysRewrite + ctx.PlatformKeyRewrites = platformKeysRewrite commands := []types.Command{ &builder.AddAdditionalEntriesToContext{}, @@ -94,7 +94,7 @@ func TestRewriteHardwareKeysWithRewritingDisabled(t *testing.T) { rewrite := types.PlatforKeyRewrite{Key: constants.BUILD_PROPERTIES_COMPILER_PATH, OldValue: "{runtime.ide.path}/hardware/tools/avr/bin/", NewValue: "{runtime.tools.avr-gcc.path}/bin/"} platformKeysRewrite := types.PlatforKeysRewrite{Rewrites: []types.PlatforKeyRewrite{rewrite}} - context[constants.CTX_PLATFORM_KEYS_REWRITE] = platformKeysRewrite + ctx.PlatformKeyRewrites = platformKeysRewrite commands := []types.Command{ &builder.AddAdditionalEntriesToContext{}, diff --git a/src/arduino.cc/builder/types/context.go b/src/arduino.cc/builder/types/context.go index ce78bf0b..cf51f621 100644 --- a/src/arduino.cc/builder/types/context.go +++ b/src/arduino.cc/builder/types/context.go @@ -28,6 +28,9 @@ type Context struct { ActualPlatform *Platform USBVidPid string + PlatformKeyRewrites PlatforKeysRewrite + HardwareRewriteResults map[*Platform][]PlatforKeyRewrite + BuildProperties props.PropertiesMap BuildCore string BuildPath string diff --git a/src/arduino.cc/builder/types/types.go b/src/arduino.cc/builder/types/types.go index f882cdd7..6345da89 100644 --- a/src/arduino.cc/builder/types/types.go +++ b/src/arduino.cc/builder/types/types.go @@ -140,6 +140,10 @@ type PlatforKeysRewrite struct { Rewrites []PlatforKeyRewrite } +func (p *PlatforKeysRewrite) Empty() bool { + return len(p.Rewrites) == 0 +} + type PlatforKeyRewrite struct { Key string OldValue string diff --git a/src/arduino.cc/builder/warn_about_platform_rewrites.go b/src/arduino.cc/builder/warn_about_platform_rewrites.go index 74ff67b1..f3fca20c 100644 --- a/src/arduino.cc/builder/warn_about_platform_rewrites.go +++ b/src/arduino.cc/builder/warn_about_platform_rewrites.go @@ -43,7 +43,7 @@ func (s *WarnAboutPlatformRewrites) Run(context map[string]interface{}, ctx *typ } logger := ctx.GetLogger() - hardwareRewriteResults := context[constants.CTX_HARDWARE_REWRITE_RESULTS].(map[*types.Platform][]types.PlatforKeyRewrite) + hardwareRewriteResults := ctx.HardwareRewriteResults targetPlatform := ctx.TargetPlatform actualPlatform := ctx.ActualPlatform From 602e02b086efaa2922b532c4d3d74d722169a0aa Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Sat, 16 Apr 2016 13:01:59 +0200 Subject: [PATCH 23/25] FileToRead field moved in Context Signed-off-by: Cristian Maglie --- src/arduino.cc/builder/constants/constants.go | 1 - src/arduino.cc/builder/gcc_preproc_runner.go | 2 +- src/arduino.cc/builder/read_file_and_store_in_context.go | 3 +-- .../builder/test/read_file_and_store_in_context_test.go | 3 +-- src/arduino.cc/builder/types/context.go | 3 +++ 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/arduino.cc/builder/constants/constants.go b/src/arduino.cc/builder/constants/constants.go index 8421e6be..06c46cba 100644 --- a/src/arduino.cc/builder/constants/constants.go +++ b/src/arduino.cc/builder/constants/constants.go @@ -73,7 +73,6 @@ const BUILD_PROPERTIES_SOURCE_PATH = "build.source.path" const BUILD_PROPERTIES_TOOLS_KEY = "tools" const BUILD_PROPERTIES_VID = "vid" const CTAGS = "ctags" -const CTX_FILE_PATH_TO_READ = "filePathToRead" const CTX_INCLUDE_SECTION = "includeSection" const CTX_INCLUDES_JUST_FOUND = "includesJustFound" const CTX_LINE_OFFSET = "lineOffset" diff --git a/src/arduino.cc/builder/gcc_preproc_runner.go b/src/arduino.cc/builder/gcc_preproc_runner.go index bf3f999c..832f4d72 100644 --- a/src/arduino.cc/builder/gcc_preproc_runner.go +++ b/src/arduino.cc/builder/gcc_preproc_runner.go @@ -64,7 +64,7 @@ func (s *GCCPreprocRunner) Run(context map[string]interface{}, ctx *types.Contex return i18n.WrapError(err) } - context[constants.CTX_FILE_PATH_TO_READ] = targetFilePath + ctx.FileToRead = targetFilePath return nil } diff --git a/src/arduino.cc/builder/read_file_and_store_in_context.go b/src/arduino.cc/builder/read_file_and_store_in_context.go index f15495df..ecd65d9a 100644 --- a/src/arduino.cc/builder/read_file_and_store_in_context.go +++ b/src/arduino.cc/builder/read_file_and_store_in_context.go @@ -30,7 +30,6 @@ package builder import ( - "arduino.cc/builder/constants" "arduino.cc/builder/i18n" "arduino.cc/builder/types" "io/ioutil" @@ -41,7 +40,7 @@ type ReadFileAndStoreInContext struct { } func (s *ReadFileAndStoreInContext) Run(context map[string]interface{}, ctx *types.Context) error { - bytes, err := ioutil.ReadFile(context[constants.CTX_FILE_PATH_TO_READ].(string)) + bytes, err := ioutil.ReadFile(ctx.FileToRead) if err != nil { return i18n.WrapError(err) } diff --git a/src/arduino.cc/builder/test/read_file_and_store_in_context_test.go b/src/arduino.cc/builder/test/read_file_and_store_in_context_test.go index 1a1d269c..74f793b0 100644 --- a/src/arduino.cc/builder/test/read_file_and_store_in_context_test.go +++ b/src/arduino.cc/builder/test/read_file_and_store_in_context_test.go @@ -31,7 +31,6 @@ package test import ( "arduino.cc/builder" - "arduino.cc/builder/constants" "arduino.cc/builder/types" "arduino.cc/builder/utils" "github.com/stretchr/testify/require" @@ -49,7 +48,7 @@ func TestReadFileAndStoreInContext(t *testing.T) { context := make(map[string]interface{}) ctx := &types.Context{} - context[constants.CTX_FILE_PATH_TO_READ] = file.Name() + ctx.FileToRead = file.Name() command := &builder.ReadFileAndStoreInContext{Target: &ctx.SourceGccMinusE} err = command.Run(context, ctx) diff --git a/src/arduino.cc/builder/types/context.go b/src/arduino.cc/builder/types/context.go index cf51f621..6963572d 100644 --- a/src/arduino.cc/builder/types/context.go +++ b/src/arduino.cc/builder/types/context.go @@ -82,6 +82,9 @@ type Context struct { logger i18n.Logger DebugLevel int + // ReadFileAndStoreInContext command + FileToRead string + // For now it is used in conjunction with the old map[string]string, but // it will be slowly populated with all the fields currently used in the // map in the next commits. From 8b74855c973510e13238c35a7e92cd9dd6128742 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Sat, 16 Apr 2016 13:12:37 +0200 Subject: [PATCH 24/25] Moved Include preprocessing and discovery fields into Context Signed-off-by: Cristian Maglie --- src/arduino.cc/builder/constants/constants.go | 3 --- .../builder/container_find_includes.go | 4 +-- .../builder/includes_finder_with_regexp.go | 3 +-- src/arduino.cc/builder/prototypes_adder.go | 2 +- .../builder/sketch_source_merger.go | 5 ++-- .../builder/test/prototypes_adder_test.go | 25 +++++++++---------- src/arduino.cc/builder/types/context.go | 3 +++ 7 files changed, 21 insertions(+), 24 deletions(-) diff --git a/src/arduino.cc/builder/constants/constants.go b/src/arduino.cc/builder/constants/constants.go index 06c46cba..15d93824 100644 --- a/src/arduino.cc/builder/constants/constants.go +++ b/src/arduino.cc/builder/constants/constants.go @@ -73,9 +73,6 @@ const BUILD_PROPERTIES_SOURCE_PATH = "build.source.path" const BUILD_PROPERTIES_TOOLS_KEY = "tools" const BUILD_PROPERTIES_VID = "vid" const CTAGS = "ctags" -const CTX_INCLUDE_SECTION = "includeSection" -const CTX_INCLUDES_JUST_FOUND = "includesJustFound" -const CTX_LINE_OFFSET = "lineOffset" const EMPTY_STRING = "" const FILE_BOARDS_LOCAL_TXT = "boards.local.txt" const FILE_BOARDS_TXT = "boards.txt" diff --git a/src/arduino.cc/builder/container_find_includes.go b/src/arduino.cc/builder/container_find_includes.go index fafd3d0e..2de30fb6 100644 --- a/src/arduino.cc/builder/container_find_includes.go +++ b/src/arduino.cc/builder/container_find_includes.go @@ -114,14 +114,14 @@ func findIncludesUntilDone(context map[string]interface{}, ctx *types.Context, s return i18n.WrapError(err) } } - if len(context[constants.CTX_INCLUDES_JUST_FOUND].([]string)) == 0 { + if len(ctx.IncludesJustFound) == 0 { done = true } else if len(ctx.ImportedLibraries) == len(importedLibraries) { err := runCommand(context, ctx, &GCCPreprocRunner{TargetFileName: constants.FILE_CTAGS_TARGET_FOR_GCC_MINUS_E}) return i18n.WrapError(err) } importedLibraries = ctx.ImportedLibraries - context[constants.CTX_INCLUDES_JUST_FOUND] = []string{} + ctx.IncludesJustFound = []string{} } return nil } diff --git a/src/arduino.cc/builder/includes_finder_with_regexp.go b/src/arduino.cc/builder/includes_finder_with_regexp.go index cc6c0286..2130307e 100644 --- a/src/arduino.cc/builder/includes_finder_with_regexp.go +++ b/src/arduino.cc/builder/includes_finder_with_regexp.go @@ -30,7 +30,6 @@ package builder import ( - "arduino.cc/builder/constants" "arduino.cc/builder/types" "arduino.cc/builder/utils" "regexp" @@ -58,7 +57,7 @@ func (s *IncludesFinderWithRegExp) Run(context map[string]interface{}, ctx *type } } - context[constants.CTX_INCLUDES_JUST_FOUND] = includes + ctx.IncludesJustFound = includes ctx.Includes = utils.AppendIfNotPresent(ctx.Includes, includes...) return nil } diff --git a/src/arduino.cc/builder/prototypes_adder.go b/src/arduino.cc/builder/prototypes_adder.go index 0c689396..bfd3087a 100644 --- a/src/arduino.cc/builder/prototypes_adder.go +++ b/src/arduino.cc/builder/prototypes_adder.go @@ -53,7 +53,7 @@ func (s *PrototypesAdder) Run(context map[string]interface{}, ctx *types.Context return nil } - insertionLine := firstFunctionLine + context[constants.CTX_LINE_OFFSET].(int) - 1 + insertionLine := firstFunctionLine + ctx.LineOffset - 1 firstFunctionChar := len(strings.Join(sourceRows[:insertionLine], "\n")) + 1 prototypeSection := composePrototypeSection(firstFunctionLine, ctx.Prototypes) ctx.PrototypesSection = prototypeSection diff --git a/src/arduino.cc/builder/sketch_source_merger.go b/src/arduino.cc/builder/sketch_source_merger.go index 288c30c8..e44d2de6 100644 --- a/src/arduino.cc/builder/sketch_source_merger.go +++ b/src/arduino.cc/builder/sketch_source_merger.go @@ -31,7 +31,6 @@ package builder import ( - "arduino.cc/builder/constants" "arduino.cc/builder/types" "regexp" "strings" @@ -50,7 +49,7 @@ func (s *SketchSourceMerger) Run(context map[string]interface{}, ctx *types.Cont } includeSection += "#line 1 \"" + strings.Replace((&sketch.MainFile).Name, "\\", "\\\\", -1) + "\"\n" lineOffset++ - context[constants.CTX_INCLUDE_SECTION] = includeSection + ctx.IncludeSection = includeSection source := includeSection source += addSourceWrappedWithLineDirective(&sketch.MainFile) @@ -59,7 +58,7 @@ func (s *SketchSourceMerger) Run(context map[string]interface{}, ctx *types.Cont source += addSourceWrappedWithLineDirective(&file) } - context[constants.CTX_LINE_OFFSET] = lineOffset + ctx.LineOffset = lineOffset ctx.Source = source return nil diff --git a/src/arduino.cc/builder/test/prototypes_adder_test.go b/src/arduino.cc/builder/test/prototypes_adder_test.go index 441afd3f..941e74bd 100644 --- a/src/arduino.cc/builder/test/prototypes_adder_test.go +++ b/src/arduino.cc/builder/test/prototypes_adder_test.go @@ -32,7 +32,6 @@ package test import ( "arduino.cc/builder" - "arduino.cc/builder/constants" "arduino.cc/builder/types" "github.com/stretchr/testify/require" "os" @@ -83,7 +82,7 @@ func TestPrototypesAdderBridgeExample(t *testing.T) { NoError(t, err) } - require.Equal(t, "#include \n#line 1 \""+absoluteSketchLocation+"\"\n", context[constants.CTX_INCLUDE_SECTION].(string)) + require.Equal(t, "#include \n#line 1 \""+absoluteSketchLocation+"\"\n", ctx.IncludeSection) require.Equal(t, "#line 33 \""+absoluteSketchLocation+"\"\nvoid setup();\n#line 46 \""+absoluteSketchLocation+"\"\nvoid loop();\n#line 62 \""+absoluteSketchLocation+"\"\nvoid process(BridgeClient client);\n#line 82 \""+absoluteSketchLocation+"\"\nvoid digitalCommand(BridgeClient client);\n#line 109 \""+absoluteSketchLocation+"\"\nvoid analogCommand(BridgeClient client);\n#line 149 \""+absoluteSketchLocation+"\"\nvoid modeCommand(BridgeClient client);\n#line 33 \""+absoluteSketchLocation+"\"\n", ctx.PrototypesSection) } @@ -419,7 +418,7 @@ func TestPrototypesAdderSketchWithConfig(t *testing.T) { NoError(t, err) } - require.Equal(t, "#include \n#line 1 \""+absoluteSketchLocation+"\"\n", context[constants.CTX_INCLUDE_SECTION].(string)) + require.Equal(t, "#include \n#line 1 \""+absoluteSketchLocation+"\"\n", ctx.IncludeSection) require.Equal(t, "#line 13 \""+absoluteSketchLocation+"\"\nvoid setup();\n#line 17 \""+absoluteSketchLocation+"\"\nvoid loop();\n#line 13 \""+absoluteSketchLocation+"\"\n", ctx.PrototypesSection) preprocessed := LoadAndInterpolate(t, filepath.Join("sketch_with_config", "sketch_with_config.preprocessed.txt"), context, ctx) @@ -466,7 +465,7 @@ func TestPrototypesAdderSketchNoFunctionsTwoFiles(t *testing.T) { NoError(t, err) } - require.Equal(t, "#include \n#line 1 \""+absoluteSketchLocation+"\"\n", context[constants.CTX_INCLUDE_SECTION].(string)) + require.Equal(t, "#include \n#line 1 \""+absoluteSketchLocation+"\"\n", ctx.IncludeSection) require.Equal(t, "", ctx.PrototypesSection) } @@ -510,7 +509,7 @@ func TestPrototypesAdderSketchNoFunctions(t *testing.T) { NoError(t, err) } - require.Equal(t, "#include \n#line 1 \""+absoluteSketchLocation+"\"\n", context[constants.CTX_INCLUDE_SECTION].(string)) + require.Equal(t, "#include \n#line 1 \""+absoluteSketchLocation+"\"\n", ctx.IncludeSection) require.Equal(t, "", ctx.PrototypesSection) } @@ -554,7 +553,7 @@ func TestPrototypesAdderSketchWithDefaultArgs(t *testing.T) { NoError(t, err) } - require.Equal(t, "#include \n#line 1 \""+absoluteSketchLocation+"\"\n", context[constants.CTX_INCLUDE_SECTION].(string)) + require.Equal(t, "#include \n#line 1 \""+absoluteSketchLocation+"\"\n", ctx.IncludeSection) require.Equal(t, "#line 4 \""+absoluteSketchLocation+"\"\nvoid setup();\n#line 7 \""+absoluteSketchLocation+"\"\nvoid loop();\n#line 1 \""+absoluteSketchLocation+"\"\n", ctx.PrototypesSection) } @@ -598,7 +597,7 @@ func TestPrototypesAdderSketchWithInlineFunction(t *testing.T) { NoError(t, err) } - require.Equal(t, "#include \n#line 1 \""+absoluteSketchLocation+"\"\n", context[constants.CTX_INCLUDE_SECTION].(string)) + require.Equal(t, "#include \n#line 1 \""+absoluteSketchLocation+"\"\n", ctx.IncludeSection) expected := "#line 1 \"" + absoluteSketchLocation + "\"\nvoid setup();\n#line 2 \"" + absoluteSketchLocation + "\"\nvoid loop();\n#line 4 \"" + absoluteSketchLocation + "\"\nshort unsigned int testInt();\n#line 8 \"" + absoluteSketchLocation + "\"\nstatic int8_t testInline();\n#line 12 \"" + absoluteSketchLocation + "\"\n__attribute__((always_inline)) uint8_t testAttribute();\n#line 1 \"" + absoluteSketchLocation + "\"\n" obtained := ctx.PrototypesSection @@ -653,7 +652,7 @@ func TestPrototypesAdderSketchWithFunctionSignatureInsideIFDEF(t *testing.T) { NoError(t, err) } - require.Equal(t, "#include \n#line 1 \""+absoluteSketchLocation+"\"\n", context[constants.CTX_INCLUDE_SECTION].(string)) + require.Equal(t, "#include \n#line 1 \""+absoluteSketchLocation+"\"\n", ctx.IncludeSection) require.Equal(t, "#line 1 \""+absoluteSketchLocation+"\"\nvoid setup();\n#line 3 \""+absoluteSketchLocation+"\"\nvoid loop();\n#line 15 \""+absoluteSketchLocation+"\"\nint8_t adalight();\n#line 1 \""+absoluteSketchLocation+"\"\n", ctx.PrototypesSection) } @@ -697,7 +696,7 @@ func TestPrototypesAdderSketchWithUSBCON(t *testing.T) { NoError(t, err) } - require.Equal(t, "#include \n#line 1 \""+absoluteSketchLocation+"\"\n", context[constants.CTX_INCLUDE_SECTION].(string)) + require.Equal(t, "#include \n#line 1 \""+absoluteSketchLocation+"\"\n", ctx.IncludeSection) require.Equal(t, "#line 5 \""+absoluteSketchLocation+"\"\nvoid ciao();\n#line 10 \""+absoluteSketchLocation+"\"\nvoid setup();\n#line 15 \""+absoluteSketchLocation+"\"\nvoid loop();\n#line 5 \""+absoluteSketchLocation+"\"\n", ctx.PrototypesSection) } @@ -740,7 +739,7 @@ func TestPrototypesAdderSketchWithTypename(t *testing.T) { NoError(t, err) } - require.Equal(t, "#include \n#line 1 \""+absoluteSketchLocation+"\"\n", context[constants.CTX_INCLUDE_SECTION].(string)) + require.Equal(t, "#include \n#line 1 \""+absoluteSketchLocation+"\"\n", ctx.IncludeSection) expected := "#line 6 \"" + absoluteSketchLocation + "\"\nvoid setup();\n#line 10 \"" + absoluteSketchLocation + "\"\nvoid loop();\n#line 12 \"" + absoluteSketchLocation + "\"\ntypename Foo::Bar func();\n#line 6 \"" + absoluteSketchLocation + "\"\n" obtained := ctx.PrototypesSection // ctags based preprocessing ignores line with typename @@ -790,7 +789,7 @@ func TestPrototypesAdderSketchWithIfDef2(t *testing.T) { NoError(t, err) } - require.Equal(t, "#include \n#line 1 \""+absoluteSketchLocation+"\"\n", context[constants.CTX_INCLUDE_SECTION].(string)) + require.Equal(t, "#include \n#line 1 \""+absoluteSketchLocation+"\"\n", ctx.IncludeSection) require.Equal(t, "#line 5 \""+absoluteSketchLocation+"\"\nvoid elseBranch();\n#line 9 \""+absoluteSketchLocation+"\"\nvoid f1();\n#line 10 \""+absoluteSketchLocation+"\"\nvoid f2();\n#line 12 \""+absoluteSketchLocation+"\"\nvoid setup();\n#line 14 \""+absoluteSketchLocation+"\"\nvoid loop();\n#line 5 \""+absoluteSketchLocation+"\"\n", ctx.PrototypesSection) expectedSource := LoadAndInterpolate(t, filepath.Join("sketch_with_ifdef", "sketch.preprocessed.txt"), context, ctx) @@ -837,7 +836,7 @@ func TestPrototypesAdderSketchWithIfDef2SAM(t *testing.T) { NoError(t, err) } - require.Equal(t, "#include \n#line 1 \""+absoluteSketchLocation+"\"\n", context[constants.CTX_INCLUDE_SECTION].(string)) + require.Equal(t, "#include \n#line 1 \""+absoluteSketchLocation+"\"\n", ctx.IncludeSection) require.Equal(t, "#line 2 \""+absoluteSketchLocation+"\"\nvoid ifBranch();\n#line 9 \""+absoluteSketchLocation+"\"\nvoid f1();\n#line 10 \""+absoluteSketchLocation+"\"\nvoid f2();\n#line 12 \""+absoluteSketchLocation+"\"\nvoid setup();\n#line 14 \""+absoluteSketchLocation+"\"\nvoid loop();\n#line 2 \""+absoluteSketchLocation+"\"\n", ctx.PrototypesSection) expectedSource := LoadAndInterpolate(t, filepath.Join("sketch_with_ifdef", "sketch.preprocessed.SAM.txt"), context, ctx) @@ -884,7 +883,7 @@ func TestPrototypesAdderSketchWithConst(t *testing.T) { NoError(t, err) } - require.Equal(t, "#include \n#line 1 \""+absoluteSketchLocation+"\"\n", context[constants.CTX_INCLUDE_SECTION].(string)) + require.Equal(t, "#include \n#line 1 \""+absoluteSketchLocation+"\"\n", ctx.IncludeSection) require.Equal(t, "#line 1 \""+absoluteSketchLocation+"\"\nvoid setup();\n#line 2 \""+absoluteSketchLocation+"\"\nvoid loop();\n#line 4 \""+absoluteSketchLocation+"\"\nconst __FlashStringHelper* test();\n#line 6 \""+absoluteSketchLocation+"\"\nconst int test3();\n#line 8 \""+absoluteSketchLocation+"\"\nvolatile __FlashStringHelper* test2();\n#line 10 \""+absoluteSketchLocation+"\"\nvolatile int test4();\n#line 1 \""+absoluteSketchLocation+"\"\n", ctx.PrototypesSection) } diff --git a/src/arduino.cc/builder/types/context.go b/src/arduino.cc/builder/types/context.go index 6963572d..f3c6902f 100644 --- a/src/arduino.cc/builder/types/context.go +++ b/src/arduino.cc/builder/types/context.go @@ -58,6 +58,7 @@ type Context struct { HeaderToLibraries map[string][]*Library ImportedLibraries []*Library LibrariesResolutionResults map[string]LibraryResolutionResult + IncludesJustFound []string IncludeFolders []string OutputGccMinusM string @@ -67,6 +68,8 @@ type Context struct { CTagsOfSource []*CTag CTagsOfPreprocessedSource []*CTag CTagsCollected []*CTag + IncludeSection string + LineOffset int PrototypesSection string PrototypesLineWhereToInsert int Prototypes []*Prototype From e6f25db65c473a3ffe594221291f01e9ba71a09e Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Sat, 16 Apr 2016 14:00:48 +0200 Subject: [PATCH 25/25] Removed context map[string]interface{} This commit concludes the refactoring. Signed-off-by: Cristian Maglie --- src/arduino.cc/arduino-builder/main.go | 26 +----- .../add_additional_entries_to_context.go | 2 +- .../add_build_board_property_if_missing.go | 2 +- ...operties_from_parent_platform_txt_files.go | 2 +- .../builder/additional_sketch_files_copier.go | 2 +- src/arduino.cc/builder/builder.go | 30 +++---- ..._source_files_from_folders_with_sources.go | 2 +- .../collect_ctags_from_sketch_files.go | 2 +- ...ototypes_from_source_and_preproc_source.go | 4 +- .../builder/container_add_prototypes.go | 4 +- .../builder/container_build_options.go | 4 +- .../builder/container_find_includes.go | 24 +++--- .../container_merge_copy_sketch_files.go | 4 +- src/arduino.cc/builder/container_setup.go | 4 +- .../builder/create_build_options_map.go | 2 +- src/arduino.cc/builder/ctags/ctags_parser.go | 2 +- src/arduino.cc/builder/ctags/ctags_runner.go | 2 +- .../builder/ctags/ctags_to_prototypes.go | 2 +- .../builder/ctags_target_file_saver.go | 2 +- .../builder/dump_build_properties.go | 2 +- src/arduino.cc/builder/dump_context.go | 50 ------------ .../builder/ensure_buildpath_exists.go | 2 +- .../builder/external_include_replacer.go | 2 +- .../fail_if_buildpath_equals_sketchpath.go | 2 +- .../fail_if_imported_library_is_wrong.go | 2 +- .../builder/gcc_minus_m_output_parser.go | 7 +- src/arduino.cc/builder/gcc_preproc_runner.go | 10 +-- .../builder/gcc_preproc_source_saver.go | 4 +- .../builder/generate_buildpath_if_missing.go | 2 +- src/arduino.cc/builder/hardware_loader.go | 2 +- .../builder/includes_finder_with_gcc.go | 4 +- .../builder/includes_finder_with_regexp.go | 2 +- .../builder/includes_to_include_folders.go | 2 +- src/arduino.cc/builder/libraries_loader.go | 2 +- .../builder/load_previous_build_options.go | 2 +- .../load_vid_pid_specific_properties.go | 2 +- .../builder/merge_sketch_with_bootloader.go | 2 +- src/arduino.cc/builder/phases/core_builder.go | 2 +- .../builder/phases/libraries_builder.go | 2 +- src/arduino.cc/builder/phases/linker.go | 2 +- .../builder/phases/sketch_builder.go | 2 +- .../builder/platform_keys_rewrite_loader.go | 2 +- .../builder/print_preprocessed_source.go | 2 +- .../print_used_and_not_used_libraries.go | 2 +- .../print_used_libraries_if_verbose.go | 2 +- src/arduino.cc/builder/prototypes_adder.go | 2 +- .../builder/read_file_and_store_in_context.go | 2 +- src/arduino.cc/builder/recipe_runner.go | 2 +- .../builder/rewrite_hardware_keys.go | 2 +- .../builder/set_custom_build_properties.go | 2 +- .../builder/setup_build_properties.go | 2 +- src/arduino.cc/builder/sketch_loader.go | 2 +- src/arduino.cc/builder/sketch_saver.go | 2 +- .../builder/sketch_source_merger.go | 2 +- .../builder/store_build_options_map.go | 2 +- .../builder/target_board_resolver.go | 2 +- .../add_additional_entries_to_context_test.go | 6 +- ...dd_build_board_property_if_missing_test.go | 6 +- .../additional_sketch_files_copier_test.go | 9 +-- src/arduino.cc/builder/test/builder_test.go | 35 +++----- ...ce_files_from_folders_with_sources_test.go | 9 +-- .../test/create_build_options_map_test.go | 3 +- .../builder/test/ctags_parser_test.go | 42 ++++------ .../builder/test/ctags_runner_test.go | 15 ++-- .../builder/test/ctags_to_prototypes_test.go | 44 ++++------ .../test/external_include_replacer_test.go | 6 +- ...ail_if_buildpath_equals_sketchpath_test.go | 6 +- .../test/gcc_minus_m_output_parser_test.go | 9 +-- .../generate_buildpath_if_missing_test.go | 12 +-- .../builder/test/hardware_loader_test.go | 12 +-- src/arduino.cc/builder/test/helper.go | 7 +- .../test/includes_finder_with_gcc_test.go | 17 ++-- .../test/includes_finder_with_regexp_test.go | 18 ++--- .../test/includes_to_include_folders_test.go | 21 ++--- .../builder/test/libraries_loader_test.go | 12 +-- .../load_previous_build_options_map_test.go | 6 +- .../load_vid_pid_specific_properties_test.go | 6 +- .../test/merge_sketch_with_bootloader_test.go | 14 ++-- .../test/platform_keys_rewrite_loader_test.go | 3 +- .../builder/test/prototypes_adder_test.go | 80 +++++++------------ .../read_file_and_store_in_context_test.go | 3 +- .../builder/test/recipe_runner_test.go | 3 +- .../test/rewrite_hardware_keys_test.go | 6 +- .../test/setup_build_properties_test.go | 12 +-- .../builder/test/sketch_loader_test.go | 21 ++--- .../builder/test/sketch_source_merger_test.go | 5 +- .../test/store_build_options_map_test.go | 3 +- .../test/target_board_resolver_test.go | 18 ++--- .../builder/test/tools_loader_test.go | 9 +-- .../try_build_of_problematic_sketch_test.go | 33 ++++---- .../unused_compiled_libraries_remover_test.go | 9 +-- ...uild_path_if_build_options_changed_test.go | 9 +-- src/arduino.cc/builder/tools_loader.go | 2 +- src/arduino.cc/builder/types/context.go | 5 -- src/arduino.cc/builder/types/types.go | 2 +- .../unused_compiled_libraries_remover.go | 2 +- .../warn_about_arch_incompatible_libraries.go | 2 +- .../builder/warn_about_platform_rewrites.go | 2 +- ...out_build_path_if_build_options_changed.go | 2 +- 99 files changed, 292 insertions(+), 515 deletions(-) delete mode 100644 src/arduino.cc/builder/dump_context.go diff --git a/src/arduino.cc/arduino-builder/main.go b/src/arduino.cc/arduino-builder/main.go index d3fa879d..365efd09 100644 --- a/src/arduino.cc/arduino-builder/main.go +++ b/src/arduino.cc/arduino-builder/main.go @@ -169,7 +169,6 @@ func main() { return } - context := make(map[string]interface{}) ctx := &types.Context{} if *buildOptionsFileFlag != "" { @@ -305,16 +304,16 @@ func main() { } if *dumpPrefsFlag { - err = builder.RunParseHardwareAndDumpBuildProperties(context, ctx) + err = builder.RunParseHardwareAndDumpBuildProperties(ctx) } else if *preprocessFlag { - err = builder.RunPreprocess(context, ctx) + err = builder.RunPreprocess(ctx) } else { if flag.NArg() == 0 { fmt.Fprintln(os.Stderr, "Last parameter must be the sketch to compile") flag.Usage() os.Exit(1) } - err = builder.RunBuilder(context, ctx) + err = builder.RunBuilder(ctx) } if err != nil { @@ -330,25 +329,6 @@ func main() { } } -func setContextSliceKeyOrLoadItFromOptions(context map[string]interface{}, cliFlag []string, buildOptions map[string]string, contextKey string, paramName string, mandatory bool) (error, bool) { - values, err := toSliceOfUnquoted(cliFlag) - if err != nil { - return err, true - } - - if len(values) == 0 && len(buildOptions[contextKey]) > 0 { - values = strings.Split(buildOptions[contextKey], ",") - } - - if mandatory && len(values) == 0 { - return errors.New("Parameter '" + paramName + "' is mandatory"), false - } - - context[contextKey] = values - - return nil, false -} - func toExitCode(err error) int { if exiterr, ok := err.(*exec.ExitError); ok { if status, ok := exiterr.Sys().(syscall.WaitStatus); ok { diff --git a/src/arduino.cc/builder/add_additional_entries_to_context.go b/src/arduino.cc/builder/add_additional_entries_to_context.go index b78d6f31..a4250c88 100644 --- a/src/arduino.cc/builder/add_additional_entries_to_context.go +++ b/src/arduino.cc/builder/add_additional_entries_to_context.go @@ -38,7 +38,7 @@ import ( type AddAdditionalEntriesToContext struct{} -func (s *AddAdditionalEntriesToContext) Run(context map[string]interface{}, ctx *types.Context) error { +func (s *AddAdditionalEntriesToContext) Run(ctx *types.Context) error { if ctx.BuildPath != "" { buildPath := ctx.BuildPath preprocPath, err := filepath.Abs(filepath.Join(buildPath, constants.FOLDER_PREPROC)) diff --git a/src/arduino.cc/builder/add_build_board_property_if_missing.go b/src/arduino.cc/builder/add_build_board_property_if_missing.go index 8bb0bebe..10cd0e2e 100644 --- a/src/arduino.cc/builder/add_build_board_property_if_missing.go +++ b/src/arduino.cc/builder/add_build_board_property_if_missing.go @@ -38,7 +38,7 @@ import ( type AddBuildBoardPropertyIfMissing struct{} -func (s *AddBuildBoardPropertyIfMissing) Run(context map[string]interface{}, ctx *types.Context) error { +func (s *AddBuildBoardPropertyIfMissing) Run(ctx *types.Context) error { packages := ctx.Hardware logger := ctx.GetLogger() diff --git a/src/arduino.cc/builder/add_missing_build_properties_from_parent_platform_txt_files.go b/src/arduino.cc/builder/add_missing_build_properties_from_parent_platform_txt_files.go index 8bf53d2f..79a44552 100644 --- a/src/arduino.cc/builder/add_missing_build_properties_from_parent_platform_txt_files.go +++ b/src/arduino.cc/builder/add_missing_build_properties_from_parent_platform_txt_files.go @@ -35,7 +35,7 @@ import ( type AddMissingBuildPropertiesFromParentPlatformTxtFiles struct{} -func (s *AddMissingBuildPropertiesFromParentPlatformTxtFiles) Run(context map[string]interface{}, ctx *types.Context) error { +func (s *AddMissingBuildPropertiesFromParentPlatformTxtFiles) Run(ctx *types.Context) error { packages := ctx.Hardware targetPackage := ctx.TargetPackage buildProperties := ctx.BuildProperties diff --git a/src/arduino.cc/builder/additional_sketch_files_copier.go b/src/arduino.cc/builder/additional_sketch_files_copier.go index d362ceb7..490e961d 100644 --- a/src/arduino.cc/builder/additional_sketch_files_copier.go +++ b/src/arduino.cc/builder/additional_sketch_files_copier.go @@ -40,7 +40,7 @@ import ( type AdditionalSketchFilesCopier struct{} -func (s *AdditionalSketchFilesCopier) Run(context map[string]interface{}, ctx *types.Context) error { +func (s *AdditionalSketchFilesCopier) Run(ctx *types.Context) error { sketch := ctx.Sketch sketchBuildPath := ctx.SketchBuildPath diff --git a/src/arduino.cc/builder/builder.go b/src/arduino.cc/builder/builder.go index 4c7b6124..7e9d08a9 100644 --- a/src/arduino.cc/builder/builder.go +++ b/src/arduino.cc/builder/builder.go @@ -66,7 +66,7 @@ const DEFAULT_BUILD_CORE = "arduino" type Builder struct{} -func (s *Builder) Run(context map[string]interface{}, ctx *types.Context) error { +func (s *Builder) Run(ctx *types.Context) error { commands := []types.Command{ &GenerateBuildPathIfMissing{}, &EnsureBuildPathExists{}, @@ -113,14 +113,14 @@ func (s *Builder) Run(context map[string]interface{}, ctx *types.Context) error &RecipeByPrefixSuffixRunner{Prefix: constants.HOOKS_POSTBUILD, Suffix: constants.HOOKS_PATTERN_SUFFIX}, } - mainErr := runCommands(context, ctx, commands, true) + mainErr := runCommands(ctx, commands, true) commands = []types.Command{ &PrintUsedAndNotUsedLibraries{}, &PrintUsedLibrariesIfVerbose{}, } - otherErr := runCommands(context, ctx, commands, false) + otherErr := runCommands(ctx, commands, false) if mainErr != nil { return mainErr @@ -131,7 +131,7 @@ func (s *Builder) Run(context map[string]interface{}, ctx *types.Context) error type Preprocess struct{} -func (s *Preprocess) Run(context map[string]interface{}, ctx *types.Context) error { +func (s *Preprocess) Run(ctx *types.Context) error { commands := []types.Command{ &GenerateBuildPathIfMissing{}, &EnsureBuildPathExists{}, @@ -153,12 +153,12 @@ func (s *Preprocess) Run(context map[string]interface{}, ctx *types.Context) err &PrintPreprocessedSource{}, } - return runCommands(context, ctx, commands, true) + return runCommands(ctx, commands, true) } type ParseHardwareAndDumpBuildProperties struct{} -func (s *ParseHardwareAndDumpBuildProperties) Run(context map[string]interface{}, ctx *types.Context) error { +func (s *ParseHardwareAndDumpBuildProperties) Run(ctx *types.Context) error { commands := []types.Command{ &GenerateBuildPathIfMissing{}, @@ -167,10 +167,10 @@ func (s *ParseHardwareAndDumpBuildProperties) Run(context map[string]interface{} &DumpBuildProperties{}, } - return runCommands(context, ctx, commands, true) + return runCommands(ctx, commands, true) } -func runCommands(context map[string]interface{}, ctx *types.Context, commands []types.Command, progressEnabled bool) error { +func runCommands(ctx *types.Context, commands []types.Command, progressEnabled bool) error { commandsLength := len(commands) progressForEachCommand := float32(100) / float32(commandsLength) @@ -178,7 +178,7 @@ func runCommands(context map[string]interface{}, ctx *types.Context, commands [] for _, command := range commands { PrintRingNameIfDebug(ctx, command) printProgressIfProgressEnabledAndMachineLogger(progressEnabled, ctx, progress) - err := command.Run(context, ctx) + err := command.Run(ctx) if err != nil { return i18n.WrapError(err) } @@ -207,17 +207,17 @@ func PrintRingNameIfDebug(ctx *types.Context, command types.Command) { } } -func RunBuilder(context map[string]interface{}, ctx *types.Context) error { +func RunBuilder(ctx *types.Context) error { command := Builder{} - return command.Run(context, ctx) + return command.Run(ctx) } -func RunParseHardwareAndDumpBuildProperties(context map[string]interface{}, ctx *types.Context) error { +func RunParseHardwareAndDumpBuildProperties(ctx *types.Context) error { command := ParseHardwareAndDumpBuildProperties{} - return command.Run(context, ctx) + return command.Run(ctx) } -func RunPreprocess(context map[string]interface{}, ctx *types.Context) error { +func RunPreprocess(ctx *types.Context) error { command := Preprocess{} - return command.Run(context, ctx) + return command.Run(ctx) } diff --git a/src/arduino.cc/builder/collect_all_source_files_from_folders_with_sources.go b/src/arduino.cc/builder/collect_all_source_files_from_folders_with_sources.go index 4caaea1d..efd51c18 100644 --- a/src/arduino.cc/builder/collect_all_source_files_from_folders_with_sources.go +++ b/src/arduino.cc/builder/collect_all_source_files_from_folders_with_sources.go @@ -42,7 +42,7 @@ import ( type CollectAllSourceFilesFromFoldersWithSources struct{} -func (s *CollectAllSourceFilesFromFoldersWithSources) Run(context map[string]interface{}, ctx *types.Context) error { +func (s *CollectAllSourceFilesFromFoldersWithSources) Run(ctx *types.Context) error { foldersWithSources := ctx.FoldersWithSourceFiles sourceFiles := ctx.CollectedSourceFiles diff --git a/src/arduino.cc/builder/collect_ctags_from_sketch_files.go b/src/arduino.cc/builder/collect_ctags_from_sketch_files.go index 45721b9e..aee6935c 100644 --- a/src/arduino.cc/builder/collect_ctags_from_sketch_files.go +++ b/src/arduino.cc/builder/collect_ctags_from_sketch_files.go @@ -37,7 +37,7 @@ import ( type CollectCTagsFromSketchFiles struct{} -func (s *CollectCTagsFromSketchFiles) Run(context map[string]interface{}, ctx *types.Context) error { +func (s *CollectCTagsFromSketchFiles) Run(ctx *types.Context) error { sketchFileNames := collectSketchFileNamesFrom(ctx.Sketch) allCtags := ctx.CTagsOfPreprocessedSource diff --git a/src/arduino.cc/builder/compare_prototypes_from_source_and_preproc_source.go b/src/arduino.cc/builder/compare_prototypes_from_source_and_preproc_source.go index 902725d7..0f19b7f1 100644 --- a/src/arduino.cc/builder/compare_prototypes_from_source_and_preproc_source.go +++ b/src/arduino.cc/builder/compare_prototypes_from_source_and_preproc_source.go @@ -29,11 +29,13 @@ package builder +// XXX: Obsolete? + import "arduino.cc/builder/types" type ComparePrototypesFromSourceAndPreprocSource struct{} -func (s *ComparePrototypesFromSourceAndPreprocSource) Run(context map[string]interface{}, ctx *types.Context) error { +func (s *ComparePrototypesFromSourceAndPreprocSource) Run(ctx *types.Context) error { ctagsOfSource := ctx.CTagsOfSource ctagsOfPreprocSource := ctx.CTagsOfPreprocessedSource diff --git a/src/arduino.cc/builder/container_add_prototypes.go b/src/arduino.cc/builder/container_add_prototypes.go index af633469..28ba1645 100644 --- a/src/arduino.cc/builder/container_add_prototypes.go +++ b/src/arduino.cc/builder/container_add_prototypes.go @@ -38,7 +38,7 @@ import ( type ContainerAddPrototypes struct{} -func (s *ContainerAddPrototypes) Run(context map[string]interface{}, ctx *types.Context) error { +func (s *ContainerAddPrototypes) Run(ctx *types.Context) error { commands := []types.Command{ &GCCPreprocRunner{TargetFileName: constants.FILE_CTAGS_TARGET_FOR_GCC_MINUS_E}, &ReadFileAndStoreInContext{Target: &ctx.SourceGccMinusE}, @@ -53,7 +53,7 @@ func (s *ContainerAddPrototypes) Run(context map[string]interface{}, ctx *types. for _, command := range commands { PrintRingNameIfDebug(ctx, command) - err := command.Run(context, ctx) + err := command.Run(ctx) if err != nil { return i18n.WrapError(err) } diff --git a/src/arduino.cc/builder/container_build_options.go b/src/arduino.cc/builder/container_build_options.go index d7407206..eff01468 100644 --- a/src/arduino.cc/builder/container_build_options.go +++ b/src/arduino.cc/builder/container_build_options.go @@ -36,7 +36,7 @@ import ( type ContainerBuildOptions struct{} -func (s *ContainerBuildOptions) Run(context map[string]interface{}, ctx *types.Context) error { +func (s *ContainerBuildOptions) Run(ctx *types.Context) error { commands := []types.Command{ &CreateBuildOptionsMap{}, &LoadPreviousBuildOptionsMap{}, @@ -46,7 +46,7 @@ func (s *ContainerBuildOptions) Run(context map[string]interface{}, ctx *types.C for _, command := range commands { PrintRingNameIfDebug(ctx, command) - err := command.Run(context, ctx) + err := command.Run(ctx) if err != nil { return i18n.WrapError(err) } diff --git a/src/arduino.cc/builder/container_find_includes.go b/src/arduino.cc/builder/container_find_includes.go index 2de30fb6..e513747a 100644 --- a/src/arduino.cc/builder/container_find_includes.go +++ b/src/arduino.cc/builder/container_find_includes.go @@ -39,15 +39,15 @@ import ( type ContainerFindIncludes struct{} -func (s *ContainerFindIncludes) Run(context map[string]interface{}, ctx *types.Context) error { - err := runCommand(context, ctx, &IncludesToIncludeFolders{}) +func (s *ContainerFindIncludes) Run(ctx *types.Context) error { + err := runCommand(ctx, &IncludesToIncludeFolders{}) if err != nil { return i18n.WrapError(err) } sketchBuildPath := ctx.SketchBuildPath sketch := ctx.Sketch - err = findIncludesUntilDone(context, ctx, filepath.Join(sketchBuildPath, filepath.Base(sketch.MainFile.Name)+".cpp")) + err = findIncludesUntilDone(ctx, filepath.Join(sketchBuildPath, filepath.Base(sketch.MainFile.Name)+".cpp")) if err != nil { return i18n.WrapError(err) } @@ -63,7 +63,7 @@ func (s *ContainerFindIncludes) Run(context map[string]interface{}, ctx *types.C } } - err = runCommand(context, ctx, &CollectAllSourceFilesFromFoldersWithSources{}) + err = runCommand(ctx, &CollectAllSourceFilesFromFoldersWithSources{}) if err != nil { return i18n.WrapError(err) } @@ -71,17 +71,17 @@ func (s *ContainerFindIncludes) Run(context map[string]interface{}, ctx *types.C sourceFilePaths := ctx.CollectedSourceFiles for !sourceFilePaths.Empty() { - err = findIncludesUntilDone(context, ctx, sourceFilePaths.Pop().(string)) + err = findIncludesUntilDone(ctx, sourceFilePaths.Pop().(string)) if err != nil { return i18n.WrapError(err) } - err := runCommand(context, ctx, &CollectAllSourceFilesFromFoldersWithSources{}) + err := runCommand(ctx, &CollectAllSourceFilesFromFoldersWithSources{}) if err != nil { return i18n.WrapError(err) } } - err = runCommand(context, ctx, &FailIfImportedLibraryIsWrong{}) + err = runCommand(ctx, &FailIfImportedLibraryIsWrong{}) if err != nil { return i18n.WrapError(err) } @@ -89,16 +89,16 @@ func (s *ContainerFindIncludes) Run(context map[string]interface{}, ctx *types.C return nil } -func runCommand(context map[string]interface{}, ctx *types.Context, command types.Command) error { +func runCommand(ctx *types.Context, command types.Command) error { PrintRingNameIfDebug(ctx, command) - err := command.Run(context, ctx) + err := command.Run(ctx) if err != nil { return i18n.WrapError(err) } return nil } -func findIncludesUntilDone(context map[string]interface{}, ctx *types.Context, sourceFilePath string) error { +func findIncludesUntilDone(ctx *types.Context, sourceFilePath string) error { targetFilePath := utils.NULLFile() importedLibraries := ctx.ImportedLibraries done := false @@ -109,7 +109,7 @@ func findIncludesUntilDone(context map[string]interface{}, ctx *types.Context, s &IncludesToIncludeFolders{}, } for _, command := range commands { - err := runCommand(context, ctx, command) + err := runCommand(ctx, command) if err != nil { return i18n.WrapError(err) } @@ -117,7 +117,7 @@ func findIncludesUntilDone(context map[string]interface{}, ctx *types.Context, s if len(ctx.IncludesJustFound) == 0 { done = true } else if len(ctx.ImportedLibraries) == len(importedLibraries) { - err := runCommand(context, ctx, &GCCPreprocRunner{TargetFileName: constants.FILE_CTAGS_TARGET_FOR_GCC_MINUS_E}) + err := runCommand(ctx, &GCCPreprocRunner{TargetFileName: constants.FILE_CTAGS_TARGET_FOR_GCC_MINUS_E}) return i18n.WrapError(err) } importedLibraries = ctx.ImportedLibraries diff --git a/src/arduino.cc/builder/container_merge_copy_sketch_files.go b/src/arduino.cc/builder/container_merge_copy_sketch_files.go index 3f6d2500..2d844b2f 100644 --- a/src/arduino.cc/builder/container_merge_copy_sketch_files.go +++ b/src/arduino.cc/builder/container_merge_copy_sketch_files.go @@ -36,7 +36,7 @@ import ( type ContainerMergeCopySketchFiles struct{} -func (s *ContainerMergeCopySketchFiles) Run(context map[string]interface{}, ctx *types.Context) error { +func (s *ContainerMergeCopySketchFiles) Run(ctx *types.Context) error { commands := []types.Command{ &SketchSourceMerger{}, &SketchSaver{}, @@ -45,7 +45,7 @@ func (s *ContainerMergeCopySketchFiles) Run(context map[string]interface{}, ctx for _, command := range commands { PrintRingNameIfDebug(ctx, command) - err := command.Run(context, ctx) + err := command.Run(ctx) if err != nil { return i18n.WrapError(err) } diff --git a/src/arduino.cc/builder/container_setup.go b/src/arduino.cc/builder/container_setup.go index 8fe2435c..e76bb500 100644 --- a/src/arduino.cc/builder/container_setup.go +++ b/src/arduino.cc/builder/container_setup.go @@ -36,7 +36,7 @@ import ( type ContainerSetupHardwareToolsLibsSketchAndProps struct{} -func (s *ContainerSetupHardwareToolsLibsSketchAndProps) Run(context map[string]interface{}, ctx *types.Context) error { +func (s *ContainerSetupHardwareToolsLibsSketchAndProps) Run(ctx *types.Context) error { commands := []types.Command{ &AddAdditionalEntriesToContext{}, &FailIfBuildPathEqualsSketchPath{}, @@ -56,7 +56,7 @@ func (s *ContainerSetupHardwareToolsLibsSketchAndProps) Run(context map[string]i for _, command := range commands { PrintRingNameIfDebug(ctx, command) - err := command.Run(context, ctx) + err := command.Run(ctx) if err != nil { return i18n.WrapError(err) } diff --git a/src/arduino.cc/builder/create_build_options_map.go b/src/arduino.cc/builder/create_build_options_map.go index 2b3a0f72..d9caa59f 100644 --- a/src/arduino.cc/builder/create_build_options_map.go +++ b/src/arduino.cc/builder/create_build_options_map.go @@ -37,7 +37,7 @@ import ( type CreateBuildOptionsMap struct{} -func (s *CreateBuildOptionsMap) Run(context map[string]interface{}, ctx *types.Context) error { +func (s *CreateBuildOptionsMap) Run(ctx *types.Context) error { buildOptions := ctx.ExtractBuildOptions() bytes, err := json.MarshalIndent(buildOptions, "", " ") if err != nil { diff --git a/src/arduino.cc/builder/ctags/ctags_parser.go b/src/arduino.cc/builder/ctags/ctags_parser.go index 31245b27..55497155 100644 --- a/src/arduino.cc/builder/ctags/ctags_parser.go +++ b/src/arduino.cc/builder/ctags/ctags_parser.go @@ -56,7 +56,7 @@ var KNOWN_TAG_KINDS = map[string]bool{ type CTagsParser struct{} -func (s *CTagsParser) Run(context map[string]interface{}, ctx *types.Context) error { +func (s *CTagsParser) Run(ctx *types.Context) error { rows := strings.Split(ctx.CTagsOutput, "\n") rows = removeEmpty(rows) diff --git a/src/arduino.cc/builder/ctags/ctags_runner.go b/src/arduino.cc/builder/ctags/ctags_runner.go index 8c9a6178..b58242d7 100644 --- a/src/arduino.cc/builder/ctags/ctags_runner.go +++ b/src/arduino.cc/builder/ctags/ctags_runner.go @@ -39,7 +39,7 @@ import ( type CTagsRunner struct{} -func (s *CTagsRunner) Run(context map[string]interface{}, ctx *types.Context) error { +func (s *CTagsRunner) Run(ctx *types.Context) error { buildProperties := ctx.BuildProperties ctagsTargetFilePath := ctx.CTagsTargetFile logger := ctx.GetLogger() diff --git a/src/arduino.cc/builder/ctags/ctags_to_prototypes.go b/src/arduino.cc/builder/ctags/ctags_to_prototypes.go index f4ff4abe..c6528fec 100644 --- a/src/arduino.cc/builder/ctags/ctags_to_prototypes.go +++ b/src/arduino.cc/builder/ctags/ctags_to_prototypes.go @@ -36,7 +36,7 @@ import ( type CTagsToPrototypes struct{} -func (s *CTagsToPrototypes) Run(context map[string]interface{}, ctx *types.Context) error { +func (s *CTagsToPrototypes) Run(ctx *types.Context) error { tags := ctx.CTagsCollected lineWhereToInsertPrototypes := findLineWhereToInsertPrototypes(tags) diff --git a/src/arduino.cc/builder/ctags_target_file_saver.go b/src/arduino.cc/builder/ctags_target_file_saver.go index e4d84bc2..0f3277ca 100644 --- a/src/arduino.cc/builder/ctags_target_file_saver.go +++ b/src/arduino.cc/builder/ctags_target_file_saver.go @@ -41,7 +41,7 @@ type CTagsTargetFileSaver struct { TargetFileName string } -func (s *CTagsTargetFileSaver) Run(context map[string]interface{}, ctx *types.Context) error { +func (s *CTagsTargetFileSaver) Run(ctx *types.Context) error { source := *s.Source preprocPath := ctx.PreprocPath diff --git a/src/arduino.cc/builder/dump_build_properties.go b/src/arduino.cc/builder/dump_build_properties.go index 06dedc99..af20cc1b 100644 --- a/src/arduino.cc/builder/dump_build_properties.go +++ b/src/arduino.cc/builder/dump_build_properties.go @@ -38,7 +38,7 @@ import ( type DumpBuildProperties struct{} -func (s *DumpBuildProperties) Run(context map[string]interface{}, ctx *types.Context) error { +func (s *DumpBuildProperties) Run(ctx *types.Context) error { buildProperties := ctx.BuildProperties keys := utils.KeysOfMapOfString(buildProperties) diff --git a/src/arduino.cc/builder/dump_context.go b/src/arduino.cc/builder/dump_context.go deleted file mode 100644 index 7cfc1a64..00000000 --- a/src/arduino.cc/builder/dump_context.go +++ /dev/null @@ -1,50 +0,0 @@ -/* - * This file is part of Arduino Builder. - * - * Arduino Builder is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - * As a special exception, you may use this file as part of a free software - * library without restriction. Specifically, if other files instantiate - * templates or use macros or inline functions from this file, or you compile - * this file and link it with other files to produce an executable, this - * file does not by itself cause the resulting executable to be covered by - * the GNU General Public License. This exception does not however - * invalidate any other reasons why the executable file might be covered by - * the GNU General Public License. - * - * Copyright 2015 Arduino LLC (http://www.arduino.cc/) - */ - -package builder - -import ( - "arduino.cc/builder/utils" - "fmt" - "sort" -) - -type DumpContext struct{} - -func (s *DumpContext) Run(context map[string]interface{}) error { - keys := utils.KeysOfMapOfStringInterface(context) - sort.Strings(keys) - - for _, key := range keys { - fmt.Print(key + "=") - fmt.Println(context[key]) - } - - return nil -} diff --git a/src/arduino.cc/builder/ensure_buildpath_exists.go b/src/arduino.cc/builder/ensure_buildpath_exists.go index 1b26bd70..39ab0156 100644 --- a/src/arduino.cc/builder/ensure_buildpath_exists.go +++ b/src/arduino.cc/builder/ensure_buildpath_exists.go @@ -37,7 +37,7 @@ import ( type EnsureBuildPathExists struct{} -func (s *EnsureBuildPathExists) Run(context map[string]interface{}, ctx *types.Context) error { +func (s *EnsureBuildPathExists) Run(ctx *types.Context) error { err := utils.EnsureFolderExists(ctx.BuildPath) if err != nil { return i18n.WrapError(err) diff --git a/src/arduino.cc/builder/external_include_replacer.go b/src/arduino.cc/builder/external_include_replacer.go index e69a1197..fc3dcb43 100644 --- a/src/arduino.cc/builder/external_include_replacer.go +++ b/src/arduino.cc/builder/external_include_replacer.go @@ -42,7 +42,7 @@ type ExternalIncludeReplacer struct { To string } -func (s *ExternalIncludeReplacer) Run(context map[string]interface{}, ctx *types.Context) error { +func (s *ExternalIncludeReplacer) Run(ctx *types.Context) error { source := *s.Source nonAbsoluteIncludes := findNonAbsoluteIncludes(ctx.Includes) diff --git a/src/arduino.cc/builder/fail_if_buildpath_equals_sketchpath.go b/src/arduino.cc/builder/fail_if_buildpath_equals_sketchpath.go index 11f2bdf0..e42adee5 100644 --- a/src/arduino.cc/builder/fail_if_buildpath_equals_sketchpath.go +++ b/src/arduino.cc/builder/fail_if_buildpath_equals_sketchpath.go @@ -38,7 +38,7 @@ import ( type FailIfBuildPathEqualsSketchPath struct{} -func (s *FailIfBuildPathEqualsSketchPath) Run(context map[string]interface{}, ctx *types.Context) error { +func (s *FailIfBuildPathEqualsSketchPath) Run(ctx *types.Context) error { if ctx.BuildPath == "" || ctx.SketchLocation == "" { return nil } diff --git a/src/arduino.cc/builder/fail_if_imported_library_is_wrong.go b/src/arduino.cc/builder/fail_if_imported_library_is_wrong.go index f0481e69..1c1c5ae1 100644 --- a/src/arduino.cc/builder/fail_if_imported_library_is_wrong.go +++ b/src/arduino.cc/builder/fail_if_imported_library_is_wrong.go @@ -39,7 +39,7 @@ import ( type FailIfImportedLibraryIsWrong struct{} -func (s *FailIfImportedLibraryIsWrong) Run(context map[string]interface{}, ctx *types.Context) error { +func (s *FailIfImportedLibraryIsWrong) Run(ctx *types.Context) error { if len(ctx.ImportedLibraries) == 0 { return nil } diff --git a/src/arduino.cc/builder/gcc_minus_m_output_parser.go b/src/arduino.cc/builder/gcc_minus_m_output_parser.go index 9ba82fa5..458d58de 100644 --- a/src/arduino.cc/builder/gcc_minus_m_output_parser.go +++ b/src/arduino.cc/builder/gcc_minus_m_output_parser.go @@ -30,7 +30,6 @@ package builder import ( - "arduino.cc/builder/constants" "arduino.cc/builder/types" "arduino.cc/builder/utils" "strings" @@ -38,16 +37,16 @@ import ( type GCCMinusMOutputParser struct{} -func (s *GCCMinusMOutputParser) Run(context map[string]interface{}, ctx *types.Context) error { +func (s *GCCMinusMOutputParser) Run(ctx *types.Context) error { output := ctx.OutputGccMinusM rows := strings.Split(output, "\n") includes := make([]string, 0) if len(rows) > 2 { for _, row := range rows[2:] { - if !strings.HasPrefix(row, constants.SPACE) { + if !strings.HasPrefix(row, " ") { row = strings.TrimSpace(row) - if row != constants.EMPTY_STRING { + if row != "" { row = strings.TrimSuffix(row, ":") row = strings.Replace(row, "\\ ", " ", -1) includes = append(includes, row) diff --git a/src/arduino.cc/builder/gcc_preproc_runner.go b/src/arduino.cc/builder/gcc_preproc_runner.go index 832f4d72..a35ba2b5 100644 --- a/src/arduino.cc/builder/gcc_preproc_runner.go +++ b/src/arduino.cc/builder/gcc_preproc_runner.go @@ -44,10 +44,10 @@ type GCCPreprocRunner struct { TargetFileName string } -func (s *GCCPreprocRunner) Run(context map[string]interface{}, ctx *types.Context) error { +func (s *GCCPreprocRunner) Run(ctx *types.Context) error { sketchBuildPath := ctx.SketchBuildPath sketch := ctx.Sketch - properties, targetFilePath, err := prepareGCCPreprocRecipeProperties(context, ctx, filepath.Join(sketchBuildPath, filepath.Base(sketch.MainFile.Name)+".cpp"), s.TargetFileName) + properties, targetFilePath, err := prepareGCCPreprocRecipeProperties(ctx, filepath.Join(sketchBuildPath, filepath.Base(sketch.MainFile.Name)+".cpp"), s.TargetFileName) if err != nil { return i18n.WrapError(err) } @@ -74,8 +74,8 @@ type GCCPreprocRunnerForDiscoveringIncludes struct { TargetFilePath string } -func (s *GCCPreprocRunnerForDiscoveringIncludes) Run(context map[string]interface{}, ctx *types.Context) error { - properties, _, err := prepareGCCPreprocRecipeProperties(context, ctx, s.SourceFilePath, s.TargetFilePath) +func (s *GCCPreprocRunnerForDiscoveringIncludes) Run(ctx *types.Context) error { + properties, _, err := prepareGCCPreprocRecipeProperties(ctx, s.SourceFilePath, s.TargetFilePath) if err != nil { return i18n.WrapError(err) } @@ -98,7 +98,7 @@ func (s *GCCPreprocRunnerForDiscoveringIncludes) Run(context map[string]interfac return nil } -func prepareGCCPreprocRecipeProperties(context map[string]interface{}, ctx *types.Context, sourceFilePath string, targetFilePath string) (props.PropertiesMap, string, error) { +func prepareGCCPreprocRecipeProperties(ctx *types.Context, sourceFilePath string, targetFilePath string) (props.PropertiesMap, string, error) { if targetFilePath != utils.NULLFile() { preprocPath := ctx.PreprocPath err := utils.EnsureFolderExists(preprocPath) diff --git a/src/arduino.cc/builder/gcc_preproc_source_saver.go b/src/arduino.cc/builder/gcc_preproc_source_saver.go index 671835a5..4eb1c083 100644 --- a/src/arduino.cc/builder/gcc_preproc_source_saver.go +++ b/src/arduino.cc/builder/gcc_preproc_source_saver.go @@ -29,6 +29,8 @@ package builder +// XXX: OBSOLETE? + import ( "arduino.cc/builder/constants" "arduino.cc/builder/i18n" @@ -39,7 +41,7 @@ import ( type GCCPreprocSourceSaver struct{} -func (s *GCCPreprocSourceSaver) Run(context map[string]interface{}, ctx *types.Context) error { +func (s *GCCPreprocSourceSaver) Run(ctx *types.Context) error { preprocPath := ctx.PreprocPath err := utils.EnsureFolderExists(preprocPath) if err != nil { diff --git a/src/arduino.cc/builder/generate_buildpath_if_missing.go b/src/arduino.cc/builder/generate_buildpath_if_missing.go index 965643bf..f165afaf 100644 --- a/src/arduino.cc/builder/generate_buildpath_if_missing.go +++ b/src/arduino.cc/builder/generate_buildpath_if_missing.go @@ -41,7 +41,7 @@ import ( type GenerateBuildPathIfMissing struct{} -func (s *GenerateBuildPathIfMissing) Run(context map[string]interface{}, ctx *types.Context) error { +func (s *GenerateBuildPathIfMissing) Run(ctx *types.Context) error { if ctx.BuildPath != "" { return nil } diff --git a/src/arduino.cc/builder/hardware_loader.go b/src/arduino.cc/builder/hardware_loader.go index 2bea5f81..02ccc996 100644 --- a/src/arduino.cc/builder/hardware_loader.go +++ b/src/arduino.cc/builder/hardware_loader.go @@ -41,7 +41,7 @@ import ( type HardwareLoader struct{} -func (s *HardwareLoader) Run(context map[string]interface{}, ctx *types.Context) error { +func (s *HardwareLoader) Run(ctx *types.Context) error { logger := ctx.GetLogger() packages := &types.Packages{} diff --git a/src/arduino.cc/builder/includes_finder_with_gcc.go b/src/arduino.cc/builder/includes_finder_with_gcc.go index 59a2c322..e4fe6a09 100644 --- a/src/arduino.cc/builder/includes_finder_with_gcc.go +++ b/src/arduino.cc/builder/includes_finder_with_gcc.go @@ -29,6 +29,8 @@ package builder +// XXX: Obsolete? + import ( "arduino.cc/builder/builder_utils" "arduino.cc/builder/constants" @@ -42,7 +44,7 @@ type IncludesFinderWithGCC struct { SourceFile string } -func (s *IncludesFinderWithGCC) Run(context map[string]interface{}, ctx *types.Context) error { +func (s *IncludesFinderWithGCC) Run(ctx *types.Context) error { buildProperties := ctx.BuildProperties verbose := ctx.Verbose logger := ctx.GetLogger() diff --git a/src/arduino.cc/builder/includes_finder_with_regexp.go b/src/arduino.cc/builder/includes_finder_with_regexp.go index 2130307e..3f85a748 100644 --- a/src/arduino.cc/builder/includes_finder_with_regexp.go +++ b/src/arduino.cc/builder/includes_finder_with_regexp.go @@ -42,7 +42,7 @@ type IncludesFinderWithRegExp struct { Source *string } -func (s *IncludesFinderWithRegExp) Run(context map[string]interface{}, ctx *types.Context) error { +func (s *IncludesFinderWithRegExp) Run(ctx *types.Context) error { source := *s.Source matches := INCLUDE_REGEXP.FindAllStringSubmatch(source, -1) diff --git a/src/arduino.cc/builder/includes_to_include_folders.go b/src/arduino.cc/builder/includes_to_include_folders.go index cd93337d..63c76f7f 100644 --- a/src/arduino.cc/builder/includes_to_include_folders.go +++ b/src/arduino.cc/builder/includes_to_include_folders.go @@ -41,7 +41,7 @@ import ( type IncludesToIncludeFolders struct{} -func (s *IncludesToIncludeFolders) Run(context map[string]interface{}, ctx *types.Context) error { +func (s *IncludesToIncludeFolders) Run(ctx *types.Context) error { includes := ctx.Includes headerToLibraries := ctx.HeaderToLibraries diff --git a/src/arduino.cc/builder/libraries_loader.go b/src/arduino.cc/builder/libraries_loader.go index 32291923..3ef57560 100644 --- a/src/arduino.cc/builder/libraries_loader.go +++ b/src/arduino.cc/builder/libraries_loader.go @@ -42,7 +42,7 @@ import ( type LibrariesLoader struct{} -func (s *LibrariesLoader) Run(context map[string]interface{}, ctx *types.Context) error { +func (s *LibrariesLoader) Run(ctx *types.Context) error { builtInLibrariesFolders := ctx.BuiltInLibrariesFolders builtInLibrariesFolders, err := utils.AbsolutizePaths(builtInLibrariesFolders) if err != nil { diff --git a/src/arduino.cc/builder/load_previous_build_options.go b/src/arduino.cc/builder/load_previous_build_options.go index d341cfdb..2d051847 100644 --- a/src/arduino.cc/builder/load_previous_build_options.go +++ b/src/arduino.cc/builder/load_previous_build_options.go @@ -40,7 +40,7 @@ import ( type LoadPreviousBuildOptionsMap struct{} -func (s *LoadPreviousBuildOptionsMap) Run(context map[string]interface{}, ctx *types.Context) error { +func (s *LoadPreviousBuildOptionsMap) Run(ctx *types.Context) error { buildOptionsFile := filepath.Join(ctx.BuildPath, constants.BUILD_OPTIONS_FILE) _, err := os.Stat(buildOptionsFile) diff --git a/src/arduino.cc/builder/load_vid_pid_specific_properties.go b/src/arduino.cc/builder/load_vid_pid_specific_properties.go index dd844922..0b17ff8f 100644 --- a/src/arduino.cc/builder/load_vid_pid_specific_properties.go +++ b/src/arduino.cc/builder/load_vid_pid_specific_properties.go @@ -40,7 +40,7 @@ import ( type LoadVIDPIDSpecificProperties struct{} -func (s *LoadVIDPIDSpecificProperties) Run(context map[string]interface{}, ctx *types.Context) error { +func (s *LoadVIDPIDSpecificProperties) Run(ctx *types.Context) error { if ctx.USBVidPid == "" { return nil } diff --git a/src/arduino.cc/builder/merge_sketch_with_bootloader.go b/src/arduino.cc/builder/merge_sketch_with_bootloader.go index a822c2f1..34fa657b 100644 --- a/src/arduino.cc/builder/merge_sketch_with_bootloader.go +++ b/src/arduino.cc/builder/merge_sketch_with_bootloader.go @@ -41,7 +41,7 @@ import ( type MergeSketchWithBootloader struct{} -func (s *MergeSketchWithBootloader) Run(context map[string]interface{}, ctx *types.Context) error { +func (s *MergeSketchWithBootloader) Run(ctx *types.Context) error { buildProperties := ctx.BuildProperties if !utils.MapStringStringHas(buildProperties, constants.BUILD_PROPERTIES_BOOTLOADER_NOBLINK) && !utils.MapStringStringHas(buildProperties, constants.BUILD_PROPERTIES_BOOTLOADER_FILE) { return nil diff --git a/src/arduino.cc/builder/phases/core_builder.go b/src/arduino.cc/builder/phases/core_builder.go index 63d4f16d..114143fb 100644 --- a/src/arduino.cc/builder/phases/core_builder.go +++ b/src/arduino.cc/builder/phases/core_builder.go @@ -40,7 +40,7 @@ import ( type CoreBuilder struct{} -func (s *CoreBuilder) Run(context map[string]interface{}, ctx *types.Context) error { +func (s *CoreBuilder) Run(ctx *types.Context) error { coreBuildPath := ctx.CoreBuildPath buildProperties := ctx.BuildProperties verbose := ctx.Verbose diff --git a/src/arduino.cc/builder/phases/libraries_builder.go b/src/arduino.cc/builder/phases/libraries_builder.go index 2aafe569..5ebd9c6b 100644 --- a/src/arduino.cc/builder/phases/libraries_builder.go +++ b/src/arduino.cc/builder/phases/libraries_builder.go @@ -42,7 +42,7 @@ import ( type LibrariesBuilder struct{} -func (s *LibrariesBuilder) Run(context map[string]interface{}, ctx *types.Context) error { +func (s *LibrariesBuilder) Run(ctx *types.Context) error { librariesBuildPath := ctx.LibrariesBuildPath buildProperties := ctx.BuildProperties includes := ctx.IncludeFolders diff --git a/src/arduino.cc/builder/phases/linker.go b/src/arduino.cc/builder/phases/linker.go index 166b2b0d..96ba5f88 100644 --- a/src/arduino.cc/builder/phases/linker.go +++ b/src/arduino.cc/builder/phases/linker.go @@ -42,7 +42,7 @@ import ( type Linker struct{} -func (s *Linker) Run(context map[string]interface{}, ctx *types.Context) error { +func (s *Linker) Run(ctx *types.Context) error { objectFilesSketch := ctx.SketchObjectFiles objectFilesLibraries := ctx.LibrariesObjectFiles objectFilesCore := ctx.CoreObjectsFiles diff --git a/src/arduino.cc/builder/phases/sketch_builder.go b/src/arduino.cc/builder/phases/sketch_builder.go index 35cdd65f..dcdc4d47 100644 --- a/src/arduino.cc/builder/phases/sketch_builder.go +++ b/src/arduino.cc/builder/phases/sketch_builder.go @@ -38,7 +38,7 @@ import ( type SketchBuilder struct{} -func (s *SketchBuilder) Run(context map[string]interface{}, ctx *types.Context) error { +func (s *SketchBuilder) Run(ctx *types.Context) error { sketchBuildPath := ctx.SketchBuildPath buildProperties := ctx.BuildProperties includes := ctx.IncludeFolders diff --git a/src/arduino.cc/builder/platform_keys_rewrite_loader.go b/src/arduino.cc/builder/platform_keys_rewrite_loader.go index 0aa64e0c..3112440c 100644 --- a/src/arduino.cc/builder/platform_keys_rewrite_loader.go +++ b/src/arduino.cc/builder/platform_keys_rewrite_loader.go @@ -44,7 +44,7 @@ import ( type PlatformKeysRewriteLoader struct{} -func (s *PlatformKeysRewriteLoader) Run(context map[string]interface{}, ctx *types.Context) error { +func (s *PlatformKeysRewriteLoader) Run(ctx *types.Context) error { logger := ctx.GetLogger() folders := ctx.HardwareFolders diff --git a/src/arduino.cc/builder/print_preprocessed_source.go b/src/arduino.cc/builder/print_preprocessed_source.go index ce2bd5e8..b788cb72 100644 --- a/src/arduino.cc/builder/print_preprocessed_source.go +++ b/src/arduino.cc/builder/print_preprocessed_source.go @@ -36,7 +36,7 @@ import ( type PrintPreprocessedSource struct{} -func (s *PrintPreprocessedSource) Run(context map[string]interface{}, ctx *types.Context) error { +func (s *PrintPreprocessedSource) Run(ctx *types.Context) error { fmt.Println(ctx.SourceGccMinusE) return nil } diff --git a/src/arduino.cc/builder/print_used_and_not_used_libraries.go b/src/arduino.cc/builder/print_used_and_not_used_libraries.go index 1a552a84..ae490a9f 100644 --- a/src/arduino.cc/builder/print_used_and_not_used_libraries.go +++ b/src/arduino.cc/builder/print_used_and_not_used_libraries.go @@ -38,7 +38,7 @@ import ( type PrintUsedAndNotUsedLibraries struct{} -func (s *PrintUsedAndNotUsedLibraries) Run(context map[string]interface{}, ctx *types.Context) error { +func (s *PrintUsedAndNotUsedLibraries) Run(ctx *types.Context) error { if ctx.DebugLevel < 0 { return nil } diff --git a/src/arduino.cc/builder/print_used_libraries_if_verbose.go b/src/arduino.cc/builder/print_used_libraries_if_verbose.go index 369a2cc6..afcf4eb4 100644 --- a/src/arduino.cc/builder/print_used_libraries_if_verbose.go +++ b/src/arduino.cc/builder/print_used_libraries_if_verbose.go @@ -37,7 +37,7 @@ import ( type PrintUsedLibrariesIfVerbose struct{} -func (s *PrintUsedLibrariesIfVerbose) Run(context map[string]interface{}, ctx *types.Context) error { +func (s *PrintUsedLibrariesIfVerbose) Run(ctx *types.Context) error { verbose := ctx.Verbose logger := ctx.GetLogger() diff --git a/src/arduino.cc/builder/prototypes_adder.go b/src/arduino.cc/builder/prototypes_adder.go index bfd3087a..9e05b109 100644 --- a/src/arduino.cc/builder/prototypes_adder.go +++ b/src/arduino.cc/builder/prototypes_adder.go @@ -39,7 +39,7 @@ import ( type PrototypesAdder struct{} -func (s *PrototypesAdder) Run(context map[string]interface{}, ctx *types.Context) error { +func (s *PrototypesAdder) Run(ctx *types.Context) error { debugOutput := ctx.DebugPreprocessor source := ctx.Source diff --git a/src/arduino.cc/builder/read_file_and_store_in_context.go b/src/arduino.cc/builder/read_file_and_store_in_context.go index ecd65d9a..bac49009 100644 --- a/src/arduino.cc/builder/read_file_and_store_in_context.go +++ b/src/arduino.cc/builder/read_file_and_store_in_context.go @@ -39,7 +39,7 @@ type ReadFileAndStoreInContext struct { Target *string } -func (s *ReadFileAndStoreInContext) Run(context map[string]interface{}, ctx *types.Context) error { +func (s *ReadFileAndStoreInContext) Run(ctx *types.Context) error { bytes, err := ioutil.ReadFile(ctx.FileToRead) if err != nil { return i18n.WrapError(err) diff --git a/src/arduino.cc/builder/recipe_runner.go b/src/arduino.cc/builder/recipe_runner.go index 34b91727..98f4632f 100644 --- a/src/arduino.cc/builder/recipe_runner.go +++ b/src/arduino.cc/builder/recipe_runner.go @@ -44,7 +44,7 @@ type RecipeByPrefixSuffixRunner struct { Suffix string } -func (s *RecipeByPrefixSuffixRunner) Run(context map[string]interface{}, ctx *types.Context) error { +func (s *RecipeByPrefixSuffixRunner) Run(ctx *types.Context) error { logger := ctx.GetLogger() if ctx.DebugLevel >= 10 { logger.Fprintln(os.Stdout, constants.LOG_LEVEL_DEBUG, constants.MSG_LOOKING_FOR_RECIPES, s.Prefix, s.Suffix) diff --git a/src/arduino.cc/builder/rewrite_hardware_keys.go b/src/arduino.cc/builder/rewrite_hardware_keys.go index 26781da1..a245d309 100644 --- a/src/arduino.cc/builder/rewrite_hardware_keys.go +++ b/src/arduino.cc/builder/rewrite_hardware_keys.go @@ -36,7 +36,7 @@ import ( type RewriteHardwareKeys struct{} -func (s *RewriteHardwareKeys) Run(context map[string]interface{}, ctx *types.Context) error { +func (s *RewriteHardwareKeys) Run(ctx *types.Context) error { if ctx.PlatformKeyRewrites.Empty() { return nil } diff --git a/src/arduino.cc/builder/set_custom_build_properties.go b/src/arduino.cc/builder/set_custom_build_properties.go index c761a028..330a25cc 100644 --- a/src/arduino.cc/builder/set_custom_build_properties.go +++ b/src/arduino.cc/builder/set_custom_build_properties.go @@ -37,7 +37,7 @@ import ( type SetCustomBuildProperties struct{} -func (s *SetCustomBuildProperties) Run(context map[string]interface{}, ctx *types.Context) error { +func (s *SetCustomBuildProperties) Run(ctx *types.Context) error { logger := ctx.GetLogger() buildProperties := ctx.BuildProperties customBuildProperties, err := props.LoadFromSlice(ctx.CustomBuildProperties, logger) diff --git a/src/arduino.cc/builder/setup_build_properties.go b/src/arduino.cc/builder/setup_build_properties.go index c61241f9..9523a09d 100644 --- a/src/arduino.cc/builder/setup_build_properties.go +++ b/src/arduino.cc/builder/setup_build_properties.go @@ -42,7 +42,7 @@ import ( type SetupBuildProperties struct{} -func (s *SetupBuildProperties) Run(context map[string]interface{}, ctx *types.Context) error { +func (s *SetupBuildProperties) Run(ctx *types.Context) error { packages := ctx.Hardware targetPlatform := ctx.TargetPlatform diff --git a/src/arduino.cc/builder/sketch_loader.go b/src/arduino.cc/builder/sketch_loader.go index ced41d30..dba7ce3c 100644 --- a/src/arduino.cc/builder/sketch_loader.go +++ b/src/arduino.cc/builder/sketch_loader.go @@ -44,7 +44,7 @@ import ( type SketchLoader struct{} -func (s *SketchLoader) Run(context map[string]interface{}, ctx *types.Context) error { +func (s *SketchLoader) Run(ctx *types.Context) error { if ctx.SketchLocation == "" { return nil } diff --git a/src/arduino.cc/builder/sketch_saver.go b/src/arduino.cc/builder/sketch_saver.go index 9f6e4827..8737cc69 100644 --- a/src/arduino.cc/builder/sketch_saver.go +++ b/src/arduino.cc/builder/sketch_saver.go @@ -38,7 +38,7 @@ import ( type SketchSaver struct{} -func (s *SketchSaver) Run(context map[string]interface{}, ctx *types.Context) error { +func (s *SketchSaver) Run(ctx *types.Context) error { sketch := ctx.Sketch sketchBuildPath := ctx.SketchBuildPath diff --git a/src/arduino.cc/builder/sketch_source_merger.go b/src/arduino.cc/builder/sketch_source_merger.go index e44d2de6..36c7c7a9 100644 --- a/src/arduino.cc/builder/sketch_source_merger.go +++ b/src/arduino.cc/builder/sketch_source_merger.go @@ -38,7 +38,7 @@ import ( type SketchSourceMerger struct{} -func (s *SketchSourceMerger) Run(context map[string]interface{}, ctx *types.Context) error { +func (s *SketchSourceMerger) Run(ctx *types.Context) error { sketch := ctx.Sketch lineOffset := 0 diff --git a/src/arduino.cc/builder/store_build_options_map.go b/src/arduino.cc/builder/store_build_options_map.go index 3044999e..a318e77f 100644 --- a/src/arduino.cc/builder/store_build_options_map.go +++ b/src/arduino.cc/builder/store_build_options_map.go @@ -38,7 +38,7 @@ import ( type StoreBuildOptionsMap struct{} -func (s *StoreBuildOptionsMap) Run(context map[string]interface{}, ctx *types.Context) error { +func (s *StoreBuildOptionsMap) Run(ctx *types.Context) error { utils.WriteFile(filepath.Join(ctx.BuildPath, constants.BUILD_OPTIONS_FILE), ctx.BuildOptionsJson) return nil } diff --git a/src/arduino.cc/builder/target_board_resolver.go b/src/arduino.cc/builder/target_board_resolver.go index 30b69854..875c9455 100644 --- a/src/arduino.cc/builder/target_board_resolver.go +++ b/src/arduino.cc/builder/target_board_resolver.go @@ -39,7 +39,7 @@ import ( type TargetBoardResolver struct{} -func (s *TargetBoardResolver) Run(context map[string]interface{}, ctx *types.Context) error { +func (s *TargetBoardResolver) Run(ctx *types.Context) error { fqbn := ctx.FQBN fqbnParts := strings.Split(fqbn, ":") diff --git a/src/arduino.cc/builder/test/add_additional_entries_to_context_test.go b/src/arduino.cc/builder/test/add_additional_entries_to_context_test.go index a300f3ae..a2bfbfc6 100644 --- a/src/arduino.cc/builder/test/add_additional_entries_to_context_test.go +++ b/src/arduino.cc/builder/test/add_additional_entries_to_context_test.go @@ -39,11 +39,10 @@ import ( ) func TestAddAdditionalEntriesToContextNoBuildPath(t *testing.T) { - context := make(map[string]interface{}) ctx := &types.Context{} command := builder.AddAdditionalEntriesToContext{} - NoError(t, command.Run(context, ctx)) + NoError(t, command.Run(ctx)) require.Empty(t, ctx.PreprocPath) require.Empty(t, ctx.SketchBuildPath) @@ -59,12 +58,11 @@ func TestAddAdditionalEntriesToContextNoBuildPath(t *testing.T) { } func TestAddAdditionalEntriesToContextWithBuildPath(t *testing.T) { - context := make(map[string]interface{}) ctx := &types.Context{} ctx.BuildPath = "folder" command := builder.AddAdditionalEntriesToContext{} - NoError(t, command.Run(context, ctx)) + NoError(t, command.Run(ctx)) require.Equal(t, Abs(t, filepath.Join("folder", constants.FOLDER_PREPROC)), ctx.PreprocPath) require.Equal(t, Abs(t, filepath.Join("folder", constants.FOLDER_SKETCH)), ctx.SketchBuildPath) diff --git a/src/arduino.cc/builder/test/add_build_board_property_if_missing_test.go b/src/arduino.cc/builder/test/add_build_board_property_if_missing_test.go index 8aa03e63..8a38f08b 100644 --- a/src/arduino.cc/builder/test/add_build_board_property_if_missing_test.go +++ b/src/arduino.cc/builder/test/add_build_board_property_if_missing_test.go @@ -39,7 +39,6 @@ import ( ) func TestAddBuildBoardPropertyIfMissing(t *testing.T) { - context := make(map[string]interface{}) ctx := &types.Context{ HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware", "user_hardware"}, FQBN: "my_avr_platform:avr:mymega", @@ -52,7 +51,7 @@ func TestAddBuildBoardPropertyIfMissing(t *testing.T) { } for _, command := range commands { - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) } @@ -67,7 +66,6 @@ func TestAddBuildBoardPropertyIfMissing(t *testing.T) { } func TestAddBuildBoardPropertyIfMissingNotMissing(t *testing.T) { - context := make(map[string]interface{}) ctx := &types.Context{ HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware", "user_hardware"}, FQBN: "my_avr_platform:avr:mymega:cpu=atmega2560", @@ -80,7 +78,7 @@ func TestAddBuildBoardPropertyIfMissingNotMissing(t *testing.T) { } for _, command := range commands { - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) } diff --git a/src/arduino.cc/builder/test/additional_sketch_files_copier_test.go b/src/arduino.cc/builder/test/additional_sketch_files_copier_test.go index fe2b68bc..85d39cb9 100644 --- a/src/arduino.cc/builder/test/additional_sketch_files_copier_test.go +++ b/src/arduino.cc/builder/test/additional_sketch_files_copier_test.go @@ -55,7 +55,6 @@ func (s ByFileInfoName) Less(i, j int) bool { } func TestCopyOtherFiles(t *testing.T) { - context := make(map[string]interface{}) ctx := &types.Context{ SketchLocation: filepath.Join("sketch1", "sketch.ino"), } @@ -70,7 +69,7 @@ func TestCopyOtherFiles(t *testing.T) { } for _, command := range commands { - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) } @@ -93,7 +92,6 @@ func TestCopyOtherFiles(t *testing.T) { } func TestCopyOtherFilesOnlyIfChanged(t *testing.T) { - context := make(map[string]interface{}) ctx := &types.Context{ SketchLocation: filepath.Join("sketch1", "sketch.ino"), } @@ -108,7 +106,7 @@ func TestCopyOtherFilesOnlyIfChanged(t *testing.T) { } for _, command := range commands { - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) } @@ -117,14 +115,13 @@ func TestCopyOtherFilesOnlyIfChanged(t *testing.T) { time.Sleep(2 * time.Second) - context = make(map[string]interface{}) ctx = &types.Context{ SketchLocation: filepath.Join("sketch1", "sketch.ino"), BuildPath: buildPath, } for _, command := range commands { - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) } diff --git a/src/arduino.cc/builder/test/builder_test.go b/src/arduino.cc/builder/test/builder_test.go index 1f20c716..5aeb8f4c 100644 --- a/src/arduino.cc/builder/test/builder_test.go +++ b/src/arduino.cc/builder/test/builder_test.go @@ -43,7 +43,6 @@ import ( func TestBuilderEmptySketch(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) - context := make(map[string]interface{}) ctx := &types.Context{ HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, ToolsFolders: []string{"downloaded_tools"}, @@ -61,7 +60,7 @@ func TestBuilderEmptySketch(t *testing.T) { ctx.DebugLevel = 10 command := builder.Builder{} - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) _, err = os.Stat(filepath.Join(buildPath, constants.FOLDER_CORE, "HardwareSerial.cpp.o")) @@ -79,7 +78,6 @@ func TestBuilderEmptySketch(t *testing.T) { func TestBuilderBridge(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) - context := make(map[string]interface{}) ctx := &types.Context{ HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, ToolsFolders: []string{"downloaded_tools"}, @@ -95,7 +93,7 @@ func TestBuilderBridge(t *testing.T) { defer os.RemoveAll(buildPath) command := builder.Builder{} - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) _, err = os.Stat(filepath.Join(buildPath, constants.FOLDER_CORE, "HardwareSerial.cpp.o")) @@ -115,7 +113,6 @@ func TestBuilderBridge(t *testing.T) { func TestBuilderSketchWithConfig(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) - context := make(map[string]interface{}) ctx := &types.Context{ HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, ToolsFolders: []string{"downloaded_tools"}, @@ -130,7 +127,7 @@ func TestBuilderSketchWithConfig(t *testing.T) { defer os.RemoveAll(buildPath) command := builder.Builder{} - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) _, err = os.Stat(filepath.Join(buildPath, constants.FOLDER_CORE, "HardwareSerial.cpp.o")) @@ -150,7 +147,6 @@ func TestBuilderSketchWithConfig(t *testing.T) { func TestBuilderBridgeTwice(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) - context := make(map[string]interface{}) ctx := &types.Context{ HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, ToolsFolders: []string{"downloaded_tools"}, @@ -165,11 +161,11 @@ func TestBuilderBridgeTwice(t *testing.T) { defer os.RemoveAll(buildPath) command := builder.Builder{} - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) command = builder.Builder{} - err = command.Run(context, ctx) + err = command.Run(ctx) NoError(t, err) _, err = os.Stat(filepath.Join(buildPath, constants.FOLDER_CORE, "HardwareSerial.cpp.o")) @@ -189,7 +185,6 @@ func TestBuilderBridgeTwice(t *testing.T) { func TestBuilderBridgeSAM(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) - context := make(map[string]interface{}) ctx := &types.Context{ HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, ToolsFolders: []string{"downloaded_tools"}, @@ -206,7 +201,7 @@ func TestBuilderBridgeSAM(t *testing.T) { ctx.WarningsLevel = "all" command := builder.Builder{} - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) _, err = os.Stat(filepath.Join(buildPath, constants.FOLDER_CORE, "syscalls_sam3.c.o")) @@ -235,7 +230,6 @@ func TestBuilderBridgeSAM(t *testing.T) { func TestBuilderBridgeRedBearLab(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) - context := make(map[string]interface{}) ctx := &types.Context{ HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware", "downloaded_board_manager_stuff"}, ToolsFolders: []string{"downloaded_tools", "downloaded_board_manager_stuff"}, @@ -250,7 +244,7 @@ func TestBuilderBridgeRedBearLab(t *testing.T) { defer os.RemoveAll(buildPath) command := builder.Builder{} - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) _, err = os.Stat(filepath.Join(buildPath, constants.FOLDER_CORE, "HardwareSerial.cpp.o")) @@ -270,7 +264,6 @@ func TestBuilderBridgeRedBearLab(t *testing.T) { func TestBuilderSketchNoFunctions(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) - context := make(map[string]interface{}) ctx := &types.Context{ HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware", "downloaded_board_manager_stuff"}, ToolsFolders: []string{"downloaded_tools", "downloaded_board_manager_stuff"}, @@ -285,14 +278,13 @@ func TestBuilderSketchNoFunctions(t *testing.T) { defer os.RemoveAll(buildPath) command := builder.Builder{} - err := command.Run(context, ctx) + err := command.Run(ctx) require.Error(t, err) } func TestBuilderSketchWithBackup(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) - context := make(map[string]interface{}) ctx := &types.Context{ HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware", "downloaded_board_manager_stuff"}, ToolsFolders: []string{"downloaded_tools", "downloaded_board_manager_stuff"}, @@ -307,14 +299,13 @@ func TestBuilderSketchWithBackup(t *testing.T) { defer os.RemoveAll(buildPath) command := builder.Builder{} - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) } func TestBuilderSketchWithOldLib(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) - context := make(map[string]interface{}) ctx := &types.Context{ HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, ToolsFolders: []string{"downloaded_tools"}, @@ -329,14 +320,13 @@ func TestBuilderSketchWithOldLib(t *testing.T) { defer os.RemoveAll(buildPath) command := builder.Builder{} - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) } func TestBuilderSketchWithSubfolders(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) - context := make(map[string]interface{}) ctx := &types.Context{ HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, ToolsFolders: []string{"downloaded_tools"}, @@ -351,14 +341,13 @@ func TestBuilderSketchWithSubfolders(t *testing.T) { defer os.RemoveAll(buildPath) command := builder.Builder{} - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) } func TestBuilderSketchBuildPathContainsUnusedPreviouslyCompiledLibrary(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) - context := make(map[string]interface{}) ctx := &types.Context{ HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, ToolsFolders: []string{"downloaded_tools"}, @@ -375,7 +364,7 @@ func TestBuilderSketchBuildPathContainsUnusedPreviouslyCompiledLibrary(t *testin NoError(t, os.MkdirAll(filepath.Join(buildPath, constants.FOLDER_LIBRARIES, "SPI"), os.FileMode(0755))) command := builder.Builder{} - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) _, err = os.Stat(filepath.Join(buildPath, constants.FOLDER_LIBRARIES, "SPI")) diff --git a/src/arduino.cc/builder/test/collect_all_source_files_from_folders_with_sources_test.go b/src/arduino.cc/builder/test/collect_all_source_files_from_folders_with_sources_test.go index 2a868bc9..6b92d840 100644 --- a/src/arduino.cc/builder/test/collect_all_source_files_from_folders_with_sources_test.go +++ b/src/arduino.cc/builder/test/collect_all_source_files_from_folders_with_sources_test.go @@ -39,7 +39,6 @@ import ( ) func TestCollectAllSourceFilesFromFoldersWithSources(t *testing.T) { - context := make(map[string]interface{}) ctx := &types.Context{} sourceFiles := &types.UniqueStringQueue{} @@ -53,7 +52,7 @@ func TestCollectAllSourceFilesFromFoldersWithSources(t *testing.T) { } for _, command := range commands { - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) } @@ -66,7 +65,6 @@ func TestCollectAllSourceFilesFromFoldersWithSources(t *testing.T) { } func TestCollectAllSourceFilesFromFoldersWithSourcesOfLibrary(t *testing.T) { - context := make(map[string]interface{}) ctx := &types.Context{} sourceFiles := &types.UniqueStringQueue{} @@ -80,7 +78,7 @@ func TestCollectAllSourceFilesFromFoldersWithSourcesOfLibrary(t *testing.T) { } for _, command := range commands { - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) } @@ -101,7 +99,6 @@ func TestCollectAllSourceFilesFromFoldersWithSourcesOfLibrary(t *testing.T) { } func TestCollectAllSourceFilesFromFoldersWithSourcesOfOldLibrary(t *testing.T) { - context := make(map[string]interface{}) ctx := &types.Context{} sourceFiles := &types.UniqueStringQueue{} @@ -117,7 +114,7 @@ func TestCollectAllSourceFilesFromFoldersWithSourcesOfOldLibrary(t *testing.T) { } for _, command := range commands { - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) } diff --git a/src/arduino.cc/builder/test/create_build_options_map_test.go b/src/arduino.cc/builder/test/create_build_options_map_test.go index 3ef78c5a..f129025c 100644 --- a/src/arduino.cc/builder/test/create_build_options_map_test.go +++ b/src/arduino.cc/builder/test/create_build_options_map_test.go @@ -37,7 +37,6 @@ import ( ) func TestCreateBuildOptionsMap(t *testing.T) { - context := make(map[string]interface{}) ctx := &types.Context{ HardwareFolders: []string{"hardware", "hardware2"}, ToolsFolders: []string{"tools"}, @@ -51,7 +50,7 @@ func TestCreateBuildOptionsMap(t *testing.T) { } create := builder.CreateBuildOptionsMap{} - err := create.Run(context, ctx) + err := create.Run(ctx) NoError(t, err) require.Equal(t, "{\n"+ diff --git a/src/arduino.cc/builder/test/ctags_parser_test.go b/src/arduino.cc/builder/test/ctags_parser_test.go index bec07c9a..45f246af 100644 --- a/src/arduino.cc/builder/test/ctags_parser_test.go +++ b/src/arduino.cc/builder/test/ctags_parser_test.go @@ -39,7 +39,6 @@ import ( ) func TestCTagsParserShouldListPrototypes(t *testing.T) { - context := make(map[string]interface{}) ctx := &types.Context{} bytes, err := ioutil.ReadFile(filepath.Join("ctags_output", "TestCTagsParserShouldListPrototypes.txt")) @@ -48,7 +47,7 @@ func TestCTagsParserShouldListPrototypes(t *testing.T) { ctx.CTagsOutput = string(bytes) ctagsParser := ctags.CTagsParser{} - ctagsParser.Run(context, ctx) + ctagsParser.Run(ctx) tags := ctx.CTagsOfPreprocessedSource @@ -88,7 +87,6 @@ func TestCTagsParserShouldListPrototypes(t *testing.T) { } func TestCTagsParserShouldListTemplates(t *testing.T) { - context := make(map[string]interface{}) ctx := &types.Context{} bytes, err := ioutil.ReadFile(filepath.Join("ctags_output", "TestCTagsParserShouldListTemplates.txt")) @@ -97,7 +95,7 @@ func TestCTagsParserShouldListTemplates(t *testing.T) { ctx.CTagsOutput = string(bytes) ctagsParser := ctags.CTagsParser{} - ctagsParser.Run(context, ctx) + ctagsParser.Run(ctx) tags := ctx.CTagsOfPreprocessedSource @@ -117,7 +115,6 @@ func TestCTagsParserShouldListTemplates(t *testing.T) { } func TestCTagsParserShouldListTemplates2(t *testing.T) { - context := make(map[string]interface{}) ctx := &types.Context{} bytes, err := ioutil.ReadFile(filepath.Join("ctags_output", "TestCTagsParserShouldListTemplates2.txt")) @@ -126,7 +123,7 @@ func TestCTagsParserShouldListTemplates2(t *testing.T) { ctx.CTagsOutput = string(bytes) ctagsParser := ctags.CTagsParser{} - ctagsParser.Run(context, ctx) + ctagsParser.Run(ctx) tags := ctx.CTagsOfPreprocessedSource @@ -148,7 +145,6 @@ func TestCTagsParserShouldListTemplates2(t *testing.T) { } func TestCTagsParserShouldDealWithClasses(t *testing.T) { - context := make(map[string]interface{}) ctx := &types.Context{} bytes, err := ioutil.ReadFile(filepath.Join("ctags_output", "TestCTagsParserShouldDealWithClasses.txt")) @@ -157,7 +153,7 @@ func TestCTagsParserShouldDealWithClasses(t *testing.T) { ctx.CTagsOutput = string(bytes) ctagsParser := ctags.CTagsParser{} - ctagsParser.Run(context, ctx) + ctagsParser.Run(ctx) tags := ctx.CTagsOfPreprocessedSource @@ -171,7 +167,6 @@ func TestCTagsParserShouldDealWithClasses(t *testing.T) { } func TestCTagsParserShouldDealWithStructs(t *testing.T) { - context := make(map[string]interface{}) ctx := &types.Context{} bytes, err := ioutil.ReadFile(filepath.Join("ctags_output", "TestCTagsParserShouldDealWithStructs.txt")) @@ -180,7 +175,7 @@ func TestCTagsParserShouldDealWithStructs(t *testing.T) { ctx.CTagsOutput = string(bytes) ctagsParser := ctags.CTagsParser{} - ctagsParser.Run(context, ctx) + ctagsParser.Run(ctx) tags := ctx.CTagsOfPreprocessedSource @@ -204,7 +199,6 @@ func TestCTagsParserShouldDealWithStructs(t *testing.T) { } func TestCTagsParserShouldDealWithMacros(t *testing.T) { - context := make(map[string]interface{}) ctx := &types.Context{} bytes, err := ioutil.ReadFile(filepath.Join("ctags_output", "TestCTagsParserShouldDealWithMacros.txt")) @@ -213,7 +207,7 @@ func TestCTagsParserShouldDealWithMacros(t *testing.T) { ctx.CTagsOutput = string(bytes) ctagsParser := ctags.CTagsParser{} - ctagsParser.Run(context, ctx) + ctagsParser.Run(ctx) tags := ctx.CTagsOfPreprocessedSource @@ -245,7 +239,6 @@ func TestCTagsParserShouldDealWithMacros(t *testing.T) { } func TestCTagsParserShouldDealFunctionWithDifferentSignatures(t *testing.T) { - context := make(map[string]interface{}) ctx := &types.Context{} bytes, err := ioutil.ReadFile(filepath.Join("ctags_output", "TestCTagsParserShouldDealFunctionWithDifferentSignatures.txt")) @@ -254,7 +247,7 @@ func TestCTagsParserShouldDealFunctionWithDifferentSignatures(t *testing.T) { ctx.CTagsOutput = string(bytes) ctagsParser := ctags.CTagsParser{} - ctagsParser.Run(context, ctx) + ctagsParser.Run(ctx) tags := ctx.CTagsOfPreprocessedSource @@ -271,7 +264,6 @@ func TestCTagsParserShouldDealFunctionWithDifferentSignatures(t *testing.T) { } func TestCTagsParserClassMembersAreFilteredOut(t *testing.T) { - context := make(map[string]interface{}) ctx := &types.Context{} bytes, err := ioutil.ReadFile(filepath.Join("ctags_output", "TestCTagsParserClassMembersAreFilteredOut.txt")) @@ -280,7 +272,7 @@ func TestCTagsParserClassMembersAreFilteredOut(t *testing.T) { ctx.CTagsOutput = string(bytes) ctagsParser := ctags.CTagsParser{} - ctagsParser.Run(context, ctx) + ctagsParser.Run(ctx) tags := ctx.CTagsOfPreprocessedSource @@ -306,7 +298,6 @@ func TestCTagsParserClassMembersAreFilteredOut(t *testing.T) { } func TestCTagsParserStructWithFunctions(t *testing.T) { - context := make(map[string]interface{}) ctx := &types.Context{} bytes, err := ioutil.ReadFile(filepath.Join("ctags_output", "TestCTagsParserStructWithFunctions.txt")) @@ -315,7 +306,7 @@ func TestCTagsParserStructWithFunctions(t *testing.T) { ctx.CTagsOutput = string(bytes) ctagsParser := ctags.CTagsParser{} - ctagsParser.Run(context, ctx) + ctagsParser.Run(ctx) tags := ctx.CTagsOfPreprocessedSource @@ -349,7 +340,6 @@ func TestCTagsParserStructWithFunctions(t *testing.T) { } func TestCTagsParserDefaultArguments(t *testing.T) { - context := make(map[string]interface{}) ctx := &types.Context{} bytes, err := ioutil.ReadFile(filepath.Join("ctags_output", "TestCTagsParserDefaultArguments.txt")) @@ -358,7 +348,7 @@ func TestCTagsParserDefaultArguments(t *testing.T) { ctx.CTagsOutput = string(bytes) ctagsParser := ctags.CTagsParser{} - ctagsParser.Run(context, ctx) + ctagsParser.Run(ctx) tags := ctx.CTagsOfPreprocessedSource @@ -376,7 +366,6 @@ func TestCTagsParserDefaultArguments(t *testing.T) { } func TestCTagsParserNamespace(t *testing.T) { - context := make(map[string]interface{}) ctx := &types.Context{} bytes, err := ioutil.ReadFile(filepath.Join("ctags_output", "TestCTagsParserNamespace.txt")) @@ -385,7 +374,7 @@ func TestCTagsParserNamespace(t *testing.T) { ctx.CTagsOutput = string(bytes) ctagsParser := ctags.CTagsParser{} - ctagsParser.Run(context, ctx) + ctagsParser.Run(ctx) tags := ctx.CTagsOfPreprocessedSource @@ -403,7 +392,6 @@ func TestCTagsParserNamespace(t *testing.T) { } func TestCTagsParserStatic(t *testing.T) { - context := make(map[string]interface{}) ctx := &types.Context{} bytes, err := ioutil.ReadFile(filepath.Join("ctags_output", "TestCTagsParserStatic.txt")) @@ -412,7 +400,7 @@ func TestCTagsParserStatic(t *testing.T) { ctx.CTagsOutput = string(bytes) ctagsParser := ctags.CTagsParser{} - ctagsParser.Run(context, ctx) + ctagsParser.Run(ctx) tags := ctx.CTagsOfPreprocessedSource @@ -429,7 +417,6 @@ func TestCTagsParserStatic(t *testing.T) { } func TestCTagsParserFunctionPointer(t *testing.T) { - context := make(map[string]interface{}) ctx := &types.Context{} bytes, err := ioutil.ReadFile(filepath.Join("ctags_output", "TestCTagsParserFunctionPointer.txt")) @@ -438,7 +425,7 @@ func TestCTagsParserFunctionPointer(t *testing.T) { ctx.CTagsOutput = string(bytes) ctagsParser := ctags.CTagsParser{} - ctagsParser.Run(context, ctx) + ctagsParser.Run(ctx) tags := ctx.CTagsOfPreprocessedSource @@ -458,7 +445,6 @@ func TestCTagsParserFunctionPointer(t *testing.T) { } func TestCTagsParserFunctionPointers(t *testing.T) { - context := make(map[string]interface{}) ctx := &types.Context{} bytes, err := ioutil.ReadFile(filepath.Join("ctags_output", "TestCTagsParserFunctionPointers.txt")) @@ -467,7 +453,7 @@ func TestCTagsParserFunctionPointers(t *testing.T) { ctx.CTagsOutput = string(bytes) ctagsParser := ctags.CTagsParser{} - ctagsParser.Run(context, ctx) + ctagsParser.Run(ctx) tags := ctx.CTagsOfPreprocessedSource diff --git a/src/arduino.cc/builder/test/ctags_runner_test.go b/src/arduino.cc/builder/test/ctags_runner_test.go index 7e188c71..d7d96ef4 100644 --- a/src/arduino.cc/builder/test/ctags_runner_test.go +++ b/src/arduino.cc/builder/test/ctags_runner_test.go @@ -46,7 +46,6 @@ func TestCTagsRunner(t *testing.T) { sketchLocation := Abs(t, filepath.Join("downloaded_libraries", "Bridge", "examples", "Bridge", "Bridge.ino")) - context := make(map[string]interface{}) ctx := &types.Context{ HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, ToolsFolders: []string{"downloaded_tools"}, @@ -76,7 +75,7 @@ func TestCTagsRunner(t *testing.T) { } for _, command := range commands { - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) } @@ -97,7 +96,6 @@ func TestCTagsRunnerSketchWithClass(t *testing.T) { sketchLocation := Abs(t, filepath.Join("sketch_with_class", "sketch.ino")) - context := make(map[string]interface{}) ctx := &types.Context{ HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, ToolsFolders: []string{"downloaded_tools"}, @@ -127,7 +125,7 @@ func TestCTagsRunnerSketchWithClass(t *testing.T) { } for _, command := range commands { - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) } @@ -146,7 +144,6 @@ func TestCTagsRunnerSketchWithTypename(t *testing.T) { sketchLocation := Abs(t, filepath.Join("sketch_with_typename", "sketch.ino")) - context := make(map[string]interface{}) ctx := &types.Context{ HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, ToolsFolders: []string{"downloaded_tools"}, @@ -176,7 +173,7 @@ func TestCTagsRunnerSketchWithTypename(t *testing.T) { } for _, command := range commands { - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) } @@ -194,7 +191,6 @@ func TestCTagsRunnerSketchWithNamespace(t *testing.T) { sketchLocation := Abs(t, filepath.Join("sketch_with_namespace", "sketch.ino")) - context := make(map[string]interface{}) ctx := &types.Context{ HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, ToolsFolders: []string{"downloaded_tools"}, @@ -224,7 +220,7 @@ func TestCTagsRunnerSketchWithNamespace(t *testing.T) { } for _, command := range commands { - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) } @@ -241,7 +237,6 @@ func TestCTagsRunnerSketchWithTemplates(t *testing.T) { sketchLocation := Abs(t, filepath.Join("sketch_with_templates_and_shift", "template_and_shift.cpp")) - context := make(map[string]interface{}) ctx := &types.Context{ HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, ToolsFolders: []string{"downloaded_tools"}, @@ -271,7 +266,7 @@ func TestCTagsRunnerSketchWithTemplates(t *testing.T) { } for _, command := range commands { - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) } diff --git a/src/arduino.cc/builder/test/ctags_to_prototypes_test.go b/src/arduino.cc/builder/test/ctags_to_prototypes_test.go index bf50e261..ca1a2a6b 100644 --- a/src/arduino.cc/builder/test/ctags_to_prototypes_test.go +++ b/src/arduino.cc/builder/test/ctags_to_prototypes_test.go @@ -40,13 +40,12 @@ import ( type CollectCtagsFromPreprocSource struct{} -func (*CollectCtagsFromPreprocSource) Run(context map[string]interface{}, ctx *types.Context) error { +func (*CollectCtagsFromPreprocSource) Run(ctx *types.Context) error { ctx.CTagsCollected = ctx.CTagsOfPreprocessedSource return nil } func TestCTagsToPrototypesShouldListPrototypes(t *testing.T) { - context := make(map[string]interface{}) ctx := &types.Context{} bytes, err := ioutil.ReadFile(filepath.Join("ctags_output", "TestCTagsParserShouldListPrototypes.txt")) @@ -61,7 +60,7 @@ func TestCTagsToPrototypesShouldListPrototypes(t *testing.T) { } for _, command := range commands { - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) } @@ -79,7 +78,6 @@ func TestCTagsToPrototypesShouldListPrototypes(t *testing.T) { } func TestCTagsToPrototypesShouldListTemplates(t *testing.T) { - context := make(map[string]interface{}) ctx := &types.Context{} bytes, err := ioutil.ReadFile(filepath.Join("ctags_output", "TestCTagsParserShouldListTemplates.txt")) @@ -94,7 +92,7 @@ func TestCTagsToPrototypesShouldListTemplates(t *testing.T) { } for _, command := range commands { - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) } @@ -110,7 +108,6 @@ func TestCTagsToPrototypesShouldListTemplates(t *testing.T) { } func TestCTagsToPrototypesShouldListTemplates2(t *testing.T) { - context := make(map[string]interface{}) ctx := &types.Context{} bytes, err := ioutil.ReadFile(filepath.Join("ctags_output", "TestCTagsParserShouldListTemplates2.txt")) @@ -125,7 +122,7 @@ func TestCTagsToPrototypesShouldListTemplates2(t *testing.T) { } for _, command := range commands { - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) } @@ -142,7 +139,6 @@ func TestCTagsToPrototypesShouldListTemplates2(t *testing.T) { } func TestCTagsToPrototypesShouldDealWithClasses(t *testing.T) { - context := make(map[string]interface{}) ctx := &types.Context{} bytes, err := ioutil.ReadFile(filepath.Join("ctags_output", "TestCTagsParserShouldDealWithClasses.txt")) @@ -157,7 +153,7 @@ func TestCTagsToPrototypesShouldDealWithClasses(t *testing.T) { } for _, command := range commands { - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) } @@ -169,7 +165,6 @@ func TestCTagsToPrototypesShouldDealWithClasses(t *testing.T) { } func TestCTagsToPrototypesShouldDealWithStructs(t *testing.T) { - context := make(map[string]interface{}) ctx := &types.Context{} bytes, err := ioutil.ReadFile(filepath.Join("ctags_output", "TestCTagsParserShouldDealWithStructs.txt")) @@ -184,7 +179,7 @@ func TestCTagsToPrototypesShouldDealWithStructs(t *testing.T) { } for _, command := range commands { - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) } @@ -200,7 +195,6 @@ func TestCTagsToPrototypesShouldDealWithStructs(t *testing.T) { } func TestCTagsToPrototypesShouldDealWithMacros(t *testing.T) { - context := make(map[string]interface{}) ctx := &types.Context{} bytes, err := ioutil.ReadFile(filepath.Join("ctags_output", "TestCTagsParserShouldDealWithMacros.txt")) @@ -215,7 +209,7 @@ func TestCTagsToPrototypesShouldDealWithMacros(t *testing.T) { } for _, command := range commands { - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) } @@ -233,7 +227,6 @@ func TestCTagsToPrototypesShouldDealWithMacros(t *testing.T) { } func TestCTagsToPrototypesShouldDealFunctionWithDifferentSignatures(t *testing.T) { - context := make(map[string]interface{}) ctx := &types.Context{} bytes, err := ioutil.ReadFile(filepath.Join("ctags_output", "TestCTagsParserShouldDealFunctionWithDifferentSignatures.txt")) @@ -248,7 +241,7 @@ func TestCTagsToPrototypesShouldDealFunctionWithDifferentSignatures(t *testing.T } for _, command := range commands { - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) } @@ -262,7 +255,6 @@ func TestCTagsToPrototypesShouldDealFunctionWithDifferentSignatures(t *testing.T } func TestCTagsToPrototypesClassMembersAreFilteredOut(t *testing.T) { - context := make(map[string]interface{}) ctx := &types.Context{} bytes, err := ioutil.ReadFile(filepath.Join("ctags_output", "TestCTagsParserClassMembersAreFilteredOut.txt")) @@ -277,7 +269,7 @@ func TestCTagsToPrototypesClassMembersAreFilteredOut(t *testing.T) { } for _, command := range commands { - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) } @@ -292,7 +284,6 @@ func TestCTagsToPrototypesClassMembersAreFilteredOut(t *testing.T) { } func TestCTagsToPrototypesStructWithFunctions(t *testing.T) { - context := make(map[string]interface{}) ctx := &types.Context{} bytes, err := ioutil.ReadFile(filepath.Join("ctags_output", "TestCTagsParserStructWithFunctions.txt")) @@ -307,7 +298,7 @@ func TestCTagsToPrototypesStructWithFunctions(t *testing.T) { } for _, command := range commands { - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) } @@ -322,7 +313,6 @@ func TestCTagsToPrototypesStructWithFunctions(t *testing.T) { } func TestCTagsToPrototypesDefaultArguments(t *testing.T) { - context := make(map[string]interface{}) ctx := &types.Context{} bytes, err := ioutil.ReadFile(filepath.Join("ctags_output", "TestCTagsParserDefaultArguments.txt")) @@ -337,7 +327,7 @@ func TestCTagsToPrototypesDefaultArguments(t *testing.T) { } for _, command := range commands { - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) } @@ -353,7 +343,6 @@ func TestCTagsToPrototypesDefaultArguments(t *testing.T) { } func TestCTagsToPrototypesNamespace(t *testing.T) { - context := make(map[string]interface{}) ctx := &types.Context{} bytes, err := ioutil.ReadFile(filepath.Join("ctags_output", "TestCTagsParserNamespace.txt")) @@ -368,7 +357,7 @@ func TestCTagsToPrototypesNamespace(t *testing.T) { } for _, command := range commands { - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) } @@ -383,7 +372,6 @@ func TestCTagsToPrototypesNamespace(t *testing.T) { } func TestCTagsToPrototypesStatic(t *testing.T) { - context := make(map[string]interface{}) ctx := &types.Context{} bytes, err := ioutil.ReadFile(filepath.Join("ctags_output", "TestCTagsParserStatic.txt")) @@ -398,7 +386,7 @@ func TestCTagsToPrototypesStatic(t *testing.T) { } for _, command := range commands { - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) } @@ -415,7 +403,6 @@ func TestCTagsToPrototypesStatic(t *testing.T) { } func TestCTagsToPrototypesFunctionPointer(t *testing.T) { - context := make(map[string]interface{}) ctx := &types.Context{} bytes, err := ioutil.ReadFile(filepath.Join("ctags_output", "TestCTagsParserFunctionPointer.txt")) @@ -430,7 +417,7 @@ func TestCTagsToPrototypesFunctionPointer(t *testing.T) { } for _, command := range commands { - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) } @@ -446,7 +433,6 @@ func TestCTagsToPrototypesFunctionPointer(t *testing.T) { } func TestCTagsToPrototypesFunctionPointers(t *testing.T) { - context := make(map[string]interface{}) ctx := &types.Context{} bytes, err := ioutil.ReadFile(filepath.Join("ctags_output", "TestCTagsParserFunctionPointers.txt")) @@ -461,7 +447,7 @@ func TestCTagsToPrototypesFunctionPointers(t *testing.T) { } for _, command := range commands { - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) } diff --git a/src/arduino.cc/builder/test/external_include_replacer_test.go b/src/arduino.cc/builder/test/external_include_replacer_test.go index b1e65b2b..e75b6597 100644 --- a/src/arduino.cc/builder/test/external_include_replacer_test.go +++ b/src/arduino.cc/builder/test/external_include_replacer_test.go @@ -71,13 +71,12 @@ var sourceWithPragmas = "#line 1 \"sketch_with_config.ino\"\n" + "}\n" func TestExternalIncludeReplacerIncludeToPragma(t *testing.T) { - context := make(map[string]interface{}) ctx := &types.Context{} ctx.Source = sourceWithIncludes ctx.Includes = []string{"/tmp/test184599776/sketch/config.h", "/tmp/test184599776/sketch/includes/de bug.h", "Bridge.h"} replacer := builder.ExternalIncludeReplacer{Source: &ctx.Source, Target: &ctx.SourceGccMinusE, From: "#include ", To: "#pragma ___MY_INCLUDE___ "} - err := replacer.Run(context, ctx) + err := replacer.Run(ctx) NoError(t, err) require.Equal(t, sourceWithIncludes, ctx.Source) @@ -85,13 +84,12 @@ func TestExternalIncludeReplacerIncludeToPragma(t *testing.T) { } func TestExternalIncludeReplacerPragmaToInclude(t *testing.T) { - context := make(map[string]interface{}) ctx := &types.Context{} ctx.SourceGccMinusE = sourceWithPragmas ctx.Includes = []string{"/tmp/test184599776/sketch/config.h", "/tmp/test184599776/sketch/includes/de bug.h", "Bridge.h"} replacer := builder.ExternalIncludeReplacer{Source: &ctx.SourceGccMinusE, Target: &ctx.SourceGccMinusE, From: "#pragma ___MY_INCLUDE___ ", To: "#include "} - err := replacer.Run(context, ctx) + err := replacer.Run(ctx) NoError(t, err) require.Empty(t, ctx.Source) diff --git a/src/arduino.cc/builder/test/fail_if_buildpath_equals_sketchpath_test.go b/src/arduino.cc/builder/test/fail_if_buildpath_equals_sketchpath_test.go index 676700f9..04da3ae7 100644 --- a/src/arduino.cc/builder/test/fail_if_buildpath_equals_sketchpath_test.go +++ b/src/arduino.cc/builder/test/fail_if_buildpath_equals_sketchpath_test.go @@ -37,23 +37,21 @@ import ( ) func TestFailIfBuildPathEqualsSketchPath(t *testing.T) { - context := make(map[string]interface{}) ctx := &types.Context{ SketchLocation: "buildPath/sketch.ino", BuildPath: "buildPath", } command := builder.FailIfBuildPathEqualsSketchPath{} - require.Error(t, command.Run(context, ctx)) + require.Error(t, command.Run(ctx)) } func TestFailIfBuildPathEqualsSketchPathSketchPathDiffers(t *testing.T) { - context := make(map[string]interface{}) ctx := &types.Context{ SketchLocation: "sketchPath/sketch.ino", BuildPath: "buildPath", } command := builder.FailIfBuildPathEqualsSketchPath{} - NoError(t, command.Run(context, ctx)) + NoError(t, command.Run(ctx)) } diff --git a/src/arduino.cc/builder/test/gcc_minus_m_output_parser_test.go b/src/arduino.cc/builder/test/gcc_minus_m_output_parser_test.go index 39cd8754..df848fcc 100644 --- a/src/arduino.cc/builder/test/gcc_minus_m_output_parser_test.go +++ b/src/arduino.cc/builder/test/gcc_minus_m_output_parser_test.go @@ -37,7 +37,6 @@ import ( ) func TestGCCMinusMOutputParser(t *testing.T) { - context := make(map[string]interface{}) ctx := &types.Context{} output := "sketch_with_config.o: sketch_with_config.ino config.h de\\ bug.h Bridge.h\n" + @@ -51,7 +50,7 @@ func TestGCCMinusMOutputParser(t *testing.T) { ctx.OutputGccMinusM = output parser := builder.GCCMinusMOutputParser{} - err := parser.Run(context, ctx) + err := parser.Run(ctx) NoError(t, err) includes := ctx.Includes @@ -62,7 +61,6 @@ func TestGCCMinusMOutputParser(t *testing.T) { } func TestGCCMinusMOutputParserEmptyOutput(t *testing.T) { - context := make(map[string]interface{}) ctx := &types.Context{} output := "sketch.ino.o: /tmp/test699709208/sketch/sketch.ino.cpp" @@ -70,7 +68,7 @@ func TestGCCMinusMOutputParserEmptyOutput(t *testing.T) { ctx.OutputGccMinusM = output parser := builder.GCCMinusMOutputParser{} - err := parser.Run(context, ctx) + err := parser.Run(ctx) NoError(t, err) includes := ctx.Includes @@ -78,7 +76,6 @@ func TestGCCMinusMOutputParserEmptyOutput(t *testing.T) { } func TestGCCMinusMOutputParserFirstLineOnMultipleLines(t *testing.T) { - context := make(map[string]interface{}) ctx := &types.Context{} output := "sketch_with_config.ino.o: \\\n" + @@ -95,7 +92,7 @@ func TestGCCMinusMOutputParserFirstLineOnMultipleLines(t *testing.T) { ctx.OutputGccMinusM = output parser := builder.GCCMinusMOutputParser{} - err := parser.Run(context, ctx) + err := parser.Run(ctx) NoError(t, err) includes := ctx.Includes diff --git a/src/arduino.cc/builder/test/generate_buildpath_if_missing_test.go b/src/arduino.cc/builder/test/generate_buildpath_if_missing_test.go index b0e98d94..e1ec6edc 100644 --- a/src/arduino.cc/builder/test/generate_buildpath_if_missing_test.go +++ b/src/arduino.cc/builder/test/generate_buildpath_if_missing_test.go @@ -39,13 +39,12 @@ import ( ) func TestGenerateBuildPathIfMissing(t *testing.T) { - context := make(map[string]interface{}) ctx := &types.Context{ SketchLocation: "test", } command := builder.GenerateBuildPathIfMissing{} - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) require.Equal(t, filepath.Join(os.TempDir(), "arduino-sketch-098F6BCD4621D373CADE4E832627B4F6"), ctx.BuildPath) @@ -54,13 +53,12 @@ func TestGenerateBuildPathIfMissing(t *testing.T) { } func TestGenerateBuildPathIfEmpty(t *testing.T) { - context := make(map[string]interface{}) ctx := &types.Context{ SketchLocation: "test", } createBuildPathIfMissing := builder.GenerateBuildPathIfMissing{} - err := createBuildPathIfMissing.Run(context, ctx) + err := createBuildPathIfMissing.Run(ctx) NoError(t, err) require.Equal(t, filepath.Join(os.TempDir(), "arduino-sketch-098F6BCD4621D373CADE4E832627B4F6"), ctx.BuildPath) @@ -69,19 +67,17 @@ func TestGenerateBuildPathIfEmpty(t *testing.T) { } func TestDontGenerateBuildPathIfPresent(t *testing.T) { - context := make(map[string]interface{}) ctx := &types.Context{} ctx.BuildPath = "test" createBuildPathIfMissing := builder.GenerateBuildPathIfMissing{} - err := createBuildPathIfMissing.Run(context, ctx) + err := createBuildPathIfMissing.Run(ctx) NoError(t, err) require.Equal(t, "test", ctx.BuildPath) } func TestGenerateBuildPathAndEnsureItExists(t *testing.T) { - context := make(map[string]interface{}) ctx := &types.Context{ SketchLocation: "test", } @@ -92,7 +88,7 @@ func TestGenerateBuildPathAndEnsureItExists(t *testing.T) { } for _, command := range commands { - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) } diff --git a/src/arduino.cc/builder/test/hardware_loader_test.go b/src/arduino.cc/builder/test/hardware_loader_test.go index f6a3dbce..c9ea1d52 100644 --- a/src/arduino.cc/builder/test/hardware_loader_test.go +++ b/src/arduino.cc/builder/test/hardware_loader_test.go @@ -41,7 +41,6 @@ import ( ) func TestLoadHardware(t *testing.T) { - context := make(map[string]interface{}) ctx := &types.Context{ HardwareFolders: []string{"downloaded_hardware", filepath.Join("..", "hardware"), "hardware"}, } @@ -51,7 +50,7 @@ func TestLoadHardware(t *testing.T) { } for _, command := range commands { - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) } @@ -86,7 +85,6 @@ func TestLoadHardware(t *testing.T) { } func TestLoadHardwareMixingUserHardwareFolder(t *testing.T) { - context := make(map[string]interface{}) ctx := &types.Context{ HardwareFolders: []string{"downloaded_hardware", filepath.Join("..", "hardware"), "hardware", "user_hardware"}, } @@ -99,7 +97,7 @@ func TestLoadHardwareMixingUserHardwareFolder(t *testing.T) { } for _, command := range commands { - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) } @@ -157,7 +155,6 @@ func TestLoadHardwareMixingUserHardwareFolder(t *testing.T) { } func TestLoadHardwareWithBoardManagerFolderStructure(t *testing.T) { - context := make(map[string]interface{}) ctx := &types.Context{ HardwareFolders: []string{"downloaded_board_manager_stuff"}, } @@ -167,7 +164,7 @@ func TestLoadHardwareWithBoardManagerFolderStructure(t *testing.T) { } for _, command := range commands { - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) } @@ -206,7 +203,6 @@ func TestLoadHardwareWithBoardManagerFolderStructure(t *testing.T) { } func TestLoadLotsOfHardware(t *testing.T) { - context := make(map[string]interface{}) ctx := &types.Context{ HardwareFolders: []string{"downloaded_board_manager_stuff", "downloaded_hardware", filepath.Join("..", "hardware"), "hardware", "user_hardware"}, } @@ -216,7 +212,7 @@ func TestLoadLotsOfHardware(t *testing.T) { } for _, command := range commands { - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) } diff --git a/src/arduino.cc/builder/test/helper.go b/src/arduino.cc/builder/test/helper.go index 3f74e310..3e83d337 100644 --- a/src/arduino.cc/builder/test/helper.go +++ b/src/arduino.cc/builder/test/helper.go @@ -44,7 +44,7 @@ import ( "text/template" ) -func LoadAndInterpolate(t *testing.T, filename string, context map[string]interface{}, ctx *types.Context) string { +func LoadAndInterpolate(t *testing.T, filename string, ctx *types.Context) string { funcsMap := template.FuncMap{ "EscapeBackSlashes": func(s string) string { return strings.Replace(s, "\\", "\\\\", -1) @@ -55,8 +55,9 @@ func LoadAndInterpolate(t *testing.T, filename string, context map[string]interf NoError(t, err) var buf bytes.Buffer - context["sketch"] = ctx.Sketch - err = tpl.Execute(&buf, context) + data := make(map[string]interface{}) + data["sketch"] = ctx.Sketch + err = tpl.Execute(&buf, data) NoError(t, err) return buf.String() diff --git a/src/arduino.cc/builder/test/includes_finder_with_gcc_test.go b/src/arduino.cc/builder/test/includes_finder_with_gcc_test.go index 16b7a694..903161f1 100644 --- a/src/arduino.cc/builder/test/includes_finder_with_gcc_test.go +++ b/src/arduino.cc/builder/test/includes_finder_with_gcc_test.go @@ -43,7 +43,6 @@ import ( func TestIncludesFinderWithGCC(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) - context := make(map[string]interface{}) ctx := &types.Context{ HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, ToolsFolders: []string{"downloaded_tools"}, @@ -65,7 +64,7 @@ func TestIncludesFinderWithGCC(t *testing.T) { } for _, command := range commands { - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) } require.Nil(t, ctx.Includes) @@ -74,7 +73,6 @@ func TestIncludesFinderWithGCC(t *testing.T) { func TestIncludesFinderWithGCCSketchWithConfig(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) - context := make(map[string]interface{}) ctx := &types.Context{ HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, ToolsFolders: []string{"downloaded_tools"}, @@ -99,7 +97,7 @@ func TestIncludesFinderWithGCCSketchWithConfig(t *testing.T) { } for _, command := range commands { - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) } @@ -115,7 +113,6 @@ func TestIncludesFinderWithGCCSketchWithConfig(t *testing.T) { func TestIncludesFinderWithGCCSketchWithDependendLibraries(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) - context := make(map[string]interface{}) ctx := &types.Context{ HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, ToolsFolders: []string{"downloaded_tools"}, @@ -139,7 +136,7 @@ func TestIncludesFinderWithGCCSketchWithDependendLibraries(t *testing.T) { } for _, command := range commands { - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) } @@ -165,7 +162,6 @@ func TestIncludesFinderWithGCCSketchWithDependendLibraries(t *testing.T) { func TestIncludesFinderWithGCCSketchWithThatChecksIfSPIHasTransactions(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) - context := make(map[string]interface{}) ctx := &types.Context{ HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, ToolsFolders: []string{"downloaded_tools"}, @@ -190,7 +186,7 @@ func TestIncludesFinderWithGCCSketchWithThatChecksIfSPIHasTransactions(t *testin } for _, command := range commands { - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) } @@ -206,7 +202,6 @@ func TestIncludesFinderWithGCCSketchWithThatChecksIfSPIHasTransactions(t *testin func TestIncludesFinderWithGCCSketchWithThatChecksIfSPIHasTransactionsAndIncludesMissingLib(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) - context := make(map[string]interface{}) ctx := &types.Context{ HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, ToolsFolders: []string{"downloaded_tools"}, @@ -229,12 +224,12 @@ func TestIncludesFinderWithGCCSketchWithThatChecksIfSPIHasTransactionsAndInclude } for _, command := range commands { - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) } command := &builder.ContainerFindIncludes{} - err := command.Run(context, ctx) + err := command.Run(ctx) require.Error(t, err) includes := ctx.Includes diff --git a/src/arduino.cc/builder/test/includes_finder_with_regexp_test.go b/src/arduino.cc/builder/test/includes_finder_with_regexp_test.go index 0766beda..1a8fb456 100644 --- a/src/arduino.cc/builder/test/includes_finder_with_regexp_test.go +++ b/src/arduino.cc/builder/test/includes_finder_with_regexp_test.go @@ -38,7 +38,6 @@ import ( ) func TestIncludesFinderWithRegExp(t *testing.T) { - context := make(map[string]interface{}) ctx := &types.Context{} output := "/some/path/sketch.ino:1:17: fatal error: SPI.h: No such file or directory\n" + @@ -48,7 +47,7 @@ func TestIncludesFinderWithRegExp(t *testing.T) { ctx.Source = output parser := builder.IncludesFinderWithRegExp{Source: &ctx.Source} - err := parser.Run(context, ctx) + err := parser.Run(ctx) NoError(t, err) includes := ctx.Includes @@ -57,7 +56,6 @@ func TestIncludesFinderWithRegExp(t *testing.T) { } func TestIncludesFinderWithRegExpEmptyOutput(t *testing.T) { - context := make(map[string]interface{}) ctx := &types.Context{} output := "" @@ -65,7 +63,7 @@ func TestIncludesFinderWithRegExpEmptyOutput(t *testing.T) { ctx.Source = output parser := builder.IncludesFinderWithRegExp{Source: &ctx.Source} - err := parser.Run(context, ctx) + err := parser.Run(ctx) NoError(t, err) includes := ctx.Includes @@ -73,7 +71,6 @@ func TestIncludesFinderWithRegExpEmptyOutput(t *testing.T) { } func TestIncludesFinderWithRegExpPreviousIncludes(t *testing.T) { - context := make(map[string]interface{}) ctx := &types.Context{ Includes: []string{"test.h"}, } @@ -86,7 +83,7 @@ func TestIncludesFinderWithRegExpPreviousIncludes(t *testing.T) { ctx.Source = output parser := builder.IncludesFinderWithRegExp{Source: &ctx.Source} - err := parser.Run(context, ctx) + err := parser.Run(ctx) NoError(t, err) includes := ctx.Includes @@ -97,7 +94,6 @@ func TestIncludesFinderWithRegExpPreviousIncludes(t *testing.T) { } func TestIncludesFinderWithRegExpPaddedIncludes(t *testing.T) { - context := make(map[string]interface{}) ctx := &types.Context{} output := "/some/path/sketch.ino:1:33: fatal error: Wire.h: No such file or directory\n" + @@ -107,7 +103,7 @@ func TestIncludesFinderWithRegExpPaddedIncludes(t *testing.T) { ctx.Source = output parser := builder.IncludesFinderWithRegExp{Source: &ctx.Source} - err := parser.Run(context, ctx) + err := parser.Run(ctx) NoError(t, err) includes := ctx.Includes @@ -117,7 +113,6 @@ func TestIncludesFinderWithRegExpPaddedIncludes(t *testing.T) { } func TestIncludesFinderWithRegExpPaddedIncludes2(t *testing.T) { - context := make(map[string]interface{}) ctx := &types.Context{} output := "/some/path/sketch.ino:1:33: fatal error: Wire.h: No such file or directory\n" + @@ -127,7 +122,7 @@ func TestIncludesFinderWithRegExpPaddedIncludes2(t *testing.T) { ctx.Source = output parser := builder.IncludesFinderWithRegExp{Source: &ctx.Source} - err := parser.Run(context, ctx) + err := parser.Run(ctx) NoError(t, err) includes := ctx.Includes @@ -137,7 +132,6 @@ func TestIncludesFinderWithRegExpPaddedIncludes2(t *testing.T) { } func TestIncludesFinderWithRegExpPaddedIncludes3(t *testing.T) { - context := make(map[string]interface{}) ctx := &types.Context{} output := "/some/path/sketch.ino:1:33: fatal error: SPI.h: No such file or directory\n" + @@ -146,7 +140,7 @@ func TestIncludesFinderWithRegExpPaddedIncludes3(t *testing.T) { ctx.Source = output parser := builder.IncludesFinderWithRegExp{Source: &ctx.Source} - err := parser.Run(context, ctx) + err := parser.Run(ctx) NoError(t, err) includes := ctx.Includes diff --git a/src/arduino.cc/builder/test/includes_to_include_folders_test.go b/src/arduino.cc/builder/test/includes_to_include_folders_test.go index eb15ac37..a0fb431f 100644 --- a/src/arduino.cc/builder/test/includes_to_include_folders_test.go +++ b/src/arduino.cc/builder/test/includes_to_include_folders_test.go @@ -42,7 +42,6 @@ import ( func TestIncludesToIncludeFolders(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) - context := make(map[string]interface{}) ctx := &types.Context{ HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, ToolsFolders: []string{"downloaded_tools"}, @@ -67,7 +66,7 @@ func TestIncludesToIncludeFolders(t *testing.T) { } for _, command := range commands { - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) } @@ -83,7 +82,6 @@ func TestIncludesToIncludeFolders(t *testing.T) { func TestIncludesToIncludeFoldersSketchWithIfDef(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) - context := make(map[string]interface{}) ctx := &types.Context{ HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, ToolsFolders: []string{"downloaded_tools"}, @@ -108,7 +106,7 @@ func TestIncludesToIncludeFoldersSketchWithIfDef(t *testing.T) { } for _, command := range commands { - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) } @@ -122,7 +120,6 @@ func TestIncludesToIncludeFoldersSketchWithIfDef(t *testing.T) { func TestIncludesToIncludeFoldersIRremoteLibrary(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) - context := make(map[string]interface{}) ctx := &types.Context{ HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, ToolsFolders: []string{"downloaded_tools"}, @@ -147,7 +144,7 @@ func TestIncludesToIncludeFoldersIRremoteLibrary(t *testing.T) { } for _, command := range commands { - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) } @@ -166,7 +163,6 @@ func TestIncludesToIncludeFoldersIRremoteLibrary(t *testing.T) { func TestIncludesToIncludeFoldersANewLibrary(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) - context := make(map[string]interface{}) ctx := &types.Context{ HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, ToolsFolders: []string{"downloaded_tools"}, @@ -191,7 +187,7 @@ func TestIncludesToIncludeFoldersANewLibrary(t *testing.T) { } for _, command := range commands { - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) } @@ -210,7 +206,6 @@ func TestIncludesToIncludeFoldersANewLibrary(t *testing.T) { func TestIncludesToIncludeFoldersDuplicateLibs(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) - context := make(map[string]interface{}) ctx := &types.Context{ HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware", "user_hardware"}, ToolsFolders: []string{"downloaded_tools"}, @@ -234,7 +229,7 @@ func TestIncludesToIncludeFoldersDuplicateLibs(t *testing.T) { } for _, command := range commands { - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) } @@ -252,7 +247,6 @@ func TestIncludesToIncludeFoldersDuplicateLibs(t *testing.T) { func TestIncludesToIncludeFoldersDuplicateLibsWithConflictingLibsOutsideOfPlatform(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) - context := make(map[string]interface{}) ctx := &types.Context{ HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware", "user_hardware"}, ToolsFolders: []string{"downloaded_tools"}, @@ -277,7 +271,7 @@ func TestIncludesToIncludeFoldersDuplicateLibsWithConflictingLibsOutsideOfPlatfo } for _, command := range commands { - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) } @@ -295,7 +289,6 @@ func TestIncludesToIncludeFoldersDuplicateLibsWithConflictingLibsOutsideOfPlatfo func TestIncludesToIncludeFoldersDuplicateLibs2(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) - context := make(map[string]interface{}) ctx := &types.Context{ HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware", "downloaded_board_manager_stuff"}, ToolsFolders: []string{"downloaded_tools", "downloaded_board_manager_stuff"}, @@ -320,7 +313,7 @@ func TestIncludesToIncludeFoldersDuplicateLibs2(t *testing.T) { } for _, command := range commands { - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) } diff --git a/src/arduino.cc/builder/test/libraries_loader_test.go b/src/arduino.cc/builder/test/libraries_loader_test.go index cc2857a4..217603aa 100644 --- a/src/arduino.cc/builder/test/libraries_loader_test.go +++ b/src/arduino.cc/builder/test/libraries_loader_test.go @@ -42,7 +42,6 @@ import ( func TestLoadLibrariesAVR(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) - context := make(map[string]interface{}) ctx := &types.Context{ HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, BuiltInLibrariesFolders: []string{"downloaded_libraries"}, @@ -58,7 +57,7 @@ func TestLoadLibrariesAVR(t *testing.T) { } for _, command := range commands { - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) } @@ -152,7 +151,6 @@ func TestLoadLibrariesAVR(t *testing.T) { func TestLoadLibrariesSAM(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) - context := make(map[string]interface{}) ctx := &types.Context{ HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, BuiltInLibrariesFolders: []string{"downloaded_libraries"}, @@ -168,7 +166,7 @@ func TestLoadLibrariesSAM(t *testing.T) { } for _, command := range commands { - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) } @@ -236,7 +234,6 @@ func TestLoadLibrariesSAM(t *testing.T) { func TestLoadLibrariesAVRNoDuplicateLibrariesFolders(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) - context := make(map[string]interface{}) ctx := &types.Context{ HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, BuiltInLibrariesFolders: []string{"downloaded_libraries"}, @@ -252,7 +249,7 @@ func TestLoadLibrariesAVRNoDuplicateLibrariesFolders(t *testing.T) { } for _, command := range commands { - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) } @@ -266,7 +263,6 @@ func TestLoadLibrariesAVRNoDuplicateLibrariesFolders(t *testing.T) { func TestLoadLibrariesMyAVRPlatform(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) - context := make(map[string]interface{}) ctx := &types.Context{ HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "user_hardware", "downloaded_hardware"}, BuiltInLibrariesFolders: []string{"downloaded_libraries"}, @@ -282,7 +278,7 @@ func TestLoadLibrariesMyAVRPlatform(t *testing.T) { } for _, command := range commands { - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) } diff --git a/src/arduino.cc/builder/test/load_previous_build_options_map_test.go b/src/arduino.cc/builder/test/load_previous_build_options_map_test.go index d3bfa7db..772d1c04 100644 --- a/src/arduino.cc/builder/test/load_previous_build_options_map_test.go +++ b/src/arduino.cc/builder/test/load_previous_build_options_map_test.go @@ -41,7 +41,6 @@ import ( ) func TestLoadPreviousBuildOptionsMap(t *testing.T) { - context := make(map[string]interface{}) ctx := &types.Context{} buildPath := SetupBuildPath(t, ctx) @@ -51,21 +50,20 @@ func TestLoadPreviousBuildOptionsMap(t *testing.T) { NoError(t, err) command := builder.LoadPreviousBuildOptionsMap{} - err = command.Run(context, ctx) + err = command.Run(ctx) NoError(t, err) require.Equal(t, "test", ctx.BuildOptionsJsonPrevious) } func TestLoadPreviousBuildOptionsMapMissingFile(t *testing.T) { - context := make(map[string]interface{}) ctx := &types.Context{} buildPath := SetupBuildPath(t, ctx) defer os.RemoveAll(buildPath) command := builder.LoadPreviousBuildOptionsMap{} - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) require.Empty(t, ctx.BuildOptionsJsonPrevious) diff --git a/src/arduino.cc/builder/test/load_vid_pid_specific_properties_test.go b/src/arduino.cc/builder/test/load_vid_pid_specific_properties_test.go index f8830f87..b0857b23 100644 --- a/src/arduino.cc/builder/test/load_vid_pid_specific_properties_test.go +++ b/src/arduino.cc/builder/test/load_vid_pid_specific_properties_test.go @@ -41,7 +41,6 @@ import ( func TestLoadVIDPIDSpecificPropertiesWhenNoVIDPIDAreProvided(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) - context := make(map[string]interface{}) ctx := &types.Context{ HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, ToolsFolders: []string{"downloaded_tools", "./tools_builtin"}, @@ -58,7 +57,7 @@ func TestLoadVIDPIDSpecificPropertiesWhenNoVIDPIDAreProvided(t *testing.T) { } for _, command := range commands { - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) } @@ -72,7 +71,6 @@ func TestLoadVIDPIDSpecificPropertiesWhenNoVIDPIDAreProvided(t *testing.T) { func TestLoadVIDPIDSpecificProperties(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) - context := make(map[string]interface{}) ctx := &types.Context{ HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, ToolsFolders: []string{"downloaded_tools", "./tools_builtin"}, @@ -91,7 +89,7 @@ func TestLoadVIDPIDSpecificProperties(t *testing.T) { } for _, command := range commands { - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) } diff --git a/src/arduino.cc/builder/test/merge_sketch_with_bootloader_test.go b/src/arduino.cc/builder/test/merge_sketch_with_bootloader_test.go index f4bbe136..ae0c91bc 100644 --- a/src/arduino.cc/builder/test/merge_sketch_with_bootloader_test.go +++ b/src/arduino.cc/builder/test/merge_sketch_with_bootloader_test.go @@ -45,7 +45,6 @@ import ( func TestMergeSketchWithBootloader(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) - context := make(map[string]interface{}) ctx := &types.Context{ HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, ToolsFolders: []string{"downloaded_tools"}, @@ -73,7 +72,7 @@ func TestMergeSketchWithBootloader(t *testing.T) { } for _, command := range commands { - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) } @@ -88,7 +87,6 @@ func TestMergeSketchWithBootloader(t *testing.T) { func TestMergeSketchWithBootloaderSketchInBuildPath(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) - context := make(map[string]interface{}) ctx := &types.Context{ HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, ToolsFolders: []string{"downloaded_tools"}, @@ -116,7 +114,7 @@ func TestMergeSketchWithBootloaderSketchInBuildPath(t *testing.T) { } for _, command := range commands { - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) } @@ -131,7 +129,6 @@ func TestMergeSketchWithBootloaderSketchInBuildPath(t *testing.T) { func TestMergeSketchWithBootloaderWhenNoBootloaderAvailable(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) - context := make(map[string]interface{}) ctx := &types.Context{ HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, ToolsFolders: []string{"downloaded_tools"}, @@ -150,7 +147,7 @@ func TestMergeSketchWithBootloaderWhenNoBootloaderAvailable(t *testing.T) { } for _, command := range commands { - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) } @@ -159,7 +156,7 @@ func TestMergeSketchWithBootloaderWhenNoBootloaderAvailable(t *testing.T) { delete(buildProperties, constants.BUILD_PROPERTIES_BOOTLOADER_FILE) command := &builder.MergeSketchWithBootloader{} - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) _, err = os.Stat(filepath.Join(buildPath, "sketch.ino.with_bootloader.hex")) @@ -170,7 +167,6 @@ func TestMergeSketchWithBootloaderWhenNoBootloaderAvailable(t *testing.T) { func TestMergeSketchWithBootloaderPathIsParameterized(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) - context := make(map[string]interface{}) ctx := &types.Context{ HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware", "user_hardware"}, ToolsFolders: []string{"downloaded_tools"}, @@ -198,7 +194,7 @@ func TestMergeSketchWithBootloaderPathIsParameterized(t *testing.T) { } for _, command := range commands { - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) } diff --git a/src/arduino.cc/builder/test/platform_keys_rewrite_loader_test.go b/src/arduino.cc/builder/test/platform_keys_rewrite_loader_test.go index ea16a8b3..47ff86a4 100644 --- a/src/arduino.cc/builder/test/platform_keys_rewrite_loader_test.go +++ b/src/arduino.cc/builder/test/platform_keys_rewrite_loader_test.go @@ -39,7 +39,6 @@ import ( ) func TestLoadPlatformKeysRewrite(t *testing.T) { - context := make(map[string]interface{}) ctx := &types.Context{ HardwareFolders: []string{"downloaded_hardware", filepath.Join("..", "hardware"), "hardware"}, } @@ -49,7 +48,7 @@ func TestLoadPlatformKeysRewrite(t *testing.T) { } for _, command := range commands { - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) } diff --git a/src/arduino.cc/builder/test/prototypes_adder_test.go b/src/arduino.cc/builder/test/prototypes_adder_test.go index 941e74bd..a6f46a45 100644 --- a/src/arduino.cc/builder/test/prototypes_adder_test.go +++ b/src/arduino.cc/builder/test/prototypes_adder_test.go @@ -46,7 +46,6 @@ func TestPrototypesAdderBridgeExample(t *testing.T) { sketchLocation := filepath.Join("downloaded_libraries", "Bridge", "examples", "Bridge", "Bridge.ino") absoluteSketchLocation := strings.Replace(Abs(t, sketchLocation), "\\", "\\\\", -1) - context := make(map[string]interface{}) ctx := &types.Context{ HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, ToolsFolders: []string{"downloaded_tools"}, @@ -78,7 +77,7 @@ func TestPrototypesAdderBridgeExample(t *testing.T) { } for _, command := range commands { - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) } @@ -89,7 +88,6 @@ func TestPrototypesAdderBridgeExample(t *testing.T) { func TestPrototypesAdderSketchWithIfDef(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) - context := make(map[string]interface{}) ctx := &types.Context{ HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, ToolsFolders: []string{"downloaded_tools"}, @@ -119,18 +117,17 @@ func TestPrototypesAdderSketchWithIfDef(t *testing.T) { } for _, command := range commands { - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) } - preprocessed := LoadAndInterpolate(t, filepath.Join("sketch2", "SketchWithIfDef.preprocessed.txt"), context, ctx) + preprocessed := LoadAndInterpolate(t, filepath.Join("sketch2", "SketchWithIfDef.preprocessed.txt"), ctx) require.Equal(t, preprocessed, strings.Replace(ctx.Source, "\r\n", "\n", -1)) } func TestPrototypesAdderBaladuino(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) - context := make(map[string]interface{}) ctx := &types.Context{ HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, ToolsFolders: []string{"downloaded_tools"}, @@ -160,18 +157,17 @@ func TestPrototypesAdderBaladuino(t *testing.T) { } for _, command := range commands { - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) } - preprocessed := LoadAndInterpolate(t, filepath.Join("sketch3", "Baladuino.preprocessed.txt"), context, ctx) + preprocessed := LoadAndInterpolate(t, filepath.Join("sketch3", "Baladuino.preprocessed.txt"), ctx) require.Equal(t, preprocessed, strings.Replace(ctx.Source, "\r\n", "\n", -1)) } func TestPrototypesAdderCharWithEscapedDoubleQuote(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) - context := make(map[string]interface{}) ctx := &types.Context{ HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, ToolsFolders: []string{"downloaded_tools"}, @@ -201,18 +197,17 @@ func TestPrototypesAdderCharWithEscapedDoubleQuote(t *testing.T) { } for _, command := range commands { - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) } - preprocessed := LoadAndInterpolate(t, filepath.Join("sketch4", "CharWithEscapedDoubleQuote.preprocessed.txt"), context, ctx) + preprocessed := LoadAndInterpolate(t, filepath.Join("sketch4", "CharWithEscapedDoubleQuote.preprocessed.txt"), ctx) require.Equal(t, preprocessed, strings.Replace(ctx.Source, "\r\n", "\n", -1)) } func TestPrototypesAdderIncludeBetweenMultilineComment(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) - context := make(map[string]interface{}) ctx := &types.Context{ HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, ToolsFolders: []string{"downloaded_tools"}, @@ -242,18 +237,17 @@ func TestPrototypesAdderIncludeBetweenMultilineComment(t *testing.T) { } for _, command := range commands { - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) } - preprocessed := LoadAndInterpolate(t, filepath.Join("sketch5", "IncludeBetweenMultilineComment.preprocessed.txt"), context, ctx) + preprocessed := LoadAndInterpolate(t, filepath.Join("sketch5", "IncludeBetweenMultilineComment.preprocessed.txt"), ctx) require.Equal(t, preprocessed, strings.Replace(ctx.Source, "\r\n", "\n", -1)) } func TestPrototypesAdderLineContinuations(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) - context := make(map[string]interface{}) ctx := &types.Context{ HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, ToolsFolders: []string{"downloaded_tools"}, @@ -283,18 +277,17 @@ func TestPrototypesAdderLineContinuations(t *testing.T) { } for _, command := range commands { - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) } - preprocessed := LoadAndInterpolate(t, filepath.Join("sketch6", "LineContinuations.preprocessed.txt"), context, ctx) + preprocessed := LoadAndInterpolate(t, filepath.Join("sketch6", "LineContinuations.preprocessed.txt"), ctx) require.Equal(t, preprocessed, strings.Replace(ctx.Source, "\r\n", "\n", -1)) } func TestPrototypesAdderStringWithComment(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) - context := make(map[string]interface{}) ctx := &types.Context{ HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, ToolsFolders: []string{"downloaded_tools"}, @@ -324,18 +317,17 @@ func TestPrototypesAdderStringWithComment(t *testing.T) { } for _, command := range commands { - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) } - preprocessed := LoadAndInterpolate(t, filepath.Join("sketch7", "StringWithComment.preprocessed.txt"), context, ctx) + preprocessed := LoadAndInterpolate(t, filepath.Join("sketch7", "StringWithComment.preprocessed.txt"), ctx) require.Equal(t, preprocessed, strings.Replace(ctx.Source, "\r\n", "\n", -1)) } func TestPrototypesAdderSketchWithStruct(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) - context := make(map[string]interface{}) ctx := &types.Context{ HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, ToolsFolders: []string{"downloaded_tools"}, @@ -365,11 +357,11 @@ func TestPrototypesAdderSketchWithStruct(t *testing.T) { } for _, command := range commands { - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) } - preprocessed := LoadAndInterpolate(t, filepath.Join("sketch8", "SketchWithStruct.preprocessed.txt"), context, ctx) + preprocessed := LoadAndInterpolate(t, filepath.Join("sketch8", "SketchWithStruct.preprocessed.txt"), ctx) obtained := strings.Replace(ctx.Source, "\r\n", "\n", -1) // ctags based preprocessing removes the space after "dostuff", but this is still OK // TODO: remove this exception when moving to a more powerful parser @@ -384,7 +376,6 @@ func TestPrototypesAdderSketchWithConfig(t *testing.T) { sketchLocation := filepath.Join("sketch_with_config", "sketch_with_config.ino") absoluteSketchLocation := strings.Replace(Abs(t, sketchLocation), "\\", "\\\\", -1) - context := make(map[string]interface{}) ctx := &types.Context{ HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, ToolsFolders: []string{"downloaded_tools"}, @@ -414,14 +405,14 @@ func TestPrototypesAdderSketchWithConfig(t *testing.T) { } for _, command := range commands { - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) } require.Equal(t, "#include \n#line 1 \""+absoluteSketchLocation+"\"\n", ctx.IncludeSection) require.Equal(t, "#line 13 \""+absoluteSketchLocation+"\"\nvoid setup();\n#line 17 \""+absoluteSketchLocation+"\"\nvoid loop();\n#line 13 \""+absoluteSketchLocation+"\"\n", ctx.PrototypesSection) - preprocessed := LoadAndInterpolate(t, filepath.Join("sketch_with_config", "sketch_with_config.preprocessed.txt"), context, ctx) + preprocessed := LoadAndInterpolate(t, filepath.Join("sketch_with_config", "sketch_with_config.preprocessed.txt"), ctx) require.Equal(t, preprocessed, strings.Replace(ctx.Source, "\r\n", "\n", -1)) } @@ -431,7 +422,6 @@ func TestPrototypesAdderSketchNoFunctionsTwoFiles(t *testing.T) { sketchLocation := filepath.Join("sketch_no_functions_two_files", "main.ino") absoluteSketchLocation := strings.Replace(Abs(t, sketchLocation), "\\", "\\\\", -1) - context := make(map[string]interface{}) ctx := &types.Context{ HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, ToolsFolders: []string{"downloaded_tools"}, @@ -461,7 +451,7 @@ func TestPrototypesAdderSketchNoFunctionsTwoFiles(t *testing.T) { } for _, command := range commands { - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) } @@ -472,7 +462,6 @@ func TestPrototypesAdderSketchNoFunctionsTwoFiles(t *testing.T) { func TestPrototypesAdderSketchNoFunctions(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) - context := make(map[string]interface{}) ctx := &types.Context{ HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, ToolsFolders: []string{"downloaded_tools"}, @@ -505,7 +494,7 @@ func TestPrototypesAdderSketchNoFunctions(t *testing.T) { } for _, command := range commands { - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) } @@ -519,7 +508,6 @@ func TestPrototypesAdderSketchWithDefaultArgs(t *testing.T) { sketchLocation := filepath.Join("sketch_with_default_args", "sketch.ino") absoluteSketchLocation := strings.Replace(Abs(t, sketchLocation), "\\", "\\\\", -1) - context := make(map[string]interface{}) ctx := &types.Context{ HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, ToolsFolders: []string{"downloaded_tools"}, @@ -549,7 +537,7 @@ func TestPrototypesAdderSketchWithDefaultArgs(t *testing.T) { } for _, command := range commands { - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) } @@ -563,7 +551,6 @@ func TestPrototypesAdderSketchWithInlineFunction(t *testing.T) { sketchLocation := filepath.Join("sketch_with_inline_function", "sketch.ino") absoluteSketchLocation := strings.Replace(Abs(t, sketchLocation), "\\", "\\\\", -1) - context := make(map[string]interface{}) ctx := &types.Context{ HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, ToolsFolders: []string{"downloaded_tools"}, @@ -593,7 +580,7 @@ func TestPrototypesAdderSketchWithInlineFunction(t *testing.T) { } for _, command := range commands { - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) } @@ -618,7 +605,6 @@ func TestPrototypesAdderSketchWithFunctionSignatureInsideIFDEF(t *testing.T) { sketchLocation := filepath.Join("sketch_with_function_signature_inside_ifdef", "sketch.ino") absoluteSketchLocation := strings.Replace(Abs(t, sketchLocation), "\\", "\\\\", -1) - context := make(map[string]interface{}) ctx := &types.Context{ HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, ToolsFolders: []string{"downloaded_tools"}, @@ -648,7 +634,7 @@ func TestPrototypesAdderSketchWithFunctionSignatureInsideIFDEF(t *testing.T) { } for _, command := range commands { - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) } @@ -662,7 +648,6 @@ func TestPrototypesAdderSketchWithUSBCON(t *testing.T) { sketchLocation := filepath.Join("sketch_with_usbcon", "sketch.ino") absoluteSketchLocation := strings.Replace(Abs(t, sketchLocation), "\\", "\\\\", -1) - context := make(map[string]interface{}) ctx := &types.Context{ HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, ToolsFolders: []string{"downloaded_tools"}, @@ -692,7 +677,7 @@ func TestPrototypesAdderSketchWithUSBCON(t *testing.T) { } for _, command := range commands { - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) } @@ -706,7 +691,6 @@ func TestPrototypesAdderSketchWithTypename(t *testing.T) { sketchLocation := filepath.Join("sketch_with_typename", "sketch.ino") absoluteSketchLocation := strings.Replace(Abs(t, sketchLocation), "\\", "\\\\", -1) - context := make(map[string]interface{}) ctx := &types.Context{ HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, LibrariesFolders: []string{"libraries", "downloaded_libraries"}, @@ -735,7 +719,7 @@ func TestPrototypesAdderSketchWithTypename(t *testing.T) { } for _, command := range commands { - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) } @@ -755,7 +739,6 @@ func TestPrototypesAdderSketchWithIfDef2(t *testing.T) { sketchLocation := filepath.Join("sketch_with_ifdef", "sketch.ino") absoluteSketchLocation := strings.Replace(Abs(t, sketchLocation), "\\", "\\\\", -1) - context := make(map[string]interface{}) ctx := &types.Context{ HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, ToolsFolders: []string{"downloaded_tools"}, @@ -785,14 +768,14 @@ func TestPrototypesAdderSketchWithIfDef2(t *testing.T) { } for _, command := range commands { - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) } require.Equal(t, "#include \n#line 1 \""+absoluteSketchLocation+"\"\n", ctx.IncludeSection) require.Equal(t, "#line 5 \""+absoluteSketchLocation+"\"\nvoid elseBranch();\n#line 9 \""+absoluteSketchLocation+"\"\nvoid f1();\n#line 10 \""+absoluteSketchLocation+"\"\nvoid f2();\n#line 12 \""+absoluteSketchLocation+"\"\nvoid setup();\n#line 14 \""+absoluteSketchLocation+"\"\nvoid loop();\n#line 5 \""+absoluteSketchLocation+"\"\n", ctx.PrototypesSection) - expectedSource := LoadAndInterpolate(t, filepath.Join("sketch_with_ifdef", "sketch.preprocessed.txt"), context, ctx) + expectedSource := LoadAndInterpolate(t, filepath.Join("sketch_with_ifdef", "sketch.preprocessed.txt"), ctx) require.Equal(t, expectedSource, strings.Replace(ctx.Source, "\r\n", "\n", -1)) } @@ -802,7 +785,6 @@ func TestPrototypesAdderSketchWithIfDef2SAM(t *testing.T) { sketchLocation := filepath.Join("sketch_with_ifdef", "sketch.ino") absoluteSketchLocation := strings.Replace(Abs(t, sketchLocation), "\\", "\\\\", -1) - context := make(map[string]interface{}) ctx := &types.Context{ HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, ToolsFolders: []string{"downloaded_tools"}, @@ -832,14 +814,14 @@ func TestPrototypesAdderSketchWithIfDef2SAM(t *testing.T) { } for _, command := range commands { - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) } require.Equal(t, "#include \n#line 1 \""+absoluteSketchLocation+"\"\n", ctx.IncludeSection) require.Equal(t, "#line 2 \""+absoluteSketchLocation+"\"\nvoid ifBranch();\n#line 9 \""+absoluteSketchLocation+"\"\nvoid f1();\n#line 10 \""+absoluteSketchLocation+"\"\nvoid f2();\n#line 12 \""+absoluteSketchLocation+"\"\nvoid setup();\n#line 14 \""+absoluteSketchLocation+"\"\nvoid loop();\n#line 2 \""+absoluteSketchLocation+"\"\n", ctx.PrototypesSection) - expectedSource := LoadAndInterpolate(t, filepath.Join("sketch_with_ifdef", "sketch.preprocessed.SAM.txt"), context, ctx) + expectedSource := LoadAndInterpolate(t, filepath.Join("sketch_with_ifdef", "sketch.preprocessed.SAM.txt"), ctx) require.Equal(t, expectedSource, strings.Replace(ctx.Source, "\r\n", "\n", -1)) } @@ -849,7 +831,6 @@ func TestPrototypesAdderSketchWithConst(t *testing.T) { sketchLocation := filepath.Join("sketch_with_const", "sketch.ino") absoluteSketchLocation := strings.Replace(Abs(t, sketchLocation), "\\", "\\\\", -1) - context := make(map[string]interface{}) ctx := &types.Context{ HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, ToolsFolders: []string{"downloaded_tools"}, @@ -879,7 +860,7 @@ func TestPrototypesAdderSketchWithConst(t *testing.T) { } for _, command := range commands { - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) } @@ -890,7 +871,6 @@ func TestPrototypesAdderSketchWithConst(t *testing.T) { func TestPrototypesAdderSketchWithDosEol(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) - context := make(map[string]interface{}) ctx := &types.Context{ HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, ToolsFolders: []string{"downloaded_tools"}, @@ -920,7 +900,7 @@ func TestPrototypesAdderSketchWithDosEol(t *testing.T) { } for _, command := range commands { - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) } // only requires no error as result diff --git a/src/arduino.cc/builder/test/read_file_and_store_in_context_test.go b/src/arduino.cc/builder/test/read_file_and_store_in_context_test.go index 74f793b0..0fb9db49 100644 --- a/src/arduino.cc/builder/test/read_file_and_store_in_context_test.go +++ b/src/arduino.cc/builder/test/read_file_and_store_in_context_test.go @@ -46,12 +46,11 @@ func TestReadFileAndStoreInContext(t *testing.T) { utils.WriteFile(file.Name(), "test test\nciao") - context := make(map[string]interface{}) ctx := &types.Context{} ctx.FileToRead = file.Name() command := &builder.ReadFileAndStoreInContext{Target: &ctx.SourceGccMinusE} - err = command.Run(context, ctx) + err = command.Run(ctx) NoError(t, err) require.Equal(t, "test test\nciao", ctx.SourceGccMinusE) diff --git a/src/arduino.cc/builder/test/recipe_runner_test.go b/src/arduino.cc/builder/test/recipe_runner_test.go index 61898ca5..5519ca5e 100644 --- a/src/arduino.cc/builder/test/recipe_runner_test.go +++ b/src/arduino.cc/builder/test/recipe_runner_test.go @@ -43,7 +43,6 @@ import ( // and that allows to test if the recipe is actually run // So this test is pretty useless func TestRecipeRunner(t *testing.T) { - context := make(map[string]interface{}) ctx := &types.Context{} buildProperties := make(props.PropertiesMap) ctx.BuildProperties = buildProperties @@ -56,7 +55,7 @@ func TestRecipeRunner(t *testing.T) { } for _, command := range commands { - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) } } diff --git a/src/arduino.cc/builder/test/rewrite_hardware_keys_test.go b/src/arduino.cc/builder/test/rewrite_hardware_keys_test.go index 2d1a07f2..cab44675 100644 --- a/src/arduino.cc/builder/test/rewrite_hardware_keys_test.go +++ b/src/arduino.cc/builder/test/rewrite_hardware_keys_test.go @@ -38,7 +38,6 @@ import ( ) func TestRewriteHardwareKeys(t *testing.T) { - context := make(map[string]interface{}) ctx := &types.Context{} packages := &types.Packages{} @@ -65,7 +64,7 @@ func TestRewriteHardwareKeys(t *testing.T) { } for _, command := range commands { - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) } @@ -73,7 +72,6 @@ func TestRewriteHardwareKeys(t *testing.T) { } func TestRewriteHardwareKeysWithRewritingDisabled(t *testing.T) { - context := make(map[string]interface{}) ctx := &types.Context{} packages := &types.Packages{} @@ -102,7 +100,7 @@ func TestRewriteHardwareKeysWithRewritingDisabled(t *testing.T) { } for _, command := range commands { - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) } diff --git a/src/arduino.cc/builder/test/setup_build_properties_test.go b/src/arduino.cc/builder/test/setup_build_properties_test.go index 06ac9972..592bccd5 100644 --- a/src/arduino.cc/builder/test/setup_build_properties_test.go +++ b/src/arduino.cc/builder/test/setup_build_properties_test.go @@ -43,7 +43,6 @@ import ( func TestSetupBuildProperties(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) - context := make(map[string]interface{}) ctx := &types.Context{ HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware", "user_hardware"}, ToolsFolders: []string{"downloaded_tools", "./tools_builtin"}, @@ -65,7 +64,7 @@ func TestSetupBuildProperties(t *testing.T) { } for _, command := range commands { - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) } @@ -105,7 +104,6 @@ func TestSetupBuildProperties(t *testing.T) { func TestSetupBuildPropertiesWithSomeCustomOverrides(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) - context := make(map[string]interface{}) ctx := &types.Context{ HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, ToolsFolders: []string{"downloaded_tools", "./tools_builtin"}, @@ -130,7 +128,7 @@ func TestSetupBuildPropertiesWithSomeCustomOverrides(t *testing.T) { } for _, command := range commands { - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) } @@ -147,7 +145,6 @@ func TestSetupBuildPropertiesWithSomeCustomOverrides(t *testing.T) { func TestSetupBuildPropertiesUserHardware(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) - context := make(map[string]interface{}) ctx := &types.Context{ HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware", "user_hardware"}, ToolsFolders: []string{"downloaded_tools", "./tools_builtin"}, @@ -169,7 +166,7 @@ func TestSetupBuildPropertiesUserHardware(t *testing.T) { } for _, command := range commands { - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) } @@ -186,7 +183,6 @@ func TestSetupBuildPropertiesUserHardware(t *testing.T) { func TestSetupBuildPropertiesWithMissingPropsFromParentPlatformTxtFiles(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) - context := make(map[string]interface{}) ctx := &types.Context{ HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware", "user_hardware"}, ToolsFolders: []string{"downloaded_tools", "./tools_builtin"}, @@ -203,7 +199,7 @@ func TestSetupBuildPropertiesWithMissingPropsFromParentPlatformTxtFiles(t *testi } for _, command := range commands { - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) } diff --git a/src/arduino.cc/builder/test/sketch_loader_test.go b/src/arduino.cc/builder/test/sketch_loader_test.go index 05373411..1ae3560e 100644 --- a/src/arduino.cc/builder/test/sketch_loader_test.go +++ b/src/arduino.cc/builder/test/sketch_loader_test.go @@ -38,33 +38,30 @@ import ( ) func TestLoadSketchWithFolder(t *testing.T) { - context := make(map[string]interface{}) ctx := &types.Context{ SketchLocation: "sketch1", } loader := builder.SketchLoader{} - err := loader.Run(context, ctx) + err := loader.Run(ctx) require.Error(t, err) require.Nil(t, ctx.Sketch) } func TestLoadSketchNonExistentPath(t *testing.T) { - context := make(map[string]interface{}) ctx := &types.Context{ SketchLocation: "asdasd78128123981723981273asdasd", } loader := builder.SketchLoader{} - err := loader.Run(context, ctx) + err := loader.Run(ctx) require.Error(t, err) require.Nil(t, ctx.Sketch) } func TestLoadSketch(t *testing.T) { - context := make(map[string]interface{}) ctx := &types.Context{ SketchLocation: filepath.Join("sketch1", "sketch.ino"), } @@ -74,7 +71,7 @@ func TestLoadSketch(t *testing.T) { } for _, command := range commands { - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) } @@ -94,19 +91,17 @@ func TestLoadSketch(t *testing.T) { } func TestFailToLoadSketchFromFolder(t *testing.T) { - context := make(map[string]interface{}) ctx := &types.Context{ SketchLocation: "./sketch1", } loader := builder.SketchLoader{} - err := loader.Run(context, ctx) + err := loader.Run(ctx) require.Error(t, err) require.Nil(t, ctx.Sketch) } func TestLoadSketchFromFolder(t *testing.T) { - context := make(map[string]interface{}) ctx := &types.Context{ SketchLocation: "sketch_with_subfolders", } @@ -116,7 +111,7 @@ func TestLoadSketchFromFolder(t *testing.T) { } for _, command := range commands { - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) } @@ -133,7 +128,6 @@ func TestLoadSketchFromFolder(t *testing.T) { } func TestLoadSketchWithBackup(t *testing.T) { - context := make(map[string]interface{}) ctx := &types.Context{ SketchLocation: filepath.Join("sketch_with_backup_files", "sketch.ino"), } @@ -143,7 +137,7 @@ func TestLoadSketchWithBackup(t *testing.T) { } for _, command := range commands { - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) } @@ -157,7 +151,6 @@ func TestLoadSketchWithBackup(t *testing.T) { } func TestLoadSketchWithMacOSXGarbage(t *testing.T) { - context := make(map[string]interface{}) ctx := &types.Context{ SketchLocation: filepath.Join("sketch_with_macosx_garbage", "sketch.ino"), } @@ -167,7 +160,7 @@ func TestLoadSketchWithMacOSXGarbage(t *testing.T) { } for _, command := range commands { - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) } diff --git a/src/arduino.cc/builder/test/sketch_source_merger_test.go b/src/arduino.cc/builder/test/sketch_source_merger_test.go index c6adc880..6cb68dc0 100644 --- a/src/arduino.cc/builder/test/sketch_source_merger_test.go +++ b/src/arduino.cc/builder/test/sketch_source_merger_test.go @@ -40,7 +40,6 @@ import ( ) func TestMergeSketch(t *testing.T) { - context := make(map[string]interface{}) ctx := &types.Context{ SketchLocation: filepath.Join("sketch1", "sketch.ino"), } @@ -51,12 +50,12 @@ func TestMergeSketch(t *testing.T) { } for _, command := range commands { - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) } source := ctx.Source - expected_source := LoadAndInterpolate(t, filepath.Join("sketch1", "merged_sketch.txt"), context, ctx) + expected_source := LoadAndInterpolate(t, filepath.Join("sketch1", "merged_sketch.txt"), ctx) require.Equal(t, expected_source, strings.Replace(source, "\r\n", "\n", -1)) } diff --git a/src/arduino.cc/builder/test/store_build_options_map_test.go b/src/arduino.cc/builder/test/store_build_options_map_test.go index c6816b90..5ff02564 100644 --- a/src/arduino.cc/builder/test/store_build_options_map_test.go +++ b/src/arduino.cc/builder/test/store_build_options_map_test.go @@ -41,7 +41,6 @@ import ( ) func TestStoreBuildOptionsMap(t *testing.T) { - context := make(map[string]interface{}) ctx := &types.Context{ HardwareFolders: []string{"hardware"}, ToolsFolders: []string{"tools"}, @@ -64,7 +63,7 @@ func TestStoreBuildOptionsMap(t *testing.T) { } for _, command := range commands { - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) } diff --git a/src/arduino.cc/builder/test/target_board_resolver_test.go b/src/arduino.cc/builder/test/target_board_resolver_test.go index fa673332..274eb92c 100644 --- a/src/arduino.cc/builder/test/target_board_resolver_test.go +++ b/src/arduino.cc/builder/test/target_board_resolver_test.go @@ -39,7 +39,6 @@ import ( ) func TestTargetBoardResolverUno(t *testing.T) { - context := make(map[string]interface{}) ctx := &types.Context{ HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, FQBN: "arduino:avr:uno", @@ -51,7 +50,7 @@ func TestTargetBoardResolverUno(t *testing.T) { } for _, command := range commands { - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) } @@ -65,7 +64,6 @@ func TestTargetBoardResolverUno(t *testing.T) { } func TestTargetBoardResolverDue(t *testing.T) { - context := make(map[string]interface{}) ctx := &types.Context{ HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, FQBN: "arduino:sam:arduino_due_x", @@ -77,7 +75,7 @@ func TestTargetBoardResolverDue(t *testing.T) { } for _, command := range commands { - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) } @@ -91,7 +89,6 @@ func TestTargetBoardResolverDue(t *testing.T) { } func TestTargetBoardResolverMega1280(t *testing.T) { - context := make(map[string]interface{}) ctx := &types.Context{ HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, FQBN: "arduino:avr:mega:cpu=atmega1280", @@ -103,7 +100,7 @@ func TestTargetBoardResolverMega1280(t *testing.T) { } for _, command := range commands { - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) } @@ -118,7 +115,6 @@ func TestTargetBoardResolverMega1280(t *testing.T) { } func TestTargetBoardResolverMega2560(t *testing.T) { - context := make(map[string]interface{}) ctx := &types.Context{ HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, FQBN: "arduino:avr:mega:cpu=atmega2560", @@ -130,7 +126,7 @@ func TestTargetBoardResolverMega2560(t *testing.T) { } for _, command := range commands { - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) } @@ -145,7 +141,6 @@ func TestTargetBoardResolverMega2560(t *testing.T) { } func TestTargetBoardResolverCustomYun(t *testing.T) { - context := make(map[string]interface{}) ctx := &types.Context{ HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware", "user_hardware"}, FQBN: "my_avr_platform:avr:custom_yun", @@ -157,7 +152,7 @@ func TestTargetBoardResolverCustomYun(t *testing.T) { } for _, command := range commands { - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) } @@ -172,7 +167,6 @@ func TestTargetBoardResolverCustomYun(t *testing.T) { } func TestTargetBoardResolverCustomCore(t *testing.T) { - context := make(map[string]interface{}) ctx := &types.Context{ HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware", "user_hardware"}, FQBN: "watterott:avr:attiny841:core=spencekonde,info=info", @@ -184,7 +178,7 @@ func TestTargetBoardResolverCustomCore(t *testing.T) { } for _, command := range commands { - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) } diff --git a/src/arduino.cc/builder/test/tools_loader_test.go b/src/arduino.cc/builder/test/tools_loader_test.go index f9a83482..2c85a942 100644 --- a/src/arduino.cc/builder/test/tools_loader_test.go +++ b/src/arduino.cc/builder/test/tools_loader_test.go @@ -55,13 +55,12 @@ func (s ByToolIDAndVersion) Less(i, j int) bool { func TestLoadTools(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) - context := make(map[string]interface{}) ctx := &types.Context{ ToolsFolders: []string{"downloaded_tools", "tools_builtin"}, } loader := builder.ToolsLoader{} - err := loader.Run(context, ctx) + err := loader.Run(ctx) NoError(t, err) tools := ctx.Tools @@ -94,13 +93,12 @@ func TestLoadTools(t *testing.T) { func TestLoadToolsWithBoardManagerFolderStructure(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) - context := make(map[string]interface{}) ctx := &types.Context{ ToolsFolders: []string{"downloaded_board_manager_stuff"}, } loader := builder.ToolsLoader{} - err := loader.Run(context, ctx) + err := loader.Run(ctx) NoError(t, err) tools := ctx.Tools @@ -121,13 +119,12 @@ func TestLoadToolsWithBoardManagerFolderStructure(t *testing.T) { func TestLoadLotsOfTools(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) - context := make(map[string]interface{}) ctx := &types.Context{ ToolsFolders: []string{"downloaded_tools", "tools_builtin", "downloaded_board_manager_stuff"}, } loader := builder.ToolsLoader{} - err := loader.Run(context, ctx) + err := loader.Run(ctx) NoError(t, err) tools := ctx.Tools diff --git a/src/arduino.cc/builder/test/try_build_of_problematic_sketch_test.go b/src/arduino.cc/builder/test/try_build_of_problematic_sketch_test.go index 181dac59..1140cb48 100644 --- a/src/arduino.cc/builder/test/try_build_of_problematic_sketch_test.go +++ b/src/arduino.cc/builder/test/try_build_of_problematic_sketch_test.go @@ -117,9 +117,9 @@ func TestTryBuild019(t *testing.T) { } func TestTryBuild020(t *testing.T) { - context, ctx := makeDefaultContext(t) + ctx := makeDefaultContext(t) ctx.OtherLibrariesFolders = []string{"dependent_libraries", "libraries"} - tryPreprocessWithContext(t, context, ctx, "sketch_with_dependend_libraries", "sketch.ino") + tryPreprocessWithContext(t, ctx, "sketch_with_dependend_libraries", "sketch.ino") } func TestTryBuild021(t *testing.T) { @@ -127,9 +127,9 @@ func TestTryBuild021(t *testing.T) { } func TestTryBuild022(t *testing.T) { - context, ctx := makeDefaultContext(t) + ctx := makeDefaultContext(t) ctx.FQBN = "arduino:samd:arduino_zero_native" - tryBuildWithContext(t, context, ctx, "sketch_usbhost", "sketch_usbhost.ino") + tryBuildWithContext(t, ctx, "sketch_usbhost", "sketch_usbhost.ino") } func TestTryBuild023(t *testing.T) { @@ -186,9 +186,9 @@ func TestTryBuild035(t *testing.T) { } func TestTryBuild036(t *testing.T) { - context, ctx := makeDefaultContext(t) + ctx := makeDefaultContext(t) ctx.FQBN = "arduino:samd:arduino_zero_native" - tryBuildWithContext(t, context, ctx, "sketch11", "sketch_fastleds.ino") + tryBuildWithContext(t, ctx, "sketch11", "sketch_fastleds.ino") } func TestTryBuild037(t *testing.T) { @@ -199,10 +199,9 @@ func TestTryBuild038(t *testing.T) { tryBuild(t, "sketch_with_multiline_prototypes", "sketch_with_multiline_prototypes.ino") } -func makeDefaultContext(t *testing.T) (map[string]interface{}, *types.Context) { +func makeDefaultContext(t *testing.T) *types.Context { DownloadCoresAndToolsAndLibraries(t) - context := make(map[string]interface{}) ctx := &types.Context{ HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware", "downloaded_board_manager_stuff"}, ToolsFolders: []string{"downloaded_tools", "downloaded_board_manager_stuff"}, @@ -216,31 +215,31 @@ func makeDefaultContext(t *testing.T) (map[string]interface{}, *types.Context) { buildPath := SetupBuildPath(t, ctx) defer os.RemoveAll(buildPath) - return context, ctx + return ctx } func tryBuild(t *testing.T, sketchPath ...string) { - context, ctx := makeDefaultContext(t) - tryBuildWithContext(t, context, ctx, sketchPath...) + ctx := makeDefaultContext(t) + tryBuildWithContext(t, ctx, sketchPath...) } -func tryBuildWithContext(t *testing.T, context map[string]interface{}, ctx *types.Context, sketchPath ...string) { +func tryBuildWithContext(t *testing.T, ctx *types.Context, sketchPath ...string) { sketchLocation := filepath.Join(sketchPath...) ctx.SketchLocation = sketchLocation - err := builder.RunBuilder(context, ctx) + err := builder.RunBuilder(ctx) NoError(t, err, "Build error for "+sketchLocation) } func tryPreprocess(t *testing.T, sketchPath ...string) { - context, ctx := makeDefaultContext(t) - tryPreprocessWithContext(t, context, ctx, sketchPath...) + ctx := makeDefaultContext(t) + tryPreprocessWithContext(t, ctx, sketchPath...) } -func tryPreprocessWithContext(t *testing.T, context map[string]interface{}, ctx *types.Context, sketchPath ...string) { +func tryPreprocessWithContext(t *testing.T, ctx *types.Context, sketchPath ...string) { sketchLocation := filepath.Join(sketchPath...) ctx.SketchLocation = sketchLocation - err := builder.RunPreprocess(context, ctx) + err := builder.RunPreprocess(ctx) NoError(t, err, "Build error for "+sketchLocation) } diff --git a/src/arduino.cc/builder/test/unused_compiled_libraries_remover_test.go b/src/arduino.cc/builder/test/unused_compiled_libraries_remover_test.go index 68feb838..98ca24a9 100644 --- a/src/arduino.cc/builder/test/unused_compiled_libraries_remover_test.go +++ b/src/arduino.cc/builder/test/unused_compiled_libraries_remover_test.go @@ -48,13 +48,12 @@ func TestUnusedCompiledLibrariesRemover(t *testing.T) { NoError(t, os.MkdirAll(filepath.Join(temp, "Bridge"), os.FileMode(0755))) NoError(t, ioutil.WriteFile(filepath.Join(temp, "dummy_file"), []byte{}, os.FileMode(0644))) - context := make(map[string]interface{}) ctx := &types.Context{} ctx.LibrariesBuildPath = temp ctx.ImportedLibraries = []*types.Library{&types.Library{Name: "Bridge"}} cmd := builder.UnusedCompiledLibrariesRemover{} - err = cmd.Run(context, ctx) + err = cmd.Run(ctx) NoError(t, err) _, err = os.Stat(filepath.Join(temp, "SPI")) @@ -67,13 +66,12 @@ func TestUnusedCompiledLibrariesRemover(t *testing.T) { } func TestUnusedCompiledLibrariesRemoverLibDoesNotExist(t *testing.T) { - context := make(map[string]interface{}) ctx := &types.Context{} ctx.LibrariesBuildPath = filepath.Join(os.TempDir(), "test") ctx.ImportedLibraries = []*types.Library{&types.Library{Name: "Bridge"}} cmd := builder.UnusedCompiledLibrariesRemover{} - err := cmd.Run(context, ctx) + err := cmd.Run(ctx) NoError(t, err) } @@ -86,13 +84,12 @@ func TestUnusedCompiledLibrariesRemoverNoUsedLibraries(t *testing.T) { NoError(t, os.MkdirAll(filepath.Join(temp, "Bridge"), os.FileMode(0755))) NoError(t, ioutil.WriteFile(filepath.Join(temp, "dummy_file"), []byte{}, os.FileMode(0644))) - context := make(map[string]interface{}) ctx := &types.Context{} ctx.LibrariesBuildPath = temp ctx.ImportedLibraries = []*types.Library{} cmd := builder.UnusedCompiledLibrariesRemover{} - err = cmd.Run(context, ctx) + err = cmd.Run(ctx) NoError(t, err) _, err = os.Stat(filepath.Join(temp, "SPI")) diff --git a/src/arduino.cc/builder/test/wipeout_build_path_if_build_options_changed_test.go b/src/arduino.cc/builder/test/wipeout_build_path_if_build_options_changed_test.go index 699cf40e..b6bd6c4a 100644 --- a/src/arduino.cc/builder/test/wipeout_build_path_if_build_options_changed_test.go +++ b/src/arduino.cc/builder/test/wipeout_build_path_if_build_options_changed_test.go @@ -41,7 +41,6 @@ import ( ) func TestWipeoutBuildPathIfBuildOptionsChanged(t *testing.T) { - context := make(map[string]interface{}) ctx := &types.Context{} buildPath := SetupBuildPath(t, ctx) @@ -57,7 +56,7 @@ func TestWipeoutBuildPathIfBuildOptionsChanged(t *testing.T) { } for _, command := range commands { - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) } @@ -73,7 +72,6 @@ func TestWipeoutBuildPathIfBuildOptionsChanged(t *testing.T) { } func TestWipeoutBuildPathIfBuildOptionsChangedNoPreviousBuildOptions(t *testing.T) { - context := make(map[string]interface{}) ctx := &types.Context{} buildPath := SetupBuildPath(t, ctx) @@ -88,7 +86,7 @@ func TestWipeoutBuildPathIfBuildOptionsChangedNoPreviousBuildOptions(t *testing. } for _, command := range commands { - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) } @@ -104,7 +102,6 @@ func TestWipeoutBuildPathIfBuildOptionsChangedNoPreviousBuildOptions(t *testing. } func TestWipeoutBuildPathIfBuildOptionsChangedBuildOptionsMatch(t *testing.T) { - context := make(map[string]interface{}) ctx := &types.Context{} buildPath := SetupBuildPath(t, ctx) @@ -120,7 +117,7 @@ func TestWipeoutBuildPathIfBuildOptionsChangedBuildOptionsMatch(t *testing.T) { } for _, command := range commands { - err := command.Run(context, ctx) + err := command.Run(ctx) NoError(t, err) } diff --git a/src/arduino.cc/builder/tools_loader.go b/src/arduino.cc/builder/tools_loader.go index a9b622c4..621a5391 100644 --- a/src/arduino.cc/builder/tools_loader.go +++ b/src/arduino.cc/builder/tools_loader.go @@ -42,7 +42,7 @@ import ( type ToolsLoader struct{} -func (s *ToolsLoader) Run(context map[string]interface{}, ctx *types.Context) error { +func (s *ToolsLoader) Run(ctx *types.Context) error { folders := ctx.ToolsFolders tools := []*types.Tool{} diff --git a/src/arduino.cc/builder/types/context.go b/src/arduino.cc/builder/types/context.go index f3c6902f..09546536 100644 --- a/src/arduino.cc/builder/types/context.go +++ b/src/arduino.cc/builder/types/context.go @@ -87,11 +87,6 @@ type Context struct { // ReadFileAndStoreInContext command FileToRead string - - // For now it is used in conjunction with the old map[string]string, but - // it will be slowly populated with all the fields currently used in the - // map in the next commits. - // When the migration will be completed the old map will be removed. } func (ctx *Context) ExtractBuildOptions() props.PropertiesMap { diff --git a/src/arduino.cc/builder/types/types.go b/src/arduino.cc/builder/types/types.go index 6345da89..b9750197 100644 --- a/src/arduino.cc/builder/types/types.go +++ b/src/arduino.cc/builder/types/types.go @@ -207,5 +207,5 @@ func LibraryToSourceFolder(library *Library) []SourceFolder { } type Command interface { - Run(context map[string]interface{}, ctx *Context) error + Run(ctx *Context) error } diff --git a/src/arduino.cc/builder/unused_compiled_libraries_remover.go b/src/arduino.cc/builder/unused_compiled_libraries_remover.go index bbd3b5d9..07b89da8 100644 --- a/src/arduino.cc/builder/unused_compiled_libraries_remover.go +++ b/src/arduino.cc/builder/unused_compiled_libraries_remover.go @@ -40,7 +40,7 @@ import ( type UnusedCompiledLibrariesRemover struct{} -func (s *UnusedCompiledLibrariesRemover) Run(context map[string]interface{}, ctx *types.Context) error { +func (s *UnusedCompiledLibrariesRemover) Run(ctx *types.Context) error { librariesBuildPath := ctx.LibrariesBuildPath _, err := os.Stat(librariesBuildPath) diff --git a/src/arduino.cc/builder/warn_about_arch_incompatible_libraries.go b/src/arduino.cc/builder/warn_about_arch_incompatible_libraries.go index 4f7ca7db..7f716c00 100644 --- a/src/arduino.cc/builder/warn_about_arch_incompatible_libraries.go +++ b/src/arduino.cc/builder/warn_about_arch_incompatible_libraries.go @@ -38,7 +38,7 @@ import ( type WarnAboutArchIncompatibleLibraries struct{} -func (s *WarnAboutArchIncompatibleLibraries) Run(context map[string]interface{}, ctx *types.Context) error { +func (s *WarnAboutArchIncompatibleLibraries) Run(ctx *types.Context) error { if ctx.DebugLevel < 0 { return nil } diff --git a/src/arduino.cc/builder/warn_about_platform_rewrites.go b/src/arduino.cc/builder/warn_about_platform_rewrites.go index f3fca20c..123057a7 100644 --- a/src/arduino.cc/builder/warn_about_platform_rewrites.go +++ b/src/arduino.cc/builder/warn_about_platform_rewrites.go @@ -37,7 +37,7 @@ import ( type WarnAboutPlatformRewrites struct{} -func (s *WarnAboutPlatformRewrites) Run(context map[string]interface{}, ctx *types.Context) error { +func (s *WarnAboutPlatformRewrites) Run(ctx *types.Context) error { if ctx.DebugLevel < 0 { return nil } diff --git a/src/arduino.cc/builder/wipeout_build_path_if_build_options_changed.go b/src/arduino.cc/builder/wipeout_build_path_if_build_options_changed.go index c3613aa2..e60d6472 100644 --- a/src/arduino.cc/builder/wipeout_build_path_if_build_options_changed.go +++ b/src/arduino.cc/builder/wipeout_build_path_if_build_options_changed.go @@ -41,7 +41,7 @@ import ( type WipeoutBuildPathIfBuildOptionsChanged struct{} -func (s *WipeoutBuildPathIfBuildOptionsChanged) Run(context map[string]interface{}, ctx *types.Context) error { +func (s *WipeoutBuildPathIfBuildOptionsChanged) Run(ctx *types.Context) error { if ctx.BuildOptionsJsonPrevious == "" { return nil }