This commit is contained in:
swrup 2025-11-11 02:07:51 +01:00
parent aa2ff7b2f0
commit 2f3113f55d
11742 changed files with 1223940 additions and 0 deletions

View file

@ -0,0 +1,35 @@
let () = Printexc.record_backtrace true
let digest =
let raw = Sys.getcwd () |> Filename.dirname |> Filename.basename in
let idx =
let store_path = Sys.getenv "DUNE_PWD_STORE" in
match open_in store_path with
| exception Sys_error _ ->
let out = open_out_gen [ Open_append; Open_creat ] 0 store_path in
Printf.fprintf out "%s\n" raw;
close_out out;
1
| store ->
let rec loop i =
match input_line store with
| line -> if line = raw then i else loop (i + 1)
| exception End_of_file ->
close_in store;
let out = open_out_gen [ Open_append; Open_creat ] 0 store_path in
Printf.fprintf out "%s\n" raw;
close_out out;
i
in
let index = loop 1 in
close_in store;
index
in
Printf.sprintf "$%d" idx
let () =
print_endline "running...";
let out = open_out "target" in
output_string out "target";
close_out out;
Printf.printf "digest: %s\n" digest

View file

@ -0,0 +1,88 @@
----------------------------------------------------------------------------------
Test that rule digest doesn't depend on irrelevant details of the dune file
$ export DUNE_PWD_STORE="$(mktemp)"
$ echo "(lang dune 3.0)" > dune-project
$ cat >dune <<EOF
> (rule
> (target target)
> (mode promote)
> (deps (sandbox always) pwd.ml)
> (action (run ocaml pwd.ml)))
> EOF
$ dune build target
running...
digest: $1
Let's add a comment to the dune file. It shouldn't affect the rule digest.
$ cat >dune <<EOF
> ; hello
> (rule
> (target target)
> (mode promote)
> (deps (sandbox always) pwd.ml)
> (action (run ocaml pwd.ml)))
> EOF
... and it doesn't.
$ rm _build/default/target target
$ dune build @default
running...
digest: $1
Now the same but with an alias.
$ cat >dune <<EOF
> (rule
> (alias default)
> (deps (sandbox always) pwd.ml)
> (action (run ocaml pwd.ml)))
> EOF
$ dune build @default
running...
digest: $2
Let's add a comment to the dune file. Dune does not re-run the rule because it
has the same digest:
$ changelocation() {
> sed -i.bak '1s/^/;; spurious location change\n/' dune
> }
$ changelocation
Now we make sure that failed rules re-run when the location changes:
$ cat >dune <<EOF
> (rule
> (alias foo)
> (action (system "echo failing; exit 1")))
> EOF
$ dune build @foo
File "dune", lines 1-3, characters 0-61:
1 | (rule
2 | (alias foo)
3 | (action (system "echo failing; exit 1")))
failing
[1]
$ changelocation
This should re-run the action
$ dune build @foo
File "dune", lines 2-4, characters 0-61:
2 | (rule
3 | (alias foo)
4 | (action (system "echo failing; exit 1")))
failing
[1]
$ dune build @default