Open jerabaul29 opened 1 year ago
You can solve this issue with:
Also, the list of built-in variables, where you can find $UNIX_TIME
. Please note that adding $UNIX_TIME
to the build flags will trigger PlatformIO Build System to recompile the project from scratch. The value changes every second...
Many thanks for the pointers @ivankravets :) . Yes, I remembered about these resources (or some older version of them), and I was aware that this can be used to solve the need :) .
I guess my point would be that it would be easier on the user to provide a list of default, readily implemented, turn key flags that are commonly used, so that the user does not need to set it up themselves but can just write a few words in the ini file. At least for some of the users I work with, who have no background in embedded from before / maybe know a tiny bit of C but no python / are not used to automation, it would be very helpful :) .
(and even for advanced users, it would be faster than reading the full doc, writing and testing the script, etc :) ).
We agree with you. This is the reason why we marked this issue as a feature request. The flags/values which you requests can't be implemented as build variables because it will need to provide the initial computation of these vars. It will increase building time. But! It is possible to call functions within the SCons template. For example
[env]
build_flags =
'-D GIT_BRANCH=${fetch_git_branch()}'
In this case, we will fetch the value by demand.
I often end up having snippets like this in my platformio.ini files:
This works perfectly fine for me. The only "issue" is that, as you can see, I am on linux, and I have set this in a way that will not work in windows / possibly mac. I do not want to myself do some work to make things platform agnostic (I do not have access to a windows machine to test for example), but still it would be really convenient for my users if things were platform agnostic.
Hence my question: would it be possible to provide, from platformio-core "natively", some sets of "pre_defined_flags" that could be enabled to provide some typical, often needed, build flags?
For example something like:
I guess this would mean:
I.e. when building such a project, the flag
COMMIT_ID
containing the commit id would be visible, but the flagCOMPILE_UNIX_TIMESTAMP
would not.As a small note / to help macro n00bs like me, it can be useful in documentation to remind that, to use all any of these flags, what is needed in the program is then: