Merge pull request #747 from rgrinberg/insert-after-build-dir-exn

Insert after build dir exn behavior tweak
This commit is contained in:
Rudi Grinberg 2018-05-08 19:19:59 +07:00 committed by GitHub
commit f603fd6598
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 5 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

@ -111,3 +111,20 @@ Path.is_local (Path.absolute "relative/path")
[%%expect{|
- : bool = false
|}]
Path.insert_after_build_dir_exn Path.root "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
|}]
Path.insert_after_build_dir_exn Path.build_dir "foobar"
[%%expect{|
- : Stdune.Path.t = _build/foobar
|}]
Path.insert_after_build_dir_exn (Path.relative Path.build_dir "qux") "foobar"
[%%expect{|
- : Stdune.Path.t = _build/foobar/qux
|}]