Skip to content

Commit

Permalink
refactor: bootstrap info cosmetic improvements (#11088)
Browse files Browse the repository at this point in the history
Signed-off-by: Rudi Grinberg <me@rgrinberg.com>
  • Loading branch information
rgrinberg authored Nov 3, 2024
1 parent 41c6a7c commit 153fcd1
Showing 1 changed file with 28 additions and 33 deletions.
61 changes: 28 additions & 33 deletions src/dune_rules/bootstrap_info.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
;;

0 comments on commit 153fcd1

Please sign in to comment.