From 78941c05820f3ae4ca26e59adebce81529b2e497 Mon Sep 17 00:00:00 2001 From: dennisppaul Date: Fri, 13 Dec 2024 11:56:15 +0100 Subject: [PATCH 1/4] improved regexp to also parse error messages with single quotes around header file name --- internal/arduino/builder/internal/detector/detector.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/arduino/builder/internal/detector/detector.go b/internal/arduino/builder/internal/detector/detector.go index 17de9377833..2d176ae11e7 100644 --- a/internal/arduino/builder/internal/detector/detector.go +++ b/internal/arduino/builder/internal/detector/detector.go @@ -478,7 +478,7 @@ func (l *SketchLibrariesDetector) failIfImportedLibraryIsWrong() error { } // includeRegexp fixdoc -var includeRegexp = regexp.MustCompile("(?ms)^\\s*#[ \t]*include\\s*[<\"](\\S+)[\">]") +var includeRegexp = regexp.MustCompile(`(?ms)[<"'](\S+)[">']`) // IncludesFinderWithRegExp fixdoc func IncludesFinderWithRegExp(source string) string { From f1faeaa00b692c1151dfeca8d0ed10f5743f05fc Mon Sep 17 00:00:00 2001 From: dennisppaul Date: Wed, 18 Dec 2024 22:48:44 +0100 Subject: [PATCH 2/4] make regexp more specific, add test --- internal/arduino/builder/internal/detector/detector.go | 2 +- .../arduino/builder/internal/detector/detector_test.go | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/internal/arduino/builder/internal/detector/detector.go b/internal/arduino/builder/internal/detector/detector.go index 2d176ae11e7..979e09ee54b 100644 --- a/internal/arduino/builder/internal/detector/detector.go +++ b/internal/arduino/builder/internal/detector/detector.go @@ -478,7 +478,7 @@ func (l *SketchLibrariesDetector) failIfImportedLibraryIsWrong() error { } // includeRegexp fixdoc -var includeRegexp = regexp.MustCompile(`(?ms)[<"'](\S+)[">']`) +var includeRegexp = regexp.MustCompile(`#include[ \t]*[<"](\S+)[">]`) // IncludesFinderWithRegExp fixdoc func IncludesFinderWithRegExp(source string) string { diff --git a/internal/arduino/builder/internal/detector/detector_test.go b/internal/arduino/builder/internal/detector/detector_test.go index 6e7f72648a4..b663f66a45e 100644 --- a/internal/arduino/builder/internal/detector/detector_test.go +++ b/internal/arduino/builder/internal/detector/detector_test.go @@ -75,3 +75,13 @@ func TestIncludesFinderWithRegExpPaddedIncludes4(t *testing.T) { require.Equal(t, "register.h", include) } + +func TestIncludesFinderWithRegExpPaddedIncludes5(t *testing.T) { + output := "/some/path/sketch.ino:23:42: fatal error: 'Foobar.h' file not found" + + " 23 | #include \"Foobar.h\"" + + " | ^~~~~~~~~~" + + include := detector.IncludesFinderWithRegExp(output) + + require.Equal(t, "Foobar.h", include) +} From 78d6d436b17da41bcbaca8a31381f2e55faeda01 Mon Sep 17 00:00:00 2001 From: dennisppaul Date: Wed, 18 Dec 2024 22:54:22 +0100 Subject: [PATCH 3/4] remove GH test failing escaped quotation marks --- internal/arduino/builder/internal/detector/detector_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/arduino/builder/internal/detector/detector_test.go b/internal/arduino/builder/internal/detector/detector_test.go index b663f66a45e..606b6bacb8e 100644 --- a/internal/arduino/builder/internal/detector/detector_test.go +++ b/internal/arduino/builder/internal/detector/detector_test.go @@ -78,7 +78,7 @@ func TestIncludesFinderWithRegExpPaddedIncludes4(t *testing.T) { func TestIncludesFinderWithRegExpPaddedIncludes5(t *testing.T) { output := "/some/path/sketch.ino:23:42: fatal error: 'Foobar.h' file not found" + - " 23 | #include \"Foobar.h\"" + + " 23 | #include " + " | ^~~~~~~~~~" include := detector.IncludesFinderWithRegExp(output) From c47f78b5f8d5185e2f83406a9180c93dc154d67a Mon Sep 17 00:00:00 2001 From: dennisppaul Date: Wed, 18 Dec 2024 22:59:16 +0100 Subject: [PATCH 4/4] fix formatting --- internal/arduino/builder/internal/detector/detector_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/arduino/builder/internal/detector/detector_test.go b/internal/arduino/builder/internal/detector/detector_test.go index 606b6bacb8e..367958f909b 100644 --- a/internal/arduino/builder/internal/detector/detector_test.go +++ b/internal/arduino/builder/internal/detector/detector_test.go @@ -78,8 +78,8 @@ func TestIncludesFinderWithRegExpPaddedIncludes4(t *testing.T) { func TestIncludesFinderWithRegExpPaddedIncludes5(t *testing.T) { output := "/some/path/sketch.ino:23:42: fatal error: 'Foobar.h' file not found" + - " 23 | #include " + - " | ^~~~~~~~~~" + " 23 | #include \"Foobar.h\"" + + " | ^~~~~~~~~~" include := detector.IncludesFinderWithRegExp(output)