mirror of
https://github.com/platformio/platformio-core.git
synced 2025-07-30 01:57:13 +02:00
Improved support for the renamed configuration options // Resolve #4270
This commit is contained in:
@ -14,6 +14,7 @@ PlatformIO Core 6
|
|||||||
6.0.1 (2022-05-??)
|
6.0.1 (2022-05-??)
|
||||||
~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
* Improved support for the renamed configuration options (`issue #4270 <https://github.com/platformio/platformio-core/issues/4270>`_)
|
||||||
* Fixed an issue when calling built-in `pio device monitor <https://docs.platformio.org/en/latest/core/userguide/device/cmd_monitor.html#filters>`__ filter
|
* Fixed an issue when calling built-in `pio device monitor <https://docs.platformio.org/en/latest/core/userguide/device/cmd_monitor.html#filters>`__ filter
|
||||||
|
|
||||||
6.0.0 (2022-05-16)
|
6.0.0 (2022-05-16)
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
|
|
||||||
from platformio.compat import MISSING
|
from platformio.compat import MISSING
|
||||||
from platformio.project.config import ProjectConfig, ProjectOptions
|
from platformio.project.config import ProjectConfig
|
||||||
|
|
||||||
|
|
||||||
def GetProjectConfig(env):
|
def GetProjectConfig(env):
|
||||||
@ -31,15 +31,17 @@ def GetProjectOption(env, option, default=MISSING):
|
|||||||
|
|
||||||
|
|
||||||
def LoadProjectOptions(env):
|
def LoadProjectOptions(env):
|
||||||
for option, value in env.GetProjectOptions():
|
config = env.GetProjectConfig()
|
||||||
option_meta = ProjectOptions.get("env." + option)
|
section = "env:" + env["PIOENV"]
|
||||||
|
for option in config.options(section):
|
||||||
|
option_meta = config.find_option_meta(section, option)
|
||||||
if (
|
if (
|
||||||
not option_meta
|
not option_meta
|
||||||
or not option_meta.buildenvvar
|
or not option_meta.buildenvvar
|
||||||
or option_meta.buildenvvar in env
|
or option_meta.buildenvvar in env
|
||||||
):
|
):
|
||||||
continue
|
continue
|
||||||
env[option_meta.buildenvvar] = value
|
env[option_meta.buildenvvar] = config.get(section, option)
|
||||||
|
|
||||||
|
|
||||||
def exists(_):
|
def exists(_):
|
||||||
|
@ -43,6 +43,8 @@ class ProjectConfigBase(object):
|
|||||||
INLINE_COMMENT_RE = re.compile(r"\s+;.*$")
|
INLINE_COMMENT_RE = re.compile(r"\s+;.*$")
|
||||||
VARTPL_RE = re.compile(r"\$\{([^\.\}\()]+)\.([^\}]+)\}")
|
VARTPL_RE = re.compile(r"\$\{([^\.\}\()]+)\.([^\}]+)\}")
|
||||||
|
|
||||||
|
CUSTOM_OPTION_PREFIXES = ("custom_", "board_")
|
||||||
|
|
||||||
expand_interpolations = True
|
expand_interpolations = True
|
||||||
warnings = []
|
warnings = []
|
||||||
|
|
||||||
@ -109,23 +111,6 @@ class ProjectConfigBase(object):
|
|||||||
self.read(item)
|
self.read(item)
|
||||||
|
|
||||||
def _maintain_renaimed_options(self):
|
def _maintain_renaimed_options(self):
|
||||||
# legacy `lib_extra_dirs` in [platformio]
|
|
||||||
if self._parser.has_section("platformio") and self._parser.has_option(
|
|
||||||
"platformio", "lib_extra_dirs"
|
|
||||||
):
|
|
||||||
if not self._parser.has_section("env"):
|
|
||||||
self._parser.add_section("env")
|
|
||||||
self._parser.set(
|
|
||||||
"env",
|
|
||||||
"lib_extra_dirs",
|
|
||||||
self._parser.get("platformio", "lib_extra_dirs"),
|
|
||||||
)
|
|
||||||
self._parser.remove_option("platformio", "lib_extra_dirs")
|
|
||||||
self.warnings.append(
|
|
||||||
"`lib_extra_dirs` configuration option is deprecated in "
|
|
||||||
"section [platformio]! Please move it to global `env` section"
|
|
||||||
)
|
|
||||||
|
|
||||||
renamed_options = {}
|
renamed_options = {}
|
||||||
for option in ProjectOptions.values():
|
for option in ProjectOptions.values():
|
||||||
if option.oldnames:
|
if option.oldnames:
|
||||||
@ -143,19 +128,20 @@ class ProjectConfigBase(object):
|
|||||||
"Please use `%s` instead"
|
"Please use `%s` instead"
|
||||||
% (option, section, renamed_options[option])
|
% (option, section, renamed_options[option])
|
||||||
)
|
)
|
||||||
# rename on-the-fly
|
# # rename on-the-fly
|
||||||
self._parser.set(
|
# self._parser.set(
|
||||||
section,
|
# section,
|
||||||
renamed_options[option],
|
# renamed_options[option],
|
||||||
self._parser.get(section, option),
|
# self._parser.get(section, option),
|
||||||
)
|
# )
|
||||||
self._parser.remove_option(section, option)
|
# self._parser.remove_option(section, option)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# unknown
|
# unknown
|
||||||
unknown_conditions = [
|
unknown_conditions = [
|
||||||
("%s.%s" % (scope, option)) not in ProjectOptions,
|
("%s.%s" % (scope, option)) not in ProjectOptions,
|
||||||
scope != "env" or not option.startswith(("custom_", "board_")),
|
scope != "env"
|
||||||
|
or not option.startswith(self.CUSTOM_OPTION_PREFIXES),
|
||||||
]
|
]
|
||||||
if all(unknown_conditions):
|
if all(unknown_conditions):
|
||||||
self.warnings.append(
|
self.warnings.append(
|
||||||
@ -237,16 +223,7 @@ class ProjectConfigBase(object):
|
|||||||
value = "\n" + value
|
value = "\n" + value
|
||||||
self._parser.set(section, option, value)
|
self._parser.set(section, option, value)
|
||||||
|
|
||||||
def getraw(self, section, option, default=MISSING):
|
def resolve_renamed_option(self, section, old_name):
|
||||||
try:
|
|
||||||
return self._getraw(section, option, default)
|
|
||||||
except configparser.NoOptionError as exc:
|
|
||||||
renamed_option = self._resolve_renamed_option(section, option)
|
|
||||||
if renamed_option:
|
|
||||||
return self._getraw(section, renamed_option, default)
|
|
||||||
raise exc
|
|
||||||
|
|
||||||
def _resolve_renamed_option(self, section, old_name):
|
|
||||||
scope = self.get_section_scope(section)
|
scope = self.get_section_scope(section)
|
||||||
if scope not in ("platformio", "env"):
|
if scope not in ("platformio", "env"):
|
||||||
return None
|
return None
|
||||||
@ -259,19 +236,39 @@ class ProjectConfigBase(object):
|
|||||||
return option_meta.name
|
return option_meta.name
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def _getraw(self, section, option, default): # pylint: disable=too-many-branches
|
def find_option_meta(self, section, option):
|
||||||
|
scope = self.get_section_scope(section)
|
||||||
|
if scope not in ("platformio", "env"):
|
||||||
|
return None
|
||||||
|
option_meta = ProjectOptions.get("%s.%s" % (scope, option))
|
||||||
|
if option_meta:
|
||||||
|
return option_meta
|
||||||
|
for option_meta in ProjectOptions.values():
|
||||||
|
if option_meta.scope == scope and option in (option_meta.oldnames or []):
|
||||||
|
return option_meta
|
||||||
|
return None
|
||||||
|
|
||||||
|
def _traverse_for_value(self, section, option, option_meta=None):
|
||||||
|
for _section, _option in self.walk_options(section):
|
||||||
|
if _option == option or (
|
||||||
|
option_meta
|
||||||
|
and (
|
||||||
|
option_meta.name == _option
|
||||||
|
or _option in (option_meta.oldnames or [])
|
||||||
|
)
|
||||||
|
):
|
||||||
|
return self._parser.get(_section, _option)
|
||||||
|
return MISSING
|
||||||
|
|
||||||
|
def getraw(
|
||||||
|
self, section, option, default=MISSING
|
||||||
|
): # pylint: disable=too-many-branches
|
||||||
if not self.expand_interpolations:
|
if not self.expand_interpolations:
|
||||||
return self._parser.get(section, option)
|
return self._parser.get(section, option)
|
||||||
|
|
||||||
value = MISSING
|
option_meta = self.find_option_meta(section, option)
|
||||||
for sec, opt in self.walk_options(section):
|
value = self._traverse_for_value(section, option, option_meta)
|
||||||
if opt == option:
|
|
||||||
value = self._parser.get(sec, option)
|
|
||||||
break
|
|
||||||
|
|
||||||
option_meta = ProjectOptions.get(
|
|
||||||
"%s.%s" % (self.get_section_scope(section), option)
|
|
||||||
)
|
|
||||||
if not option_meta:
|
if not option_meta:
|
||||||
if value == MISSING:
|
if value == MISSING:
|
||||||
value = (
|
value = (
|
||||||
@ -342,9 +339,7 @@ class ProjectConfigBase(object):
|
|||||||
except configparser.Error as e:
|
except configparser.Error as e:
|
||||||
raise exception.InvalidProjectConfError(self.path, str(e))
|
raise exception.InvalidProjectConfError(self.path, str(e))
|
||||||
|
|
||||||
option_meta = ProjectOptions.get(
|
option_meta = self.find_option_meta(section, option)
|
||||||
"%s.%s" % (self.get_section_scope(section), option)
|
|
||||||
)
|
|
||||||
if not option_meta:
|
if not option_meta:
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
@ -101,9 +101,13 @@ debug_flags = -D DEBUG=1
|
|||||||
debug_server =
|
debug_server =
|
||||||
${platformio.packages_dir}/tool-openocd/openocd
|
${platformio.packages_dir}/tool-openocd/openocd
|
||||||
--help
|
--help
|
||||||
|
src_filter = -<*>
|
||||||
|
+<a>
|
||||||
|
+<b>
|
||||||
|
|
||||||
[env:extra_2]
|
[env:extra_2]
|
||||||
build_flags = -Og
|
build_flags = -Og
|
||||||
|
src_filter = ${custom.src_filter} +<c>
|
||||||
"""
|
"""
|
||||||
|
|
||||||
DEFAULT_CORE_DIR = os.path.join(fs.expanduser("~"), ".platformio")
|
DEFAULT_CORE_DIR = os.path.join(fs.expanduser("~"), ".platformio")
|
||||||
@ -130,7 +134,7 @@ def test_empty_config():
|
|||||||
|
|
||||||
def test_warnings(config):
|
def test_warnings(config):
|
||||||
config.validate(["extra_2", "base"], silent=True)
|
config.validate(["extra_2", "base"], silent=True)
|
||||||
assert len(config.warnings) == 2
|
assert len(config.warnings) == 3
|
||||||
assert "lib_install" in config.warnings[1]
|
assert "lib_install" in config.warnings[1]
|
||||||
|
|
||||||
with pytest.raises(UnknownEnvNamesError):
|
with pytest.raises(UnknownEnvNamesError):
|
||||||
@ -213,8 +217,9 @@ def test_options(config):
|
|||||||
def test_has_option(config):
|
def test_has_option(config):
|
||||||
assert config.has_option("env:base", "monitor_speed")
|
assert config.has_option("env:base", "monitor_speed")
|
||||||
assert not config.has_option("custom", "monitor_speed")
|
assert not config.has_option("custom", "monitor_speed")
|
||||||
assert not config.has_option("env:extra_1", "lib_install")
|
assert config.has_option("env:extra_1", "lib_install")
|
||||||
assert config.has_option("env:test_extends", "lib_compat_mode")
|
assert config.has_option("env:test_extends", "lib_compat_mode")
|
||||||
|
assert config.has_option("env:extra_2", "src_filter")
|
||||||
|
|
||||||
|
|
||||||
def test_sysenv_options(config):
|
def test_sysenv_options(config):
|
||||||
@ -312,6 +317,8 @@ def test_getraw_value(config):
|
|||||||
assert config.getraw("platformio", "build_dir") == "~/tmp/pio-$PROJECT_HASH"
|
assert config.getraw("platformio", "build_dir") == "~/tmp/pio-$PROJECT_HASH"
|
||||||
|
|
||||||
# renamed option
|
# renamed option
|
||||||
|
assert config.getraw("env:extra_1", "lib_install") == "574"
|
||||||
|
assert config.getraw("env:extra_1", "lib_deps") == "574"
|
||||||
assert config.getraw("env:base", "debug_load_cmd") == ["load"]
|
assert config.getraw("env:base", "debug_load_cmd") == ["load"]
|
||||||
|
|
||||||
|
|
||||||
@ -349,6 +356,11 @@ def test_get_value(config):
|
|||||||
)
|
)
|
||||||
assert "$PROJECT_HASH" not in config.get("platformio", "build_dir")
|
assert "$PROJECT_HASH" not in config.get("platformio", "build_dir")
|
||||||
|
|
||||||
|
# renamed option
|
||||||
|
assert config.get("env:extra_1", "lib_install") == ["574"]
|
||||||
|
assert config.get("env:extra_1", "lib_deps") == ["574"]
|
||||||
|
assert config.get("env:base", "debug_load_cmd") == ["load"]
|
||||||
|
|
||||||
|
|
||||||
def test_items(config):
|
def test_items(config):
|
||||||
assert config.items("custom") == [
|
assert config.items("custom") == [
|
||||||
@ -363,6 +375,7 @@ def test_items(config):
|
|||||||
"\n%s/tool-openocd/openocd\n--help"
|
"\n%s/tool-openocd/openocd\n--help"
|
||||||
% os.path.join(DEFAULT_CORE_DIR, "packages"),
|
% os.path.join(DEFAULT_CORE_DIR, "packages"),
|
||||||
),
|
),
|
||||||
|
("src_filter", "-<*>\n+<a>\n+<b>"),
|
||||||
]
|
]
|
||||||
assert config.items(env="base") == [
|
assert config.items(env="base") == [
|
||||||
("build_flags", ["-D DEBUG=1"]),
|
("build_flags", ["-D DEBUG=1"]),
|
||||||
@ -379,9 +392,10 @@ def test_items(config):
|
|||||||
"build_flags",
|
"build_flags",
|
||||||
["-fdata-sections", "-Wl,--gc-sections", "-lc -lm", "-D DEBUG=1"],
|
["-fdata-sections", "-Wl,--gc-sections", "-lc -lm", "-D DEBUG=1"],
|
||||||
),
|
),
|
||||||
("lib_deps", ["574"]),
|
("lib_install", ["574"]),
|
||||||
("monitor_speed", 9600),
|
("monitor_speed", 9600),
|
||||||
("custom_monitor_speed", "115200"),
|
("custom_monitor_speed", "115200"),
|
||||||
|
("lib_deps", ["574"]),
|
||||||
("lib_ignore", ["LibIgnoreCustom"]),
|
("lib_ignore", ["LibIgnoreCustom"]),
|
||||||
("custom_builtin_option", "release"),
|
("custom_builtin_option", "release"),
|
||||||
]
|
]
|
||||||
@ -396,6 +410,7 @@ def test_items(config):
|
|||||||
"--help",
|
"--help",
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
("src_filter", ["-<*>", "+<a>", "+<b> +<c>"]),
|
||||||
("monitor_speed", 9600),
|
("monitor_speed", 9600),
|
||||||
("custom_monitor_speed", "115200"),
|
("custom_monitor_speed", "115200"),
|
||||||
("lib_deps", ["Lib1", "Lib2"]),
|
("lib_deps", ["Lib1", "Lib2"]),
|
||||||
@ -496,10 +511,10 @@ def test_dump(tmpdir_factory):
|
|||||||
(
|
(
|
||||||
"platformio",
|
"platformio",
|
||||||
[
|
[
|
||||||
|
("env_default", ["base", "extra_2"]),
|
||||||
("src_dir", "${custom.src_dir}"),
|
("src_dir", "${custom.src_dir}"),
|
||||||
("build_dir", "${custom.build_dir}"),
|
("build_dir", "${custom.build_dir}"),
|
||||||
("extra_configs", ["extra_envs.ini", "extra_debug.ini"]),
|
("extra_configs", ["extra_envs.ini", "extra_debug.ini"]),
|
||||||
("default_envs", ["base", "extra_2"]),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
|
Reference in New Issue
Block a user