Fix issue with nested interpolation

This commit is contained in:
Ivan Kravets
2022-05-04 14:52:11 +03:00
parent 38906478d3
commit 653f22f85b
2 changed files with 24 additions and 1 deletions

View File

@ -300,7 +300,7 @@ class ProjectConfigBase(object):
return parent_section[4:]
# handle nested calls
try:
value = self.getraw(section, option)
value = self.get(section, option)
except RecursionError:
raise exception.ProjectOptionValueError(
"Infinite recursion has been detected", option, section

View File

@ -343,6 +343,7 @@ def test_get_value(config):
assert config.get("platformio", "src_dir") == os.path.abspath(
os.path.join(os.getcwd(), "source")
)
assert "$PROJECT_HASH" not in config.get("platformio", "build_dir")
def test_items(config):
@ -597,3 +598,25 @@ custom_option = ${this.board}
config = ProjectConfig(str(project_conf))
assert config.get("env:myenv", "custom_option") == "uno"
assert config.get("env:myenv", "build_flags") == ["-Dmyenv"]
def test_nested_interpolation(tmp_path: Path):
project_conf = tmp_path / "platformio.ini"
project_conf.write_text(
"""
[platformio]
build_dir = ~/tmp/pio-$PROJECT_HASH
[env:myenv]
test_testing_command =
${platformio.packages_dir}/tool-simavr/bin/simavr
-m
atmega328p
-f
16000000L
${platformio.build_dir}/${this.__env__}/firmware.elf
"""
)
config = ProjectConfig(str(project_conf))
testing_command = config.get("env:myenv", "test_testing_command")
assert "$" not in " ".join(testing_command)