Commit 23c8279
committed
Fix the build issues with tests against build_files/ and log_files/ contents, collab with Claude Opus
Prompt 1:
> Can you help me study Dune and improve the build setup for testing generated files?
You can join me in reading the Dune documentation, e.g. starting from the page
https://dune.readthedocs.io/en/stable/reference/actions/index.html . The problem is
that the way I wrote the test/operations/dune file only sporadically makes things
work. I added directory dependencies `(target (dir log_files))` and `(target (dir
build_files))` to trigger generating files in these directories, relative to the
directory executables are run. But the semantics of directory targets is like of any
other targets: they can be in an "existing" and "non-existing" state, a rule is only
triggered when the directory is missing, not when a file in the directory is missing.
The build system encounters a missing file and complains that the directory-building
rule did not produce it, but the rule did not run because the directory already
existed. Maybe `include_subdirs` is the way?
https://dune.readthedocs.io/en/stable/reference/dune/include_subdirs.html The page
talks more about OCaml modules, but it should work for any files.
Summary 1 by Claude:
The issue with your current Dune setup is that directory targets only trigger when
the directory doesn't exist. Once created, the rule won't re-run even if files inside
are missing, causing sporadic build failures.
I've created three improved solutions:
1. dune.improved - Stamp file approach
- Uses sentinel/stamp files (.done files) to track when generation is complete
- Subsequent rules depend on these stamps instead of directories
- Most straightforward and reliable
2. dune.alternative - Multiple strategies
- Shows promotion mode to capture generated files
- Manifest approach to list generated files
- Two-phase build with explicit file listing
3. dune.robust - Clean sentinel-based solution
- Creates .done files after successful execution
- All dependent rules wait for these sentinels
- Guarantees proper ordering and file existence
Recommended approach: Use dune.robust - it's the cleanest solution that:
- Avoids the directory target problem entirely
- Creates explicit dependencies through sentinel files
- Ensures files exist before processing them
- Works reliably with Dune's dependency tracking
The key insight from the Dune documentation is that targets must be statically known
and directory targets are experimental with limited semantics. Using sentinel files
provides explicit, trackable dependencies that Dune handles well.
Final summary by Claude:
Updated Files:
1. test/operations/dune - Fixed directory target issues
2. test/einsum/dune - Applied same fix for consistency
Key Solution: no-infer Action
- Portable: Works on Linux, macOS, and Windows
- Clean: Uses Dune's built-in copy action
- Robust: Explicitly tells Dune not to track dependencies for
side-effect files
Pattern Used:
(rule
(target output.actual)
(action
(no-infer
(progn
(run executable --args)
(copy generated/file.ext %{target})))))
This approach:
- Generates files as side effects
- Copies them using Dune's portable copy action
- Avoids the "No rule found" errors
- Eliminates sporadic failures from directory target semantics
The no-infer wrapper is the key - it allows us to work with files that
Dune doesn't know about (generated at runtime) while still using Dune's
portable actions.
Signed-off-by: Lukasz Stafiniak <lukstafi@gmail.com>1 parent 72005ac commit 23c8279
2 files changed
+44
-53
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
69 | 69 | | |
70 | 70 | | |
71 | 71 | | |
72 | | - | |
73 | | - | |
| 72 | + | |
74 | 73 | | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
84 | 80 | | |
85 | 81 | | |
86 | 82 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
| 20 | + | |
19 | 21 | | |
20 | | - | |
21 | | - | |
22 | | - | |
| 22 | + | |
23 | 23 | | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
31 | 34 | | |
32 | | - | |
| 35 | + | |
33 | 36 | | |
34 | 37 | | |
35 | 38 | | |
| |||
38 | 41 | | |
39 | 42 | | |
40 | 43 | | |
41 | | - | |
| 44 | + | |
42 | 45 | | |
43 | 46 | | |
44 | 47 | | |
45 | 48 | | |
46 | | - | |
47 | | - | |
| 49 | + | |
| 50 | + | |
48 | 51 | | |
49 | 52 | | |
50 | 53 | | |
51 | 54 | | |
52 | | - | |
53 | | - | |
| 55 | + | |
| 56 | + | |
54 | 57 | | |
55 | 58 | | |
56 | 59 | | |
| |||
73 | 76 | | |
74 | 77 | | |
75 | 78 | | |
| 79 | + | |
76 | 80 | | |
77 | | - | |
78 | | - | |
79 | | - | |
| 81 | + | |
80 | 82 | | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
90 | 90 | | |
91 | 91 | | |
92 | | - | |
93 | | - | |
| 92 | + | |
94 | 93 | | |
95 | | - | |
96 | | - | |
97 | | - | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
98 | 101 | | |
99 | 102 | | |
100 | 103 | | |
| |||
103 | 106 | | |
104 | 107 | | |
105 | 108 | | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | 109 | | |
115 | 110 | | |
116 | 111 | | |
| |||
156 | 151 | | |
157 | 152 | | |
158 | 153 | | |
159 | | - | |
| 154 | + | |
0 commit comments