Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide a ${this.__name__} variable (like ${this.__env__} but valid in all sections) #4531

Open
1 task done
nomis opened this issue Jan 26, 2023 · 1 comment
Open
1 task done
Labels
config platformio.ini
Milestone

Comments

@nomis
Copy link
Contributor

nomis commented Jan 26, 2023

What kind of issue is this?

  • Feature Request.

Configuration

PlatformIO Version (platformio --version): 6.1.6

Description of problem

As stated in #4480 (comment), I am using ${this.__env__} to get the environment name in a non-environment section that will later be extended by an environment. This is being rejected as invalid (but it works) so I need the suggested ${this.__name__} to insert the name of the section/environment when the value is being evaluated.

[a]
test_testing_command =
	script.sh
	${platformio.build_dir}/${this.__name__}/test
	${platformio.build_dir}/${this.__name__}/program

[env:b]
extends = a

Where ${this.__name__} is expected to evaluate to b when the test_testing_command is used (this works with ${this.__env__} on 6.1.5).

@nomis
Copy link
Contributor Author

nomis commented Mar 24, 2024

I don't think ${this.__name__} is going to help because I don't want a or env:b, I need b which is the name of the environment. This is the only way to make a custom test_testing_command in a section that is not the final environment.

The ${this.__env__} variable is not returning the current environment being executed, but the environment name implied by the section name where the variable is accessed (which isn't necessarily the section where it's defined).

The only reason this works at all in older versions is because my section names are app:... extended by a single env:... so removing the first 4 characters happens to produce the current environment name.

[app:native_test]
extends = app:native
build_flags =
        ${app:native.build_flags}
        -DUNITY_INCLUDE_PRINT_FORMATTED
test_build_src = true
test_testing_command =
        app/pio/testing-command.sh
        ${platformio.build_dir}/${this.__env__}/test
        ${platformio.build_dir}/${this.__env__}/program

[app:native_test_coverage]
extends = app:native_test
build_flags =
        ${app:native_test.build_flags}
        -fprofile-arcs -ftest-coverage -lgcov --coverage

[env:native_test]
extends = app:native_test

[env:native_test_coverage]
extends = app:native_test_coverage

With v6.1.5, ${this.__env__} is being evaluated as native_test and native_test_coverage because the section names are app:native_test and app:native_test_coverage, even though test_testing_command which uses ${this.__env__} isn't defined in app:native_test_coverage!

This would be a lot easier if the testing command was executed with PIO environment variables (including the program name).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
config platformio.ini
Projects
None yet
Development

No branches or pull requests

2 participants