Skip to content

Commit

Permalink
use a more compact formatting style
Browse files Browse the repository at this point in the history
(this match irmin's style and the RFC changes proposed in
ocaml-ppx/ocamlformat#1851)
  • Loading branch information
samoht committed Oct 11, 2021
1 parent c2590f5 commit c57dff5
Show file tree
Hide file tree
Showing 84 changed files with 1 addition and 509 deletions.
1 change: 1 addition & 0 deletions .ocamlformat
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ version = 0.19.0
profile = conventional
break-infix = fit-or-vertical
parse-docstrings = true
module-item-spacing = compact
20 changes: 0 additions & 20 deletions lib/functoria/DSL.ml
Original file line number Diff line number Diff line change
Expand Up @@ -17,47 +17,27 @@
*)

type 'a key = 'a Key.key

type 'a value = 'a Key.value

type abstract_key = Key.t

type package = Package.t

type scope = Package.scope

type 'a typ = 'a Type.t

type 'a impl = 'a Impl.t

type abstract_impl = Impl.abstract

type 'a device = ('a, Impl.abstract) Device.t

type context = Key.context

type job = Job.t

type info = Info.t

let package = Package.v

let ( @-> ) = Type.( @-> )

let typ = Type.v

let ( $ ) = Impl.( $ )

let of_device = Impl.of_device

let key = Key.v

let dep = Impl.abstract

let abstract = dep

let if_impl = Impl.if_

let match_impl = Impl.match_

let impl ?packages ?packages_v ?install ?install_v ?keys ?extra_deps ?connect
Expand Down
43 changes: 0 additions & 43 deletions lib/functoria/action.ml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@
let src = Logs.Src.create "functoria.action" ~doc:"functoria library"

module Log = (val Logs.src_log src : Logs.LOG)

open Astring

type 'a or_err = ('a, Rresult.R.msg) result

type tmp_name_pat = Bos.OS.File.tmp_name_pat

type 'a with_output = {
Expand All @@ -36,9 +34,7 @@ type 'a with_output = {
}

type channel = [ `Null | `Fmt of Format.formatter ]

type cmd = { cmd : Bos.Cmd.t; err : channel; out : channel; trim : bool }

type ls = { root : Fpath.t; filter : Fpath.t -> bool }

type _ command =
Expand Down Expand Up @@ -67,9 +63,7 @@ and _ t =
| Run : 'r command * ('r -> 'a t) -> 'a t

let ok x = Done x

let error e = Fail e

let errorf fmt = Fmt.kstr error fmt

let rec bind ~f = function
Expand All @@ -80,33 +74,19 @@ let rec bind ~f = function
Run (c, k2)

let map ~f x = bind x ~f:(fun y -> ok (f y))

let rec seq = function [] -> ok () | h :: t -> bind ~f:(fun () -> seq t) h

let wrap x = Run (x, ok)

let ( ! ) = Fpath.normalize

let rm path = wrap @@ Rm !path

let rmdir path = wrap @@ Rmdir !path

let mkdir path = wrap @@ Mkdir !path

let ls path filter = wrap @@ Ls { root = !path; filter }

let with_dir path f = wrap @@ With_dir (!path, f)

let pwd () = wrap @@ Pwd

let is_file path = wrap @@ Is_file !path

let is_dir path = wrap @@ Is_dir !path

let size_of path = wrap @@ Size_of !path

let set_var c v = wrap @@ Set_var (c, v)

let get_var c = wrap @@ Get_var c

let run_cmd ?(err = `Fmt Fmt.stderr) ?(out = `Fmt Fmt.stdout) cmd =
Expand All @@ -116,11 +96,8 @@ let run_cmd_out ?(err = `Fmt Fmt.stderr) cmd =
wrap @@ Run_cmd_out { cmd; out = `Null; err; trim = true }

let run_cmd_cli cmd = wrap @@ Run_cmd_cli cmd

