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

Modernize codebase a bit #9

Merged
merged 4 commits into from
Apr 13, 2024
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: 1 addition & 1 deletion .ocamlformat
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ type-decl=sparse
break-separators=before
if-then-else=keyword-first
dock-collection-brackets=false
version=0.24.1
version=0.26.1
20 changes: 16 additions & 4 deletions dune
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,34 @@
(targets merge-fmt-help.txt)
(deps ./src/merge_fmt.exe)
(mode promote)
(action (with-stdout-to %{targets} (run ./src/merge_fmt.exe --help=plain))))
(action
(with-stdout-to
%{targets}
(run ./src/merge_fmt.exe --help=plain))))

(rule
(targets merge-fmt-mergetool-help.txt)
(deps ./src/merge_fmt.exe)
(mode promote)
(action (with-stdout-to %{targets} (run ./src/merge_fmt.exe mergetool --help=plain))))
(action
(with-stdout-to
%{targets}
(run ./src/merge_fmt.exe mergetool --help=plain))))

(rule
(targets merge-fmt-setup-mergetool-help.txt)
(deps ./src/merge_fmt.exe)
(mode promote)
(action (with-stdout-to %{targets} (run ./src/merge_fmt.exe setup-mergetool --help=plain))))
(action
(with-stdout-to
%{targets}
(run ./src/merge_fmt.exe setup-mergetool --help=plain))))

(rule
(targets merge-fmt-setup-merge-help.txt)
(deps ./src/merge_fmt.exe)
(mode promote)
(action (with-stdout-to %{targets} (run ./src/merge_fmt.exe setup-merge --help=plain))))
(action
(with-stdout-to
%{targets}
(run ./src/merge_fmt.exe setup-merge --help=plain))))
3 changes: 1 addition & 2 deletions dune-project
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
(lang dune 1.6)
(using fmt 1.0)
(lang dune 3.0)
(name merge-fmt)
2 changes: 1 addition & 1 deletion merge-fmt.opam
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ build: [["dune" "build" "-p" name "-j" jobs]]

depends: [
"ocaml" {>= "4.06.1"}
"dune" {>= "1.6"}
"dune" {>= "3.0"}
"cmdliner" {>= "1.1.0"}
"base"
"stdio"
Expand Down
8 changes: 4 additions & 4 deletions src/common.ml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ let open_process_in_respect_exit ~echo fmt =
let contents = In_channel.input_all ic in
match Unix.close_process_in ic with
| WEXITED 0 -> contents
| WEXITED n -> Caml.exit n
| WSIGNALED _ | WSTOPPED _ -> Caml.exit 1)
| WEXITED n -> Stdlib.exit n
| WSIGNALED _ | WSTOPPED _ -> Stdlib.exit 1)
fmt

let system ~echo fmt =
Expand All @@ -35,8 +35,8 @@ let system_respect_exit ~echo fmt =
if echo then eprintf "+ %s\n%!" s;
match Unix.system s with
| WEXITED 0 -> ()
| WEXITED n -> Caml.exit n
| WSIGNALED _ | WSTOPPED _ -> Caml.exit 1)
| WEXITED n -> Stdlib.exit n
| WSIGNALED _ | WSTOPPED _ -> Stdlib.exit 1)
fmt

module Flags = struct
Expand Down
7 changes: 3 additions & 4 deletions src/dune
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
(executables
(names merge_fmt)
(public_names merge-fmt)
(libraries base stdio unix cmdliner)
)
(names merge_fmt)
(public_names merge-fmt)
(libraries base stdio unix cmdliner))
2 changes: 1 addition & 1 deletion src/fmters.ml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ let dune ~bin =

let find ~config ~filename ~name =
let filename = Option.value ~default:filename name in
match (filename, Caml.Filename.extension filename, config) with
match (filename, Stdlib.Filename.extension filename, config) with
| _, (".ml" | ".mli"), { ocamlformat_path; _ } ->
Some (ocamlformat ~bin:ocamlformat_path ~name)
| _, (".re" | ".rei"), { refmt_path; _ } -> Some (refmt ~bin:refmt_path)
Expand Down
10 changes: 6 additions & 4 deletions src/merge_cmd.ml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ open Common
let debug_oc =
lazy
(Out_channel.create ~append:true
(Filename.concat (Filename.get_temp_dir_name ()) "merge-fmt.log"))
(Stdlib.Filename.concat
(Stdlib.Filename.get_temp_dir_name ())
"merge-fmt.log"))

