Skip to content

Commit

Permalink
Simplify and fix bugs of bootstrap json file generating script (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
haampie authored Oct 18, 2024
1 parent ddcb14a commit 299786a
Show file tree
Hide file tree
Showing 12 changed files with 111 additions and 322 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/clingo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
with:
repository: spack/spack
path: spack
ref: c710a1597f3566ab850d0ee8c82e71af04a08f9e
ref: d36452cf4e70fa1da8b9db43921850872b82ced9
# See https://github.com/actions/setup-python/issues/960
- name: Workaround for broken Python versions from setup-python
run: brew install gettext zlib
Expand All @@ -57,7 +57,7 @@ jobs:
spack external find --not-buildable cmake bison
spack config add "config:install_tree:padded_length:256"
spack python clingo/scripts/install_clingo.py
spack python clingo/install_clingo.py
spack buildcache push --unsigned ./binary-mirror clingo-bootstrap
- uses: actions/upload-artifact@v3
with:
Expand Down Expand Up @@ -127,15 +127,15 @@ jobs:
needs: [ upload-manylinux2014, macos_clingo ]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
- uses: actions/checkout@v4
with:
python-version: 3.9
repository: spack/spack
path: spack
ref: d36452cf4e70fa1da8b9db43921850872b82ced9
- uses: actions/download-artifact@v3
with:
name: clingo_binary_mirror
- run: |
pip install ruamel.yaml
python3 clingo/scripts/clingo_json.py
- run: ./spack/bin/spack python ./generate_bootstrap_json.py clingo
- uses: actions/upload-artifact@v3
with:
name: clingo_manifest
Expand Down
10 changes: 3 additions & 7 deletions .github/workflows/gnupg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
with:
repository: spack/spack
path: spack
ref: c710a1597f3566ab850d0ee8c82e71af04a08f9e
ref: d36452cf4e70fa1da8b9db43921850872b82ced9
- name: Install gnupg
run: |
brew install gawk perl
Expand Down Expand Up @@ -127,15 +127,11 @@ jobs:
with:
repository: spack/spack
path: spack
- uses: actions/setup-python@v4
with:
python-version: 3.11
ref: d36452cf4e70fa1da8b9db43921850872b82ced9
- uses: actions/download-artifact@v3
with:
name: gnupg_binary_mirror
- run: |
. spack/share/spack/setup-env.sh
spack python gnupg/scripts/gnupg_json.py
- run: ./spack/bin/spack python ./generate_bootstrap_json.py gnupg
- uses: actions/upload-artifact@v3
with:
name: gnupg_manifest
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/patchelf.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,15 @@ jobs:
needs: [ upload-manylinux2014 ]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
- uses: actions/checkout@v4
with:
python-version: 3.9
repository: spack/spack
path: spack
ref: d36452cf4e70fa1da8b9db43921850872b82ced9
- uses: actions/download-artifact@v3
with:
name: patchelf_binary_mirror
- run: |
pip install ruamel.yaml
python3 patchelf/scripts/patchelf_json.py
- run: ./spack/bin/spack python ./generate_bootstrap_json.py patchelf
- uses: actions/upload-artifact@v3
with:
name: patchelf_manifest
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.env
18 changes: 9 additions & 9 deletions clingo/Dockerfile.manylinux2014
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,22 @@ ENV PATH="/root/spack/bin/:$PATH" \

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

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

COPY clingo/scripts/install_clingo.py /root/install_clingo.py
COPY clingo/install_clingo.py /root/install_clingo.py

RUN SPACK_PYTHON=/opt/python/cp313-cp313/bin/python3 spack python install_clingo.py
RUN SPACK_PYTHON=/opt/python/cp312-cp312/bin/python3 spack python install_clingo.py
RUN SPACK_PYTHON=/opt/python/cp311-cp311/bin/python3 spack python install_clingo.py
RUN SPACK_PYTHON=/opt/python/cp310-cp310/bin/python3 spack python install_clingo.py
RUN SPACK_PYTHON=/opt/python/cp39-cp39/bin/python3 spack python install_clingo.py
RUN SPACK_PYTHON=/opt/python/cp38-cp38/bin/python3 spack python install_clingo.py
RUN SPACK_PYTHON=/opt/python/cp37-cp37m/bin/python3 spack python install_clingo.py
RUN SPACK_PYTHON=/opt/python/cp36-cp36m/bin/python3 spack python install_clingo.py
RUN SPACK_PYTHON=/opt/python/cp37-cp37m/bin/python3 spack python install_clingo.py
RUN SPACK_PYTHON=/opt/python/cp38-cp38/bin/python3 spack python install_clingo.py
RUN SPACK_PYTHON=/opt/python/cp39-cp39/bin/python3 spack python install_clingo.py
RUN SPACK_PYTHON=/opt/python/cp310-cp310/bin/python3 spack python install_clingo.py
RUN SPACK_PYTHON=/opt/python/cp311-cp311/bin/python3 spack python install_clingo.py
RUN SPACK_PYTHON=/opt/python/cp312-cp312/bin/python3 spack python install_clingo.py
RUN SPACK_PYTHON=/opt/python/cp313-cp313/bin/python3 spack python install_clingo.py

RUN spack buildcache push --unsigned ./binary-mirror $(spack --color=never find --hashes clingo-bootstrap)
2 changes: 2 additions & 0 deletions clingo/scripts/install_clingo.py → clingo/install_clingo.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env spack-python

import archspec.cpu
import spack.bootstrap.config
import spack.main
Expand Down
110 changes: 0 additions & 110 deletions clingo/scripts/clingo_json.py

This file was deleted.

82 changes: 82 additions & 0 deletions generate_bootstrap_json.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#!/usr/bin/env spack-python
"""Produce a bootstrap json file for a selected package"""

import glob
import hashlib
import json
import os
import sys

import spack.deptypes as dt
import spack.spec
import spack.traverse

# Each entry in clingo.json has the following keys:
#
# "spec": root spec to be matched
# "binaries": list of tuples (pkg name, dag hash, sha256 sum)


def sha256(path):
fn = hashlib.sha256()
with open(path, "rb") as f:
fn.update(f.read())
return fn.hexdigest()


def tarball_hash(path: str):
# extract hash from /path/to/<...>-<hash>.spack
name, _ = os.path.splitext(os.path.basename(path))
return name.split("-")[-1]


def run(pkg: str, deps=dt.NONE, python: bool = False):
name = "clingo-bootstrap" if pkg == "clingo" else pkg
shas = {
tarball_hash(tarball): sha256(tarball)
for tarball in glob.glob("./build_cache/**/*.spack", recursive=True)
}

specs = [
spack.spec.Spec.from_specfile(f) for f in glob.glob("./build_cache/*.json") if name in f
]

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

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

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

mirror_info = [
{
"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)))
if not s.external
],
}
for s in specs
]

# 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)


if __name__ == "__main__":
assert len(sys.argv) == 2, f"Usage: {sys.argv[0]} <clingo|gnupg|patchelf>"
pkg = sys.argv[1]
# unfortunately we refer to clingo-bootstrap by alias "clingo"
assert pkg in ("clingo", "gnupg", "patchelf")
run(
pkg,
# 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",
)
2 changes: 1 addition & 1 deletion gnupg/Dockerfile.manylinux2014
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ ENV PATH="/root/spack/bin/:$PATH" \

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

# Set externals, locate compilers
RUN spack external find --not-buildable gawk perl
Expand Down
Loading

0 comments on commit 299786a

Please sign in to comment.