build,json: fixup missing arch_packages
[openwrt/staging/dangole.git] / scripts / json_overview_image_info.py
1 #!/usr/bin/env python3
2
3 from os import getenv, environ
4 from pathlib import Path
5 from subprocess import run, PIPE
6 from sys import argv
7 import json
8
9 if len(argv) != 2:
10 print("JSON info files script requires ouput file as argument")
11 exit(1)
12
13 output_path = Path(argv[1])
14
15 assert getenv("WORK_DIR"), "$WORK_DIR required"
16
17 work_dir = Path(getenv("WORK_DIR"))
18
19 output = {}
20
21 for json_file in work_dir.glob("*.json"):
22 image_info = json.loads(json_file.read_text())
23 if not output:
24 output.update(image_info)
25 else:
26 # get first (and only) profile in json file
27 device_id = next(iter(image_info["profiles"].keys()))
28 if device_id not in output["profiles"]:
29 output["profiles"].update(image_info["profiles"])
30 else:
31 output["profiles"][device_id]["images"].append(
32 image_info["profiles"][device_id]["images"][0]
33 )
34
35 if output:
36 output["default_packages"] = run(
37 [
38 "make",
39 "--no-print-directory",
40 "-C",
41 "target/linux/{}".format(output["target"].split("/")[0]),
42 "val.DEFAULT_PACKAGES",
43 "DUMP=1",
44 ],
45 stdout=PIPE,
46 stderr=PIPE,
47 check=True,
48 env=environ.copy().update({"TOPDIR": Path().cwd()}),
49 universal_newlines=True,
50 ).stdout.split()
51
52 output["arch_packages"] = run(
53 [
54 "make",
55 "--no-print-directory",
56 "val.ARCH_PACKAGES",
57 ],
58 stdout=PIPE,
59 stderr=PIPE,
60 check=True,
61 env=environ.copy().update({"TOPDIR": Path().cwd()}),
62 universal_newlines=True,
63 ).stdout.strip()
64
65 output_path.write_text(json.dumps(output, sort_keys=True, separators=(",", ":")))
66 else:
67 print("JSON info file script could not find any JSON files for target")