miniroon

Simplistic macaroon-based authorization for Unix systems
git clone https://ccx.te2000.cz/git/miniroon
Log | Files | Refs | README

commit 04ac4016e6cc410962e332aa9e3a5f830e41440b
parent 80c588299bd369e945956b119bf06054128870e3
Author: Jan Pobrislo <ccx@te2000.cz>
Date:   Sun, 11 May 2025 23:36:47 +0000

Alter build scripts to the new layout

Diffstat:
M.gitignore | 4++++
Abuild_scripts/make_vars.py | 83+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/build.mk | 34++++++++++++++++------------------
Msrc/cmd_test.c | 11+++++++++++
4 files changed, 114 insertions(+), 18 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -2,3 +2,7 @@ *.sw[op] build tags +build_info +venv +virtualenvs +wheels diff --git a/build_scripts/make_vars.py b/build_scripts/make_vars.py @@ -0,0 +1,83 @@ +#!/usr/bin/env python + +from __future__ import ( + absolute_import, + division, + generators, + print_function, + with_statement, +) + +import os +import sys + +try: + import venv +except ImportError: + venv = None + +try: + from packaging.tags import sys_tags + + def get_tag(): + tag = sys_tags().__next__() + return (tag.interpreter, tag.abi, tag.platform) + +except ImportError: + from wheel.pep425tags import get_abbr_impl, get_abi_tag, get_impl_ver, get_platform + + # sporked from wheel.bdist_wheel.get_tag + def get_tag(): + """Get the specific implementation name in a wheel-compatible format.""" + plat_name = get_platform().replace('-', '_').replace('.', '_') + impl_name = get_abbr_impl() + impl_ver = get_impl_ver() + impl = impl_name + impl_ver + abi_tag = str(get_abi_tag()).lower() + tag = (impl, abi_tag, plat_name) + return tag + + +PY2 = sys.version_info[0] == 2 + + +def main(mk_dir): + tag = '%s-%s-%s' % get_tag() + mk_filename = '%s/python_vars_%s.mk' % (mk_dir, tag) + os.makedirs(mk_dir, exist_ok=True) + with open(mk_filename, 'wt') as f: + # TODO: add proper escaping whenever I feel like staring into the abyss + f.write('PYTHON_IMPL:=%s\n' % tag) + + f.write( + "PYTHON_VENV:=%s\n" + % ( + "virtualenv -p $(PYTHON_EXE)" + if venv is None + else "$(PYTHON_EXE) -m venv" + ) + ) + + f.write( + "PYTHON_VENV_INSTALL:=%s\n" + % ("'setuptools<45.0.0' 'pip<20.3' 'pip-tools<6'" if PY2 else "'pip-tools'") + ) + print("include %s" % mk_filename) + + +def usage(exitcode=100): + sys.stderr.write('usage: make_vars.py directory\n') + sys.exit(exitcode) + + +if __name__ == '__main__': + if len(sys.argv) < 2: + sys.stderr.write('make_vars.py: fatal: too few arguments\n') + usage() + if len(sys.argv) > 2: + sys.stderr.write('make_vars.py: fatal: too many arguments\n') + usage() + main(sys.argv[1]) + +# pylama:linters=pycodestyle,pyflakes:ignore=D212,D203,D100,D101,D102,D107 +# vim: fileencoding=utf-8 ft=python et sw=4 ts=4 sts=4 tw=79 diff --git a/src/build.mk b/src/build.mk @@ -1,40 +1,38 @@ -all: tools -.PHONY: all - miniroon_tool_names:=read verify test -tools:=$(patsubst %,build/miniroon-%,$(miniroon_tool_names)) +tools:=$(patsubst %,$(build_dir)/miniroon-%,$(miniroon_tool_names)) tools: $(tools) .PHONY: tools define miniroon_autolink = -include build/cmd_$(1).c.deps.mk -build/miniroon-$(1): $$(LINKDEP_cmd_$(1)__c) ../link build/cmd_$(1).c.deps.mk - ../link -o '$$@' $$(LINKDEP_cmd_$(1)__c) +include $$(build_dir)/cmd_$(1).c.deps.mk +$$(build_dir)/miniroon-$(1): $$(LINKDEP_cmd_$(1)__c) $$(build_scripts)/link $$(build_dir)/cmd_$(1).c.deps.mk + $$(build_scripts)/link -o '$$@' $$(LINKDEP_cmd_$(1)__c) endef $(foreach var,$(miniroon_tool_names),$(eval $(call miniroon_autolink,$(var)))) clean: - rm -r $(tools) build + rm -r $(tools) $(build_dir) .PHONY: clean -test: build/miniroon-test - cd ../test && ../src/build/miniroon-test -v +test: $(build_dir)/miniroon-test + env TEST_DIR='$(test_dir)' $(build_dir)/miniroon-test -v + .PHONY: test ## pattern rules: -%_perfhash.c %_perfhash.h: %_perfhash.txt ../genhash - ../genhash '$*_perfhash' '$<' +%_perfhash.c %_perfhash.h: %_perfhash.txt $(build_scripts)/genhash + $(build_scripts)/genhash '$*_perfhash' '$<' -build/%.c.i: %.c ../cc build/.exists - ../cc -E -C -o '$@' '$*.c' +$(build_dir)/%.c.i: %.c $(build_scripts)/cc $(build_dir)/.exists + $(build_scripts)/cc -E -C -o '$@' '$*.c' -build/%.o: build/%.c.i ../cc - ../cc -fpreprocessed -c -o '$@' 'build/$*.c.i' +$(build_dir)/%.o: $(build_dir)/%.c.i $(build_scripts)/cc + $(build_scripts)/cc -fpreprocessed -c -o '$@' '$(build_dir)/$*.c.i' -build/%.c.deps.mk: build/%.c.i ../codedeps.awk - awk -v srcname='$*.c' -v target='build/$*.c.i' -f ../codedeps.awk 'build/$*.c.i' >'$@.new' +$(build_dir)/%.c.deps.mk: $(build_dir)/%.c.i $(build_scripts)/codedeps.awk + awk -v srcname='$*.c' -v target='$(build_dir)/$*.c.i' -f $(build_scripts)/codedeps.awk '$(build_dir)/$*.c.i' >'$@.new' mv '$@.new' '$@' %/.exists: diff --git a/src/cmd_test.c b/src/cmd_test.c @@ -1,3 +1,8 @@ +#include <stdlib.h> /* getenv */ +#include <unistd.h> /* chdir */ + +#include <skalibs/strerr.h> + #include "tests.h" /* Declare a local suite. */ @@ -18,6 +23,12 @@ SUITE(selftest) { GREATEST_MAIN_DEFS(); int main(int argc, char **argv) { + char *test_dir = getenv("TEST_DIR"); + if(test_dir != NULL) { + if(chdir(test_dir) != 0) { + strerr_dief3sys(111, "could not chdir to: '", test_dir, "'"); + } + } GREATEST_MAIN_BEGIN(); /* command-line arguments, initialization. */ RUN_SUITE(selftest);