mirror of
https://github.com/openwrt/openwrt.git
synced 2024-12-18 13:26:34 +00:00
c857145e03
Currently downstream tools like ASU lack information about kernel version to find out the relevant kmod build folder on downloads server. So lets fix it by providing a new `linux_kernel` JSON array which would for the start provide Linux kernel version, revision and vermagic information. "linux_kernel": { "release": "1", "vermagic": "b57450c07d3a786158c3601fc5cee57d", "version": "6.6.61" }, Fixes: openwrt/openwrt#17036 Fixes: efahl/owut#9 Co-developed-by: Petr Štetiar <ynezz@true.cz> Signed-off-by: Eric Fahlgren <ericfahlgren@gmail.com> Link: https://github.com/openwrt/openwrt/pull/17042 Signed-off-by: Petr Štetiar <ynezz@true.cz>
84 lines
2.3 KiB
Python
Executable File
84 lines
2.3 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
from os import getenv, environ
|
|
from pathlib import Path
|
|
from subprocess import run, PIPE
|
|
from sys import argv
|
|
import json
|
|
|
|
if len(argv) != 2:
|
|
print("JSON info files script requires output file as argument")
|
|
exit(1)
|
|
|
|
output_path = Path(argv[1])
|
|
|
|
assert getenv("WORK_DIR"), "$WORK_DIR required"
|
|
|
|
work_dir = Path(getenv("WORK_DIR"))
|
|
|
|
output = {}
|
|
|
|
|
|
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
|
|
|
|
|
|
for json_file in work_dir.glob("*.json"):
|
|
image_info = json.loads(json_file.read_text())
|
|
|
|
if not output:
|
|
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
|
|
else:
|
|
output["profiles"][device_id]["images"].extend(profile["images"])
|
|
|
|
# make image lists unique by name, keep last/latest
|
|
for device_id, profile in output.get("profiles", {}).items():
|
|
profile["images"] = list({e["name"]: e for e in profile["images"]}.values())
|
|
|
|
|
|
if output:
|
|
(
|
|
default_packages,
|
|
output["arch_packages"],
|
|
linux_version,
|
|
linux_release,
|
|
linux_vermagic,
|
|
) = run(
|
|
[
|
|
"make",
|
|
"--no-print-directory",
|
|
"-C",
|
|
"target/linux/",
|
|
"val.DEFAULT_PACKAGES",
|
|
"val.ARCH_PACKAGES",
|
|
"val.LINUX_VERSION",
|
|
"val.LINUX_RELEASE",
|
|
"val.LINUX_VERMAGIC",
|
|
"V=s",
|
|
],
|
|
stdout=PIPE,
|
|
check=True,
|
|
env=environ.copy().update({"TOPDIR": Path().cwd()}),
|
|
universal_newlines=True,
|
|
).stdout.splitlines()
|
|
|
|
output["default_packages"] = sorted(default_packages.split())
|
|
output["linux_kernel"] = {
|
|
"version": linux_version,
|
|
"release": linux_release,
|
|
"vermagic": linux_vermagic,
|
|
}
|
|
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")
|