ocaml / dune

A composable build system for OCaml.
https://dune.build/
MIT License
1.62k stars 401 forks source link

Cannot promote empty files over a non-existing file #8073

Open Julow opened 1 year ago

Julow commented 1 year ago

Expected Behavior

I would expect empty files to be promotable.

Actual Behavior

When diffing an empty file on the right and a non existing file on the left, Dune log that files differs and promotion doesn't create the file.

Reproduction

Here's the diff in the non-existent.t test:

diff --git a/test/blackbox-tests/test-cases/promote/non-existent.t/dune b/test/blackbox-tests/test-cases/promote/non-existent.t/dune
index cf4a75c92..012f182b9 100644
--- a/test/blackbox-tests/test-cases/promote/non-existent.t/dune
+++ b/test/blackbox-tests/test-cases/promote/non-existent.t/dune
@@ -1,4 +1,4 @@
-(rule (with-stdout-to x.gen (echo "toto")))
+(rule (with-stdout-to x.gen (echo "")))

 (rule
  (alias blah-non-existent)
diff --git a/test/blackbox-tests/test-cases/promote/non-existent.t/run.t b/test/blackbox-tests/test-cases/promote/non-existent.t/run.t
index 5ca32bf3a..0adea85b2 100644
--- a/test/blackbox-tests/test-cases/promote/non-existent.t/run.t
+++ b/test/blackbox-tests/test-cases/promote/non-existent.t/run.t
@@ -7,12 +7,9 @@ Tests for promoting with non existent reference
   [1]

   $ dune build @blah-non-existent
-  File "x-non-existent", line 1, characters 0-0:
-  Error: Files _build/default/x-non-existent and _build/default/x.gen differ.
-  [1]

   $ dune promote
-  Promoting _build/default/x.gen to x-non-existent.

   $ cat x-non-existent
-  toto
+  cat: x-non-existent: No such file or directory
+  [1]

Specifications

Alizter commented 1 year ago

Can you create a PR with the cram test with the promoted output and write in the cram the behaviour you expect? It will make it easier for us to take a look.

Julow commented 1 year ago

I'll do that.

Though, this might not be a bug. The documentation mention that non-existing files are treated as empty files for the purpose of diffing. It's normal that diffing two empty files result in no diff, triggering no promotion.

Alizter commented 1 year ago

Right, but in that case we could probably still register the file for promotion even if it is empty.