Skip to content

Commit

Permalink
Fix #657
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeremie Dimino authored and jeremiedimino committed Mar 27, 2018
1 parent daef49c commit ad00c15
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 11 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ next
directories that include .odoc files, rather than the include flags of the
libraries. (#652 fixes #651 @rgrinberg)

- Fix a regression introduced by beta19 where the generated merlin
files didn't include the right `-ppx` flags in some cases (#658
fixess #657 @diml)

1.0+beta19.1 (21/03/2018)
-------------------------

Expand Down
1 change: 1 addition & 0 deletions src/jbuild.mli
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ module Pp : sig
type t = private string
val of_string : string -> t
val to_string : t -> string
val compare : t -> t -> Ordering.t
end

module Preprocess : sig
Expand Down
43 changes: 33 additions & 10 deletions src/merlin.ml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,37 @@ open! No_io

module SC = Super_context

module Preprocess = struct
type t =
| Pps of Jbuild.Preprocess.pps
| Other

let make : Jbuild.Preprocess.t -> t = function
| Pps pps -> Pps pps
| _ -> Other

let merge a b =
match a, b with
| Other, Other -> Other
| Pps _, Other -> a
| Other, Pps _ -> b
| Pps { pps = pps1; flags = flags1 },
Pps { pps = pps2; flags = flags2 } ->
match
match List.compare flags1 flags2 ~compare:String.compare with
| Eq ->
List.compare pps1 pps2 ~compare:(fun (_, a) (_, b) ->
Jbuild.Pp.compare a b)
| ne -> ne
with
| Eq -> a
| _ -> Other
end

type t =
{ requires : (unit, Lib.t list) Build.t
; flags : (unit, string list) Build.t
; preprocess : Jbuild.Preprocess.t
; preprocess : Preprocess.t
; libname : string option
; source_dirs: Path.Set.t
; objs_dirs : Path.Set.t
Expand All @@ -22,9 +49,9 @@ let make
?(objs_dirs=Path.Set.empty)
() =
(* Merlin shouldn't cause the build to fail, so we just ignore errors *)
{ requires = Build.catch requires ~on_error:(fun _ -> [])
; flags = Build.catch flags ~on_error:(fun _ -> [])
; preprocess
{ requires = Build.catch requires ~on_error:(fun _ -> [])
; flags = Build.catch flags ~on_error:(fun _ -> [])
; preprocess = Preprocess.make preprocess
; libname
; source_dirs
; objs_dirs
Expand All @@ -46,7 +73,7 @@ let ppx_flags sctx ~dir:_ ~scope ~src_dir:_ { preprocess; libname; _ } =
|> String.concat ~sep:" "
in
[sprintf "FLG -ppx %s" (Filename.quote command)]
| _ -> []
| Other -> []

let dot_merlin sctx ~dir ~scope ({ requires; flags; _ } as t) =
match Path.drop_build_context dir with
Expand Down Expand Up @@ -125,11 +152,7 @@ let merge_two a b =
>>^ fun (x, y) ->
Lib.L.remove_dups (x @ y))
; flags = a.flags &&& b.flags >>^ (fun (a, b) -> a @ b)
; preprocess =
if a.preprocess = b.preprocess then
a.preprocess
else
No_preprocessing
; preprocess = Preprocess.merge a.preprocess b.preprocess
; libname =
(match a.libname with
| Some _ as x -> x
Expand Down
10 changes: 10 additions & 0 deletions src/stdune/list.ml
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,13 @@ let sort t ~compare =

let stable_sort t ~compare =
stable_sort t ~cmp:(fun a b -> Ordering.to_int (compare a b))

let rec compare a b ~compare:f : Ordering.t =
match a, b with
| [], [] -> Eq
| [], _ :: _ -> Lt
| _ :: _, [] -> Gt
| x :: a, y :: b ->
match (f x y : Ordering.t) with
| Eq -> compare a b ~compare:f
| ne -> ne
2 changes: 2 additions & 0 deletions src/stdune/list.mli
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,5 @@ val last : 'a t -> 'a option

val sort : 'a t -> compare:('a -> 'a -> Ordering.t) -> 'a t
val stable_sort : 'a t -> compare:('a -> 'a -> Ordering.t) -> 'a t

val compare : 'a t -> 'a t -> compare:('a -> 'a -> Ordering.t) -> Ordering.t
2 changes: 1 addition & 1 deletion test/blackbox-tests/test-cases/merlin-tests/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
B $LIB_PREFIX/lib/findlib
B $LIB_PREFIX/lib/ocaml
FLG -open Foo -w -40 -open Bar -w -40
FLG -ppx '$PPX/fooppx@/ppx.exe --as-ppx --cookie '\''library-name="foo"'\'''
S .
S $LIB_PREFIX/lib/bytes
S $LIB_PREFIX/lib/findlib
Expand All @@ -31,4 +32,3 @@
Make sure a ppx directive is generated
$ grep -q ppx lib/.merlin
[1]

0 comments on commit ad00c15

Please sign in to comment.