packages.zephyr: Include blobs in modules
This commit is contained in:
parent
453af715ee
commit
6400d73e5f
|
@ -1,17 +1,35 @@
|
|||
{ stdenvNoCC, fetchFromGitHub, version ? null, module }:
|
||||
let src = fetchFromGitHub module;
|
||||
{ stdenvNoCC, lib, fetchFromGitHub, symlinkJoin, fetchurl, version ? null
|
||||
, module }:
|
||||
let
|
||||
labeledName = label:
|
||||
if version != null then
|
||||
"${module.name}-${label}-${version}"
|
||||
else
|
||||
"${module.name}-${label}";
|
||||
fetchBlob = blob:
|
||||
let blobFile = fetchurl { inherit (blob) url sha256; };
|
||||
in stdenvNoCC.mkDerivation {
|
||||
name = "blob-${blob.path}";
|
||||
passAsFile = [ "buildCommand" ];
|
||||
buildCommand = ''
|
||||
mkdir -p $out/${builtins.dirOf blob.path}
|
||||
ln -s ${blobFile} $out/${blob.path}
|
||||
'';
|
||||
};
|
||||
baseSrc = fetchFromGitHub { inherit (module) owner repo rev name sha256; };
|
||||
blobbedSrc = symlinkJoin {
|
||||
name = labeledName "with-blobs";
|
||||
paths = [ baseSrc ] ++ (map fetchBlob module.blobs);
|
||||
};
|
||||
in stdenvNoCC.mkDerivation (finalAttrs: {
|
||||
name = if version != null then
|
||||
"${module.name}-wrapped-${version}"
|
||||
else
|
||||
"${module.name}-wrapped";
|
||||
name = labeledName "wrapped";
|
||||
|
||||
passthru.modulePath = "${finalAttrs.finalPackage.out}/${module.name}";
|
||||
|
||||
passAsFile = [ "buildCommand" ];
|
||||
buildCommand = ''
|
||||
mkdir -p $out
|
||||
ln -s "${src}" "$out/${module.name}"
|
||||
ln -s ${blobbedSrc} "$out/${module.name}"
|
||||
'';
|
||||
})
|
||||
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -1,5 +1,5 @@
|
|||
#!/usr/bin/env nix-shell
|
||||
#! nix-shell -i python3 -p python3 python3Packages.requests python3Packages.pyyaml nix-prefetch
|
||||
#! nix-shell -i python3 -p python3 python3Packages.requests python3Packages.pyyaml
|
||||
import requests
|
||||
import json
|
||||
import yaml
|
||||
|
@ -12,23 +12,37 @@ 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,
|
||||
"nix-prefetch-url",
|
||||
"--unpack",
|
||||
"--print-path",
|
||||
f"https://github.com/{owner}/{repo}/archive/{rev}.tar.gz",
|
||||
],
|
||||
stdout=subprocess.PIPE,
|
||||
check=True,
|
||||
)
|
||||
return json.loads(out.stdout.decode("utf-8"))
|
||||
sha256, path, *_ = out.stdout.decode("utf-8").split("\n")
|
||||
return {
|
||||
"owner": owner,
|
||||
"repo": repo,
|
||||
"rev": rev,
|
||||
"name": name,
|
||||
"sha256": sha256,
|
||||
}, path
|
||||
|
||||
|
||||
def get_blobs(module_root):
|
||||
module_yml_path = os.path.join(module_root, "zephyr", "module.yml")
|
||||
if not os.path.isfile(module_yml_path):
|
||||
return []
|
||||
with open(module_yml_path) as module_file:
|
||||
blobs_yml = yaml.safe_load(module_file).get("blobs", [])
|
||||
|
||||
blobs = []
|
||||
for blob in blobs_yml:
|
||||
blobs.append(
|
||||
{"path": blob["path"], "url": blob["url"], "sha256": blob["sha256"]}
|
||||
)
|
||||
return blobs
|
||||
|
||||
|
||||
release = requests.get(
|
||||
|
@ -37,15 +51,10 @@ release = requests.get(
|
|||
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, zephyr_path = get_repo("zephyrproject-rtos", "zephyr", tag, "zephyr")
|
||||
|
||||
zephyr = get_repo("zephyrproject-rtos", "zephyr", tag, "zephyr")
|
||||
with open(os.path.join(zephyr_path, "west.yml")) as west_yml:
|
||||
manifest = yaml.safe_load(west_yml)["manifest"]
|
||||
|
||||
default_remote = manifest["defaults"]["remote"]
|
||||
|
||||
|
@ -62,9 +71,10 @@ for project in manifest["projects"]:
|
|||
repo = project["name"]
|
||||
owner = remotes[project.get("remote", default_remote)]
|
||||
|
||||
modules[project["name"]] = get_repo(
|
||||
modules[project["name"]], path = get_repo(
|
||||
owner, repo, project["revision"], project["name"]
|
||||
)
|
||||
modules[project["name"]]["blobs"] = get_blobs(path)
|
||||
|
||||
out_obj = {"version": version, "zephyr": zephyr, "modules": modules}
|
||||
|
||||
|
|
Loading…
Reference in a new issue