catala/Makefile

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

364 lines
11 KiB
Makefile
Raw Normal View History

2021-03-19 19:36:09 +03:00
help : Makefile
@sed -n 's/^#> //p' $<
2020-08-07 18:37:28 +03:00
ROOT_DIR:=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
export DUNE_PROFILE ?= dev
# Export all variables to sub-make
export
2020-05-13 15:17:19 +03:00
##########################################
# Dependencies
##########################################
2020-04-20 09:35:22 +03:00
EXECUTABLES = groff python3 node npm ninja pandoc
2020-05-13 15:53:53 +03:00
K := $(foreach exec,$(EXECUTABLES),\
$(if $(shell which $(exec)),some string,$(warning [WARNING] No "$(exec)" executable found. \
Please install this executable for everything to work smoothly)))
OPAM = opam --cli=2.1
2022-03-09 19:00:53 +03:00
dependencies-ocaml:
$(OPAM) pin . --no-action
OPAMVAR_cataladevmode=1 $(OPAM) install . --with-doc --with-test --update-invariant --depext-only
OPAMVAR_cataladevmode=1 $(OPAM) install . --with-doc --with-test --update-invariant --deps-only
2020-04-26 19:42:42 +03:00
2022-03-09 19:00:53 +03:00
dependencies-ocaml-with-z3:
$(OPAM) pin . --no-action
OPAMVAR_cataladevmode=1 OPAMVAR_catalaz3mode=1 $(OPAM) install . --with-doc --with-test --update-invariant --depext-only
OPAMVAR_cataladevmode=1 OPAMVAR_catalaz3mode=1 $(OPAM) install . --with-doc --with-test --update-invariant --deps-only
PY_VENV_DIR = _python_venv
PY_VENV_ACTIVATE = . $(PY_VENV_DIR)/bin/activate;
# Rebuild when requirements change
$(PY_VENV_DIR): $(PY_VENV_DIR)/stamp
$(PY_VENV_DIR)/stamp: \
runtimes/python/pyproject.toml \
syntax_highlighting/en/pygments/pyproject.toml \
syntax_highlighting/fr/pygments/pyproject.toml \
syntax_highlighting/pl/pygments/pyproject.toml
test -d $(PY_VENV_DIR) || python3 -m venv $(PY_VENV_DIR)
$(PY_VENV_ACTIVATE) python3 -m pip install -U pip
$(PY_VENV_ACTIVATE) python3 -m pip install -U \
-e runtimes/python \
-e syntax_highlighting/en/pygments \
-e syntax_highlighting/fr/pygments \
-e syntax_highlighting/pl/pygments
touch $@
dependencies-python: $(PY_VENV_DIR)
build-runtime-python: dependencies-python
$(PY_VENV_ACTIVATE) python3 -m pip install -U build
$(PY_VENV_ACTIVATE) python -m build runtimes/python -o _build/python-runtime/
publish-runtime-python:
$(PY_VENV_ACTIVATE) python3 -m pip install -U twine
$(PY_VENV_ACTIVATE) python -m twine upload _build/python-runtime/*
2021-06-21 12:54:56 +03:00
#> dependencies : Install the Catala OCaml, JS and Git dependencies
dependencies: dependencies-ocaml dependencies-python
dependencies-with-z3: dependencies-ocaml-with-z3 dependencies-python
2020-05-13 15:17:19 +03:00
##########################################
# Catala compiler rules
##########################################
2021-06-21 12:39:06 +03:00
COMPILER_DIR=compiler
BUILD_SYSTEM_DIR=build_system
2021-06-21 12:39:06 +03:00
#> build_dev : Builds the Catala compiler, without formatting code
build_dev: parser-messages
dune build \
$(COMPILER_DIR)/catala.exe \
$(COMPILER_DIR)/plugins/ \
2023-09-13 15:03:53 +03:00
$(BUILD_SYSTEM_DIR)/clerk.exe
2022-09-06 18:25:57 +03:00
# Just the base compiler as needed to run the tests
compiler: parser-messages
dune build $(COMPILER_DIR)/catala.exe $(COMPILER_DIR)/plugins/ $(BUILD_SYSTEM_DIR)/clerk.exe
#> build : Builds the Catala compiler
build: parser-messages format build_dev
2020-04-19 17:30:18 +03:00
#> js_build : Builds the Web-compatible JS versions of the Catala compiler
2021-01-16 20:06:22 +03:00
js_build:
dune build $(COMPILER_DIR)/catala.bc.js $(COMPILER_DIR)/catala_web_interpreter.bc.js
2021-01-05 16:35:04 +03:00
#> doc : Generates the HTML OCaml documentation
2021-02-01 22:24:50 +03:00
doc:
2020-05-23 00:02:48 +03:00
dune build @doc
2020-12-14 20:09:38 +03:00
ln -sf $(PWD)/_build/default/_doc/_html/index.html doc/odoc.html
2020-05-23 00:02:48 +03:00
prepare-install:
2024-01-12 16:14:25 +03:00
dune build @install --promote-install-files
2020-04-16 18:47:35 +03:00
install: prepare-install
if [ x$$($(OPAM) --version) = "x2.1.5" ]; then \
$(OPAM) install . --working-dir; \
else \
$(OPAM) install . --working-dir --assume-built; \
fi
# `dune install` would work, but does a dirty install to the opam prefix without
# registering with opam.
# --assume-built is broken in 2.1.5
inst: prepare-install
@opam custom-install \
catala.$$(_build/install/default/bin/catala --version) \
--solver=builtin-mccs+glpk -- \
dune install catala
# This is better, but 'opam custom-install' is still an experimental plugin
#> runtimes : Builds the OCaml and js_of_ocaml runtimes
runtimes:
dune build runtimes/
#> plugins : Builds the compiler backend plugins
plugins: runtimes
dune build compiler/plugins/
##########################################
# Rules related to promoted files
##########################################
check-promoted:
dune build @update-parser-messages @fmt
compiler/surface/parser.messages: compiler/surface/tokens.mly compiler/surface/parser.mly
-dune build @update-parser-messages --auto-promote
parser-messages: compiler/surface/parser.messages
format:
-dune build @fmt --auto-promote 2>/dev/null
2020-05-13 15:17:19 +03:00
##########################################
2020-08-19 00:16:27 +03:00
# Syntax highlighting rules
2020-05-13 15:17:19 +03:00
##########################################
2020-03-08 05:30:37 +03:00
2020-04-27 10:57:13 +03:00
SYNTAX_HIGHLIGHTING_FR=${CURDIR}/syntax_highlighting/fr
SYNTAX_HIGHLIGHTING_EN=${CURDIR}/syntax_highlighting/en
2021-05-09 23:55:50 +03:00
SYNTAX_HIGHLIGHTING_PL=${CURDIR}/syntax_highlighting/pl
pygmentize_%: $(PY_VENV_DIR)
$(PY_VENV_ACTIVATE) python3 -m pip install syntax_highlighting/$*/pygments
2021-05-09 23:55:50 +03:00
#> pygments : Extends your pygmentize executable with Catala lexers
2021-05-10 20:05:18 +03:00
pygments: pygmentize_fr pygmentize_en pygmentize_pl
2020-04-27 10:57:13 +03:00
atom_fr: ${CURDIR}/syntax_highlighting/fr/setup_atom.sh
chmod +x $<
$<
2020-04-20 09:35:22 +03:00
2020-04-27 10:57:13 +03:00
atom_en: ${CURDIR}/syntax_highlighting/en/setup_atom.sh
2020-04-26 21:59:04 +03:00
chmod +x $<
$<
2021-05-09 23:55:50 +03:00
atom_pl: ${CURDIR}/syntax_highlighting/pl/setup_atom.sh
chmod +x $<
$<
#> atom : Installs Catala syntax highlighting for Atom
atom: atom_fr atom_en atom_pl
2020-04-26 21:59:04 +03:00
2020-08-19 00:16:27 +03:00
vscode_fr: ${CURDIR}/syntax_highlighting/fr/setup_vscode.sh
chmod +x $<
$<
vscode_en: ${CURDIR}/syntax_highlighting/en/setup_vscode.sh
chmod +x $<
$<
2021-05-16 21:14:35 +03:00
# TODO
# vscode_pl: ${CURDIR}/syntax_highlighting/pl/setup_vscode.sh
# chmod +x $<
# $<
2021-05-09 23:55:50 +03:00
#> vscode : Installs Catala syntax highlighting for VSCode
vscode: vscode_fr vscode_en
2020-08-19 00:16:27 +03:00
##########################################
# Extra documentation
##########################################
#> syntax : Buils syntax sheet (requires latexmk and dejavu fonts)
syntax:
$(MAKE) -C doc/syntax
2021-06-25 11:50:49 +03:00
##########################################
# High-level test and benchmarks commands
##########################################
CATALAOPTS ?=
CLERK_OPTS ?=
2022-01-11 14:51:34 +03:00
2022-12-22 22:42:56 +03:00
CATALA_BIN=_build/default/$(COMPILER_DIR)/catala.exe
CLERK_BIN=_build/default/$(BUILD_SYSTEM_DIR)/clerk.exe
2022-01-11 14:51:34 +03:00
CLERK_TEST=$(CLERK_BIN) test --exe $(CATALA_BIN) \
$(CLERK_OPTS) $(if $(CATALAOPTS),--catala-opts=$(CATALAOPTS),)
2022-01-11 14:51:34 +03:00
2021-06-25 11:50:49 +03:00
.FORCE:
unit-tests: .FORCE
dune build @for-tests @runtest
#> test : Run interpreter tests
test: .FORCE unit-tests
$(CLERK_TEST) tests doc
tests: test
TEST_FLAGS_LIST = ""\
-O \
--lcalc \
--lcalc,--avoid-exceptions,-O
# Does not include running dune (to avoid duplication when run among bigger rules)
testsuite-base: .FORCE
@for F in $(TEST_FLAGS_LIST); do \
echo >&2; \
[ -z "$$F" ] || echo ">> RE-RUNNING TESTS WITH FLAGS: $$F" >&2; \
2024-05-06 12:15:58 +03:00
$(CLERK_TEST) tests --test-flags="$$F" || exit 1; \
done
#> testsuite : Run interpreter tests over a selection of configurations
testsuite: unit-tests
$(MAKE) testsuite-base
#> reset-tests : Update the expected test results from current run
reset-tests: .FORCE $(CLERK_BIN)
2024-04-26 16:40:55 +03:00
$(CLERK_TEST) tests doc --reset
2021-06-25 11:50:49 +03:00
2022-07-11 17:03:47 +03:00
tests/%: .FORCE
$(CLERK_TEST) test $@
2022-07-11 17:03:47 +03:00
2020-05-13 15:17:19 +03:00
##########################################
# Website assets
##########################################
# Note: these are already built by the @doc dune alias
# (and therefore the doc target here)
WEBSITE_ASSETS_LOCAL_BASE = grammar.html catala.html clerk.html
WEBSITE_ASSETS_LOCAL = $(addprefix _build/default/,$(WEBSITE_ASSETS_BASE))
WEBSITE_ASSETS_EXAMPLES_BASE = \
tutorial_en/tutorial_en.html \
tutoriel_fr/tutoriel_fr.html \
us_tax_code/us_tax_code.html \
allocations_familiales/Allocations_familiales.html \
allocations_familiales/Allocations_familiales_schema.json \
aides_logement/Aides_logement.html \
aides_logement/Aides_logement_schema.json
WEBSITE_ASSETS_EXAMPLES = \
$(addprefix _build/default/,$(WEBSITE_ASSETS_EXAMPLES_BASE))
$(WEBSITE_ASSETS_LOCAL): build
dune build $(WEBSITE_ASSETS)
2020-05-05 18:04:53 +03:00
$(WEBSITE_ASSETS_EXAMPLES):
$(call local_tmp_clone,catala-examples) && \
$(MAKE) -C catala-examples.tmp \
CATALA=../$(CATALA_BIN) \
CLERK=../$(CLERK_BIN) \
BUILD=../_build/default \
$(addprefix ../,$(WEBSITE_ASSETS_EXAMPLES))
website-assets.tar: $(WEBSITE_ASSETS_LOCAL) $(WEBSITE_ASSETS_EXAMPLES)
tar cf $@ $(foreach file,$^,-C $(CURDIR)/$(dir $(file)) $(notdir $(file)))
2020-05-13 14:52:20 +03:00
#> website-assets : Builds all the assets necessary for the Catala website
website-assets: website-assets.tar
2020-05-13 15:17:19 +03:00
##########################################
# Miscellaneous
2020-05-13 15:17:19 +03:00
##########################################
2021-06-21 12:39:06 +03:00
#> all : Run all make commands
2021-06-24 19:17:54 +03:00
all: \
build js_build doc \
2021-06-24 19:30:54 +03:00
tests \
runtimes \
plugins
2021-06-24 19:17:54 +03:00
BRANCH = $(shell git branch --show-current 2>/dev/null || echo master)
# Attempt a clone of the named CatalaLang repo into <name>.tmp, using local git
# objects in ../<name> if available, the branch with the same name as the
# current branch if it exists (master otherwise), and falling back to a local
# clone of ../<name> if the network is not available. The temp dir is removed
# when the shell terminates, so this must be run in the same "Makefile line" as
# its usage.
local_tmp_clone = { \
rm -rf $1.tmp && \
trap "rm -rf $1.tmp" EXIT && \
git clone https://github.com/CatalaLang/$1 \
--depth 1 --reference-if-able ../$1 \
$1.tmp -b $(BRANCH) || \
git clone https://github.com/CatalaLang/$1 \
--depth 1 --reference-if-able ../$1 \
$1.tmp || \
git clone -s ../$1 $1.tmp -b $(BRANCH) || \
git clone -s ../$1 $1.tmp -b master; \
}
2024-02-14 14:06:43 +03:00
test_title = printf "\n\# \e[33m=========== \e[1m%-30s \e[2m===========\e[m \n"
#> alltest : Runs more extensive tests, including the examples and french-law. Use before push!
2024-02-14 14:06:43 +03:00
alltest: dependencies-python
@export DUNE_PROFILE=check OCAMLPATH=$(CURDIR)/_build/install/default/lib && \
$(test_title) "Local build and unit tests" && \
2024-02-14 14:06:43 +03:00
dune build @update-parser-messages @install @runtest && \
$(test_title) "Local testsuite" && \
$(MAKE) testsuite && \
$(test_title) "Running catala-examples" && \
$(call local_tmp_clone,catala-examples) && \
$(MAKE) -C catala-examples.tmp \
CATALA=$(CURDIR)/_build/install/default/bin/catala \
CLERK=$(CURDIR)/_build/install/default/bin/clerk \
BUILD=../_build/default \
all testsuite local-install && \
$(test_title) "Running french-law tests" && \
$(call local_tmp_clone,french-law) && \
touch french-law.tmp/dune-workspace && \
$(MAKE) -C french-law.tmp \
OCAMLPATH=$(CURDIR)/_build/install/default/lib \
PY_VENV_DIR=$(ROOT_DIR)/_python_venv \
dependencies \
bench_ocaml \
bench_js \
bench_python && \
printf "\n# \e[42;30m[ ALL TESTS PASSED ]\e[m \e[32m☺\e[m\n" || \
{ printf "\n# \e[41;30m[ TESTS FAILED ]\e[m \e[31m☹\e[m\n" ; exit 1; }
2020-05-13 15:17:19 +03:00
#> clean : Clean build artifacts
2020-04-20 09:35:22 +03:00
clean:
dune clean
2022-08-01 20:56:04 +03:00
rm -rf artifacts
2020-04-19 17:30:18 +03:00
2020-04-13 19:57:24 +03:00
inspect:
2021-05-09 23:55:50 +03:00
gitinspector -f ml,mli,mly,iro,tex,catala,catala_en,catala_pl,catala_fr,md,fst,mld --grading
2020-04-20 20:37:16 +03:00
2022-01-11 14:51:34 +03:00
#> help_clerk : Display the clerk man page
help_clerk:
$(CLERK_BIN) --help
#> help_catala : Display the catala man page
help_catala:
$(CATALA_BIN) --help
2020-05-13 15:17:19 +03:00
##########################################
2020-04-20 20:37:16 +03:00
# Special targets
2020-05-13 15:17:19 +03:00
##########################################
.PHONY: inspect clean all english alltest pygments install build_dev build doc \
format dependencies dependencies-ocaml catala.html help parser-messages \
plugins website-assets.tar website-assets-base