Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[2.9] Compatibility with OCaml 5.0 #5351

Merged
merged 3 commits into from
Jan 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Unreleased
- No longer reference deprecated Toploop functions when using dune files in
OCaml syntax. (#4834, fixes #4830, @nojb)

- Use the stag format API to be compatible with OCaml 5.0 (#5351, @emillon).

2.9.1 (07/09/2021)
------------------

Expand Down
28 changes: 13 additions & 15 deletions src/dune_lang/t.ml
Original file line number Diff line number Diff line change
Expand Up @@ -77,32 +77,30 @@ module Deprecated = struct
let state = ref [] in
Format.pp_set_mark_tags ppf true;
let ofuncs = Format.pp_get_formatter_out_functions ppf () in
let tfuncs =
(Format.pp_get_formatter_tag_functions ppf () [@warning "-3"])
in
Format.pp_set_formatter_tag_functions ppf
let tfuncs = Format.pp_get_formatter_stag_functions ppf () in
Format.pp_set_formatter_stag_functions ppf
{ tfuncs with
mark_open_tag =
mark_open_stag =
(function
| "atom" ->
| Format.String_tag "atom" ->
state := In_atom :: !state;
""
| "makefile-action" ->
| Format.String_tag "makefile-action" ->
state := In_makefile_action :: !state;
""
| "makefile-stuff" ->
| Format.String_tag "makefile-stuff" ->
state := In_makefile_stuff :: !state;
""
| s -> tfuncs.mark_open_tag s)
; mark_close_tag =
| s -> tfuncs.mark_open_stag s)
; mark_close_stag =
(function
| "atom"
| "makefile-action"
| "makefile-stuff" ->
| Format.String_tag "atom"
| Format.String_tag "makefile-action"
| Format.String_tag "makefile-stuff" ->
state := List.tl !state;
""
| s -> tfuncs.mark_close_tag s)
} [@warning "-3"];
| s -> tfuncs.mark_close_stag s)
};
Format.pp_set_formatter_out_functions ppf
{ ofuncs with
out_newline =
Expand Down
28 changes: 15 additions & 13 deletions src/dune_rules/colors.ml
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,25 @@ module Style = struct
| _ -> None
end

let mark_open_tag s =
match Style.of_string s with
| Some style -> Ansi_color.Style.escape_sequence (Style.to_styles style)
| None ->
if s <> "" && s.[0] = '\027' then
s
else
""
let mark_open_stag = function
| Format.String_tag s -> (
match Style.of_string s with
| Some style -> Ansi_color.Style.escape_sequence (Style.to_styles style)
| None ->
if s <> "" && s.[0] = '\027' then
s
else
"")
| _ -> ""

let setup_err_formatter_colors () =
let open Format in
if Lazy.force Ansi_color.stderr_supports_color then
List.iter [ err_formatter; Dune_util.Report_error.ppf ] ~f:(fun ppf ->
let funcs = (pp_get_formatter_tag_functions ppf () [@warning "-3"]) in
let funcs = pp_get_formatter_stag_functions ppf () in
pp_set_mark_tags ppf true;
pp_set_formatter_tag_functions ppf
pp_set_formatter_stag_functions ppf
{ funcs with
mark_close_tag = (fun _ -> Ansi_color.Style.escape_sequence [])
; mark_open_tag
} [@warning "-3"])
mark_close_stag = (fun _ -> Ansi_color.Style.escape_sequence [])
; mark_open_stag
})