Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

improved regexp to also parse error messages with single quotes around header file name#2782

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged

Conversation

@dennisppaul
Copy link
Contributor

@dennisppauldennisppaul commentedDec 13, 2024
edited
Loading

What kind of change does this PR introduce?

this change improves the behavior of functionIncludesFinderWithRegExp indetector.go by changing the regexp to also extract a library header file name. even when it is surrounded by single quotes.

background: when working on a board definition that uses the desktop gcc compiler, we found that the error message emitted, which is used to deduce a library header file name, failed to produce the desired result with the current regular expression. the desktop gcc compiler emits the error message surrounding the header file name with single quotes like this:

g++:

... fatal error: 'Foobar.h' file not found    2 | #include <Foobar.h>

while other compilers, currently used in arduino board definitions, omit the single quotes and therefore can be processed correctly:

avr-g++:

... fatal error: Foobar.h: No such file or directory #include <Foobar.h>

arm-none-eabi-g++:

... fatal error: Foobar.h: No such file or directory    2 | #include <Foobar.h>

riscv32-esp-elf-g++:

... fatal error: Foobar.h: No such file or directory    2 | #include <Foobar.h>

in order to address this issues we have changed the regular expression to the following:

var includeRegexp = regexp.MustCompile(`(?ms)[<"'](\S+)[">']`)

with this change error messages from all compilers are parsed correctly.

this issues has been encountered with desktop gcc compiler on macOS :

$ gcc --versionApple clang version 16.0.0 (clang-1600.0.26.6)Target: arm64-apple-darwin24.1.0Thread model: posixInstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

Does this PR introduce a breaking change, and istitled accordingly?

as far as we know this PR does not introduce a breaking change. however, only four compilers have been tested.

PS the old regexp used to work on macOS until recently. apparently the error message emitted by desktop gcc on macOS has been changed, which broke the arduino header file name detection …

@CLAassistant
Copy link

CLAassistant commentedDec 13, 2024
edited
Loading

CLA assistant check
All committers have signed the CLA.

@codecov
Copy link

codecovbot commentedDec 13, 2024
edited
Loading

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 67.63%. Comparing base(84fc413) to head(fea0d5b).
Report is 11 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@##           master    #2782      +/-   ##==========================================+ Coverage   67.57%   67.63%   +0.05%==========================================  Files         238      238                Lines       22362    22392      +30     ==========================================+ Hits        15111    15144      +33+ Misses       6062     6060       -2+ Partials     1189     1188       -1
FlagCoverage Δ
unit67.63% <ø> (+0.05%)⬆️

Flags with carried forward coverage won't be shown.Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report?Share it here.

cmaglie
cmaglie previously requested changesDec 18, 2024
Copy link
Member

@cmagliecmaglie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Hi@dennisppaul, thanks for the detailed report.

g++:

... fatal error: 'Foobar.h' file not found    2 | #include <Foobar.h>

while other compilers, currently used in arduino board definitions, omit the single quotes and therefore can be processed correctly:

Actually, the matching is done on the#include <...> part (the part of the source code that is quoted in the error message) and not in the error message itself, the missing quotes do not affect the result.

https://regex101.com/r/CYmT4J/1

in order to address this issues we have changed the regular expression to the following:

var includeRegexp = regexp.MustCompile(`(?ms)[<"'](\S+)[">']`)

This works but I'm concerned that it will be too broader, and it would match errors that just contains quoted strings like in this examplehttps://regex101.com/r/2rhB6a/1 (look the latest case).

I would just relax the regex a bit to include the missing case, something like:

varincludeRegexp=regexp.MustCompile(`(?ms)^\s*[0-9 |]*\s*#[ \t]*include\s*[<"](\S+)[">]`)

https://regex101.com/r/nWPv0h/1

Can you add a couple of test cases indetector_test.go too?

@dennisppaul
Copy link
ContributorAuthor

i understand your concern and i do agree, the regexp is too broad. i tried yours, however, the patterns that work in regex101.com does not seem to work in a similar way in go ( interesting! ). i therefore suggest to use a pattern that is not as generic but still works in go as well:

var includeRegexp = regexp.MustCompile(`#include[ \t]*[<"](\S+)[">]`)

i also added a test:

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)}

@cmaglie
Copy link
Member

i understand your concern and i do agree, the regexp is too broad. i tried yours, however, the patterns that work in regex101.com does not seem to work in a similar way in go ( interesting! ). i therefore suggest to use a pattern that is not as generic but still works in go as well:

The problem was that in the new unit-test you forgot to add the newlines in the test string (see the fix in my latest pushed commit). I've reverted the regex with my last suggestion and the test PASS.

@cmagliecmaglie self-assigned thisJan 7, 2025
@cmagliecmaglie added type: enhancementProposed improvement topic: build-processRelated to the sketch build process labelsJan 7, 2025
@cmagliecmaglie added this to theArduino CLI v1.1.2 milestoneJan 7, 2025
Copy link
Contributor

@MatteoPologrutoMatteoPologruto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

LGTM, good job 🚀

cmaglie reacted with heart emoji
@cmagliecmaglie merged commit63bfd5c intoarduino:masterJan 7, 2025
98 checks passed
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@MatteoPologrutoMatteoPologrutoMatteoPologruto approved these changes

@cmagliecmaglieAwaiting requested review from cmaglie

@alessio-peruginialessio-peruginiAwaiting requested review from alessio-perugini

Assignees

@cmagliecmaglie

Labels

topic: build-processRelated to the sketch build processtype: enhancementProposed improvement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@dennisppaul@CLAassistant@cmaglie@MatteoPologruto

[8]ページ先頭

©2009-2025 Movatter.jp