@@ -177,22 +177,12 @@ let get_path ctx_name =
177177 | false -> None
178178 | true -> Some ctx)
179179 in
180- let * lock_dir_paths =
181- match ctx with
182- | None | Some (Default { lock_dir = None ; _ } ) ->
183- Memo. return (Some (default_source_path, default_path))
184- | Some (Default { lock_dir = Some lock_dir_selection ; _ } ) ->
185- let + source_lock_dir = select_lock_dir lock_dir_selection in
186- Some (source_lock_dir, lock_dir_of_source source_lock_dir)
187- | Some (Opam _ ) -> Memo. return None
188- in
189- match lock_dir_paths with
190- | None -> Memo. return None
191- | Some (source_path , lock_dir_path ) ->
192- let * in_source_tree = Source_tree. find_dir source_path in
193- (match in_source_tree with
194- | Some _ -> Memo. return (Some lock_dir_path)
195- | None -> Memo. return None )
180+ match ctx with
181+ | None | Some (Default { lock_dir = None ; _ } ) -> Memo. return (Some default_path)
182+ | Some (Default { lock_dir = Some lock_dir_selection ; _ } ) ->
183+ let + source_lock_dir = select_lock_dir lock_dir_selection in
184+ Some (lock_dir_of_source source_lock_dir)
185+ | Some (Opam _ ) -> Memo. return None
196186;;
197187
198188let get_workspace_lock_dir ctx =
@@ -250,15 +240,77 @@ let of_dev_tool_if_lock_dir_exists dev_tool =
250240 else Memo. return None
251241;;
252242
243+ let lock_dirs_of_workspace (workspace : Workspace.t ) =
244+ let module Set = Path.Source. Set in
245+ let + lock_dirs_from_ctx =
246+ Memo.List. map workspace.contexts ~f: (function
247+ | Opam _ | Default { lock_dir = None ; _ } -> Memo. return None
248+ | Default { lock_dir = Some selection ; _ } ->
249+ let + path = select_lock_dir selection in
250+ Some path)
251+ >> | List. filter_opt
252+ in
253+ match lock_dirs_from_ctx, workspace.lock_dirs with
254+ | [] , [] -> Set. singleton default_source_path
255+ | lock_dirs_from_ctx , lock_dirs_from_toplevel ->
256+ let lock_paths_from_toplevel =
257+ List. map lock_dirs_from_toplevel ~f: (fun (lock_dir : Workspace.Lock_dir.t ) ->
258+ lock_dir.path)
259+ in
260+ Set. union (Set. of_list lock_paths_from_toplevel) (Set. of_list lock_dirs_from_ctx)
261+ ;;
262+
263+ let enabled () =
264+ match ! Clflags. ignore_lock_dir with
265+ | true -> Memo. return false
266+ | false ->
267+ let * workspace = Workspace. workspace () in
268+ (match workspace.config.pkg_enabled with
269+ | Set (_ , `Enabled) -> Memo. return true
270+ | Set (_ , `Disabled) -> Memo. return false
271+ | Unset ->
272+ let * lock_dirs = lock_dirs_of_workspace workspace in
273+ Path.Source.Set. to_list lock_dirs
274+ |> Memo.List. exists ~f: (fun lock_dir ->
275+ Fs_memo. dir_exists (Path.Outside_build_dir. In_source_dir lock_dir)))
276+ ;;
277+
278+ let get_path_if_source_exists ctx_name =
279+ let * workspace = Workspace. workspace () in
280+ let ctx =
281+ List. find_map workspace.contexts ~f: (fun ctx ->
282+ match Context_name. equal (Workspace.Context. name ctx) ctx_name with
283+ | false -> None
284+ | true -> Some ctx)
285+ in
286+ let * lock_dir_paths =
287+ match ctx with
288+ | None | Some (Default { lock_dir = None ; _ } ) ->
289+ Memo. return (Some (default_source_path, default_path))
290+ | Some (Default { lock_dir = Some lock_dir_selection ; _ } ) ->
291+ let + source_lock_dir = select_lock_dir lock_dir_selection in
292+ Some (source_lock_dir, lock_dir_of_source source_lock_dir)
293+ | Some (Opam _ ) -> Memo. return None
294+ in
295+ match lock_dir_paths with
296+ | None -> Memo. return None
297+ | Some (source_path , lock_dir_path ) ->
298+ let * in_source_tree = Source_tree. find_dir source_path in
299+ (match in_source_tree with
300+ | Some _ -> Memo. return (Some lock_dir_path)
301+ | None -> Memo. return None )
302+ ;;
303+
253304let lock_dir_active ctx =
254305 let open Memo.O in
255306 if ! Clflags. ignore_lock_dir
256307 then Memo. return false
257308 else
258309 let * workspace = Workspace. workspace () in
259310 match workspace.config.pkg_enabled with
311+ | Set (_ , `Enabled) -> Memo. return true
260312 | Set (_ , `Disabled) -> Memo. return false
261- | Set ( _ , `Enabled ) | Unset -> get_path ctx >> | Option. is_some
313+ | Unset -> get_path_if_source_exists ctx >> | Option. is_some
262314;;
263315
264316let source_kind (source : Dune_pkg.Source.t ) =
0 commit comments