Skip to content

Commit 5cd9868

Browse files
author
Martin Jambon
authored
[atdgen] Restore behavior where '-j-std' implies '-j' and print a warning (#444)
The following test should print code that's related to JSON and not Biniou: $ echo 'type t = int' | ./_build/install/default/bin/atdgen -j-std
1 parent 7b08631 commit 5cd9868

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

CHANGES.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
3.0.1 (2025-12-09)
2+
------------------
3+
4+
* atdgen: `-j-std` now implies `-j` like before to avoid breaking
5+
existing uses. A warning is now also printed to encourage migration (#443)
6+
17
3.0.0 (2025-12-09)
28
------------------
39

atdgen/bin/ag_main.ml

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@ open Atd.Import
22
open Atdgen_emit
33

44
let fail_deprecated_variable = "ATDGEN_FAIL_DEPRECATED_OPTIONS"
5+
56
let 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

1013
let 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

Comments
 (0)