Skip to content

Commit bd5d3ec

Browse files
committed
Fix include resolution for older compilers
the regexp was only handling the #include line Signed-off-by: Martino Facchin <[email protected]>
1 parent 3449672 commit bd5d3ec

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

src/arduino.cc/builder/includes_finder_with_regexp.go

+18
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ func (s *IncludesFinderWithRegExp) Run(context map[string]interface{}) error {
5151
includes = append(includes, strings.TrimSpace(match[1]))
5252
}
5353

54+
if len(includes) == 0 {
55+
include := findIncludesForOldCompilers(source)
56+
if include != "" {
57+
includes = append(includes, include)
58+
}
59+
}
60+
5461
context[constants.CTX_INCLUDES_JUST_FOUND] = includes
5562

5663
if !utils.MapHas(context, constants.CTX_INCLUDES) {
@@ -62,3 +69,14 @@ func (s *IncludesFinderWithRegExp) Run(context map[string]interface{}) error {
6269

6370
return nil
6471
}
72+
73+
func findIncludesForOldCompilers(source string) string {
74+
firstLine := strings.Split(source, "\n")[0]
75+
splittedLine := strings.Split(firstLine, ":")
76+
for i, _ := range splittedLine {
77+
if strings.Contains(splittedLine[i], "fatal error") {
78+
return strings.TrimSpace(splittedLine[i+1])
79+
}
80+
}
81+
return ""
82+
}

src/arduino.cc/builder/test/includes_finder_with_regexp_test.go

+21
Original file line numberDiff line numberDiff line change
@@ -182,3 +182,24 @@ func TestIncludesFinderWithRegExpPaddedIncludes2(t *testing.T) {
182182
sort.Strings(includes)
183183
require.Equal(t, "Wire.h", includes[0])
184184
}
185+
186+
func TestIncludesFinderWithRegExpPaddedIncludes3(t *testing.T) {
187+
context := make(map[string]interface{})
188+
189+
context[constants.CTX_INCLUDES] = []string{}
190+
191+
output := "/some/path/sketch.ino:1:33: fatal error: SPI.h: No such file or directory\n" +
192+
"compilation terminated.\n"
193+
194+
context["source"] = output
195+
196+
parser := builder.IncludesFinderWithRegExp{ContextField: "source"}
197+
err := parser.Run(context)
198+
NoError(t, err)
199+
200+
require.NotNil(t, context[constants.CTX_INCLUDES])
201+
includes := context[constants.CTX_INCLUDES].([]string)
202+
require.Equal(t, 1, len(includes))
203+
sort.Strings(includes)
204+
require.Equal(t, "SPI.h", includes[0])
205+
}

0 commit comments

Comments
 (0)