In my Dune-based project, I want to apply a filter to all JSON files, so that they will be “normalized” via
jq . -S before being saved as test oracles. This will prevent spurious differences (whitespace, key order, etc.) from creating unnecessary noise.
The problem is that the commands that produce such files can only write their outputs to other files, not to stdout, so I cannot directly filter them with
jq. They create a
.json file (whose contents I do not care about), and this file will be
jq-ified to produce a final JSON, which is the output I care about.
However, when I try to do so using a rule containing an action with multiple commands (with
progn), the command reading the first
.json file fails with
No rule found, as if it expected the file to be necessarily produced by a specific
Here’s a minimal example: after doing
dune init project proj and adding this rule to
(rule (targets "b.txt") (action (progn (run touch a.txt) ; produces a.txt, but I don't care about it (with-stdin-from "a.txt" (with-stdout-to "b.txt" (run cat))) ; consumes a.txt ) ) )
Error: No rule found for lib/a.txt when running
Since the first
run command creates the
a.txt file, and the commands are supposed to run in sequence, I expected the second command to be able to use
a.txt. But the
with-stdin-from part does not seem to like it.
Is there a way to do this without separating the commands in two rules?