Skip to content

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

Closed
NicoHood opened this issue Dec 23, 2015 · 15 comments
Closed

Renaming C to CPP gives errors #4335

NicoHood opened this issue Dec 23, 2015 · 15 comments
Assignees
Labels
Component: Compilation Related to compilation of Arduino sketches feature request A request to make an enhancement (not a bug fix) Type: Bug
Milestone

Comments

@NicoHood
Copy link
Contributor

@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.

@matthijskooijman
Copy link
Collaborator

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.

@Testato
Copy link

Testato commented Dec 23, 2015

This happen when you rename the file by OS and the file is already opened
in the IDE. If you rename and reboot the ide the problem disappear.

It is a bug or a normal behaviour ?
The IDE must refresh and re-read the filename+extension ?

One of the solution can be enable renaming inside IDE
Il 23/dic/2015 08:51, "Nico" [email protected] ha scritto:

@matthijskooijman https://github.com/matthijskooijman @Testato
https://github.com/testato @lmihalkovic https://github.com/lmihalkovic
#4333 (comment)
#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.


Reply to this email directly or view it on GitHub
#4335.

@matthijskooijman
Copy link
Collaborator

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

@Testato
Copy link

Testato commented Dec 23, 2015

So is it posdible change a file name inside ide ? From pippo.c to pippo.cpp or pippo2.c ?

@lmihalkovic
Copy link

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.

@matthijskooijman
Copy link
Collaborator

@Testato, Yes, there is a "rename tab" option in the dropdown to the right of the tabs (little arrow/triangle pointing down).

@NicoHood
Copy link
Contributor Author

I used the rename tab in this case.
Not sure if deleting all then disables the "do not recompile already compiled files" optimization.

@matthijskooijman
Copy link
Collaborator

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:

  1. The original files in your sketchbook
  2. The files loaded into memory in the editor. If there's unsaved changes, these are different from 2.
  3. A temporary save of the sketch. This is generated by the IDE when there are unsaved changes, to allow passing the in-memory modifications to arduino-builder.
  4. A copy in the final build folder. The .ino files are modified here with prototypes, other files are copied as-is.

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

@matthijskooijman
Copy link
Collaborator

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.

@matthijskooijman
Copy link
Collaborator

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

@lmihalkovic
Copy link

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

@matthijskooijman
Copy link
Collaborator

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

@Testato
Copy link

Testato commented Dec 23, 2015

Sorry for the noise, but a question:
In the 1.6.7 official it is not supported use a library inside thev sketch folder ?
Actually if i update a lib by library manager i loose my lib modification.

@cmaglie
Copy link
Member

cmaglie commented Dec 23, 2015

Actually if i update a lib by library manager i loose my lib modification.

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.

@cmaglie cmaglie added feature request A request to make an enhancement (not a bug fix) Type: Bug Component: Compilation Related to compilation of Arduino sketches labels Dec 23, 2015
@matthijskooijman matthijskooijman self-assigned this Dec 28, 2015
matthijskooijman added a commit to matthijskooijman/Arduino that referenced this issue Dec 28, 2015
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
matthijskooijman added a commit to matthijskooijman/Arduino that referenced this issue Dec 28, 2015
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
Copy link
Collaborator

@NicoHood, I just created a PR to fix this. Could you perhaps try it to confirm it fixes your problem?

matthijskooijman added a commit to matthijskooijman/Arduino that referenced this issue Dec 30, 2015
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
@cmaglie cmaglie added this to the Release 1.6.8 milestone Jan 19, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Compilation Related to compilation of Arduino sketches feature request A request to make an enhancement (not a bug fix) Type: Bug
Projects
None yet
Development

No branches or pull requests

5 participants