From 0f8dcc5848009fcaaa4b60d75983da919d8ed018 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Tue, 8 May 2018 17:23:41 +0700 Subject: [PATCH] Change Path.insert_after_build_dir_exn not to hard code _build Use the build_dir variable rather than the "_build" string and treat the case Path.build_dir argument differently. Previously this would error: Path.insert_after_build_dir_exn Path.build_dir "foo" Now, it will return _build/foo --- src/stdune/path.ml | 14 +++++++++----- test/unit-tests/path.mlt | 4 +--- 2 files changed, 10 insertions(+), 8 deletions(-) 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"