Skip to content

Conversation

@Leonidas-from-XIV
Copy link
Collaborator

This is a WIP PR to implement rules that copy the lock dirs (project lock dirs and dev-tool lock dirs) into the build folder before the package rules. It's a a prerequisite for #11775 which changes the logic to directly generate the lock directories in the build directory.

]))))
let dev_tool_lock_dir = Dune_rules.Lock_dir.dev_tool_source_lock_dir dev_tool in
let* lock_dir_exists =
Dune_engine.Fs_memo.dir_exists (In_source_dir dev_tool_lock_dir)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should be using Source_tree (or at least Fs_memo) to inspect the source tree.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But this is using Fs_memo?

val parallel_map : 'a list -> f:('a -> 'b t) -> 'b list t
val readdir_with_kinds : Path.t -> (Filename.t * Unix.file_kind) list t
val with_lexbuf_from_file : Path.t -> f:(Lexing.lexbuf -> 'a) -> 'a t
val stats_kind : Path.t -> (File_kind.t, Unix_error.Detailed.t) result t
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How come this function went away?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was only used in check_path which was used to get information about a lock dir path. But given lock dirs are read from the build directory and created by copy rules (so either they exist because the rule exists or they don't which makes the build fail), there is nothing useful that check_path could communicate to the user anymore.

Fs_memo.dir_exists
(Path.as_outside_build_dir_exn
(Dune_pkg.Lock_dir.dev_tool_lock_dir_path dev_tool))
Source_tree.find_dir (Lock_dir.dev_tool_source_lock_dir dev_tool)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this change needed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the dev-tool lock dir stops being in the source tree but ends up being read from the build folder, then as_outside_build_dir_exn will always fail with an exception. Hence I changed it, but then I realized that for now we need to check the existance of the dev tool lock dir in the source tree.

In any case, Source_tree.find_dir seems like the more appropriate function anyway, as it takes ignore-rules into account, whereas Fs_memo.dir_exists will happily read directories that were declared as to be ignored by the user.

let readdir_with_kinds path =
Fs_memo.dir_contents (Path.as_outside_build_dir_exn path)
>>| function
Readdir.read_directory_with_kinds (Path.to_string path)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see how this can work if the lock directory is still in the source directory. Without some sort of dependency tracking mechanism, dune will not know to invalidate the rules in watch mode if the lock directory changes.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't read the source directory (hence why the PR this is spun off used Path.Build.t as path for a while). If the lock dir changes, the copy rule is retriggered, thus updating the files in the build folder.

@Leonidas-from-XIV Leonidas-from-XIV added the rule Internal dune rules label Sep 9, 2025
@Leonidas-from-XIV Leonidas-from-XIV force-pushed the lock-dir-copy-rule branch 2 times, most recently from 884e272 to abb1d61 Compare September 16, 2025 09:10
Leonidas-from-XIV added a commit to Leonidas-from-XIV/dune that referenced this pull request Sep 22, 2025
This is pulling out a change from ocaml#12394 to make it easier to control
whether package management should be force-enabled, force-disabled or
left at the default setting.

Signed-off-by: Marek Kubica <[email protected]>
Leonidas-from-XIV added a commit to Leonidas-from-XIV/dune that referenced this pull request Sep 22, 2025
This is factored out of ocaml#12394 and makes sure that the dev tool flag is
set when attempting to use dev-tool functionality.

Signed-off-by: Marek Kubica <[email protected]>
Leonidas-from-XIV added a commit to Leonidas-from-XIV/dune that referenced this pull request Sep 24, 2025
This is factored out of ocaml#12394 and makes sure that the dev tool flag is
set when attempting to use dev-tool functionality.

Signed-off-by: Marek Kubica <[email protected]>
Leonidas-from-XIV added a commit that referenced this pull request Sep 24, 2025
This is factored out of #12394 and makes sure that the dev tool flag is
set when attempting to use dev-tool functionality.

Signed-off-by: Marek Kubica <[email protected]>
Leonidas-from-XIV added a commit to Leonidas-from-XIV/dune that referenced this pull request Sep 24, 2025
This is pulling out a change from ocaml#12394 to make it easier to control
whether package management should be force-enabled, force-disabled or
left at the default setting.

Signed-off-by: Marek Kubica <[email protected]>
Leonidas-from-XIV added a commit that referenced this pull request Sep 24, 2025
This is pulling out a change from #12394 to make it easier to control
whether package management should be force-enabled, force-disabled or
left at the default setting.

Signed-off-by: Marek Kubica <[email protected]>
@Leonidas-from-XIV Leonidas-from-XIV force-pushed the lock-dir-copy-rule branch 4 times, most recently from 3c601d9 to 18c1f60 Compare September 25, 2025 08:54
@Leonidas-from-XIV Leonidas-from-XIV force-pushed the lock-dir-copy-rule branch 8 times, most recently from 554c924 to e41b636 Compare October 1, 2025 12:43
@Leonidas-from-XIV Leonidas-from-XIV marked this pull request as ready for review October 1, 2025 12:59
@gridbugs
Copy link
Collaborator

gridbugs commented Oct 2, 2025

Looks good to me. Happy for the disabled tests to be fixed in a later change. Nice work!

@Alizter Alizter force-pushed the lock-dir-copy-rule branch from e41b636 to 54268d6 Compare October 2, 2025 09:58
@Alizter Alizter merged commit 2258b66 into ocaml:main Oct 2, 2025
16 checks passed
@Leonidas-from-XIV Leonidas-from-XIV deleted the lock-dir-copy-rule branch October 2, 2025 10:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

package management rule Internal dune rules

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants