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
This commit is contained in:
Rudi Grinberg 2018-05-08 17:23:41 +07:00
parent 6ee133b4dd
commit 0f8dcc5848
2 changed files with 10 additions and 8 deletions

View File

@ -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 =

View File

@ -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 <abstr>.
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"