Generate french_law artifacts through dune

The files where manually generated through Makefile rules, and
versionned (with an outdated version).

The issue was that we had:
- `dune` building Catala
- Makefiles calling `catala` to build and copy the `french_law/ocaml/law_source`
  files
- then `dune` again to build `french_law`

The result was that `dune build` (without running `make` first) would
return a weird error.

The proposed solution adds ad-hoc dune rules to call the catala
binary, so that it can handle the whole pipeline correctly. If OCaml
is purely a backend, though, a simpler solution that makes us less
dependent on dune would be to handle the compilation of `french_law`
manually.

The dune rules are set to 'promote' the files so that it preserves the
fact that they are versionned (but with no confusion of the build system
about where they should come from anymore)
This commit is contained in:
Louis Gesbert 2022-07-29 16:39:33 +02:00
parent 3df99acb21
commit 0600501ec6
11 changed files with 6788 additions and 7460 deletions

View File

@ -199,18 +199,13 @@ literate_examples: literate_allocations_familiales literate_code_general_impots
FRENCH_LAW_OCAML_LIB_DIR=french_law/ocaml
$(FRENCH_LAW_OCAML_LIB_DIR)/law_source/allocations_familiales_api_web.ml:
CATALA_OPTS="$(CATALA_OPTS) -t" $(MAKE) -C $(ALLOCATIONS_FAMILIALES_DIR) allocations_familiales_api_web.ml
cp -f $(ALLOCATIONS_FAMILIALES_DIR)/allocations_familiales_api_web.ml $@
cp -f $(ALLOCATIONS_FAMILIALES_DIR)/allocations_familiales.ml $(FRENCH_LAW_OCAML_LIB_DIR)/law_source/allocations_familiales.ml
dune build $@
$(FRENCH_LAW_OCAML_LIB_DIR)/law_source/aides_logement_api_web.ml:
CATALA_OPTS="$(CATALA_OPTS) -t" $(MAKE) -C $(AIDES_LOGEMENT_DIR) aides_logement_api_web.ml
cp -f $(AIDES_LOGEMENT_DIR)/aides_logement_api_web.ml $@
cp -f $(AIDES_LOGEMENT_DIR)/aides_logement.ml $(FRENCH_LAW_OCAML_LIB_DIR)/law_source/aides_logement.ml
dune build $@
$(FRENCH_LAW_OCAML_LIB_DIR)/law_source/unit_tests/tests_allocations_familiales.ml:
CATALA_OPTS="$(CATALA_OPTS) -t" $(MAKE) -C $(ALLOCATIONS_FAMILIALES_DIR) tests/tests_allocations_familiales.ml
cp -f $(ALLOCATIONS_FAMILIALES_DIR)/tests/tests_allocations_familiales.ml $@
dune build $@
#> generate_french_law_library_ocaml : Generates the French law library OCaml sources from Catala
generate_french_law_library_ocaml: plugins \

4
dune
View File

@ -1,6 +1,6 @@
(dirs runtimes compiler french_law build_system)
(dirs runtimes compiler french_law build_system examples)
(data_only_dirs tests examples syntax_highlighting)
(data_only_dirs tests syntax_highlighting)
(alias
(name exec)

View File

@ -0,0 +1,12 @@
(rule
(targets aides_logement.ml aides_logement_api_web.ml)
(deps
(source_tree ..)
../../compiler/plugins/api_web%{ext_plugin})
(action
(run
catala
api_web
-t
--plugin-dir=../../compiler/plugins
aides_logement.catala_fr)))

View File

@ -0,0 +1,12 @@
(rule
(targets allocations_familiales.ml allocations_familiales_api_web.ml)
(deps
(source_tree ..)
../../compiler/plugins/api_web%{ext_plugin})
(action
(run
catala
api_web
-t
--plugin-dir=../../compiler/plugins
allocations_familiales.catala_fr)))

View File

@ -0,0 +1,6 @@
(rule
(targets tests_allocations_familiales.ml)
(deps
(source_tree .))
(action
(run catala OCaml -t tests_allocations_familiales.catala_fr)))

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1 @@
*

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -4,3 +4,27 @@
(preprocess
(pps js_of_ocaml-ppx))
(libraries catala.runtime_ocaml catala.runtime_jsoo js_of_ocaml))
(rule
(target allocations_familiales.ml)
(mode promote)
(action
(copy ../../../examples/allocations_familiales/%{target} %{target})))
(rule
(target allocations_familiales_api_web.ml)
(mode promote)
(action
(copy ../../../examples/allocations_familiales/%{target} %{target})))
(rule
(target aides_logement.ml)
(mode promote)
(action
(copy ../../../examples/aides_logement/%{target} %{target})))
(rule
(target aides_logement_api_web.ml)
(mode promote)
(action
(copy ../../../examples/aides_logement/%{target} %{target})))

View File

@ -2,3 +2,6 @@
(name run_tests)
(modes native)
(libraries catala.runtime_ocaml ANSITerminal))
(copy_files#
../../../../examples/allocations_familiales/tests/tests_allocations_familiales.ml)