commit cb08d18284b5d538ef02b4e3bd74da45ccfab8ab
parent 768b584650bb7387759d41077a93f2ac27f59e4b
Author: Jan Pobříslo <ccx@te2000.cz>
Date: Wed, 7 Jun 2023 18:52:50 +0200
Convert existing packages to templated format
Diffstat:
5 files changed, 122 insertions(+), 17 deletions(-)
diff --git a/genpkg.py b/genpkg.py
@@ -16,7 +16,9 @@ class Main:
autoescape=False,
)
self.env.globals["pkg_sha256"] = self.pkg_sha256
- self.rendered = {}
+ self.env.globals["pkg_install_name"] = self.pkg_install_name
+ self.env.globals["pkg_install_dir"] = self.pkg_install_dir
+ self.package_hashes = {}
self.rendering = []
def load_vars_yaml(self, fname="vars.yaml"):
@@ -24,19 +26,38 @@ class Main:
self.env.globals.update(yaml.safe_load(f))
def pkg_sha256(self, name):
- return hashlib.sha256(self.render_pkg(name)).hexdigest()
-
- def render_pkg(self, name):
- if name in self.rendered:
- return self.rendered[name]
+ if name in self.package_hashes:
+ return self.package_hashes[name]
if name in self.rendering:
raise RuntimeError("circular dependency: %r", self.rendering)
+
t = self.env.get_template("pkg/" + name)
self.rendering.append(name)
- self.rendered[name] = bytes(t.render().encode('utf8'))
+ data = bytes(t.render().encode('utf8'))
+ self.package_hashes[name] = hashlib.sha256(data).hexdigest()
lastname = self.rendering.pop()
assert name == lastname
- return self.rendered[name]
+
+ out_path = self.out_dir / name
+ old_hash = None
+ if out_path.exists():
+ with out_path.open('rb') as f:
+ old_hash = hashlib.file_digest(f, "sha256").hexdigest()
+ if old_hash is None or old_hash != self.package_hashes[name]:
+ tmp_path = out_path.with_suffix('.new')
+ tmp_path.write_bytes(data)
+ tmp_path.replace(out_path)
+
+ return self.package_hashes[name]
+
+ def pkg_install_name(self, name):
+ return "%s.%s" % (name.split(":")[0], self.pkg_sha256(name))
+
+ def pkg_install_dir(self, name):
+ return os.path.join(
+ self.env.globals["versions"],
+ self.pkg_install_name(name),
+ )
def list_packages(self):
for tplname in self.env.list_templates():
@@ -48,7 +69,7 @@ class Main:
def render_all(self):
for pkgname in self.list_packages():
- print("%s:\t%s" % (pkgname, self.pkg_sha256(pkgname)))
+ print("%s\t%s" % (pkgname, self.pkg_sha256(pkgname)))
if __name__ == '__main__':
@@ -58,6 +79,3 @@ if __name__ == '__main__':
m.load_vars_yaml()
pp(m.env.list_templates(filter_func=lambda name: "/." not in name))
m.render_all()
- os.write(1, b"\n\n---\n")
- os.write(1, m.rendered["musl-cross-make:bootstrap"])
- os.write(1, b"---\n")
diff --git a/templates/genlinks b/templates/genlinks
@@ -2,13 +2,11 @@
{%- block body -%}
{%- block script %}
{% endblock %}
-cd "$pthbs_destdir/{{versions}}/$pthbs_package"
+cd "$pthbs_destdir{{versions}}/$pthbs_package"
find -type d -o -print | awk -F/ '
BEGIN {
-{% block genlinks_begin %}
- x["./bin/{{triplet}}-g++"]=1
- x["./bin/{{triplet}}-gcc"]=1
-{% endblock %}
+{%- block genlinks_begin %}
+{% endblock -%}
}
function r1(s) {
diff --git a/templates/pkg/busybox b/templates/pkg/busybox
@@ -0,0 +1,34 @@
+{% extends "base" %}
+{%- block body %}
+#+*
+#+{{pkg_install_name("musl-cross-make:bootstrap")}}
+#+{{pkg_install_name("gnu-make:bootstrap")}}
+#+{{pkg_install_name("busybox:bootstrap")}}
+#@git:aa4d303a3139107919f73cece4eaf85a7dc75db6:busybox
+#@sha256:e653a2f29743ec8f96d68f62c4db7c76db5ff769ec9e7cd6671397c7cc2b942f:busybox/.config
+
+: ${JOBS:=1}
+mcm={{pkg_install_dir("musl-cross-make:bootstrap")}}
+make={{pkg_install_dir("gnu-make:bootstrap")}}
+bb={{pkg_install_dir("busybox:bootstrap")}}
+
+export PATH="$bb/bin:$mcm/bin:$make/bin"
+export CC="$mcm/bin/x86_64-linux-musl-gcc"
+export CXX="$mcm/bin/x86_64-linux-musl-g++"
+export CFLAGS="-D_GNU_SOURCE"
+export LDFLAGS="-static"
+
+cd busybox
+$make/bin/make V=1 LDFLAGS=-static HOSTLDFLAGS=-static \
+ HOSTCC="$CC -static" CC="$CC -static" HOSTCFLAGS=-D_GNU_SOURCE -j$JOBS
+
+mkdir -p "$pthbs_destdir{{versions}}/$pthbs_package/command"
+cp -a busybox "$pthbs_destdir{{versions}}/$pthbs_package/command/"
+cd "$pthbs_destdir{{versions}}/$pthbs_package"
+echo false | ./command/busybox --list >/dev/null # test if it works
+./command/busybox --list | awk '
+{ print "./command/busybox\t./command/busybox" $0 }
+END { print "./command/busybox\t./command/busybox" }
+' >.install-links.new
+mv .install-links.new .install-links
+{% endblock %}
diff --git a/templates/pkg/busybox:bootstrap b/templates/pkg/busybox:bootstrap
@@ -0,0 +1,30 @@
+{% extends "base" %}
+{%- block body %}
+#+*
+#@git:aa4d303a3139107919f73cece4eaf85a7dc75db6:busybox
+#@sha256:e653a2f29743ec8f96d68f62c4db7c76db5ff769ec9e7cd6671397c7cc2b942f:busybox/.config
+
+: ${JOBS:=1}
+mcm={{pkg_install_dir("musl-cross-make:bootstrap")}}
+make={{pkg_install_dir("gnu-make:bootstrap")}}
+
+export PATH="$mcm/bin:$make/bin:$PATH"
+export CC="$mcm/bin/x86_64-linux-musl-gcc"
+export CXX="$mcm/bin/x86_64-linux-musl-g++"
+export CFLAGS="-D_GNU_SOURCE"
+export LDFLAGS="-static"
+
+cd busybox
+$make/bin/make V=1 LDFLAGS=-static HOSTLDFLAGS=-static \
+ HOSTCC="$CC -static" CC="$CC -static" HOSTCFLAGS=-D_GNU_SOURCE -j$JOBS
+
+mkdir -p "$pthbs_destdir{{versions}}/$pthbs_package/command"
+cp -a busybox "$pthbs_destdir{{versions}}/$pthbs_package/command/"
+cd "$pthbs_destdir{{versions}}/$pthbs_package"
+echo false | ./command/busybox --list >/dev/null # test if it works
+./command/busybox --list | awk '
+{ print "./command/busybox\t./command/busybox" $0 }
+END { print "./command/busybox\t./command/busybox" }
+' >.install-links.new
+mv .install-links.new .install-links
+{% endblock %}
diff --git a/templates/pkg/gnu-make:bootstrap b/templates/pkg/gnu-make:bootstrap
@@ -0,0 +1,25 @@
+{% extends "genlinks" %}
+{%- block script %}
+#+*
+#@untar:-vz:sha256:dd16fb1d67bfab79a72f5e8390735c49e3e8e70b4945a15ab1f81ddb78658fb3:.
+
+: ${JOBS:=1}
+pthbs_versions=/home/ccx/versions
+mcm={{versions}}/musl-cross-make.{{pkg_sha256("musl-cross-make:bootstrap")}}
+
+export PATH="$mcm/bin:$PATH"
+export CC="$mcm/bin/x86_64-linux-musl-gcc"
+export CXX="$mcm/bin/x86_64-linux-musl-g++"
+export CFLAGS="-D_GNU_SOURCE"
+export LDFLAGS="-static"
+
+cd make-4.4.1
+./configure -C --prefix="$pthbs_versions/$pthbs_package" --build="$($CC -dumpmachine)" --disable-nls
+
+make -j$JOBS -l$(1+JOBS)
+make DESTDIR="$pthbs_destdir" install-strip
+{% endblock %}
+{% block genlinks_begin %}
+ x["./bin/make"]=1
+ x["./share/man/man1/make.1"]=1
+{% endblock %}