diff --git a/src/stdune/path.ml b/src/stdune/path.ml index 8f58d7d0..96961419 100644 --- a/src/stdune/path.ml +++ b/src/stdune/path.ml @@ -468,12 +468,16 @@ let insert_after_build_dir_exn = ] in fun a b -> - if not (is_local a) || String.contains b '/' then error a b; - match String.lsplit2 a ~on:'/' with - | Some ("_build", rest) -> - Printf.sprintf "_build/%s/%s" b rest - | _ -> + if not (is_local a) then error a b + else if a = build_dir then + relative build_dir b + else + match String.lsplit2 a ~on:'/' with + | Some (build_dir', rest) when build_dir = build_dir' -> + Local.append (relative build_dir b) rest + | _ -> + error a b let rm_rf = let rec loop dir = diff --git a/test/unit-tests/path.mlt b/test/unit-tests/path.mlt index 258e4e04..bffb0366 100644 --- a/test/unit-tests/path.mlt +++ b/test/unit-tests/path.mlt @@ -121,9 +121,7 @@ Called from file "toplevel/toploop.ml", line 180, characters 17-56 Path.insert_after_build_dir_exn Path.build_dir "foobar" [%%expect{| -Exception: Stdune__Exn.Code_error . -Raised at file "src/stdune/exn.ml", line 30, characters 37-131 -Called from file "toplevel/toploop.ml", line 180, characters 17-56 +- : Stdune.Path.t = _build/foobar |}] Path.insert_after_build_dir_exn (Path.relative Path.build_dir "qux") "foobar"