Src_dir setting using pre-build extra script with latest platformio release

Hi,

I am using Platform IO to build images for teensy and esp32 platforms.
I have multiple targets placed in src folder as:
src ->
teensy1_project
main.c
*.h
teensy2_project
main.c
*.h
I have platorm.ini places at the top level folder pointing to a pre-buld script that used to setup src_dir as follows.
env[‘PROJECTSRC_DIR’] = env[‘PROJECT_DIR’] + “\src\” + env[“PIOENV”]

This used to work until recently, and would pick up the correct project when tried to build individually from Platform IO environment in visual studio code, or I could do build all by clicking platformIO build.

With a latest update to platformIO, sometime last week I think, this project src directory setting no longer seems to work.
As I look for src_dir settings, I can see that there is mention of PLATFORMIO_SRC_DIR that can be set to individual src directory. But I couldn’t find a way to do that from pre-build script. Only the env variables seems to be able to be set in script, not a platformio variable.

I do not really want to use a separate platform.ini for each project. What changes in the latest release has broken this? Is there still a way I can do this through script?

Thanks,
Meena

Hi,

Could any one help with this?

Regards,
Meena

Do you have a downloadable minimal example which reproduces the problem?

Hi,

I have uploaded an example at GitHub - MElanchery/demo_platformio: Platformio examples and demo code.

As you can see in the image attached, when I build env:teensy_board1, it is not just building teensy_board1 environment, other board folders are included as well.
Whatever setting I am doing in adj_src_dir.py doesn’t seem to take effect, this used to work earlier. Build works if I have src_dir setup directly in in [platformio] inside platform.ini. But I want to continue using the same platform.ini for the 3 boards as I have been doing, taking care of src_dir setting from pre-run extra build script.

Thanks,
Meena

It’s your variable name @meena… it should be PROJECT_SRC_DIR, not PROJECTSRC_DIR (note the underscore between PROJECT and SRC).

print(env.Dump()) is your friend :wink:

Thanks to your script, that solves the problem I was having with trying to make it so I could compile examples for a library… and it does it dynamically based on the environment name. Thanks! :slight_smile:

i.e.

Import("env")
env['PROJECT_SRC_DIR'] = env['PROJECT_DIR'] + "\\examples\\" + env["PIOENV"]
print("Setting the project directory to: {}".format(env['PROJECT_SRC_DIR']))

with an environment named after each example folder allows for each example to compiled individually, or all compiled in one go.

Hi,

Thanks, using PROJECT_SRC_DIR worked.
That environment variable change was confusing. When I print(env.Dump()), there also I can see PROJECTSRC_DIR and PROJECT_SRC_DIR.

Thank you for the help.

Regards,
Meena

Hi,

Just wanted to point out that both these environment variables are required to get my esp32 projects to build successfully. I use same folder structure as I have in my teensy projects for esp32 board also.

By setting only PROJECT_SRC_DIR, ESP32 build was not picking up the right sdkconfig.h from individual project src folder. It was trying to pick the file from src folder directly though I had sdkconfig.h files separately in src/esp32_board1 folder.

Since I saw PROJECTSRC_DIR also in the environment dump file pointing to src folder, I decided to change that also in my script to be same as PROJECT_SRC_DIR. By doing that, the build is picking up sdkconfig.h from the right folder.

So it seems both environment variables are being used, is this intentional or is subject to change in later releases?

Thanks,
Meena

It seems PROJECTSRC_DIR is legacy, but is still in use in the espressif32 platform scripts.

Strangely, neither the atmelavr or teensy platforms seem to reference either form, but still seems to have the desired effect.

Hi,

Thanks for confirmation. Yeah, it is strange if teensy platform is not directly referencing it. I hope future versions will not have a change in behavior.

Thanks,
Meena

Well, please don’t hate me then… I’ve submitted a PR for the espressif32 platform package , to change PROJECTSRC_DIR to PROJECT_SRC_DIR since it’s supposed to be a legacy variable… and if that’s accepted, I’ll check out all the other platform packages and fix them too for consistency… betcha it’s the only one though! :laughing:

Thanks for following it through.

Meena

1 Like