-
-
Notifications
You must be signed in to change notification settings - Fork 398
add #line tags to AdditionalFiles when copying to build directory, to… #707
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
add #line tags to AdditionalFiles when copying to build directory, to… #707
Conversation
… improve error messages
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.
Thanks for this PR, would be a nice change to see. I have three remarks, one-and-a-half of which I had already posted on the original PR:
- For what kinds of files is this #line directive now added? .cpp, .c and .h files are of course fine, but how about assembly files? Can there be any other types of files in the list of "Additional files" that do not like #line directives?
- When files to be modified are really big, then the in-memory prepending of the line directive might be ineffecient (compared to writing the line directive first and then the original contents). I can see why we need this to compare the file contents, though. Maybe that could also be done in two parts, though. For big files, completely loading into memory might be a bit problematic by itself, but creating a complete copy of the contents might double that problem.
- This now happens in a function called
writeIfDifferent
, which is a nice and generic function that now hardcodes this C-preprocessor-specific bit of content. Maybe it would be cleaner if this function would accept an arbitrary "prefix" argument, and the calller (maybe a few levels up) that knows more about the types of files being processed could compones the#line
directive?
My answers:
|
Re 1.: Is this the authoritative list? arduino-cli/arduino/globals/globals.go Line 29 in c387167
These should all be fine? No ASM? |
Yeah, looks like. Looking at those, I think all of them use the preprocessor.
Yeah, this is probably true. Especially since this considers just sketch files, not all compiled code (e.g. it excludes all libraries and system headers), all of which also have to be loaded into memory.
I don't think that is true: Currently the file is loaded into memory once, with this change it is loaded twice (one []byte with the original, one []byte with the prefixed version). And this could be fixed by never appending the two in memory, but comparing and writing the parts separately. But that would make the code more complex for probably minimal gain.
Ah, I see it is actually in So with that, I think the code is fine as it is now, as far as I'm concerned (though I'm not in a position to decide on this). One addition that might be useful: Add a testcase that verifies this works (mostly to prevent later changes from breaking it again). I can imagine a small unittest that just tests the sketch copying and verifies the |
That's true, and I did realise that when I wrote it. Coming from C++ you do tend to think about what you're doing with the machine's resources. However, IMHO it is just not relevant here. This is the thought process I followed when writing my one line of code: find ~/arduino-1.8.12/ -name '*.cpp' -or -name '*.h' -print0 | xargs -0 ls -lS | head -n1
1021807 hardware/arduino/avr/firmwares/wifishield/wifi_dnld/src/wl_fw.h The largest possible file (which would never, ever be included as "addtiional files" in the sketch folder) is 1MB. If we hold that in memory twice it's 2MB. A raspbery PIe 3, perhaps the smallest possible host, has 1GB RAM, so we are golden by 2-3 orders of magnitude here. That's why I said "YAGNI", and I agree that it's not worth making the code more complicated to "prematurely optimise for memory usage".
Great, thank you.
OK, That testing framework might be a big learning curve. I can't promise I will manage the time for that, but I will try. |
Are we sure this is right?
https://stackoverflow.com/a/7190511/1087626
Maybe I need to special case the ".s' and skip the '#line'? |
I did a quick proof of concept test using the attached "Hello Wolrd" assembler test: Result. If I name the file asm.S (with capital S) then it works just fine, compiles, with added '#line ..' What I don't understand is why it is compiled at all. '*.S' is not one of the patterns here: arduino-cli/arduino/globals/globals.go Line 29 in c387167
If I rename gcc -c .... sketch/asm.s -o /dev/null -DARDUINO_LIB_DISCOVERY_PHASE but not actually compiled to a Not quite sure I understand:
My tentative conclusion: That list in globals.go is not the authoritative list, and/or there are other places where decisions are made on what to do with these "additional files"? |
Hah, good catch about
Yup, case insensitive indeed, at least for including files in the sketch and thus copying them: arduino-cli/arduino/sketch/sketch.go Line 98 in 24503d5
arduino-cli/arduino/builder/sketch.go Line 190 in 24503d5
Seems there is a different list for compilation, probably because this code was imported from arduino-cli/legacy/builder/builder_utils/utils.go Lines 71 to 82 in 0866d99
So, that check is not case sensitive (probably should be, be that's out of scope for this PR. Maybe something for @cmaglie to look at, I think he was working on removing some of the legacy).
The reason it is processed at all, is that the "include detection" uses a different code path, that just runs commands on all source files, using yet another list of extensions:
arduino-cli/legacy/builder/builder.go Line 36 in 0866d99
For completeness, I checked that that list is again checked case insensitively: arduino-cli/legacy/builder/utils/utils.go Line 387 in 0866d99
As for why this does not barf on Now the real question is: If A related question would be: Are these |
Wow, OK, that's pandorra's box of legacy issues.... :-) Can Windows even tell if a file is upper/lowercase with their case in-sentitive filesystem? I wouldn't know, haven't coded for Windows for two decades. I think your last question is the real one. Should #line be used for .s or .S ? The answer is no I believe. All of those other things should probably be addressed as you point out, but as you say, probably out of scope and should be separate. so would a (pseudo-code): if (!toUpper(filename).endsWidth('.S')) prependLineNo() be safer, and solve the issue without scope creep? As part of the legacy cleanup "what do to with each kind of file", I would aim for some kind of central struct/config which stores all the filters/actions for each file type in each situation - and the above "insert #line tags" should be one of those. But I don't know the code, so I can't say if that's realistic. |
Did you confirm whether
Yeah, it's just that you cannot have both cases in the same directory at the same time and file opens etc. match insensitively, but files do have a case sensitive canonical name.
Yeah, I think that would indeed make sense. Cleaning up existing code would be out of scope, but for new checks, maybe we could do something nicer. Such as adding a 'doesNotSupportLineDirective' map to https://github.com/arduino/arduino-cli/blob/c3871677ab82229181975f6aba1170bd721a58d5/arduino/globals/globals.go. Might not be the perfect solution, but then at least this new check is anchored to One super-tricky thing here is that this particular check must be case sensitive, while all other extension checks are (or should be) case insensitive, so that requires a clear comment to prevent future confusion (a future refactor could maybe store regexes or otherwise make the case (in)sensitivity more explicit, but again, out of scope). |
Neither causes an error but the lowercase version doesn't get compiled for unrelated reasons. Re the other stuff: None of these issues really relate to the #line issue/feature. I am happy to make any appropriate change to if/switch/case/match in whatever source code file. But really this needs a decision from someone who can take responsibility for the dev path of that whole situation. The actual coding bit is fairly trivial. So if we want this feature, and there is such a person, please speak up now. |
Oh wait, I misread your earlier comment: You proposed to disable adding the line directive for both To implement that, I would still suggest adding something to
Yup. I would think @cmaglie or @facchinm, though there are some more devs in this repo I do not really know yet :-) |
@oschonrock , @matthijskooijman , you guys have considered so many features not relating directly to this pull request, including but not limited to:
All of those are very interesting questions indeed, but what bothers me more is if this change branch ever gets merged to the main trunk. I wrote my original pull request with the same purpose for arduino-builder almost a year ago, though it remained ignored by the arduion team. And then the branches diverged during a huge refactoring making the changes incompatible. A friend of mine wrote a new patch for the current version of arduino-cli roughly half a year ago, reportedly even on the very same line as @oschonrock , but my friend did not even bother to publish his change and I can only wonder why... Studying source codes and proposing changes is really hip! However more important matter is making the arudion team notice our changes and embrace them instead of disregarding them. Up until now they seem a little oblivious to the open source community. Any ideas how to change this situation? |
I completely agree. My proposed changeset is precisely 1 line, in order to achieve a purpose with minimum fuss. All the complicated discussions came from the other guy... ;-) And they ultimately came to nothing. In the end, I said exactly the same thing as you: Unless we get someone with main branch commit rights to approve this, this is a waste of time. That's where the discussion stopped. I am running a patched version on my machine, so I am happy. I tried to share. It came to nothing so far. You can't force open source project to prioritise your preferred changes. TBH, I get the impression that this project is riddled with many complication due to the long legacy of the arduino IDE. This often happens in older projects, and it can be very difficult to make improvements, because every change breaks something, so you tend to "leave it alone, unless Rome is burning". |
In my experience, one of the most effective ways to get something merged, is to make sure it is easy to review, and the code has good quality (so minimal improvement cycles are needed). Both reduce the amount of time a core dev has to spend on a PR. All of my questions and comments on this PR have been with these goals in mind, not for "studying source codes". I have indeed posed some questions which are not directly related to the change in this PR, but are related to the way this PR fits into the broader context. One can disregard those as irrelevant, but failing to see the broader context (and then deciding whether a change might need some refactoring to better fit) will likely result in code that is harder to maintain, eventually slowing down development, rather than speeding it up. Also, a lot of the questions I've posed are likely things that the core devs will also be wondering when they review this PR. Having those questions considered, and answered will again help speed up review (even if the answer is "the PR does not need to be changed", it helps if this is made explicit). In that sense, it might be helpful to summarize some of the questions considered, observations made and conclusions resulting from those.
AFAICS, this is more a problem of workload: There seem to be a lot more issues and contributions than the core devs can currently process. I'm pretty sure they would want for some extra hours in the day to fix this, but that is not the reality. It may seem that your contribution, or the contributions that you care about are being ignored, but that probably means that time is spent getting other contributions merged. So, as a community, we can probably try to help things by doing our best to make things easy to review, but also review each other's contributions and getting them into a better shape before the core devs get a chance to look at them in detail. The risk is that you spend time getting something perfect that does not end up being merged, or ends up broken in a big refactor, but I'm not sure how to better handle this with the resources available...
I certainly think this is a problem for Arduino, but I do not have the impression that it much applies here. |
No offence, but I think the far reaching, sweeping discussion about out of scope refactorings of other parts of the code is quite disproportionate for a one line change. IMHO it makes this pull request totally unusable if someone with commit right actually looked at. They would have to read for 30mins in order to approve 1 line of change. This should be clean and straightforward. 1 line changeset. Approve or reject, by someone with the permissions and rights to do so. It is now getting even worse, because it is turning into a philosophical discussion about how open source works. I have been doing open source for over 20 years, and I can tell you, this is not how. So since this pull request is now unusable for anyone with the permissions, I am going to close it and abort. If you can find someone with decision making power who cares, we can make a new one. Enjoy. |
@oschonrock if you don't mind, I've had this one in my backlog, so I'll reopen it. Apologies for the slow responsiveness, but we are really under a heavy workload, I understand that this could be frustrating sometimes... |
Related to: arduino/arduino-builder#325 |
Sure. If you've read this far, you must be really keen ;-) |
Fixes #965 |
Merged in #1224 |
… improve error messages
Please check if the PR fulfills these requirements
What kind of change does this PR introduce?
Feature. Usable file:line locations in compiler error messages for Additional files
What is the current behavior?
Additional files show error message location in build directory, which is not useful
What is the new behavior?
Compiler Error messages in additional files now reference the original file. Same behaviour as for main and extra sketch files
Does this PR introduce a breaking change?
No
Other information:
It's a trivial one liner. Please change it there is a better way.
See how to contribute