2020-03-12 22:55:41 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
2020-06-30 11:02:43 +00:00
|
|
|
from os import getenv, environ
|
2020-03-12 22:55:41 +00:00
|
|
|
from pathlib import Path
|
2020-07-06 23:14:42 +00:00
|
|
|
from subprocess import run, PIPE
|
2020-03-12 22:55:41 +00:00
|
|
|
from sys import argv
|
2020-06-30 11:02:43 +00:00
|
|
|
import json
|
2020-03-12 22:55:41 +00:00
|
|
|
|
|
|
|
if len(argv) != 2:
|
|
|
|
print("JSON info files script requires ouput file as argument")
|
|
|
|
exit(1)
|
|
|
|
|
|
|
|
output_path = Path(argv[1])
|
|
|
|
|
|
|
|
assert getenv("WORK_DIR"), "$WORK_DIR required"
|
|
|
|
|
|
|
|
work_dir = Path(getenv("WORK_DIR"))
|
|
|
|
|
|
|
|
output = {}
|
|
|
|
|
2021-02-21 23:18:10 +00:00
|
|
|
|
|
|
|
def get_initial_output(image_info):
|
|
|
|
# preserve existing profiles.json
|
|
|
|
if output_path.is_file():
|
|
|
|
profiles = json.loads(output_path.read_text())
|
|
|
|
if profiles["version_code"] == image_info["version_code"]:
|
|
|
|
return profiles
|
|
|
|
return image_info
|
|
|
|
|
|
|
|
|
2020-03-12 22:55:41 +00:00
|
|
|
for json_file in work_dir.glob("*.json"):
|
|
|
|
image_info = json.loads(json_file.read_text())
|
2021-02-21 23:18:10 +00:00
|
|
|
|
2020-03-12 22:55:41 +00:00
|
|
|
if not output:
|
2021-02-21 23:18:10 +00:00
|
|
|
output = get_initial_output(image_info)
|
|
|
|
|
|
|
|
# get first and only profile in json file
|
|
|
|
device_id, profile = next(iter(image_info["profiles"].items()))
|
|
|
|
if device_id not in output["profiles"]:
|
|
|
|
output["profiles"][device_id] = profile
|
2020-03-12 22:55:41 +00:00
|
|
|
else:
|
2021-02-21 23:18:10 +00:00
|
|
|
output["profiles"][device_id]["images"].extend(profile["images"])
|
|
|
|
|
|
|
|
# make image lists unique by name, keep last/latest
|
|
|
|
for device_id, profile in output["profiles"].items():
|
|
|
|
profile["images"] = list({e["name"]: e for e in profile["images"]}.values())
|
|
|
|
|
2020-03-12 22:55:41 +00:00
|
|
|
|
|
|
|
if output:
|
2021-03-25 20:25:54 +00:00
|
|
|
default_packages, output["arch_packages"] = run(
|
2020-07-03 20:57:52 +00:00
|
|
|
[
|
|
|
|
"make",
|
|
|
|
"--no-print-directory",
|
|
|
|
"-C",
|
2021-03-25 20:25:54 +00:00
|
|
|
"target/linux/",
|
2020-07-03 20:57:52 +00:00
|
|
|
"val.DEFAULT_PACKAGES",
|
2021-03-24 21:01:46 +00:00
|
|
|
"val.ARCH_PACKAGES",
|
|
|
|
],
|
|
|
|
stdout=PIPE,
|
|
|
|
stderr=PIPE,
|
|
|
|
check=True,
|
|
|
|
env=environ.copy().update({"TOPDIR": Path().cwd()}),
|
|
|
|
universal_newlines=True,
|
2021-03-25 20:25:54 +00:00
|
|
|
).stdout.splitlines()
|
|
|
|
|
|
|
|
output["default_packages"] = sorted(default_packages.split())
|
2020-07-03 20:57:52 +00:00
|
|
|
|
2020-03-12 22:55:41 +00:00
|
|
|
output_path.write_text(json.dumps(output, sort_keys=True, separators=(",", ":")))
|
|
|
|
else:
|
|
|
|
print("JSON info file script could not find any JSON files for target")
|