Skip to content

Commit e8b55b4

Browse files
authored
Merge branch 'master' into watch-mode
2 parents 1a1289f + 9d61c59 commit e8b55b4

24 files changed

Lines changed: 220 additions & 122 deletions

bin/main.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,7 @@ let resolve_target common ~(setup : Main.setup) s =
758758
else
759759
(1, true)
760760
in
761-
let s = String.sub s ~pos ~len:(String.length s - pos) in
761+
let s = String.drop s pos in
762762
let path = Path.relative Path.root (prefix_target common s) in
763763
check_path setup.contexts path;
764764
if Path.is_root path then

src/artifacts.ml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ let create (context : Context.t) ~public_libs l ~f =
2323
| None -> Filename.basename src
2424
in
2525
let key =
26-
if Sys.win32 && Filename.extension name = ".exe" then
27-
String.sub name ~pos:0 ~len:(String.length name - 4)
26+
if Sys.win32 then
27+
Option.value ~default:name
28+
(String.drop_suffix name ~suffix:".exe")
2829
else
2930
name
3031
in

src/context.ml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -178,13 +178,12 @@ let create ~(kind : Kind.t) ~path ~env ~env_nodes ~name ~merlin ~targets
178178
>>= fun findlib_config ->
179179

180180
let get_tool_using_findlib_config prog =
181-
Option.bind findlib_config ~f:(fun conf ->
182-
match Findlib.Config.get conf prog with
183-
| None -> None
184-
| Some s ->
185-
match Filename.analyze_program_name s with
186-
| In_path | Relative_to_current_dir -> which s
187-
| Absolute -> Some (Path.of_filename_relative_to_initial_cwd s))
181+
let open Option.O in
182+
findlib_config >>= fun conf ->
183+
Findlib.Config.get conf prog >>= fun s ->
184+
match Filename.analyze_program_name s with
185+
| In_path | Relative_to_current_dir -> which s
186+
| Absolute -> Some (Path.of_filename_relative_to_initial_cwd s)
188187
in
189188

190189
let ocamlc =

src/dsexp/dsexp.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ module Of_sexp = struct
557557
let if_paren_colon_form ~then_ ~else_ =
558558
peek_exn >>= function
559559
| List (_, Atom (loc, A s) :: _) when String.is_prefix s ~prefix:":" ->
560-
let name = String.sub s ~pos:1 ~len:(String.length s - 1) in
560+
let name = String.drop s 1 in
561561
enter
562562
(junk >>= fun () ->
563563
then_ >>| fun f ->

src/dune_file.ml

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -614,8 +614,7 @@ module Lib_dep = struct
614614
~before:(let%map s = string in
615615
let len = String.length s in
616616
if len > 0 && s.[0] = '!' then
617-
let s = String.sub s ~pos:1 ~len:(len - 1) in
618-
Right s
617+
Right (String.drop s 1)
619618
else
620619
Left s)
621620
~after:file
@@ -1145,9 +1144,8 @@ module Executables = struct
11451144
let is_ok (_, candidate) =
11461145
compare candidate link_mode = Eq
11471146
in
1148-
match List.find ~f:is_ok simple_representations with
1149-
| Some (s, _) -> Some (Dsexp.unsafe_atom_of_string s)
1150-
| None -> None
1147+
List.find ~f:is_ok simple_representations
1148+
|> Option.map ~f:(fun (s, _) -> Dsexp.unsafe_atom_of_string s)
11511149

11521150
let dgen link_mode =
11531151
match simple_dgen link_mode with
@@ -1288,13 +1286,12 @@ module Executables = struct
12881286
in
12891287
List.map2 names public_names
12901288
~f:(fun (_, name) (_, pub) ->
1291-
match pub with
1292-
| None -> None
1293-
| Some pub -> Some ({ Install_conf.
1294-
src = name ^ ext
1295-
; dst = Some pub
1296-
}))
1297-
|> List.filter_map ~f:(fun x -> x)
1289+
Option.map pub ~f:(fun pub ->
1290+
{ Install_conf.
1291+
src = name ^ ext
1292+
; dst = Some pub
1293+
}))
1294+
|> List.filter_opt
12981295
in
12991296
match to_install with
13001297
| [] -> begin

src/findlib.ml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ let path t = t.path
200200
let root_package_name s =
201201
match String.index s '.' with
202202
| None -> s
203-
| Some i -> String.sub s ~pos:0 ~len:i
203+
| Some i -> String.take s i
204204

