mirror of
https://github.com/platformio/platformio-core.git
synced 2025-07-30 10:07:14 +02:00
Extend "load_project_ide_data" API to return IDE data for more than one environment
This commit is contained in:
@ -140,6 +140,8 @@ def DumpIDEData(env, projenv):
|
|||||||
LINTCXXCOM = "$CXXFLAGS $CCFLAGS $CPPFLAGS"
|
LINTCXXCOM = "$CXXFLAGS $CCFLAGS $CPPFLAGS"
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
|
"env_name":
|
||||||
|
env['PIOENV'],
|
||||||
"libsource_dirs": [env.subst(l) for l in env.GetLibSourceDirs()],
|
"libsource_dirs": [env.subst(l) for l in env.GetLibSourceDirs()],
|
||||||
"defines":
|
"defines":
|
||||||
_dump_defines(env),
|
_dump_defines(env),
|
||||||
|
@ -194,20 +194,29 @@ def compute_project_checksum(config):
|
|||||||
return checksum.hexdigest()
|
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
|
from platformio.commands.run import cli as cmd_run
|
||||||
result = CliRunner().invoke(cmd_run, [
|
assert envs
|
||||||
"--project-dir", project_dir, "--environment", env_name, "--target",
|
if not isinstance(envs, (list, tuple)):
|
||||||
"idedata"
|
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,
|
if result.exit_code != 0 and not isinstance(result.exception,
|
||||||
exception.ReturnErrorCode):
|
exception.ReturnErrorCode):
|
||||||
raise result.exception
|
raise result.exception
|
||||||
if '"includes":' not in result.output:
|
if '"includes":' not in result.output:
|
||||||
raise exception.PlatformioException(result.output)
|
raise exception.PlatformioException(result.output)
|
||||||
|
|
||||||
|
data = {}
|
||||||
for line in result.output.split("\n"):
|
for line in result.output.split("\n"):
|
||||||
line = line.strip()
|
line = line.strip()
|
||||||
if line.startswith('{"') and line.endswith("}"):
|
if (line.startswith('{"') and line.endswith("}")
|
||||||
return json.loads(line)
|
and "env_name" in line):
|
||||||
return None
|
_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
|
||||||
|
Reference in New Issue
Block a user