Arduino IDE - Pre and Post Build Hooks - Any before include determination?

128 views
Skip to first unread message

Owen Lyke

unread,
May 18, 2020, 5:43:18 PM5/18/20
to devel...@arduino.cc
Hi everyone - I am working on an Arduino core using this specification:

I have a need to run a script to generate my include paths before the "Detecting libraries used..." step however the earliest hook listed in that document occurs after that step and before the step to compile the sketch "Compiling sketch..." This is problematic because the library detection step needs my full list of includes - which are generated by this script call. 

The reason why I need to generate the includes is because there are so many locations that command line commands begin to exceed their ~32,000 character limit. I want to place includes in a file to be included using GCC's '@file' option.

AFAIK I cannot use relative paths except from provided locations such as {runtime.platform.path} because I don't know what working directory Arduino will call my compile steps from... besides {runtime.platform.path} just seems like a good cross-platform feature to stick with. So the plan is to generate an absolute list of include paths using {runtime.platform.path} every time the user clicks 'verify'

Does anyone have insight into this issue? Is there an undocumented hook that I can use that executes as the first thing during a build? 

Thanks,
Owen L

Martino Facchin

unread,
May 22, 2020, 6:21:17 AM5/22/20
to devel...@arduino.cc
Hi Owen,
would you mind opening an issue in https://arduino.github.io/arduino-cli/ with a request to add an early hook? I think other people might find it useful and being on github could speedup the process.
About your specific problem, I think I answered you here https://github.com/arduino/ArduinoCore-nRF528x-mbedos/issues/78 :)

Cheers
M

--
You received this message because you are subscribed to the Google Groups "Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to developers+...@arduino.cc.
To view this discussion on the web visit https://groups.google.com/a/arduino.cc/d/msgid/developers/CAC64nR_1Kyi%3DcuU3xaXW4Dt-NAHdrv_%3D4H%2B%2B3c%2BsHPYXaOOfYw%40mail.gmail.com.

William Westfield

unread,
May 26, 2020, 1:38:52 AM5/26/20
to Developers

I cannot use relative paths except from provided locations such as {runtime.platform.path} because I don't know what working directory Arduino will call my compile steps from.

You know that relative paths inside an include file are relative to the the directory that contains the include file, or to paths that you did give an -I switch for,  right?
So an Arduino zero build does:

  "-I/Applications/Arduino-1.8.9… tools/CMSIS-Atmel/1.2.0/CMSIS/Device/ATMEL/“

But does NOT have to include the directories below that in order for the
#include “samd.h”  // in sam.h
#include "samd21/include/samd21.h”  // in samd.h
#include “samd21g18a.h”  // in samd21.h
#include “component/dac.h”   //in samd21g18a.h

includes to work…

I’m not arguing with the need for an earlier hook, but I’m a bit boggled that you’ve exceeded 32k characters of paths…

BillW/WestfW

Owen Lyke

unread,
May 26, 2020, 10:34:23 AM5/26/20
to devel...@arduino.cc
Martino / Bill

Yes - I will gladly open an issue on the CLI repo. I was also shocked to find myself running into this limitation. My previous strategy was to blindly match all the "-I" flags that the target project (mbed) generated (about 16k characters using relative paths and bloated to ~39k characters when prefixed with the absolute path to my platform install location). For the time being I am solving the issue by regenerating the include structure with absolute paths so that I can use the feature that Bill mentioned (I will end up with a single -I flag to the root of my mbed include structure). I will look at Martino's answer on the nRF528x core as well to see if I can find inspiration for a more elegant solution.

Thank you much for both of your responses.

Owen

--
You received this message because you are subscribed to the Google Groups "Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to developers+...@arduino.cc.


--
Owen Lyke
Product Development Engineer
SparkFun Electronics, Inc.
a:6333 Dry Creek Pkwy
 Niwot, CO. 80503
w:
e:  
sparkfun.com
owen.lyke@sparkfun.com 

      

Owen Lyke

unread,
May 26, 2020, 10:49:05 AM5/26/20
to devel...@arduino.cc
Aha - Martino's answer to my issue is just what I was looking for. He revealed a GCC option that I had never seen before. Maybe it will be useful to others in the future so I'll briefly summarize here as well:

-iprefix specifies a prefix that may be used with subsequent flags
-iwithprefixbefore appends a combination of the string previously specified with -iprefix and the string from this flag itself to the include search path similarly to the -I flag
-iwithprefix does the same except the end behaviour matches the -idirafter flag

This should save me the headache of duplicating the source headers. Fantastic!


William Westfield

unread,
May 26, 2020, 9:45:55 PM5/26/20
to 'Owen Lyke' via Developers

-iprefix specifies a prefix that may be used with subsequent flags

Neat.  I had never noticed that before, either.  Thanks for reporting it back to the list!

BillW/WestfW

Reply all
Reply to author
Forward
0 new messages