Files
RecordFlux-parser/Makefile
Johannes Kliemann 953cf1a51e Update to current langkit master
ref #41
2023-01-03 17:57:22 +00:00

185 lines
6.2 KiB
Makefile

VERBOSE ?= @
TEST_PROCS ?= $(shell nproc)
RECORDFLUX_ORIGIN ?= https://github.com/Componolit
ADACORE_ORIGIN ?= https://github.com/AdaCore
VERSION = 0.13.0
BUILDDIR = $(PWD)/build
PYTHON_PACKAGES = language tests disttools/setup.py disttools/gprgen.py
PYTHON_STYLE_HEAD = 7f2584cd5e72fb6e7a80dcc8cce296f5821dcf8e
GNATCOLL_HEAD = 25459f07a2e96eb0f28dcfd5b03febcb72930987
LANGKIT_HEAD = 33127ce82a6731f8f1428dab818523e0419bb4af
PYTEST := python3 -m pytest -n$(TEST_PROCS) -vv
# Switch to a specific revision of the git repository.
#
# @param $(1) directory of the git repository
# @param $(2) commit id
define checkout_repo
$(shell test -d $(1) && git -C $(1) fetch && git -C $(1) -c advice.detachedHead=false checkout $(2))
endef
# Get the HEAD revision of the git repository.
#
# @param $(1) directory of the git repository
# @param $(2) default value
repo_head = $(shell test -d $(1) && git -C $(1) rev-parse HEAD || echo $(2))
# Switch to the expected revision of the git repository, if the current HEAD is not the expected one.
#
# @param $(1) directory of the git repository
# @param $(2) expected revision
reinit_repo = $(if $(filter-out $(2),$(call repo_head,$(1),$(2))),$(call checkout_repo,$(1),$(2)),)
# Remove the git repository, if no changes are present.
#
# The function looks for changed and untracked files as well as commits that are not pushed to a
# remote branch. If the repository is unchanged, it will be removed completely.
#
# @param $(1) directory of the git repository
define remove_repo
$(if
$(or
$(shell test -d $(1) && git -C $(1) status --porcelain),
$(shell test -d $(1) && git -C $(1) log --branches --not --remotes --format=oneline)
),
$(info Keeping $(1) due to local changes),
$(shell rm -rf $(1))
)
endef
ifneq ($(MAKECMDGOALS),clean)
DUMMY := $(shell mkdir -p $(BUILDDIR))
ifeq ($(DISTDIR),)
DISTDIR := $(shell mktemp -d --tmpdir=$(BUILDDIR) dist-XXXXXXXX)
endif
endif
$(shell $(call reinit_repo,.config/python-style,$(PYTHON_STYLE_HEAD)))
$(shell $(call reinit_repo,contrib/gnatcoll-bindings,$(GNATCOLL_HEAD)))
$(shell $(call reinit_repo,contrib/langkit,$(langkit_HEAD)))
export MYPYPATH = $(PWD)/stubs
.PHONY: all
all: check test
.PHONY: init deinit
init: .config/python-style contrib/gnatcoll-bindings contrib/langkit
$(VERBOSE)$(call checkout_repo,.config/python-style,$(PYTHON_STYLE_HEAD))
$(VERBOSE)$(call checkout_repo,contrib/gnatcoll-bindings,$(GNATCOLL_HEAD))
$(VERBOSE)$(call checkout_repo,contrib/langkit,$(LANGKIT_HEAD))
$(VERBOSE)ln -sf .config/python-style/pyproject.toml
$(VERBOSE)git update-index --skip-worktree pyproject.toml
deinit:
$(VERBOSE)$(call remove_repo,.config/python-style)
$(VERBOSE)$(call remove_repo,contrib/gnatcoll-bindings)
$(VERBOSE)$(call remove_repo,contrib/langkit)
$(VERBOSE)ln -sf .config/pyproject.toml
$(VERBOSE)git update-index --no-skip-worktree pyproject.toml
.config/python-style:
$(VERBOSE)git clone $(RECORDFLUX_ORIGIN)/python-style.git .config/python-style
contrib/gnatcoll-bindings:
$(VERBOSE)mkdir -p contrib
$(VERBOSE)git clone $(ADACORE_ORIGIN)/gnatcoll-bindings.git contrib/gnatcoll-bindings
contrib/langkit:
$(VERBOSE)mkdir -p contrib
$(VERBOSE)git clone $(ADACORE_ORIGIN)/langkit.git contrib/langkit
.PHONY: check check_black check_isort check_flake8 check_pylint check_mypy check_pydocstyle format \
test test_python test_python_coverage install install_devel install_devel_edge clean
check: check_black check_isort check_flake8 check_pylint check_mypy check_pydocstyle
check_black:
black --check --diff --line-length 100 $(PYTHON_PACKAGES)
check_isort:
isort --check --diff $(PYTHON_PACKAGES)
check_flake8:
pflake8 $(PYTHON_PACKAGES)
check_pylint:
pylint $(PYTHON_PACKAGES)
check_mypy:
mypy --pretty $(PYTHON_PACKAGES)
check_pydocstyle:
pydocstyle $(PYTHON_PACKAGES)
format:
black -l 100 $(PYTHON_PACKAGES)
isort $(PYTHON_PACKAGES)
test: test_python_coverage
test_python:
$(PYTEST) tests
test_python_coverage:
$(PYTEST) --cov=librflxlang --cov-branch --cov-fail-under=75 --cov-report=term-missing:skip-covered tests
install: $(BUILDDIR)/RecordFlux-parser-$(VERSION).tar.gz
pip3 install --force-reinstall $<
install_devel: install
$(MAKE) -C .config/python-style install_devel
install_devel_edge: install
$(MAKE) -C .config/python-style install_devel_edge
dist: $(BUILDDIR)/RecordFlux-parser-$(VERSION).tar.gz
@echo "============================================================================================================"
@echo "Source distribution generated at $<."
@echo "To upload to PyPI use"
@echo " $$ twine upload $<"
@echo "To upload to Test PyPI use"
@echo " $$ twine upload -r testpypi $<"
@echo "============================================================================================================"
$(BUILDDIR)/RecordFlux-parser-$(VERSION).tar.gz: $(DISTDIR)/gdbinit.py disttools/setup.py
$(VERBOSE)(cd $(DISTDIR) && python3 -m build --sdist --outdir=$(BUILDDIR))
$(VERBOSE)rm -rf $(DISTDIR)
$(VERBOSE)ls -l $@
$(DISTDIR)/gdbinit.py: language/generate.py language/lexer.py language/parser.py language/rflx_ast.py
$(VERBOSE)pip3 install --upgrade -r requirements.txt
$(VERBOSE)python3 -m venv $(DISTDIR)/.venv
$(VERBOSE)$(DISTDIR)/.venv/bin/python -m pip --quiet install contrib/langkit
$(VERBOSE)PYTHONPATH=$(PWD) $(DISTDIR)/.venv/bin/python language/generate.py $(DISTDIR) $(VERSION)
$(VERBOSE)cp -a $(PWD)/contrib/langkit $(DISTDIR)/
$(VERBOSE)cp -a $(PWD)/contrib/gnatcoll-bindings $(DISTDIR)/
$(VERBOSE)ln -sf $(PWD)/disttools/MANIFEST.in $(DISTDIR)/MANIFEST.in
$(VERBOSE)cp disttools/setup.py $(DISTDIR)/setup.py
$(VERBOSE)cp disttools/pyproject.toml $(DISTDIR)/pyproject.toml
$(VERBOSE)mv $(DISTDIR)/librflxlang.gpr $(BUILDDIR)/librflxlang.gpr.bak
$(VERBOSE)./disttools/gprgen.py rflxlang $(DISTDIR) $(BUILDDIR)/librflxlang.gpr.bak
$(VERBOSE)sed -i -e 's/##VERSION##/$(VERSION)/g' $(DISTDIR)/setup.py
$(VERBOSE)cp README.md $(DISTDIR)/README.md
$(VERBOSE)touch $(DISTDIR)/python/librflxlang/py.typed
install_gnat:
alr toolchain --install gnat_native=11.2.1 && \
mkdir -p build && \
cd build && \
alr -n init --lib alire && \
cd alire && \
alr -n with gnatcoll_iconv gnatcoll_gmp
printenv_gnat:
@test -d build/alire && \
cd build/alire && \
alr printenv
clean:
rm -rf .mypy_cache .pytest_cache .egg build