Skip to content

Commit

Permalink
Fix for ocaml#2990
Browse files Browse the repository at this point in the history
The second argument of a 'diff?' action is removed from the set of
targets as the action consumes (i.e. deletes) the file.

Signed-off-by: Geoffrey Reedy <geoff@programmer-monk.net>
  • Loading branch information
greedy committed May 5, 2020
1 parent 4ed0d3a commit 9443c00
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 1 deletion.
36 changes: 35 additions & 1 deletion src/dune/action_unexpanded.ml
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,8 @@ end = struct
val ( +<+ ) : outcome -> target -> outcome

val ( +<! ) : outcome -> program -> outcome

val ( +<- ) : outcome -> path -> outcome
end

module Make
Expand Down Expand Up @@ -420,7 +422,7 @@ end = struct
| Digest_files l -> List.fold_left l ~init:acc ~f:( +< )
| Diff { optional; file1; file2; mode = _ } ->
if optional then
acc +< file1
acc +< file1 +<- file2
else
acc +< file1 +< file2
| Merge_files_into (sources, _extras, target) ->
Expand Down Expand Up @@ -466,6 +468,14 @@ end = struct
let ( +<+ ) acc fn =
{ acc with deps = Path.Set.add acc.deps (Path.build fn) }

let ( +<- ) acc fn =
match Path.as_in_build_dir fn with
| Some target ->
{ acc with
targets = Path.Build.Set.remove acc.targets target
}
| None -> acc

let ( +<! ) acc prog =
match prog with
| Ok p -> acc +< p
Expand Down Expand Up @@ -494,6 +504,15 @@ end = struct
{ acc with deps = Path.Set.add acc.deps (Path.build fn) }
| Unexpanded _ -> acc

let ( +<- ) acc (fn : _ String_with_vars.Partial.t) =
match fn with
| Expanded fn -> (
match Path.as_in_build_dir fn with
| Some target ->
{ acc with targets = Path.Build.Set.remove acc.targets target }
| None -> acc )
| Unexpanded _ -> acc

let ( +<! ) acc fn =
match (fn : Partial.program) with
| Expanded (This fn) -> { acc with deps = Path.Set.add acc.deps fn }
Expand Down Expand Up @@ -522,6 +541,15 @@ end = struct
{ acc with deps = Path.Set.add acc.deps (Path.build fn) }
| Unexpanded _ -> acc

let ( +<- ) acc (fn : _ String_with_vars.Partial.t) =
match fn with
| Expanded fn -> (
match Path.as_in_build_dir fn with
| Some target ->
{ acc with targets = Path.Build.Set.remove acc.targets target }
| None -> acc )
| Unexpanded _ -> acc

let ( +<! ) acc fn =
match (fn : Partial.program) with
| Expanded (This fn) -> { acc with deps = Path.Set.add acc.deps fn }
Expand Down Expand Up @@ -584,6 +612,12 @@ end = struct
let ( +<+ ) acc _ = acc

let ( +<! ) = ( +< )

let ( +<- ) acc fn =
if String_with_vars.is_var fn ~name:"null" then
acc
else
{ acc with targets = List.filter acc.targets ~f:(fun t -> t <> fn) }
end)

let unexpanded_targets t = (Unexp.infer t).targets
Expand Down
10 changes: 10 additions & 0 deletions test/blackbox-tests/dune.inc
Original file line number Diff line number Diff line change
Expand Up @@ -1034,6 +1034,14 @@
test-cases/github2848
(progn (run dune-cram run run.t) (diff? run.t run.t.corrected)))))

(rule
(alias github2990)
(deps (package dune) (source_tree test-cases/github2990))
(action
(chdir
test-cases/github2990
(progn (run dune-cram run run.t) (diff? run.t run.t.corrected)))))

(rule
(alias github3046)
(deps (package dune) (source_tree test-cases/github3046))
Expand Down Expand Up @@ -2584,6 +2592,7 @@
(alias github2629)
(alias github2681)
(alias github2848)
(alias github2990)
(alias github3046)
(alias github3180)
(alias github3412)
Expand Down Expand Up @@ -2871,6 +2880,7 @@
(alias github2629)
(alias github2681)
(alias github2848)
(alias github2990)
(alias github3046)
(alias github3180)
(alias github3412)
Expand Down
15 changes: 15 additions & 0 deletions test/blackbox-tests/test-cases/github2990/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
(executable
(name print)
(modules print))

(rule
(with-stdout-to print.ml
(echo "let () = print_endline \"MESSAGE\"")))

(rule
(alias runtest)
(action
(progn
(with-stdout-to output.expected (echo "MESSAGE\n"))
(with-stdout-to output.actual (run ./print.exe))
(diff? output.expected output.actual))))
1 change: 1 addition & 0 deletions test/blackbox-tests/test-cases/github2990/dune-project
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(lang dune 2.5)
3 changes: 3 additions & 0 deletions test/blackbox-tests/test-cases/github2990/run.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Test for problem in #2990

$ dune runtest

0 comments on commit 9443c00

Please sign in to comment.