diff --git a/src/depgraph/dune_describe_graph.ml b/src/depgraph/dune_describe_graph.ml index 4af01ea..b416b96 100644 --- a/src/depgraph/dune_describe_graph.ml +++ b/src/depgraph/dune_describe_graph.ml @@ -1,5 +1,6 @@ open Common open Dune_describe +open Std module Digest_map = Map.Make (Digest) @@ -36,13 +37,11 @@ let g_of_modules parent modules = List.fold_left fold_module G.empty modules let find_library_module_name _library modules: string option = - (* TODO: List.find_map isn't on OCaml 4.08 *) - List.find_map (fun (m: module_) -> - (* TODO: String.ends_with isn't on OCaml 4.08 *) + List_compat.find_map (fun (m: module_) -> match m.impl with - | Some impl when String.ends_with ~suffix:".ml-gen" impl && String.ends_with ~suffix:"__" m.name -> + | Some impl when String_compat.ends_with ~suffix:".ml-gen" impl && String_compat.ends_with ~suffix:"__" m.name -> Some (String.sub m.name 0 (String.length m.name - 2)) - | Some impl when String.ends_with ~suffix:".ml-gen" impl -> + | Some impl when String_compat.ends_with ~suffix:".ml-gen" impl -> Some m.name | _ -> None ) modules diff --git a/src/std/list_compat.ml b/src/std/list_compat.ml new file mode 100644 index 0000000..4d22ddb --- /dev/null +++ b/src/std/list_compat.ml @@ -0,0 +1,7 @@ +let rec find_map f = function + | [] -> None + | x :: l -> ( + match f x with + | Some _ as result -> result + | None -> find_map f l + ) diff --git a/src/std/string_compat.ml b/src/std/string_compat.ml new file mode 100644 index 0000000..325535e --- /dev/null +++ b/src/std/string_compat.ml @@ -0,0 +1,11 @@ +open String + +let ends_with ~suffix s = + let len_s = length s + and len_suf = length suffix in + let diff = len_s - len_suf in + let rec aux i = + if i = len_suf then true + else if unsafe_get s (diff + i) <> unsafe_get suffix i then false + else aux (i + 1) + in diff >= 0 && aux 0