Switch to ocaml-migrate-parsetree.driver-main
This commit is contained in:
parent
9423e5ae74
commit
35ac2e84ed
|
@ -168,6 +168,8 @@ module Gen(P : Params) = struct
|
|||
create findlib P.internal_libraries
|
||||
~dirs_with_dot_opam_files:P.dirs_with_dot_opam_files
|
||||
|
||||
let find ~from name = find t ~from name
|
||||
|
||||
module Libs_vfile =
|
||||
Vfile_kind.Make_full
|
||||
(struct type t = Lib.t list end)
|
||||
|
@ -178,7 +180,7 @@ module Gen(P : Params) = struct
|
|||
(struct
|
||||
open Sexp.Of_sexp
|
||||
let t dir sexp =
|
||||
List.map (list string sexp) ~f:(Lib_db.find t ~from:dir)
|
||||
List.map (list string sexp) ~f:(Lib_db.find_exn t ~from:dir)
|
||||
end)
|
||||
|
||||
let vrequires ~dir ~item =
|
||||
|
@ -567,43 +569,55 @@ module Gen(P : Params) = struct
|
|||
|
||||
let ppx_drivers = Hashtbl.create 32
|
||||
|
||||
let build_ppx_driver ~dir ~dep_kind ~target ~main pp_names ~driver =
|
||||
let migrate_driver_main = "ocaml-migrate-parsetree.driver-main"
|
||||
|
||||
let build_ppx_driver ~dir ~dep_kind ~target pp_names ~driver =
|
||||
let mode = Mode.best in
|
||||
let compiler = Option.value_exn (Mode.compiler mode) in
|
||||
let pp_names = pp_names @ [migrate_driver_main] in
|
||||
let libs =
|
||||
Lib_db.closure ~dir ~dep_kind (List.map pp_names ~f:Lib_dep.direct)
|
||||
in
|
||||
let libs =
|
||||
(* Put the driver back at the end *)
|
||||
(* Put the driver back at the end, just before migrate_driver_main *)
|
||||
match driver with
|
||||
| None -> libs
|
||||
| Some driver ->
|
||||
libs >>^ fun libs ->
|
||||
let libs, driver =
|
||||
let is_driver name = name = driver || name = migrate_driver_main in
|
||||
let libs, drivers =
|
||||
List.partition_map libs ~f:(fun lib ->
|
||||
if (match lib with
|
||||
| External pkg -> pkg.name = driver
|
||||
| External pkg -> is_driver pkg.name
|
||||
| Internal (_, lib) ->
|
||||
lib.name = driver ||
|
||||
is_driver lib.name ||
|
||||
match lib.public with
|
||||
| None -> false
|
||||
| Some { name; _ } -> name = driver)
|
||||
| Some { name; _ } -> is_driver name)
|
||||
then
|
||||
Inr lib
|
||||
else
|
||||
Inl lib)
|
||||
in
|
||||
libs @ driver
|
||||
libs @ drivers
|
||||
in
|
||||
(* Provide a better error for migrate_driver_main given that this is an implicit
|
||||
dependency *)
|
||||
let libs =
|
||||
match Lib_db.find ~from:dir migrate_driver_main with
|
||||
| None ->
|
||||
Build.fail { fail = fun () ->
|
||||
die "@{<error>Error@}: I couldn't find '%s'.\n\
|
||||
I need this library in order to use ppx rewriters.\n\
|
||||
See the manual for details.\n\
|
||||
Hint: opam install ocaml-migrate-parsetree"
|
||||
migrate_driver_main
|
||||
}
|
||||
>>>
|
||||
libs
|
||||
| Some _ ->
|
||||
libs
|
||||
in
|
||||
add_rule
|
||||
(Build.action ~targets:[main] (Write_file (main, {|(* File generated by jbuilder *)
|
||||
let () =
|
||||
Printf.eprintf "%s: driver missing!
|
||||
If you see this message, it means that you are missing a ppx driver at the
|
||||
end of your list of preprocessors. Consult the manual for more details."
|
||||
Sys.argv.(0);
|
||||
exit 1
|
||||
|})));
|
||||
add_rule
|
||||
(libs
|
||||
>>>
|
||||
|
@ -612,7 +626,7 @@ end of your list of preprocessors. Consult the manual for more details."
|
|||
Build.run (Dep compiler)
|
||||
[ A "-o" ; Target target
|
||||
; Dyn (Lib.link_flags ~mode)
|
||||
; Dep main ]);
|
||||
]);
|
||||
libs
|
||||
|
||||
let ppx_dir = Path.of_string (sprintf "_build/.ppx/%s" ctx.name)
|
||||
|
@ -634,9 +648,8 @@ end of your list of preprocessors. Consult the manual for more details."
|
|||
| None ->
|
||||
let ppx_dir = Path.relative ppx_dir key in
|
||||
let exe = Path.relative ppx_dir "ppx.exe" in
|
||||
let main = Path.relative ppx_dir "jbuilder_ppx_main.ml" in
|
||||
let libs =
|
||||
build_ppx_driver names ~dir ~dep_kind ~target:exe ~main ~driver
|
||||
build_ppx_driver names ~dir ~dep_kind ~target:exe ~driver
|
||||
in
|
||||
Hashtbl.add ppx_drivers ~key ~data:(exe, libs);
|
||||
(exe, libs)
|
||||
|
|
|
@ -24,7 +24,7 @@ let find_by_internal_name t ~from name =
|
|||
let scope = internal_name_scope t ~dir:from in
|
||||
String_map.find name !scope
|
||||
|
||||
let find t ~from name =
|
||||
let find_exn t ~from name =
|
||||
match find_by_internal_name t ~from name with
|
||||
| Some x -> Lib.Internal x
|
||||
| None ->
|
||||
|
@ -32,6 +32,11 @@ let find t ~from name =
|
|||
~f:(fun name ->
|
||||
External (Findlib.find_exn t.findlib name))
|
||||
|
||||
let find t ~from name =
|
||||
match find_exn t ~from name with
|
||||
| exception _ -> None
|
||||
| x -> Some x
|
||||
|
||||
let find_internal t ~from name =
|
||||
match find_by_internal_name t ~from name with
|
||||
| Some _ as some -> some
|
||||
|
@ -111,18 +116,18 @@ let interpret_lib_deps t ~dir lib_deps =
|
|||
let libs, failures =
|
||||
List.partition_map lib_deps ~f:(function
|
||||
| Lib_dep.Direct name -> begin
|
||||
match find t ~from:dir name with
|
||||
match find_exn t ~from:dir name with
|
||||
| x -> Inl [x]
|
||||
| exception e ->
|
||||
(* Call [find] again to get a proper backtrace *)
|
||||
Inr { fail = fun () -> ignore (find t ~from:dir name : Lib.t); raise e }
|
||||
Inr { fail = fun () -> ignore (find_exn t ~from:dir name : Lib.t); raise e }
|
||||
end
|
||||
| Select { result_fn; choices } ->
|
||||
match
|
||||
List.find_map choices ~f:(fun { lits; _ } ->
|
||||
match
|
||||
List.filter_map lits ~f:(function
|
||||
| Pos s -> Some (find t ~from:dir s)
|
||||
| Pos s -> Some (find_exn t ~from:dir s)
|
||||
| Neg s ->
|
||||
if lib_is_installable t ~from:dir s then
|
||||
raise Exit
|
||||
|
|
|
@ -10,7 +10,8 @@ val create
|
|||
-> (Path.t * Jbuild_types.Library.t) list
|
||||
-> t
|
||||
|
||||
val find : t -> from:Path.t -> string -> Lib.t
|
||||
val find : t -> from:Path.t -> string -> Lib.t option
|
||||
val find_exn : t -> from:Path.t -> string -> Lib.t
|
||||
|
||||
val internal_libs_without_non_installable_optional_ones : t -> Lib.Internal.t list
|
||||
|
||||
|
|
Loading…
Reference in New Issue