packages.zephyr: Include blobs in modules
This commit is contained in:
parent
453af715ee
commit
6400d73e5f
|
@ -1,17 +1,35 @@
|
||||||
{ stdenvNoCC, fetchFromGitHub, version ? null, module }:
|
{ stdenvNoCC, lib, fetchFromGitHub, symlinkJoin, fetchurl, version ? null
|
||||||
let src = fetchFromGitHub module;
|
, module }:
|
||||||
in stdenvNoCC.mkDerivation (finalAttrs: {
|
let
|
||||||
name = if version != null then
|
labeledName = label:
|
||||||
"${module.name}-wrapped-${version}"
|
if version != null then
|
||||||
|
"${module.name}-${label}-${version}"
|
||||||
else
|
else
|
||||||
"${module.name}-wrapped";
|
"${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 = labeledName "wrapped";
|
||||||
|
|
||||||
passthru.modulePath = "${finalAttrs.finalPackage.out}/${module.name}";
|
passthru.modulePath = "${finalAttrs.finalPackage.out}/${module.name}";
|
||||||
|
|
||||||
passAsFile = [ "buildCommand" ];
|
passAsFile = [ "buildCommand" ];
|
||||||
buildCommand = ''
|
buildCommand = ''
|
||||||
mkdir -p $out
|
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
|
#!/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 requests
|
||||||
import json
|
import json
|
||||||
import yaml
|
import yaml
|
||||||
|
@ -12,23 +12,37 @@ BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||||
def get_repo(owner, repo, rev, name):
|
def get_repo(owner, repo, rev, name):
|
||||||
out = subprocess.run(
|
out = subprocess.run(
|
||||||
[
|
[
|
||||||
"nix-prefetch",
|
"nix-prefetch-url",
|
||||||
"--output",
|
"--unpack",
|
||||||
"json",
|
"--print-path",
|
||||||
"fetchFromGitHub",
|
f"https://github.com/{owner}/{repo}/archive/{rev}.tar.gz",
|
||||||
"--owner",
|
|
||||||
owner,
|
|
||||||
"--repo",
|
|
||||||
repo,
|
|
||||||
"--rev",
|
|
||||||
rev,
|
|
||||||
"--name",
|
|
||||||
repo,
|
|
||||||
],
|
],
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
check=True,
|
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(
|
release = requests.get(
|
||||||
|
@ -37,15 +51,10 @@ release = requests.get(
|
||||||
tag = release["tag_name"]
|
tag = release["tag_name"]
|
||||||
version = tag[1:]
|
version = tag[1:]
|
||||||
|
|
||||||
# nix-prefetch won't save the source so we download the manifest separately
|
zephyr, zephyr_path = get_repo("zephyrproject-rtos", "zephyr", tag, "zephyr")
|
||||||
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")
|
with open(os.path.join(zephyr_path, "west.yml")) as west_yml:
|
||||||
|
manifest = yaml.safe_load(west_yml)["manifest"]
|
||||||
|
|
||||||
default_remote = manifest["defaults"]["remote"]
|
default_remote = manifest["defaults"]["remote"]
|
||||||
|
|
||||||
|
@ -62,9 +71,10 @@ for project in manifest["projects"]:
|
||||||
repo = project["name"]
|
repo = project["name"]
|
||||||
owner = remotes[project.get("remote", default_remote)]
|
owner = remotes[project.get("remote", default_remote)]
|
||||||
|
|
||||||
modules[project["name"]] = get_repo(
|
modules[project["name"]], path = get_repo(
|
||||||
owner, repo, project["revision"], project["name"]
|
owner, repo, project["revision"], project["name"]
|
||||||
)
|
)
|
||||||
|
modules[project["name"]]["blobs"] = get_blobs(path)
|
||||||
|
|
||||||
out_obj = {"version": version, "zephyr": zephyr, "modules": modules}
|
out_obj = {"version": version, "zephyr": zephyr, "modules": modules}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue