user10024: What I am trying to accomplish is to include information about the state of my environment at build time in my code. For example, I may want the setup() code to print the git sha it was built against, and the time of build. 
There are two related issues here:

How to include that information in the code
How to specify to the build environment what to generate in the first place.

The first can be addressed in a number of ways:

-D options can be generated at build time, and the corresponding defined macros expanded in the code. For example, the compiler could be invoked as g++ -DGIT_SHA=$(git rev-parse HEAD) -DDATE=$(date '+%Y%m%d-%H:%M:%S'), and my code could have something like #define strfy(_x) #_x followed by Serial.println(strfy(GIT_SHA));. Or the build tool could generate a header file that would define these as external string variables, which the main sketch could then include and print. Or any other number of tricks.

The question I am really asking is: how should I specify this sort of stuff for arduino-builder?
Ideally, it would be a custom recipe in platform.txt, but if there is a way to invoke shell commands in recipes and use the results to modify other variables (such as preproc.macro.flags), I haven't been able to find it (if there is documentation, it's really well hidden). Ideally I would want to be able to say preproc.macros.flags=-w -x c++ -E -CC -DGIT_SHA=$(git rev-parse HEAD) and have the shell command be executed at the point.
So, before I set out to hack arduino-builder, do people have any opinion on this? My main criterion is something that would be of general value and has a chance of being incorporated in the code, rather than a kludge that only works for me and which I have to patch every time I upgrade. Please do not suggest workarounds. I can think of several myself!
I did try to search, and this sort of issue has come up before, but I didn't see any satisfactory answers from people who knew what they were talking about.
Thanks!
/ji 

user4143: That is a tough one...  Because arduino-builder is basically a custom go script you don't get the facilities you get in a Makefile, like shell execution. 
I would be inclined to do this kind of thing outside that environment - use some external program or tool to generate a config.h file (maybe use something like GNU Autotools) that contains your custom defines. That can then be #included in your sketch.

10024: <p>What I am trying to accomplish is to include information about the state of my environment at build time in my code. For example, I may want the <code>setup()</code> code to print the git sha it was built against, and the time of build. </p>

<p>There are two related issues here:</p>

<ol>
<li>How to include that information in the code</li>
<li>How to specify to the build environment what to generate in the first place.</li>
</ol>

<p>The first can be addressed in a number of ways:</p>

<ul>
<li>-D options can be generated at build time, and the corresponding defined macros expanded in the code. For example, the compiler could be invoked as <code>g++ -DGIT_SHA=$(git rev-parse HEAD) -DDATE=$(date '+%Y%m%d-%H:%M:%S')</code>, and my code could have something like <code>#define strfy(_x) #_x</code> followed by <code>Serial.println(strfy(GIT_SHA));</code>. Or the build tool could generate a header file that would define these as external string variables, which the main sketch could then include and print. Or any other number of tricks.</li>
</ul>

<p>The question I am really asking is: <strong>how should I specify this sort of stuff for <code>arduino-builder</code>?</strong></p>

<p>Ideally, it would be a custom recipe in <code>platform.txt</code>, but if there is a way to invoke shell commands in recipes and use the results to modify other variables (such as <code>preproc.macro.flags</code>), I haven't been able to find it (if there is documentation, it's really well hidden). Ideally I would want to be able to say <code>preproc.macros.flags=-w -x c++ -E -CC -DGIT_SHA=$(git rev-parse HEAD)</code> and have the shell command be executed at the point.</p>

<p>So, before I set out to hack arduino-builder, do people have any opinion on this? My main criterion is something that would be of general value and has a chance of being incorporated in the code, rather than a kludge that only works for me and which I have to patch every time I upgrade. Please do not suggest workarounds. I can think of several myself!</p>

<p>I <em>did</em> try to search, and this sort of issue has come up before, but I didn't see any satisfactory answers from people who knew what they were talking about.</p>

<p>Thanks!</p>

<p>/ji </p>
 4143: <p>That is a tough one...  Because arduino-builder is basically a custom go script you don't get the facilities you get in a Makefile, like shell execution. </p>

<p>I would be inclined to do this kind of thing outside that environment - use some external program or tool to generate a config.h file (maybe use something like GNU Autotools) that contains your custom defines. That can then be #included in your sketch.</p>
