commit 26fa36f36e9f0d12e23d8827cedf303d7f998f4a
parent e74cb04ee80230b9864289a2232ca2e9006b3127
Author: Jan Pobrislo <ccx@te2000.cz>
Date: Wed, 19 Mar 2025 01:14:16 +0000
Support generating build variants
Diffstat:
3 files changed, 29 insertions(+), 4 deletions(-)
diff --git a/Makefile b/Makefile
@@ -1,2 +1,3 @@
default: pycodestyle
+cache:=../cache
include genpkgpy.mk
diff --git a/genpkg.py b/genpkg.py
@@ -88,6 +88,8 @@ class Main:
argument_parser.add_argument('-T', '--template-dir', default='templates')
argument_parser.add_argument('-I', '--index-dir', default='.')
argument_parser.add_argument('-C', '--cache-dir', default='cache')
+ argument_parser.add_argument('-V', '--vars-file', default='vars.yaml')
+ argument_parser.add_argument('-M', '--write-mkfile')
def __init__(self, out_dir, template_dir, index_dir, cache_dir):
assert isinstance(out_dir, Path)
@@ -114,17 +116,27 @@ class Main:
@classmethod
def from_argv(cls, args=None):
args = cls.argument_parser.parse_args(args)
- return cls(
+ obj = cls(
out_dir=Path(args.package_dir),
template_dir=Path(args.template_dir),
index_dir=Path(args.index_dir),
cache_dir=Path(args.cache_dir),
)
+ obj.load_vars_yaml(args.vars_file)
+ if args.write_mkfile:
+ obj.write_mkfile(args.write_mkfile)
+ return obj
- def load_vars_yaml(self, fname="vars.yaml"):
+ def load_vars_yaml(self, fname):
with open(fname) as f:
self.env.globals.update(yaml.safe_load(f))
+ def write_mkfile(self, fname):
+ t = self.env.from_string('versions:={{versions}}\npackages:={{packages}}\n')
+ with open(fname + '.new', 'wt') as f:
+ f.write(t.render(packages=self.out_dir))
+ os.rename(fname + '.new', fname)
+
def pkg_env_sha256(self, name):
current = self.rendering[-1]
if current not in self.deps:
@@ -206,7 +218,6 @@ class Main:
if __name__ == '__main__':
m = Main.from_argv()
- m.load_vars_yaml()
m.render_all()
# pylama:linters=pycodestyle,pyflakes:ignore=D212,D203,D100,D101,D102,D105,D107
diff --git a/genpkgpy.mk b/genpkgpy.mk
@@ -1,6 +1,7 @@
PYTHON_EXE?=python3
pthbs_genpkgpy?=.
-cache?=../cache
+cache?=cache
+variants?=variants
# re-evaluate each time because there's no sensible way to check
# whether the python interpreter changed
@@ -39,6 +40,18 @@ py-genpkg: $(VENV)/.done $(cache)/link/git-commit-sha1/.local $(cache)/link/file
--index-dir='$(index)' \
--cache-dir='$(cache)'
+py-genpkgall: $(VENV)/.done $(cache)/link/git-commit-sha1/.local $(cache)/link/file-sha256/.local
+ for varsfile in '$(variants)'/*.yaml; do \
+ mkdir -p "$${varsfile%.yaml}" && \
+ '$(VENV)/bin/python' $(pthbs_genpkgpy)/genpkg.py \
+ --vars-file="$${varsfile}" \
+ --write-mkfile="$${varsfile%.yaml}.mk" \
+ --package-dir="$${varsfile%.yaml}" \
+ --template-dir='$(templates)' \
+ --index-dir='$(index)' \
+ --cache-dir='$(cache)' || exit $$?; \
+ done
+
# -- requirement file rules
$(PY_REQ): $(pthbs_genpkgpy)/py-requirements.in $(VENV)/bin/pip-compile