let write_file path contents = wrap @@ Write_file (!path, contents)

let read_file path = wrap @@ Read_file !path

let tmp_file ?mode pat = wrap @@ Tmp_file (mode, pat)

let with_output ?mode ?(append = false) ~path ~purpose contents =
Expand Down Expand Up @@ -247,15 +224,10 @@ module Env : sig
type t

val eq : t -> t -> bool

val pp : t Fmt.t

val diff_files : old:t -> t -> Fpath.Set.t

val pwd : t -> Fpath.t

val chdir : t -> Fpath.t -> t

val ls : t -> Fpath.t -> Fpath.t list option

val v :
Expand All @@ -267,27 +239,16 @@ module Env : sig
t

val exec : t -> Bos.Cmd.t -> (string * string) option

val is_file : t -> Fpath.t -> bool

val is_dir : t -> Fpath.t -> bool

val mkdir : t -> Fpath.t -> (t * bool) option

val rm : t -> Fpath.t -> (t * bool) option

val rmdir : t -> Fpath.t -> t

val size_of : t -> Fpath.t -> int option

val write : t -> Fpath.t -> string -> t

val read : t -> Fpath.t -> string option

val tmp_file : t -> tmp_name_pat -> Fpath.t

val set_var : t -> string -> string option -> t

val get_var : t -> string -> string option
end = struct
type t = {
Expand Down Expand Up @@ -354,7 +315,6 @@ end = struct
]

let pwd t = t.pwd

let exec t cmd = t.exec cmd

let mk_path t path =
Expand Down Expand Up @@ -471,7 +431,6 @@ let env = Env.v
type 'a domain = { result : 'a or_err; env : Env.t; logs : string list }

let pp_or_err pp_a = Rresult.R.pp ~error:Rresult.R.pp_msg ~ok:pp_a

let eq_or_err eq_a = Rresult.R.equal ~error:( = ) ~ok:eq_a

let pp_domain pp_a =
Expand Down Expand Up @@ -667,15 +626,13 @@ let generated_files ?(env = env ~exec:(fun _ -> None) ()) t =

module Infix = struct
let ( >>= ) x f = bind ~f x

let ( >|= ) x f = map ~f x
end

module Syntax = struct
open Infix

let ( let* ) = ( >>= )

let ( let+ ) = ( >|= )
end

Expand Down
3 changes: 0 additions & 3 deletions lib/functoria/action.mli
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,16 @@ val seq : unit t list -> unit t

module List : sig
val iter : f:('a -> unit t) -> 'a list -> unit t

val map : f:('a -> 'b t) -> 'a list -> 'b list t
end

module Infix : sig
val ( >>= ) : 'a t -> ('a -> 'b t) -> 'b t

val ( >|= ) : 'a t -> ('a -> 'b) -> 'b t
end

module Syntax : sig
val ( let* ) : 'a t -> ('a -> 'b t) -> 'b t

val ( let+ ) : 'a t -> ('a -> 'b) -> 'b t
end

Expand Down
7 changes: 0 additions & 7 deletions lib/functoria/cli.ml
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,8 @@ let setup_log style_renderer level =
open Cmdliner

let common_section = "COMMON OPTIONS"

let configuration_section = "CONFIGURE OPTIONS"

let query_section = "QUERY OPTIONS"

let description_section = "DESCRIBE OPTIONS"

type query_kind =
Expand Down Expand Up @@ -197,9 +194,7 @@ type 'a configure_args = {
}

type 'a build_args = 'a args

type 'a clean_args = 'a args

type 'a help_args = 'a args

type 'a describe_args = {
Expand Down Expand Up @@ -247,9 +242,7 @@ let pp_configure pp_a =
]

let pp_build = pp_args

let pp_clean = pp_args

let pp_help = pp_args

let pp_query_kind ppf (q : query_kind) =
Expand Down
2 changes: 0 additions & 2 deletions lib/functoria/context.ml
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ module Map = Map.Make (String)
type t = exn Map.t

