Skip to content

Commit 5403138

Browse files
authored
Merge pull request #693 from LPCIC/support-multiple-elpi-version
ifdefs on elpi version in source code
2 parents 92c1879 + d961ac6 commit 5403138

File tree

7 files changed

+171
-3
lines changed

7 files changed

+171
-3
lines changed

.github/workflows/nix-action-coq-8.20.yml

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,126 @@
11
jobs:
2+
QuickChick:
3+
needs:
4+
- coq
5+
- mathcomp-ssreflect
6+
runs-on: ubuntu-latest
7+
steps:
8+
- name: Determine which commit to initially checkout
9+
run: "if [ ${{ github.event_name }} = \"push\" ]; then\n echo \"target_commit=${{\
10+
\ github.sha }}\" >> $GITHUB_ENV\nelse\n echo \"target_commit=${{ github.event.pull_request.head.sha\
11+
\ }}\" >> $GITHUB_ENV\nfi\n"
12+
- name: Git checkout
13+
uses: actions/checkout@v4
14+
with:
15+
fetch-depth: 0
16+
ref: ${{ env.target_commit }}
17+
- name: Determine which commit to test
18+
run: "if [ ${{ github.event_name }} = \"push\" ]; then\n echo \"tested_commit=${{\
19+
\ github.sha }}\" >> $GITHUB_ENV\nelse\n merge_commit=$(git ls-remote ${{\
20+
\ github.event.repository.html_url }} refs/pull/${{ github.event.number }}/merge\
21+
\ | cut -f1)\n mergeable=$(git merge --no-commit --no-ff ${{ github.event.pull_request.base.sha\
22+
\ }} > /dev/null 2>&1; echo $?; git merge --abort > /dev/null 2>&1 || true)\n\
23+
\ if [ -z \"$merge_commit\" -o \"x$mergeable\" != \"x0\" ]; then\n echo\
24+
\ \"tested_commit=${{ github.event.pull_request.head.sha }}\" >> $GITHUB_ENV\n\
25+
\ else\n echo \"tested_commit=$merge_commit\" >> $GITHUB_ENV\n fi\nfi\n"
26+
- name: Git checkout
27+
uses: actions/checkout@v4
28+
with:
29+
fetch-depth: 0
30+
ref: ${{ env.tested_commit }}
31+
- name: Cachix install
32+
uses: cachix/install-nix-action@v27
33+
with:
34+
nix_path: nixpkgs=channel:nixpkgs-unstable
35+
- name: Cachix setup coq-elpi
36+
uses: cachix/cachix-action@v15
37+
with:
38+
authToken: ${{ secrets.CACHIX_AUTH_TOKEN }}
39+
extraPullNames: coq, coq-community, math-comp
40+
name: coq-elpi
41+
- id: stepCheck
42+
name: Checking presence of CI target QuickChick
43+
run: "nb_dry_run=$(NIXPKGS_ALLOW_UNFREE=1 nix-build --no-out-link \\\n --argstr\
44+
\ bundle \"coq-8.20\" --argstr job \"QuickChick\" \\\n --dry-run 2>&1 >\
45+
\ /dev/null)\necho $nb_dry_run\necho status=$(echo $nb_dry_run | grep \"built:\"\
46+
\ | sed \"s/.*/built/\") >> $GITHUB_OUTPUT\n"
47+
- if: steps.stepCheck.outputs.status == 'built'
48+
name: 'Building/fetching previous CI target: coq'
49+
run: NIXPKGS_ALLOW_UNFREE=1 nix-build --no-out-link --argstr bundle "coq-8.20"
50+
--argstr job "coq"
51+
- if: steps.stepCheck.outputs.status == 'built'
52+
name: 'Building/fetching previous CI target: mathcomp-ssreflect'
53+
run: NIXPKGS_ALLOW_UNFREE=1 nix-build --no-out-link --argstr bundle "coq-8.20"
54+
--argstr job "mathcomp-ssreflect"
55+
- if: steps.stepCheck.outputs.status == 'built'
56+
name: 'Building/fetching previous CI target: coq-ext-lib'
57+
run: NIXPKGS_ALLOW_UNFREE=1 nix-build --no-out-link --argstr bundle "coq-8.20"
58+
--argstr job "coq-ext-lib"
59+
- if: steps.stepCheck.outputs.status == 'built'
60+
name: 'Building/fetching previous CI target: simple-io'
61+
run: NIXPKGS_ALLOW_UNFREE=1 nix-build --no-out-link --argstr bundle "coq-8.20"
62+
--argstr job "simple-io"
63+
- if: steps.stepCheck.outputs.status == 'built'
64+
name: Building/fetching current CI target
65+
run: NIXPKGS_ALLOW_UNFREE=1 nix-build --no-out-link --argstr bundle "coq-8.20"
66+
--argstr job "QuickChick"
67+
autosubst:
68+
needs:
69+
- coq
70+
- mathcomp-ssreflect
71+
runs-on: ubuntu-latest
72+
steps:
73+
- name: Determine which commit to initially checkout
74+
run: "if [ ${{ github.event_name }} = \"push\" ]; then\n echo \"target_commit=${{\
75+
\ github.sha }}\" >> $GITHUB_ENV\nelse\n echo \"target_commit=${{ github.event.pull_request.head.sha\
76+
\ }}\" >> $GITHUB_ENV\nfi\n"
77+
- name: Git checkout
78+
uses: actions/checkout@v4
79+
with:
80+
fetch-depth: 0
81+
ref: ${{ env.target_commit }}
82+
- name: Determine which commit to test
83+
run: "if [ ${{ github.event_name }} = \"push\" ]; then\n echo \"tested_commit=${{\
84+
\ github.sha }}\" >> $GITHUB_ENV\nelse\n merge_commit=$(git ls-remote ${{\
85+
\ github.event.repository.html_url }} refs/pull/${{ github.event.number }}/merge\
86+
\ | cut -f1)\n mergeable=$(git merge --no-commit --no-ff ${{ github.event.pull_request.base.sha\
87+
\ }} > /dev/null 2>&1; echo $?; git merge --abort > /dev/null 2>&1 || true)\n\
88+
\ if [ -z \"$merge_commit\" -o \"x$mergeable\" != \"x0\" ]; then\n echo\
89+
\ \"tested_commit=${{ github.event.pull_request.head.sha }}\" >> $GITHUB_ENV\n\
90+
\ else\n echo \"tested_commit=$merge_commit\" >> $GITHUB_ENV\n fi\nfi\n"
91+
- name: Git checkout
92+
uses: actions/checkout@v4
93+
with:
94+
fetch-depth: 0
95+
ref: ${{ env.tested_commit }}
96+
- name: Cachix install
97+
uses: cachix/install-nix-action@v27
98+
with:
99+
nix_path: nixpkgs=channel:nixpkgs-unstable
100+
- name: Cachix setup coq-elpi
101+
uses: cachix/cachix-action@v15
102+
with:
103+
authToken: ${{ secrets.CACHIX_AUTH_TOKEN }}
104+
extraPullNames: coq, coq-community, math-comp
105+
name: coq-elpi
106+
- id: stepCheck
107+
name: Checking presence of CI target autosubst
108+
run: "nb_dry_run=$(NIXPKGS_ALLOW_UNFREE=1 nix-build --no-out-link \\\n --argstr\
109+
\ bundle \"coq-8.20\" --argstr job \"autosubst\" \\\n --dry-run 2>&1 > /dev/null)\n\
110+
echo $nb_dry_run\necho status=$(echo $nb_dry_run | grep \"built:\" | sed \"\
111+
s/.*/built/\") >> $GITHUB_OUTPUT\n"
112+
- if: steps.stepCheck.outputs.status == 'built'
113+
name: 'Building/fetching previous CI target: coq'
114+
run: NIXPKGS_ALLOW_UNFREE=1 nix-build --no-out-link --argstr bundle "coq-8.20"
115+
--argstr job "coq"
116+
- if: steps.stepCheck.outputs.status == 'built'
117+
name: 'Building/fetching previous CI target: mathcomp-ssreflect'
118+
run: NIXPKGS_ALLOW_UNFREE=1 nix-build --no-out-link --argstr bundle "coq-8.20"
119+
--argstr job "mathcomp-ssreflect"
120+
- if: steps.stepCheck.outputs.status == 'built'
121+
name: Building/fetching current CI target
122+
run: NIXPKGS_ALLOW_UNFREE=1 nix-build --no-out-link --argstr bundle "coq-8.20"
123+
--argstr job "autosubst"
2124
coq:
3125
needs: []
4126
runs-on: ubuntu-latest

.nix/coq-nix-toolbox.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
"24e96b4870378d5e87fd2d0dd46405b471c286ab"
1+
"42eecc8a0f642b84bd179859d708ddc710c92004"

coq-elpi.opam

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ depends: [
1919
"ocaml" {>= "4.10.0"}
2020
"stdlib-shims"
2121
"elpi" {>= "1.18.2" & < "1.20.0~"}
22-
"coq" {>= "8.20" & < "8.21"}
22+
"coq" {>= "8.20+rc1" & < "8.21~"}
2323
"ppx_optcomp"
2424
"ocaml-lsp-server" {with-dev-setup}
2525
"odoc" {with-doc}

etc/dune

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,11 @@
99
(public_name coq_elpi_optcomp)
1010
(modules optcomp)
1111
(libraries str)
12+
(package coq-elpi))
13+
14+
(executable
15+
(name version_parser)
16+
(public_name coq_elpi_version_parser)
17+
(modules version_parser)
18+
(libraries str)
1219
(package coq-elpi))

etc/version_parser.ml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
let is_number x = try let _ = int_of_string x in true with _ -> false ;;
3+
4+
let main () =
5+
let v = Sys.argv.(1) in
6+
let l = String.split_on_char '.' Str.(replace_first (regexp "^v") "" v) in
7+
(* sanitization *)
8+
let l =
9+
match l with
10+
| l when List.for_all is_number l -> l
11+
| ( [""] | ["%%VERSION_NUM%%"] ) -> ["99";"99";"99"]
12+
| _ -> Printf.eprintf "version_parser: cannot parse: %s\n" v; exit 1 in
13+
let open Format in
14+
printf "(%a)%!" (pp_print_list ~pp_sep:(fun fmt () -> pp_print_string fmt ", ") pp_print_string) l
15+
;;
16+
17+
main ()

src/coq_elpi_builtins_synterp.ml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
(* license: GNU Lesser General Public License Version 2.1 or later *)
33
(* ------------------------------------------------------------------------- *)
44

5+
[%%import "coq_elpi_config.mlh"]
6+
57
module API = Elpi.API
68
module State = API.State
79
module Conv = API.Conversion
@@ -150,6 +152,12 @@ let invocation_site_loc_synterp : API.Ast.Loc.t State.component =
150152
~init:(fun () -> API.Ast.Loc.initial "(should-not-happen)")
151153
~start:(fun x -> x) ()
152154

155+
[%%if elpi >= (1, 20, 0)]
156+
let compat_graft x = x
157+
[%%else]
158+
let compat_graft = Option.map (function `Remove, _ -> nYI "clause removal" | ((`Replace | `Before | `After), _) as x -> x)
159+
[%%endif]
160+
153161
type accumulation_item = qualified_name * API.Ast.program * Id.t list * Coq_elpi_utils.clause_scope
154162
let accumulate_clauses ~clauses_for_later ~accumulate_to_db ~preprocess_clause ~scope ~dbname clauses ~depth ~options state =
155163
let invocation_loc = State.get invocation_site_loc_synterp state in
@@ -158,7 +166,7 @@ let accumulate_clauses ~clauses_for_later ~accumulate_to_db ~preprocess_clause ~
158166
let clauses scope =
159167
clauses |> CList.rev_map (fun (name,graft,clause) ->
160168
let vars, clause = preprocess_clause ~depth clause in
161-
let graft = Option.map (function `Remove, _ -> nYI "clause removal" | ((`Replace | `Before | `After), _) as x -> x) graft in
169+
let graft = compat_graft graft in
162170
let clause = U.clause_of_term ?name ?graft ~depth loc clause in
163171
(dbname,clause,vars,scope)) in
164172
let local = (options : options).local = Some true in

src/dune

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
(public_name coq-elpi.elpi)
44
(synopsis "Elpi")
55
(flags :standard -w -27)
6+
(preprocessor_deps coq_elpi_config.mlh)
67
(preprocess (pps ppx_optcomp -- -cookie "ppx_optcomp.env=env ~coq:(Defined \"%{coq:version.major}.%{coq:version.minor}\")"))
78
(libraries coq-core.plugins.ltac coq-core.vernac elpi))
89

@@ -30,7 +31,20 @@
3031
(target coq_elpi_config.ml)
3132
(action (with-stdout-to %{target}
3233
(progn
34+
(echo "(* Automatically generated, don't edit *)\n")
35+
(echo "[%%import \"coq_elpi_config.mlh\"]\n")
36+
(echo "let elpi_version = \"%{version:elpi}\"\n")
3337
(echo "let elpi2html = \"%{lib:elpi:elpi2html.elpi}\";;")))))
3438

39+
(rule
40+
(target coq_elpi_config.mlh)
41+
(action (with-stdout-to %{target}
42+
(progn
43+
(echo "(* Automatically generated, don't edit *)\n")
44+
(echo "[%%define elpi ")
45+
(run coq_elpi_version_parser %{version:elpi})
46+
(echo "]\n")))))
47+
48+
3549
(coq.pp
3650
(modules coq_elpi_vernacular_syntax coq_elpi_arg_syntax))

0 commit comments

Comments
 (0)