Skip to content

Commit d4fa53b

Browse files
committed
dune-project: Add the (subst disabled/enabled) stanza
Signed-off-by: Kate <kit.ty.kate@disroot.org>
1 parent b8b2818 commit d4fa53b

9 files changed

Lines changed: 161 additions & 1 deletion

File tree

src/dune_engine/dune_engine.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ module Source_tree = Source_tree
2828
module Opam_file = Opam_file
2929
module Action_dune_lang = Action_dune_lang
3030
module Format_config = Format_config
31+
module Subst_config = Subst_config
3132
module Dune_lexer = Dune_lexer
3233
module Predicate_lang = Predicate_lang
3334
module Section = Section

src/dune_engine/dune_project.ml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ type t =
152152
; dialects : Dialect.DB.t
153153
; explicit_js_mode : bool
154154
; format_config : Format_config.t option
155+
; subst_config : Subst_config.t option
155156
; strict_package_deps : bool
156157
; cram : bool
157158
}
@@ -207,6 +208,7 @@ let to_dyn
207208
; dialects
208209
; explicit_js_mode
209210
; format_config
211+
; subst_config
210212
; strict_package_deps
211213
; cram
212214
} =
@@ -232,6 +234,7 @@ let to_dyn
232234
; ("dialects", Dialect.DB.to_dyn dialects)
233235
; ("explicit_js_mode", bool explicit_js_mode)
234236
; ("format_config", option Format_config.to_dyn format_config)
237+
; ("subst_config", option Subst_config.to_dyn subst_config)
235238
; ("strict_package_deps", bool strict_package_deps)
236239
; ("cram", bool cram)
237240
]
@@ -460,6 +463,8 @@ let format_config t =
460463
let version = dune_version t in
461464
Format_config.of_config ~ext ~dune_lang ~version
462465

466+
let subst_config t = Subst_config.of_config t.subst_config
467+
463468
let default_name ~dir ~(packages : Package.t Package.Name.Map.t) =
464469
match Package.Name.Map.min_binding packages with
465470
| None -> Name.anonymous dir
@@ -515,6 +520,7 @@ let infer ~dir packages =
515520
; dialects = Dialect.DB.builtin
516521
; explicit_js_mode
517522
; format_config = None
523+
; subst_config = None
518524
; strict_package_deps
519525
; cram
520526
}
@@ -614,6 +620,7 @@ let parse ~dir ~lang ~opam_packages ~file ~dir_status =
614620
field_o_b "explicit_js_mode"
615621
~check:(Dune_lang.Syntax.since Stanza.syntax (1, 11))
616622
and+ format_config = Format_config.field ~since:(2, 0)
623+
and+ subst_config = Subst_config.field ~since:(3, 0)
617624
and+ strict_package_deps =
618625
field_o_b "strict_package_deps"
619626
~check:(Dune_lang.Syntax.since Stanza.syntax (2, 3))
@@ -796,6 +803,7 @@ let parse ~dir ~lang ~opam_packages ~file ~dir_status =
796803
; dialects
797804
; explicit_js_mode
798805
; format_config
806+
; subst_config
799807
; strict_package_deps
800808
; cram
801809
}))

src/dune_engine/dune_project.mli

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ val explicit_js_mode : t -> bool
7171

7272
val format_config : t -> Format_config.t
7373

74+
val subst_config : t -> Subst_config.t
75+
7476
val equal : t -> t -> bool
7577

7678
val hash : t -> int

src/dune_engine/subst_config.ml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
open! Stdune
2+
open Import
3+
open Dune_lang.Decoder
4+
5+
(* Can be extended later if needed *)
6+
type t =
7+
| Disabled
8+
| Enabled
9+
10+
let to_dyn conf =
11+
let open Dyn.Encoder in
12+
match conf with
13+
| Disabled -> string "disabled"
14+
| Enabled -> string "enabled"
15+
16+
let decoder =
17+
keyword "disabled" >>> return Disabled
18+
<|> (keyword "enabled" >>> return Enabled)
19+
20+
let field ~since =
21+
field_o "subst" (Dune_lang.Syntax.since Stanza.syntax since >>> decoder)
22+
23+
let of_config = function
24+
| None -> Enabled
25+
| Some conf -> conf

src/dune_engine/subst_config.mli

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
open! Stdune
2+
open Import
3+
4+
type t =
5+
| Disabled
6+
| Enabled
7+
8+
val to_dyn : t -> Dyn.t
9+
10+
val field :
11+
since:Dune_lang.Syntax.Version.t -> t option Dune_lang.Decoder.fields_parser
12+
13+
val of_config : t option -> t

