@@ -2,10 +2,13 @@ open Atd.Import
22open Atdgen_emit
33
44let fail_deprecated_variable = " ATDGEN_FAIL_DEPRECATED_OPTIONS"
5+
56let maybe_fail_deprecated where =
67 match Sys. getenv fail_deprecated_variable with
7- | "true" -> Printf. ksprintf failwith " Error: option %S is forbidden." where
8- | _ | exception _ -> ()
8+ | "true" ->
9+ Printf. ksprintf failwith " Error: option %S is forbidden." where
10+ | _ | exception _ ->
11+ Printf. eprintf " Warning: option %S is deprecated.\n %!" where
912
1013let append l1 l2 =
1114 List. concat_map (fun s1 -> List. map (fun s2 -> s1 ^ s2) l2) l1
@@ -67,6 +70,9 @@ let main () =
6770 let all_rec = ref false in
6871 let out_prefix = ref None in
6972 let mode = ref (None : mode option ) in
73+ (* uses_deprecated_jstd_option is now only used to imply '-j' if a user
74+ passes '-j-std' or '-std-json' without '-j' *)
75+ let uses_deprecated_jstd_option = ref false in
7076 let add_generic_modules = ref false in
7177 let j_preprocess_input = ref None in
7278 let j_defaults = ref false in
@@ -185,9 +191,12 @@ let main () =
185191 including OCaml type definitions." ;
186192
187193 " -j-std" ,
188- Arg. Unit (fun () -> maybe_fail_deprecated " -j-std" ),
194+ Arg. Unit (fun () ->
195+ uses_deprecated_jstd_option := true ;
196+ maybe_fail_deprecated " -j-std" ),
189197 "
190- [deprecated] This option does nothing; kept for backwards compatibility." ;
198+ [deprecated] This option is now equivalent to -j;
199+ kept for backward compatibility." ;
191200
192201 " -j-gen-modules" ,
193202 Arg. Unit (fun () ->
@@ -198,7 +207,9 @@ let main () =
198207 module Typename: sig type t ... val read: ... val to_string: ... end" ;
199208
200209 " -std-json" ,
201- Arg. Unit (fun () -> maybe_fail_deprecated " -std-json" ),
210+ Arg. Unit (fun () ->
211+ uses_deprecated_jstd_option := true ;
212+ maybe_fail_deprecated " -std-json" ),
202213 "
203214 [deprecated] No-op: same as -j-std." ;
204215
@@ -306,7 +317,8 @@ to make their use fail and hence help clean-up your build scripts.
306317|} Sys. argv.(0 ) fail_deprecated_variable in
307318 Arg. parse options (fun file -> files := file :: ! files) msg;
308319
309- if (! unknown_field_handler <> None ) && ! mode = None then
320+ if (! uses_deprecated_jstd_option
321+ || ! unknown_field_handler <> None ) && ! mode = None then
310322 set_once " output mode" mode Json ;
311323
312324 let mode =
0 commit comments