mirror of
https://github.com/CatalaLang/catala.git
synced 2024-11-08 07:51:43 +03:00
Clerk: fix handling of dependency on the catala exec
This commit is contained in:
parent
d4198f52b4
commit
c019d1568f
@ -232,18 +232,7 @@ module Poll = struct
|
||||
| Some root ->
|
||||
Unix.realpath
|
||||
File.(root / "_build" / "default" / "compiler" / "catala.exe")
|
||||
| None ->
|
||||
Unix.realpath
|
||||
@@ String.trim
|
||||
@@ File.process_out
|
||||
~check_exit:(function
|
||||
| 0 -> ()
|
||||
| _ ->
|
||||
Message.raise_error
|
||||
"Could not find the @{<yellow>catala@} program, please \
|
||||
fix your installation")
|
||||
"/bin/sh"
|
||||
["-c"; "command -v catala"])
|
||||
| None -> File.check_exec "catala")
|
||||
|
||||
let build_dir : File.t Lazy.t =
|
||||
lazy
|
||||
@ -401,7 +390,7 @@ let base_bindings catala_exe catala_flags =
|
||||
Nj.binding Var.catala_exe
|
||||
[
|
||||
(match catala_exe with
|
||||
| Some e -> e
|
||||
| Some e -> File.check_exec e
|
||||
| None -> Lazy.force Poll.catala_exe);
|
||||
];
|
||||
Nj.binding Var.catala_flags catala_flags;
|
||||
@ -518,6 +507,12 @@ let gen_build_statements (item : Scan.item) : Nj.ninja =
|
||||
List.map (fun m -> (!Var.builddir / src /../ m) ^ ".cmx") modules
|
||||
@ [ml_file]
|
||||
in
|
||||
(* Note: this rule is incomplete in that it only provide the direct module
|
||||
dependencies, and ocamlopt needs the transitive closure of dependencies
|
||||
for linking, which we can't provide here ; catala does that work for
|
||||
the interpret case, so we should probably add a [catala link] (or
|
||||
[clerk link]) command that gathers these dependencies and wraps
|
||||
[ocamlopt]. *)
|
||||
Nj.build "ocaml-exec" ~inputs
|
||||
~outputs:[target "exe"]
|
||||
~implicit_out:(List.map target implicit_out_exts)
|
||||
@ -650,8 +645,8 @@ let test_targets_by_dir items =
|
||||
]
|
||||
|
||||
let build_statements dir =
|
||||
(* Unfortunately we need to express the module name bindings first, so need to
|
||||
iterate twice using Seq.memoize *)
|
||||
(* Todo: generate the targets_by_dir alongside the targets, avoiding the need
|
||||
for [memoize] and two traversals here *)
|
||||
Scan.tree dir
|
||||
|> Seq.memoize
|
||||
|> fun items ->
|
||||
|
@ -119,6 +119,22 @@ let check_file f =
|
||||
try if Sys.is_directory f then None else Some f
|
||||
with Unix.Unix_error _ | Sys_error _ -> None
|
||||
|
||||
let get_command t =
|
||||
String.trim
|
||||
@@ process_out
|
||||
~check_exit:(function 0 -> () | _ -> raise Not_found)
|
||||
"/bin/sh"
|
||||
["-c"; "command -v " ^ Filename.quote t]
|
||||
|
||||
let dir_sep_char = Filename.dir_sep.[0]
|
||||
|
||||
let check_exec t =
|
||||
try if String.contains t dir_sep_char then Unix.realpath t else get_command t
|
||||
with Unix.Unix_error _ | Sys_error _ ->
|
||||
Message.raise_error
|
||||
"Could not find the @{<yellow>%s@} program, please fix your installation"
|
||||
(Filename.quote t)
|
||||
|
||||
let ( / ) a b =
|
||||
if a = "" || a = Filename.current_dir_name then b else Filename.concat a b
|
||||
|
||||
@ -127,7 +143,7 @@ let ( /../ ) a b = dirname a / b
|
||||
let ( -.- ) file ext = Filename.chop_extension file ^ "." ^ ext
|
||||
|
||||
let path_to_list path =
|
||||
String.split_on_char Filename.dir_sep.[0] path
|
||||
String.split_on_char dir_sep_char path
|
||||
|> List.filter (function "" | "." -> false | _ -> true)
|
||||
|
||||
let equal a b =
|
||||
|
@ -89,6 +89,12 @@ val check_file : t -> t option
|
||||
(** Returns its argument if it exists and is a plain file, [None] otherwise.
|
||||
Does not do resolution like [check_directory]. *)
|
||||
|
||||
val check_exec : t -> t
|
||||
(** Resolves a command:
|
||||
- if [t] is a plain name, resolve in PATH
|
||||
- if [t] is relative, returns its absolute path
|
||||
- fails with an error explaining that [t] was not found *)
|
||||
|
||||
val ( / ) : t -> t -> t
|
||||
(** [Filename.concat]: Sugar to allow writing
|
||||
[File.("some" / "relative" / "path")]. As an exception, if the lhs is [.],
|
||||
|
Loading…
Reference in New Issue
Block a user