diff --git a/src/module.ml b/src/module.ml index 70d930e9c26..aa2c8bef48c 100644 --- a/src/module.ml +++ b/src/module.ml @@ -269,25 +269,25 @@ let obj_name t = t.obj_name let cm_source t kind = file t (Cm_kind.source kind) -let cm_file_unsafe t ?ext kind = - let ext = Option.value ext ~default:(Cm_kind.ext kind) in +let cm_file_unsafe t kind = + let ext = Cm_kind.ext kind in obj_file t ~kind ~ext -let cm_file t ?ext (kind : Cm_kind.t) = +let cm_file t (kind : Cm_kind.t) = match kind with | (Cmx | Cmo) when not (has_impl t) -> None - | _ -> Some (cm_file_unsafe t ?ext kind) + | _ -> Some (cm_file_unsafe t kind) -let cm_public_file_unsafe t ?ext kind = - let ext = Option.value ext ~default:(Cm_kind.ext kind) in +let cm_public_file_unsafe t kind = + let ext = Cm_kind.ext kind in let base = Obj_dir.cm_public_dir t.obj_dir kind in Path.relative base (t.obj_name ^ ext) -let cm_public_file t ?ext (kind : Cm_kind.t) = +let cm_public_file t (kind : Cm_kind.t) = match kind with | (Cmx | Cmo) when not (has_impl t) -> None | Cmi when is_private t -> None - | _ -> Some (cm_public_file_unsafe t ?ext kind) + | _ -> Some (cm_public_file_unsafe t kind) let cmt_file t (kind : Ml_kind.t) = match kind with diff --git a/src/module.mli b/src/module.mli index 056ccd25f12..962d02c721e 100644 --- a/src/module.mli +++ b/src/module.mli @@ -113,8 +113,8 @@ val pp_flags : t -> (unit, string list) Build.t option val file : t -> Ml_kind.t -> Path.t option val cm_source : t -> Cm_kind.t -> Path.t option -val cm_file : t -> ?ext:string -> Cm_kind.t -> Path.t option -val cm_public_file : t -> ?ext:string -> Cm_kind.t -> Path.t option +val cm_file : t -> Cm_kind.t -> Path.t option +val cm_public_file : t -> Cm_kind.t -> Path.t option val cmt_file : t -> Ml_kind.t -> Path.t option val obj_file : t -> kind:Cm_kind.t -> ext:string -> Path.t @@ -123,10 +123,9 @@ val obj_name : t -> string (** Same as [cm_file] but doesn't raise if [cm_kind] is [Cmo] or [Cmx] and the module has no implementation. - If present [ext] replace the extension of the kind *) -val cm_file_unsafe : t -> ?ext:string -> Cm_kind.t -> Path.t -val cm_public_file_unsafe : t -> ?ext:string -> Cm_kind.t -> Path.t +val cm_file_unsafe : t -> Cm_kind.t -> Path.t +val cm_public_file_unsafe : t -> Cm_kind.t -> Path.t val odoc_file : t -> doc_dir:Path.Build.t -> Path.Build.t diff --git a/src/virtual_rules.ml b/src/virtual_rules.ml index d25bb77db35..f576f1f80f7 100644 --- a/src/virtual_rules.ml +++ b/src/virtual_rules.ml @@ -45,9 +45,9 @@ let setup_copy_rules_for_impl ~sctx ~dir vimpl = let modes = Dune_file.Mode_conf.Set.eval impl.modes ~has_native:(Option.is_some ctx.ocamlopt) in - let copy_obj_file ~src ~dst ?ext kind = - let src = Module.cm_file_unsafe src ?ext kind in - let dst = Module.cm_file_unsafe dst ?ext kind in + let copy_obj_file ~src ~dst kind = + let src = Module.cm_file_unsafe src kind in + let dst = Module.cm_file_unsafe dst kind in copy_to_obj_dir ~src ~dst:(Path.as_in_build_dir_exn dst) in let copy_objs src = let dst = Module.set_obj_dir ~obj_dir:(Obj_dir.of_local impl_obj_dir) src in @@ -62,9 +62,13 @@ let setup_copy_rules_for_impl ~sctx ~dir vimpl = if Module.has_impl src then begin if modes.byte then copy_obj_file ~src ~dst Cmo; - if modes.native then - List.iter [Cm_kind.ext Cmx; ctx.ext_obj] - ~f:(fun ext -> copy_obj_file ~src ~dst ~ext Cmx) + if modes.native then begin + copy_obj_file ~src ~dst Cmx; + (let object_file = Module.obj_file ~kind:Cmx ~ext:ctx.ext_obj in + copy_to_obj_dir + ~src:(object_file src) + ~dst:(Path.as_in_build_dir_exn (object_file dst))) + end end in let copy_all_deps =