pthbs

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

commit c6649bb39704ad5583a74c78286c09fff9ac2c75
parent 1c067b19b7c431f8edbd48b38b33812f513ffac3
Author: ccx <ccx@te2000.cz>
Date:   Fri, 25 Oct 2024 21:32:44 +0000

Generate index filelist for bundled files

Diffstat:
Acommand/pthbs-link-from-index | 24++++++++++++++++++++++++
Mcommand/pthbs-makegen | 33++++++++++++++++++++++++++++-----
Mpthbs.mk | 13+++++++------
Autil/gen-filelist-sha256 | 2++
4 files changed, 61 insertions(+), 11 deletions(-)

diff --git a/command/pthbs-link-from-index b/command/pthbs-link-from-index @@ -0,0 +1,24 @@ +#!/bin/sh -e +link_dir=$1 +shift +test -d "$link_dir" || exit 1 +exec >"$link_dir/.local.new" +for index_file in "$@"; do + exec <"$index_file" + index_base=$(realpath "$index_file") + index_base=$(dirname "$index_base") + while IFS= read -r line; do + origin=$link_dir/${line%% *} + target=${line#* } + case $target in + (/*) ;; + (*) target=$index_base/$target + esac + if test -L "$origin"; then + rm "$origin" + fi + ln -s "$target" "$origin" + done + printf '%s %s\n' "${line%% *}" "$target" +done +mv "$link_dir/.local.new" "$link_dir/.local" diff --git a/command/pthbs-makegen b/command/pthbs-makegen @@ -6,6 +6,14 @@ if test -z "$pthbs_workdir"; then printf '%s\n' >&2 "$0: fatal: pthbs_workdir env var undefined or empty" exit 100 fi +if test -z "$pthbs_cache"; then + printf '%s\n' >&2 "$0: fatal: pthbs_cache env var undefined or empty" + exit 100 +fi +if test -z "$pthbs_indexdir"; then + printf '%s\n' >&2 "$0: fatal: pthbs_indexdir env var undefined or empty" + exit 100 +fi workdir=$pthbs_workdir/builddir.$$ script=$(realpath "$1") @@ -18,12 +26,22 @@ exec env \ scriptname="${script##*/}" \ bsh="$bsh" \ package="$pthbs_package" \ + makedir="$pthbs_cache/make" \ awk -v single_quote="'" ' BEGIN { - while(getline <"downloadlist.sha256") { + downloadlist_path=ENVIRON["pthbs_indexdir"]"/downloadlist.sha256" + filelist_path=ENVIRON["pthbs_indexdir"]"/filelist.sha256" + printf "DBG: reading downloadlist: %s\n", downloadlist_path >"/dev/stderr" + while(getline <downloadlist_path) { downloadable_hashes["sha256",$1] = 1 } - close("downloadlist.sha256") + close(downloadlist_path) + + printf "DBG: reading filelist: %s\n", filelist_path >"/dev/stderr" + while(getline <filelist_path) { + linkable_hashes["sha256",$1] = 1 + } + close(filelist_path) settings["sandbox"] = 1 settings["set_path"] = 1 @@ -47,10 +65,15 @@ function fatal(msg) { } function have_file(hash_type, file_hash) { - if(!((hash_type, file_hash) in downloadable_hashes)) { + if(((hash_type, file_hash) in linkable_hashes)) { + deps[++dep_count] = "$(cache)/link/files-"hash_type"/.local" + return + } + if(((hash_type, file_hash) in downloadable_hashes)) { + deps[++dep_count] = "$(cache)/make/file."hash_type"."file_hash".downloaded" return } - deps[++dep_count] = "$(cache)/make/file."hash_type"."file_hash".downloaded" + fatal("Could not determine source for file "hash_type":"file_hash) } function have_envdep(package) { @@ -66,7 +89,7 @@ function make_envfile( n, envfile, envhash) { if(!env_count) { fatal("environment is empty") } - envfile = "$(cache)/make/package.sha256."ENVIRON["bsh"]".env" + envfile = makedir "/package.sha256."ENVIRON["bsh"]".env" for(n=1; n<=env_count; n++) { print env[n] >envfile } diff --git a/pthbs.mk b/pthbs.mk @@ -10,6 +10,7 @@ export PATH:=$(abspath $(pthbs))/command:$(PATH) export pthbs_versions:=$(versions) export pthbs_pkgdir:=$(abspath $(packages)) export pthbs_workdir:=$(abspath $(work)) +export pthbs_indexdir:=$(abspath $(index)) export pthbs_cache:=$(abspath $(cache)) no_default: @@ -24,6 +25,10 @@ $(versions)/environment.%/.env: mkdir -p '$*' touch '$@' + +$(cache)/link/files-%/.local: $(index)/filelist.% $(cache)/link/files-%/.exists + pthbs-link-from-index '$(cache)/link/files-$*/' '$(index)/filelist.$*' + $(cache)/make/package.%.mk: $(packages)/% $(cache)/make/.exists $(pthbs)/command/pthbs-makegen pthbs-makegen '$(packages)/$*' >'$@.new' mv '$@.new' '$@' @@ -32,13 +37,9 @@ $(cache)/make/downloads.%.mk: downloadlist.% $(cache)/make/.exists $(pthbs)/comm pthbs-makegen-downloads '$*' 'downloadlist.$*' >'$@.new' mv '$@.new' '$@' -include make/downloads.sha256.mk +include $(cache)/make/downloads.sha256.mk pkg_files=$(wildcard packages/*) #env_files=$(wildcard environments/*) -mk_files=$(patsubst packages/%,make/package.%.mk,$(pkg_files)) +mk_files=$(patsubst packages/%,$(cache)/make/package.%.mk,$(pkg_files)) include $(mk_files) - -ifneq (,$(filter py%,$(MAKECMDGOALS))) -include python.mk -endif diff --git a/util/gen-filelist-sha256 b/util/gen-filelist-sha256 @@ -0,0 +1,2 @@ +#!/bin/sh +busybox find "$@" -type f -print0 | busybox sort -z | busybox xargs -0 busybox sha256sum