# SPDX-License-Identifier: CC0-1.0 # Copyright (C) 2022 Wojtek Kosior <koszko@koszko.org> # # Available under the terms of Creative Commons Zero v1.0 Universal. GUIX ?= guix # Almost all commands in this Makefilo are run through `guix time-machine` with # Guix revision fixed to the one from the commit below. This ensures that the # same working environment is always used. GUIX_COMMIT ?= a86979b41a49a8fcdaa887970ba594dbba701226 GUIX_TM ?= $(GUIX) time-machine --commit=$(GUIX_COMMIT) -- GUIX_FULL_PACKAGE_FLAGS = -f guix.scm GUIX_MINIMAL_PACKAGE_FLAGS = -e '(@ (hydrilla-base) hydrilla-without-haketilo)' -L ./guix-module-dir GUIX_PACKAGE_SELECTION_FLAGS = $(GUIX_FULL_PACKAGE_FLAGS) GUIX_DEVSHELL = $(GUIX_TM) shell -D $(GUIX_PACKAGE_SELECTION_FLAGS) -- GUIX_MINIMAL_DEVSHELL = $(GUIX_TM) shell -D $(GUIX_MINIMAL_PACKAGE_FLAGS) -- GET_VER = $$(grep '^Version:' src/hydrilla.egg-info/PKG-INFO | cut -d' ' -f2) RECORD_VER = VER="$(GET_VER)" DETERMINISTIC_TAR = $(GUIX_TM) shell tar -- tar \ --mtime='1970-01-01 00:00Z' \ --sort=name \ --owner=0 --group=0 --numeric-owner \ --pax-option=exthdr.name=%d/PaxHeaders/%f,delete=atime,delete=ctime DETERMINE_USER_SHELL_TO_USE = \ case "$$SHELL" in \ ?*) \ SHELL_TO_USE="$$SHELL";; \ *) \ SHELL_TO_USE="/bin/sh";; \ esac wheel: $(GUIX_DEVSHELL) python3 -m build # Make a source tarball and repack in a deterministic way so that its # reproducible. dist src/hydrilla/_version.py: $(GUIX_MINIMAL_DEVSHELL) python3 -m build -s $(RECORD_VER) && \ RELNAME=hydrilla-"$$VER" && \ DISTFILE=dist/"$$RELNAME".tar.gz && \ $(MAKE) clean-source-tarball-repack && \ mkdir source-tarball-repack/ && \ tar -C source-tarball-repack/ -xf "$$DISTFILE" && \ $(DETERMINISTIC_TAR) -C source-tarball-repack/ \ -cf "$$DISTFILE" "$$RELNAME" @printf "Generated source tarball in:\n" @printf "./dist/hydrilla-$(GET_VER).tar.gz\n" doc: $(MAKE) clean-doc $(GUIX_DEVSHELL) python3 setup.py build_htmldoc # Make a release tarball and repack its files as writeable - this will make it # easier for non-technical users to remove the unpacked release once they no # longer need it. release: dist doc $(GUIX_TM) pack -L ./guix-module-dir -RR hydrilla \ -S /hydrilla=bin/hydrilla \ -S /hydrilla-builder=bin/hydrilla-builder \ -S /hydrilla-server=bin/hydrilla-server \ -S /haketilo=bin/haketilo | tee make-release.log $(RECORD_VER) && \ RELNAME=haketilo-and-hydrilla-bin-"$$VER"-"$$(arch)" && \ PACKFILE="$$(tail -1 make-release.log)" && \ $(MAKE) clean-bin-tarball-repack && \ mkdir bin-tarball-repack/ && \ mkdir bin-tarball-repack/"$$RELNAME" && \ tar -C bin-tarball-repack/"$$RELNAME"/ -xf "$$PACKFILE" && \ chmod -R +w bin-tarball-repack/"$$RELNAME" && \ cp -R htmldoc/ bin-tarball-repack/"$$RELNAME" && \ $(DETERMINISTIC_TAR) -C bin-tarball-repack/ \ -cf "$$RELNAME".tar.gz "$$RELNAME" @printf "Generated binary release tarball for $$(arch) in:\n" @printf "./haketilo-and-hydrilla-bin-$(GET_VER)-$$(arch).tar.gz\n" # If using bash, modify the prompt to indicate that the environment is active. shell: $(DETERMINE_USER_SHELL_TO_USE); \ case "$$SHELL_TO_USE" in \ *bash*) \ HYDRILLA_SHELL_NAME=hydrilla-dev \ $(GUIX_DEVSHELL) "$$SHELL_TO_USE" \ --rcfile ./bashrc || true;; \ *) \ $(GUIX_DEVSHELL) "$$SHELL_TO_USE" || true;; \ esac # Modify prompt for bash, like above. shell-with-haketilo: dist $(DETERMINE_USER_SHELL_TO_USE); \ case "$$SHELL_TO_USE" in \ *bash*) \ HYDRILLA_SHELL_NAME=hydrilla \ $(GUIX_TM) shell \ --rebuild-cache \ $(GUIX_PACKAGE_SELECTION_FLAGS) -- \ "$$SHELL_TO_USE" --rcfile ./bashrc || true;; \ *) \ $(GUIX_TM) shell --rebuild-cache \ $(GUIX_PACKAGE_SELECTION_FLAGS) -- \ || true;; \ esac .PHONY: shell-with-hydrilla-only: $(MAKE) shell-with-haketilo \ GUIX_PACKAGE_SELECTION_FLAGS="$(GUIX_MINIMAL_PACKAGE_FLAGS)" catalogs: $(GUIX_DEVSHELL) python3 setup.py compile_catalog refresh-catalogs: $(GUIX_DEVSHELL) sh -c \ "python3 setup.py extract_messages && python3 setup.py update_catalog && python3 setup.py compile_catalog" test: src/hydrilla/_version.py catalogs $(GUIX_DEVSHELL) pytest run-haketilo: src/hydrilla/_version.py catalogs PYTHONPATH=./src $(GUIX_DEVSHELL) python3 -m hydrilla.mitmproxy_launcher reuse-lint: $(GUIX_DEVSHELL) reuse lint mypy-lint: src/hydrilla/_version.py PYTHONPATH=./src/ $(GUIX_DEVSHELL) mypy -p hydrilla mypy-lint-server: src/hydrilla/_version.py $(GUIX_DEVSHELL) mypy src/hydrilla/server/__main__.py mypy-lint-builder: src/hydrilla/_version.py $(GUIX_DEVSHELL) mypy src/hydrilla/builder/__main__.py mypy-lint-haketilo: src/hydrilla/_version.py $(GUIX_DEVSHELL) mypy \ src/hydrilla/proxy/addon.py \ src/hydrilla/mitmproxy_launcher/__main__.py clean-bin-tarball-repack: test -d bin-tarball-repack/ && chmod -R +w bin-tarball-repack/ || true rm -rf bin-tarball-repack/ clean-source-tarball-repack: rm -rf source-tarball-repack/ clean-doc: rm -rf htmldoc/ clean: clean-bin-tarball-repack clean-source-tarball-repack clean-doc rm -rf build/ dist/ src/hydrilla.egg-info/ src/hydrilla/_version.py \ src/hydrilla/locales/messages.pot make-release.log \ haketilo-and-hydrilla-bin-*.tar.gz .mypy_cache/ .pytest_cache/ find src/hydrilla/locales/ -name "messages.mo" -delete rm -rf $$(find -name "__pycache__") .PHONY: shell shell-with-haketilo \ wheel dist doc release catalogs \ refresh-catalogs test run-haketilo \ reuse-lint \ mypy-lint mypy-lint-server mypy-lint-builder mypy-lint-haketilo \ clean-bin-tarball-repack clean-source-tarball-repack clean-doc \ clean