src/dune_rules/opam_create.ml

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,20 @@ let default_build_command =
5656
]
5757
[ "dune" "install" "-p" name "--create-install-files" name ]
5858
]
59+
|}))
60+
and from_3_0_without_subst =
61+
lazy
62+
(Opam_file.parse_value
63+
(Lexbuf.from_string ~fname:"<internal>"
64+
{|
65+
[
66+
[ "dune" "build" "-p" name "-j" jobs "--promote-install-files" "false"
67+
"@install"
68+
"@runtest" {with-test}
69+
"@doc" {with-doc}
70+
]
71+
[ "dune" "install" "-p" name "--create-install-files" name ]
72+
]
5973
|}))
6074
in
6175
fun project ->
@@ -66,8 +80,12 @@ let default_build_command =
6680
from_1_11_before_2_7
6781
else if Dune_project.dune_version project < (2, 9) then
6882
from_2_7
83+
else if Dune_project.dune_version project < (3, 0) then
84+
from_2_9
6985
else
70-
from_2_9)
86+
match Dune_project.subst_config project with
87+
| Disabled -> from_3_0_without_subst
88+
| Enabled -> from_2_9)
7189

7290
let package_fields
7391
{ Package.synopsis

src/dune_rules/watermarks.ml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,19 @@ let subst vcs =
310310
[ Pp.text "dune subst must be executed from the root of the project."
311311
]
312312
in
313+
(match Dune_project.subst_config dune_project.project with
314+
| Dune_engine.Subst_config.Disabled ->
315+
User_error.raise
316+
[ Pp.text
317+
"dune subst has been disabled in this project. Any use of it is \
318+
forbidden."
319+
]
320+
~hints:
321+
[ Pp.text
322+
"If you wish to re-enable it, change to (subst enabled) in the \
323+
dune-project file."
324+
]
325+
| Dune_engine.Subst_config.Enabled -> ());
313326
let info =
314327
let loc, name =
315328
match dune_project.name with

test/blackbox-tests/test-cases/dune-project-meta/main.t/run.t

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,3 +517,58 @@ the doc dependencies:
517517
"something"
518518
"odoc" {with-doc}
519519
]
520+
521+
$ cat > dune-project <<EOF
522+
> (lang dune 3.0)
523+
> (name foo)
524+
> (generate_opam_files true)
525+
> (subst disabled)
526+
> (package (name foo) (depends (odoc :with-test) something))
527+
> EOF
528+
529+
$ dune build foo.opam
530+
$ grep -A15 ^build: foo.opam
531+
build: [
532+
[
533+
"dune"
534+
"build"
535+
"-p"
536+
name
537+
"-j"
538+
jobs
539+
"--promote-install-files"
540+
"false"
541+
"@install"
542+
"@runtest" {with-test}
543+
"@doc" {with-doc}
544+
]
545+
["dune" "install" "-p" name "--create-install-files" name]
546+
]
547+
548+
$ cat > dune-project <<EOF
549+
> (lang dune 3.0)
550+
> (name foo)
551+
> (generate_opam_files true)
552+
> (subst enabled)
553+
> (package (name foo) (depends (odoc :with-test) something))
554+
> EOF
555+
556+
$ dune build foo.opam
557+
$ grep -A16 ^build: foo.opam
558+
build: [
559+
["dune" "subst"] {dev}
560+
[
561+
"dune"
562+
"build"
563+
"-p"
564+
name
565+
"-j"
566+
jobs
567+
"--promote-install-files"
568+
"false"
569+
"@install"
570+
"@runtest" {with-test}
571+
"@doc" {with-doc}
572+
]
573+
["dune" "install" "-p" name "--create-install-files" name]
574+
]

test/blackbox-tests/test-cases/subst.t/run.t

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,29 @@ Test subst and files with unicode (#3879)
106106
(version 1.0)
107107
(package (name foo) (authors "John Doe <john@doe.com>"))
108108

109+
$ cat > dune-project <<EOF
110+
> (lang dune 3.0)
111+
> (name foo)
112+
> (version 1.0)
113+
> (package (name foo) (authors "John Doe <john@doe.com>"))
114+
> (subst disabled)
115+
> EOF
116+
117+
$ dune subst
118+
Error: dune subst has been disabled in this project. Any use of it is
119+
forbidden.
120+
Hint: If you wish to re-enable it, change to (subst enabled) in the
121+
dune-project file.
122+
[1]
123+
124+
$ cat > dune-project <<EOF
125+
> (lang dune 3.0)
126+
> (name foo)
127+
> (version 1.0)
128+
> (package (name foo) (authors "John Doe <john@doe.com>"))
129+
> (subst enabled)
130+
> EOF
131+
132+
$ dune subst
133+
109134
$ rm -rf .git

0 commit comments

Comments
 (0)