Skip to content
This repository has been archived by the owner on Aug 25, 2022. It is now read-only.

Commit

Permalink
minor tweaks: add build field to package, remve hardcoded ocamlfind a…
Browse files Browse the repository at this point in the history
…nd ocamlbuild from here
  • Loading branch information
hannesm committed Nov 20, 2016
1 parent 1a88cbf commit 07d29e9
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 28 deletions.
45 changes: 24 additions & 21 deletions lib/functoria.ml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ module Key = Functoria_key

type package = {
opam : string ;
build : bool ;
ocamlfind : String.Set.t ;
min : string option ;
max : string option
Expand Down Expand Up @@ -75,18 +76,19 @@ module Package = struct
in
match min, max with
| Some a, Some b when compare_version a b >= 0 -> invalid_arg "version constraint must be that min is smaller than max"
| _ -> Some { opam ; ocamlfind ; min ; max }
| _ -> Some { opam ; build = a.build ; ocamlfind ; min ; max }

let package ?sub ?ocamlfind ?min ?max opam =
let ocamlfind = match sub, ocamlfind with
| None, None -> String.Set.singleton opam
| Some a, None -> String.Set.of_list [ opam ; opam ^ "." ^ a ]
| None, Some a -> String.Set.of_list a
let package ?(build = false) ?sublibs ?ocamlfind ?min ?max opam =
let ocamlfind = match sublibs, ocamlfind with
| None, None -> [opam]
| Some xs, None -> opam :: List.map (fun x -> opam ^ "." ^ x) xs
| None, Some a -> a
| Some _, Some _ -> invalid_arg "only either ~sub or ~ocamlfind may be specified"
in
let ocamlfind = String.Set.of_list ocamlfind in
match min, max with
| Some min, Some max when compare_version min max >= 0 -> invalid_arg "min must be < max"
| _ -> { opam ; ocamlfind ; min ; max }
| _ -> { opam ; build ; ocamlfind ; min ; max }
end

let package = Package.package
Expand Down Expand Up @@ -124,18 +126,19 @@ module Info = struct
in
{ name; root; keys; packages; context }

let pp_constraint min max = match min, max with
| None, None -> ""
| Some a, None -> Printf.sprintf "{>=\"%s\"}" a
| None, Some b -> Printf.sprintf "{<\"%s\"}" b
| Some a, Some b -> Printf.sprintf "{>=\"%s\" & <\"%s\"}" a b
let exts_to_string min max build =
let bui = if build then "build & " else "" in
match min, max with
| None, None -> if build then "{build}" else ""
| Some a, None -> Printf.sprintf "{%s>=\"%s\"}" bui a
| None, Some b -> Printf.sprintf "{%s<\"%s\"}" bui b
| Some a, Some b -> Printf.sprintf "{%s>=\"%s\" & <\"%s\"}" bui a b

let pp_package t ppf p =
Fmt.pf ppf "%s%s%s@ %s" t p.opam t (pp_constraint p.min p.max)
Fmt.pf ppf "%s%s%s@ %s" t p.opam t (exts_to_string p.min p.max p.build)

let pp_packages tick ?sep ppf t =
let tick = if tick then "\"" else "" in
Fmt.pf ppf "%a" (Fmt.iter ?sep List.iter (pp_package tick)) (packages t)
let pp_packages ?(surround = "") ?sep ppf t =
Fmt.pf ppf "%a" (Fmt.iter ?sep List.iter (pp_package surround)) (packages t)

let pp verbose ppf ({ name ; root ; keys ; context ; _ } as t) =
let show name = Fmt.pf ppf "@[<2>%a@ %a@]@," Log.blue name in
Expand All @@ -144,16 +147,16 @@ module Info = struct
show "Root " Fmt.string root;
show "Keys " (Key.pps context) keys;
if verbose then show "Libraries " list (libraries t);
if verbose then show "Packages " (pp_packages false ~sep:(Fmt.unit ",@ ")) t
if verbose then
show "Packages "
(pp_packages ?surround:None ~sep:(Fmt.unit ",@ ")) t

let opam ?name ppf t =
let name = match name with None -> t.name | Some x -> x in
Fmt.pf ppf "opam-version: \"1.2\"@." ;
Fmt.pf ppf "name: \"%s\"@." name ;
Fmt.pf ppf "depends: [ @[<2>%s@ %s@ %a@]@ ]@,"
"\"ocamlbuild\" {build}"
"\"ocamlfind\" {build}"
(pp_packages true ~sep:(Fmt.unit "@ ")) t
Fmt.pf ppf "depends: [ @[<2>%a@]@ ]@."
(pp_packages ~surround:"\"" ~sep:(Fmt.unit "@ ")) t
end

type _ typ =
Expand Down
17 changes: 10 additions & 7 deletions lib/functoria.mli
Original file line number Diff line number Diff line change
Expand Up @@ -108,24 +108,27 @@ module type KEY = module type of struct include Functoria_key end

type package = private {
opam : string ;
build : bool ;
ocamlfind : Astring.String.Set.t ;
min : string option ;
max : string option
}
(** The type of a package *)

val package :
?sub:string ->
?build:bool ->
?sublibs:string list ->
?ocamlfind:string list ->
?min:string ->
?max:string ->
string -> package
(** [package ~sub ~ocamlfind ~min ~max opam] is a [package]. The ocamlfind name
is by default the same as [opam], you can specify [~sub] to add an
additional sublibrary (e.g. [~sub:"mirage" "foo"] will result in the findlib
names [ ["foo"; "foo.mirage"] ]. In case the findlib name is disjoint (or
empty), use [~ocamlfind]. Version constraints are given as [min]
(inclusive) and [max] (exclusive). *)
(** [package ~build ~sublibs ~ocamlfind ~min ~max opam] is a [package]. [Build]
indicates a build-time dependency only, defaults to [false]. The ocamlfind
name is by default the same as [opam], you can specify [~sublibs] to add
additional sublibraries (e.g. [~sublibs:["mirage"] "foo"] will result in the
findlib names [ ["foo"; "foo.mirage"] ]. In case the findlib name is
disjoint (or empty), use [~ocamlfind]. Version constraints are given as
[min] (inclusive) and [max] (exclusive). *)

(** {1:app Application Builder}
Expand Down

0 comments on commit 07d29e9

Please sign in to comment.