Skip to content

Commit 299786a

Browse files
authored
Simplify and fix bugs of bootstrap json file generating script (#40)
1 parent ddcb14a commit 299786a

File tree

12 files changed

+111
-322
lines changed

12 files changed

+111
-322
lines changed

.github/workflows/clingo.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ jobs:
4141
with:
4242
repository: spack/spack
4343
path: spack
44-
ref: c710a1597f3566ab850d0ee8c82e71af04a08f9e
44+
ref: d36452cf4e70fa1da8b9db43921850872b82ced9
4545
# See https://github.com/actions/setup-python/issues/960
4646
- name: Workaround for broken Python versions from setup-python
4747
run: brew install gettext zlib
@@ -57,7 +57,7 @@ jobs:
5757
spack external find --not-buildable cmake bison
5858
spack config add "config:install_tree:padded_length:256"
5959
60-
spack python clingo/scripts/install_clingo.py
60+
spack python clingo/install_clingo.py
6161
spack buildcache push --unsigned ./binary-mirror clingo-bootstrap
6262
- uses: actions/upload-artifact@v3
6363
with:
@@ -127,15 +127,15 @@ jobs:
127127
needs: [ upload-manylinux2014, macos_clingo ]
128128
steps:
129129
- uses: actions/checkout@v4
130-
- uses: actions/setup-python@v4
130+
- uses: actions/checkout@v4
131131
with:
132-
python-version: 3.9
132+
repository: spack/spack
133+
path: spack
134+
ref: d36452cf4e70fa1da8b9db43921850872b82ced9
133135
- uses: actions/download-artifact@v3
134136
with:
135137
name: clingo_binary_mirror
136-
- run: |
137-
pip install ruamel.yaml
138-
python3 clingo/scripts/clingo_json.py
138+
- run: ./spack/bin/spack python ./generate_bootstrap_json.py clingo
139139
- uses: actions/upload-artifact@v3
140140
with:
141141
name: clingo_manifest

.github/workflows/gnupg.yml

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ jobs:
4141
with:
4242
repository: spack/spack
4343
path: spack
44-
ref: c710a1597f3566ab850d0ee8c82e71af04a08f9e
44+
ref: d36452cf4e70fa1da8b9db43921850872b82ced9
4545
- name: Install gnupg
4646
run: |
4747
brew install gawk perl
@@ -127,15 +127,11 @@ jobs:
127127
with:
128128
repository: spack/spack
129129
path: spack
130-
- uses: actions/setup-python@v4
131-
with:
132-
python-version: 3.11
130+
ref: d36452cf4e70fa1da8b9db43921850872b82ced9
133131
- uses: actions/download-artifact@v3
134132
with:
135133
name: gnupg_binary_mirror
136-
- run: |
137-
. spack/share/spack/setup-env.sh
138-
spack python gnupg/scripts/gnupg_json.py
134+
- run: ./spack/bin/spack python ./generate_bootstrap_json.py gnupg
139135
- uses: actions/upload-artifact@v3
140136
with:
141137
name: gnupg_manifest

.github/workflows/patchelf.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,15 @@ jobs:
8383
needs: [ upload-manylinux2014 ]
8484
steps:
8585
- uses: actions/checkout@v4
86-
- uses: actions/setup-python@v4
86+
- uses: actions/checkout@v4
8787
with:
88-
python-version: 3.9
88+
repository: spack/spack
89+
path: spack
90+
ref: d36452cf4e70fa1da8b9db43921850872b82ced9
8991
- uses: actions/download-artifact@v3
9092
with:
9193
name: patchelf_binary_mirror
92-
- run: |
93-
pip install ruamel.yaml
94-
python3 patchelf/scripts/patchelf_json.py
94+
- run: ./spack/bin/spack python ./generate_bootstrap_json.py patchelf
9595
- uses: actions/upload-artifact@v3
9696
with:
9797
name: patchelf_manifest

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.env

clingo/Dockerfile.manylinux2014

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,22 @@ ENV PATH="/root/spack/bin/:$PATH" \
1111

1212
# Clone the repo and install Spack
1313
RUN git clone https://github.com/spack/spack.git && \
14-
git -C spack checkout -b docker-reference c710a1597f3566ab850d0ee8c82e71af04a08f9e
14+
git -C spack checkout -b docker-reference d36452cf4e70fa1da8b9db43921850872b82ced9
1515

1616
# Set externals, locate compilers
1717
RUN spack external find -j 1 --not-buildable bison cmake
1818
RUN spack compiler find
1919
RUN spack config add "config:install_tree:padded_length:256"
2020

21-
COPY clingo/scripts/install_clingo.py /root/install_clingo.py
21+
COPY clingo/install_clingo.py /root/install_clingo.py
2222

23-
RUN SPACK_PYTHON=/opt/python/cp313-cp313/bin/python3 spack python install_clingo.py
24-
RUN SPACK_PYTHON=/opt/python/cp312-cp312/bin/python3 spack python install_clingo.py
25-
RUN SPACK_PYTHON=/opt/python/cp311-cp311/bin/python3 spack python install_clingo.py
26-
RUN SPACK_PYTHON=/opt/python/cp310-cp310/bin/python3 spack python install_clingo.py
27-
RUN SPACK_PYTHON=/opt/python/cp39-cp39/bin/python3 spack python install_clingo.py
28-
RUN SPACK_PYTHON=/opt/python/cp38-cp38/bin/python3 spack python install_clingo.py
29-
RUN SPACK_PYTHON=/opt/python/cp37-cp37m/bin/python3 spack python install_clingo.py
3023
RUN SPACK_PYTHON=/opt/python/cp36-cp36m/bin/python3 spack python install_clingo.py
24+
RUN SPACK_PYTHON=/opt/python/cp37-cp37m/bin/python3 spack python install_clingo.py
25+
RUN SPACK_PYTHON=/opt/python/cp38-cp38/bin/python3 spack python install_clingo.py
26+
RUN SPACK_PYTHON=/opt/python/cp39-cp39/bin/python3 spack python install_clingo.py
27+
RUN SPACK_PYTHON=/opt/python/cp310-cp310/bin/python3 spack python install_clingo.py
28+
RUN SPACK_PYTHON=/opt/python/cp311-cp311/bin/python3 spack python install_clingo.py
29+
RUN SPACK_PYTHON=/opt/python/cp312-cp312/bin/python3 spack python install_clingo.py
30+
RUN SPACK_PYTHON=/opt/python/cp313-cp313/bin/python3 spack python install_clingo.py
3131

3232
RUN spack buildcache push --unsigned ./binary-mirror $(spack --color=never find --hashes clingo-bootstrap)

clingo/scripts/install_clingo.py renamed to clingo/install_clingo.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#!/usr/bin/env spack-python
2+
13
import archspec.cpu
24
import spack.bootstrap.config
35
import spack.main

clingo/scripts/clingo_json.py

Lines changed: 0 additions & 110 deletions
This file was deleted.

generate_bootstrap_json.py

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#!/usr/bin/env spack-python
2+
"""Produce a bootstrap json file for a selected package"""
3+
4+
import glob
5+
import hashlib
6+
import json
7+
import os
8+
import sys
9+
10+
import spack.deptypes as dt
11+
import spack.spec
12+
import spack.traverse
13+
14+
# Each entry in clingo.json has the following keys:
15+
#
16+
# "spec": root spec to be matched
17+
# "binaries": list of tuples (pkg name, dag hash, sha256 sum)
18+
19+
20+
def sha256(path):
21+
fn = hashlib.sha256()
22+
with open(path, "rb") as f:
23+
fn.update(f.read())
24+
return fn.hexdigest()
25+
26+
27+
def tarball_hash(path: str):
28+
# extract hash from /path/to/<...>-<hash>.spack
29+
name, _ = os.path.splitext(os.path.basename(path))
30+
return name.split("-")[-1]
31+
32+
33+
def run(pkg: str, deps=dt.NONE, python: bool = False):
34+
name = "clingo-bootstrap" if pkg == "clingo" else pkg
35+
shas = {
36+
tarball_hash(tarball): sha256(tarball)
37+
for tarball in glob.glob("./build_cache/**/*.spack", recursive=True)
38+
}
39+
40+
specs = [
41+
spack.spec.Spec.from_specfile(f) for f in glob.glob("./build_cache/*.json") if name in f
42+
]
43+
44+
assert len(specs) > 0, f"No specs found for {name}"
45+
46+
fmt = "{name}{@version}{%compiler.name} platform={platform} target={target}"
47+
48+
if python:
49+
fmt_spec = lambda s: f"{s.format(fmt)} ^python@{s.dependencies('python')[0].version}"
50+
else:
51+
fmt_spec = lambda s: s.format(fmt)
52+
53+
mirror_info = [
54+
{
55+
"spec": fmt_spec(s),
56+
"binaries": [
57+
(s.name, s.dag_hash(), shas[s.dag_hash()])
58+
for s in reversed(list(s.traverse(order="topo", deptype=deps)))
59+
if not s.external
60+
],
61+
}
62+
for s in specs
63+
]
64+
65+
# sort as strings, cause Spec instances with deps don't sort properly
66+
mirror_info.sort(key=lambda x: x["spec"])
67+
68+
with open(f"./{pkg}.json", "w") as f:
69+
json.dump({"verified": mirror_info}, f, sort_keys=True, indent=2)
70+
71+
72+
if __name__ == "__main__":
73+
assert len(sys.argv) == 2, f"Usage: {sys.argv[0]} <clingo|gnupg|patchelf>"
74+
pkg = sys.argv[1]
75+
# unfortunately we refer to clingo-bootstrap by alias "clingo"
76+
assert pkg in ("clingo", "gnupg", "patchelf")
77+
run(
78+
pkg,
79+
# clingo is special: statically links libstdc++ and other deps are loaded by interpreter
80+
deps=dt.NONE if pkg == "clingo" else dt.LINK | dt.RUN,
81+
python=pkg == "clingo",
82+
)

gnupg/Dockerfile.manylinux2014

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ ENV PATH="/root/spack/bin/:$PATH" \
99

1010
# Clone the repo and install Spack
1111
RUN git clone https://github.com/spack/spack.git && \
12-
git -C spack checkout -b docker-reference c710a1597f3566ab850d0ee8c82e71af04a08f9e
12+
git -C spack checkout -b docker-reference d36452cf4e70fa1da8b9db43921850872b82ced9
1313

1414
# Set externals, locate compilers
1515
RUN spack external find --not-buildable gawk perl

0 commit comments

Comments
 (0)