From 153fcd1bc5c9f850a1f6b50e213a48d548c377ac Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Sun, 3 Nov 2024 15:00:23 +0000 Subject: [PATCH] refactor: bootstrap info cosmetic improvements (#11088) Signed-off-by: Rudi Grinberg --- src/dune_rules/bootstrap_info.ml | 61 +++++++++++++++----------------- 1 file changed, 28 insertions(+), 33 deletions(-) diff --git a/src/dune_rules/bootstrap_info.ml b/src/dune_rules/bootstrap_info.ml index c82054fd94b..db8de83b396 100644 --- a/src/dune_rules/bootstrap_info.ml +++ b/src/dune_rules/bootstrap_info.ml @@ -5,12 +5,18 @@ let def name dyn = Pp.box ~indent:2 (Pp.textf "let %s = " name ++ Dyn.pp dyn) ;; +let flags flags = + let open Dyn in + list (pair (list string) (list string)) flags +;; + let rule sctx ~requires_link = let open Action_builder.O in let* () = Action_builder.return () in let* locals, externals = - let+ libs = Resolve.Memo.read (Memo.Lazy.force requires_link) in - List.partition_map libs ~f:(fun lib -> + Memo.Lazy.force requires_link + |> Resolve.Memo.read + >>| List.partition_map ~f:(fun lib -> match Lib.Local.of_lib lib with | Some x -> Left x | None -> Right lib) @@ -58,42 +64,31 @@ let rule sctx ~requires_link = ]) |> Action_builder.of_memo in + let externals = + List.filter_map externals ~f:(fun lib -> + let name = Lib.name lib in + Option.some_if (Lib_name.equal name (Lib_name.of_string "threads.posix")) name) + in Format.asprintf "%a@." Pp.to_fmt - (Pp.vbox - (Pp.concat - ~sep:Pp.cut - [ def - "external_libraries" - (List - (List.filter_map externals ~f:(fun x -> - let name = Lib.name x in - if Lib_name.equal name (Lib_name.of_string "threads.posix") - then None - else Some (Lib_name.to_dyn name)))) - ; Pp.nop - ; def "local_libraries" (List locals) - ; Pp.nop - ; def - "build_flags" - (let open Dyn in - list (pair (list string) (list string)) build_flags) - ; Pp.nop - ; def - "link_flags" - (let open Dyn in - list (pair (list string) (list string)) link_flags) - ])) + (Pp.concat + ~sep:Pp.cut + [ def "external_libraries" (Dyn.list Lib_name.to_dyn externals) + ; Pp.nop + ; def "local_libraries" (List locals) + ; Pp.nop + ; def "build_flags" (flags build_flags) + ; Pp.nop + ; def "link_flags" (flags link_flags) + ] + |> Pp.vbox) ;; let gen_rules sctx (exes : Executables.t) ~dir ~requires_link = Memo.Option.iter exes.bootstrap_info ~f:(fun fname -> - Super_context.add_rule - sctx - ~loc:exes.buildable.loc - ~dir - (Action_builder.write_file_dyn - (Path.Build.relative dir fname) - (rule sctx ~requires_link))) + Action_builder.write_file_dyn + (Path.Build.relative dir fname) + (rule sctx ~requires_link) + |> Super_context.add_rule sctx ~loc:exes.buildable.loc ~dir) ;;