From 83bf34fb7766894c8873e809e247de537e5d4b30 Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Thu, 29 Aug 2019 16:01:36 +0300 Subject: [PATCH] Extend "load_project_ide_data" API to return IDE data for more than one environment --- platformio/builder/tools/pioide.py | 2 ++ platformio/project/helpers.py | 25 +++++++++++++++++-------- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/platformio/builder/tools/pioide.py b/platformio/builder/tools/pioide.py index 1814f1b9..43d32404 100644 --- a/platformio/builder/tools/pioide.py +++ b/platformio/builder/tools/pioide.py @@ -140,6 +140,8 @@ def DumpIDEData(env, projenv): LINTCXXCOM = "$CXXFLAGS $CCFLAGS $CPPFLAGS" data = { + "env_name": + env['PIOENV'], "libsource_dirs": [env.subst(l) for l in env.GetLibSourceDirs()], "defines": _dump_defines(env), diff --git a/platformio/project/helpers.py b/platformio/project/helpers.py index 0be42893..166ef420 100644 --- a/platformio/project/helpers.py +++ b/platformio/project/helpers.py @@ -194,20 +194,29 @@ def compute_project_checksum(config): return checksum.hexdigest() -def load_project_ide_data(project_dir, env_name): +def load_project_ide_data(project_dir, envs): from platformio.commands.run import cli as cmd_run - result = CliRunner().invoke(cmd_run, [ - "--project-dir", project_dir, "--environment", env_name, "--target", - "idedata" - ]) + assert envs + if not isinstance(envs, (list, tuple)): + envs = [envs] + args = ["--project-dir", project_dir, "--target", "idedata"] + for env in envs: + args.extend(["-e", env]) + result = CliRunner().invoke(cmd_run, args) if result.exit_code != 0 and not isinstance(result.exception, exception.ReturnErrorCode): raise result.exception if '"includes":' not in result.output: raise exception.PlatformioException(result.output) + data = {} for line in result.output.split("\n"): line = line.strip() - if line.startswith('{"') and line.endswith("}"): - return json.loads(line) - return None + if (line.startswith('{"') and line.endswith("}") + and "env_name" in line): + _data = json.loads(line) + if "env_name" in _data: + data[_data['env_name']] = _data + if len(envs) == 1 and envs[0] in data: + return data[envs[0]] + return data or None