-
Notifications
You must be signed in to change notification settings - Fork 449
Description
Expected Behavior
Files promoted to the source directory should be read-only because they are generated. If they're edited, they're going to be eventually overwritten by a following build. Setting them read-only would prevent user confusion.
In this case, read-only would only be useful for humans, and Dune should make the file writable again if it needs to overwrite it.
Actual Behavior
Say that files m.mli
and m.mli
are generated by gen.exe
, and used as part of a library. I want LSP and Merlin to be able to jump to the symbols defined in these files if they're used from the library, so I need these files to be present in the source tree (it's a known limitation of these tools, for good reason. They never jump into the build directory). I don't want to use the diff
action to compare or promote the generated files, so I'm using (mode (promote (until-clean)))
in the rule that generates m.ml
and m.mli
. The generated files are excluded from version control. I'd like the promoted files to be marked read-only, so that devs who open the file when jumping to it don't start editing it. Unfortunately, due to Dune setting files in its cache and in the build directory as read-only (for good reasons), it unconditionally sets the write permission on all files it promotes to the source directory. See #2850 and #2853.
dune/src/dune_engine/target_promotion.ml
Lines 84 to 89 in 6cd8230
(* The file in the build directory might be read-only if it comes from the | |
shared cache. However, we want the file in the source tree to be | |
writable by the user, so we explicitly set the user writable bit. *) | |
let chmod = Path.Permissions.add Path.Permissions.write in | |
let+ () = promote_source ~chmod ~delete_dst_if_it_is_a_directory:true ~src ~dst in | |
true |
Specifications
- Version of
dune
(output ofdune --version
): 3.20.2 - Version of
ocaml
(output ofocamlc --version
): 4.14.2 - Operating system (distribution and version): Ubuntu 25.04
If setting the promoted files as read-only isn't possible or implies other problems, could there be a work-around for my use case?