Skip to content

Commit a7d2b01

Browse files
committed
Use dune-site to find resources (when installed)
1 parent c5f30c8 commit a7d2b01

File tree

7 files changed

+74
-36
lines changed

7 files changed

+74
-36
lines changed

easycrypt.opam

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,22 @@ depends: [
1414
"zarith" {>= "1.10"}
1515
"odoc" {with-doc}
1616
]
17+
build: [
18+
["dune" "subst"] {dev}
19+
[
20+
"dune"
21+
"build"
22+
"-p"
23+
name
24+
"-j"
25+
jobs
26+
"--promote-install-files=false"
27+
"@install"
28+
"@runtest" {with-test}
29+
"@doc" {with-doc}
30+
]
31+
["dune" "install" "-p" name "--create-install-files" name]
32+
]
1733
opam-version: "2.0"
1834

1935
homepage: "https://www.easycrypt.info/"
@@ -36,8 +52,3 @@ can install AltErgo (package: alt-ergo).
3652

3753
The required steps for configuring the provers are listed on:
3854
https://github.com/EasyCrypt/easycrypt#configuring-why3"""
39-
40-
build: [
41-
["dune" "subst"]
42-
["dune" "build" "-p" name "-j" jobs "@install"]
43-
]

easycrypt.opam.template

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,3 @@ can install AltErgo (package: alt-ergo).
2020

2121
The required steps for configuring the provers are listed on:
2222
https://github.com/EasyCrypt/easycrypt#configuring-why3"""
23-
24-
build: [
25-
["dune" "subst"]
26-
["dune" "build" "-p" name "-j" jobs "@install"]
27-
]

src/dune

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,23 @@
55

66
(include_subdirs unqualified)
77

8+
(generate_sites_module
9+
(module ecDuneSites)
10+
(sites easycrypt))
11+
812
(library
913
(name ecLib)
1014
(public_name easycrypt.ecLib)
1115
(modules :standard \ ec)
12-
(libraries batteries camlp-streams dune-build-info inifiles why3 yojson zarith)
16+
(libraries batteries camlp-streams dune-build-info dune-site inifiles why3 yojson zarith)
1317
)
1418

1519
(executable
1620
(public_name easycrypt)
1721
(name ec)
1822
(modules ec)
1923
(promote (until-clean))
20-
(libraries batteries camlp-streams dune-build-info inifiles why3 yojson zarith ecLib))
24+
(libraries batteries camlp-streams dune-build-info dune-site inifiles why3 yojson zarith ecLib))
2125

2226
(ocamllex ecLexer)
2327

src/ec.ml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ type pconfig = {
3838
}
3939

4040
let print_config config =
41+
let (module Sites) = EcRelocate.sites in
42+
4143
(* Print git-hash *)
4244
Format.eprintf "git-hash: %s@\n%!" EcVersion.hash;
4345

@@ -92,6 +94,9 @@ let print_config config =
9294
(String.concat ", " (List.map string_of_prover provers))
9395
end;
9496

97+
(* Command path *)
98+
Format.eprintf "Commands PATH: %s@\n%!" Sites.commands;
99+
95100
(* Print system PATH *)
96101
Format.eprintf "System PATH:@\n%!";
97102
List.iter
@@ -105,7 +110,7 @@ let main () =
105110
* disallows Why3 server to detect external provers completion *)
106111
let _ : int list = Unix.sigprocmask Unix.SIG_SETMASK [] in
107112

108-
let theories = EcRelocate.Sites.theories in
113+
let (module Sites) = EcRelocate.sites in
109114

