Skip to content

Commit

Permalink
Fix OCaml 4.08 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
sim642 committed Mar 9, 2024
1 parent dcb4dfc commit 29bedd9
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/depgraph/dune_describe_graph.ml
@@ -1,5 +1,6 @@
open Common
open Dune_describe
open Std

module Digest_map = Map.Make (Digest)

Expand Down Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions 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
)
11 changes: 11 additions & 0 deletions 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

0 comments on commit 29bedd9

Please sign in to comment.