Fixed an issue when referencing "*_dir" option from a custom project configuration environment // Resolve #4110

This commit is contained in:
Ivan Kravets
2021-12-02 14:19:54 +02:00
parent e40b251c06
commit 014090c407
4 changed files with 26 additions and 14 deletions

View File

@ -16,7 +16,8 @@ PlatformIO Core 5
- Upgraded build engine to the SCons 4.3 (`release notes <https://github.com/SCons/scons/blob/rel_4.3.0/CHANGES.txt>`__) - Upgraded build engine to the SCons 4.3 (`release notes <https://github.com/SCons/scons/blob/rel_4.3.0/CHANGES.txt>`__)
- Fixed an issue with the CLion project generator when a macro contains a space (`issue #4102 <https://github.com/platformio/platformio-core/issues/4102>`_) - Fixed an issue with the CLion project generator when a macro contains a space (`issue #4102 <https://github.com/platformio/platformio-core/issues/4102>`_)
- Fixed an issue with the NetBeans project generator when the path to PlatformIO contains a space (`issue #4096 <https://github.com/platformio/platformio-core/issues/4096>`_) - Fixed an issue with the NetBeans project generator when the path to PlatformIO contains a space (`issue #4096 <https://github.com/platformio/platformio-core/issues/4096>`_)
- Fixed a bug when the system environment variable does not override a project configuration option (`issue #4125 <https://github.com/platformio/platformio-core/issues/4125>`_) - Fixed an issue when the system environment variable does not override a project configuration option (`issue #4125 <https://github.com/platformio/platformio-core/issues/4125>`_)
- Fixed an issue when referencing "*_dir" option from a custom project configuration environment (`issue #4110 <https://github.com/platformio/platformio-core/issues/4110>`_)
5.2.3 (2021-11-05) 5.2.3 (2021-11-05)
~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~

View File

@ -279,9 +279,6 @@ class ProjectConfigBase(object):
if value == MISSING: if value == MISSING:
return None return None
if option_meta.validate:
value = option_meta.validate(value)
return self._expand_interpolations(value) return self._expand_interpolations(value)
def _expand_interpolations(self, value): def _expand_interpolations(self, value):
@ -318,6 +315,8 @@ class ProjectConfigBase(object):
if not option_meta: if not option_meta:
return value return value
if option_meta.validate:
value = option_meta.validate(value)
if option_meta.multiple: if option_meta.multiple:
value = self.parse_multi_values(value or []) value = self.parse_multi_values(value or [])
try: try:

View File

@ -117,14 +117,13 @@ def validate_dir(path):
return fs.normalize_path(path) return fs.normalize_path(path)
def validate_core_dir(path): def get_default_core_dir():
default_dir = ProjectOptions["platformio.core_dir"].default path = os.path.join(fs.expanduser("~"), ".platformio")
win_core_dir = None if IS_WINDOWS:
if IS_WINDOWS and path == default_dir:
win_core_dir = os.path.splitdrive(path)[0] + "\\.platformio" win_core_dir = os.path.splitdrive(path)[0] + "\\.platformio"
if os.path.isdir(win_core_dir): if os.path.isdir(win_core_dir):
path = win_core_dir return win_core_dir
return validate_dir(path) return path
ProjectOptions = OrderedDict( ProjectOptions = OrderedDict(
@ -169,8 +168,8 @@ ProjectOptions = OrderedDict(
), ),
oldnames=["home_dir"], oldnames=["home_dir"],
sysenvvar="PLATFORMIO_CORE_DIR", sysenvvar="PLATFORMIO_CORE_DIR",
default=os.path.join(fs.expanduser("~"), ".platformio"), default=get_default_core_dir(),
validate=validate_core_dir, validate=validate_dir,
), ),
ConfigPlatformioOption( ConfigPlatformioOption(
group="directory", group="directory",

View File

@ -26,7 +26,8 @@ from platformio.project.exception import InvalidProjectConfError, UnknownEnvName
BASE_CONFIG = """ BASE_CONFIG = """
[platformio] [platformio]
env_default = base, extra_2 env_default = base, extra_2
build_dir = ~/tmp/pio-$PROJECT_HASH src_dir = ${custom.src_dir}
build_dir = ${custom.build_dir}
extra_configs = extra_configs =
extra_envs.ini extra_envs.ini
extra_debug.ini extra_debug.ini
@ -53,6 +54,8 @@ extends = strict_ldf, monitor_custom
build_flags = -D RELEASE build_flags = -D RELEASE
[custom] [custom]
src_dir = source
build_dir = ~/tmp/pio-$PROJECT_HASH
debug_flags = -D RELEASE debug_flags = -D RELEASE
lib_flags = -lc -lm lib_flags = -lc -lm
extra_flags = ${sysenv.__PIO_TEST_CNF_EXTRA_FLAGS} extra_flags = ${sysenv.__PIO_TEST_CNF_EXTRA_FLAGS}
@ -297,6 +300,7 @@ def test_getraw_value(config):
config.getraw("custom", "debug_server") config.getraw("custom", "debug_server")
== f"\n{packages_dir}/tool-openocd/openocd\n--help" == f"\n{packages_dir}/tool-openocd/openocd\n--help"
) )
assert config.getraw("platformio", "build_dir") == "~/tmp/pio-$PROJECT_HASH"
def test_get_value(config): def test_get_value(config):
@ -327,10 +331,16 @@ def test_get_value(config):
os.path.join(DEFAULT_CORE_DIR, "packages/tool-openocd/openocd"), os.path.join(DEFAULT_CORE_DIR, "packages/tool-openocd/openocd"),
"--help", "--help",
] ]
# test relative dir
assert config.get("platformio", "src_dir") == os.path.abspath(
os.path.join(os.getcwd(), "source")
)
def test_items(config): def test_items(config):
assert config.items("custom") == [ assert config.items("custom") == [
("src_dir", "source"),
("build_dir", "~/tmp/pio-$PROJECT_HASH"),
("debug_flags", "-D DEBUG=1"), ("debug_flags", "-D DEBUG=1"),
("lib_flags", "-lc -lm"), ("lib_flags", "-lc -lm"),
("extra_flags", ""), ("extra_flags", ""),
@ -473,7 +483,8 @@ def test_dump(tmpdir_factory):
( (
"platformio", "platformio",
[ [
("build_dir", "~/tmp/pio-$PROJECT_HASH"), ("src_dir", "${custom.src_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"]), ("default_envs", ["base", "extra_2"]),
], ],
@ -497,6 +508,8 @@ def test_dump(tmpdir_factory):
( (
"custom", "custom",
[ [
("src_dir", "source"),
("build_dir", "~/tmp/pio-$PROJECT_HASH"),
("debug_flags", "-D RELEASE"), ("debug_flags", "-D RELEASE"),
("lib_flags", "-lc -lm"), ("lib_flags", "-lc -lm"),
("extra_flags", "${sysenv.__PIO_TEST_CNF_EXTRA_FLAGS}"), ("extra_flags", "${sysenv.__PIO_TEST_CNF_EXTRA_FLAGS}"),