Skip to content

Commit d37f451

Browse files
author
Federico Fissore
committed
Hooks were missing "recipe.", resulting in no hooks being run
Signed-off-by: Federico Fissore <[email protected]>
1 parent 36a6f9e commit d37f451

File tree

3 files changed

+102
-23
lines changed

3 files changed

+102
-23
lines changed

Diff for: src/arduino.cc/builder/builder.go

+10-10
Original file line numberDiff line numberDiff line change
@@ -86,25 +86,25 @@ func (s *Builder) Run(context map[string]interface{}) error {
8686

8787
&ContainerAddPrototypes{},
8888

89-
&RecipeByPrefixSuffixRunner{Prefix: constants.HOOKS_SKETCH + constants.HOOKS_PREBUILD_SUFFIX, Suffix: constants.HOOKS_PATTERN_SUFFIX},
89+
&RecipeByPrefixSuffixRunner{Prefix: constants.HOOKS_SKETCH_PREBUILD, Suffix: constants.HOOKS_PATTERN_SUFFIX},
9090
&phases.SketchBuilder{},
91-
&RecipeByPrefixSuffixRunner{Prefix: constants.HOOKS_SKETCH + constants.HOOKS_POSTBUILD_SUFFIX, Suffix: constants.HOOKS_PATTERN_SUFFIX},
91+
&RecipeByPrefixSuffixRunner{Prefix: constants.HOOKS_SKETCH_POSTBUILD, Suffix: constants.HOOKS_PATTERN_SUFFIX},
9292

93-
&RecipeByPrefixSuffixRunner{Prefix: constants.HOOKS_LIBRARIES + constants.HOOKS_PREBUILD_SUFFIX, Suffix: constants.HOOKS_PATTERN_SUFFIX},
93+
&RecipeByPrefixSuffixRunner{Prefix: constants.HOOKS_LIBRARIES_PREBUILD, Suffix: constants.HOOKS_PATTERN_SUFFIX},
9494
&phases.LibrariesBuilder{},
95-
&RecipeByPrefixSuffixRunner{Prefix: constants.HOOKS_LIBRARIES + constants.HOOKS_POSTBUILD_SUFFIX, Suffix: constants.HOOKS_PATTERN_SUFFIX},
95+
&RecipeByPrefixSuffixRunner{Prefix: constants.HOOKS_LIBRARIES_POSTBUILD, Suffix: constants.HOOKS_PATTERN_SUFFIX},
9696

97-
&RecipeByPrefixSuffixRunner{Prefix: constants.HOOKS_CORE + constants.HOOKS_PREBUILD_SUFFIX, Suffix: constants.HOOKS_PATTERN_SUFFIX},
97+
&RecipeByPrefixSuffixRunner{Prefix: constants.HOOKS_CORE_PREBUILD, Suffix: constants.HOOKS_PATTERN_SUFFIX},
9898
&phases.CoreBuilder{},
99-
&RecipeByPrefixSuffixRunner{Prefix: constants.HOOKS_CORE + constants.HOOKS_POSTBUILD_SUFFIX, Suffix: constants.HOOKS_PATTERN_SUFFIX},
99+
&RecipeByPrefixSuffixRunner{Prefix: constants.HOOKS_CORE_POSTBUILD, Suffix: constants.HOOKS_PATTERN_SUFFIX},
100100

101-
&RecipeByPrefixSuffixRunner{Prefix: constants.HOOKS_LINKING + constants.HOOKS_PRELINK_SUFFIX, Suffix: constants.HOOKS_PATTERN_SUFFIX},
101+
&RecipeByPrefixSuffixRunner{Prefix: constants.HOOKS_LINKING_PRELINK, Suffix: constants.HOOKS_PATTERN_SUFFIX},
102102
&phases.Linker{},
103-
&RecipeByPrefixSuffixRunner{Prefix: constants.HOOKS_LINKING + constants.HOOKS_POSTLINK_SUFFIX, Suffix: constants.HOOKS_PATTERN_SUFFIX},
103+
&RecipeByPrefixSuffixRunner{Prefix: constants.HOOKS_LINKING_POSTLINK, Suffix: constants.HOOKS_PATTERN_SUFFIX},
104104

105-
&RecipeByPrefixSuffixRunner{Prefix: constants.HOOKS_OBJCOPY + constants.HOOKS_PREOBJCOPY, Suffix: constants.HOOKS_PATTERN_SUFFIX},
105+
&RecipeByPrefixSuffixRunner{Prefix: constants.HOOKS_OBJCOPY_PREOBJCOPY, Suffix: constants.HOOKS_PATTERN_SUFFIX},
106106
&RecipeByPrefixSuffixRunner{Prefix: "recipe.objcopy.", Suffix: constants.HOOKS_PATTERN_SUFFIX},
107-
&RecipeByPrefixSuffixRunner{Prefix: constants.HOOKS_OBJCOPY + constants.HOOKS_POSTOBJCOPY, Suffix: constants.HOOKS_PATTERN_SUFFIX},
107+
&RecipeByPrefixSuffixRunner{Prefix: constants.HOOKS_OBJCOPY_POSTOBJCOPY, Suffix: constants.HOOKS_PATTERN_SUFFIX},
108108

109109
&MergeSketchWithBootloader{},
110110

Diff for: src/arduino.cc/builder/constants/constants.go

+24-13
Original file line numberDiff line numberDiff line change
@@ -135,20 +135,31 @@ const FOLDER_SKETCH = "sketch"
135135
const FOLDER_SYSTEM = "system"
136136
const FOLDER_TOOLS = "tools"
137137
const FOLDER_VARIANTS = "variants"
138-
const HOOKS_CORE = "hooks.core"
139-
const HOOKS_LIBRARIES = "hooks.libraries"
140-
const HOOKS_LINKING = "hooks.linking"
141-
const HOOKS_OBJCOPY = "hooks.objcopy"
138+
const hooks_core = hooks + ".core"
139+
const HOOKS_CORE_POSTBUILD = hooks_core + hooks_postbuild_suffix
140+
const HOOKS_CORE_PREBUILD = hooks_core + hooks_prebuild_suffix
141+
const hooks_libraries = hooks + ".libraries"
142+
const HOOKS_LIBRARIES_POSTBUILD = hooks_libraries + hooks_postbuild_suffix
143+
const HOOKS_LIBRARIES_PREBUILD = hooks_libraries + hooks_prebuild_suffix
144+
const hooks_linking = hooks + ".linking"
145+
const HOOKS_LINKING_POSTLINK = hooks_linking + hooks_postlink_suffix
146+
const HOOKS_LINKING_PRELINK = hooks_linking + hooks_prelink_suffix
147+
const hooks_objcopy = hooks + ".objcopy"
148+
const HOOKS_OBJCOPY_POSTOBJCOPY = hooks_objcopy + hooks_postobjcopy_suffix
149+
const HOOKS_OBJCOPY_PREOBJCOPY = hooks_objcopy + hooks_preobjcopy_suffix
142150
const HOOKS_PATTERN_SUFFIX = ".pattern"
143-
const HOOKS_POSTBUILD = "hooks.postbuild"
144-
const HOOKS_POSTBUILD_SUFFIX = ".postbuild"
145-
const HOOKS_POSTLINK_SUFFIX = ".postlink"
146-
const HOOKS_POSTOBJCOPY = ".postobjcopy"
147-
const HOOKS_PREBUILD = "hooks.prebuild"
148-
const HOOKS_PREBUILD_SUFFIX = ".prebuild"
149-
const HOOKS_PRELINK_SUFFIX = ".prelink"
150-
const HOOKS_PREOBJCOPY = ".preobjcopy"
151-
const HOOKS_SKETCH = "hooks.sketch"
151+
const HOOKS_POSTBUILD = hooks + hooks_postbuild_suffix
152+
const hooks_postbuild_suffix = ".postbuild"
153+
const hooks_postlink_suffix = ".postlink"
154+
const hooks_postobjcopy_suffix = ".postobjcopy"
155+
const HOOKS_PREBUILD = hooks + hooks_prebuild_suffix
156+
const hooks_prebuild_suffix = ".prebuild"
157+
const hooks_prelink_suffix = ".prelink"
158+
const hooks_preobjcopy_suffix = ".preobjcopy"
159+
const hooks = "recipe.hooks"
160+
const hooks_sketch = hooks + ".sketch"
161+
const HOOKS_SKETCH_POSTBUILD = hooks_sketch + hooks_postbuild_suffix
162+
const HOOKS_SKETCH_PREBUILD = hooks_sketch + hooks_prebuild_suffix
152163
const IDE_VERSION = "ide_version"
153164
const ID = "_id"
154165
const LIB_CATEGORY_UNCATEGORIZED = "Uncategorized"

Diff for: src/arduino.cc/builder/test/recipe_runner_test.go

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* This file is part of Arduino Builder.
3+
*
4+
* Arduino Builder is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation; either version 2 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program; if not, write to the Free Software
16+
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17+
*
18+
* As a special exception, you may use this file as part of a free software
19+
* library without restriction. Specifically, if other files instantiate
20+
* templates or use macros or inline functions from this file, or you compile
21+
* this file and link it with other files to produce an executable, this
22+
* file does not by itself cause the resulting executable to be covered by
23+
* the GNU General Public License. This exception does not however
24+
* invalidate any other reasons why the executable file might be covered by
25+
* the GNU General Public License.
26+
*
27+
* Copyright 2015 Arduino LLC (http://www.arduino.cc/)
28+
*/
29+
30+
package test
31+
32+
import (
33+
"arduino.cc/builder"
34+
"arduino.cc/builder/constants"
35+
"arduino.cc/builder/types"
36+
"github.com/stretchr/testify/require"
37+
"testing"
38+
)
39+
40+
// TODO
41+
// I can't find a command I can run on linux, mac and windows
42+
// and that allows to test if the recipe is actually run
43+
// So this test is pretty useless
44+
func TestRecipeRunner(t *testing.T) {
45+
context := make(map[string]interface{})
46+
buildProperties := make(map[string]string)
47+
context[constants.CTX_BUILD_PROPERTIES] = buildProperties
48+
49+
buildProperties["recipe.hooks.prebuild.1.pattern"] = "echo"
50+
51+
commands := []types.Command{
52+
&builder.SetupHumanLoggerIfMissing{},
53+
&builder.AddAdditionalEntriesToContext{},
54+
&builder.RecipeByPrefixSuffixRunner{Prefix: constants.HOOKS_PREBUILD, Suffix: constants.HOOKS_PATTERN_SUFFIX},
55+
}
56+
57+
for _, command := range commands {
58+
err := command.Run(context)
59+
NoError(t, err)
60+
}
61+
}
62+
63+
func TestRecipesComposition(t *testing.T) {
64+
require.Equal(t, "recipe.hooks.core.postbuild", constants.HOOKS_CORE_POSTBUILD)
65+
require.Equal(t, "recipe.hooks.postbuild", constants.HOOKS_POSTBUILD)
66+
require.Equal(t, "recipe.hooks.linking.prelink", constants.HOOKS_LINKING_PRELINK)
67+
require.Equal(t, "recipe.hooks.objcopy.preobjcopy", constants.HOOKS_OBJCOPY_PREOBJCOPY)
68+
}

0 commit comments

Comments
 (0)