let empty = Map.empty

let add k v (t : t) : t = Map.add k.name (k.put v) t

let mem k (t : t) = Map.mem k.name t

let find k (t : t) =
Expand Down
1 change: 0 additions & 1 deletion lib/functoria/context_cache.ml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ module Log = (val Logs.src_log src : Logs.LOG)
type t = string array

let empty = [| "" |]

let is_empty t = t = empty

let write file argv =
Expand Down
18 changes: 0 additions & 18 deletions lib/functoria/device.ml
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,9 @@ open Action.Syntax
open Astring

type abstract_key = Key.t

type package = Package.t

type info = Info.t

type 'a value = 'a Key.value

type 'a code = string

type ('a, 'impl) t = {
Expand Down Expand Up @@ -60,16 +56,13 @@ let pp : type a b. b Fmt.t -> (a, b) t Fmt.t =
record fields ppf t

let equal x y = Typeid.equal x.id y.id

let witness x y = Typeid.witness x.id y.id

let hash x = Typeid.id x.id

let default_connect _ _ l =
Printf.sprintf "return (%s)" (String.concat ~sep:", " l)

let niet _ = Action.ok ()

let nil _ = []

let merge empty union a b =
Expand All @@ -80,7 +73,6 @@ let merge empty union a b =
| Some a, Some b -> Key.(pure union $ pure a $ b)

let merge_packages = merge [] List.append

let merge_install = merge Install.empty Install.union

let v ?packages ?packages_v ?install ?install_v ?(keys = []) ?(extra_deps = [])
Expand All @@ -107,17 +99,11 @@ let v ?packages ?packages_v ?install ?install_v ?(keys = []) ?(extra_deps = [])
}

let id t = Typeid.id t.id

let module_name t = t.module_name

let module_type t = t.module_type

let packages t = t.packages

let install t = t.install

let connect t = t.connect

let configure t = t.configure

let files t i =
Expand All @@ -127,16 +113,13 @@ let files t i =
| Some files -> Fpath.Set.(union gen (of_list (files i)))

let dune t = t.dune

let keys t = t.keys

let extra_deps t = t.extra_deps

let start impl_name args =
Fmt.str "@[%s.start@ %a@]" impl_name Fmt.(list ~sep:sp string) args

let uniq t = Fpath.Set.(elements (of_list t))

let exec_hook i = function None -> Action.ok () | Some h -> h i

let extend ?packages ?packages_v ?dune ?pre_configure ?post_configure ?files t =
Expand Down Expand Up @@ -180,7 +163,6 @@ module Graph = struct
type t = dtree

let hash (D t) = t.id

let equal (D t1) (D t2) = Int.equal t1.id t2.id
end)

Expand Down
6 changes: 0 additions & 6 deletions lib/functoria/dune.ml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@
open Astring

type stanza = string option

type t = string list

let stanza v = Some (String.trim v)

let stanzaf fmt = Fmt.kstr stanza fmt

let v x : t =
Expand All @@ -32,15 +30,12 @@ let v x : t =
[] (List.rev x)

let pp_list pp = Fmt.(list ~sep:(any "\n\n") pp)

let pp ppf (t : t) = Fmt.pf ppf "%a" (pp_list Fmt.string) t

let to_string t = Fmt.to_to_string pp t ^ "\n"

let headers ~name ~version =
let module M = Filegen.Make (struct
let name = name

let version = version
end) in
M.headers `Sexp
Expand Down Expand Up @@ -115,5 +110,4 @@ let base ~packages ~name ~version ~config_ml_file =
disable_duniverse :: dune_base

let base_project = [ stanza "(lang dune 2.7)" ]

let base_workspace = v [ stanza "(lang dune 2.0)\n(context default)" ]
Loading

0 comments on commit c57dff5

Please sign in to comment.