From 7a10027d25008f76f6e528c41008906db7b54d29 Mon Sep 17 00:00:00 2001 From: Ali Caglayan Date: Wed, 25 Mar 2026 12:04:40 +0100 Subject: [PATCH] fix(path): use External.append_local in Build.to_string for consistent separators Replace Filename.concat with External.append_local when stringifying external build paths with a local suffix. This ensures forward slashes are used on all platforms, removing the need for conditional Windows/Unix test expectations. Signed-off-by: Ali Caglayan --- otherlibs/stdune/src/path.ml | 2 +- .../stdune/test/path_external_build_tests.ml | 21 ++----------------- 2 files changed, 3 insertions(+), 20 deletions(-) diff --git a/otherlibs/stdune/src/path.ml b/otherlibs/stdune/src/path.ml index deadb92577d..9c9ef5f7096 100644 --- a/otherlibs/stdune/src/path.ml +++ b/otherlibs/stdune/src/path.ml @@ -371,7 +371,7 @@ module Build = struct | External b -> if Local.is_root p then External.to_string b - else Filename.concat (External.to_string b) (Local.to_string p) + else External.to_string (External.append_local b p) ;; let to_string_maybe_quoted p = String.maybe_quoted (to_string p) diff --git a/otherlibs/stdune/test/path_external_build_tests.ml b/otherlibs/stdune/test/path_external_build_tests.ml index 9413510b412..7a10873f9ee 100644 --- a/otherlibs/stdune/test/path_external_build_tests.ml +++ b/otherlibs/stdune/test/path_external_build_tests.ml @@ -4,21 +4,7 @@ open Stdune path. The existing stdune_unit_tests set build dir to "_build" (In_source_dir), so the [External b] branch of [Build.to_string] and cross-tree [reach] are never exercised there. This library has its own init because [set_root] and - [Build.set_build_dir] can only be called once per process. - - CR-someday Alizter: After the fix to use [External.append_local] instead of - [Filename.concat], the conditional Windows expectations can be consolidated - with the Unix ones. *) - -let check_on_win_or_unix output ~wind ~unix = - let expected = String.trim (if Sys.win32 then wind else unix) in - let output = String.trim output in - if not (String.equal output expected) - then - Code_error.raise - "output mismatch" - [ "expected", String expected; "got", String output ] -;; + [Build.set_build_dir] can only be called once per process. *) let () = Printexc.record_backtrace false; @@ -33,10 +19,7 @@ let%expect_test "Build.to_string root" = let%expect_test "Build.to_string relative" = Path.Build.to_string (Path.Build.relative Path.Build.root "foo/bar") |> print_endline; - check_on_win_or_unix - [%expect.output] - ~wind:{| /external-build\foo/bar |} - ~unix:{| /external-build/foo/bar |} + [%expect {| /external-build/foo/bar |}] ;; let%expect_test "to_absolute_filename source path" =