From 213aea00959708f6189f244ed3a63042fff378f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ulysse=20G=C3=A9rard?= Date: Tue, 21 Dec 2021 14:47:48 +0100 Subject: [PATCH 1/4] Add a test illustrating issue #1388 --- tests/test-dirs/config/issue1388.t | 32 ++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 tests/test-dirs/config/issue1388.t diff --git a/tests/test-dirs/config/issue1388.t b/tests/test-dirs/config/issue1388.t new file mode 100644 index 0000000000..4987bdec99 --- /dev/null +++ b/tests/test-dirs/config/issue1388.t @@ -0,0 +1,32 @@ + $ cat >.merlin < STDLIB /my/std + > FLG -I +../cerberus/flags + > S +../cerberus/source + > B +../cerberus/build + > EOF + +FIXME include_dir should also replace the `+` by the lib path + $ echo "" | $MERLIN single dump-configuration -filename test.ml | \ + > grep -A2 'include_dirs\|source_path\|build_path' + "include_dirs": [ + "$TESTCASE_ROOT/+../cerberus/flags" + ], + -- + "build_path": [ + "/my/cerberus/build" + ], + "source_path": [ + "/my/cerberus/source" + ], + + $ echo "" | $MERLIN single dump -what paths -filename test.ml + { + "class": "return", + "value": [ + "$TESTCASE_ROOT", + "$TESTCASE_ROOT/+../cerberus/flags", + "/my/cerberus/build", + "lib/ocaml" + ], + "notifications": [] + } From bc11990d65ee5723e98ad53c350fe1ca8f060341 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ulysse=20G=C3=A9rard?= Date: Tue, 21 Dec 2021 14:30:35 +0100 Subject: [PATCH 2/4] Make dot-merlin-reader send the STDLIB option --- src/dot-merlin/dot_merlin_reader.ml | 1 + 1 file changed, 1 insertion(+) diff --git a/src/dot-merlin/dot_merlin_reader.ml b/src/dot-merlin/dot_merlin_reader.ml index 9219dad312..78c1715049 100644 --- a/src/dot-merlin/dot_merlin_reader.ml +++ b/src/dot-merlin/dot_merlin_reader.ml @@ -461,6 +461,7 @@ let postprocess cfg = ; List.concat_map pkg_paths ~f:(fun p -> [ `B p; `S p ]) ; ppx ; List.map failures ~f:(fun s -> `ERROR_MSG s) + ; Option.to_list cfg.stdlib |> List.map ~f:(fun std -> `STDLIB std) ] let load dot_merlin_file = From c45a94fe460e8be3ad3dc5f412a465ec87e6f493 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ulysse=20G=C3=A9rard?= Date: Tue, 21 Dec 2021 14:32:06 +0100 Subject: [PATCH 3/4] Delay flags canonization for `expand_directory` to work as expected --- src/kernel/mconfig.ml | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/src/kernel/mconfig.ml b/src/kernel/mconfig.ml index e542384c59..181aebee46 100644 --- a/src/kernel/mconfig.ml +++ b/src/kernel/mconfig.ml @@ -63,6 +63,9 @@ let canonicalize_filename path = let marg_path f = Marg.param "path" (fun path acc -> f (canonicalize_filename path) acc) +let marg_path_no_canon f = + Marg.param "path" (fun path acc -> f path acc) + let marg_commandline f = Marg.param "command" (fun workval acc -> f {workdir = unsafe_get_cwd (); workval} acc) @@ -413,7 +416,7 @@ let ocaml_alert_spec = let ocaml_flags = [ ( "-I", - marg_path (fun dir ocaml -> + marg_path_no_canon (fun dir ocaml -> {ocaml with include_dirs = dir :: ocaml.include_dirs}), " Add to the list of include directories" ); @@ -691,7 +694,7 @@ let source_path config = config.merlin.source_path] |> List.filter_dup -let build_path config = ( +let include_dirs ~stdlib config = let dirs = match config.ocaml.threads with | `None -> config.ocaml.include_dirs @@ -703,10 +706,12 @@ let build_path config = ( config.merlin.build_path @ dirs in + List.map dirs ~f:(fun dir -> Misc.expand_directory stdlib dir + |> Misc.canonicalize_filename) + +let build_path config = ( let stdlib = stdlib config in - let exp_dirs = - List.map ~f:(Misc.expand_directory stdlib) dirs - in + let exp_dirs = include_dirs ~stdlib config in let stdlib = if config.ocaml.no_std_include then [] else [stdlib] in let dirs = List.rev_append exp_dirs stdlib in let result = @@ -721,21 +726,8 @@ let build_path config = ( ) let cmt_path config = ( - let dirs = - match config.ocaml.threads with - | `None -> config.ocaml.include_dirs - | `Threads -> "+threads" :: config.ocaml.include_dirs - | `Vmthreads -> "+vmthreads" :: config.ocaml.include_dirs - in - let dirs = - config.merlin.cmt_path @ - config.merlin.build_path @ - dirs - in let stdlib = stdlib config in - let exp_dirs = - List.map ~f:(Misc.expand_directory stdlib) dirs - in + let exp_dirs = include_dirs ~stdlib config in let stdlib = if config.ocaml.no_std_include then [] else [stdlib] in config.query.directory :: List.rev_append exp_dirs stdlib ) From e1f7659c70aeac01063c10028ac7b24ab0be2170 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ulysse=20G=C3=A9rard?= Date: Tue, 21 Dec 2021 14:49:14 +0100 Subject: [PATCH 4/4] Promote corrected test --- tests/test-dirs/config/issue1388.t | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tests/test-dirs/config/issue1388.t b/tests/test-dirs/config/issue1388.t index 4987bdec99..a9597a3702 100644 --- a/tests/test-dirs/config/issue1388.t +++ b/tests/test-dirs/config/issue1388.t @@ -5,11 +5,10 @@ > B +../cerberus/build > EOF -FIXME include_dir should also replace the `+` by the lib path $ echo "" | $MERLIN single dump-configuration -filename test.ml | \ > grep -A2 'include_dirs\|source_path\|build_path' "include_dirs": [ - "$TESTCASE_ROOT/+../cerberus/flags" + "+../cerberus/flags" ], -- "build_path": [ @@ -24,9 +23,9 @@ FIXME include_dir should also replace the `+` by the lib path "class": "return", "value": [ "$TESTCASE_ROOT", - "$TESTCASE_ROOT/+../cerberus/flags", + "/my/cerberus/flags", "/my/cerberus/build", - "lib/ocaml" + "/my/std" ], "notifications": [] }