Interesting pull request to add build options

What could be included in further releases, or for the forum.
User avatar
Rick Kimball
Posts: 1078
Joined: Tue Apr 28, 2015 1:26 am
Location: Eastern NC, US
Contact:

Interesting pull request to add build options

Post by Rick Kimball » Mon Dec 11, 2017 5:20 pm

The STM32 guys have added an interesting pull to their core. It lets you add a build_opt.h to your sketch files. That file is then used as the @ file on the command line. This lets you override defines in the core things like F_CPU etc before any includes. With the libmaple core this approach might be a simple way to control the -DSERIAL_USB or the-DCONFIG_MAPLE_MINI_NO_DISABLE_DEBUG flag from a user sketch instead of at the board level. Useful for flags you might want to add the boards.txt file but you skip it because you don't want to disrupt every sketch.

https://github.com/stm32duino/Arduino_C ... 2/pull/174

This change came out of a questions someone else had about the STM32 core and I proposed a solution however I didn't really implement it. I just suggested an approach that might work. Fred has taken the idea and realized it quite nicely.

https://github.com/stm32duino/Arduino_C ... /issues/41

This might be something to think about for the libmaple core.
-rick

stevestrong
Posts: 2070
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany
Contact:

Re: Interesting pull request to add build options

Post by stevestrong » Mon Dec 11, 2017 5:59 pm

+5 :mrgreen:
but only if it does not break anything in the existing build process.

zmemw16
Posts: 1685
Joined: Wed Jul 08, 2015 2:09 pm
Location: St Annes, Lancs,UK

Re: Interesting pull request to add build options

Post by zmemw16 » Mon Dec 11, 2017 7:30 pm

bricks built on bricks built on bricks, the trick is to realise when to put the roof on +5
srp

User avatar
RogerClark
Posts: 7693
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: Interesting pull request to add build options

Post by RogerClark » Mon Dec 11, 2017 7:43 pm

Thanks Rick

that’s very interesting

What happens if the file is not present ?
According to the PR, it gets created if it’s not present, but I could not see what created it.

It’s certsinly a very powerful feature, and would resolve a number of problems, which require defines to be added to the build

Do you know if libraries can supply this file or whether it’s only the main sketch ? ( because I know the IDE does strange things like copying various files to a temp directory to compile them, I wonder if this file put inside a library could end up in the temp build directory

User avatar
RogerClark
Posts: 7693
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: Interesting pull request to add build options

Post by RogerClark » Mon Dec 11, 2017 7:52 pm

Rick

I read the other link, and I can see how you propose to create the file using another external script, but I don’t see that script in STMs change.

Perhaps they are using the feature for some other purpose?

User avatar
RogerClark
Posts: 7693
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: Interesting pull request to add build options

Post by RogerClark » Mon Dec 11, 2017 8:14 pm

Sorry.. but here is another question

Can the recipe hooks have different scripts on different platforms ?

It would need to support the same sort of system which the upload recipies use.
I presume the Arduino team implemented this

User avatar
Rick Kimball
Posts: 1078
Joined: Tue Apr 28, 2015 1:26 am
Location: Eastern NC, US
Contact:

Re: Interesting pull request to add build options

Post by Rick Kimball » Mon Dec 11, 2017 8:58 pm

RogerClark wrote:
Mon Dec 11, 2017 7:52 pm
I read the other link, and I can see how you propose to create the file using another external script, but I don’t see that script in STMs change.
RogerClark wrote:
Mon Dec 11, 2017 8:14 pm
Sorry.. but here is another question
Can the recipe hooks have different scripts on different platforms ?
He takes care of both of your questions with what he is doing here:
+# Pre and post build hooks
+recipe.hooks.prebuild.1.pattern.windows=cmd /c "if not exist {build.path}\sketch\build_opt.h mkdir {build.path}\sketch & type NUL > {build.path}\sketch\build_opt.h"
+recipe.hooks.prebuild.1.pattern.linux=bash -c "[ -f {build.path}/sketch/build_opt.h ] || mkdir -p {build.path}/sketch && touch {build.path}/sketch/build_opt.h"
+recipe.hooks.prebuild.1.pattern.macosx=bash -c "[ -f {build.path}/sketch/build_opt.h ] || mkdir -p {build.path}/sketch && touch {build.path}/sketch/build_opt.h"
He uses the file called build_opt.h instead of the file I proposed. I used a txt file but that is not something you can add as a new tab in the Arduino IDE. You can add a .h file though and that is what he looks for. He checks to see if the sketch has that file using the recipe hooks above. If the file doesn't exists, he uses the target platform to create an empty build_opt.h ... using 'type NULL >build_opt.h" on windows and "touch > build_opt.h" on linux and osx'
-rick

User avatar
Rick Kimball
Posts: 1078
Joined: Tue Apr 28, 2015 1:26 am
Location: Eastern NC, US
Contact:

Re: Interesting pull request to add build options

Post by Rick Kimball » Mon Dec 11, 2017 9:09 pm

stevestrong wrote:
Mon Dec 11, 2017 5:59 pm
+5 :mrgreen:
but only if it does not break anything in the existing build process.
Absolutely!

My response to this stemmed from another stm32duino Core PR request that was hacking up the boards.txt file to deal with sketch level configuration that can't be done easily. I've not kept the modification I made to test this out. It was more an experiment to see if what I was going to propose would work.

This change is kind of out there as far as Arduino IDE platform mods go. I personally think the Arduino IDE needs a way to make command line define changes on a per sketch basis. It doesn't offer a native solution. This is just working within their bounds to try and get something that might work. It is unlikely this approach will get buy in from the official Arduino platforms. This is the main reason I didn't even suggest this as a github issue or pull. Just something to ponder.
-rick

User avatar
RogerClark
Posts: 7693
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: Interesting pull request to add build options

Post by RogerClark » Mon Dec 11, 2017 9:53 pm

Hi Rick

I don't see any problems with adding this, because if no build_opt is specified, it should make no difference

The .txt vs .h, its a shame the IDE can't support .txt because I agree its not ideal calling it .h, but its probably better than the other naming options that are available

fpiSTM
Posts: 320
Joined: Fri Sep 16, 2016 12:33 pm
Location: Le Mans, France

Re: Interesting pull request to add build options

Post by fpiSTM » Tue Dec 12, 2017 5:17 am

Thanks Rick. ;)
RogerClark wrote:
Mon Dec 11, 2017 7:43 pm
Do you know if libraries can supply this file or whether it’s only the main sketch ? ( because I know the IDE does strange things like copying various files to a temp directory to compile them, I wonder if this file put inside a library could end up in the temp build directory
I will check that Roger.
RogerClark wrote:
Mon Dec 11, 2017 9:53 pm
I don't see any problems with adding this, because if no build_opt is specified, it should make no difference
Right, that's the goal.
RogerClark wrote:
Mon Dec 11, 2017 9:53 pm
The .txt vs .h, its a shame the IDE can't support .txt because I agree its not ideal calling it .h, but its probably better than the other naming options that are available
About .h extensions, it is to avoid creating scripts for each OS and be able to open it with the IDE (which copy it automatically in {build.path}/sketch folder at the start of build).

They are several pre and post build hooks which can be useful:
https://github.com/arduino/Arduino/wiki ... ce-ide-165

Note: I do not test it for Mac OS, if someone could test.

Post Reply