110115
(* Parse command line arguments *)
111116
let conffile, options =
@@ -190,7 +195,7 @@ let main () =
190195
| Some root ->
191196
List.fold_left Filename.concat root ["scripts"; "testing"]
192197
| None ->
193-
EcRelocate.resource ["commands"] in
198+
Sites.commands in
194199
let cmd = Filename.concat root "runtest" in
195200
let args =
196201
[
@@ -219,7 +224,7 @@ let main () =
219224
let pwd = Sys.getcwd () in
220225
Sys.chdir (
221226
List.fold_left Filename.concat
222-
(List.hd EcRelocate.Sites.theories)
227+
(List.hd Sites.theories)
223228
(List.init 3 (fun _ -> ".."))
224229
); Some pwd
225230

@@ -263,7 +268,7 @@ let main () =
263268
EcCommands.addidir ~namespace:`System (Filename.concat theory "prelude");
264269
if not ldropts.ldro_boot then
265270
EcCommands.addidir ~namespace:`System ~recursive:true theory
266-
) theories;
271+
) Sites.theories;
267272
List.iter (fun (onm, name, isrec) ->
268273
EcCommands.addidir
269274
?namespace:(omap (fun nm -> `Named nm) onm)

src/ecLoader.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ let rec addidir ?namespace ?(recursive = false) (idir : string) (ecl : ecloader)
5151
try Sys.is_directory filename with Sys_error _ -> false
5252
in
5353

54-
let dirs = (try EcUtils.Os.listdir idir with Unix.Unix_error _ -> []) in
54+
let dirs = (try EcUtils.Os.listdir idir with Unix.Unix_error _ | Sys_error _ -> []) in
5555
let dirs = List.sort compare (List.filter isdir dirs) in
5656

5757
List.iter (fun filename ->

src/ecRelocate.ml

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,48 @@
1+
(* -------------------------------------------------------------------- *)
12
let myname = Filename.basename Sys.executable_name
23
let mydir = Filename.dirname Sys.executable_name
34

4-
let eclocal =
5+
(* -------------------------------------------------------------------- *)
6+
let eclocal : bool =
57
let rex = EcRegexp.regexp "^ec\\.(?:native|byte|exe)$" in
68
EcRegexp.match_ (`C rex) myname
79

8-
let sourceroot =
10+
(* -------------------------------------------------------------------- *)
11+
let sourceroot : string option =
912
if eclocal then
1013
if Filename.basename mydir = "src"
1114
then Some (Filename.dirname mydir)
1215
else Some mydir
1316
else None
1417

15-
let resource name =
16-
match eclocal with
17-
| true ->
18-
if Filename.basename mydir = "src" then
19-
List.fold_left Filename.concat mydir
20-
([Filename.parent_dir_name] @ name)
21-
else
22-
List.fold_left Filename.concat mydir name
23-
24-
| false ->
25-
List.fold_left Filename.concat mydir
26-
([Filename.parent_dir_name; "lib"; "easycrypt"] @ name)
27-
28-
module Sites = struct
29-
let theories = [resource ["theories"]]
18+
(* -------------------------------------------------------------------- *)
19+
let local (name : string list) : string =
20+
List.fold_left Filename.concat (Option.value ~default:"." sourceroot) name
21+
22+
(* -------------------------------------------------------------------- *)
23+
module type Sites = sig
24+
val commands : string
25+
val theories : string list
26+
end
27+
28+
(* -------------------------------------------------------------------- *)
29+
module LocalSites() : Sites = struct
30+
let commands = local ["scripts"; "testing"]
31+
let theories = [local ["theories"]]
3032
end
33+
34+
(* -------------------------------------------------------------------- *)
35+
module DuneSites() : Sites = struct
36+
let commands =
37+
Option.value ~default:"."
38+
(EcUtils.List.Exceptionless.hd EcDuneSites.Sites.commands)
39+
40+
let theories =
41+
EcDuneSites.Sites.theories
42+
end
43+
44+
(* -------------------------------------------------------------------- *)
45+
let sites : (module Sites) =
46+
if eclocal
47+
then (module LocalSites ())
48+
else (module DuneSites ())

src/ecRelocate.mli

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1+
(* -------------------------------------------------------------------- *)
12
val sourceroot : string option
2-
val resource : string list -> string
33

4-
module Sites : sig
4+
(* -------------------------------------------------------------------- *)
5+
module type Sites = sig
6+
val commands : string
57
val theories : string list
68
end
9+
10+
(* -------------------------------------------------------------------- *)
11+
val sites : (module Sites)

0 commit comments

Comments
 (0)