Extend "load_project_ide_data" API to return IDE data for more than one environment

This commit is contained in:
Ivan Kravets
2019-08-29 16:01:36 +03:00
parent 1c8666e946
commit 83bf34fb77
2 changed files with 19 additions and 8 deletions

View File

@ -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),

View File

@ -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