205205
let dummy_package t ~name =
206206
let dir =
@@ -223,8 +223,7 @@ let parse_package t ~meta_file ~name ~parent_dir ~vars =
223223
| None | Some "" -> parent_dir
224224
| Some pkg_dir ->
225225
if pkg_dir.[0] = '+' || pkg_dir.[0] = '^' then
226-
Path.relative t.stdlib_dir
227-
(String.sub pkg_dir ~pos:1 ~len:(String.length pkg_dir - 1))
226+
Path.relative t.stdlib_dir (String.drop pkg_dir 1)
228227
else if Filename.is_relative pkg_dir then
229228
Path.relative parent_dir pkg_dir
230229
else
@@ -305,9 +304,9 @@ let find_and_acknowledge_meta t ~fq_name =
305304
else
306305
loop dirs
307306
| [] ->
308-
match String.Map.find t.builtins root_name with
309-
| Some meta -> Some (t.stdlib_dir, Path.of_string "<internal>", meta)
310-
| None -> None
307+
String.Map.find t.builtins root_name
308+
|> Option.map ~f:(fun meta ->
309+
(t.stdlib_dir, Path.of_string "<internal>", meta))
311310
in
312311
match loop t.path with
313312
| None ->

src/install_rules.ml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,7 @@ module Gen(P : Params) = struct
102102
List.iter template ~f:(fun s ->
103103
if String.is_prefix s ~prefix:"#" then
104104
match
105-
String.extract_blank_separated_words
106-
(String.sub s ~pos:1 ~len:(String.length s - 1))
105+
String.extract_blank_separated_words (String.drop s 1)
107106
with
108107
| ["JBUILDER_GEN" | "DUNE_GEN"] ->
109108
Format.fprintf ppf "%a@," Meta.pp meta.entries

src/installed_dune_file.ml

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,13 @@ let parse_sub_systems ~parsing_context sexps =
44
List.filter_map sexps ~f:(fun sexp ->
55
let name, ver, data =
66
Dsexp.Of_sexp.(parse (triple string (located Syntax.Version.dparse) raw)
7-
parsing_context) sexp
7+
parsing_context) sexp
88
in
9-
match Sub_system_name.get name with
10-
| None ->
11-
(* We ignore sub-systems that are not internally known. These
12-
correspond to plugins that are not in use in the current
13-
workspace. *)
14-
None
15-
| Some name -> Some (name, (Dsexp.Ast.loc sexp, ver, data)))
9+
(* We ignore sub-systems that are not internally known. These
10+
correspond to plugins that are not in use in the current
11+
workspace. *)
12+
Option.map (Sub_system_name.get name) ~f:(fun name ->
13+
(name, (Dsexp.Ast.loc sexp, ver, data))))
1614
|> Sub_system_name.Map.of_list
1715
|> (function
1816
| Ok x -> x

src/module.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ let make ?impl ?intf ?obj_name name =
7272
let fn = Path.basename file.path in
7373
match String.index fn '.' with
7474
| None -> fn
75-
| Some i -> String.sub fn ~pos:0 ~len:i
75+
| Some i -> String.take fn i
7676
in
7777
{ name
7878
; impl

src/ocaml-config/ocaml_config.ml

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -215,12 +215,9 @@ module Vars = struct
215215
match String.index line ':' with
216216
| Some i ->
217217
let x =
218-
(String.sub line ~pos:0 ~len:i,
219-
let len = String.length line - i - 2 in
220-
if len < 0 then
221-
""
222-
else
223-
String.sub line ~pos:(i + 2) ~len)
218+
( String.take line i
219+
, String.drop line (i + 2) (* skipping the space *)
220+
)
224221
in
225222
loop (x :: acc) lines
226223
| None ->
@@ -264,13 +261,11 @@ module Vars = struct
264261
fail "Value of %S is neither 'true' neither 'false': %s." var s
265262

266263
let get_int_opt t var =
267-
match get_opt t var with
268-
| None -> None
269-
| Some s ->
264+
Option.bind (get_opt t var) ~f:(fun s ->
270265
match int_of_string s with
271266
| x -> Some x
272267
| exception _ ->
273-
fail "Value of %S is not an integer: %s." var s
268+
fail "Value of %S is not an integer: %s." var s)
274269

275270
let get_words t var =
276271
match get_opt t var with

0 commit comments

Comments
 (0)