diff --git a/src/stdune/path.ml b/src/stdune/path.ml index e5066859..d19410c3 100644 --- a/src/stdune/path.ml +++ b/src/stdune/path.ml @@ -667,13 +667,14 @@ let append_local a b = | External a -> external_ (External.relative a (Local.to_string b)) let append a b = - match kind b with - | External _ -> - Exn.code_error "Path.append called with non-local second path" + match b with + | In_build_dir _ | External _ -> + Exn.code_error "Path.append called with directory that's \ + not in the source tree" [ "a", sexp_of_t a ; "b", sexp_of_t b ] - | Local b -> append_local a b + | In_source_tree b -> append_local a b let basename t = match kind t with diff --git a/test/unit-tests/path.mlt b/test/unit-tests/path.mlt index a956d7b2..0f47a2b8 100644 --- a/test/unit-tests/path.mlt +++ b/test/unit-tests/path.mlt @@ -243,12 +243,24 @@ Path.append Path.build_dir (Path.relative Path.root "foo") Path.append Path.build_dir (Path.relative Path.build_dir "foo") [%%expect{| -- : Path.t = (In_build_dir "_build/foo") +Exception: +Code_error + (List + [Quoted_string + "Path.append called with directory that's not in the source tree"; + List [Atom (A "a"); List [Atom (A "In_build_dir"); Atom (A ".")]]; + List [Atom (A "b"); List [Atom (A "In_build_dir"); Atom (A "foo")]]]). |}] Path.append Path.root (Path.relative Path.build_dir "foo") [%%expect{| -- : Path.t = (In_source_tree "_build/foo") +Exception: +Code_error + (List + [Quoted_string + "Path.append called with directory that's not in the source tree"; + List [Atom (A "a"); List [Atom (A "In_source_tree"); Atom (A ".")]]; + List [Atom (A "b"); List [Atom (A "In_build_dir"); Atom (A "foo")]]]). |}] Path.append Path.root (Path.relative Path.root "foo") @@ -263,7 +275,13 @@ Path.append (Path.of_string "/root") (Path.relative Path.root "foo") Path.append (Path.of_string "/root") (Path.relative Path.build_dir "foo") [%%expect{| -- : Path.t = (External "/root/_build/foo") +Exception: +Code_error + (List + [Quoted_string + "Path.append called with directory that's not in the source tree"; + List [Atom (A "a"); List [Atom (A "External"); Atom (A "/root")]]; + List [Atom (A "b"); List [Atom (A "In_build_dir"); Atom (A "foo")]]]). |}] Path.rm_rf (Path.of_string "/does/not/exist/foo/bar/baz")