From 1a50763ad58aa1f4815b260c3a8f53610711dce4 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Sat, 25 Mar 2023 00:50:53 +0100 Subject: [PATCH 1/2] Removed some legacy constants --- legacy/builder/builder_utils/utils.go | 2 +- legacy/builder/constants/constants.go | 7 ------- legacy/builder/container_add_prototypes.go | 5 ++--- legacy/builder/ctags_runner.go | 11 +++++------ legacy/builder/gcc_preproc_runner.go | 13 ++++++------- legacy/builder/preprocess_sketch.go | 11 +++++------ legacy/builder/test/builder_test.go | 12 ++++++------ 7 files changed, 25 insertions(+), 36 deletions(-) diff --git a/legacy/builder/builder_utils/utils.go b/legacy/builder/builder_utils/utils.go index 67617cd5f15..44cc55c90af 100644 --- a/legacy/builder/builder_utils/utils.go +++ b/legacy/builder/builder_utils/utils.go @@ -163,7 +163,7 @@ func compileFileWithRecipe(ctx *types.Context, sourcePath *paths.Path, source *p properties := buildProperties.Clone() properties.Set(constants.BUILD_PROPERTIES_COMPILER_WARNING_FLAGS, properties.Get(constants.BUILD_PROPERTIES_COMPILER_WARNING_FLAGS+"."+ctx.WarningsLevel)) properties.Set(constants.BUILD_PROPERTIES_INCLUDES, strings.Join(includes, constants.SPACE)) - properties.SetPath(constants.BUILD_PROPERTIES_SOURCE_FILE, source) + properties.SetPath("source_file", source) relativeSource, err := sourcePath.RelTo(source) if err != nil { return nil, errors.WithStack(err) diff --git a/legacy/builder/constants/constants.go b/legacy/builder/constants/constants.go index 47d7a95c652..49229438887 100644 --- a/legacy/builder/constants/constants.go +++ b/legacy/builder/constants/constants.go @@ -31,14 +31,8 @@ const BUILD_PROPERTIES_COMPILER_WARNING_FLAGS = "compiler.warning_flags" const BUILD_PROPERTIES_FQBN = "build.fqbn" const BUILD_PROPERTIES_INCLUDES = "includes" const BUILD_PROPERTIES_OBJECT_FILE = "object_file" -const BUILD_PROPERTIES_PATTERN = "pattern" -const BUILD_PROPERTIES_PREPROCESSED_FILE_PATH = "preprocessed_file_path" const BUILD_PROPERTIES_RUNTIME_PLATFORM_PATH = "runtime.platform.path" -const BUILD_PROPERTIES_SOURCE_FILE = "source_file" -const BUILD_PROPERTIES_TOOLS_KEY = "tools" -const CTAGS = "ctags" const EMPTY_STRING = "" -const FILE_CTAGS_TARGET_FOR_GCC_MINUS_E = "ctags_target_for_gcc_minus_e.cpp" const FILE_PLATFORM_KEYS_REWRITE_TXT = "platform.keys.rewrite.txt" const FOLDER_BOOTLOADERS = "bootloaders" const FOLDER_CORE = "core" @@ -65,7 +59,6 @@ const PLATFORM_URL = "url" const PLATFORM_VERSION = "version" const RECIPE_AR_PATTERN = "recipe.ar.pattern" const RECIPE_C_COMBINE_PATTERN = "recipe.c.combine.pattern" -const RECIPE_PREPROC_MACROS = "recipe.preproc.macros" const REWRITING_DISABLED = "disabled" const REWRITING = "rewriting" const SPACE = " " diff --git a/legacy/builder/container_add_prototypes.go b/legacy/builder/container_add_prototypes.go index ed16f6e2aff..a2b37c8c93f 100644 --- a/legacy/builder/container_add_prototypes.go +++ b/legacy/builder/container_add_prototypes.go @@ -19,7 +19,6 @@ import ( "fmt" bldr "github.com/arduino/arduino-cli/arduino/builder" - "github.com/arduino/arduino-cli/legacy/builder/constants" "github.com/arduino/arduino-cli/legacy/builder/types" "github.com/pkg/errors" ) @@ -31,7 +30,7 @@ func (s *ContainerAddPrototypes) Run(ctx *types.Context) error { if err := ctx.PreprocPath.MkdirAll(); err != nil { return errors.WithStack(err) } - targetFilePath := ctx.PreprocPath.Join(constants.FILE_CTAGS_TARGET_FOR_GCC_MINUS_E) + targetFilePath := ctx.PreprocPath.Join("ctags_target_for_gcc_minus_e.cpp") // Run preprocessor sourceFile := ctx.SketchBuildPath.Join(ctx.Sketch.MainFile.Base() + ".cpp") @@ -53,7 +52,7 @@ func (s *ContainerAddPrototypes) Run(ctx *types.Context) error { commands := []types.Command{ &ReadFileAndStoreInContext{FileToRead: targetFilePath, Target: &ctx.SourceGccMinusE}, &FilterSketchSource{Source: &ctx.SourceGccMinusE}, - &CTagsTargetFileSaver{Source: &ctx.SourceGccMinusE, TargetFileName: constants.FILE_CTAGS_TARGET_FOR_GCC_MINUS_E}, + &CTagsTargetFileSaver{Source: &ctx.SourceGccMinusE, TargetFileName: "ctags_target_for_gcc_minus_e.cpp"}, &CTagsRunner{}, &PrototypesAdder{}, } diff --git a/legacy/builder/ctags_runner.go b/legacy/builder/ctags_runner.go index 64a6c9f5e24..998cbdf0902 100644 --- a/legacy/builder/ctags_runner.go +++ b/legacy/builder/ctags_runner.go @@ -19,7 +19,6 @@ import ( "os" "os/exec" - "github.com/arduino/arduino-cli/legacy/builder/constants" "github.com/arduino/arduino-cli/legacy/builder/ctags" "github.com/arduino/arduino-cli/legacy/builder/types" "github.com/arduino/arduino-cli/legacy/builder/utils" @@ -34,12 +33,12 @@ func (s *CTagsRunner) Run(ctx *types.Context) error { ctagsTargetFilePath := ctx.CTagsTargetFile ctagsProperties := buildProperties.Clone() - ctagsProperties.Merge(buildProperties.SubTree(constants.BUILD_PROPERTIES_TOOLS_KEY).SubTree(constants.CTAGS)) - ctagsProperties.SetPath(constants.BUILD_PROPERTIES_SOURCE_FILE, ctagsTargetFilePath) + ctagsProperties.Merge(buildProperties.SubTree("tools").SubTree("ctags")) + ctagsProperties.SetPath("source_file", ctagsTargetFilePath) - pattern := ctagsProperties.Get(constants.BUILD_PROPERTIES_PATTERN) - if pattern == constants.EMPTY_STRING { - return errors.Errorf(tr("%s pattern is missing"), constants.CTAGS) + pattern := ctagsProperties.Get("pattern") + if pattern == "" { + return errors.Errorf(tr("%s pattern is missing"), "ctags") } commandLine := ctagsProperties.ExpandPropsInString(pattern) diff --git a/legacy/builder/gcc_preproc_runner.go b/legacy/builder/gcc_preproc_runner.go index 5066cd6f1f0..7a87d07c1f4 100644 --- a/legacy/builder/gcc_preproc_runner.go +++ b/legacy/builder/gcc_preproc_runner.go @@ -20,7 +20,6 @@ import ( "strings" "github.com/arduino/arduino-cli/legacy/builder/builder_utils" - "github.com/arduino/arduino-cli/legacy/builder/constants" "github.com/arduino/arduino-cli/legacy/builder/types" "github.com/arduino/arduino-cli/legacy/builder/utils" "github.com/arduino/go-paths-helper" @@ -58,18 +57,18 @@ func GCCPreprocRunnerForDiscoveringIncludes(ctx *types.Context, sourceFilePath * func prepareGCCPreprocRecipeProperties(ctx *types.Context, sourceFilePath *paths.Path, targetFilePath *paths.Path, includes paths.PathList) (*exec.Cmd, error) { properties := ctx.BuildProperties.Clone() properties.Set("build.library_discovery_phase", "1") - properties.SetPath(constants.BUILD_PROPERTIES_SOURCE_FILE, sourceFilePath) - properties.SetPath(constants.BUILD_PROPERTIES_PREPROCESSED_FILE_PATH, targetFilePath) + properties.SetPath("source_file", sourceFilePath) + properties.SetPath("preprocessed_file_path", targetFilePath) includesStrings := utils.Map(includes.AsStrings(), utils.WrapWithHyphenI) - properties.Set(constants.BUILD_PROPERTIES_INCLUDES, strings.Join(includesStrings, constants.SPACE)) + properties.Set("includes", strings.Join(includesStrings, " ")) - if properties.Get(constants.RECIPE_PREPROC_MACROS) == "" { + if properties.Get("recipe.preproc.macros") == "" { //generate PREPROC_MACROS from RECIPE_CPP_PATTERN - properties.Set(constants.RECIPE_PREPROC_MACROS, GeneratePreprocPatternFromCompile(properties.Get("recipe.cpp.o.pattern"))) + properties.Set("recipe.preproc.macros", GeneratePreprocPatternFromCompile(properties.Get("recipe.cpp.o.pattern"))) } - cmd, err := builder_utils.PrepareCommandForRecipe(properties, constants.RECIPE_PREPROC_MACROS, true, ctx.PackageManager.GetEnvVarsForSpawnedProcess()) + cmd, err := builder_utils.PrepareCommandForRecipe(properties, "recipe.preproc.macros", true, ctx.PackageManager.GetEnvVarsForSpawnedProcess()) if err != nil { return nil, errors.WithStack(err) } diff --git a/legacy/builder/preprocess_sketch.go b/legacy/builder/preprocess_sketch.go index 3a47d11587c..a8f66d96245 100644 --- a/legacy/builder/preprocess_sketch.go +++ b/legacy/builder/preprocess_sketch.go @@ -23,7 +23,6 @@ import ( "runtime" bldr "github.com/arduino/arduino-cli/arduino/builder" - "github.com/arduino/arduino-cli/legacy/builder/constants" "github.com/arduino/arduino-cli/legacy/builder/types" "github.com/arduino/arduino-cli/legacy/builder/utils" properties "github.com/arduino/go-properties-orderedmap" @@ -52,7 +51,7 @@ func (s *PreprocessSketchArduino) Run(ctx *types.Context) error { return errors.WithStack(err) } - GCCPreprocRunner(ctx, sourceFile, ctx.PreprocPath.Join(constants.FILE_CTAGS_TARGET_FOR_GCC_MINUS_E), ctx.IncludeFolders) + GCCPreprocRunner(ctx, sourceFile, ctx.PreprocPath.Join("ctags_target_for_gcc_minus_e.cpp"), ctx.IncludeFolders) for _, command := range commands { PrintRingNameIfDebug(ctx, command) @@ -69,15 +68,15 @@ type ArduinoPreprocessorRunner struct{} func (s *ArduinoPreprocessorRunner) Run(ctx *types.Context) error { buildProperties := ctx.BuildProperties - targetFilePath := ctx.PreprocPath.Join(constants.FILE_CTAGS_TARGET_FOR_GCC_MINUS_E) + targetFilePath := ctx.PreprocPath.Join("ctags_target_for_gcc_minus_e.cpp") preprocProperties := buildProperties.Clone() toolProps := buildProperties.SubTree("tools").SubTree("arduino-preprocessor") preprocProperties.Merge(toolProps) - preprocProperties.SetPath(constants.BUILD_PROPERTIES_SOURCE_FILE, targetFilePath) + preprocProperties.SetPath("source_file", targetFilePath) - pattern := preprocProperties.Get(constants.BUILD_PROPERTIES_PATTERN) - if pattern == constants.EMPTY_STRING { + pattern := preprocProperties.Get("pattern") + if pattern == "" { return errors.New(tr("arduino-preprocessor pattern is missing")) } diff --git a/legacy/builder/test/builder_test.go b/legacy/builder/test/builder_test.go index 79da75775c0..bcb9584a8e9 100644 --- a/legacy/builder/test/builder_test.go +++ b/legacy/builder/test/builder_test.go @@ -61,7 +61,7 @@ func TestBuilderEmptySketch(t *testing.T) { exist, err := buildPath.Join(constants.FOLDER_CORE, "HardwareSerial.cpp.o").ExistCheck() NoError(t, err) require.True(t, exist) - exist, err = buildPath.Join(constants.FOLDER_PREPROC, constants.FILE_CTAGS_TARGET_FOR_GCC_MINUS_E).ExistCheck() + exist, err = buildPath.Join(constants.FOLDER_PREPROC, "ctags_target_for_gcc_minus_e.cpp").ExistCheck() NoError(t, err) require.True(t, exist) exist, err = buildPath.Join(constants.FOLDER_SKETCH, "sketch1.ino.cpp.o").ExistCheck() @@ -91,7 +91,7 @@ func TestBuilderBridge(t *testing.T) { exist, err := buildPath.Join(constants.FOLDER_CORE, "HardwareSerial.cpp.o").ExistCheck() NoError(t, err) require.True(t, exist) - exist, err = buildPath.Join(constants.FOLDER_PREPROC, constants.FILE_CTAGS_TARGET_FOR_GCC_MINUS_E).ExistCheck() + exist, err = buildPath.Join(constants.FOLDER_PREPROC, "ctags_target_for_gcc_minus_e.cpp").ExistCheck() NoError(t, err) require.True(t, exist) exist, err = buildPath.Join(constants.FOLDER_SKETCH, "Bridge.ino.cpp.o").ExistCheck() @@ -124,7 +124,7 @@ func TestBuilderSketchWithConfig(t *testing.T) { exist, err := buildPath.Join(constants.FOLDER_CORE, "HardwareSerial.cpp.o").ExistCheck() NoError(t, err) require.True(t, exist) - exist, err = buildPath.Join(constants.FOLDER_PREPROC, constants.FILE_CTAGS_TARGET_FOR_GCC_MINUS_E).ExistCheck() + exist, err = buildPath.Join(constants.FOLDER_PREPROC, "ctags_target_for_gcc_minus_e.cpp").ExistCheck() NoError(t, err) require.True(t, exist) exist, err = buildPath.Join(constants.FOLDER_SKETCH, "sketch_with_config.ino.cpp.o").ExistCheck() @@ -162,7 +162,7 @@ func TestBuilderBridgeTwice(t *testing.T) { exist, err := buildPath.Join(constants.FOLDER_CORE, "HardwareSerial.cpp.o").ExistCheck() NoError(t, err) require.True(t, exist) - exist, err = buildPath.Join(constants.FOLDER_PREPROC, constants.FILE_CTAGS_TARGET_FOR_GCC_MINUS_E).ExistCheck() + exist, err = buildPath.Join(constants.FOLDER_PREPROC, "ctags_target_for_gcc_minus_e.cpp").ExistCheck() NoError(t, err) require.True(t, exist) exist, err = buildPath.Join(constants.FOLDER_SKETCH, "Bridge.ino.cpp.o").ExistCheck() @@ -202,7 +202,7 @@ func TestBuilderBridgeSAM(t *testing.T) { exist, err = buildPath.Join(constants.FOLDER_CORE, "avr", "dtostrf.c.d").ExistCheck() NoError(t, err) require.True(t, exist) - exist, err = buildPath.Join(constants.FOLDER_PREPROC, constants.FILE_CTAGS_TARGET_FOR_GCC_MINUS_E).ExistCheck() + exist, err = buildPath.Join(constants.FOLDER_PREPROC, "ctags_target_for_gcc_minus_e.cpp").ExistCheck() NoError(t, err) require.True(t, exist) exist, err = buildPath.Join(constants.FOLDER_SKETCH, "Bridge.ino.cpp.o").ExistCheck() @@ -242,7 +242,7 @@ func TestBuilderBridgeRedBearLab(t *testing.T) { exist, err := buildPath.Join(constants.FOLDER_CORE, "HardwareSerial.cpp.o").ExistCheck() NoError(t, err) require.True(t, exist) - exist, err = buildPath.Join(constants.FOLDER_PREPROC, constants.FILE_CTAGS_TARGET_FOR_GCC_MINUS_E).ExistCheck() + exist, err = buildPath.Join(constants.FOLDER_PREPROC, "ctags_target_for_gcc_minus_e.cpp").ExistCheck() NoError(t, err) require.True(t, exist) exist, err = buildPath.Join(constants.FOLDER_SKETCH, "Bridge.ino.cpp.o").ExistCheck() From 331f85bc163c02eec4a4f7c7cc33df8b18f513df Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Fri, 24 Mar 2023 17:10:28 +0100 Subject: [PATCH 2/2] Converted PreprocessSketchArduino and ContainerAddPrototypes into functions --- legacy/builder/builder.go | 6 +-- legacy/builder/container_add_prototypes.go | 4 +- legacy/builder/create_cmake_rule.go | 7 ++-- legacy/builder/preprocess_sketch.go | 4 +- legacy/builder/test/prototypes_adder_test.go | 42 ++++++++++---------- 5 files changed, 29 insertions(+), 34 deletions(-) diff --git a/legacy/builder/builder.go b/legacy/builder/builder.go index a21b4668670..d94308839f0 100644 --- a/legacy/builder/builder.go +++ b/legacy/builder/builder.go @@ -115,13 +115,11 @@ func (s *Builder) Run(ctx *types.Context) error { type PreprocessSketch struct{} func (s *PreprocessSketch) Run(ctx *types.Context) error { - var commands []types.Command if ctx.UseArduinoPreprocessor { - commands = append(commands, &PreprocessSketchArduino{}) + return PreprocessSketchWithArduinoPreprocessor(ctx) } else { - commands = append(commands, &ContainerAddPrototypes{}) + return PreprocessSketchWithCtags(ctx) } - return runCommands(ctx, commands) } type Preprocess struct{} diff --git a/legacy/builder/container_add_prototypes.go b/legacy/builder/container_add_prototypes.go index a2b37c8c93f..d710b82c979 100644 --- a/legacy/builder/container_add_prototypes.go +++ b/legacy/builder/container_add_prototypes.go @@ -23,9 +23,7 @@ import ( "github.com/pkg/errors" ) -type ContainerAddPrototypes struct{} - -func (s *ContainerAddPrototypes) Run(ctx *types.Context) error { +func PreprocessSketchWithCtags(ctx *types.Context) error { // Generate the full pathname for the preproc output file if err := ctx.PreprocPath.MkdirAll(); err != nil { return errors.WithStack(err) diff --git a/legacy/builder/create_cmake_rule.go b/legacy/builder/create_cmake_rule.go index 06f29d02f26..b7640ca58be 100644 --- a/legacy/builder/create_cmake_rule.go +++ b/legacy/builder/create_cmake_rule.go @@ -114,13 +114,14 @@ func (s *ExportProjectCMake) Run(ctx *types.Context) error { fmt.Println(err) } + if err := PreprocessSketchWithCtags(ctx); err != nil { + return err + } + // Use old ctags method to generate export file commands := []types.Command{ - //&ContainerMergeCopySketchFiles{}, - &ContainerAddPrototypes{}, &FilterSketchSource{Source: &ctx.Source, RemoveLineMarkers: true}, } - for _, command := range commands { command.Run(ctx) } diff --git a/legacy/builder/preprocess_sketch.go b/legacy/builder/preprocess_sketch.go index a8f66d96245..27d86b0f974 100644 --- a/legacy/builder/preprocess_sketch.go +++ b/legacy/builder/preprocess_sketch.go @@ -39,9 +39,7 @@ var ArduinoPreprocessorProperties = properties.NewFromHashmap(map[string]string{ "preproc.macros.flags": "-w -x c++ -E -CC", }) -type PreprocessSketchArduino struct{} - -func (s *PreprocessSketchArduino) Run(ctx *types.Context) error { +func PreprocessSketchWithArduinoPreprocessor(ctx *types.Context) error { sourceFile := ctx.SketchBuildPath.Join(ctx.Sketch.MainFile.Base() + ".cpp") commands := []types.Command{ &ArduinoPreprocessorRunner{}, diff --git a/legacy/builder/test/prototypes_adder_test.go b/legacy/builder/test/prototypes_adder_test.go index 013d05aff69..6d88f2ce9d3 100644 --- a/legacy/builder/test/prototypes_adder_test.go +++ b/legacy/builder/test/prototypes_adder_test.go @@ -51,13 +51,13 @@ func TestPrototypesAdderBridgeExample(t *testing.T) { &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, &builder.ContainerMergeCopySketchFiles{}, &builder.ContainerFindIncludes{}, - &builder.ContainerAddPrototypes{}, } for _, command := range commands { err := command.Run(ctx) NoError(t, err) } + NoError(t, builder.PreprocessSketchWithCtags(ctx)) require.Contains(t, ctx.Source, "#include \n#line 1 "+quotedSketchLocation+"\n") require.Equal(t, "#line 33 "+quotedSketchLocation+"\nvoid setup();\n#line 46 "+quotedSketchLocation+"\nvoid loop();\n#line 62 "+quotedSketchLocation+"\nvoid process(BridgeClient client);\n#line 82 "+quotedSketchLocation+"\nvoid digitalCommand(BridgeClient client);\n#line 109 "+quotedSketchLocation+"\nvoid analogCommand(BridgeClient client);\n#line 149 "+quotedSketchLocation+"\nvoid modeCommand(BridgeClient client);\n#line 33 "+quotedSketchLocation+"\n", ctx.PrototypesSection) @@ -83,13 +83,13 @@ func TestPrototypesAdderSketchWithIfDef(t *testing.T) { &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, &builder.ContainerMergeCopySketchFiles{}, &builder.ContainerFindIncludes{}, - &builder.ContainerAddPrototypes{}, } for _, command := range commands { err := command.Run(ctx) NoError(t, err) } + NoError(t, builder.PreprocessSketchWithCtags(ctx)) preprocessed := LoadAndInterpolate(t, filepath.Join("SketchWithIfDef", "SketchWithIfDef.preprocessed.txt"), ctx) require.Equal(t, preprocessed, strings.Replace(ctx.Source, "\r\n", "\n", -1)) @@ -115,13 +115,13 @@ func TestPrototypesAdderBaladuino(t *testing.T) { &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, &builder.ContainerMergeCopySketchFiles{}, &builder.ContainerFindIncludes{}, - &builder.ContainerAddPrototypes{}, } for _, command := range commands { err := command.Run(ctx) NoError(t, err) } + NoError(t, builder.PreprocessSketchWithCtags(ctx)) preprocessed := LoadAndInterpolate(t, filepath.Join("Baladuino", "Baladuino.preprocessed.txt"), ctx) require.Equal(t, preprocessed, strings.Replace(ctx.Source, "\r\n", "\n", -1)) @@ -147,13 +147,13 @@ func TestPrototypesAdderCharWithEscapedDoubleQuote(t *testing.T) { &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, &builder.ContainerMergeCopySketchFiles{}, &builder.ContainerFindIncludes{}, - &builder.ContainerAddPrototypes{}, } for _, command := range commands { err := command.Run(ctx) NoError(t, err) } + NoError(t, builder.PreprocessSketchWithCtags(ctx)) preprocessed := LoadAndInterpolate(t, filepath.Join("CharWithEscapedDoubleQuote", "CharWithEscapedDoubleQuote.preprocessed.txt"), ctx) require.Equal(t, preprocessed, strings.Replace(ctx.Source, "\r\n", "\n", -1)) @@ -179,13 +179,13 @@ func TestPrototypesAdderIncludeBetweenMultilineComment(t *testing.T) { &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, &builder.ContainerMergeCopySketchFiles{}, &builder.ContainerFindIncludes{}, - &builder.ContainerAddPrototypes{}, } for _, command := range commands { err := command.Run(ctx) NoError(t, err) } + NoError(t, builder.PreprocessSketchWithCtags(ctx)) preprocessed := LoadAndInterpolate(t, filepath.Join("IncludeBetweenMultilineComment", "IncludeBetweenMultilineComment.preprocessed.txt"), ctx) require.Equal(t, preprocessed, strings.Replace(ctx.Source, "\r\n", "\n", -1)) @@ -211,13 +211,13 @@ func TestPrototypesAdderLineContinuations(t *testing.T) { &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, &builder.ContainerMergeCopySketchFiles{}, &builder.ContainerFindIncludes{}, - &builder.ContainerAddPrototypes{}, } for _, command := range commands { err := command.Run(ctx) NoError(t, err) } + NoError(t, builder.PreprocessSketchWithCtags(ctx)) preprocessed := LoadAndInterpolate(t, filepath.Join("LineContinuations", "LineContinuations.preprocessed.txt"), ctx) require.Equal(t, preprocessed, strings.Replace(ctx.Source, "\r\n", "\n", -1)) @@ -243,13 +243,13 @@ func TestPrototypesAdderStringWithComment(t *testing.T) { &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, &builder.ContainerMergeCopySketchFiles{}, &builder.ContainerFindIncludes{}, - &builder.ContainerAddPrototypes{}, } for _, command := range commands { err := command.Run(ctx) NoError(t, err) } + NoError(t, builder.PreprocessSketchWithCtags(ctx)) preprocessed := LoadAndInterpolate(t, filepath.Join("StringWithComment", "StringWithComment.preprocessed.txt"), ctx) require.Equal(t, preprocessed, strings.Replace(ctx.Source, "\r\n", "\n", -1)) @@ -275,13 +275,13 @@ func TestPrototypesAdderSketchWithStruct(t *testing.T) { &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, &builder.ContainerMergeCopySketchFiles{}, &builder.ContainerFindIncludes{}, - &builder.ContainerAddPrototypes{}, } for _, command := range commands { err := command.Run(ctx) NoError(t, err) } + NoError(t, builder.PreprocessSketchWithCtags(ctx)) preprocessed := LoadAndInterpolate(t, filepath.Join("SketchWithStruct", "SketchWithStruct.preprocessed.txt"), ctx) obtained := strings.Replace(ctx.Source, "\r\n", "\n", -1) @@ -315,13 +315,13 @@ func TestPrototypesAdderSketchWithConfig(t *testing.T) { &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, &builder.ContainerMergeCopySketchFiles{}, &builder.ContainerFindIncludes{}, - &builder.ContainerAddPrototypes{}, } for _, command := range commands { err := command.Run(ctx) NoError(t, err) } + NoError(t, builder.PreprocessSketchWithCtags(ctx)) require.Contains(t, ctx.Source, "#include \n#line 1 "+quotedSketchLocation+"\n") require.Equal(t, "#line 13 "+quotedSketchLocation+"\nvoid setup();\n#line 17 "+quotedSketchLocation+"\nvoid loop();\n#line 13 "+quotedSketchLocation+"\n", ctx.PrototypesSection) @@ -353,13 +353,13 @@ func TestPrototypesAdderSketchNoFunctionsTwoFiles(t *testing.T) { &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, &builder.ContainerMergeCopySketchFiles{}, &builder.ContainerFindIncludes{}, - &builder.ContainerAddPrototypes{}, } for _, command := range commands { err := command.Run(ctx) NoError(t, err) } + NoError(t, builder.PreprocessSketchWithCtags(ctx)) require.Contains(t, ctx.Source, "#include \n#line 1 "+quotedSketchLocation+"\n") require.Equal(t, "", ctx.PrototypesSection) @@ -388,13 +388,13 @@ func TestPrototypesAdderSketchNoFunctions(t *testing.T) { &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, &builder.ContainerMergeCopySketchFiles{}, &builder.ContainerFindIncludes{}, - &builder.ContainerAddPrototypes{}, } for _, command := range commands { err := command.Run(ctx) NoError(t, err) } + NoError(t, builder.PreprocessSketchWithCtags(ctx)) require.Contains(t, ctx.Source, "#include \n#line 1 "+quotedSketchLocation+"\n") require.Equal(t, "", ctx.PrototypesSection) @@ -423,13 +423,13 @@ func TestPrototypesAdderSketchWithDefaultArgs(t *testing.T) { &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, &builder.ContainerMergeCopySketchFiles{}, &builder.ContainerFindIncludes{}, - &builder.ContainerAddPrototypes{}, } for _, command := range commands { err := command.Run(ctx) NoError(t, err) } + NoError(t, builder.PreprocessSketchWithCtags(ctx)) require.Contains(t, ctx.Source, "#include \n#line 1 "+quotedSketchLocation+"\n") require.Equal(t, "#line 4 "+quotedSketchLocation+"\nvoid setup();\n#line 7 "+quotedSketchLocation+"\nvoid loop();\n#line 1 "+quotedSketchLocation+"\n", ctx.PrototypesSection) @@ -458,13 +458,13 @@ func TestPrototypesAdderSketchWithInlineFunction(t *testing.T) { &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, &builder.ContainerMergeCopySketchFiles{}, &builder.ContainerFindIncludes{}, - &builder.ContainerAddPrototypes{}, } for _, command := range commands { err := command.Run(ctx) NoError(t, err) } + NoError(t, builder.PreprocessSketchWithCtags(ctx)) require.Contains(t, ctx.Source, "#include \n#line 1 "+quotedSketchLocation+"\n") @@ -504,13 +504,13 @@ func TestPrototypesAdderSketchWithFunctionSignatureInsideIFDEF(t *testing.T) { &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, &builder.ContainerMergeCopySketchFiles{}, &builder.ContainerFindIncludes{}, - &builder.ContainerAddPrototypes{}, } for _, command := range commands { err := command.Run(ctx) NoError(t, err) } + NoError(t, builder.PreprocessSketchWithCtags(ctx)) require.Contains(t, ctx.Source, "#include \n#line 1 "+quotedSketchLocation+"\n") require.Equal(t, "#line 1 "+quotedSketchLocation+"\nvoid setup();\n#line 3 "+quotedSketchLocation+"\nvoid loop();\n#line 15 "+quotedSketchLocation+"\nint8_t adalight();\n#line 1 "+quotedSketchLocation+"\n", ctx.PrototypesSection) @@ -539,13 +539,13 @@ func TestPrototypesAdderSketchWithUSBCON(t *testing.T) { &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, &builder.ContainerMergeCopySketchFiles{}, &builder.ContainerFindIncludes{}, - &builder.ContainerAddPrototypes{}, } for _, command := range commands { err := command.Run(ctx) NoError(t, err) } + NoError(t, builder.PreprocessSketchWithCtags(ctx)) require.Contains(t, ctx.Source, "#include \n#line 1 "+quotedSketchLocation+"\n") require.Equal(t, "#line 5 "+quotedSketchLocation+"\nvoid ciao();\n#line 10 "+quotedSketchLocation+"\nvoid setup();\n#line 15 "+quotedSketchLocation+"\nvoid loop();\n#line 5 "+quotedSketchLocation+"\n", ctx.PrototypesSection) @@ -573,13 +573,13 @@ func TestPrototypesAdderSketchWithTypename(t *testing.T) { &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, &builder.ContainerMergeCopySketchFiles{}, &builder.ContainerFindIncludes{}, - &builder.ContainerAddPrototypes{}, } for _, command := range commands { err := command.Run(ctx) NoError(t, err) } + NoError(t, builder.PreprocessSketchWithCtags(ctx)) require.Contains(t, ctx.Source, "#include \n#line 1 "+quotedSketchLocation+"\n") expected := "#line 6 " + quotedSketchLocation + "\nvoid setup();\n#line 10 " + quotedSketchLocation + "\nvoid loop();\n#line 12 " + quotedSketchLocation + "\ntypename Foo::Bar func();\n#line 6 " + quotedSketchLocation + "\n" @@ -614,13 +614,13 @@ func TestPrototypesAdderSketchWithIfDef2(t *testing.T) { &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, &builder.ContainerMergeCopySketchFiles{}, &builder.ContainerFindIncludes{}, - &builder.ContainerAddPrototypes{}, } for _, command := range commands { err := command.Run(ctx) NoError(t, err) } + NoError(t, builder.PreprocessSketchWithCtags(ctx)) require.Contains(t, ctx.Source, "#include \n#line 1 "+quotedSketchLocation+"\n") require.Equal(t, "#line 5 "+quotedSketchLocation+"\nvoid elseBranch();\n#line 9 "+quotedSketchLocation+"\nvoid f1();\n#line 10 "+quotedSketchLocation+"\nvoid f2();\n#line 12 "+quotedSketchLocation+"\nvoid setup();\n#line 14 "+quotedSketchLocation+"\nvoid loop();\n#line 5 "+quotedSketchLocation+"\n", ctx.PrototypesSection) @@ -652,13 +652,13 @@ func TestPrototypesAdderSketchWithIfDef2SAM(t *testing.T) { &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, &builder.ContainerMergeCopySketchFiles{}, &builder.ContainerFindIncludes{}, - &builder.ContainerAddPrototypes{}, } for _, command := range commands { err := command.Run(ctx) NoError(t, err) } + NoError(t, builder.PreprocessSketchWithCtags(ctx)) require.Contains(t, ctx.Source, "#include \n#line 1 "+quotedSketchLocation+"\n") require.Equal(t, "#line 2 "+quotedSketchLocation+"\nvoid ifBranch();\n#line 9 "+quotedSketchLocation+"\nvoid f1();\n#line 10 "+quotedSketchLocation+"\nvoid f2();\n#line 12 "+quotedSketchLocation+"\nvoid setup();\n#line 14 "+quotedSketchLocation+"\nvoid loop();\n#line 2 "+quotedSketchLocation+"\n", ctx.PrototypesSection) @@ -690,13 +690,13 @@ func TestPrototypesAdderSketchWithConst(t *testing.T) { &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, &builder.ContainerMergeCopySketchFiles{}, &builder.ContainerFindIncludes{}, - &builder.ContainerAddPrototypes{}, } for _, command := range commands { err := command.Run(ctx) NoError(t, err) } + NoError(t, builder.PreprocessSketchWithCtags(ctx)) require.Contains(t, ctx.Source, "#include \n#line 1 "+quotedSketchLocation+"\n") require.Equal(t, "#line 1 "+quotedSketchLocation+"\nvoid setup();\n#line 2 "+quotedSketchLocation+"\nvoid loop();\n#line 4 "+quotedSketchLocation+"\nconst __FlashStringHelper* test();\n#line 6 "+quotedSketchLocation+"\nconst int test3();\n#line 8 "+quotedSketchLocation+"\nvolatile __FlashStringHelper* test2();\n#line 10 "+quotedSketchLocation+"\nvolatile int test4();\n#line 1 "+quotedSketchLocation+"\n", ctx.PrototypesSection) @@ -722,13 +722,13 @@ func TestPrototypesAdderSketchWithDosEol(t *testing.T) { &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, &builder.ContainerMergeCopySketchFiles{}, &builder.ContainerFindIncludes{}, - &builder.ContainerAddPrototypes{}, } for _, command := range commands { err := command.Run(ctx) NoError(t, err) } + NoError(t, builder.PreprocessSketchWithCtags(ctx)) // only requires no error as result } @@ -754,13 +754,13 @@ func TestPrototypesAdderSketchWithSubstringFunctionMember(t *testing.T) { &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, &builder.ContainerMergeCopySketchFiles{}, &builder.ContainerFindIncludes{}, - &builder.ContainerAddPrototypes{}, } for _, command := range commands { err := command.Run(ctx) NoError(t, err) } + NoError(t, builder.PreprocessSketchWithCtags(ctx)) require.Contains(t, ctx.Source, "class Foo {\nint blooper(int x) { return x+1; }\n};\n\nFoo foo;\n\n#line 7 "+quotedSketchLocation+"\nvoid setup();") }