Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

merlin: communicate STDLIB directive #4211

Merged
merged 3 commits into from
Feb 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ Unreleased
- Dune no longer automatically create or edit `dune-project` files
(#4239, fixes #4108, @jeremiedimino)

- Have `dune` communicate the location of the standard library directory to
`merlin` (#4211, fixes #4188, @nojb)

2.8.2 (21/01/2021)
------------------

Expand Down
4 changes: 3 additions & 1 deletion src/dune_rules/exe_rules.ml
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ let executables_rules ~sctx ~dir ~expander ~dir_contents ~scope ~compile_info
~modules ~flags ~requires_link ~requires_compile ~preprocessing:pp
~js_of_ocaml ~opaque:Inherit_from_settings ~package:exes.package
in
let stdlib_dir = ctx.Context.stdlib_dir in
let requires_compile = Compilation_context.requires_compile cctx in
let preprocess =
Preprocess.Per_module.with_instrumentation exes.buildable.preprocess
Expand Down Expand Up @@ -197,7 +198,8 @@ let executables_rules ~sctx ~dir ~expander ~dir_contents ~scope ~compile_info
~promote:exes.promote ~embed_in_plugin_libraries
in
( cctx
, Merlin.make ~requires:requires_compile ~flags ~modules ~preprocess ~obj_dir
, Merlin.make ~requires:requires_compile ~stdlib_dir ~flags ~modules
~preprocess ~obj_dir
~dialects:(Dune_project.dialects (Scope.project scope))
~ident:(Lib.Compile.merlin_ident compile_info)
() )
Expand Down
5 changes: 3 additions & 2 deletions src/dune_rules/lib_rules.ml
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,7 @@ let library_rules (lib : Library.t) ~cctx ~source_modules ~dir_contents
let dir = Compilation_context.dir cctx in
let scope = Compilation_context.scope cctx in
let requires_compile = Compilation_context.requires_compile cctx in
let stdlib_dir = (Compilation_context.context cctx).Context.stdlib_dir in
let dep_graphs = Dep_rules.rules cctx ~modules in
Option.iter vimpl ~f:(Virtual_rules.setup_copy_rules_for_impl ~sctx ~dir);
Check_rules.add_obj_dir sctx ~obj_dir;
Expand Down Expand Up @@ -415,8 +416,8 @@ let library_rules (lib : Library.t) ~cctx ~source_modules ~dir_contents
; compile_info
};
( cctx
, Merlin.make ~requires:requires_compile ~flags ~modules ~preprocess
~libname:(snd lib.name) ~obj_dir
, Merlin.make ~requires:requires_compile ~stdlib_dir ~flags ~modules
~preprocess ~libname:(snd lib.name) ~obj_dir
~dialects:(Dune_project.dialects (Scope.project scope))
~ident:(Lib.Compile.merlin_ident compile_info)
() )
Expand Down
22 changes: 14 additions & 8 deletions src/dune_rules/merlin.ml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ module Processed = struct

(* Most of the configuration is shared accros a same lib/exe... *)
type config =
{ obj_dirs : Path.Set.t
{ stdlib_dir : Path.t
; obj_dirs : Path.Set.t
; src_dirs : Path.Set.t
; flags : string list
; extensions : string Ml_kind.Dict.t list
Expand All @@ -42,13 +43,14 @@ module Processed = struct

let load_file = Persist.load

let to_sexp ~pp { obj_dirs; src_dirs; flags; extensions } =
let to_sexp ~pp { stdlib_dir; obj_dirs; src_dirs; flags; extensions } =
let serialize_path = Path.to_absolute_filename in
let to_atom s = Sexp.Atom s in
let make_directive tag value = Sexp.List [ Atom tag; value ] in
let make_directive_of_path tag path =
make_directive tag (Sexp.Atom (serialize_path path))
in
let stdlib_dir = [ make_directive_of_path "STDLIB" stdlib_dir ] in
let exclude_query_dir = [ Sexp.List [ Atom "EXCLUDE_QUERY_DIR" ] ] in
let obj_dirs =
Path.Set.to_list obj_dirs |> List.map ~f:(make_directive_of_path "B")
Expand All @@ -73,7 +75,8 @@ module Processed = struct
make_directive "SUFFIX" (Sexp.Atom (Printf.sprintf "%s %s" impl intf)))
in
Sexp.List
(List.concat [ exclude_query_dir; obj_dirs; src_dirs; flags; suffixes ])
(List.concat
[ stdlib_dir; exclude_query_dir; obj_dirs; src_dirs; flags; suffixes ])

let get { modules; pp_config; config } ~filename =
let fname = Filename.remove_extension filename |> String.lowercase in
Expand Down Expand Up @@ -106,7 +109,8 @@ module Unprocessed = struct
for it's elaboration via the function [process : Unprocessed.t ... ->
Processed.t] *)
type config =
{ requires : Lib.Set.t
{ stdlib_dir : Path.t
; requires : Lib.Set.t
; flags : string list Action_builder.t
; preprocess :
Preprocess.Without_instrumentation.t Preprocess.t Module_name.Per_item.t
Expand All @@ -122,7 +126,7 @@ module Unprocessed = struct
; modules : Modules.t
}

let make ?(requires = Ok []) ~flags
let make ?(requires = Ok []) ~stdlib_dir ~flags
?(preprocess = Preprocess.Per_module.no_preprocessing ()) ?libname
?(source_dirs = Path.Source.Set.empty) ~modules ~obj_dir ~dialects ~ident
() =
Expand All @@ -146,7 +150,8 @@ module Unprocessed = struct
in
let extensions = Dialect.DB.extensions_for_merlin dialects in
let config =
{ requires
{ stdlib_dir
; requires
; flags = Action_builder.catch flags ~on_error:[]
; preprocess
; libname
Expand Down Expand Up @@ -235,7 +240,8 @@ module Unprocessed = struct
{ modules
; ident = _
; config =
{ extensions
{ stdlib_dir
; extensions
; flags
; objs_dirs
; source_dirs
Expand All @@ -260,7 +266,7 @@ module Unprocessed = struct
Path.Set.union src_dirs
(Path.Set.of_list_map ~f:Path.source more_src_dirs)
in
{ Processed.src_dirs; obj_dirs; flags; extensions }
{ Processed.stdlib_dir; src_dirs; obj_dirs; flags; extensions }
and+ pp_config =
Module_name.Per_item.map_with_targets preprocess
~f:(pp_flags sctx ~expander libname)
Expand Down
1 change: 1 addition & 0 deletions src/dune_rules/merlin.mli
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ end

val make :
?requires:Lib.t list Or_exn.t
-> stdlib_dir:Path.t
-> flags:Ocaml_flags.t
-> ?preprocess:
Preprocess.Without_instrumentation.t Preprocess.t Module_name.Per_item.t
Expand Down
9 changes: 6 additions & 3 deletions test/blackbox-tests/test-cases/github1946.t/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ This test demonstrates that -ppx is no more missing when two stanzas are
in the same dune file, but require different ppx specifications

$ dune build @all --profile release
$ dune ocaml-merlin --dump-config=$(pwd)
$ dune ocaml-merlin --dump-config=$(pwd) |
> sed 's#'$(opam config var prefix)'#OPAM_PREFIX#'
Usesppx1
((EXCLUDE_QUERY_DIR)
((STDLIB OPAM_PREFIX/lib/ocaml)
(EXCLUDE_QUERY_DIR)
(B
$TESTCASE_ROOT/_build/default/.usesppx1.objs/byte)
(S
Expand All @@ -17,7 +19,8 @@ in the same dune file, but require different ppx specifications
'library-name="usesppx1"'"))
(FLG (-open Usesppx1 -w -40)))
Usesppx2
((EXCLUDE_QUERY_DIR)
((STDLIB OPAM_PREFIX/lib/ocaml)
(EXCLUDE_QUERY_DIR)
(B
$TESTCASE_ROOT/_build/default/.usesppx2.objs/byte)
(S
Expand Down
18 changes: 12 additions & 6 deletions test/blackbox-tests/test-cases/github759.t/run.t
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
$ dune build foo.cma --profile release
$ dune ocaml-merlin --dump-config=$(pwd)
$ dune ocaml-merlin --dump-config=$(pwd) |
> sed 's#'$(opam config var prefix)'#OPAM_PREFIX#'
Foo
((EXCLUDE_QUERY_DIR)
((STDLIB OPAM_PREFIX/lib/ocaml)
(EXCLUDE_QUERY_DIR)
(B
$TESTCASE_ROOT/_build/default/.foo.objs/byte)
(S
Expand All @@ -10,9 +12,11 @@

$ rm -f .merlin
$ dune build foo.cma --profile release
$ dune ocaml-merlin --dump-config=$(pwd)
$ dune ocaml-merlin --dump-config=$(pwd) |
> sed 's#'$(opam config var prefix)'#OPAM_PREFIX#'
Foo
((EXCLUDE_QUERY_DIR)
((STDLIB OPAM_PREFIX/lib/ocaml)
(EXCLUDE_QUERY_DIR)
(B
$TESTCASE_ROOT/_build/default/.foo.objs/byte)
(S
Expand All @@ -21,9 +25,11 @@

$ echo toto > .merlin
$ dune build foo.cma --profile release
$ dune ocaml-merlin --dump-config=$(pwd)
$ dune ocaml-merlin --dump-config=$(pwd) |
> sed 's#'$(opam config var prefix)'#OPAM_PREFIX#'
Foo
((EXCLUDE_QUERY_DIR)
((STDLIB OPAM_PREFIX/lib/ocaml)
(EXCLUDE_QUERY_DIR)
(B
$TESTCASE_ROOT/_build/default/.foo.objs/byte)
(S
Expand Down
6 changes: 4 additions & 2 deletions test/blackbox-tests/test-cases/merlin/github4125.t/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ We call `$(opam switch show)` so that this test always uses an existing switch
..
lib-foo

$ dune ocaml-merlin --dump-config="$(pwd)"
$ dune ocaml-merlin --dump-config="$(pwd)" |
> sed 's#'$(opam config var prefix)'#OPAM_PREFIX#'
Foo
((EXCLUDE_QUERY_DIR)
((STDLIB OPAM_PREFIX/lib/ocaml)
(EXCLUDE_QUERY_DIR)
(B
$TESTCASE_ROOT/_build/cross/.foo.objs/byte)
(S
Expand Down
17 changes: 10 additions & 7 deletions test/blackbox-tests/test-cases/merlin/merlin-from-subdir.t/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ We build the project
bar

Verify that merlin configuration was generated...
$ dune ocaml-merlin --dump-config=$(pwd)
$ dune ocaml-merlin --dump-config=$(pwd) |
> sed 's#'$(opam config var prefix)'#OPAM_PREFIX#'
Test
((EXCLUDE_QUERY_DIR)
((STDLIB OPAM_PREFIX/lib/ocaml)
(EXCLUDE_QUERY_DIR)
(B
$TESTCASE_ROOT/_build/default/.foo.objs/byte)
(B
Expand All @@ -22,7 +24,8 @@ Verify that merlin configuration was generated...
-short-paths
-keep-locs)))
Foo
((EXCLUDE_QUERY_DIR)
((STDLIB OPAM_PREFIX/lib/ocaml)
(EXCLUDE_QUERY_DIR)
(B
$TESTCASE_ROOT/_build/default/.foo.objs/byte)
(S
Expand All @@ -44,12 +47,12 @@ Now we check that both querying from the root and the subfolder works
$ FILE=$(pwd)/foo.ml
$ FILE411=$(pwd)/411/test.ml

$ dune ocaml-merlin <<EOF | sed -E "s/[[:digit:]]+:/\?:/g"
$ dune ocaml-merlin <<EOF | sed -E "s/[[:digit:]]+:/\?:/g" | sed 's#'$(opam config var prefix)'#OPAM_PREFIX#'
> (4:File${#FILE}:$FILE)
> EOF
((?:EXCLUDE_QUERY_DIR)(?:B?:$TESTCASE_ROOT/_build/default/.foo.objs/byte)(?:S?:$TESTCASE_ROOT)(?:S?:$TESTCASE_ROOT/411)(?:FLG(?:-w?:@1..3@5..28@30..39@43@46..47@49..57@61..62-?:-strict-sequence?:-strict-formats?:-short-paths?:-keep-locs)))
((?:STDLIB?:OPAM_PREFIX/lib/ocaml)(?:EXCLUDE_QUERY_DIR)(?:B?:$TESTCASE_ROOT/_build/default/.foo.objs/byte)(?:S?:$TESTCASE_ROOT)(?:S?:$TESTCASE_ROOT/411)(?:FLG(?:-w?:@1..3@5..28@30..39@43@46..47@49..57@61..62-?:-strict-sequence?:-strict-formats?:-short-paths?:-keep-locs)))

$ dune ocaml-merlin <<EOF | sed -E "s/[[:digit:]]+:/\?:/g"
$ dune ocaml-merlin <<EOF | sed -E "s/[[:digit:]]+:/\?:/g" | sed 's#'$(opam config var prefix)'#OPAM_PREFIX#'
> (4:File${#FILE411}:$FILE411)
> EOF
((?:EXCLUDE_QUERY_DIR)(?:B?:$TESTCASE_ROOT/_build/default/.foo.objs/byte)(?:B?:$TESTCASE_ROOT/_build/default/.test.eobjs/byte)(?:S?:$TESTCASE_ROOT)(?:S?:$TESTCASE_ROOT/411)(?:FLG(?:-w?:@1..3@5..28@30..39@43@46..47@49..57@61..62-?:-strict-sequence?:-strict-formats?:-short-paths?:-keep-locs)))
((?:STDLIB?:OPAM_PREFIX/lib/ocaml)(?:EXCLUDE_QUERY_DIR)(?:B?:$TESTCASE_ROOT/_build/default/.foo.objs/byte)(?:B?:$TESTCASE_ROOT/_build/default/.test.eobjs/byte)(?:S?:$TESTCASE_ROOT)(?:S?:$TESTCASE_ROOT/411)(?:FLG(?:-w?:@1..3@5..28@30..39@43@46..47@49..57@61..62-?:-strict-sequence?:-strict-formats?:-short-paths?:-keep-locs)))
24 changes: 16 additions & 8 deletions test/blackbox-tests/test-cases/merlin/merlin-tests.t/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ CRAM sanitization
$ dune ocaml-merlin --dump-config=$(pwd)/exe |
> sed 's#'$(opam config var prefix)'#OPAM_PREFIX#'
X
((EXCLUDE_QUERY_DIR)
((STDLIB OPAM_PREFIX/lib/ocaml)
(EXCLUDE_QUERY_DIR)
(B OPAM_PREFIX/lib/bytes)
(B OPAM_PREFIX/lib/findlib)
(B OPAM_PREFIX/lib/ocaml)
Expand All @@ -27,7 +28,8 @@ CRAM sanitization
$ dune ocaml-merlin --dump-config=$(pwd)/lib |
> sed 's#'$(opam config var prefix)'#OPAM_PREFIX#'
File
((EXCLUDE_QUERY_DIR)
((STDLIB OPAM_PREFIX/lib/ocaml)
(EXCLUDE_QUERY_DIR)
(B
$TESTCASE_ROOT/_build/default/lib/.bar.objs/byte)
(S
Expand All @@ -42,7 +44,8 @@ CRAM sanitization
'library-name="bar"'"))
(FLG (-open Bar -w -40)))
Bar
((EXCLUDE_QUERY_DIR)
((STDLIB OPAM_PREFIX/lib/ocaml)
(EXCLUDE_QUERY_DIR)
(B
$TESTCASE_ROOT/_build/default/lib/.bar.objs/byte)
(S
Expand All @@ -57,7 +60,8 @@ CRAM sanitization
'library-name="bar"'"))
(FLG (-open Bar -w -40)))
Privmod
((EXCLUDE_QUERY_DIR)
((STDLIB OPAM_PREFIX/lib/ocaml)
(EXCLUDE_QUERY_DIR)
(B OPAM_PREFIX/lib/bytes)
(B OPAM_PREFIX/lib/findlib)
(B OPAM_PREFIX/lib/ocaml)
Expand All @@ -78,7 +82,8 @@ CRAM sanitization
'library-name="foo"'"))
(FLG (-open Foo -w -40)))
Foo
((EXCLUDE_QUERY_DIR)
((STDLIB OPAM_PREFIX/lib/ocaml)
(EXCLUDE_QUERY_DIR)
(B OPAM_PREFIX/lib/bytes)
(B OPAM_PREFIX/lib/findlib)
(B OPAM_PREFIX/lib/ocaml)
Expand Down Expand Up @@ -108,7 +113,8 @@ Make sure pp flag is correct and variables are expanded
$ dune ocaml-merlin --dump-config=$(pwd)/pp-with-expand |
> sed 's#'$(opam config var prefix)'#OPAM_PREFIX#'
Foobar
((EXCLUDE_QUERY_DIR)
((STDLIB OPAM_PREFIX/lib/ocaml)
(EXCLUDE_QUERY_DIR)
(B
$TESTCASE_ROOT/_build/default/pp-with-expand/.foobar.eobjs/byte)
(S
Expand All @@ -124,7 +130,8 @@ Check hash of executables names if more than one
$ dune ocaml-merlin --dump-config=$(pwd)/exes |
> sed 's#'$(opam config var prefix)'#OPAM_PREFIX#'
Y
((EXCLUDE_QUERY_DIR)
((STDLIB OPAM_PREFIX/lib/ocaml)
(EXCLUDE_QUERY_DIR)
(B
$TESTCASE_ROOT/_build/default/exes/.x.eobjs/byte)
(S
Expand All @@ -137,7 +144,8 @@ Check hash of executables names if more than one
-short-paths
-keep-locs)))
X
((EXCLUDE_QUERY_DIR)
((STDLIB OPAM_PREFIX/lib/ocaml)
(EXCLUDE_QUERY_DIR)
(B
$TESTCASE_ROOT/_build/default/exes/.x.eobjs/byte)
(S
Expand Down
9 changes: 6 additions & 3 deletions test/blackbox-tests/test-cases/merlin/per-module-pp.t/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
We dump the config for Foo and Bar modules but the pp.exe preprocessor
should appear only once since only Foo is using it.

$ dune ocaml-merlin --dump-config=$(pwd)
$ dune ocaml-merlin --dump-config=$(pwd) |
> sed 's#'$(opam config var prefix)'#OPAM_PREFIX#'
Foo
((EXCLUDE_QUERY_DIR)
((STDLIB OPAM_PREFIX/lib/ocaml)
(EXCLUDE_QUERY_DIR)
(B
$TESTCASE_ROOT/_build/default/.foo.objs/byte)
(S
Expand All @@ -21,7 +23,8 @@ should appear only once since only Foo is using it.
-short-paths
-keep-locs)))
Bar
((EXCLUDE_QUERY_DIR)
((STDLIB OPAM_PREFIX/lib/ocaml)
(EXCLUDE_QUERY_DIR)
(B
$TESTCASE_ROOT/_build/default/.foo.objs/byte)
(S
Expand Down
8 changes: 4 additions & 4 deletions test/blackbox-tests/test-cases/merlin/server.t/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

$ dune build @check

$ dune ocaml-merlin <<EOF | sed -E "s/[[:digit:]]+:/\?:/g"
$ dune ocaml-merlin <<EOF | sed -E "s/[[:digit:]]+:/\?:/g" | sed 's#'$(opam config var prefix)'#OPAM_PREFIX#'
> (4:File${#FILE}:$FILE)
> EOF
((?:EXCLUDE_QUERY_DIR)(?:B?:$TESTCASE_ROOT/_build/default/.main.eobjs/byte)(?:B?:$TESTCASE_ROOT/_build/default/.mylib.objs/byte)(?:B?:$TESTCASE_ROOT/_build/default/.mylib3.objs/byte)(?:S?:$TESTCASE_ROOT)(?:FLG(?:-open?:Dune__exe?:-w?:@[email protected]@30..39@[email protected]@[email protected]?:-strict-sequence?:-strict-formats?:-short-paths?:-keep-locs)))
((?:STDLIB?:OPAM_PREFIX/lib/ocaml)(?:EXCLUDE_QUERY_DIR)(?:B?:$TESTCASE_ROOT/_build/default/.main.eobjs/byte)(?:B?:$TESTCASE_ROOT/_build/default/.mylib.objs/byte)(?:B?:$TESTCASE_ROOT/_build/default/.mylib3.objs/byte)(?:S?:$TESTCASE_ROOT)(?:FLG(?:-open?:Dune__exe?:-w?:@[email protected]@30..39@[email protected]@[email protected]?:-strict-sequence?:-strict-formats?:-short-paths?:-keep-locs)))

$ FILE=$PWD/lib3.ml
$ dune ocaml-merlin <<EOF | sed -E "s/[[:digit:]]+:/\?:/g"
$ dune ocaml-merlin <<EOF | sed -E "s/[[:digit:]]+:/\?:/g" | sed 's#'$(opam config var prefix)'#OPAM_PREFIX#'
> (4:File${#FILE}:$FILE)
> EOF
((?:EXCLUDE_QUERY_DIR)(?:B?:$TESTCASE_ROOT/_build/default/.mylib.objs/byte)(?:B?:$TESTCASE_ROOT/_build/default/.mylib3.objs/byte)(?:S?:$TESTCASE_ROOT)(?:FLG(?:-open?:Mylib?:-w?:@[email protected]@30..39@[email protected]@[email protected]?:-strict-sequence?:-strict-formats?:-short-paths?:-keep-locs)))
((?:STDLIB?:OPAM_PREFIX/lib/ocaml)(?:EXCLUDE_QUERY_DIR)(?:B?:$TESTCASE_ROOT/_build/default/.mylib.objs/byte)(?:B?:$TESTCASE_ROOT/_build/default/.mylib3.objs/byte)(?:S?:$TESTCASE_ROOT)(?:FLG(?:-open?:Mylib?:-w?:@[email protected]@30..39@[email protected]@[email protected]?:-strict-sequence?:-strict-formats?:-short-paths?:-keep-locs)))
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ library also has more than one src dir.
> EOF

$ dune build lib2/.merlin-conf/lib-lib2
$ dune ocaml-merlin --dump-config=$(pwd)/lib2
$ dune ocaml-merlin --dump-config=$(pwd)/lib2 |
> sed 's#'$(opam config var prefix)'#OPAM_PREFIX#'
Lib2
((EXCLUDE_QUERY_DIR)
((STDLIB OPAM_PREFIX/lib/ocaml)
(EXCLUDE_QUERY_DIR)
(B
$TESTCASE_ROOT/_build/default/lib1/.lib1.objs/byte)
(B
Expand Down
Loading