-
-
Notifications
You must be signed in to change notification settings - Fork 388
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed sketch compile with broken symlink #2497
Conversation
719185d
to
6cf55a6
Compare
Also see #1438 for an older approach for this problem, which would ignore stat errors from broken symlinks, and only raise an error if a broken symlink was actually opened (e.g. for copying into the build directory). That is less broad than the fix in this PR, which IIUC omits all broken symlinks from the list of sketch files (so e.g. would silently omit a broken myfile.c symlink from compilation) which probably works better in more cases, but could also end up making things fail in unexpected ways silently. Note that the approach in the other PR ended up not solving the actual problem I was having at the time (ignoring a broken compilation_commands.json symlink), since .json files are now also sketch files that will be copied, so I ended up adding an extra explicit ignore for compilation_commands.json there. For me this problem is now solved differently (using a |
4cd14f3
to
5e95130
Compare
This PR is not trying to omit a broken symlink to
Besides that, looking at the integration tests, it seems quite hard to get this thing right (luckily we have a ton of tests...). The tricky part is that when you recurse subdirs you have to decide if you should follow a symlink or not, but you don't know in advance if a broken symlink points to a directory or a file, for example:
in this case, the link points to a sketch file, and it should error on compile. BTW when we do the ReadDirRecursive we don't know if the link points to a file or a dir, so we cannot just ignore it. I've approached this with a bit of heuristic, if the name of the symlink has one of the accepted file extensions and it is a broken link, it must be accepted as part of the sketch file list. BTW thinking on this a bit more the symlink existence check should be moved inside the ReadDirRecursive, so it will not error if the symlink is broken (assuming it is a directory), but just pass the symlink path in the result list (as it was a file) for further processing. I'll make this change and see how it goes. Another tricky issue is that when we ignore errors on broken symlinks, we may be affected by infinite symlink loop recursion because previously we stopped at the first "path too long" error, but now we don't! (well it's not exactly infinite recursion, but an exponentially long recursion). So I had to implement a better loop recursion detection: arduino/go-paths-helper#29 Finally, there is another test case that is failing now:
this one I hadn't the time to check yet... |
Ah, I see. I only looked quickly before and missed the "Fail if a sketch file is a broken symlink" which changes the check to indeed not omit broken symlinks with supported extensions.
That sound reasonable, yes.
Hm, I do not see how this follows from the "omit some broken symlinks from the file list" change in this PR, but maybe you mean that it results from some earlier change in go-paths-helper? Though I can't quite see which one. Also, did you happen to have a look at arduino/go-paths-helper#13? It fixes some (broken) symlink related stuff (and also adds an Lstat() method just like you did recently ;-p). I haven't had a closer look now, though, I'm out of time :-) |
Yes, it's very tricky, it has surprised me too, consider this folder:
basically both points to the current dir, so you can write any path like
we may catch the exact
It's going to be fully implemented with the other incoming PRs on go-paths-helper... :-) |
dbcd232
to
415c711
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #2497 +/- ##
==========================================
+ Coverage 68.82% 68.92% +0.10%
==========================================
Files 204 204
Lines 20457 20451 -6
==========================================
+ Hits 14079 14096 +17
+ Misses 5221 5206 -15
+ Partials 1157 1149 -8
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
The version of go-paths imported in go.mod is the one containing this PR: arduino/go-paths-helper#30 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remember to replace the go-paths-helper with the tagged version.
Previously the unit tests were creating the wrong env to test: internal/arduino/libraries/testdata/TestLib ├── examples │ ├── UpGoer1 -> testdata/TestLib │ └── UpGoer2 -> testdata/TestLib ├── library.properties └── src └── TestLib.h The two UpGoer1 and UpGoer2 are broken links. The correct tree is the following: internal/arduino/libraries/testdata/TestLib ├── examples │ ├── UpGoer1 -> .. │ └── UpGoer2 -> .. ├── library.properties └── src └── TestLib.h that actually triggers the symlink loop we are testing.
42e0475
to
e9dc764
Compare
Please check if the PR fulfills these requirements
See how to contribute
before creating one)
our contributing guidelines
UPGRADING.md
has been updated with a migration guide (for breaking changes)configuration.schema.json
updated if new parameters are added.What kind of change does this PR introduce?
Fix sketch compilation when there is a broken symlink.
What is the current behavior?
What is the new behavior?
Does this PR introduce a breaking change, and is titled accordingly?
Some sketches may start failing to build, but this is not a breaking change, I see it as a long-standing bug fix
Other information
Fix #1765
Supersedes #1438