-
Notifications
You must be signed in to change notification settings - Fork 17
modular sqfs #224
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
simonpintarelli
wants to merge
9
commits into
main
Choose a base branch
from
feat/modular-sqfs
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
modular sqfs #224
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
97716ec
typo
simonpintarelli eff1127
remove duplicate target
simonpintarelli b99664b
modular uenv
simonpintarelli a51de61
remove unused Makefiler.compilers
simonpintarelli edbd6d1
Merge remote-tracking branch 'origin/main' into feat/modular-sqfs
simonpintarelli 0f932c7
format
simonpintarelli bc8bf63
cleanup
simonpintarelli 9f9c85f
cleanup
simonpintarelli 146b453
delete unused templates
simonpintarelli File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,21 @@ | ||
#!/bin/bash | ||
|
||
set -euo pipefail | ||
args=() | ||
shopt -s dotglob | ||
|
||
# from /user-environment/foo/bar/baz store /user-environment as _top_level | ||
_top_level=$(echo $STORE | cut -d "/" -f 2 | xargs printf "/%s") | ||
|
||
for d in /*; do | ||
# skip STORE | ||
if [ "$d" = "${_top_level}" ]; then | ||
continue | ||
fi | ||
# skip invalid symlinks, as they will break bwrap | ||
if [ ! -L "$d" ] || [ -e "$d" ]; then | ||
args+=("--dev-bind" "$d" "$d") | ||
fi | ||
done | ||
PS1="\[\e[36;1m\]build-env >>> \[\e[0m\]" bwrap "${args[@]}" "$@" | ||
|
||
PS1="\[\e[36;1m\]build-env >>> \[\e[0m\]" bwrap "${args[@]}" "$@" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/bin/bash | ||
|
||
set -euo pipefail | ||
|
||
mkdir -p $STORE | ||
|
||
bwrap --dev-bind / / \ | ||
--bind ${BUILD_ROOT}/store $STORE \ | ||
-- "$@" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
#!/usr/bin/python3 | ||
|
||
import argparse | ||
import json | ||
import subprocess | ||
import pathlib | ||
import yaml | ||
|
||
|
||
def compiler_extra_attributes(name, prefix): | ||
"""Find paths to compiler""" | ||
if name == "gcc": | ||
cc = "gcc" | ||
cxx = "g++" | ||
f90 = "gfortran" | ||
elif name == "llvm": | ||
cc = "clang" | ||
cxx = "clang++" | ||
f90 = None | ||
elif name == "nvhpc": | ||
cc = "nvc" | ||
cxx = "nvc++" | ||
f90 = "nvfortran" | ||
else: | ||
# this is not a compiler | ||
return {} | ||
|
||
def find(comp): | ||
p = subprocess.run( | ||
["find", prefix, "-name", f"{comp}", "-path", "*/bin/*"], | ||
shell=False, | ||
check=True, | ||
stdout=subprocess.PIPE, | ||
stderr=subprocess.PIPE, | ||
) | ||
return p.stdout.strip().decode("utf-8") | ||
|
||
extra_attributes = {"extra_attributes": {"compilers": {"c": find(cc), "cxx": find(cxx)}}} | ||
if f90 is not None: | ||
extra_attributes["extra_attributes"]["compilers"]["fortran"] = find(f90) | ||
|
||
return extra_attributes | ||
|
||
|
||
def gen_packages_impl(lock_file, env_path): | ||
spack_lock = json.load(open(lock_file, "r")) | ||
|
||
packages = {"packages": {}} | ||
|
||
for dd in spack_lock["roots"]: | ||
hash = dd["hash"] | ||
# call subprocess to find install dir | ||
spack_find_prefix = subprocess.run( | ||
["spack", "--color=never", "-e", env_path, "find", "--format={prefix}", f"/{hash}"], | ||
shell=False, | ||
check=True, | ||
stdout=subprocess.PIPE, | ||
stderr=subprocess.PIPE, | ||
) | ||
|
||
spack_find_spec = subprocess.run( | ||
["spack", "--color=never", "-e", env_path, "find", "--format={name}|{version}|{variants}", f"/{hash}"], | ||
shell=False, | ||
check=True, | ||
stdout=subprocess.PIPE, | ||
stderr=subprocess.PIPE, | ||
) | ||
|
||
name, version, variants = spack_find_spec.stdout.strip().decode("utf-8").split("|") | ||
prefix = spack_find_prefix.stdout.strip().decode("utf-8") | ||
|
||
packages["packages"][name] = { | ||
"buildable": False, | ||
"externals": [ | ||
{ | ||
"spec": f"{name}@{version} {variants}", | ||
"prefix": prefix, | ||
} | ||
], | ||
} | ||
# add `extra_attributes` for compilers | ||
if name in ["gcc", "nvhpc", "llvm"]: | ||
extra_attributes = compiler_extra_attributes(name, prefix) | ||
packages["packages"][name]["externals"][0].update(extra_attributes) | ||
|
||
return packages | ||
|
||
|
||
if __name__ == "__main__": | ||
# parse CLI arguments | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument("--lock-file", help="spack.lock", type=str) | ||
parser.add_argument("--env-path", help="path to spack env", type=str) | ||
parser.add_argument("--view", help="path to spack view", type=str) | ||
|
||
args = parser.parse_args() | ||
|
||
packages = gen_packages_impl(args.lock_file, args.env_path) | ||
|
||
dst = pathlib.Path(args.view) / "packages.yaml" | ||
with open(dst, "w") as f: | ||
yaml.dump(packages, f) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#!/bin/bash | ||
# Function to display usage | ||
usage() { | ||
echo "Usage: $0 --build-root=<build-root> --sqfs-images '<sqfs1>:<mnt1> <sqfs2>:<mnt2> ..' -- <command>" | ||
exit 1 | ||
} | ||
|
||
# Initialize variables | ||
BUILD_ROOT="" | ||
SQFS_IMAGES="" | ||
|
||
# Parse options using getopt | ||
TEMP=$(getopt -o '' --long build-root: --long sqfs-images: -n "$0" -- "$@") | ||
if [ $? -ne 0 ]; then | ||
echo "Error parsing arguments" >&2 | ||
usage | ||
fi | ||
|
||
# Reset the positional parameters to the short options | ||
eval set -- "$TEMP" | ||
|
||
# Extract options | ||
while true; do | ||
case "$1" in | ||
--build-root) | ||
BUILD_ROOT="$2" | ||
shift 2 | ||
;; | ||
--sqfs-images) | ||
SQFS_IMAGES="$2" | ||
shift 2 | ||
;; | ||
--) | ||
shift | ||
break | ||
;; | ||
*) | ||
echo "Unknown option: $1" | ||
usage | ||
;; | ||
esac | ||
done | ||
|
||
if [ -z "$BUILD_ROOT" ]; then | ||
echo "Error: --build-root is required" >&2 | ||
usage | ||
fi | ||
|
||
if [ -z "$SQFS_IMAGES" ]; then | ||
# no images to mount, skip squashfs-mount | ||
exec "$@" | ||
fi | ||
|
||
read -ra array <<<"$SQFS_IMAGES" | ||
|
||
if [ ${#array[@]} -eq 0 ]; then | ||
echo "no mountpoints specified, skip squashfs-mount" | ||
exec "$@" | ||
fi | ||
|
||
build_root_mounts="" | ||
for elem in "${array[@]}"; do | ||
mount_point=${elem#*:} | ||
sqfs=${elem%%:*} | ||
tmp_mount_point="${BUILD_ROOT}/tmp/mounts/${mount_point}" | ||
mkdir -p ${tmp_mount_point} | ||
build_root_mounts="${build_root_mounts} ${sqfs}:${tmp_mount_point}" | ||
done | ||
|
||
squashfs-mount $build_root_mounts -- "$@" |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor: formatting to be fixed?