Skip to content

Commit 7c24777

Browse files
Output package definition to lock file for now
1 parent 6bd038d commit 7c24777

File tree

1 file changed

+18
-20
lines changed

1 file changed

+18
-20
lines changed

src/dune_rules/lock_rules.ml

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,19 @@ module Spec = struct
55
type ('path, 'target) t =
66
{ target : 'target
77
; lock_dir : string
8+
; projects : Dune_project.t list
89
}
910

1011
let name = "lock"
1112
let version = 1
1213
let bimap t _ g = { t with target = g t.target }
1314
let is_useful_to ~memoize = memoize
1415

15-
let encode { target; lock_dir } _encode_path encode_target : Sexp.t =
16+
let encode { target; lock_dir; projects = _ } _encode_path encode_target : Sexp.t =
1617
Sexp.List [ encode_target target; Sexp.Atom lock_dir ]
1718
;;
1819

19-
let action { target; lock_dir } ~ectx:_ ~eenv:_ =
20+
let action { target; lock_dir; projects } ~ectx:_ ~eenv:_ =
2021
let open Fiber.O in
2122
let+ () = Fiber.return () in
2223
Printf.eprintf
@@ -25,28 +26,25 @@ module Spec = struct
2526
lock_dir;
2627
let path = Path.build target in
2728
Path.mkdir_p path;
28-
let t = Unix.localtime @@ Unix.gettimeofday () in
2929
let content =
30-
sprintf
31-
"Created on %d-%0.2d-%0.2d %0.2d:%0.2d:%0.2d"
32-
(t.tm_year + 1900)
33-
(t.tm_mon + 1)
34-
t.tm_mday
35-
t.tm_hour
36-
t.tm_min
37-
t.tm_sec
30+
projects
31+
|> List.map ~f:(fun project ->
32+
let pkgs = Dune_project.packages project in
33+
Dune_lang.Package_name.Map.to_dyn Package.to_dyn pkgs
34+
|>
35+
Dyn.to_string)
36+
|> String.concat ~sep:"\n"
3837
in
39-
Io.write_file ~binary:true (Path.relative path "lock.dune") content;
40-
()
38+
Io.write_file ~binary:true (Path.relative path "lock.dune") content
4139
;;
4240
end
4341

4442
module A = Action_ext.Make (Spec)
4543

46-
let action ~target ~lock_dir = A.action { Spec.target; lock_dir }
44+
let action ~projects ~target ~lock_dir = A.action { Spec.target; lock_dir; projects }
4745

48-
let lock ~target ~lock_dir =
49-
action ~target ~lock_dir
46+
let lock ~projects ~target ~lock_dir =
47+
action ~projects ~target ~lock_dir
5048
|> Action.Full.make ~can_go_in_shared_cache:false
5149
|> Action_builder.With_targets.return
5250
|> Action_builder.With_targets.add_directories ~directory_targets:[ target ]
@@ -61,15 +59,15 @@ let rule ?loc { Action_builder.With_targets.build; targets } =
6159

6260
let setup_lock_rules ~dir ~lock_dir ~projects : Gen_rules.result =
6361
let target = Path.Build.relative dir "content" in
64-
let gen_rules lock_dir =
65-
let lock_rule = lock ~target ~lock_dir in
62+
let gen_rules projects lock_dir =
63+
let lock_rule = lock ~projects ~target ~lock_dir in
6664
rule ~loc:Loc.none lock_rule
6765
in
6866
let rules =
6967
Rules.collect_unit (fun () ->
7068
(* deref Memo to create dependency on project *)
71-
let* _projects = projects in
72-
gen_rules lock_dir)
69+
let* projects = projects in
70+
gen_rules projects lock_dir)
7371
in
7472
let directory_targets = Path.Build.Map.singleton target Loc.none in
7573
Gen_rules.make ~directory_targets rules

0 commit comments

Comments
 (0)