Skip to content

Mark promoted files as read-only #12465

@MisterDA

Description

@MisterDA

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.

(* 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 of dune --version): 3.20.2
  • Version of ocaml (output of ocamlc --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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions