Skip to content

Commit

Permalink
cram: demonstrate bug with %{bin:public_binary} and absolute DUNE_B…
Browse files Browse the repository at this point in the history
…UILD_DIR

Signed-off-by: Antonio Nuno Monteiro <[email protected]>
  • Loading branch information
anmonteiro committed Oct 25, 2022
1 parent 83aea14 commit 848cdfe
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 2 deletions.
4 changes: 4 additions & 0 deletions otherlibs/stdune/path.ml
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,10 @@ module Build = struct
let lstat t = Unix.lstat (to_string t)

let unlink_no_err t = Fpath.unlink_no_err (to_string t)

let to_absolute_filename (t : t) =
Outside_build_dir.to_absolute_filename
(Outside_build_dir.append_local (Fdecl.get build_dir) t)
end

module T : sig
Expand Down
2 changes: 2 additions & 0 deletions otherlibs/stdune/path.mli
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,8 @@ module Build : sig
val lstat : t -> Unix.stats

val unlink_no_err : t -> unit

val to_absolute_filename : t -> string
end

type t = private
Expand Down
3 changes: 1 addition & 2 deletions src/dune_rules/context.ml
Original file line number Diff line number Diff line change
Expand Up @@ -514,9 +514,8 @@ let create ~(kind : Kind.t) ~path ~env ~env_nodes ~name ~merlin ~targets
else env
in
let env =
let cwd = Sys.getcwd () in
let extend_var var ?(path_sep = Bin.path_sep) v =
let v = Filename.concat cwd (Path.Build.to_string v) in
let v = Path.Build.to_absolute_filename v in
match Env.get env var with
| None -> (var, v)
| Some prev -> (var, sprintf "%s%c%s" v path_sep prev)
Expand Down
32 changes: 32 additions & 0 deletions test/blackbox-tests/test-cases/cram/public-name.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
Cram and public binaries with an absolute build directory

$ mkdir fresh && cd fresh

$ cat >dune-project <<EOF
> (lang dune 2.8)
> (cram enable)
> (name public-name-exe-test)
> EOF
$ touch public-name-exe-test.opam

$ mkdir helper
$ cat >helper/dune <<EOF
> (executable (public_name helper))
> EOF
$ cat >helper/helper.ml <<EOF
> print_endline "Helper launched successfully";;
> EOF

$ mkdir tests
$ cat >tests/run.t <<EOF
> $ helper
> Helper launched successfully
> EOF
$ echo "(cram (deps %{bin:helper}))" > tests/dune

Running `dune runtest` with a relative build directory works

$ DUNE_BUILD_DIR=./_other_build dune runtest

$ export NEW_BUILD_DIR="$PWD/_other_build"
$ DUNE_BUILD_DIR="$NEW_BUILD_DIR" dune runtest --auto-promote

0 comments on commit 848cdfe

Please sign in to comment.