hi everyone, I'm working on a parser will be used as a hook before the Arduino processing. As referred in Arduino IDE 1.5 3rd party Hardware specification · arduino/Arduino Wiki · GitHub, I should be able to use the properties {source.file} and {runtime.ide.path} to retrieve the absolute path of the source file and the runtime path. Despite other properties ({runtime.hardware.path},{build.folder},etc) are correctly solved by the IDE, {source.file} and {runtime.ide.path} are not.
Any idea to solve the problem?
Thanks
Note it's {source_file}, not {source.file}. However, I confirm that {source_file} and {runtime.ide.path} are not working in the hook recipes. {source_file} does work in standard recipes, in fact it's essential to the compilation process. I was not able to get {runtime.ide.path} working in any of my tests (using Windows 10) no matter where it was used.
This definitely seems like a bug to me. I recommend you test to see if it still occurs with the beta build:
Hooks support was added in Arduino IDE 1.6.2 so it would be helpful to install that version to see if those properties were ever supported or if support was lost in some version between 1.6.2 and 1.8.5.
If the issue still occurs with the beta build of the Arduino IDE, I recommend that you submit a bug report to the issue tracker here:
be sure to provide a clear description of the problem and any information that might make it easier for the developers to fix the problem.
pert, thank you for the answer. I have already tried with the beta and it has the same problem. Seems a bug also to me, I'll fill a bug report to developers.
The issue report:
I spent some more time looking into this. I created a dummy platform.txt, which I've attached. The "{compiler.path}{compiler.size.cmd}" -v
part is just a workaround I used to generate commands that wouldn't fail the build so that all the recipes could run. If you set verbose compilation output in File > Preferences, compile something, then examine the output in the console window it really makes it clear how the hook recipes are used and also where each property is defined.
So I still think the {runtime.ide.path} issue is purely a bug but I now understand more why {source_file} is not defined in the hook recipes. To truly make that work they would need to either modify the current hooks to be run before and after the compilation of each file or add additional hook to do this.
Note that if you are trying to get the path and name of the .cpp file generated from the sketch that is already accessible from any recipe as {build.path}/sketch/{build.project_name}.cpp
.
platform.txt (19.6 KB)
Pert, thanks for the further information. Anyway, the access to .ccp file is not suitable for me, in fact I need to parse the .ino file before it goes into the Arduino processing.
I don't think there is currently any way to get the sketch folder. I believe the reason for this is that it will allow people to add the sketch folder to the include path. After that, libraries can include files from the sketch folder, which makes it so that libraries can be configured from the sketch using the preprocessor. It is official Arduino policy that this is not desirable because they are afraid it will lead to libraries having a less beginner friendly API. I kind of understand where they're coming from but I really don't think it's such a big problem as they expect and it has the side effect of preventing things like what you're trying to do. Of course the IDE knows the sketch location but to expose this data to the user I believe you'd need to modify the IDE's source code and then build it.
There are a ton of issues and pull requests related to this topic. You can find most of them by following the web of references in this PR:
That includes many other proposals for adding this functionality in various ways so they will not all directly apply to your requirement other than that they contain explanations of why Arduino does not allow this.
I think creating a property that contains the sketch folder path would not really lead to a change in library APIs as long as the official Arduino hardware packages don't add the sketch folder to the include path. The majority of library authors are going to want their libraries to work with the standard hardware packages so it's unlikely many would base their API around things only possible when used with a small number of 3rd party hardware packages.
pert, thanks another time, your answer was really helpful. Unfortunately, I cannot modify the IDE, so I'm trying to figure out wether I can find a way to modify the source file before entering in the arduino process phase.
The .ino.cpp file is the source file. Before starting a compilation the Arduino IDE does a few things to turn the .ino file(s) into valid C++:
- Concatenate all .ino files, starting with the one that matches the sketch folder name, then the rest in alphabetical order.
- Generate function prototypes for all functions that don't already have one
- Add the line
#include <Arduino.h>
- Add #line directives so that warning/error output will still match the sketch
- Save the resulting file to the temporary build folder with the .cpp extension appended to the file name.
So all the code from the sketch is in that .ino.cpp file, there's just some extra code added to it. In the beta build all the code for the core library is also added to the sketch so that generated file gets huge! This is due to the new arduino-preprocessor tool working differently than the sketch preprocessing process done by arduino-builder in the non-beta IDE versions.
If you use the recipe.hooks.sketch.prebuild.NUMBER.pattern to modify {build.path}/sketch/{build.project_name}.cpp you will be modifying the source file before the compilation starts. At the time that hook is called I believe the only things that have happened is the sketch preprocessing I explained above and arduino-builder determining the necessary include path ({includes}).
I think it might be helpful if you provided details about what you're trying to accomplish.
pert, sorry for the delay, i think i solved the problem using the {build.path}/sketch/{build.project_name}.cpp file. Anyway, i'm working on a preparser to launch before the arduino building process, able to recognise different loop functions, each have a defined activation time. Thank you very much for the support, it has been very helpful.
Glad to hear it's working for you now! Enjoy.
Per