packages.zephyr: Add source for zephyr and modules
This commit is contained in:
parent
763d83f157
commit
da07bd75a0
|
@ -1,5 +1,7 @@
|
|||
{ callPackage, stdenv, lib }:
|
||||
let assets = lib.importJSON ./assets.json;
|
||||
{ callPackage, stdenv, lib, fetchFromGitHub }:
|
||||
let
|
||||
assets = lib.importJSON ./assets.json;
|
||||
modules = lib.importJSON ./modules.json;
|
||||
in {
|
||||
host-tools = callPackage ./host-tools.nix {
|
||||
inherit (assets) version hosts;
|
||||
|
@ -16,4 +18,7 @@ in {
|
|||
inherit (assets) version hosts;
|
||||
source = assets.sdk;
|
||||
};
|
||||
|
||||
src = fetchFromGitHub modules.zephyr;
|
||||
modules = lib.mapAttrs (_: fetchFromGitHub) modules.modules;
|
||||
}
|
||||
|
|
1
packages/zephyr/modules.json
Normal file
1
packages/zephyr/modules.json
Normal file
File diff suppressed because one or more lines are too long
72
packages/zephyr/update-src.py
Executable file
72
packages/zephyr/update-src.py
Executable file
|
@ -0,0 +1,72 @@
|
|||
#!/usr/bin/env nix-shell
|
||||
#! nix-shell -i python3 -p python3 python3Packages.requests python3Packages.pyyaml nix-prefetch
|
||||
import requests
|
||||
import json
|
||||
import yaml
|
||||
import subprocess
|
||||
import os
|
||||
|
||||
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||
|
||||
|
||||
def get_repo(owner, repo, rev, name):
|
||||
out = subprocess.run(
|
||||
[
|
||||
"nix-prefetch",
|
||||
"--output",
|
||||
"json",
|
||||
"fetchFromGitHub",
|
||||
"--owner",
|
||||
owner,
|
||||
"--repo",
|
||||
repo,
|
||||
"--rev",
|
||||
rev,
|
||||
"--name",
|
||||
repo,
|
||||
],
|
||||
stdout=subprocess.PIPE,
|
||||
check=True,
|
||||
)
|
||||
return json.loads(out.stdout.decode("utf-8"))
|
||||
|
||||
|
||||
release = requests.get(
|
||||
"https://api.github.com/repos/zephyrproject-rtos/zephyr/releases/latest"
|
||||
).json()
|
||||
tag = release["tag_name"]
|
||||
version = tag[1:]
|
||||
|
||||
# nix-prefetch won't save the source so we download the manifest separately
|
||||
manifest = yaml.load(
|
||||
requests.get(
|
||||
f"https://raw.githubusercontent.com/zephyrproject-rtos/zephyr/{tag}/west.yml"
|
||||
).text,
|
||||
Loader=yaml.Loader,
|
||||
)["manifest"]
|
||||
|
||||
zephyr = get_repo("zephyrproject-rtos", "zephyr", tag, "zephyr")
|
||||
|
||||
default_remote = manifest["defaults"]["remote"]
|
||||
|
||||
remotes = {}
|
||||
for remote in manifest["remotes"]:
|
||||
# Works for github URLs, which is all they use
|
||||
remotes[remote["name"]] = remote["url-base"].removeprefix("https://github.com/")
|
||||
|
||||
modules = {}
|
||||
for project in manifest["projects"]:
|
||||
if "repo-path" in project:
|
||||
repo = project["repo-path"].removesuffix(".git")
|
||||
else:
|
||||
repo = project["name"]
|
||||
owner = remotes[project.get("remote", default_remote)]
|
||||
|
||||
modules[project["name"]] = get_repo(
|
||||
owner, repo, project["revision"], project["name"]
|
||||
)
|
||||
|
||||
out_obj = {"version": version, "zephyr": zephyr, "modules": modules}
|
||||
|
||||
with open(os.path.join(BASE_DIR, "modules.json"), "w") as out_file:
|
||||
json.dump(out_obj, out_file)
|
Loading…
Reference in a new issue