@@ -97,16 +97,14 @@ let make_metadata ~has_embedded_location promotion loc =
9797module External = struct
9898 let which prog = Bin. which ~path: (Env_path. path Env. initial) prog
9999
100- let diff ~skip_trailing_cr ~dir promotion loc file1 file2 =
100+ let diff ~skip_trailing_cr ~dir promotion loc ( label1 , file1 ) ( label2 , file2 ) =
101101 which " diff"
102102 |> Option. map ~f: (fun prog ->
103103 let relative = Path. reach ~from: dir in
104- let file1 = relative file1 in
105- let file2 = relative file2 in
106104 let args =
107- [ " -u" ; " --label" ; file1 ; " --label" ; file2 ]
105+ [ " -u" ; " --label" ; relative label1 ; " --label" ; relative label2 ]
108106 @ (if skip_trailing_cr then [ " --strip-trailing-cr" ] else [] )
109- @ [ file1; file2 ]
107+ @ [ relative file1; relative file2 ]
110108 in
111109 { dir
112110 ; prog
@@ -158,6 +156,8 @@ module External = struct
158156 ;;
159157end
160158
159+ let noent_to_dev_null f = if Fpath. exists (Path. to_string f) then f else Dev_null. path
160+
161161let prepare ~skip_trailing_cr promotion path1 path2 =
162162 let dir, loc =
163163 let dir, file1 =
@@ -170,15 +170,19 @@ let prepare ~skip_trailing_cr promotion path1 path2 =
170170 in
171171 dir, Loc. in_file file1
172172 in
173+ let label1 = Path. drop_optional_sandbox_root path1 in
174+ let label2 = Path. drop_optional_sandbox_root path2 in
175+ let path1 = noent_to_dev_null path1 in
176+ let path2 = noent_to_dev_null path2 in
173177 let fallback =
174178 With_fallback. fail
175179 (User_error. make
176180 ~loc
177181 ?promotion
178182 [ Pp. textf
179183 " Files %s and %s differ."
180- (Path. to_string_maybe_quoted (Path. drop_optional_sandbox_root path1 ))
181- (Path. to_string_maybe_quoted (Path. drop_optional_sandbox_root path2 ))
184+ (Path. to_string_maybe_quoted (Path. drop_optional_sandbox_root label1 ))
185+ (Path. to_string_maybe_quoted (Path. drop_optional_sandbox_root label2 ))
182186 ])
183187 in
184188 match ! Clflags. diff_command with
@@ -215,7 +219,9 @@ let prepare ~skip_trailing_cr promotion path1 path2 =
215219 | None -> fallback
216220 | Some diff -> With_fallback. run diff ~fallback
217221 in
218- let diff = External. diff ~skip_trailing_cr ~dir promotion loc path1 path2 in
222+ let diff =
223+ External. diff ~skip_trailing_cr ~dir promotion loc (label1, path1) (label2, path2)
224+ in
219225 if Execution_env. inside_dune
220226 then or_fallback ~fallback diff
221227 else (
0 commit comments