commit 0e342864d6c4c441e1302632d13bc6c399a0d6c0
parent 255c9a47218c093e27c6b7c7b3010f643b9438d7
Author: Jan Pobříslo <ccx@te2000.cz>
Date: Sat, 10 Jun 2023 18:47:46 +0200
Environment and downloads makegen
Diffstat:
5 files changed, 102 insertions(+), 36 deletions(-)
diff --git a/Makefile b/Makefile
@@ -1,12 +1,14 @@
VERSIONS:=$(HOME)/versions
-CURRENT:=$(HOME)/current
-CURRENT_ENV:=$(shell pthbs-getenvhash environments/current)
+#CURRENT:=$(HOME)/current
+#CURRENT_ENV:=$(shell pthbs-getenvhash environments/current)
+#
+#current: $(VERSIONS)/env.$(CURRENT_ENV)/.pthbs-env
+# @if cmp -s '$(VERSIONS)/env.$(CURRENT_ENV)/.pthbs-env' '$(CURRENT)/.pthbs-env'; then echo "Already installed!"; else \
+# ln -vTsf '$(VERSIONS)/env.$(CURRENT_ENV)' '$(CURRENT)' && \
+# cp -va environments/current "environments/installed.$(date +%s)" \
+# fi
-current: $(VERSIONS)/env.$(CURRENT_ENV)/.pthbs-env
- @if cmp -s '$(VERSIONS)/env.$(CURRENT_ENV)/.pthbs-env' '$(CURRENT)/.pthbs-env'; then echo "Already installed!"; else \
- ln -vTsf '$(VERSIONS)/env.$(CURRENT_ENV)' '$(CURRENT)' && \
- cp -va environments/current "environments/installed.$(date +%s)" \
- fi
+default: default.environment
$(VERSIONS)/environment.%/.env:
@echo mkdir "$$(dirname '$@')"
@@ -17,13 +19,18 @@ $(VERSIONS)/environment.%/.env:
mkdir -p '$*'
touch '$@'
-make/package.%.mk: packages/% make/.exists
+make/package.%.mk: packages/% make/.exists command/pthbs-makegen
pthbs-makegen 'packages/$*' >'$@.new'
mv '$@.new' '$@'
+make/downloads.%.mk: downloadlist.% make/.exists command/pthbs-makegen-downloads
+ pthbs-makegen-downloads '$*' 'downloadlist.$*' >'$@.new'
+ mv '$@.new' '$@'
+
+include make/downloads.sha256.mk
pkg_files=$(wildcard packages/*)
-env_files=$(wildcard environments/*)
+#env_files=$(wildcard environments/*)
mk_files=$(patsubst packages/%,make/package.%.mk,$(pkg_files))
include $(mk_files)
@@ -32,8 +39,9 @@ pycodestyle: .pycodestyle.genpkg.py
.pycodestyle.%.py: %.py
isort - <$< >$<.tmp1
+ cp -a $< $<.tmp2
black -S - <$<.tmp1 >$<.tmp2
rm $<.tmp1
- mv $<.tmp2 $<
+ if cmp -s $<.tmp2 $<; then mv $<.tmp2 $<; else rm $<.tmp2; fi
touch $@
diff --git a/command/pthbs-download b/command/pthbs-download
@@ -0,0 +1,5 @@
+#!/bin/sh
+echo >&2 "$0 not implemented yet"
+set -x
+: "$@"
+exit 1
diff --git a/command/pthbs-makegen b/command/pthbs-makegen
@@ -13,6 +13,7 @@ exec env \
basedir="$basedir" \
workdir="$workdir" \
script="$script" \
+ scriptname="${script##*/}" \
bsh="$bsh" \
package="$pthbs_package" \
awk -v single_quote="'" '
@@ -25,6 +26,10 @@ BEGIN {
sandbox = 1
dep_count = 0
env_count = 0
+ is_envfile = ENVIRON["script"] ~ /\.environment$/
+ if(is_envfile) {
+ envname = substr(ENVIRON["scriptname"], 1, length(ENVIRON["scriptname"])-12)
+ }
FS=":"
}
@@ -34,7 +39,7 @@ function q(s) { # quote string for sh
}
function fatal(msg) {
- printf "FATAL: %s %s:%d: \"%s\"\n", msg, FILENAME, FNR, $0 >"/dev/stderr"
+ printf "FATAL: pthbs-makegen: %s %s:%d: \"%s\"\n", msg, FILENAME, FNR, $0 >"/dev/stderr"
exit 1
}
@@ -54,16 +59,43 @@ function have_envdep(package) {
envdep[env_count] = "$(VERSIONS)/"package"/.install-links"
}
+function make_envfile( n, envfile, envhash) {
+ if(!env_count) {
+ fatal("environment is empty")
+ }
+ envfile = "make/package.sha256."ENVIRON["bsh"]".env"
+ for(n=1; n<=env_count; n++) {
+ print env[n] >envfile
+ }
+ close(envfile)
+ if(("pthbs-getenvhash "q(envfile) | getline) < 1) {
+ fatal("Error getting envhash from "q(envfile))
+ }
+ envhash=$0
+ if(match(envhash, "^[0-9a-f]{64}$") == 0) {
+ fatal("received invalid envhash: "q(envhash))
+ }
+ deps[++dep_count] = "$(VERSIONS)/env."envhash"/.pthbs-env"
+ printf "%s:", "$(VERSIONS)/env."envhash"/.pthbs-env"
+ for(n=1; n<=env_count; n++) {
+ printf " %s", envdep[n]
+ }
+ for(n=1; n<=env_count; n++) {
+ printf "\n\t%s", "pthbs-link "q("$(VERSIONS)/"env[n])" "q("$(VERSIONS)/env."envhash)
+ }
+ printf "\n\t%s\n\n", "sort -u <"q(envfile)" >"q("$@")
+ return envhash
+}
/^#!/ { next }
/^#\+/ {
if($0 == "#+*") {
sandbox = 0
- next
} else {
have_envdep(substr($0, 3))
}
+ next
}
-/^#@/ {
+/^#@/ && !is_envfile {
if($1 == "#@git") {
next
} else if($1 == "#@sha256") {
@@ -81,39 +113,29 @@ function have_envdep(package) {
}
next
}
-/^$/ {
+/^$/ && !is_envfile {
if(env_count) {
- envfile = "make/package.sha256."ENVIRON["bsh"]".env"
- for(n=1; n<=env_count; n++) {
- print env[n] >envfile
- }
- close(envfile)
- if(("pthbs-getenvhash "q(envfile) | getline) < 1) {
- fatal("Error getting envhash from "q(envfile))
- }
- envhash=$0
- if(match(envhash, "^[0-9a-f]{64}$") == 0) {
- fatal("received invalid envhash: "q(envhash))
- }
- deps[++dep_count] = "$(VERSIONS)/env."envhash"/.pthbs-env"
- printf "%s:", "$(VERSIONS)/env."envhash"/.pthbs-env"
- for(n=1; n<=env_count; n++) {
- printf " %s", envdep[n]
- }
- for(n=1; n<=env_count; n++) {
- printf "\n\t%s", "pthbs-link "q("$(VERSIONS)/"env[n])" "q("$(VERSIONS)/env."envhash)
- }
- printf "\n\t%s\n\n", "sort -u <"q(envfile)" >"q("$@")
-
+ make_envfile()
}
printf "%s", "$(VERSIONS)/"ENVIRON["package"]"/.install-links:"
for(n=1; n<=dep_count; n++) {
printf " %s", deps[n]
}
printf "\n\t%s\n", "pthbs-build "q(ENVIRON["script"])
+ has_body = 1
exit 0
}
{
fatal("unexpected line")
}
+END{
+ if(!is_envfile){
+ if(has_body) { exit 0 }
+ fatal("no build script present")
+ }
+ env_installdir = "$(VERSIONS)/env." make_envfile()
+ printf "%s: %s %s\n", ENVIRON["scriptname"], env_installdir"/.pthbs-env", "namedenv/.exists"
+ printf "\t%s\n\n", "busybox -sTf "q(env_installdir)" "q("namedenv/"envname)
+ printf ".PHONY: %s\n", ENVIRON["scriptname"]
+}
' "$script"
diff --git a/command/pthbs-makegen-downloads b/command/pthbs-makegen-downloads
@@ -0,0 +1,30 @@
+#!/bin/sh
+format=$1
+shift || exit $?
+exec awk -v format="$format" -v single_quote="'" '
+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: pthbs-makegen: %s %s:%d: \"%s\"\n", msg, FILENAME, FNR, $0 >"/dev/stderr"
+ exit 1
+}
+
+/^$/ { next }
+
+/^[0-9a-f]{64} [0-9]+ /{
+ printf "%s:\n", "make/file."format"."$1".downloaded"
+ printf "\tpthbs-download sha256"
+ for(n=1; n<=NF; n++){
+ printf " %s", q($n)
+ }
+ printf "\n\n"
+ next
+}
+
+{
+ fatal("unexpected line")
+}
+' "$@"
diff --git a/templates/pkg/default.environment b/templates/pkg/default.environment
@@ -0,0 +1 @@
+#+{{pkg_install_name("busybox")}}