diff --git a/src/jbuild_load.ml b/src/jbuild_load.ml index 8af32ff3..2d3100a1 100644 --- a/src/jbuild_load.ml +++ b/src/jbuild_load.ml @@ -124,7 +124,7 @@ end [ [ "-I"; "+compiler-libs" ] ; includes ; List.map cmas ~f:(Path.reach ~from:dir) - ; [ Path.reach ~from:dir wrapper ] + ; [ Path.to_absolute_filename wrapper ] ] in (* CR-someday jdimino: if we want to allow plugins to use findlib: diff --git a/src/merlin.ml b/src/merlin.ml index 0978253d..0351cf70 100644 --- a/src/merlin.ml +++ b/src/merlin.ml @@ -12,15 +12,12 @@ type t = ; source_dirs: Path.Set.t } -(* This must be forced after we change the cwd to the workspace root *) -let root_absolute_name = lazy (Sys.getcwd ()) - let ppx_flags sctx ~dir ~src_dir:_ { preprocess; libname; _ } = match preprocess with | Pps { pps; flags } -> let exe = SC.PP.get_ppx_driver sctx pps ~dir ~dep_kind:Optional in let command = - List.map (Filename.concat (Lazy.force root_absolute_name) (Path.to_string exe) + List.map (Path.to_absolute_filename exe :: "--as-ppx" :: SC.PP.cookie_library_name libname @ flags) diff --git a/src/path.ml b/src/path.ml index a08217cf..9aefa25b 100644 --- a/src/path.ml +++ b/src/path.ml @@ -272,6 +272,14 @@ let absolute fn = else fn +let to_absolute_filename t = + if is_local t then begin + let root = !Clflags.workspace_root in + assert (not (Filename.is_relative root)); + Filename.concat root (to_string t) + end else + t + let reach t ~from = match is_local t, is_local from with | false, _ -> t diff --git a/src/path.mli b/src/path.mli index e59e0d51..1fc5f699 100644 --- a/src/path.mli +++ b/src/path.mli @@ -61,6 +61,10 @@ val relative : ?error_loc:Loc.t -> t -> string -> t relative to the initial directory jbuilder was launched in. *) val absolute : string -> t +(** Convert a path to an absolute filename. Must be called after the + workspace root has been set. *) +val to_absolute_filename : t -> string + val reach : t -> from:t -> string val reach_for_running : t -> from:t -> string