Validate real FreeBSD package builds
This commit is contained in:
216
tests/guix/run-phase6-real-package-build.sh
Executable file
216
tests/guix/run-phase6-real-package-build.sh
Executable file
@@ -0,0 +1,216 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
|
||||
repo_root=$(CDPATH= cd -- "$(dirname "$0")/../.." && pwd)
|
||||
metadata_target=${METADATA_OUT:-}
|
||||
|
||||
cleanup=0
|
||||
if [ -n "${WORKDIR:-}" ]; then
|
||||
workdir=$WORKDIR
|
||||
mkdir -p "$workdir"
|
||||
else
|
||||
workdir=$(mktemp -d /tmp/fruix-phase6-real-package.XXXXXX)
|
||||
cleanup=1
|
||||
fi
|
||||
if [ "${KEEP_WORKDIR:-0}" -eq 1 ]; then
|
||||
cleanup=0
|
||||
fi
|
||||
|
||||
setup_metadata=$workdir/setup-metadata.txt
|
||||
setup_env=$workdir/setup-env.sh
|
||||
metadata_file=$workdir/phase6-real-package-metadata.txt
|
||||
daemon_socket=$workdir/guix-daemon.sock
|
||||
daemon_log=$workdir/guix-daemon.log
|
||||
fetch_tarball=$workdir/hello-2.12.3.tar.gz
|
||||
build_stdout=$workdir/fruix-build.out
|
||||
build_stderr=$workdir/fruix-build.err
|
||||
references_log=$workdir/references.log
|
||||
package_template=$workdir/phase6-hello.scm.in
|
||||
package_file=$workdir/phase6-hello.scm
|
||||
|
||||
daemon_pid=
|
||||
cleanup_workdir() {
|
||||
if [ -n "$daemon_pid" ]; then
|
||||
sudo kill "$daemon_pid" >/dev/null 2>&1 || true
|
||||
wait "$daemon_pid" 2>/dev/null || true
|
||||
fi
|
||||
rm -f "$daemon_socket"
|
||||
if [ "$cleanup" -eq 1 ]; then
|
||||
rm -rf "$workdir"
|
||||
fi
|
||||
}
|
||||
trap cleanup_workdir EXIT INT TERM
|
||||
|
||||
fetch -o "$fetch_tarball" https://ftp.gnu.org/gnu/hello/hello-2.12.3.tar.gz >/dev/null
|
||||
[ "$(sha256 -q "$fetch_tarball")" = '0d5f60154382fee10b114a1c34e785d8b1f492073ae2d3a6f7b147687b366aa0' ] || {
|
||||
echo "unexpected hello tarball hash" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
WORKDIR=$workdir/setup KEEP_WORKDIR=1 \
|
||||
METADATA_OUT=$setup_metadata ENV_OUT=$setup_env \
|
||||
"$repo_root/tests/guix/setup-phase5-checkout.sh" >"$workdir/setup.log" 2>&1
|
||||
|
||||
# shellcheck disable=SC1090
|
||||
. "$setup_env"
|
||||
|
||||
cd "$PHASE5_BUILDDIR"
|
||||
export LD_LIBRARY_PATH GUILE_LOAD_PATH GUILE_LOAD_COMPILED_PATH GUILE_EXTENSIONS_PATH
|
||||
export GUILE_AUTO_COMPILE=0
|
||||
|
||||
cat >"$package_template" <<'EOF'
|
||||
(use-modules (gnu packages base)
|
||||
(guix packages)
|
||||
(guix build-system)
|
||||
(guix store)
|
||||
(guix monads)
|
||||
(guix gexp)
|
||||
(guix derivations))
|
||||
|
||||
(define source-file "__SOURCE_FILE__")
|
||||
(define source-item
|
||||
(local-file source-file "hello-2.12.3.tar.gz"))
|
||||
|
||||
(define* (phase6-lower name #:key source inputs native-inputs outputs system target #:allow-other-keys)
|
||||
(bag
|
||||
(name name)
|
||||
(system system)
|
||||
(target target)
|
||||
(host-inputs `(,@(if source `(("source" ,source)) '()) ,@inputs))
|
||||
(build-inputs native-inputs)
|
||||
(outputs outputs)
|
||||
(build phase6-build)
|
||||
(arguments `(#:source ,source #:package-name ,name))))
|
||||
|
||||
(define* (phase6-build name inputs #:key source (outputs '("out")) (system (%current-system)) #:allow-other-keys)
|
||||
(mlet* %store-monad ((shell (interned-file "/bin/sh" "sh" #:recursive? #t))
|
||||
(source* (lower-object source system))
|
||||
(builder (text-file "phase6-hello-builder.sh"
|
||||
"#!/bin/sh
|
||||
set -eu
|
||||
export PATH=/bin:/usr/bin:/usr/local/bin
|
||||
src_tar=\"$1\"
|
||||
/bin/mkdir -p \"$TMPDIR/phase6-build\"
|
||||
cd \"$TMPDIR/phase6-build\"
|
||||
/usr/bin/tar -xf \"$src_tar\"
|
||||
cd hello-2.12.3
|
||||
export CC=/usr/bin/cc
|
||||
export CONFIG_SHELL=/bin/sh
|
||||
export CPPFLAGS='-I/usr/local/include'
|
||||
export LDFLAGS='-L/usr/local/lib -Wl,-rpath,/usr/local/lib'
|
||||
./configure --prefix=\"$out\"
|
||||
/usr/local/bin/gmake -j1
|
||||
/usr/local/bin/gmake -j1 check
|
||||
/usr/local/bin/gmake -j1 install
|
||||
/bin/mkdir -p \"$out/share/fruix-phase6\"
|
||||
printf '%s\\n' \"$src_tar\" > \"$out/share/fruix-phase6/source-store-path.txt\"
|
||||
"
|
||||
(list (if (derivation? source*)
|
||||
(derivation->output-path source*)
|
||||
source*)))))
|
||||
(lambda (store)
|
||||
(values (derivation store name shell
|
||||
(list "-e" builder
|
||||
(if (derivation? source*)
|
||||
(derivation->output-path source*)
|
||||
source*))
|
||||
#:env-vars '(("HOME" . "/homeless")
|
||||
("PATH" . "/bin:/usr/bin:/usr/local/bin"))
|
||||
#:inputs `(,@(if (derivation? source*) `((,source*)) '())
|
||||
(,shell) (,builder))
|
||||
#:sources `(,shell ,builder)
|
||||
#:system system
|
||||
#:outputs outputs)
|
||||
store))))
|
||||
|
||||
(define phase6-build-system
|
||||
(build-system
|
||||
(name 'phase6-freebsd-host-gnu)
|
||||
(description "Phase 6 FreeBSD host GNU build system")
|
||||
(lower phase6-lower)))
|
||||
|
||||
(package/inherit hello
|
||||
(source source-item)
|
||||
(build-system phase6-build-system)
|
||||
(supported-systems (list (%current-system))))
|
||||
EOF
|
||||
|
||||
sed "s|__SOURCE_FILE__|$fetch_tarball|g" "$package_template" > "$package_file"
|
||||
|
||||
sudo env GUIX_DAEMON_SOCKET=unix://$daemon_socket \
|
||||
"$PHASE5_GUIX_DAEMON" --disable-chroot --listen "$daemon_socket" --no-substitutes \
|
||||
>"$daemon_log" 2>&1 &
|
||||
daemon_pid=$!
|
||||
for _ in 1 2 3 4 5 6 7 8 9 10; do
|
||||
[ -S "$daemon_socket" ] && break
|
||||
sleep 1
|
||||
done
|
||||
[ -S "$daemon_socket" ] || {
|
||||
echo "daemon socket was not created: $daemon_socket" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
GUIX_DAEMON_SOCKET=unix://$daemon_socket \
|
||||
./pre-inst-env fruix build -f "$package_file" >"$build_stdout" 2>"$build_stderr"
|
||||
|
||||
out_path=$(awk 'NF { last = $0 } END { print last }' "$build_stdout")
|
||||
drv_path=$(sed -n 's/^successfully built //p' "$build_stderr" | tail -n 1)
|
||||
source_store_path=$(tr -d '\n' < "$out_path/share/fruix-phase6/source-store-path.txt")
|
||||
runtime_output=$("$out_path/bin/hello")
|
||||
GUIX_DAEMON_SOCKET=unix://$daemon_socket \
|
||||
./pre-inst-env fruix gc --references "$out_path" >"$references_log" 2>"$workdir/fruix-gc.err"
|
||||
|
||||
[ -n "$drv_path" ] || { echo "missing derivation path in $build_stderr" >&2; exit 1; }
|
||||
case "$drv_path" in
|
||||
/frx/store/*.drv) : ;;
|
||||
*) echo "unexpected derivation path: $drv_path" >&2; exit 1 ;;
|
||||
esac
|
||||
case "$out_path" in
|
||||
/frx/store/*-hello-2.12.3) : ;;
|
||||
*) echo "unexpected output path: $out_path" >&2; exit 1 ;;
|
||||
esac
|
||||
case "$source_store_path" in
|
||||
/frx/store/*-hello-2.12.3.tar.gz) : ;;
|
||||
*) echo "unexpected source store path: $source_store_path" >&2; exit 1 ;;
|
||||
esac
|
||||
[ "$runtime_output" = 'Hello, world!' ] || {
|
||||
echo "unexpected runtime output: $runtime_output" >&2
|
||||
exit 1
|
||||
}
|
||||
grep -Fx "$source_store_path" "$references_log" >/dev/null || {
|
||||
echo "source store path was not preserved as a reference" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
cat >"$metadata_file" <<EOF
|
||||
workdir=$workdir
|
||||
setup_metadata=$setup_metadata
|
||||
setup_env=$setup_env
|
||||
phase5_builddir=$PHASE5_BUILDDIR
|
||||
daemon_socket=$daemon_socket
|
||||
daemon_log=$daemon_log
|
||||
fetch_tarball=$fetch_tarball
|
||||
package_file=$package_file
|
||||
build_stdout=$build_stdout
|
||||
build_stderr=$build_stderr
|
||||
references_log=$references_log
|
||||
drv_path=$drv_path
|
||||
out_path=$out_path
|
||||
source_store_path=$source_store_path
|
||||
runtime_output=$runtime_output
|
||||
frontend_invocation=./pre-inst-env fruix build -f $package_file
|
||||
EOF
|
||||
|
||||
if [ -n "$metadata_target" ]; then
|
||||
mkdir -p "$(dirname "$metadata_target")"
|
||||
cp "$metadata_file" "$metadata_target"
|
||||
fi
|
||||
|
||||
printf 'PASS phase6-real-package-build\n'
|
||||
printf 'Work directory: %s\n' "$workdir"
|
||||
printf 'Metadata file: %s\n' "$metadata_file"
|
||||
if [ -n "$metadata_target" ]; then
|
||||
printf 'Copied metadata to: %s\n' "$metadata_target"
|
||||
fi
|
||||
printf '%s\n' '--- metadata ---'
|
||||
cat "$metadata_file"
|
||||
Reference in New Issue
Block a user