pthbs

Packaging Through Hashed Build Scripts
git clone https://ccx.te2000.cz/git/pthbs
Log | Files | Refs | Submodules | README

commit 1cd8d329caeaea80caaa144db5d8b2c559996cc9
parent e425e6476487487de45f7f69ad2cc1bbef18c29b
Author: Jan Pobříslo <ccx@te2000.cz>
Date:   Thu, 25 May 2023 10:34:16 +0200

pthbs-build, unsandboxed build script for m-c-m

Diffstat:
A.gitignore | 2++
Acommand/pthbs-build | 87+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Apackages.aat | 45+++++++++++++++++++++++++++++++++++++++++++++
Apackages/musl-cross-make | 9+++++++++
Ascript_env.txt | 3+++
Ascript_header.txt | 11+++++++++++
6 files changed, 157 insertions(+), 0 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -0,0 +1,2 @@ +sources/by-commit +work diff --git a/command/pthbs-build b/command/pthbs-build @@ -0,0 +1,87 @@ +#!/bin/sh +set -x +bsh=$(sha256sum $1) || exit $? +bsh=${bsh%% *} +basedir=$(dirname "$(dirname "$(realpath "$0")")") +workdir=$basedir/work/builddir.$$ +script=$(realpath "$1") + +mkdir -p "$workdir" +env \ + basedir="$basedir" \ + workdir="$workdir" \ + script="$script" \ + awk -v single_quote="'" >"$workdir/pthbs-setup" ' +BEGIN { + sandbox = 1 + FS=":" + print "#!/bin/sh -xe" + print "cd "q(ENVIRON["workdir"]) +} + +function q(s) { # quote string for sh + gsub(single_quote, single_quote "\\" single_quote single_quote, s) + return single_quote s single_quote +} + +function fatal(msg) { + printf "FATAL: %s %s:%d: \"%s\"\n", msg, FILENAME, FNR, $0 >"/dev/stderr" + exit 1 +} + +function at_git(commit_id, dstdir){ + print "mkdir "q(dstdir) + print "(cd "q(ENVIRON["basedir"]"/sources/by-commit/"commit_id)" && git archive --format=tar "q(commit_id)" ) | tar --no-same-owner --no-same-permissions -xC "q(dstdir) +} + +/^#!/ { next } +/^#\+/ { + if($0 == "#+*") { + sandbox = 0 + next + } else { + fatal("dependencies not implemented yet:") + } +} +/^#@/ { + if($1 == "#@git") { + if(match($0, "^#@git:[0-9a-f]+:") == 0) { + fatal("invalid syntax for @git:") + } + at_git($2, substr($0, RLENGTH+1)) + } else { + fatal("unrecognized @command:") + } + next +} +/^$/ { + print "exec sh -xe "q(ENVIRON["script"]) + exit 0 +} +{ + fatal("unexpected line") +} +' "$1" || exit $? +cat "$workdir/pthbs-setup" + +JOBS=$(nproc) +if test -z "$JOBS"; then + JOBS=$(grep -ce '^processor' /proc/cpuinfo) + if test -z "$JOBS"; then + JOBS=1 + fi +fi + +if env -i \ + PATH="$PATH" \ + pthbs_script="$script" \ + DESTDIR="$workdir/destdir" \ + PREFIX="${0##*/}-$bsh" \ + JOBS="$JOBS" \ + sh -xe "$workdir/pthbs-setup"; then + echo "BUILD SUCCESFUL" + find "$workdir/destdir" +else + echo "BUILD FAILED: exitcode $$" + rm -r "$workdir" +fi diff --git a/packages.aat b/packages.aat @@ -0,0 +1,45 @@ +|start_package("musl-cross-make") + awk -vPWD="$PWD" '{gsub(/@@PWD@@/,PWD); print}' musl-cross-make.config.mak >musl-cross-make/config.mak.new || exit $? + mv musl-cross-make/config.mak.new musl-cross-make/config.mak || exit $? + make -C musl-cross-make -j$JOBS -l$JOBS || exit $? + make -C musl-cross-make install || exit $? +|end() +|start_package("skalibs") + git checkout --force || exit $? + git clean -fx || exit $? + ./configure --disable-shared --enable-static --enable-slashpackage="$slashpackage" || exit $? + make -j${jobs} || exit $? + make install || exit $? + make -L update || exit $? + make -L global-links || exit $? +|end() +|start_package("s6") + git checkout --force || exit $? + git clean -fx || exit $? + #patch -up 1 -i ../s6_clone_newpid.patch || exit $? + patch -up 1 -i ../s6_clone3_newpid.patch || exit $? + ./configure --disable-shared --enable-static --enable-allstatic --enable-static-libc --enable-slashpackage="$slashpackage" || exit $? + make -j${jobs} CFLAGS=-DWANT_CLONE_NEWPID || exit $? + make install || exit $? + make -L update || exit $? + make -L global-links || exit $? +|end() +@for p in packages +|start + git checkout --force || exit $? + git clean -fx || exit $? + ./configure --disable-shared --enable-static --enable-allstatic --enable-static-libc --enable-slashpackage="$slashpackage" || exit $? + make -j${jobs} || exit $? + make install || exit $? + make -L update || exit $? + make -L global-links || exit $? +|end() +@endfor +|# (cd execline && install_generic) || exit $? +|# (cd s6-rc && install_generic) || exit $? +|# (cd s6-portable-utils && install_generic) || exit $? +|# (cd s6-linux-utils && install_generic) || exit $? +|# (cd s6-linux-init && install_generic) || exit $? +|# (cd mdevd && install_generic) || exit $? +|# (cd s6-dns && install_generic) || exit $? +|# (cd s6-networking && install_generic) || exit $? diff --git a/packages/musl-cross-make b/packages/musl-cross-make @@ -0,0 +1,9 @@ +#!/usr/bin/env pthbs-build +#+* +#@git:fe915821b652a7fa37b34a596f47d8e20bc72338:musl-cross-make + +export TARGET=x86_64-linux-musl +export OUTPUT=$DESTDIR/$PREFIX +: ${JOBS:=1} +make -C musl-cross-make -j$JOBS -l$JOBS || exit $? +make -C musl-cross-make install || exit $? diff --git a/script_env.txt b/script_env.txt @@ -0,0 +1,3 @@ +DESTDIR=./destdir # where files get copied to +PREFIX=/versions/package-XXXX # final installation dir? +MAKE_JOBS/NPROCS diff --git a/script_header.txt b/script_header.txt @@ -0,0 +1,11 @@ +package dependency +file hash +git commit hash + +--- +#!/usr/bin/env pthbs-build +#+package-name +#@git:commit-hash:dirname +#@sha256:file-hash:filename +<mandatory empty line> +script start