-
-
Notifications
You must be signed in to change notification settings - Fork 7k
Renaming C to CPP gives errors #4335
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
Comments
When you have unsaved changes, the IDE writes a copy of the sketch to a temporary dir, and lets arduino-builder compile that. When there are no unsaved changes, arduino-builder is called on the original sketch dir instead. Since the rename is not done on the temporary copy, it breaks, and saving it fixes it because then the original sketch dir is used again. I suspect that simply deleting the temporary copy after each compilation would be best here, since every new compilation completely copies it again anyway. |
This happen when you rename the file by OS and the file is already opened It is a bug or a normal behaviour ? One of the solution can be enable renaming inside IDE
|
I actually think the bug NicoHood is describing happens when you rename the file withing the IDE itself. If you rename the file externally, then indeed, the IDE will not know about this and you must restart the IDE (or re-open the sketch) to make it find out. In general, you should not modify your sketch externally, unless "external editor" is set. At some point, it might make sense to let the IDE automatically check for external modifications, even when external editor is disabled, but this is not the subject of this issue :-) |
So is it posdible change a file name inside ide ? From pippo.c to pippo.cpp or pippo2.c ? |
IMHO this is a real annoyance that makes the ide feel like it comes straight from the 80's... which can be fixed with only a handfull of loc. |
@Testato, Yes, there is a "rename tab" option in the dropdown to the right of the tabs (little arrow/triangle pointing down). |
I used the rename tab in this case. |
Hm. I think it will not disable that optimization, but I'm also not really sure why that optimization works at all when there's unsaved changes. In any case, in the process there's (at most) four copies of the sketch files:
When calling arduino-builder, 1. is passed if possible, but if there are modifications, 3. is generated and passed. 4. is always generated by arduino-builder. If there are no modifications, arduino-builder can compare timestamps between 1. and the .o files in .4 and reuse them if unchanged (directory 4 is kept around until the IDE is closed and deleted then). However, when 3. is generated, those will always get fresh timestamps now. I thought that perhaps arduino-builder was passed both the original sketch as well as 3., but it seems it just gets 3. So I'm not so sure why how it can detect that a file was not changed, but somehow it does (even when I delete directory 3. manually). I'm a bit puzzled about this. In any case, it seems like an improvement over the current mechanism would be to only write the modified files to 3. and then pass both 1. and 3. to arduino-builder. It will then use files from 3. when they exist and 1. otherwise. This allows arduino-builder to see the original timestamps on unmodified files. On modified files, this will always see an updated timestamp (so these will always be recompiled, even if they were not changed since the last compile), but that seems ok. A big advantage of this approach is that any unmodified files, or additional files (in the sketch directory, but not loaded in the editor) do not need to copied into 3., saving one copy (they will still need to be copied into 4.) |
On additional reason for the last change proposed above, is that now if you compile without modified files and then with modified files, the sketch path changes (as far as arduino-builder can see) so arduino-builder recompiles everything. |
Ah, figured out why arduino-builder does not currently recompiles all sketch files when some files are modified. Arduino builder currently copies files from the sketch directory (1. or 3. above) into the build directory (4. above), but first compares their content. If the content has not changed, the files are not copied into the build directory. Then the actual compilation looks at the timestamps of the source files in the build directory, which will not have changed if the contents of a file did not change. So, deleting directory 3. in the IDE after every compilation should not affect this optimization currently. I still think we should consider my above suggestion, but for now we could start with fixing this on the IDE side (deleting the entire directory 3. should also happen when it just contains changed files). |
Dunno what you will do for your version, but i am rewriting this [particularly 3]. I want to keep track of files as they get modified and compile only what needs to be compiled. What i saw is that everybit of knowledge that exists at a layer in the chain gets wiped when going down. my situation is made worse by the fact that i support local libraries inside a sketch. I am also leaning towards caches per architecture so that a sketch can be tested accross boards without encurring compile-the-world each time (currently the binaries are directly accessible in their containing folder, preventing several architecture to stay there side by side). In the end this is not impacting builder as i have my own compiler-driver (i can switch between aeduino-builder and mine). |
Any suggestions on how to remove the need for directory 3? Passing file contents through stdin as JSON or something like that? In the end, the modified contents will have to end up in a file for gcc to work with it (or you can probably let gcc compile from stdin, but I'm not sure if that's the best way to handle this...). |
Sorry for the noise, but a question: |
If you're developing a library you probably don't want to use the lib manager at all, but clone it with git instead (that has a much better tracking capabilities so your changes can be easily maintained in sync with upstream development) BTW this question is totally offtopic here, please open another issue or comment on an already existing one that is in topic. |
When a sketch has unsaved changes, a temporary copy of the sketch is made with those changes applied. This copy is then passed to arduino-builder. Previously, this temporary copy was kept around and only deleted when the IDE was closed. However, all files were written to it again on every build, so keeping the old files around did not serve any real purpose. When a file was renamed in the IDE, the original name would still be present in the temporary copy, and could cause linker errors when both were compiled. This commit makes sure the temporary copy is deleted after every build, instead of at IDE exit, which fixes this problem with renames. When a file is deleted from the sketch, the file would also be deleted from the temporary problem, presumably to fix this same problem for deletes (but renames were forgotten). With this commit, this special handling for deleting files is no longer needed, so it is removed. This fixes arduino#4335
When a sketch has unsaved changes, a temporary copy of the sketch is made with those changes applied. This copy is then passed to arduino-builder. Previously, this temporary copy was kept around and only deleted when the IDE was closed. However, all files were written to it again on every build, so keeping the old files around did not serve any real purpose. When a file was renamed in the IDE, the original name would still be present in the temporary copy, and could cause linker errors because both were compiled. This commit makes sure the temporary copy is deleted after every build, instead of at IDE exit, which fixes this problem with renames. When a file is deleted from the sketch, the file would also be deleted from the temporary copy, presumably to fix this same problem for deletes (but renames were forgotten). With this commit, this special handling for deleting files is no longer needed, so it is removed. This fixes arduino#4335
@NicoHood, I just created a PR to fix this. Could you perhaps try it to confirm it fixes your problem? |
When a sketch has unsaved changes, a temporary copy of the sketch is made with those changes applied. This copy is then passed to arduino-builder. Previously, this temporary copy was kept around and only deleted when the IDE was closed. However, all files were written to it again on every build, so keeping the old files around did not serve any real purpose. When a file was renamed in the IDE, the original name would still be present in the temporary copy, and could cause linker errors because both were compiled. This commit makes sure the temporary copy is deleted after every build, instead of at IDE exit, which fixes this problem with renames. When a file is deleted from the sketch, the file would also be deleted from the temporary copy, presumably to fix this same problem for deletes (but renames were forgotten). With this commit, this special handling for deleting files is no longer needed, so it is removed. This fixes arduino#4335
@matthijskooijman @Testato @lmihalkovic
#4333 (comment)
If you rename the c files to cpp (or vice versa) the other is kept in the temporary directly for compiling and sometimes leftover. Saving fixes this, editing again breaks it again. I have no test for this though.
The text was updated successfully, but these errors were encountered: