mirror of
https://github.com/platformio/platformio-core.git
synced 2025-07-30 10:07:14 +02:00
Fix issue when handling dynamic variables
This commit is contained in:
@ -80,7 +80,7 @@ class ProjectConfig(object):
|
|||||||
def items(self, section):
|
def items(self, section):
|
||||||
items = []
|
items = []
|
||||||
for option in self._parser.options(section):
|
for option in self._parser.options(section):
|
||||||
items.append((option, self._parser.get(section, option)))
|
items.append((option, self.get(section, option)))
|
||||||
return items
|
return items
|
||||||
|
|
||||||
def get(self, section, option):
|
def get(self, section, option):
|
||||||
@ -95,7 +95,7 @@ class ProjectConfig(object):
|
|||||||
def _re_sub_handler(self, match):
|
def _re_sub_handler(self, match):
|
||||||
section, option = match.group(1), match.group(2)
|
section, option = match.group(1), match.group(2)
|
||||||
if section in ("env",
|
if section in ("env",
|
||||||
"sysenv") and not self._parser.has_section(section):
|
"sysenv") and not self.has_section(section):
|
||||||
if section == "env":
|
if section == "env":
|
||||||
click.secho(
|
click.secho(
|
||||||
"Warning! Access to system environment variable via "
|
"Warning! Access to system environment variable via "
|
||||||
@ -103,4 +103,4 @@ class ProjectConfig(object):
|
|||||||
"`${{sysenv.{0}}}` instead".format(option),
|
"`${{sysenv.{0}}}` instead".format(option),
|
||||||
fg="yellow")
|
fg="yellow")
|
||||||
return os.getenv(option)
|
return os.getenv(option)
|
||||||
return self._parser.get(section, option)
|
return self.get(section, option)
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
|
import os
|
||||||
from platformio.project.config import ProjectConfig
|
from platformio.project.config import ProjectConfig
|
||||||
|
|
||||||
BASE_CONFIG = """
|
BASE_CONFIG = """
|
||||||
@ -23,12 +24,13 @@ extra_configs =
|
|||||||
[common]
|
[common]
|
||||||
debug_flags = -D RELEASE
|
debug_flags = -D RELEASE
|
||||||
lib_flags = -lc -lm
|
lib_flags = -lc -lm
|
||||||
|
extra_flags = ${sysenv.__PIO_TEST_CNF_EXTRA_FLAGS}
|
||||||
|
|
||||||
[env:esp-wrover-kit]
|
[env:esp-wrover-kit]
|
||||||
platform = espressif32
|
platform = espressif32
|
||||||
framework = espidf
|
framework = espidf
|
||||||
board = esp-wrover-kit
|
board = esp-wrover-kit
|
||||||
build_flags = ${common.debug_flags}
|
build_flags = ${common.debug_flags} ${common.extra_flags}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
EXTRA_ENVS_CONFIG = """
|
EXTRA_ENVS_CONFIG = """
|
||||||
@ -42,7 +44,7 @@ build_flags = ${common.lib_flags} ${common.debug_flags}
|
|||||||
platform = espressif32
|
platform = espressif32
|
||||||
framework = espidf
|
framework = espidf
|
||||||
board = lolin32
|
board = lolin32
|
||||||
build_flags = ${common.debug_flags}
|
build_flags = ${common.debug_flags} ${common.extra_flags}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
EXTRA_DEBUG_CONFIG = """
|
EXTRA_DEBUG_CONFIG = """
|
||||||
@ -65,10 +67,27 @@ def test_parser(tmpdir):
|
|||||||
config = ProjectConfig(tmpdir.join("platformio.ini").strpath)
|
config = ProjectConfig(tmpdir.join("platformio.ini").strpath)
|
||||||
assert config
|
assert config
|
||||||
|
|
||||||
|
# sections
|
||||||
assert config.sections() == [
|
assert config.sections() == [
|
||||||
"platformio", "common", "env:esp-wrover-kit", "env:esp32dev",
|
"platformio", "common", "env:esp-wrover-kit", "env:esp32dev",
|
||||||
"env:lolin32"
|
"env:lolin32"
|
||||||
]
|
]
|
||||||
|
|
||||||
|
# sysenv
|
||||||
|
assert config.get("common", "extra_flags") == ""
|
||||||
|
os.environ["__PIO_TEST_CNF_EXTRA_FLAGS"] = "-L /usr/local/lib"
|
||||||
|
assert config.get("common", "extra_flags") == "-L /usr/local/lib"
|
||||||
|
|
||||||
|
# get
|
||||||
assert config.get("common", "debug_flags") == "-D DEBUG=1"
|
assert config.get("common", "debug_flags") == "-D DEBUG=1"
|
||||||
assert config.get("env:esp32dev", "build_flags") == "-lc -lm -D DEBUG=1"
|
assert config.get("env:esp32dev", "build_flags") == "-lc -lm -D DEBUG=1"
|
||||||
assert config.get("env:lolin32", "build_flags") == "-Og"
|
assert config.get("env:lolin32", "build_flags") == "-Og"
|
||||||
|
assert config.get("env:esp-wrover-kit",
|
||||||
|
"build_flags") == ("-D DEBUG=1 -L /usr/local/lib")
|
||||||
|
|
||||||
|
# items
|
||||||
|
assert config.items("env:esp32dev") == [("platform", "espressif32"),
|
||||||
|
("framework", "espidf"),
|
||||||
|
("board", "esp32dev"),
|
||||||
|
("build_flags",
|
||||||
|
"-lc -lm -D DEBUG=1")]
|
||||||
|
Reference in New Issue
Block a user