Skip to content

Commit

Permalink
simplify further: record ^python as part of spec, and record version
Browse files Browse the repository at this point in the history
  • Loading branch information
haampie committed Oct 18, 2024
1 parent e5738d2 commit af38e8d
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 31 deletions.
7 changes: 0 additions & 7 deletions clingo/spec_info.json

This file was deleted.

20 changes: 8 additions & 12 deletions generate_bootstrap_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
#
# "spec": root spec to be matched
# "binaries": list of tuples (pkg name, dag hash, sha256 sum)
# optionally "python": constraints on the python interpreter (could've been part of `spec` but
# for unknown reasons it is not)


def sha256(path):
fn = hashlib.sha256()
Expand All @@ -33,7 +30,7 @@ def tarball_hash(path: str):
return name.split("-")[-1]


def run(pkg: str, arch_to_spec: Dict[str, str], deps=dt.NONE, python: bool = False):
def run(pkg: str, deps=dt.NONE, python: bool = False):
name = "clingo-bootstrap" if pkg == "clingo" else pkg
shas = {
tarball_hash(tarball): sha256(tarball)
Expand All @@ -46,15 +43,16 @@ def run(pkg: str, arch_to_spec: Dict[str, str], deps=dt.NONE, python: bool = Fal

assert len(specs) > 0, f"No specs found for {name}"

fmt = "{name}{@version}{%compiler.name} platform={platform} target={target}"

if python:
with_python = lambda s: {"python": f"python@{s.dependencies('python')[0].version}"}
fmt_spec = lambda s: f"{s.format(fmt)} ^python@{s.dependencies('python')[0].version}"
else:
with_python = lambda _: {}
fmt_spec = lambda s: s.format(fmt)

mirror_info = [
{
"spec": arch_to_spec[f"{s.architecture.os}-{s.architecture.target}"],
**with_python(s),
"spec": fmt_spec(s),
"binaries": [
(s.name, s.dag_hash(), shas[s.dag_hash()])
for s in reversed(list(s.traverse(order="topo", deptype=deps)))
Expand All @@ -64,8 +62,8 @@ def run(pkg: str, arch_to_spec: Dict[str, str], deps=dt.NONE, python: bool = Fal
for s in specs
]

if python:
mirror_info.sort(key=lambda x: spack.spec.Spec(x["python"]))
# sort as strings, cause Spec instances with deps don't sort properly
mirror_info.sort(key=lambda x: x["spec"])

with open(f"./{pkg}.json", "w") as f:
json.dump({"verified": mirror_info}, f, sort_keys=True, indent=2)
Expand All @@ -76,10 +74,8 @@ def run(pkg: str, arch_to_spec: Dict[str, str], deps=dt.NONE, python: bool = Fal
pkg = sys.argv[1]
# unfortunately we refer to clingo-bootstrap by alias "clingo"
assert pkg in ("clingo", "gnupg", "patchelf")
file = f"{os.path.dirname(__file__)}/{pkg}/spec_info.json"
run(
pkg,
arch_to_spec=json.load(open(file)),
# clingo is special: statically links libstdc++ and other deps are loaded by interpreter
deps=dt.NONE if pkg == "clingo" else dt.LINK | dt.RUN,
python=pkg == "clingo",
Expand Down
7 changes: 0 additions & 7 deletions gnupg/spec_info.json

This file was deleted.

5 changes: 0 additions & 5 deletions patchelf/spec_info.json

This file was deleted.

0 comments on commit af38e8d

Please sign in to comment.