Skip to content

Commit

Permalink
Fix OCaml 5 compatibility (#110)
Browse files Browse the repository at this point in the history
* Fix OCaml 5 compatibility

By removing the compatibility with 4.02.3. The opam dependencies have a constraint on OCaml >= 4.08.0 anyways.

* Replace Lwt_log with Logs_lwt

* Remove asciiart example which doesn't build on OCaml 5
  • Loading branch information
tmattio authored Jul 5, 2022
1 parent aed0eb6 commit bb98730
Show file tree
Hide file tree
Showing 13 changed files with 25 additions and 256 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ jobs:

- run: opam install . --deps-only --with-test

- run: opam install camlimages

- run: opam exec -- dune build

- run: opam exec -- dune runtest
5 changes: 0 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,6 @@ To build the examples:

Binaries for the examples will be in `_build/default/examples`.

The `asciiart` example is not built by default as it as an additional
dependency on the `camlimages` library. To build it run:

$ dune build examples/asciiart/asciiart.exe

Terminal emulators compatibility
--------------------------------

Expand Down
2 changes: 1 addition & 1 deletion dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ facilities in console applications.")
(depends
(ocaml
(>= 4.08.0))
logs
(lwt
(>= 4.2.0))
lwt_log
lwt_react
(mew_vi
(and
Expand Down
14 changes: 7 additions & 7 deletions dune-workspace.dev
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
(lang dune 1.1)

;; This file is used by `make all-supported-ocaml-versions`
(context (opam (switch 4.02.3)))
(context (opam (switch 4.03.0)))
(context (opam (switch 4.04.2)))
(context (opam (switch 4.05.0)))
(context (opam (switch 4.06.1)))
(context (opam (switch 4.07.0)))

(context (opam (switch 4.08.1)))
(context (opam (switch 4.09.1)))
(context (opam (switch 4.10.2)))
(context (opam (switch 4.11.2)))
(context (opam (switch 4.12.1)))
(context (opam (switch 4.13.1)))
(context (opam (switch 4.14.0)))
215 changes: 0 additions & 215 deletions examples/asciiart/asciiart.ml

This file was deleted.

5 changes: 0 additions & 5 deletions examples/asciiart/dune

This file was deleted.

2 changes: 1 addition & 1 deletion lambda-term.opam
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ bug-reports: "https://github.com/ocaml-community/lambda-term/issues"
depends: [
"dune" {>= "3.0"}
"ocaml" {>= "4.08.0"}
"logs"
"lwt" {>= "4.2.0"}
"lwt_log"
"lwt_react"
"mew_vi" {>= "0.5.0" & < "0.6.0"}
"react"
Expand Down
2 changes: 1 addition & 1 deletion src/dune
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
(name lambda_term)
(public_name lambda-term)
(wrapped false)
(libraries lwt lwt.unix lwt_react zed lwt_log mew_vi uucp)
(libraries logs logs.lwt lwt lwt.unix lwt_react zed mew_vi uucp)
(flags (:standard -safe-string))
(synopsis "Cross-platform library for terminal manipulation")
(c_library_flags (:standard (:include c_library_flags)))
Expand Down
2 changes: 0 additions & 2 deletions src/lTerm_buttons_impl.ml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ module Make (LiteralIntf: LiteralIntf.Type) = struct
open LTerm_mouse
open LTerm_widget_callbacks

let section = Lwt_log.Section.make "lambda-term(buttons_impl)"

class t = LTerm_widget_base_impl.t

let space = Char(Uchar.of_char ' ')
Expand Down
15 changes: 9 additions & 6 deletions src/lTerm_history.ml
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,9 @@ let unescape line =
in
loop 0 0

let section = Lwt_log.Section.make "lambda-term(history)"

let src = Logs.Src.create "lambda-term.history" ~doc:"logs LTerm_history module's events"
module Log = (val Logs_lwt.src_log src : Logs_lwt.LOG)

let rec safe_lockf fn fd cmd ofs =
Lwt.catch (fun () ->
Expand All @@ -331,7 +333,7 @@ let rec safe_lockf fn fd cmd ofs =
| Unix.Unix_error (Unix.EINTR, _, _) ->
safe_lockf fn fd cmd ofs
| Unix.Unix_error (error, _, _) ->
Lwt_log.ign_warning_f ~section "failed to lock file '%s': %s" fn (Unix.error_message error);
Log.warn (fun m -> m "failed to lock file '%s': %s" fn (Unix.error_message error)) >>= fun () ->
return false
| exn -> Lwt.fail exn)

Expand All @@ -344,7 +346,7 @@ let open_history fn =
| Unix.Unix_error (Unix.ENOENT, _, _) ->
return None
| Unix.Unix_error (Unix.EACCES, _, _) ->
Lwt_log.ign_info_f "cannot open file '%s' in read and write mode: %s" fn (Unix.error_message Unix.EACCES);
Log.info (fun m -> m "cannot open file '%s' in read and write mode: %s" fn (Unix.error_message Unix.EACCES)) >>= fun () ->
(* If the file cannot be openned in read & write mode,
open it in read only mode but do not lock it. *)
Lwt.catch (fun () ->
Expand All @@ -369,7 +371,7 @@ let load history ?log ?(skip_empty=true) ?(skip_dup=true) fn =
func
| None ->
fun line msg ->
Lwt_log.ign_error_f ~section "File %S, at line %d: %s" fn line msg
Log.info (fun m -> m "File %S, at line %d: %s" fn line msg)
in
(* File opening. *)
open_history fn >>= fun history_file ->
Expand All @@ -392,11 +394,12 @@ let load history ?log ?(skip_empty=true) ?(skip_dup=true) fn =
if not (skip_empty && is_empty entry) && not (skip_dup && is_dup history entry) then begin
add_aux history entry size;
history.old_count <- history.length
end
end;
Lwt.return ()
with
| Zed_string.Invalid (msg, _)-> log num msg
| Zed_utf8.Invalid (msg, _)-> log num msg
);
) >>= fun () ->
aux (num + 1)
in
aux 1)
Expand Down
2 changes: 1 addition & 1 deletion src/lTerm_history.mli
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ val set_max_entries : t -> int -> unit
oldest entries to honor the new limit. *)

val load : t ->
?log : (int -> string -> unit) ->
?log : (int -> string -> unit Lwt.t) ->
?skip_empty : bool ->
?skip_dup : bool ->
string -> unit Lwt.t
Expand Down
7 changes: 0 additions & 7 deletions src/lTerm_key.ml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,6 @@
* This file is a part of Lambda-Term.
*)

(* little hack to maintain 4.02.3 compat with warnings *)
module String = struct
[@@@ocaml.warning "-3-32"]
let lowercase_ascii = StringLabels.lowercase
include String
end

type code =
| Char of Uchar.t
| Enter
Expand Down
Loading

0 comments on commit bb98730

Please sign in to comment.