From 7606dd4faf9ae73684043c5c07390af8e042fca1 Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Fri, 16 Feb 2024 17:06:50 +0200 Subject: [PATCH] Minor improvements // Issue #4710 --- platformio/builder/tools/piobuild.py | 2 +- platformio/debug/config/base.py | 4 ++- platformio/project/helpers.py | 46 +++++++++++++++------------- platformio/test/runners/unity.py | 4 --- 4 files changed, 28 insertions(+), 28 deletions(-) diff --git a/platformio/builder/tools/piobuild.py b/platformio/builder/tools/piobuild.py index 047090c7..b3d650a5 100644 --- a/platformio/builder/tools/piobuild.py +++ b/platformio/builder/tools/piobuild.py @@ -54,7 +54,7 @@ def GetBuildType(env): modes.append("debug") if "__test" in COMMAND_LINE_TARGETS or env.GetProjectOption("build_type") == "test": modes.append("test") - return "+".join(modes or ["release"]) + return ", ".join(modes or ["release"]) def BuildProgram(env): diff --git a/platformio/debug/config/base.py b/platformio/debug/config/base.py index 2a9f2235..1caae23f 100644 --- a/platformio/debug/config/base.py +++ b/platformio/debug/config/base.py @@ -148,7 +148,9 @@ class DebugConfigBase: # pylint: disable=too-many-instance-attributes ) def _load_build_data(self): - data = load_build_metadata(os.getcwd(), self.env_name, cache=True, debug=True) + data = load_build_metadata( + os.getcwd(), self.env_name, cache=True, build_type="debug" + ) if not data: raise DebugInvalidOptionsError("Could not load a build configuration") return data diff --git a/platformio/project/helpers.py b/platformio/project/helpers.py index cb004d23..4d153492 100644 --- a/platformio/project/helpers.py +++ b/platformio/project/helpers.py @@ -131,27 +131,27 @@ def compute_project_checksum(config): return checksum.hexdigest() -def load_build_metadata(project_dir, env_or_envs, cache=False, debug=False): +def load_build_metadata(project_dir, env_or_envs, cache=False, build_type=None): assert env_or_envs env_names = env_or_envs if not isinstance(env_names, list): env_names = [env_names] with fs.cd(project_dir): - result = _get_cached_build_metadata(project_dir, env_names) if cache else {} + result = _get_cached_build_metadata(env_names) if cache else {} # incompatible build-type data - for name in list(result.keys()): - build_type = result[name].get("build_type", "") - outdated_conds = [ - not build_type, - debug and "debug" not in build_type, - not debug and "debug" in build_type, - ] - if any(outdated_conds): - del result[name] + for env_name in list(result.keys()): + if build_type is None: + build_type = ProjectConfig.get_instance().get( + f"env:{env_name}", "build_type" + ) + if result[env_name].get("build_type", "") != build_type: + del result[env_name] missed_env_names = set(env_names) - set(result.keys()) if missed_env_names: - result.update(_load_build_metadata(project_dir, missed_env_names, debug)) + result.update( + _load_build_metadata(project_dir, missed_env_names, build_type) + ) if not isinstance(env_or_envs, list) and env_or_envs in result: return result[env_or_envs] @@ -162,14 +162,16 @@ def load_build_metadata(project_dir, env_or_envs, cache=False, debug=False): load_project_ide_data = load_build_metadata -def _load_build_metadata(project_dir, env_names, debug=False): +def _load_build_metadata(project_dir, env_names, build_type=None): # pylint: disable=import-outside-toplevel from platformio import app from platformio.run.cli import cli as cmd_run args = ["--project-dir", project_dir, "--target", "__idedata"] - if debug: + if build_type == "debug": args.extend(["--target", "__debug"]) + # if build_type == "test": + # args.extend(["--target", "__test"]) for name in env_names: args.extend(["-e", name]) app.set_session_var("pause_telemetry", True) @@ -181,16 +183,16 @@ def _load_build_metadata(project_dir, env_names, debug=False): raise result.exception if '"includes":' not in result.output: raise exception.UserSideException(result.output) - return _get_cached_build_metadata(project_dir, env_names) + return _get_cached_build_metadata(env_names) -def _get_cached_build_metadata(project_dir, env_names): - build_dir = ProjectConfig.get_instance( - os.path.join(project_dir, "platformio.ini") - ).get("platformio", "build_dir") +def _get_cached_build_metadata(env_names): + build_dir = ProjectConfig.get_instance().get("platformio", "build_dir") result = {} - for name in env_names: - if not os.path.isfile(os.path.join(build_dir, name, "idedata.json")): + for env_name in env_names: + if not os.path.isfile(os.path.join(build_dir, env_name, "idedata.json")): continue - result[name] = fs.load_json(os.path.join(build_dir, name, "idedata.json")) + result[env_name] = fs.load_json( + os.path.join(build_dir, env_name, "idedata.json") + ) return result diff --git a/platformio/test/runners/unity.py b/platformio/test/runners/unity.py index 935a1328..0d0d9e82 100644 --- a/platformio/test/runners/unity.py +++ b/platformio/test/runners/unity.py @@ -184,10 +184,6 @@ void unityOutputComplete(void) { unittest_uart_end(); } ), ) - def __init__(self, *args, **kwargs): - """Delete when Unity > 2.5.2 is released""" - super().__init__(*args, **kwargs) - def get_unity_framework_config(self): if not self.platform.is_embedded(): return self.UNITY_FRAMEWORK_CONFIG["native"]