let debug fmt =
if true
Expand All @@ -15,7 +17,7 @@ let debug fmt =
let merge config echo current base other output name =
match (current, base, other) with
| (None | Some ""), _, _ | _, (None | Some ""), _ | _, _, (None | Some "") ->
Caml.exit 1
Stdlib.exit 1
| Some current, Some base, Some other -> (
match Fmters.find ~config ~filename:current ~name with
| None ->
Expand All @@ -33,7 +35,7 @@ let merge config echo current base other output name =
|> Result.map_error ~f:(Fn.const "base")
in
match Result.combine_errors [ x; y; z ] with
| Error _ -> Caml.exit 1
| Error _ -> Stdlib.exit 1
| Ok (_ : unit list) ->
debug "process all three revision successfully\n%!";
debug "running git merge-file\n%!";
Expand All @@ -44,7 +46,7 @@ let merge config echo current base other output name =
(match output with
| None -> Out_channel.output_string stdout result
| Some o -> Out_channel.write_all o ~data:result);
Caml.exit 0))
Stdlib.exit 0))

open Cmdliner

Expand Down
8 changes: 4 additions & 4 deletions src/resolve_cmd.ml
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ let show ~echo version versions =

let create_tmp ~echo fn version versions =
let content = show ~echo version versions in
let ext = Caml.Filename.extension fn in
let ext = Stdlib.Filename.extension fn in
let base =
if String.equal ext "" then fn else Caml.Filename.chop_extension fn
if String.equal ext "" then fn else Stdlib.Filename.chop_extension fn
in
let fn' = sprintf "%s.%s%s" base (string_of_version version) ext in
let oc = Out_channel.create fn' in
Expand Down Expand Up @@ -114,7 +114,7 @@ let resolve config echo () =
if Map.is_empty all
then (
eprintf "Nothing to resolve\n%!";
Caml.exit 1);
Stdlib.exit 1);
Map.iteri all ~f:(fun ~key:filename ~data:versions ->
match versions with
| Ok versions -> (
Expand All @@ -131,7 +131,7 @@ let resolve config echo () =
| None -> eprintf "Ignore %s (no formatter register)\n%!" filename)
| Error reason -> eprintf "Ignore %s (%s)\n%!" filename reason);
let all = ls ~echo () in
if Map.is_empty all then Caml.exit 0 else Caml.exit 1
if Map.is_empty all then Stdlib.exit 0 else Stdlib.exit 1

open Cmdliner

Expand Down
27 changes: 16 additions & 11 deletions test/dune
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
(library
(name merge_fmt_test)
(libraries base stdio unix core_unix core_unix.filename_unix)
(inline_tests)
(preprocessor_deps ../src/merge_fmt.exe)
(preprocess (pps ppx_expect)))

(name merge_fmt_test)
(libraries base stdio unix core_unix core_unix.filename_unix)
(inline_tests)
(preprocessor_deps ../src/merge_fmt.exe)
(preprocess
(pps ppx_expect)))

;; [rebase_a.ml] and [rebase_b.ml] should be the same expect that
;; [rebase_b.ml] does rebase in an intermediate revision.

(rule
(targets rebase.diff.gen)
(action (with-stdout-to %{targets} (bash "diff %{dep:rebase_a.ml} %{dep:rebase_b.ml} || true"))))
(targets rebase.diff.gen)
(action
(with-stdout-to
%{targets}
(bash "diff %{dep:rebase_a.ml} %{dep:rebase_b.ml} || true"))))

(alias
(name runtest)
(action (diff rebase.diff rebase.diff.gen)))
(rule
(alias runtest)
(action
(diff rebase.diff rebase.diff.gen)))
Loading