-
-
Notifications
You must be signed in to change notification settings - Fork 7k
Subfolders can no longer be included #5186
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
This is a serious issue that hast the potential to break many projects & sketches. |
it is not same as #5176 ? |
Yes, and it is a serious issue. I commented further here: |
Couldn't this be resolved by simply adding the original sketch directory to the include path? |
I think this is a good idea. Although, does the IDE share all settings globally between IDE instances. |
If the IDE is not going to copy the full sketch directory, then the IDE should tell the compiler to look in the original sketch directory for includes by adding it to the include path. @Chris--A From a broader perspective, |
becuase you can have unsaved changes. |
Signed-off-by: Cristian Maglie <[email protected]>
The change to limit recursive compilation to the
This is because the .ino files need to be preprocessed to:
Since writing such a temporary file to the original sketch directory isn't proper (and sometimes impossible when it is read-only), it must be written to some temporary folder. Since the .ino files can include other files in the sketch directory, these have to be copied too. An alternative approach to copying these other files would be adding the original sketch directory to the include path (possibly using A related issue is that when the IDE has unsaved files, another copy of the sketch is made, which gets copies of all files, and inclues the unsaved changes too. For this case, it seems elegant to create a directory with only the files with unsaved changes and use the include path to also access the unchanged files, but this runs into an issue where an unchanged file includes a changed file (since The latter issue does not apply when putting just the pre-processed .ino files in the build directory, since that preprocessed file is never included itself. So, are there other corner cases not covered by using the include path (preferably using |
Signed-off-by: Cristian Maglie <[email protected]>
See arduino/Arduino#5186 Signed-off-by: Cristian Maglie <[email protected]>
See arduino/Arduino#5186 Partially revert #148 Signed-off-by: Cristian Maglie <[email protected]>
Should fix: arduino/Arduino#5186 Signed-off-by: Cristian Maglie <[email protected]>
I'll also look more closely to the rationale for using a If you want to use subfolders, an obvious approach is to simply recursively list all files in the sketch or library directory, and compile them. This has one big problem: All files will be used as source files, with a filter on file extension being the only thing that prevents a file from being included in the build. In effect, the entire directory is (recursively) marked as containing source files. Now, if different things are to be included (such as examples, documentation, etc.), this is effectively impossible, since all subdirectories will be scanned for source files. This does not directly cause a problem if these other things use different filename extensions, but once your example includes a .c file, things will break. So, essentially you need a way to let the build environment distinguish between "source files" and "other things". Solutions will probably either:
Both of these can again be implemented in two ways:
Together, these form four options (implicit opt-in, implicit opt-out, explicit opt-in, explicit opt-out). There might of course be other options, but for now I'll limit the discussion to these four. Using the explicit options give the code author the most flexibility about how to arrange his source files. However, it also has some downsides:
For these reasons, I think the implicit option is better in an environment like Arduino. The implicit opt-in option seems the most flexible to me: Putting all source files in a Hence, this is why I think using the implicit opt-in method, i.e. only recursively compiling files inside the Note that this rationale does apply to compilation of source files, but does not really apply to inclusion of header files, which is really the subject of this issue. The distinction here is that header files are explicitely named through When we decided to limit recursive compilation to the |
Should fix: arduino/Arduino#5186 Signed-off-by: Cristian Maglie <[email protected]>
Signed-off-by: Cristian Maglie <[email protected]>
Should fix: arduino/Arduino#5186 Signed-off-by: Cristian Maglie <[email protected]>
There was already a test for including from inside the `src/` subfolder, but including from other subdirectories should also be supported (even when source files inside those directories are not compiled). This adds a test for this. See also arduino/Arduino#5186. Signed-off-by: Matthijs Kooijman <[email protected]>
There was already a test for including from inside the `src/` subfolder, but including from other subdirectories should also be supported (even when source files inside those directories are not compiled). This adds a test for this. See also arduino/Arduino#5186. Signed-off-by: Matthijs Kooijman <[email protected]>
@matthijskooijman The focus seemed to be on what directories are used to recursively look in for compiling things or to automatically include as part of the build. I don't really have any strong feelings on this and restricting the directories used for automatically compiled sources seems reasonable, even if it is to single directory named 'src'. However, I have seen some interesting embedded projects on sites like make/makerzine/instructables, that have sub directories in their sketch directory for libraries and utility code. However, what seemed unreasonable was the restriction of not being able to use sub directories for organizing include files. In C++ since you can have function definition (code) in the header file. Restoring the ability of a sketch to use #include "subdir/file" would restore a consistency with library code. Can't the include issue be solved by simply adding the original sketch directory to the include path? |
Commit 405a24a (Limit recursive sketch compilation to the `src` directory) modified the sketch loading to only recursively load files from the `src` subdirectory of a sketch, in order to only compile source files in that subdirectory. As a side effect, this also prevents source and header files in other subdirectories from being copied into the build directory, and hence from being included. This side effect was not entirely unanticipated, but its implications were underestimated. This commit undoes these side effects: source and header files are again loaded (and thus copied) recursively in all subdirectories of a sketch. Compilation is still limited to the src subdirectory (there already was code to achieve this). This commit also modifies include detection to be limited to the src subdirectory (which was previously implicit, since it can only look at files that were copied into the build directory). With this commit, the the meaning of "loading" a file becomes a bit fuzzy in the code, but this is intended to be fixed in a future refactor. A test will be added in the next commit. This fixes arduino/Arduino#5186. Signed-off-by: Cristian Maglie <[email protected]> Signed-off-by: Matthijs Kooijman <[email protected]>
There was already a test for including from inside the `src/` subfolder, but including from other subdirectories should also be supported (even when source files inside those directories are not compiled). This adds a test for this. See also arduino/Arduino#5186. Signed-off-by: Matthijs Kooijman <[email protected]>
Note that this is still possible: Just put the subdirectories in the The current proposal is to re-instate the copying of source and header files in subdirectories as it was before, but still limit the compilation of source files to the |
Btw, see arduino/arduino-builder#172 for the implementation of that proposal. |
Seems like a very sensible approach. Any changes that the IDE makes relating to how sketches are built can have ripple effects in all those other tools causing their toolsets to break or put lots of work on those tool maintainers. |
The next hourly-build should have fixed this issue. |
yes, sorry, #5211 is duplicate. |
up to version 1.6.9; if you had .h files in a subfolder of a sketch, you could #include "subfolder/file.h" and it would compile.
In 1.6.10 this function has been removed.
The text was updated successfully, but these errors were encountered: