Skip to content

Commit 6c0b0c3

Browse files
Add a configuration option to enable package management (ocaml#12025)
* Add a configuration option to enable package management Signed-off-by: Marek Kubica <[email protected]> * Add tests for user config vs workspace config semantics Signed-off-by: Marek Kubica <[email protected]> * Add note to change this code when we stop reading lockfiles from source Signed-off-by: Marek Kubica <[email protected]> * Fix typo Co-authored-by: Stephen Sherratt <[email protected]> Signed-off-by: Marek Kubica <[email protected]> --------- Signed-off-by: Marek Kubica <[email protected]> Signed-off-by: Marek Kubica <[email protected]> Co-authored-by: Stephen Sherratt <[email protected]>
1 parent 50859b7 commit 6c0b0c3

File tree

6 files changed

+85
-2
lines changed

6 files changed

+85
-2
lines changed

bin/common.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,7 @@ let shared_with_config_file =
520520
; action_stdout_on_success
521521
; action_stderr_on_success
522522
; project_defaults = None
523+
; pkg_enabled = None
523524
; experimental = None
524525
}
525526
;;

bin/pkg/pkg_enabled.ml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@ let term =
1717
List.exists lock_dir_paths ~f:(fun lock_dir_path ->
1818
Path.exists (Path.source lock_dir_path))
1919
in
20-
if any_lockdir_exists then () else exit 1)
20+
(* CR-Leonidas-from-XIV: change this logic when we stop detecting lock
21+
directories in the source tree *)
22+
let enabled = any_lockdir_exists || workspace.config.pkg_enabled in
23+
match enabled with
24+
| true -> ()
25+
| false -> exit 1)
2126
;;
2227

2328
let info =

src/dune_config_file/dune_config_file.ml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,14 @@ module Dune_config = struct
5353
;;
5454
end
5555

56+
module Pkg_enabled = struct
57+
type t = bool
58+
59+
let decode = enum' [ "enabled", return true; "disabled", return false ]
60+
let equal = Bool.equal
61+
let to_dyn = Dyn.bool
62+
end
63+
5664
module Terminal_persistence = struct
5765
type t =
5866
| Preserve
@@ -236,6 +244,7 @@ module Dune_config = struct
236244
; action_stdout_on_success : Action_output_on_success.t field
237245
; action_stderr_on_success : Action_output_on_success.t field
238246
; project_defaults : Project_defaults.t field
247+
; pkg_enabled : Pkg_enabled.t field
239248
; experimental : (string * (Loc.t * string)) list field
240249
}
241250
end
@@ -260,6 +269,7 @@ module Dune_config = struct
260269
; action_stdout_on_success
261270
; action_stderr_on_success
262271
; project_defaults
272+
; pkg_enabled
263273
; experimental
264274
}
265275
=
@@ -287,6 +297,7 @@ module Dune_config = struct
287297
(Tuple.T2.equal String.equal (Tuple.T2.equal Loc.equal String.equal)))
288298
t.experimental
289299
experimental
300+
&& field Pkg_enabled.equal t.pkg_enabled pkg_enabled
290301
;;
291302
end
292303

@@ -314,6 +325,7 @@ module Dune_config = struct
314325
; action_stderr_on_success =
315326
field a.action_stderr_on_success b.action_stderr_on_success
316327
; project_defaults = field a.project_defaults b.project_defaults
328+
; pkg_enabled = field a.pkg_enabled b.pkg_enabled
317329
; experimental = field a.experimental b.experimental
318330
}
319331
;;
@@ -338,6 +350,7 @@ module Dune_config = struct
338350
; action_stdout_on_success
339351
; action_stderr_on_success
340352
; project_defaults
353+
; pkg_enabled
341354
; experimental
342355
}
343356
=
@@ -358,6 +371,7 @@ module Dune_config = struct
358371
; ( "action_stderr_on_success"
359372
, field Action_output_on_success.to_dyn action_stderr_on_success )
360373
; "project_defaults", field Project_defaults.to_dyn project_defaults
374+
; "pkg_enabled", field Pkg_enabled.to_dyn pkg_enabled
361375
; ( "experimental"
362376
, field Dyn.(list (pair string (fun (_, v) -> string v))) experimental )
363377
]
@@ -382,6 +396,7 @@ module Dune_config = struct
382396
; action_stdout_on_success = None
383397
; action_stderr_on_success = None
384398
; project_defaults = None
399+
; pkg_enabled = None
385400
; experimental = None
386401
}
387402
;;
@@ -467,6 +482,7 @@ module Dune_config = struct
467482
; maintenance_intent = None
468483
; license = Some [ "LICENSE" ]
469484
}
485+
; pkg_enabled = false
470486
; experimental = []
471487
}
472488
;;
@@ -533,6 +549,7 @@ module Dune_config = struct
533549
and+ action_stderr_on_success =
534550
field_o "action_stderr_on_success" (3, 0) Action_output_on_success.decode
535551
and+ project_defaults = field_o "project_defaults" (3, 17) Project_defaults.decode
552+
and+ pkg_enabled = field_o "pkg" (3, 20) Pkg_enabled.decode
536553
and+ experimental =
537554
field_o "experimental" (3, 8) (repeat (pair string (located string)))
538555
in
@@ -554,6 +571,7 @@ module Dune_config = struct
554571
; action_stdout_on_success
555572
; action_stderr_on_success
556573
; project_defaults
574+
; pkg_enabled
557575
; experimental
558576
}
559577
;;

src/dune_config_file/dune_config_file.mli

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ module Dune_config : sig
5454
end
5555
end
5656

57+
module Pkg_enabled : sig
58+
type t = bool
59+
end
60+
5761
module Terminal_persistence : sig
5862
type t =
5963
| Preserve
@@ -83,6 +87,7 @@ module Dune_config : sig
8387
; action_stdout_on_success : Action_output_on_success.t field
8488
; action_stderr_on_success : Action_output_on_success.t field
8589
; project_defaults : Project_defaults.t field
90+
; pkg_enabled : Pkg_enabled.t field
8691
; experimental : (string * (Loc.t * string)) list field
8792
}
8893
end

test/blackbox-tests/test-cases/pkg/pkg-enabled.t

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ should be used.
1919
> EOF
2020

2121
$ cat > dune-project <<EOF
22-
> (lang dune 3.13)
22+
> (lang dune 3.20)
2323
> (package
2424
> (allow_empty)
2525
> (name foo))
@@ -39,3 +39,54 @@ When the default lockdir is present pkg is enabled:
3939
When a non-default lockdir is present, pkg is still enabled:
4040
$ dune pkg lock dune.other.lock > /dev/null 2> /dev/null
4141
$ dune pkg enabled
42+
43+
Remove the other lock dir and make sure the status didn't latch to be always
44+
enabled.
45+
46+
$ rm -r dune.other.lock
47+
$ dune pkg enabled
48+
[1]
49+
50+
Manually enable package management in the workspace, it should be reported as
51+
enabled:
52+
53+
$ cat > dune-workspace <<EOF
54+
> (lang dune 3.20)
55+
> (pkg enabled)
56+
> EOF
57+
$ dune pkg enabled && echo "Yes, it is enabled"
58+
Yes, it is enabled
59+
60+
If we remove the setting from the workspace it should go back to the default
61+
(disabled)
62+
63+
$ cat > dune-workspace <<EOF
64+
> (lang dune 3.20)
65+
> EOF
66+
$ dune pkg enabled || echo "Package management disabled"
67+
Package management disabled
68+
69+
Enable the package management globally in the user's config.
70+
71+
$ cat > config <<EOF
72+
> (lang dune 3.20)
73+
> (pkg enabled)
74+
> EOF
75+
$ dune pkg enabled --config-file=config && echo "Yes, it is enabled"
76+
Yes, it is enabled
77+
78+
Disable it in the user config, but enable it in the workspace. Workspace is
79+
higher precedence so it should be enabled:
80+
81+
$ cat > config <<EOF
82+
> (lang dune 3.20)
83+
> (pkg disabled)
84+
> EOF
85+
$ dune pkg enabled --config-file=config || echo "Successfully disabled by config"
86+
Successfully disabled by config
87+
$ cat > dune-workspace <<EOF
88+
> (lang dune 3.20)
89+
> (pkg enabled)
90+
> EOF
91+
$ dune pkg enabled --config-file=config && echo "Workspace config overrides user config"
92+
Workspace config overrides user config

test/expect-tests/dune_config_file/dune_config_test.ml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ let%expect_test "cache-check-probability 0.1" =
3333
; maintenance_intent = None
3434
; license = Some [ "LICENSE" ]
3535
}
36+
; pkg_enabled = false
3637
; experimental = []
3738
}
3839
|}]
@@ -57,6 +58,7 @@ let%expect_test "cache-storage-mode copy" =
5758
; maintenance_intent = None
5859
; license = Some [ "LICENSE" ]
5960
}
61+
; pkg_enabled = false
6062
; experimental = []
6163
}
6264
|}]
@@ -81,6 +83,7 @@ let%expect_test "cache-storage-mode hardlink" =
8183
; maintenance_intent = None
8284
; license = Some [ "LICENSE" ]
8385
}
86+
; pkg_enabled = false
8487
; experimental = []
8588
}
8689
|}]

0 commit comments

Comments
 (0)