Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions bin/build.ml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ let run_build_system ~common ~request =
Fiber.return ())
;;

let poll_handling_rpc_build_requests ~(common : Common.t) ~config =
let poll_handling_rpc_build_requests ~(common : Common.t) =
let open Fiber.O in
let rpc =
match Common.rpc common with
Expand All @@ -96,8 +96,7 @@ let poll_handling_rpc_build_requests ~(common : Common.t) ~config =
let request setup =
let root = Common.root common in
match kind with
| Build targets ->
Target.interpret_targets (Common.root common) config setup targets
| Build targets -> Target.interpret_targets (Common.root common) setup targets
| Runtest test_paths ->
Runtest_common.make_request
~contexts:setup.contexts
Expand All @@ -114,15 +113,15 @@ let run_build_command_poll_eager ~(common : Common.t) ~config ~request : unit =
named on the command line in reaction to file system changes. The other
is responsible for building targets named in RPC build requests. *)
let+ () = Dune_engine.Scheduler.Run.poll (run_build_system ~common ~request)
and+ () = poll_handling_rpc_build_requests ~common ~config in
and+ () = poll_handling_rpc_build_requests ~common in
())
;;

let run_build_command_poll_passive ~common ~config ~request:_ : unit =
(* CR-someday aalekseyev: It would've been better to complain if [request] is
non-empty, but we can't check that here because [request] is a function.*)
Scheduler.go_with_rpc_server_and_console_status_reporting ~common ~config (fun () ->
poll_handling_rpc_build_requests ~common ~config)
poll_handling_rpc_build_requests ~common)
;;

let run_build_command_once ~(common : Common.t) ~config ~request =
Expand Down Expand Up @@ -235,9 +234,7 @@ let build =
targets
>>| Rpc.Rpc_common.wrap_build_outcome_exn ~print_on_success:true)
| Ok () ->
let request setup =
Target.interpret_targets (Common.root common) config setup targets
in
let request setup = Target.interpret_targets (Common.root common) setup targets in
run_build_command ~common ~config ~request
in
Cmd.v (Cmd.info "build" ~doc ~man ~envs:Common.envs) term
Expand Down
2 changes: 1 addition & 1 deletion bin/common.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1272,7 +1272,7 @@ let build (root : Workspace_root.t) (builder : Builder.t) =
let cats =
match Sys.getenv_opt "DUNE_TRACE" with
| None ->
Dune_trace.Category.[ Sandbox; Persistent; Process; Rules; Pkg; Promote ]
Dune_trace.Category.[ Sandbox; Persistent; Process; Rules; Pkg; Promote; Build ]
| Some s ->
String.split ~on:',' s
|> List.map ~f:(fun x ->
Expand Down
3 changes: 1 addition & 2 deletions bin/print_rules.ml
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,7 @@ let term =
Target.all_direct_targets None
>>| Path.Build.Map.foldi ~init:[] ~f:(fun p _ acc -> Path.build p :: acc)
>>| Action_builder.paths
| _ ->
Memo.return (Target.interpret_targets (Common.root common) config setup targets)
| _ -> Memo.return (Target.interpret_targets (Common.root common) setup targets)
in
let+ rules = Dune_engine.Reflection.eval ~request ~recursive in
let print oc =
Expand Down
47 changes: 24 additions & 23 deletions bin/target.ml
Original file line number Diff line number Diff line change
Expand Up @@ -220,34 +220,35 @@ let resolve_target root ~setup target =
| dep -> Action_builder.return (Error (dep, []))
;;

let resolve_targets
root
(config : Dune_config.t)
(setup : Dune_rules.Main.build_system)
user_targets
=
let resolve_targets root (setup : Dune_rules.Main.build_system) user_targets =
match user_targets with
| [] -> Action_builder.return []
| _ ->
let+ targets = Action_builder.List.map user_targets ~f:(resolve_target root ~setup) in
(match config.display with
| Simple { verbosity = Verbose; _ } ->
Log.info
[ Pp.text "Actual targets:"
; Pp.enumerate
(List.concat_map targets ~f:(function
| Ok targets -> targets
| Error _ -> []))
~f:(function
| File p -> Pp.verbatim (Path.to_string_maybe_quoted p)
| Alias a -> Alias.pp a)
]
| _ -> ());
Dune_trace.emit Build (fun () ->
let files, aliases =
List.concat_map targets ~f:(function
| Ok targets -> targets
| Error _ -> [])
|> List.partition_map ~f:(function
| Request.File p -> Left p
| Alias { name; recursive; dir; contexts } ->
Right
({ name = Dune_engine.Alias.Name.to_string name
; recursive
; dir
; contexts =
List.map contexts ~f:(fun ctx ->
Dune_rules.Context.name ctx |> Context_name.to_string)
}
: Dune_trace.Event.alias))
in
Dune_trace.Event.resolve_targets files aliases);
targets
;;

let resolve_targets_exn root config setup user_targets =
resolve_targets root config setup user_targets
let resolve_targets_exn root setup user_targets =
resolve_targets root setup user_targets
>>| List.concat_map ~f:(function
| Error (dep, hints) ->
User_error.raise
Expand All @@ -256,9 +257,9 @@ let resolve_targets_exn root config setup user_targets =
| Ok targets -> targets)
;;

let interpret_targets root config setup user_targets =
let interpret_targets root setup user_targets =
let* () = Action_builder.return () in
resolve_targets_exn root config setup user_targets >>= request
resolve_targets_exn root setup user_targets >>= request
;;

type target_type = Target_type.t =
Expand Down
1 change: 0 additions & 1 deletion bin/target.mli
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ val all_direct_targets : Path.Source.t option -> target_type Path.Build.Map.t Me

val interpret_targets
: Workspace_root.t
-> Dune_config.t
-> Dune_rules.Main.build_system
-> Arg.Dep.t list
-> unit Dune_engine.Action_builder.t
Expand Down
2 changes: 2 additions & 0 deletions doc/changes/changed/12955.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Add a target resolution event to replace the equivalent log message (#12955,
@rgrinberg)
7 changes: 6 additions & 1 deletion src/dune_trace/category.ml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ type t =
| Pkg
| Scheduler
| Promote
| Build

let all = [ Rpc; Gc; Fd; Sandbox; Persistent; Process; Rules; Pkg; Scheduler; Promote ]
let all =
[ Rpc; Gc; Fd; Sandbox; Persistent; Process; Rules; Pkg; Scheduler; Promote; Build ]
;;

let to_string = function
| Rpc -> "rpc"
Expand All @@ -25,6 +28,7 @@ let to_string = function
| Pkg -> "pkg"
| Scheduler -> "scheduler"
| Promote -> "promote"
| Build -> "build"
;;

let of_string =
Expand All @@ -51,5 +55,6 @@ module Set = Bit_set.Make (struct
| Pkg -> 7
| Scheduler -> 8
| Promote -> 9
| Build -> 10
;;
end)
1 change: 1 addition & 0 deletions src/dune_trace/category.mli
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ type t =
| Pkg
| Scheduler
| Promote
| Build

val to_string : t -> string
val of_string : string -> t option
Expand Down
10 changes: 10 additions & 0 deletions src/dune_trace/dune_trace.mli
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ module Category : sig
| Pkg
| Scheduler
| Promote
| Build

val of_string : string -> t option
end
Expand Down Expand Up @@ -73,6 +74,15 @@ module Event : sig
val fd_count : unit -> t option
val promote : Path.Build.t -> Path.Source.t -> t

type alias =
{ dir : Path.Source.t
; name : string
; recursive : bool
; contexts : string list
}

val resolve_targets : Path.t list -> alias list -> t

module Rpc : sig
type stage =
| Start
Expand Down
34 changes: 34 additions & 0 deletions src/dune_trace/event.ml
Original file line number Diff line number Diff line change
Expand Up @@ -354,3 +354,37 @@ let promote src dst =
in
Event.instant ~args common
;;

type alias =
{ dir : Path.Source.t
; name : string
; recursive : bool
; contexts : string list
}

let json_of_alias { dir; name; recursive; contexts } =
`Assoc
[ "dir", `String (Path.Source.to_string dir)
; "name", `String name
; "recursive", `Bool recursive
; "contexts", `List (List.map contexts ~f:Json.string)
]
;;

let resolve_targets targets aliases =
let module Event = Chrome_trace.Event in
let ts = Event.Timestamp.of_float_seconds (Time.now () |> Time.to_secs) in
let args =
[ "targets", List.map targets ~f:(fun p -> `String (Path.to_string p))
; "aliases", List.map aliases ~f:json_of_alias
]
|> List.filter_map ~f:(fun (k, v) ->
match v with
| [] -> None
| _ :: _ -> Some (k, `List v))
in
let common =
Event.common_fields ~cat:[ Category.to_string Build ] ~name:"targets" ~ts ()
in
Event.instant ~args common
;;
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,21 @@ prefixed and unprefixed modules are built.
$ dune clean
$ dune build @t1

$ buildAndShow() {
> dune build --trace-file trace.json $@
> jq '.[] | select(.name == "targets") | .args' trace.json
> }

Command line version.

$ dune build --verbose %{cmo:a} %{cmo:b} %{cmo:c} 2>&1 | grep -A100 'Actual targets'
Actual targets:
- _build/default/.a1.objs/byte/a1__A.cmo
- _build/default/.b.eobjs/byte/dune__exe__B.cmo
- _build/default/.c1.objs/byte/c.cmo
$ buildAndShow %{cmo:a} %{cmo:b} %{cmo:c}
{
"targets": [
"_build/default/.a1.objs/byte/a1__A.cmo",
"_build/default/.b.eobjs/byte/dune__exe__B.cmo",
"_build/default/.c1.objs/byte/c.cmo"
]
}

The next test tries to build a .cmi file (of a module in a wrapped library).

Expand All @@ -30,9 +38,12 @@ The next test tries to build a .cmi file (of a module in a wrapped library).

Command line version.

$ dune build --verbose %{cmi:a} 2>&1 | grep -A100 'Actual targets'
Actual targets:
- _build/default/.a1.objs/byte/a1__A.cmi
$ buildAndShow %{cmi:a}
{
"targets": [
"_build/default/.a1.objs/byte/a1__A.cmi"
]
}

Command line version; note that the error message is slightly different.

Expand All @@ -48,9 +59,12 @@ The next test builds a native .cmxa.

Command line version.

$ dune build --verbose %{cmxa:a1} 2>&1 | grep -A100 'Actual targets'
Actual targets:
- _build/default/a1.cmxa
$ buildAndShow %{cmxa:a1}
{
"targets": [
"_build/default/a1.cmxa"
]
}

Command line version.

Expand All @@ -67,9 +81,12 @@ defined. The library is public in this case, but we use the local name.

Command line version.

$ dune build --verbose %{cma:sub2/bar2} 2>&1 | grep -A100 'Actual targets'
Actual targets:
- _build/default/sub2/bar2.cma
$ buildAndShow %{cma:sub2/bar2}
{
"targets": [
"_build/default/sub2/bar2.cma"
]
}

This test builds a .cmo in a subdirectory (same project).

Expand All @@ -78,21 +95,27 @@ This test builds a .cmo in a subdirectory (same project).

Command line version.

$ dune build --verbose %{cmo:sub/x} 2>&1 | grep -A100 'Actual targets'
Actual targets:
- _build/default/sub/.bar.objs/byte/bar__X.cmo
$ buildAndShow %{cmo:sub/x}
{
"targets": [
"_build/default/sub/.bar.objs/byte/bar__X.cmo"
]
}

This test builds a module in a subdirectory (different project) belonging to a
private library.

$ dune clean
$ dune build @t8

COmmand line version.
Command line version.

$ dune build --verbose %{cmo:sub3/x} 2>&1 | grep -A100 'Actual targets'
Actual targets:
- _build/default/sub3/.c1.objs/byte/c1__X.cmo
$ buildAndShow %{cmo:sub3/x}
{
"targets": [
"_build/default/sub3/.c1.objs/byte/c1__X.cmo"
]
}

This test builds a private library in a subdirectory belonging to a different
project.
Expand All @@ -102,9 +125,12 @@ project.

Command line version.

$ dune build --verbose %{cma:sub3/c1} 2>&1 | grep -A100 'Actual targets'
Actual targets:
- _build/default/sub3/c1.cma
$ buildAndShow %{cma:sub3/c1}
{
"targets": [
"_build/default/sub3/c1.cma"
]
}

This test builds a library in the current directory that has the same name as a
public library defined in a subdirectory.
Expand All @@ -114,9 +140,12 @@ public library defined in a subdirectory.

Command line version.

$ dune build --verbose %{cma:c1} 2>&1 | grep -A100 'Actual targets'
Actual targets:
- _build/default/c1.cma
$ buildAndShow %{cma:c1}
{
"targets": [
"_build/default/c1.cma"
]
}

This test checks error handling.

Expand Down
3 changes: 3 additions & 0 deletions test/blackbox-tests/test-cases/variables-for-artifacts/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(cram
(applies_to artifact-variables)
(deps %{bin:jq}))
Loading