From dbb4963e9550ace3a7a9f5ad1337668579707ed2 Mon Sep 17 00:00:00 2001 From: andrewray Date: Mon, 22 May 2017 17:03:37 +0100 Subject: [PATCH 01/46] almost working ppx for jbuilder; just cant get linkall to apply... --- _oasis | 7 +- myocamlbuild.ml | 3 + src/ppx/ppx_lwt.ml | 3 +- src/ppx/ppx_lwt_ex.ml | 376 +--------------------------------------- src/ppx/ppx_lwt_int.ml | 380 +++++++++++++++++++++++++++++++++++++++++ 5 files changed, 392 insertions(+), 377 deletions(-) create mode 100644 src/ppx/ppx_lwt_int.ml diff --git a/_oasis b/_oasis index 74d7a90860..43b2256997 100644 --- a/_oasis +++ b/_oasis @@ -288,9 +288,10 @@ Library "ppx" FindlibName: ppx FindlibParent: lwt Path: src/ppx - Modules: Ppx_lwt + Modules: Ppx_lwt_int, Ppx_lwt + BuildDepends: compiler-libs.common, ppx_tools_versioned, ppx_tools_versioned.metaquot_404, ocaml-migrate-parsetree XMETADescription: Lwt PPX syntax extension - XMETARequires: lwt + XMETARequires: lwt, ppx_tools_versioned, ocaml-migrate-parsetree XMETAExtraLines: ppx = "ppx_lwt" Executable "ppx_lwt" @@ -298,7 +299,7 @@ Executable "ppx_lwt" Install$: flag(ppx) || flag(all) Path: src/ppx MainIs: ppx_lwt_ex.ml - BuildDepends: compiler-libs.common, ppx_tools.metaquot + BuildDepends: compiler-libs.common, ppx_tools_versioned, ppx_tools_versioned.metaquot_404, ocaml-migrate-parsetree CompiledObject: best # +-------------------------------------------------------------------+ diff --git a/myocamlbuild.ml b/myocamlbuild.ml index 35dce3e88d..fad524aa44 100644 --- a/myocamlbuild.ml +++ b/myocamlbuild.ml @@ -117,6 +117,9 @@ let () = dispatch begin fun hook -> flag ["ocaml"; "compile"; "ppx_lwt"] & S [A "-ppx"; A ("src/ppx/ppx_lwt_ex." ^ native_suffix)]; + (*tag_file "src/ppx/ppx.cmxa" ["linkme"]; + flag ["linkme"] & S[A"-linkall"];*) + (* Use an introduction page with categories *) tag_file "lwt-api.docdir/index.html" ["apiref"]; dep ["apiref"] ["doc/apiref-intro"]; diff --git a/src/ppx/ppx_lwt.ml b/src/ppx/ppx_lwt.ml index 3fe087d259..ebdb9d303a 100644 --- a/src/ppx/ppx_lwt.ml +++ b/src/ppx/ppx_lwt.ml @@ -1 +1,2 @@ -(* Dummy ML file to workaround https://github.com/ocsigen/lwt/issues/91 *) + +let () = Ppx_lwt_int.register () diff --git a/src/ppx/ppx_lwt_ex.ml b/src/ppx/ppx_lwt_ex.ml index fc8132828d..33292e82ec 100644 --- a/src/ppx/ppx_lwt_ex.ml +++ b/src/ppx/ppx_lwt_ex.ml @@ -1,373 +1,3 @@ -open Ast_mapper -open Ast_helper -open Asttypes -open Parsetree - -open Ast_convenience - -(** {2 Convenient stuff} *) - -let with_loc f {txt ; loc = _loc} = - (f txt) [@metaloc _loc] - -let def_loc txt = - { txt; loc = !default_loc } - -(** Test if a case is a catchall. *) -let is_catchall case = - let rec is_catchall_pat p = match p.ppat_desc with - | Ppat_any | Ppat_var _ -> true - | Ppat_alias (p, _) -> is_catchall_pat p - | _ -> false - in - case.pc_guard = None && is_catchall_pat case.pc_lhs - -(** Add a wildcard case in there is none. Useful for exception handlers. *) -let add_wildcard_case cases = - let has_wildcard = - List.exists is_catchall cases - in - if not has_wildcard - then cases @ [Exp.case [%pat? exn] [%expr Lwt.fail exn]] - else cases - -(** {3 Internal names} *) - -let lwt_prefix = "__ppx_lwt_" - -(** {2 Here we go!} *) - -let warn_let_lwt_rec loc attrs = - let attr = attribute_of_warning loc "\"let%lwt rec\" is not a recursive Lwt binding" in - attr :: attrs - -let debug = ref true -let log = ref false -let sequence = ref true -let strict_seq = ref true - -(** let%lwt related functions *) - -let gen_name i = lwt_prefix ^ string_of_int i - -(** [p = x] ≡ [__ppx_lwt_$i = x] *) -let gen_bindings l = - let aux i binding = - { binding with - pvb_pat = (pvar (gen_name i)) [@metaloc binding.pvb_expr.pexp_loc] - } - in - List.mapi aux l - -(** [p = x] and e ≡ [Lwt.bind __ppx_lwt_$i (fun p -> e)] *) -let gen_binds e_loc l e = - let rec aux i bindings = - match bindings with - | [] -> e - | binding :: t -> - let name = (* __ppx_lwt_$i, at the position of $x$ *) - (evar (gen_name i)) [@metaloc binding.pvb_expr.pexp_loc] - in - let fun_ = - [%expr (fun [%p binding.pvb_pat] -> [%e aux (i+1) t])] [@metaloc binding.pvb_loc] - in - let new_exp = - if !debug then - [%expr Lwt.backtrace_bind (fun exn -> try raise exn with exn -> exn) - [%e name] [%e fun_]] [@metaloc e_loc] - else - [%expr Lwt.bind [%e name] [%e fun_]] [@metaloc e_loc] - in - { new_exp with pexp_attributes = binding.pvb_attributes } - in aux 0 l - -(** [p = x and p' = x' and ...] ≡ - [p, p', ... = Lwt_main.run ( - Lwt.bind x (fun __ppx_lwt_$i -> - Lwt.bind x' (fun __ppx_lwt_$i' -> - ... - Lwt.return (__ppx_lwt_$i, __ppx_lwt_$i', ...))))] *) - -let gen_top_binds vbs = - let gen_exp vbs i = - match vbs with - | {pvb_expr; _}::_rest -> - if !debug then - [%expr Lwt.backtrace_bind (fun exn -> try raise exn with exn -> exn) - [%e pvb_expr] (fun [%p pvar (gen_name i)] -> gen_exp _rest (i + 1))] - else - [%expr Lwt.bind [%e pvb_expr] (fun [%p pvar (gen_name i)] -> gen_exp rest (i + 1))] - | [] -> - let rec names i = - if i >= 0 then evar (gen_name i) :: names (i - 1) else [] - in Exp.tuple (names i) - in - [Vb.mk (Pat.tuple (vbs |> List.map (fun { pvb_pat; _ } -> pvb_pat))) - [%expr Lwt_main.run [%e gen_exp vbs 0]]] - -(** For expressions only *) -(* We only expand the first level after a %lwt. - After that, we call the mapper to expand sub-expressions. *) -let lwt_expression mapper exp attributes = - default_loc := exp.pexp_loc; - let pexp_attributes = attributes @ exp.pexp_attributes in - match exp.pexp_desc with - - (* [let%lwt $p$ = $e$ in $e'$] ≡ [Lwt.bind $e$ (fun $p$ -> $e'$)] *) - | Pexp_let (Nonrecursive, vbl , e) -> - let new_exp = - Exp.let_ - Nonrecursive - (gen_bindings vbl) - (gen_binds exp.pexp_loc vbl e) - in mapper.expr mapper { new_exp with pexp_attributes } - - (* [match%lwt $e$ with $c$] ≡ [Lwt.bind $e$ (function $c$)] - [match%lwt $e$ with exception $x$ | $c$] ≡ - [Lwt.try_bind (fun () -> $e$) (function $c$) (function $x$)] *) - | Pexp_match (e, cases) -> - let exns, cases = - cases |> List.partition ( - function - | {pc_lhs = [%pat? exception [%p? _]]; _} -> true - | _ -> false) - in - let exns = - exns |> List.map ( - function - | {pc_lhs = [%pat? exception [%p? pat]]; _} as case -> - { case with pc_lhs = pat } - | _ -> assert false) - in - let exns = add_wildcard_case exns in - let new_exp = - match exns with - | [] -> [%expr Lwt.bind [%e e] [%e Exp.function_ cases]] - | _ -> [%expr Lwt.try_bind (fun () -> [%e e]) - [%e Exp.function_ cases] [%e Exp.function_ exns]] - in - mapper.expr mapper { new_exp with pexp_attributes } - - (* [assert%lwt $e$] ≡ - [try Lwt.return (assert $e$) with exn -> Lwt.fail exn] *) - | Pexp_assert e -> - let new_exp = - [%expr try Lwt.return (assert [%e e]) with exn -> Lwt.fail exn] - in mapper.expr mapper { new_exp with pexp_attributes } - - (* [while%lwt $cond$ do $body$ done] ≡ - [let rec __ppx_lwt_loop () = - if $cond$ then Lwt.bind $body$ __ppx_lwt_loop - else Lwt.return_unit - in __ppx_lwt_loop] - *) - | Pexp_while (cond, body) -> - let new_exp = - [%expr - let rec __ppx_lwt_loop () = - if [%e cond] then Lwt.bind [%e body] __ppx_lwt_loop - else Lwt.return_unit - in __ppx_lwt_loop () - ] - in mapper.expr mapper { new_exp with pexp_attributes } - - (* [for%lwt $p$ = $start$ (to|downto) $end$ do $body$ done] ≡ - [let __ppx_lwt_bound = $end$ in - let rec __ppx_lwt_loop $p$ = - if $p$ COMP __ppx_lwt_bound then Lwt.return_unit - else Lwt.bind $body$ (fun () -> __ppx_lwt_loop ($p$ OP 1)) - in __ppx_lwt_loop $start$] - *) - | Pexp_for ({ppat_desc = Ppat_var p_var; _} as p, start, bound, dir, body) -> - let comp, op = match dir with - | Upto -> evar ">", evar "+" - | Downto -> evar "<", evar "-" - in - let p' = with_loc (fun s -> evar s) p_var in - - let exp_bound = [%expr __ppx_lwt_bound] [@metaloc bound.pexp_loc] in - let pat_bound = [%pat? __ppx_lwt_bound] [@metaloc bound.pexp_loc] in - - let new_exp = - [%expr - let [%p pat_bound] : int = [%e bound] in - let rec __ppx_lwt_loop [%p p] = - if [%e comp] [%e p'] [%e exp_bound] then Lwt.return_unit - else Lwt.bind [%e body] (fun () -> __ppx_lwt_loop ([%e op] [%e p'] 1)) - in __ppx_lwt_loop [%e start] - ] - in mapper.expr mapper { new_exp with pexp_attributes } - - - (* [try%lwt $e$ with $c$] ≡ - [Lwt.catch (fun () -> $e$) (function $c$)] - *) - | Pexp_try (expr, cases) -> - let cases = add_wildcard_case cases in - let new_exp = - if !debug then - [%expr Lwt.backtrace_catch (fun exn -> try raise exn with exn -> exn) - (fun () -> [%e expr]) [%e Exp.function_ cases]] - else - [%expr Lwt.catch (fun () -> [%e expr]) [%e Exp.function_ cases]] - in - mapper.expr mapper { new_exp with pexp_attributes } - - (* [if%lwt $c$ then $e1$ else $e2$] ≡ - [match%lwt $c$ with true -> $e1$ | false -> $e2$] - [if%lwt $c$ then $e1$] ≡ - [match%lwt $c$ with true -> $e1$ | false -> Lwt.return_unit] - *) - | Pexp_ifthenelse (cond, e1, e2) -> - let e2 = match e2 with None -> [%expr Lwt.return_unit] | Some e -> e in - let cases = - [ - Exp.case [%pat? true] e1 ; - Exp.case [%pat? false] e2 ; - ] - in - let new_exp = [%expr Lwt.bind [%e cond] [%e Exp.function_ cases]] in - mapper.expr mapper { new_exp with pexp_attributes } - - (* [[%lwt $e$]] ≡ [Lwt.catch (fun () -> $e$) Lwt.fail] *) - | _ -> - let exp = - match exp with - | { pexp_loc; pexp_desc=Pexp_let (Recursive, _, _); pexp_attributes } -> - let attr = attribute_of_warning pexp_loc "\"let%lwt rec\" is not a recursive Lwt binding" in - { exp with pexp_attributes = attr :: pexp_attributes } - | _ -> exp - in - let new_exp = - if !debug then - [%expr Lwt.backtrace_catch (fun exn -> try raise exn with exn -> exn) - (fun () -> [%e exp]) Lwt.fail] - else - [%expr Lwt.catch (fun () -> [%e exp]) Lwt.fail] - in - mapper.expr mapper { new_exp with pexp_attributes } - -let make_loc {Location.loc_start; _} = - let (file, line, char) = Location.get_pos_info loc_start in - [%expr ([%e str file], [%e int line], [%e int char])] - -(** - [Lwt_log.error "message"] ≡ - [let __pa_log_section = Lwt_log.Section.main in - if Lwt_log.Error >= (Lwt_log.Section.level __pa_log_section) - then Lwt_log.error ~location:("foo.ml", 1, 0) ~section:__pa_log_section "message" - else Lwt.return_unit]; - [Lwt_log.error ~section "message"] ≡ - [let __pa_log_section = section in ...]. - Additionally, remove debug-level statements if -no-debug is given. **) -let lwt_log mapper fn args attrs loc = - let open Longident in - match fn with - | {pexp_desc = Pexp_ident {txt = Ldot (Lident "Lwt_log", func); _}; _} -> - let len = String.length func in - let fmt = len >= 2 && func.[len - 2] = '_' && func.[len - 1] = 'f' - and ign = len >= 4 && func.[0] = 'i' && func.[1] = 'g' && func.[2] = 'n' && func.[3] = '_' in - let level = - match fmt, ign with - | false, false -> func - | true, false -> String.sub func 0 (len - 2) - | false, true -> String.sub func 4 (len - 4) - | true, true -> String.sub func 4 (len - 6) - in - let level = (String.capitalize [@ocaml.warning "-3"]) level in - if level = "Debug" && (not !debug) then - let new_exp = if ign then [%expr ()] else [%expr Lwt.return_unit] in - mapper.expr mapper { new_exp with pexp_attributes = attrs } - else if List.mem level ["Fatal"; "Error"; "Warning"; "Notice"; "Info"; "Debug"] then - let args = List.map (fun (l,e) -> l, mapper.expr mapper e) args in - let new_exp = - let args = (Label.labelled "location", make_loc loc) :: - (Label.labelled "section", [%expr __pa_log_section]) :: - List.remove_assoc (Label.labelled "section") args in - [%expr - if [%e Exp.construct (def_loc (Ldot (Lident "Lwt_log", level))) None] >= - Lwt_log.Section.level __pa_log_section then - [%e Exp.apply (Exp.ident (def_loc (Ldot (Lident "Lwt_log", func)))) args] - else - [%e if ign then [%expr ()] else [%expr Lwt.return_unit]]] - in - try - let section = List.assoc (Label.labelled "section") args in - [%expr let __pa_log_section = [%e section] in [%e new_exp]] - with Not_found -> - [%expr let __pa_log_section = Lwt_log.Section.main in [%e new_exp]] - else default_mapper.expr mapper (Exp.apply ~attrs fn args) - | _ -> default_mapper.expr mapper (Exp.apply ~attrs fn args) - -let lwt_mapper args = - args |> List.iter (fun arg -> - match arg with - | "-no-debug" -> debug := false - | "-log" -> log := true - | "-no-log" -> log := false - | "-no-sequence" -> sequence := false - | "-no-strict-sequence" -> strict_seq := false - | _ -> raise (Location.Error (Location.errorf "Unknown lwt.ppx argument: %s" arg))); - { default_mapper with - expr = (fun mapper expr -> - match expr with - | [%expr [%lwt [%e? exp]]] -> - lwt_expression mapper exp expr.pexp_attributes - - - (* [($e$)[%finally $f$]] ≡ - [Lwt.finalize (fun () -> $e$) (fun () -> $f$)] *) - | [%expr [%e? exp ] [%finally [%e? finally]] ] - | [%expr [%e? exp ] [%lwt.finally [%e? finally]] ] -> - let new_exp = - if !debug then - [%expr Lwt.backtrace_finalize (fun exn -> try raise exn with exn -> exn) - (fun () -> [%e exp]) (fun () -> [%e finally])] - else - [%expr Lwt.finalize (fun () -> [%e exp]) (fun () -> [%e finally])] - in - mapper.expr mapper - { new_exp with - pexp_attributes = expr.pexp_attributes @ exp.pexp_attributes - } - - | [%expr [%finally [%e? _ ]]] - | [%expr [%lwt.finally [%e? _ ]]] -> - raise (Location.Error ( - Location.errorf - ~loc:expr.pexp_loc - "Lwt's finally should be used only with the syntax: \"()[%%finally ...]\"." - )) - - - | [%expr [%e? lhs] >> [%e? rhs]] -> - if !sequence then - let pat = if !strict_seq then [%pat? ()] else [%pat? _] in - let lhs, rhs = mapper.expr mapper lhs, mapper.expr mapper rhs in - if !debug then - [%expr Lwt.backtrace_bind (fun exn -> try raise exn with exn -> exn) - [%e lhs] (fun [%p pat] -> [%e rhs])] - else - [%expr Lwt.bind [%e lhs] (fun [%p pat] -> [%e rhs])] - else - default_mapper.expr mapper expr - | { pexp_desc = Pexp_apply (fn, args); pexp_attributes; pexp_loc } when !log -> - default_loc := pexp_loc; - lwt_log mapper fn args pexp_attributes pexp_loc - | _ -> default_mapper.expr mapper expr); - structure_item = (fun mapper stri -> - default_loc := stri.pstr_loc; - match stri with - | [%stri let%lwt [%p? var] = [%e? exp]] -> - [%stri let [%p var] = Lwt_main.run [%e mapper.expr mapper exp]] - | {pstr_desc = Pstr_extension (({txt = "lwt"; _}, PStr [ - {pstr_desc = Pstr_value (Recursive, _); _}]) as content, attrs); pstr_loc} -> - {stri with pstr_desc = - Pstr_extension (content, warn_let_lwt_rec pstr_loc attrs)} - | {pstr_desc = Pstr_extension (({txt = "lwt"; _}, PStr [ - {pstr_desc = Pstr_value (Nonrecursive, vbs); _}]), _); _} -> - mapper.structure_item mapper (Str.value Nonrecursive (gen_top_binds vbs)) - | x -> default_mapper.structure_item mapper x); - } - -let () = run_main lwt_mapper +let () = + Ppx_lwt_int.register (); + Migrate_parsetree.Driver.run_as_ppx_rewriter () diff --git a/src/ppx/ppx_lwt_int.ml b/src/ppx/ppx_lwt_int.ml new file mode 100644 index 0000000000..4e4aec3585 --- /dev/null +++ b/src/ppx/ppx_lwt_int.ml @@ -0,0 +1,380 @@ +open Migrate_parsetree +open Ast_mapper +open Ast_helper +open Asttypes +open Parsetree + +open Ast_convenience_404 + +(** {2 Convenient stuff} *) + +let with_loc f {txt ; loc = _loc} = + (f txt) [@metaloc _loc] + +let def_loc txt = + { txt; loc = !default_loc } + +(** Test if a case is a catchall. *) +let is_catchall case = + let rec is_catchall_pat p = match p.ppat_desc with + | Ppat_any | Ppat_var _ -> true + | Ppat_alias (p, _) -> is_catchall_pat p + | _ -> false + in + case.pc_guard = None && is_catchall_pat case.pc_lhs + +(** Add a wildcard case in there is none. Useful for exception handlers. *) +let add_wildcard_case cases = + let has_wildcard = + List.exists is_catchall cases + in + if not has_wildcard + then cases @ [Exp.case [%pat? exn] [%expr Lwt.fail exn]] + else cases + +(** {3 Internal names} *) + +let lwt_prefix = "__ppx_lwt_" + +(** {2 Here we go!} *) + +let warn_let_lwt_rec loc attrs = + let attr = attribute_of_warning loc "\"let%lwt rec\" is not a recursive Lwt binding" in + attr :: attrs + +let debug = ref true +let log = ref false +let sequence = ref true +let strict_seq = ref true + +(** let%lwt related functions *) + +let gen_name i = lwt_prefix ^ string_of_int i + +(** [p = x] ≡ [__ppx_lwt_$i = x] *) +let gen_bindings l = + let aux i binding = + { binding with + pvb_pat = (pvar (gen_name i)) [@metaloc binding.pvb_expr.pexp_loc] + } + in + List.mapi aux l + +(** [p = x] and e ≡ [Lwt.bind __ppx_lwt_$i (fun p -> e)] *) +let gen_binds e_loc l e = + let rec aux i bindings = + match bindings with + | [] -> e + | binding :: t -> + let name = (* __ppx_lwt_$i, at the position of $x$ *) + (evar (gen_name i)) [@metaloc binding.pvb_expr.pexp_loc] + in + let fun_ = + [%expr (fun [%p binding.pvb_pat] -> [%e aux (i+1) t])] [@metaloc binding.pvb_loc] + in + let new_exp = + if !debug then + [%expr Lwt.backtrace_bind (fun exn -> try raise exn with exn -> exn) + [%e name] [%e fun_]] [@metaloc e_loc] + else + [%expr Lwt.bind [%e name] [%e fun_]] [@metaloc e_loc] + in + { new_exp with pexp_attributes = binding.pvb_attributes } + in aux 0 l + +(** [p = x and p' = x' and ...] ≡ + [p, p', ... = Lwt_main.run ( + Lwt.bind x (fun __ppx_lwt_$i -> + Lwt.bind x' (fun __ppx_lwt_$i' -> + ... + Lwt.return (__ppx_lwt_$i, __ppx_lwt_$i', ...))))] *) + +let gen_top_binds vbs = + let gen_exp vbs i = + match vbs with + | {pvb_expr; _}::_rest -> + if !debug then + [%expr Lwt.backtrace_bind (fun exn -> try raise exn with exn -> exn) + [%e pvb_expr] (fun [%p pvar (gen_name i)] -> gen_exp _rest (i + 1))] + else + [%expr Lwt.bind [%e pvb_expr] (fun [%p pvar (gen_name i)] -> gen_exp rest (i + 1))] + | [] -> + let rec names i = + if i >= 0 then evar (gen_name i) :: names (i - 1) else [] + in Exp.tuple (names i) + in + [Vb.mk (Pat.tuple (vbs |> List.map (fun { pvb_pat; _ } -> pvb_pat))) + [%expr Lwt_main.run [%e gen_exp vbs 0]]] + +(** For expressions only *) +(* We only expand the first level after a %lwt. + After that, we call the mapper to expand sub-expressions. *) +let lwt_expression mapper exp attributes = + default_loc := exp.pexp_loc; + let pexp_attributes = attributes @ exp.pexp_attributes in + match exp.pexp_desc with + + (* [let%lwt $p$ = $e$ in $e'$] ≡ [Lwt.bind $e$ (fun $p$ -> $e'$)] *) + | Pexp_let (Nonrecursive, vbl , e) -> + let new_exp = + Exp.let_ + Nonrecursive + (gen_bindings vbl) + (gen_binds exp.pexp_loc vbl e) + in mapper.expr mapper { new_exp with pexp_attributes } + + (* [match%lwt $e$ with $c$] ≡ [Lwt.bind $e$ (function $c$)] + [match%lwt $e$ with exception $x$ | $c$] ≡ + [Lwt.try_bind (fun () -> $e$) (function $c$) (function $x$)] *) + | Pexp_match (e, cases) -> + let exns, cases = + cases |> List.partition ( + function + | {pc_lhs = [%pat? exception [%p? _]]; _} -> true + | _ -> false) + in + let exns = + exns |> List.map ( + function + | {pc_lhs = [%pat? exception [%p? pat]]; _} as case -> + { case with pc_lhs = pat } + | _ -> assert false) + in + let exns = add_wildcard_case exns in + let new_exp = + match exns with + | [] -> [%expr Lwt.bind [%e e] [%e Exp.function_ cases]] + | _ -> [%expr Lwt.try_bind (fun () -> [%e e]) + [%e Exp.function_ cases] [%e Exp.function_ exns]] + in + mapper.expr mapper { new_exp with pexp_attributes } + + (* [assert%lwt $e$] ≡ + [try Lwt.return (assert $e$) with exn -> Lwt.fail exn] *) + | Pexp_assert e -> + let new_exp = + [%expr try Lwt.return (assert [%e e]) with exn -> Lwt.fail exn] + in mapper.expr mapper { new_exp with pexp_attributes } + + (* [while%lwt $cond$ do $body$ done] ≡ + [let rec __ppx_lwt_loop () = + if $cond$ then Lwt.bind $body$ __ppx_lwt_loop + else Lwt.return_unit + in __ppx_lwt_loop] + *) + | Pexp_while (cond, body) -> + let new_exp = + [%expr + let rec __ppx_lwt_loop () = + if [%e cond] then Lwt.bind [%e body] __ppx_lwt_loop + else Lwt.return_unit + in __ppx_lwt_loop () + ] + in mapper.expr mapper { new_exp with pexp_attributes } + + (* [for%lwt $p$ = $start$ (to|downto) $end$ do $body$ done] ≡ + [let __ppx_lwt_bound = $end$ in + let rec __ppx_lwt_loop $p$ = + if $p$ COMP __ppx_lwt_bound then Lwt.return_unit + else Lwt.bind $body$ (fun () -> __ppx_lwt_loop ($p$ OP 1)) + in __ppx_lwt_loop $start$] + *) + | Pexp_for ({ppat_desc = Ppat_var p_var; _} as p, start, bound, dir, body) -> + let comp, op = match dir with + | Upto -> evar ">", evar "+" + | Downto -> evar "<", evar "-" + in + let p' = with_loc (fun s -> evar s) p_var in + + let exp_bound = [%expr __ppx_lwt_bound] [@metaloc bound.pexp_loc] in + let pat_bound = [%pat? __ppx_lwt_bound] [@metaloc bound.pexp_loc] in + + let new_exp = + [%expr + let [%p pat_bound] : int = [%e bound] in + let rec __ppx_lwt_loop [%p p] = + if [%e comp] [%e p'] [%e exp_bound] then Lwt.return_unit + else Lwt.bind [%e body] (fun () -> __ppx_lwt_loop ([%e op] [%e p'] 1)) + in __ppx_lwt_loop [%e start] + ] + in mapper.expr mapper { new_exp with pexp_attributes } + + + (* [try%lwt $e$ with $c$] ≡ + [Lwt.catch (fun () -> $e$) (function $c$)] + *) + | Pexp_try (expr, cases) -> + let cases = add_wildcard_case cases in + let new_exp = + if !debug then + [%expr Lwt.backtrace_catch (fun exn -> try raise exn with exn -> exn) + (fun () -> [%e expr]) [%e Exp.function_ cases]] + else + [%expr Lwt.catch (fun () -> [%e expr]) [%e Exp.function_ cases]] + in + mapper.expr mapper { new_exp with pexp_attributes } + + (* [if%lwt $c$ then $e1$ else $e2$] ≡ + [match%lwt $c$ with true -> $e1$ | false -> $e2$] + [if%lwt $c$ then $e1$] ≡ + [match%lwt $c$ with true -> $e1$ | false -> Lwt.return_unit] + *) + | Pexp_ifthenelse (cond, e1, e2) -> + let e2 = match e2 with None -> [%expr Lwt.return_unit] | Some e -> e in + let cases = + [ + Exp.case [%pat? true] e1 ; + Exp.case [%pat? false] e2 ; + ] + in + let new_exp = [%expr Lwt.bind [%e cond] [%e Exp.function_ cases]] in + mapper.expr mapper { new_exp with pexp_attributes } + + (* [[%lwt $e$]] ≡ [Lwt.catch (fun () -> $e$) Lwt.fail] *) + | _ -> + let exp = + match exp with + | { pexp_loc; pexp_desc=Pexp_let (Recursive, _, _); pexp_attributes } -> + let attr = attribute_of_warning pexp_loc "\"let%lwt rec\" is not a recursive Lwt binding" in + { exp with pexp_attributes = attr :: pexp_attributes } + | _ -> exp + in + let new_exp = + if !debug then + [%expr Lwt.backtrace_catch (fun exn -> try raise exn with exn -> exn) + (fun () -> [%e exp]) Lwt.fail] + else + [%expr Lwt.catch (fun () -> [%e exp]) Lwt.fail] + in + mapper.expr mapper { new_exp with pexp_attributes } + +let make_loc {Location.loc_start; _} = + let (file, line, char) = Location.get_pos_info loc_start in + [%expr ([%e str file], [%e int line], [%e int char])] + +(** + [Lwt_log.error "message"] ≡ + [let __pa_log_section = Lwt_log.Section.main in + if Lwt_log.Error >= (Lwt_log.Section.level __pa_log_section) + then Lwt_log.error ~location:("foo.ml", 1, 0) ~section:__pa_log_section "message" + else Lwt.return_unit]; + [Lwt_log.error ~section "message"] ≡ + [let __pa_log_section = section in ...]. + Additionally, remove debug-level statements if -no-debug is given. **) +let lwt_log mapper fn args attrs loc = + let open Longident in + match fn with + | {pexp_desc = Pexp_ident {txt = Ldot (Lident "Lwt_log", func); _}; _} -> + let len = String.length func in + let fmt = len >= 2 && func.[len - 2] = '_' && func.[len - 1] = 'f' + and ign = len >= 4 && func.[0] = 'i' && func.[1] = 'g' && func.[2] = 'n' && func.[3] = '_' in + let level = + match fmt, ign with + | false, false -> func + | true, false -> String.sub func 0 (len - 2) + | false, true -> String.sub func 4 (len - 4) + | true, true -> String.sub func 4 (len - 6) + in + let level = (String.capitalize [@ocaml.warning "-3"]) level in + if level = "Debug" && (not !debug) then + let new_exp = if ign then [%expr ()] else [%expr Lwt.return_unit] in + mapper.expr mapper { new_exp with pexp_attributes = attrs } + else if List.mem level ["Fatal"; "Error"; "Warning"; "Notice"; "Info"; "Debug"] then + let args = List.map (fun (l,e) -> l, mapper.expr mapper e) args in + let new_exp = + let args = (Label.labelled "location", make_loc loc) :: + (Label.labelled "section", [%expr __pa_log_section]) :: + List.remove_assoc (Label.labelled "section") args in + [%expr + if [%e Exp.construct (def_loc (Ldot (Lident "Lwt_log", level))) None] >= + Lwt_log.Section.level __pa_log_section then + [%e Exp.apply (Exp.ident (def_loc (Ldot (Lident "Lwt_log", func)))) args] + else + [%e if ign then [%expr ()] else [%expr Lwt.return_unit]]] + in + try + let section = List.assoc (Label.labelled "section") args in + [%expr let __pa_log_section = [%e section] in [%e new_exp]] + with Not_found -> + [%expr let __pa_log_section = Lwt_log.Section.main in [%e new_exp]] + else default_mapper.expr mapper (Exp.apply ~attrs fn args) + | _ -> default_mapper.expr mapper (Exp.apply ~attrs fn args) + +let lwt_mapper () = + { default_mapper with + expr = (fun mapper expr -> + match expr with + | [%expr [%lwt [%e? exp]]] -> + lwt_expression mapper exp expr.pexp_attributes + + + (* [($e$)[%finally $f$]] ≡ + [Lwt.finalize (fun () -> $e$) (fun () -> $f$)] *) + | [%expr [%e? exp ] [%finally [%e? finally]] ] + | [%expr [%e? exp ] [%lwt.finally [%e? finally]] ] -> + let new_exp = + if !debug then + [%expr Lwt.backtrace_finalize (fun exn -> try raise exn with exn -> exn) + (fun () -> [%e exp]) (fun () -> [%e finally])] + else + [%expr Lwt.finalize (fun () -> [%e exp]) (fun () -> [%e finally])] + in + mapper.expr mapper + { new_exp with + pexp_attributes = expr.pexp_attributes @ exp.pexp_attributes + } + + | [%expr [%finally [%e? _ ]]] + | [%expr [%lwt.finally [%e? _ ]]] -> + raise (Location.Error ( + Location.errorf + ~loc:expr.pexp_loc + "Lwt's finally should be used only with the syntax: \"()[%%finally ...]\"." + )) + + + | [%expr [%e? lhs] >> [%e? rhs]] -> + if !sequence then + let pat = if !strict_seq then [%pat? ()] else [%pat? _] in + let lhs, rhs = mapper.expr mapper lhs, mapper.expr mapper rhs in + if !debug then + [%expr Lwt.backtrace_bind (fun exn -> try raise exn with exn -> exn) + [%e lhs] (fun [%p pat] -> [%e rhs])] + else + [%expr Lwt.bind [%e lhs] (fun [%p pat] -> [%e rhs])] + else + default_mapper.expr mapper expr + | { pexp_desc = Pexp_apply (fn, args); pexp_attributes; pexp_loc } when !log -> + default_loc := pexp_loc; + lwt_log mapper fn args pexp_attributes pexp_loc + | _ -> default_mapper.expr mapper expr); + structure_item = (fun mapper stri -> + default_loc := stri.pstr_loc; + match stri with + | [%stri let%lwt [%p? var] = [%e? exp]] -> + [%stri let [%p var] = Lwt_main.run [%e mapper.expr mapper exp]] + | {pstr_desc = Pstr_extension (({txt = "lwt"; _}, PStr [ + {pstr_desc = Pstr_value (Recursive, _); _}]) as content, attrs); pstr_loc} -> + {stri with pstr_desc = + Pstr_extension (content, warn_let_lwt_rec pstr_loc attrs)} + | {pstr_desc = Pstr_extension (({txt = "lwt"; _}, PStr [ + {pstr_desc = Pstr_value (Nonrecursive, vbs); _}]), _); _} -> + mapper.structure_item mapper (Str.value Nonrecursive (gen_top_binds vbs)) + | x -> default_mapper.structure_item mapper x); + } + + +let args = + Arg.([ + "-no-debug", Clear debug, "disable debug mode"; + "-log", Set log, "enable logging"; + "-no-log", Clear log, "disable logging"; + "-no-sequence", Clear sequence, "disable sequence operator"; + "-no-strict-sequence", Clear strict_seq, "allow non-unit sequence operations"; + ]) + +let register () = + Driver.register ~name:"ppx_lwt" ~args Versions.ocaml_404 + (fun _config _cookies -> lwt_mapper ()) + + From 0fa50d2d3ceb830fc735a85d4f05cdf0548dd275 Mon Sep 17 00:00:00 2001 From: andrewray Date: Mon, 22 May 2017 17:08:04 +0100 Subject: [PATCH 02/46] magic cmxs ocamlbuild rule courtest @jdimino fixes the linkall issue on the ppx --- _tags | 2 ++ myocamlbuild.ml | 13 +++++++++++++ 2 files changed, 15 insertions(+) diff --git a/_tags b/_tags index 6f37a509a9..b9399e0da0 100644 --- a/_tags +++ b/_tags @@ -29,5 +29,7 @@ not : safe_string # Scratch directory "scratch": -traverse +: linkall + # OASIS_START # OASIS_STOP diff --git a/myocamlbuild.ml b/myocamlbuild.ml index fad524aa44..2068c60424 100644 --- a/myocamlbuild.ml +++ b/myocamlbuild.ml @@ -143,6 +143,19 @@ let () = dispatch begin fun hook -> conditional_warnings_as_errors (); + rule "Generate a cmxs from a cmxa" + ~dep:"%.cmxa" + ~prod:"%.cmxs" + ~insert:`top + (fun env _ -> + Cmd (S [ !Options.ocamlopt + ; A "-shared" + ; A "-linkall" + ; A "-I"; A (Pathname.dirname (env "%")) + ; A (env "%.cmxa") + ; A "-o" + ; A (env "%.cmxs") + ])) | _ -> () end From 68b161f92d3da8665c80849868acc71df586b420 Mon Sep 17 00:00:00 2001 From: andrewray Date: Tue, 23 May 2017 01:49:48 +0100 Subject: [PATCH 03/46] 1st pass at jbuilder --- .gitignore | 4 + Makefile | 8 +- opam/descr => descr | 0 doc/examples/gtk/jbuild | 6 + doc/examples/unix/jbuild | 7 + jbuild | 13 + lwt.opam | 59 ++ opam/files/lwt.install | 6 - opam/opam | 66 -- src/camlp4/jbuild | 23 + src/core/jbuild | 7 + src/glib/config/discover.ml | 24 + src/glib/config/jbuild | 5 + src/glib/jbuild | 20 + src/glib/myocamlbuild.ml | 83 -- src/logger/jbuild | 9 + src/ppx/.merlin | 12 +- src/ppx/jbuild | 15 + src/ppx/ppx_lwt.ml | 380 ++++++++- src/ppx/ppx_lwt.mli | 4 + src/ppx/ppx_lwt_ex.ml | 3 - src/ppx/ppx_lwt_int.ml | 380 --------- src/preemptive/jbuild | 8 + src/react/jbuild | 8 + src/simple_top/jbuild | 8 + src/ssl/jbuild | 8 + src/unix/config/discover.ml | 799 ++++++++++++++++++ src/unix/config/jbuild | 5 + src/unix/jbuild | 112 +++ src/unix/lwt_unix_stubs.c | 4 +- src/unix/{lwt_unix_unix.c => lwt_unix_unix.h} | 0 ...{lwt_unix_windows.c => lwt_unix_windows.h} | 0 src/unix/{ => stubs}/gen_stubs.ml | 6 +- src/unix/stubs/jbuild | 4 + tests/core/jbuild | 10 + tests/jbuild | 7 + tests/ppx/jbuild | 12 + tests/preemptive/jbuild | 11 + tests/react/jbuild | 10 + tests/test.ml | 4 +- tests/unix/jbuild | 15 + 41 files changed, 1611 insertions(+), 554 deletions(-) rename opam/descr => descr (100%) create mode 100644 doc/examples/gtk/jbuild create mode 100644 doc/examples/unix/jbuild create mode 100644 jbuild create mode 100644 lwt.opam delete mode 100644 opam/files/lwt.install delete mode 100644 opam/opam create mode 100644 src/camlp4/jbuild create mode 100644 src/core/jbuild create mode 100644 src/glib/config/discover.ml create mode 100644 src/glib/config/jbuild create mode 100644 src/glib/jbuild delete mode 100644 src/glib/myocamlbuild.ml create mode 100644 src/logger/jbuild create mode 100644 src/ppx/jbuild delete mode 100644 src/ppx/ppx_lwt_ex.ml delete mode 100644 src/ppx/ppx_lwt_int.ml create mode 100644 src/preemptive/jbuild create mode 100644 src/react/jbuild create mode 100644 src/simple_top/jbuild create mode 100644 src/ssl/jbuild create mode 100644 src/unix/config/discover.ml create mode 100644 src/unix/config/jbuild create mode 100644 src/unix/jbuild rename src/unix/{lwt_unix_unix.c => lwt_unix_unix.h} (100%) rename src/unix/{lwt_unix_windows.c => lwt_unix_windows.h} (100%) rename src/unix/{ => stubs}/gen_stubs.ml (99%) create mode 100644 src/unix/stubs/jbuild create mode 100644 tests/core/jbuild create mode 100644 tests/jbuild create mode 100644 tests/ppx/jbuild create mode 100644 tests/preemptive/jbuild create mode 100644 tests/react/jbuild create mode 100644 tests/unix/jbuild diff --git a/.gitignore b/.gitignore index a7529f3946..c64e2c8963 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,7 @@ _coverage/ # For local work, tests, etc. scratch/ + +.merlin +*.install + diff --git a/Makefile b/Makefile index 0b1bb32e64..d0cdc12072 100644 --- a/Makefile +++ b/Makefile @@ -29,8 +29,8 @@ setup.exe: setup.ml setup: $(SETUP) -build: $(SETUP) setup.data - ./$(SETUP) -build $(BUILDFLAGS) +build: + jbuilder build @install doc: $(SETUP) setup.data build ./$(SETUP) -doc $(DOCFLAGS) @@ -38,8 +38,8 @@ doc: $(SETUP) setup.data build doc-api: $(SETUP) setup.data build ./$(SETUP) -build lwt-api.docdir/index.html -test: $(SETUP) setup.data build clean-coverage - ./$(SETUP) -test $(TESTFLAGS) +test: + jbuilder runtest all: $(SETUP) ./$(SETUP) -all $(ALLFLAGS) diff --git a/opam/descr b/descr similarity index 100% rename from opam/descr rename to descr diff --git a/doc/examples/gtk/jbuild b/doc/examples/gtk/jbuild new file mode 100644 index 0000000000..7cf29c886f --- /dev/null +++ b/doc/examples/gtk/jbuild @@ -0,0 +1,6 @@ +(jbuild_version 1) + +(executable + ((name connect) + (libraries (lwt.unix lwt.glib threads lablgtk2)) + (preprocess (pps (lwt.ppx))))) diff --git a/doc/examples/unix/jbuild b/doc/examples/unix/jbuild new file mode 100644 index 0000000000..89c6ad6809 --- /dev/null +++ b/doc/examples/unix/jbuild @@ -0,0 +1,7 @@ +(jbuild_version 1) + +(executables + ((names (logging relay parallelize)) + (libraries (lwt.unix)) + (preprocess (pps (lwt.ppx))))) + diff --git a/jbuild b/jbuild new file mode 100644 index 0000000000..e76d21a2db --- /dev/null +++ b/jbuild @@ -0,0 +1,13 @@ +(jbuild_version 1) + +(alias + ((name unix-examples) + (deps (doc/examples/unix/logging.exe + doc/examples/unix/relay.exe + doc/examples/unix/parallelize.exe)))) + +(alias + ((name gtk-example) + (deps (doc/examples/gtk/connect.exe)))) + + diff --git a/lwt.opam b/lwt.opam new file mode 100644 index 0000000000..a72a4093a2 --- /dev/null +++ b/lwt.opam @@ -0,0 +1,59 @@ +opam-version: "1.2" +name: "lwt" +version: "dev" +maintainer: [ + "Anton Bachin " + "Mauricio Fernandez " + "Simon Cruanes " +] +authors: [ + "Jérôme Vouillon" + "Jérémie Dimino" +] +homepage: "https://github.com/ocsigen/lwt" +doc: "https://ocsigen.org/lwt/manual/" +bug-reports: "https://github.com/ocsigen/lwt/issues" +license: "LGPL with OpenSSL linking exception" +dev-repo: "https://github.com/ocsigen/lwt.git" +build: [ + [ "jbuilder" "build" "-p" name "-j" jobs ] +] +build-test: [ + [ "jbuilder" "runtest" ] +] +depends: [ + "ocamlfind" {build & >= "1.5.0"} + "jbuilder" { build & >= "1.0+beta9" } + "result" + "cppo" {build} + + "ocaml-migrate-parsetree" + "ppx_tools_versioned" + + # XXX because most configuration is not enabled + "base-threads" + "base-unix" + "conf-libev" + "camlp4" +] +#depopts: [ +# "base-threads" +# "base-unix" +# "conf-libev" +# "camlp4" +#] +#conflicts: [ +# "ppx_tools" {< "1.0.0" } +#] +available: [ocaml-version >= "4.02.0" & compiler != "4.02.1+BER"] +#messages: [ +# "For module Lwt_ssl, please install package lwt_ssl" +# {ssl:installed & !lwt_ssl:installed} +# "For module Lwt_glib, please install package lwt_glib" +# {lablgtk:installed & !lwt_glib:installed} +# "For module Lwt_react, please install package lwt_react" +# {react:installed & !lwt_react:installed} +#] +post-messages: [ + "Lwt+jbuilder has some major breaking changes!!!" +] diff --git a/opam/files/lwt.install b/opam/files/lwt.install deleted file mode 100644 index d88814c3cd..0000000000 --- a/opam/files/lwt.install +++ /dev/null @@ -1,6 +0,0 @@ -lib: "opam/opam" { "opam" } -doc: [ - "README.md" - "CHANGES" - "doc/COPYING" { "LICENSE" } -] diff --git a/opam/opam b/opam/opam deleted file mode 100644 index 26effc65d0..0000000000 --- a/opam/opam +++ /dev/null @@ -1,66 +0,0 @@ -opam-version: "1.2" -name: "lwt" -version: "dev" -maintainer: [ - "Anton Bachin " - "Mauricio Fernandez " - "Simon Cruanes " -] -authors: [ - "Jérôme Vouillon" - "Jérémie Dimino" -] -homepage: "https://github.com/ocsigen/lwt" -doc: "https://ocsigen.org/lwt/manual/" -bug-reports: "https://github.com/ocsigen/lwt/issues" -license: "LGPL with OpenSSL linking exception" -dev-repo: "https://github.com/ocsigen/lwt.git" -build: [ - [make "setup"] - ["ocaml" "setup.ml" "-configure" - "--prefix" prefix - "--%{conf-libev:enable}%-libev" - "--%{camlp4:enable}%-camlp4" - "--%{base-unix:enable}%-unix" - "--%{base-threads:enable}%-preemptive" - "--%{ppx_tools:enable}%-ppx"] - [make "build"] -] -build-test: [ - ["ocaml" "setup.ml" "-configure" "--enable-tests"] - [make "test"] -] -install: [[make "install"]] -remove: [[ "ocamlfind" "remove" "lwt" ]] -depends: [ - "ocamlfind" {build & >= "1.5.0"} - "ocamlbuild" {build} - "result" - "cppo" {build} - # See https://github.com/ocsigen/lwt/issues/266 - ( "base-no-ppx" | "ppx_tools" {build} ) - ## OASIS is not required in released version - "oasis" {build & >= "0.4.8"} -] -depopts: [ - "base-threads" - "base-unix" - "conf-libev" - "camlp4" -] -conflicts: [ - "ppx_tools" {< "1.0.0" } -] -available: [ocaml-version >= "4.02.0" & compiler != "4.02.1+BER"] -messages: [ - "For module Lwt_ssl, please install package lwt_ssl" - {ssl:installed & !lwt_ssl:installed} - "For module Lwt_glib, please install package lwt_glib" - {lablgtk:installed & !lwt_glib:installed} - "For module Lwt_react, please install package lwt_react" - {react:installed & !lwt_react:installed} -] -post-messages: [ - "Lwt 3.0.0 made some minor breaking changes, announced in 2.7.0. See - https://github.com/ocsigen/lwt/issues/308" -] diff --git a/src/camlp4/jbuild b/src/camlp4/jbuild new file mode 100644 index 0000000000..d9706a9982 --- /dev/null +++ b/src/camlp4/jbuild @@ -0,0 +1,23 @@ +(library + ((name lwt_syntax_options) + (public_name lwt.syntax-options) + (modules pa_lwt_options) + (wrapped false) + (libraries (camlp4)))) + +(library + ((name lwt_syntax) + (public_name lwt.syntax) + (modules pa_lwt) + (wrapped false) + (libraries (camlp4.extend camlp4.quotations.o lwt.syntax-options)) + (preprocess (action (run camlp4oof ${<}))))) + +(library + ((name lwt_syntax_log) + (public_name lwt.syntax-log) + (modules pa_lwt_log) + (wrapped false) + (libraries (camlp4.extend camlp4.quotations.o lwt.syntax-options)) + (preprocess (action (run camlp4oof ${<}))))) + diff --git a/src/core/jbuild b/src/core/jbuild new file mode 100644 index 0000000000..82bdaf64f0 --- /dev/null +++ b/src/core/jbuild @@ -0,0 +1,7 @@ +(jbuild_version 1) + +(library + ((name lwt) + (public_name lwt) + (wrapped false) + (libraries (bytes result)))) diff --git a/src/glib/config/discover.ml b/src/glib/config/discover.ml new file mode 100644 index 0000000000..e183546660 --- /dev/null +++ b/src/glib/config/discover.ml @@ -0,0 +1,24 @@ +open Base +open Stdio +module C = Configurator + +let write_sexp fn sexp = + Out_channel.write_all fn ~data:(Sexp.to_string sexp) + +let () = + C.main ~name:"glib-2.0" (fun c -> + let default : C.Pkg_config.package_conf = + { libs = ["-lglib-2.0"] + ; cflags = [] + } + in + let conf = + match C.Pkg_config.get c with + | None -> default + | Some pc -> + Option.value (C.Pkg_config.query pc ~package:"glib-2.0") ~default + in + + write_sexp "c_flags.sexp" (sexp_of_list sexp_of_string conf.cflags); + write_sexp "c_library_flags.sexp" (sexp_of_list sexp_of_string conf.libs)) + diff --git a/src/glib/config/jbuild b/src/glib/config/jbuild new file mode 100644 index 0000000000..e9c1f41a3e --- /dev/null +++ b/src/glib/config/jbuild @@ -0,0 +1,5 @@ +(jbuild_version 1) + +(executables + ((names (discover)) + (libraries (base stdio configurator)))) diff --git a/src/glib/jbuild b/src/glib/jbuild new file mode 100644 index 0000000000..d17fc4650b --- /dev/null +++ b/src/glib/jbuild @@ -0,0 +1,20 @@ +(jbuild_version 1) + +(library + ((name lwt_glib) + (public_name lwt.glib) + (wrapped false) + (libraries (lwt lwt.unix)) + (c_names (lwt_glib_stubs)) + (c_flags (:include c_flags.sexp)) + (c_library_flags (:include c_library_flags.sexp)))) + +;; +;; see src/glib/myocamlbuild.ml for functionality needed for windows +;; +(rule + ((targets (c_flags.sexp + c_library_flags.sexp)) + (deps (config/discover.exe)) + (action (run ${<} -ocamlc ${OCAMLC})))) + diff --git a/src/glib/myocamlbuild.ml b/src/glib/myocamlbuild.ml deleted file mode 100644 index 2e468f55be..0000000000 --- a/src/glib/myocamlbuild.ml +++ /dev/null @@ -1,83 +0,0 @@ -(* OASIS_START *) -(* OASIS_STOP *) - -(* This is largely based on the Glib-related code in the main build system, - though rewritten somewhat. *) - -let split = - let regexp = Str.regexp " +" in - fun s -> Str.split regexp s - -(* Runs pkg-config with the given arguments. *) -let pkg_config arguments = - (* Run the pkg-config command. *) - let command = Printf.sprintf "pkg-config %s" arguments in - let input_channel = Unix.open_process_in command in - let result = - try Pervasives.input_line input_channel - with End_of_file -> "" - in - let status = Unix.close_process_in input_channel in - - match status with - | Unix.WEXITED 0 -> - (* On success, split the output of pkg-config result (arguments for the - compiler) into tokens. *) - let result = split result in - - (* Then, look for any -Wl,-framework tokens. Replace them with -framework - tokens, and remove the prefix "-Wl," from the next token. This is - necessary because pkg-config emits options for the compiler to pass to - the linker, so they are prefixed with "-Wl,". However, ocamlmktop - expects the -framework options unprefixed. *) - let rec unprefix_framework_arguments acc = function - | [] -> List.rev acc - | "-Wl,-framework"::framework::rest -> - let framework = String.sub framework 4 (String.length framework - 4) in - unprefix_framework_arguments (framework::"-framework"::acc) rest - | argument::rest -> - unprefix_framework_arguments (argument::acc) rest - in - let result = unprefix_framework_arguments [] result in - - result - - | _ -> - Printf.eprintf "Command failed: %s" command; - exit 1 - -(* Loads values from setup.data. In particular, this build needs to check - whether ccomp_type, as detected by configure, is "msvc". *) -let env = - BaseEnvLight.load - ~allow_empty:true - ~filename:(Pathname.basename BaseEnvLight.default_filename) - () - -let () = - dispatch begin fun hook -> - dispatch_default hook; - - match hook with - | After_rules -> - (* Get compiler and linker options using pkg-config. *) - let cflags = pkg_config "--cflags glib-2.0" in - let libs = - let ccomp_type = BaseEnvLight.var_get "ccomp_type" env in - if ccomp_type = "msvc" then - pkg_config "--libs-only-L glib-2.0" @ - pkg_config "--libs-only-l --msvc_syntax glib-2.0" - else - pkg_config "--libs glib-2.0" - in - - (* Forward compiler and linker options to Ocamlbuild. *) - flag ["ocamlmklib"; "c"] @@ - S (List.map (fun s -> A s) libs); - flag ["compile"; "c"] @@ - S (List.map (fun s -> S [A "-ccopt"; A s]) cflags); - flag ["link"; "ocaml"] @@ - S (List.map (fun s -> S [A "-cclib"; A s]) libs); - - | _ -> () - end diff --git a/src/logger/jbuild b/src/logger/jbuild new file mode 100644 index 0000000000..de12609b54 --- /dev/null +++ b/src/logger/jbuild @@ -0,0 +1,9 @@ +(jbuild_version 1) + +(ocamllex (lwt_log_rules)) + +(library + ((name lwt_log) + (public_name "lwt.log") + (wrapped false) + (libraries (lwt)))) diff --git a/src/ppx/.merlin b/src/ppx/.merlin index 69dfe6fcae..0bfd90cf11 100644 --- a/src/ppx/.merlin +++ b/src/ppx/.merlin @@ -1,4 +1,8 @@ -PKG ppx_tools -PKG ppx_tools.metaquot - -REC \ No newline at end of file +B ../../_build/default/src/ppx +FLG -open Ppx_js -w -40 +FLG -ppx "../../_build/default/.ppx/ppx_tools_versioned.metaquot_404/ppx.exe --as-ppx --cookie 'library-name="ppx_js"'" +PKG compiler-libs +PKG compiler-libs.common +PKG ocaml-migrate-parsetree +PKG ppx_tools_versioned +S . diff --git a/src/ppx/jbuild b/src/ppx/jbuild new file mode 100644 index 0000000000..56f503eaad --- /dev/null +++ b/src/ppx/jbuild @@ -0,0 +1,15 @@ +(jbuild_version 1) + +(library + ((name ppx_js) + (public_name lwt.ppx) + (synopsis "Lwt ppx") + (modules (ppx_lwt)) + (libraries (compiler-libs.common + ocaml-migrate-parsetree + ppx_tools_versioned)) + (ppx_runtime_libraries (lwt)) + (kind ppx_rewriter) + (preprocess (pps (ppx_tools_versioned.metaquot_404))) + )) + diff --git a/src/ppx/ppx_lwt.ml b/src/ppx/ppx_lwt.ml index ebdb9d303a..3609694057 100644 --- a/src/ppx/ppx_lwt.ml +++ b/src/ppx/ppx_lwt.ml @@ -1,2 +1,380 @@ +open Migrate_parsetree +open Ast_mapper +open Ast_helper +open Asttypes +open Parsetree + +open Ast_convenience_404 + +(** {2 Convenient stuff} *) + +let with_loc f {txt ; loc = _loc} = + (f txt) [@metaloc _loc] + +let def_loc txt = + { txt; loc = !default_loc } + +(** Test if a case is a catchall. *) +let is_catchall case = + let rec is_catchall_pat p = match p.ppat_desc with + | Ppat_any | Ppat_var _ -> true + | Ppat_alias (p, _) -> is_catchall_pat p + | _ -> false + in + case.pc_guard = None && is_catchall_pat case.pc_lhs + +(** Add a wildcard case in there is none. Useful for exception handlers. *) +let add_wildcard_case cases = + let has_wildcard = + List.exists is_catchall cases + in + if not has_wildcard + then cases @ [Exp.case [%pat? exn] [%expr Lwt.fail exn]] + else cases + +(** {3 Internal names} *) + +let lwt_prefix = "__ppx_lwt_" + +(** {2 Here we go!} *) + +let warn_let_lwt_rec loc attrs = + let attr = attribute_of_warning loc "\"let%lwt rec\" is not a recursive Lwt binding" in + attr :: attrs + +let debug = ref true +let log = ref false +let sequence = ref true +let strict_seq = ref true + +(** let%lwt related functions *) + +let gen_name i = lwt_prefix ^ string_of_int i + +(** [p = x] ≡ [__ppx_lwt_$i = x] *) +let gen_bindings l = + let aux i binding = + { binding with + pvb_pat = (pvar (gen_name i)) [@metaloc binding.pvb_expr.pexp_loc] + } + in + List.mapi aux l + +(** [p = x] and e ≡ [Lwt.bind __ppx_lwt_$i (fun p -> e)] *) +let gen_binds e_loc l e = + let rec aux i bindings = + match bindings with + | [] -> e + | binding :: t -> + let name = (* __ppx_lwt_$i, at the position of $x$ *) + (evar (gen_name i)) [@metaloc binding.pvb_expr.pexp_loc] + in + let fun_ = + [%expr (fun [%p binding.pvb_pat] -> [%e aux (i+1) t])] [@metaloc binding.pvb_loc] + in + let new_exp = + if !debug then + [%expr Lwt.backtrace_bind (fun exn -> try raise exn with exn -> exn) + [%e name] [%e fun_]] [@metaloc e_loc] + else + [%expr Lwt.bind [%e name] [%e fun_]] [@metaloc e_loc] + in + { new_exp with pexp_attributes = binding.pvb_attributes } + in aux 0 l + +(** [p = x and p' = x' and ...] ≡ + [p, p', ... = Lwt_main.run ( + Lwt.bind x (fun __ppx_lwt_$i -> + Lwt.bind x' (fun __ppx_lwt_$i' -> + ... + Lwt.return (__ppx_lwt_$i, __ppx_lwt_$i', ...))))] *) + +let gen_top_binds vbs = + let gen_exp vbs i = + match vbs with + | {pvb_expr; _}::_rest -> + if !debug then + [%expr Lwt.backtrace_bind (fun exn -> try raise exn with exn -> exn) + [%e pvb_expr] (fun [%p pvar (gen_name i)] -> gen_exp _rest (i + 1))] + else + [%expr Lwt.bind [%e pvb_expr] (fun [%p pvar (gen_name i)] -> gen_exp rest (i + 1))] + | [] -> + let rec names i = + if i >= 0 then evar (gen_name i) :: names (i - 1) else [] + in Exp.tuple (names i) + in + [Vb.mk (Pat.tuple (vbs |> List.map (fun { pvb_pat; _ } -> pvb_pat))) + [%expr Lwt_main.run [%e gen_exp vbs 0]]] + +(** For expressions only *) +(* We only expand the first level after a %lwt. + After that, we call the mapper to expand sub-expressions. *) +let lwt_expression mapper exp attributes = + default_loc := exp.pexp_loc; + let pexp_attributes = attributes @ exp.pexp_attributes in + match exp.pexp_desc with + + (* [let%lwt $p$ = $e$ in $e'$] ≡ [Lwt.bind $e$ (fun $p$ -> $e'$)] *) + | Pexp_let (Nonrecursive, vbl , e) -> + let new_exp = + Exp.let_ + Nonrecursive + (gen_bindings vbl) + (gen_binds exp.pexp_loc vbl e) + in mapper.expr mapper { new_exp with pexp_attributes } + + (* [match%lwt $e$ with $c$] ≡ [Lwt.bind $e$ (function $c$)] + [match%lwt $e$ with exception $x$ | $c$] ≡ + [Lwt.try_bind (fun () -> $e$) (function $c$) (function $x$)] *) + | Pexp_match (e, cases) -> + let exns, cases = + cases |> List.partition ( + function + | {pc_lhs = [%pat? exception [%p? _]]; _} -> true + | _ -> false) + in + let exns = + exns |> List.map ( + function + | {pc_lhs = [%pat? exception [%p? pat]]; _} as case -> + { case with pc_lhs = pat } + | _ -> assert false) + in + let exns = add_wildcard_case exns in + let new_exp = + match exns with + | [] -> [%expr Lwt.bind [%e e] [%e Exp.function_ cases]] + | _ -> [%expr Lwt.try_bind (fun () -> [%e e]) + [%e Exp.function_ cases] [%e Exp.function_ exns]] + in + mapper.expr mapper { new_exp with pexp_attributes } + + (* [assert%lwt $e$] ≡ + [try Lwt.return (assert $e$) with exn -> Lwt.fail exn] *) + | Pexp_assert e -> + let new_exp = + [%expr try Lwt.return (assert [%e e]) with exn -> Lwt.fail exn] + in mapper.expr mapper { new_exp with pexp_attributes } + + (* [while%lwt $cond$ do $body$ done] ≡ + [let rec __ppx_lwt_loop () = + if $cond$ then Lwt.bind $body$ __ppx_lwt_loop + else Lwt.return_unit + in __ppx_lwt_loop] + *) + | Pexp_while (cond, body) -> + let new_exp = + [%expr + let rec __ppx_lwt_loop () = + if [%e cond] then Lwt.bind [%e body] __ppx_lwt_loop + else Lwt.return_unit + in __ppx_lwt_loop () + ] + in mapper.expr mapper { new_exp with pexp_attributes } + + (* [for%lwt $p$ = $start$ (to|downto) $end$ do $body$ done] ≡ + [let __ppx_lwt_bound = $end$ in + let rec __ppx_lwt_loop $p$ = + if $p$ COMP __ppx_lwt_bound then Lwt.return_unit + else Lwt.bind $body$ (fun () -> __ppx_lwt_loop ($p$ OP 1)) + in __ppx_lwt_loop $start$] + *) + | Pexp_for ({ppat_desc = Ppat_var p_var; _} as p, start, bound, dir, body) -> + let comp, op = match dir with + | Upto -> evar ">", evar "+" + | Downto -> evar "<", evar "-" + in + let p' = with_loc (fun s -> evar s) p_var in + + let exp_bound = [%expr __ppx_lwt_bound] [@metaloc bound.pexp_loc] in + let pat_bound = [%pat? __ppx_lwt_bound] [@metaloc bound.pexp_loc] in + + let new_exp = + [%expr + let [%p pat_bound] : int = [%e bound] in + let rec __ppx_lwt_loop [%p p] = + if [%e comp] [%e p'] [%e exp_bound] then Lwt.return_unit + else Lwt.bind [%e body] (fun () -> __ppx_lwt_loop ([%e op] [%e p'] 1)) + in __ppx_lwt_loop [%e start] + ] + in mapper.expr mapper { new_exp with pexp_attributes } + + + (* [try%lwt $e$ with $c$] ≡ + [Lwt.catch (fun () -> $e$) (function $c$)] + *) + | Pexp_try (expr, cases) -> + let cases = add_wildcard_case cases in + let new_exp = + if !debug then + [%expr Lwt.backtrace_catch (fun exn -> try raise exn with exn -> exn) + (fun () -> [%e expr]) [%e Exp.function_ cases]] + else + [%expr Lwt.catch (fun () -> [%e expr]) [%e Exp.function_ cases]] + in + mapper.expr mapper { new_exp with pexp_attributes } + + (* [if%lwt $c$ then $e1$ else $e2$] ≡ + [match%lwt $c$ with true -> $e1$ | false -> $e2$] + [if%lwt $c$ then $e1$] ≡ + [match%lwt $c$ with true -> $e1$ | false -> Lwt.return_unit] + *) + | Pexp_ifthenelse (cond, e1, e2) -> + let e2 = match e2 with None -> [%expr Lwt.return_unit] | Some e -> e in + let cases = + [ + Exp.case [%pat? true] e1 ; + Exp.case [%pat? false] e2 ; + ] + in + let new_exp = [%expr Lwt.bind [%e cond] [%e Exp.function_ cases]] in + mapper.expr mapper { new_exp with pexp_attributes } + + (* [[%lwt $e$]] ≡ [Lwt.catch (fun () -> $e$) Lwt.fail] *) + | _ -> + let exp = + match exp with + | { pexp_loc; pexp_desc=Pexp_let (Recursive, _, _); pexp_attributes } -> + let attr = attribute_of_warning pexp_loc "\"let%lwt rec\" is not a recursive Lwt binding" in + { exp with pexp_attributes = attr :: pexp_attributes } + | _ -> exp + in + let new_exp = + if !debug then + [%expr Lwt.backtrace_catch (fun exn -> try raise exn with exn -> exn) + (fun () -> [%e exp]) Lwt.fail] + else + [%expr Lwt.catch (fun () -> [%e exp]) Lwt.fail] + in + mapper.expr mapper { new_exp with pexp_attributes } + +let make_loc {Location.loc_start; _} = + let (file, line, char) = Location.get_pos_info loc_start in + [%expr ([%e str file], [%e int line], [%e int char])] + +(** + [Lwt_log.error "message"] ≡ + [let __pa_log_section = Lwt_log.Section.main in + if Lwt_log.Error >= (Lwt_log.Section.level __pa_log_section) + then Lwt_log.error ~location:("foo.ml", 1, 0) ~section:__pa_log_section "message" + else Lwt.return_unit]; + [Lwt_log.error ~section "message"] ≡ + [let __pa_log_section = section in ...]. + Additionally, remove debug-level statements if -no-debug is given. **) +let lwt_log mapper fn args attrs loc = + let open Longident in + match fn with + | {pexp_desc = Pexp_ident {txt = Ldot (Lident "Lwt_log", func); _}; _} -> + let len = String.length func in + let fmt = len >= 2 && func.[len - 2] = '_' && func.[len - 1] = 'f' + and ign = len >= 4 && func.[0] = 'i' && func.[1] = 'g' && func.[2] = 'n' && func.[3] = '_' in + let level = + match fmt, ign with + | false, false -> func + | true, false -> String.sub func 0 (len - 2) + | false, true -> String.sub func 4 (len - 4) + | true, true -> String.sub func 4 (len - 6) + in + let level = (String.capitalize [@ocaml.warning "-3"]) level in + if level = "Debug" && (not !debug) then + let new_exp = if ign then [%expr ()] else [%expr Lwt.return_unit] in + mapper.expr mapper { new_exp with pexp_attributes = attrs } + else if List.mem level ["Fatal"; "Error"; "Warning"; "Notice"; "Info"; "Debug"] then + let args = List.map (fun (l,e) -> l, mapper.expr mapper e) args in + let new_exp = + let args = (Label.labelled "location", make_loc loc) :: + (Label.labelled "section", [%expr __pa_log_section]) :: + List.remove_assoc (Label.labelled "section") args in + [%expr + if [%e Exp.construct (def_loc (Ldot (Lident "Lwt_log", level))) None] >= + Lwt_log.Section.level __pa_log_section then + [%e Exp.apply (Exp.ident (def_loc (Ldot (Lident "Lwt_log", func)))) args] + else + [%e if ign then [%expr ()] else [%expr Lwt.return_unit]]] + in + try + let section = List.assoc (Label.labelled "section") args in + [%expr let __pa_log_section = [%e section] in [%e new_exp]] + with Not_found -> + [%expr let __pa_log_section = Lwt_log.Section.main in [%e new_exp]] + else default_mapper.expr mapper (Exp.apply ~attrs fn args) + | _ -> default_mapper.expr mapper (Exp.apply ~attrs fn args) + +let mapper = + { default_mapper with + expr = (fun mapper expr -> + match expr with + | [%expr [%lwt [%e? exp]]] -> + lwt_expression mapper exp expr.pexp_attributes + + + (* [($e$)[%finally $f$]] ≡ + [Lwt.finalize (fun () -> $e$) (fun () -> $f$)] *) + | [%expr [%e? exp ] [%finally [%e? finally]] ] + | [%expr [%e? exp ] [%lwt.finally [%e? finally]] ] -> + let new_exp = + if !debug then + [%expr Lwt.backtrace_finalize (fun exn -> try raise exn with exn -> exn) + (fun () -> [%e exp]) (fun () -> [%e finally])] + else + [%expr Lwt.finalize (fun () -> [%e exp]) (fun () -> [%e finally])] + in + mapper.expr mapper + { new_exp with + pexp_attributes = expr.pexp_attributes @ exp.pexp_attributes + } + + | [%expr [%finally [%e? _ ]]] + | [%expr [%lwt.finally [%e? _ ]]] -> + raise (Location.Error ( + Location.errorf + ~loc:expr.pexp_loc + "Lwt's finally should be used only with the syntax: \"()[%%finally ...]\"." + )) + + + | [%expr [%e? lhs] >> [%e? rhs]] -> + if !sequence then + let pat = if !strict_seq then [%pat? ()] else [%pat? _] in + let lhs, rhs = mapper.expr mapper lhs, mapper.expr mapper rhs in + if !debug then + [%expr Lwt.backtrace_bind (fun exn -> try raise exn with exn -> exn) + [%e lhs] (fun [%p pat] -> [%e rhs])] + else + [%expr Lwt.bind [%e lhs] (fun [%p pat] -> [%e rhs])] + else + default_mapper.expr mapper expr + | { pexp_desc = Pexp_apply (fn, args); pexp_attributes; pexp_loc } when !log -> + default_loc := pexp_loc; + lwt_log mapper fn args pexp_attributes pexp_loc + | _ -> default_mapper.expr mapper expr); + structure_item = (fun mapper stri -> + default_loc := stri.pstr_loc; + match stri with + | [%stri let%lwt [%p? var] = [%e? exp]] -> + [%stri let [%p var] = Lwt_main.run [%e mapper.expr mapper exp]] + | {pstr_desc = Pstr_extension (({txt = "lwt"; _}, PStr [ + {pstr_desc = Pstr_value (Recursive, _); _}]) as content, attrs); pstr_loc} -> + {stri with pstr_desc = + Pstr_extension (content, warn_let_lwt_rec pstr_loc attrs)} + | {pstr_desc = Pstr_extension (({txt = "lwt"; _}, PStr [ + {pstr_desc = Pstr_value (Nonrecursive, vbs); _}]), _); _} -> + mapper.structure_item mapper (Str.value Nonrecursive (gen_top_binds vbs)) + | x -> default_mapper.structure_item mapper x); + } + + +let args = + Arg.([ + "-no-debug", Clear debug, "disable debug mode"; + "-log", Set log, "enable logging"; + "-no-log", Clear log, "disable logging"; + "-no-sequence", Clear sequence, "disable sequence operator"; + "-no-strict-sequence", Clear strict_seq, "allow non-unit sequence operations"; + ]) + +let () = + Driver.register ~name:"ppx_lwt" ~args Versions.ocaml_404 + (fun _config _cookies -> mapper) + -let () = Ppx_lwt_int.register () diff --git a/src/ppx/ppx_lwt.mli b/src/ppx/ppx_lwt.mli index 21ee9c9946..69d7f8d216 100644 --- a/src/ppx/ppx_lwt.mli +++ b/src/ppx/ppx_lwt.mli @@ -238,3 +238,7 @@ else - Debug messages are removed if the option [-no-debug] is passed. *) + + +val mapper : Migrate_parsetree.OCaml_404.Ast.Ast_mapper.mapper + diff --git a/src/ppx/ppx_lwt_ex.ml b/src/ppx/ppx_lwt_ex.ml deleted file mode 100644 index 33292e82ec..0000000000 --- a/src/ppx/ppx_lwt_ex.ml +++ /dev/null @@ -1,3 +0,0 @@ -let () = - Ppx_lwt_int.register (); - Migrate_parsetree.Driver.run_as_ppx_rewriter () diff --git a/src/ppx/ppx_lwt_int.ml b/src/ppx/ppx_lwt_int.ml deleted file mode 100644 index 4e4aec3585..0000000000 --- a/src/ppx/ppx_lwt_int.ml +++ /dev/null @@ -1,380 +0,0 @@ -open Migrate_parsetree -open Ast_mapper -open Ast_helper -open Asttypes -open Parsetree - -open Ast_convenience_404 - -(** {2 Convenient stuff} *) - -let with_loc f {txt ; loc = _loc} = - (f txt) [@metaloc _loc] - -let def_loc txt = - { txt; loc = !default_loc } - -(** Test if a case is a catchall. *) -let is_catchall case = - let rec is_catchall_pat p = match p.ppat_desc with - | Ppat_any | Ppat_var _ -> true - | Ppat_alias (p, _) -> is_catchall_pat p - | _ -> false - in - case.pc_guard = None && is_catchall_pat case.pc_lhs - -(** Add a wildcard case in there is none. Useful for exception handlers. *) -let add_wildcard_case cases = - let has_wildcard = - List.exists is_catchall cases - in - if not has_wildcard - then cases @ [Exp.case [%pat? exn] [%expr Lwt.fail exn]] - else cases - -(** {3 Internal names} *) - -let lwt_prefix = "__ppx_lwt_" - -(** {2 Here we go!} *) - -let warn_let_lwt_rec loc attrs = - let attr = attribute_of_warning loc "\"let%lwt rec\" is not a recursive Lwt binding" in - attr :: attrs - -let debug = ref true -let log = ref false -let sequence = ref true -let strict_seq = ref true - -(** let%lwt related functions *) - -let gen_name i = lwt_prefix ^ string_of_int i - -(** [p = x] ≡ [__ppx_lwt_$i = x] *) -let gen_bindings l = - let aux i binding = - { binding with - pvb_pat = (pvar (gen_name i)) [@metaloc binding.pvb_expr.pexp_loc] - } - in - List.mapi aux l - -(** [p = x] and e ≡ [Lwt.bind __ppx_lwt_$i (fun p -> e)] *) -let gen_binds e_loc l e = - let rec aux i bindings = - match bindings with - | [] -> e - | binding :: t -> - let name = (* __ppx_lwt_$i, at the position of $x$ *) - (evar (gen_name i)) [@metaloc binding.pvb_expr.pexp_loc] - in - let fun_ = - [%expr (fun [%p binding.pvb_pat] -> [%e aux (i+1) t])] [@metaloc binding.pvb_loc] - in - let new_exp = - if !debug then - [%expr Lwt.backtrace_bind (fun exn -> try raise exn with exn -> exn) - [%e name] [%e fun_]] [@metaloc e_loc] - else - [%expr Lwt.bind [%e name] [%e fun_]] [@metaloc e_loc] - in - { new_exp with pexp_attributes = binding.pvb_attributes } - in aux 0 l - -(** [p = x and p' = x' and ...] ≡ - [p, p', ... = Lwt_main.run ( - Lwt.bind x (fun __ppx_lwt_$i -> - Lwt.bind x' (fun __ppx_lwt_$i' -> - ... - Lwt.return (__ppx_lwt_$i, __ppx_lwt_$i', ...))))] *) - -let gen_top_binds vbs = - let gen_exp vbs i = - match vbs with - | {pvb_expr; _}::_rest -> - if !debug then - [%expr Lwt.backtrace_bind (fun exn -> try raise exn with exn -> exn) - [%e pvb_expr] (fun [%p pvar (gen_name i)] -> gen_exp _rest (i + 1))] - else - [%expr Lwt.bind [%e pvb_expr] (fun [%p pvar (gen_name i)] -> gen_exp rest (i + 1))] - | [] -> - let rec names i = - if i >= 0 then evar (gen_name i) :: names (i - 1) else [] - in Exp.tuple (names i) - in - [Vb.mk (Pat.tuple (vbs |> List.map (fun { pvb_pat; _ } -> pvb_pat))) - [%expr Lwt_main.run [%e gen_exp vbs 0]]] - -(** For expressions only *) -(* We only expand the first level after a %lwt. - After that, we call the mapper to expand sub-expressions. *) -let lwt_expression mapper exp attributes = - default_loc := exp.pexp_loc; - let pexp_attributes = attributes @ exp.pexp_attributes in - match exp.pexp_desc with - - (* [let%lwt $p$ = $e$ in $e'$] ≡ [Lwt.bind $e$ (fun $p$ -> $e'$)] *) - | Pexp_let (Nonrecursive, vbl , e) -> - let new_exp = - Exp.let_ - Nonrecursive - (gen_bindings vbl) - (gen_binds exp.pexp_loc vbl e) - in mapper.expr mapper { new_exp with pexp_attributes } - - (* [match%lwt $e$ with $c$] ≡ [Lwt.bind $e$ (function $c$)] - [match%lwt $e$ with exception $x$ | $c$] ≡ - [Lwt.try_bind (fun () -> $e$) (function $c$) (function $x$)] *) - | Pexp_match (e, cases) -> - let exns, cases = - cases |> List.partition ( - function - | {pc_lhs = [%pat? exception [%p? _]]; _} -> true - | _ -> false) - in - let exns = - exns |> List.map ( - function - | {pc_lhs = [%pat? exception [%p? pat]]; _} as case -> - { case with pc_lhs = pat } - | _ -> assert false) - in - let exns = add_wildcard_case exns in - let new_exp = - match exns with - | [] -> [%expr Lwt.bind [%e e] [%e Exp.function_ cases]] - | _ -> [%expr Lwt.try_bind (fun () -> [%e e]) - [%e Exp.function_ cases] [%e Exp.function_ exns]] - in - mapper.expr mapper { new_exp with pexp_attributes } - - (* [assert%lwt $e$] ≡ - [try Lwt.return (assert $e$) with exn -> Lwt.fail exn] *) - | Pexp_assert e -> - let new_exp = - [%expr try Lwt.return (assert [%e e]) with exn -> Lwt.fail exn] - in mapper.expr mapper { new_exp with pexp_attributes } - - (* [while%lwt $cond$ do $body$ done] ≡ - [let rec __ppx_lwt_loop () = - if $cond$ then Lwt.bind $body$ __ppx_lwt_loop - else Lwt.return_unit - in __ppx_lwt_loop] - *) - | Pexp_while (cond, body) -> - let new_exp = - [%expr - let rec __ppx_lwt_loop () = - if [%e cond] then Lwt.bind [%e body] __ppx_lwt_loop - else Lwt.return_unit - in __ppx_lwt_loop () - ] - in mapper.expr mapper { new_exp with pexp_attributes } - - (* [for%lwt $p$ = $start$ (to|downto) $end$ do $body$ done] ≡ - [let __ppx_lwt_bound = $end$ in - let rec __ppx_lwt_loop $p$ = - if $p$ COMP __ppx_lwt_bound then Lwt.return_unit - else Lwt.bind $body$ (fun () -> __ppx_lwt_loop ($p$ OP 1)) - in __ppx_lwt_loop $start$] - *) - | Pexp_for ({ppat_desc = Ppat_var p_var; _} as p, start, bound, dir, body) -> - let comp, op = match dir with - | Upto -> evar ">", evar "+" - | Downto -> evar "<", evar "-" - in - let p' = with_loc (fun s -> evar s) p_var in - - let exp_bound = [%expr __ppx_lwt_bound] [@metaloc bound.pexp_loc] in - let pat_bound = [%pat? __ppx_lwt_bound] [@metaloc bound.pexp_loc] in - - let new_exp = - [%expr - let [%p pat_bound] : int = [%e bound] in - let rec __ppx_lwt_loop [%p p] = - if [%e comp] [%e p'] [%e exp_bound] then Lwt.return_unit - else Lwt.bind [%e body] (fun () -> __ppx_lwt_loop ([%e op] [%e p'] 1)) - in __ppx_lwt_loop [%e start] - ] - in mapper.expr mapper { new_exp with pexp_attributes } - - - (* [try%lwt $e$ with $c$] ≡ - [Lwt.catch (fun () -> $e$) (function $c$)] - *) - | Pexp_try (expr, cases) -> - let cases = add_wildcard_case cases in - let new_exp = - if !debug then - [%expr Lwt.backtrace_catch (fun exn -> try raise exn with exn -> exn) - (fun () -> [%e expr]) [%e Exp.function_ cases]] - else - [%expr Lwt.catch (fun () -> [%e expr]) [%e Exp.function_ cases]] - in - mapper.expr mapper { new_exp with pexp_attributes } - - (* [if%lwt $c$ then $e1$ else $e2$] ≡ - [match%lwt $c$ with true -> $e1$ | false -> $e2$] - [if%lwt $c$ then $e1$] ≡ - [match%lwt $c$ with true -> $e1$ | false -> Lwt.return_unit] - *) - | Pexp_ifthenelse (cond, e1, e2) -> - let e2 = match e2 with None -> [%expr Lwt.return_unit] | Some e -> e in - let cases = - [ - Exp.case [%pat? true] e1 ; - Exp.case [%pat? false] e2 ; - ] - in - let new_exp = [%expr Lwt.bind [%e cond] [%e Exp.function_ cases]] in - mapper.expr mapper { new_exp with pexp_attributes } - - (* [[%lwt $e$]] ≡ [Lwt.catch (fun () -> $e$) Lwt.fail] *) - | _ -> - let exp = - match exp with - | { pexp_loc; pexp_desc=Pexp_let (Recursive, _, _); pexp_attributes } -> - let attr = attribute_of_warning pexp_loc "\"let%lwt rec\" is not a recursive Lwt binding" in - { exp with pexp_attributes = attr :: pexp_attributes } - | _ -> exp - in - let new_exp = - if !debug then - [%expr Lwt.backtrace_catch (fun exn -> try raise exn with exn -> exn) - (fun () -> [%e exp]) Lwt.fail] - else - [%expr Lwt.catch (fun () -> [%e exp]) Lwt.fail] - in - mapper.expr mapper { new_exp with pexp_attributes } - -let make_loc {Location.loc_start; _} = - let (file, line, char) = Location.get_pos_info loc_start in - [%expr ([%e str file], [%e int line], [%e int char])] - -(** - [Lwt_log.error "message"] ≡ - [let __pa_log_section = Lwt_log.Section.main in - if Lwt_log.Error >= (Lwt_log.Section.level __pa_log_section) - then Lwt_log.error ~location:("foo.ml", 1, 0) ~section:__pa_log_section "message" - else Lwt.return_unit]; - [Lwt_log.error ~section "message"] ≡ - [let __pa_log_section = section in ...]. - Additionally, remove debug-level statements if -no-debug is given. **) -let lwt_log mapper fn args attrs loc = - let open Longident in - match fn with - | {pexp_desc = Pexp_ident {txt = Ldot (Lident "Lwt_log", func); _}; _} -> - let len = String.length func in - let fmt = len >= 2 && func.[len - 2] = '_' && func.[len - 1] = 'f' - and ign = len >= 4 && func.[0] = 'i' && func.[1] = 'g' && func.[2] = 'n' && func.[3] = '_' in - let level = - match fmt, ign with - | false, false -> func - | true, false -> String.sub func 0 (len - 2) - | false, true -> String.sub func 4 (len - 4) - | true, true -> String.sub func 4 (len - 6) - in - let level = (String.capitalize [@ocaml.warning "-3"]) level in - if level = "Debug" && (not !debug) then - let new_exp = if ign then [%expr ()] else [%expr Lwt.return_unit] in - mapper.expr mapper { new_exp with pexp_attributes = attrs } - else if List.mem level ["Fatal"; "Error"; "Warning"; "Notice"; "Info"; "Debug"] then - let args = List.map (fun (l,e) -> l, mapper.expr mapper e) args in - let new_exp = - let args = (Label.labelled "location", make_loc loc) :: - (Label.labelled "section", [%expr __pa_log_section]) :: - List.remove_assoc (Label.labelled "section") args in - [%expr - if [%e Exp.construct (def_loc (Ldot (Lident "Lwt_log", level))) None] >= - Lwt_log.Section.level __pa_log_section then - [%e Exp.apply (Exp.ident (def_loc (Ldot (Lident "Lwt_log", func)))) args] - else - [%e if ign then [%expr ()] else [%expr Lwt.return_unit]]] - in - try - let section = List.assoc (Label.labelled "section") args in - [%expr let __pa_log_section = [%e section] in [%e new_exp]] - with Not_found -> - [%expr let __pa_log_section = Lwt_log.Section.main in [%e new_exp]] - else default_mapper.expr mapper (Exp.apply ~attrs fn args) - | _ -> default_mapper.expr mapper (Exp.apply ~attrs fn args) - -let lwt_mapper () = - { default_mapper with - expr = (fun mapper expr -> - match expr with - | [%expr [%lwt [%e? exp]]] -> - lwt_expression mapper exp expr.pexp_attributes - - - (* [($e$)[%finally $f$]] ≡ - [Lwt.finalize (fun () -> $e$) (fun () -> $f$)] *) - | [%expr [%e? exp ] [%finally [%e? finally]] ] - | [%expr [%e? exp ] [%lwt.finally [%e? finally]] ] -> - let new_exp = - if !debug then - [%expr Lwt.backtrace_finalize (fun exn -> try raise exn with exn -> exn) - (fun () -> [%e exp]) (fun () -> [%e finally])] - else - [%expr Lwt.finalize (fun () -> [%e exp]) (fun () -> [%e finally])] - in - mapper.expr mapper - { new_exp with - pexp_attributes = expr.pexp_attributes @ exp.pexp_attributes - } - - | [%expr [%finally [%e? _ ]]] - | [%expr [%lwt.finally [%e? _ ]]] -> - raise (Location.Error ( - Location.errorf - ~loc:expr.pexp_loc - "Lwt's finally should be used only with the syntax: \"()[%%finally ...]\"." - )) - - - | [%expr [%e? lhs] >> [%e? rhs]] -> - if !sequence then - let pat = if !strict_seq then [%pat? ()] else [%pat? _] in - let lhs, rhs = mapper.expr mapper lhs, mapper.expr mapper rhs in - if !debug then - [%expr Lwt.backtrace_bind (fun exn -> try raise exn with exn -> exn) - [%e lhs] (fun [%p pat] -> [%e rhs])] - else - [%expr Lwt.bind [%e lhs] (fun [%p pat] -> [%e rhs])] - else - default_mapper.expr mapper expr - | { pexp_desc = Pexp_apply (fn, args); pexp_attributes; pexp_loc } when !log -> - default_loc := pexp_loc; - lwt_log mapper fn args pexp_attributes pexp_loc - | _ -> default_mapper.expr mapper expr); - structure_item = (fun mapper stri -> - default_loc := stri.pstr_loc; - match stri with - | [%stri let%lwt [%p? var] = [%e? exp]] -> - [%stri let [%p var] = Lwt_main.run [%e mapper.expr mapper exp]] - | {pstr_desc = Pstr_extension (({txt = "lwt"; _}, PStr [ - {pstr_desc = Pstr_value (Recursive, _); _}]) as content, attrs); pstr_loc} -> - {stri with pstr_desc = - Pstr_extension (content, warn_let_lwt_rec pstr_loc attrs)} - | {pstr_desc = Pstr_extension (({txt = "lwt"; _}, PStr [ - {pstr_desc = Pstr_value (Nonrecursive, vbs); _}]), _); _} -> - mapper.structure_item mapper (Str.value Nonrecursive (gen_top_binds vbs)) - | x -> default_mapper.structure_item mapper x); - } - - -let args = - Arg.([ - "-no-debug", Clear debug, "disable debug mode"; - "-log", Set log, "enable logging"; - "-no-log", Clear log, "disable logging"; - "-no-sequence", Clear sequence, "disable sequence operator"; - "-no-strict-sequence", Clear strict_seq, "allow non-unit sequence operations"; - ]) - -let register () = - Driver.register ~name:"ppx_lwt" ~args Versions.ocaml_404 - (fun _config _cookies -> lwt_mapper ()) - - diff --git a/src/preemptive/jbuild b/src/preemptive/jbuild new file mode 100644 index 0000000000..a9f90bc174 --- /dev/null +++ b/src/preemptive/jbuild @@ -0,0 +1,8 @@ +(jbuild_version 1) + +(library + ((name lwt_preemptive) + (public_name lwt.preemptive) + (wrapped false) + (libraries (lwt lwt.unix threads)))) + diff --git a/src/react/jbuild b/src/react/jbuild new file mode 100644 index 0000000000..213caf1735 --- /dev/null +++ b/src/react/jbuild @@ -0,0 +1,8 @@ +(jbuild_version 1) + +(library + ((name lwt_react) + (public_name lwt.react) + (wrapped false) + (libraries (lwt react)))) + diff --git a/src/simple_top/jbuild b/src/simple_top/jbuild new file mode 100644 index 0000000000..f85b03e0c6 --- /dev/null +++ b/src/simple_top/jbuild @@ -0,0 +1,8 @@ +(jbuild_version 1) + +(library + ((name lwt_simple_top) + (public_name lwt.simple-top) + (wrapped false) + (libraries (lwt lwt.unix compiler-libs.common)))) + diff --git a/src/ssl/jbuild b/src/ssl/jbuild new file mode 100644 index 0000000000..cc0e6f5a31 --- /dev/null +++ b/src/ssl/jbuild @@ -0,0 +1,8 @@ +(jbuild_version 1) + +(library + ((name lwt_ssl) + (public_name lwt.ssl) + (wrapped false) + (libraries (ssl lwt.unix)))) + diff --git a/src/unix/config/discover.ml b/src/unix/config/discover.ml new file mode 100644 index 0000000000..e036d14d64 --- /dev/null +++ b/src/unix/config/discover.ml @@ -0,0 +1,799 @@ +(* Lightweight thread library for OCaml + * http://www.ocsigen.org/lwt + * Program discover + * Copyright (C) 2010 Jérémie Dimino + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, with linking exceptions; + * either version 2.1 of the License, or (at your option) any later + * version. See COPYING file for details. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + *) + +(* Discover available features *) + +open Printf + +(* +-----------------------------------------------------------------+ + | Search path | + +-----------------------------------------------------------------+ *) + +(* List of search paths for header files, mostly for MacOS + users. libev is installed by port systems into non-standard + locations by default on MacOS. + + We use a hardcorded list of path + the ones from C_INCLUDE_PATH and + LIBRARY_PATH. +*) + +let ( // ) = Filename.concat + +let default_search_paths = + List.map (fun dir -> (dir // "include", dir // "lib")) [ + "/usr"; + "/usr/local"; + "/usr/pkg"; + "/opt"; + "/opt/local"; + "/sw"; + "/mingw"; + ] + +let path_sep = if Sys.os_type = "Win32" then ';' else ':' + +let split_path str = + let len = String.length str in + let rec aux i = + if i >= len then + [] + else + let j = try String.index_from str i path_sep with Not_found -> len in + String.sub str i (j - i) :: aux (j + 1) + in + aux 0 + +let rec replace_last path ~patt ~repl = + let comp = Filename.basename path + and parent = Filename.dirname path in + if comp = patt then + parent // repl + else if parent = path then + path + else + (replace_last parent ~patt ~repl) // comp + +let search_paths = + let get var f = + try + List.map f (split_path (Sys.getenv var)) + with Not_found -> + [] + in + List.flatten [ + get "C_INCLUDE_PATH" (fun dir -> (dir, replace_last dir ~patt:"include" ~repl:"lib")); + get "LIBRARY_PATH" (fun dir -> (replace_last dir ~patt:"lib" ~repl:"include", dir)); + default_search_paths; + ] + +(* +-----------------------------------------------------------------+ + | Test codes | + +-----------------------------------------------------------------+ *) + +let caml_code = " +external test : unit -> unit = \"lwt_test\" +let () = test () +" + +let trivial_code = " +#include + +CAMLprim value lwt_test(value Unit) +{ + return Val_unit; +} +" + +let pthread_code = " +#include +#include + +CAMLprim value lwt_test(value Unit) +{ + pthread_create(0, 0, 0, 0); + return Val_unit; +} +" + +let libev_code = " +#include +#include + +CAMLprim value lwt_test(value Unit) +{ + ev_default_loop(0); + return Val_unit; +} +" + +let fd_passing_code = " +#include +#include +#include + +CAMLprim value lwt_test(value Unit) +{ + struct msghdr msg; + msg.msg_controllen = 0; + msg.msg_control = 0; + return Val_unit; +} +" + +let getcpu_code = " +#include +#define _GNU_SOURCE +#include + +CAMLprim value lwt_test(value Unit) +{ + sched_getcpu(); + return Val_unit; +} +" + +let affinity_code = " +#include +#define _GNU_SOURCE +#include + +CAMLprim value lwt_test(value Unit) +{ + sched_getaffinity(0, 0, 0); + return Val_unit; +} +" + +let eventfd_code = " +#include +#include + +CAMLprim value lwt_test(value Unit) +{ + eventfd(0, 0); + return Val_unit; +} +" + +let get_credentials_code struct_name = " +#define _GNU_SOURCE +#include +#include +#include + +CAMLprim value lwt_test(value Unit) +{ + struct " ^ struct_name ^ " cred; + socklen_t cred_len = sizeof(cred); + getsockopt(0, SOL_SOCKET, SO_PEERCRED, &cred, &cred_len); + return Val_unit; +} +" + +let get_peereid_code = " +#include +#include +#include + +CAMLprim value lwt_test(value Unit) +{ + uid_t euid; + gid_t egid; + getpeereid(0, &euid, &egid); + return Val_unit; +} +" + +let fdatasync_code = " +#include +#include + +CAMLprim value lwt_test(value Unit) +{ + int (*fdatasyncp)(int) = fdatasync; + fdatasyncp(0); + return Val_unit; +} +" + +let glib_code = " +#include +#include + +CAMLprim value lwt_test(value Unit) +{ + g_main_context_dispatch(0); + return Val_unit; +} +" + +let netdb_reentrant_code = " +#define _POSIX_PTHREAD_SEMANTICS +#include +#include +#include + +CAMLprim value lwt_test(value Unit) +{ + struct hostent *he; + struct servent *se; + he = gethostbyname_r((const char *)NULL, (struct hostent *)NULL,(char *)NULL, (int)0, (struct hostent **)NULL, (int *)NULL); + he = gethostbyaddr_r((const char *)NULL, (int)0, (int)0,(struct hostent *)NULL, (char *)NULL, (int)0, (struct hostent **)NULL,(int *)NULL); + se = getservbyname_r((const char *)NULL, (const char *)NULL,(struct servent *)NULL, (char *)NULL, (int)0, (struct servent **)NULL); + se = getservbyport_r((int)0, (const char *)NULL,(struct servent *)NULL, (char *)NULL, (int)0, (struct servent **)NULL); + pr = getprotoent_r((struct protoent *)NULL, (char *)NULL, (int)0, (struct protoent **)NULL); + pr = getprotobyname_r((const char *)NULL, (struct protoent *)NULL, (char *)NULL, (int)0, (struct protoent **)NULL); + pr = getprotobynumber_r((int)0, (struct protoent *)NULL, (char *)NULL, (int)0, (struct protoent **)NULL); + + return Val_unit; +} +" + +let hostent_reentrant_code = " +#define _GNU_SOURCE +#include +#include +#include +/* Helper functions for not re-entrant functions */ +#if !defined(HAS_GETHOSTBYADDR_R) || (HAS_GETHOSTBYADDR_R != 7 && HAS_GETHOSTBYADDR_R != 8) +#define NON_R_GETHOSTBYADDR 1 +#endif + +#if !defined(HAS_GETHOSTBYNAME_R) || (HAS_GETHOSTBYNAME_R != 5 && HAS_GETHOSTBYNAME_R != 6) +#define NON_R_GETHOSTBYNAME 1 +#endif + +CAMLprim value lwt_test(value u) +{ + (void)u; +#if defined(NON_R_GETHOSTBYNAME) || defined(NON_R_GETHOSTBYNAME) +#error \"not available\" +#else + return Val_unit; +#endif +} +" + +let struct_ns_code conversion = " +#define _GNU_SOURCE +#include +#include +#include +#include + +#define NANOSEC" ^ conversion ^ " + +CAMLprim value lwt_test() { + struct stat *buf; + double a, m, c; + a = (double)NANOSEC(buf, a); + m = (double)NANOSEC(buf, m); + c = (double)NANOSEC(buf, c); + return Val_unit; +} +" + +let bsd_mincore_code = " +#include +#include +#include + +CAMLprim value lwt_test() +{ + int (*mincore_ptr)(const void*, size_t, char*) = mincore; + return Val_int(mincore_ptr == mincore_ptr); +} +" + +(* +-----------------------------------------------------------------+ + | Compilation | + +-----------------------------------------------------------------+ *) + +let ocamlc = ref "ocamlfind ocamlc" +let ext_obj = ref ".o" +let exec_name = ref "a.out" +let use_libev = ref true +let use_glib = ref false +let use_pthread = ref true +let use_unix = ref true +let os_type = ref "Unix" +let android_target = ref false +let ccomp_type = ref "cc" +let libev_default = ref true +let debug = ref (try Sys.getenv "DEBUG" = "y" with Not_found -> false) + +let dprintf fmt = + if !debug then + ( + eprintf "DBG: "; + kfprintf (fun oc -> fprintf oc "\n%!") stderr fmt + ) + else ifprintf stderr fmt + +let log_file = ref "" +let caml_file = ref "" + +(* Search for a header file in standard directories. *) +let search_header header = + let rec loop = function + | [] -> + None + | (dir_include, dir_lib) :: dirs -> + if Sys.file_exists (dir_include // header) then + Some (dir_include, dir_lib) + else + loop dirs + in + loop search_paths + +(* CFLAGS should not be passed to the linker. *) +let compile (opt, lib) stub_file = + let cmd fmt = ksprintf (fun s -> + dprintf "RUN: %s" s; + Sys.command s = 0) fmt in + let obj_file = Filename.chop_suffix stub_file ".c" ^ !ext_obj + in + (* First compile the .c file using -ocamlc and CFLAGS (opt) *) + (cmd + "%s -c %s %s -ccopt -o -ccopt %s >> %s 2>&1" + !ocamlc + (String.concat " " (List.map (fun x -> "-ccopt " ^ x) (List.map Filename.quote opt))) + (Filename.quote stub_file) + (Filename.quote obj_file) + (Filename.quote !log_file)) + && + (* Now link the resulting .o with the LDFLAGS (lib) *) + (cmd + "%s -custom %s %s %s >> %s 2>&1" + !ocamlc + (Filename.quote obj_file) + (Filename.quote !caml_file) + (String.concat " " (List.map (sprintf "-cclib %s") lib)) + (Filename.quote !log_file)) + +let safe_remove file_name = + if !debug then + dprintf "DEBUG: Not removing %s\n" file_name + else + try + Sys.remove file_name + with exn -> + () + +let test_code args stub_code = + let stub_file, oc = Filename.open_temp_file "lwt_stub" ".c" in + let cleanup () = + safe_remove stub_file; + safe_remove (Filename.chop_extension stub_file ^ !ext_obj) + in + try + output_string oc stub_code; + flush oc; + close_out oc; + let result = compile args stub_file in + cleanup (); + result + with exn -> + (try close_out oc with _ -> ()); + cleanup (); + raise exn + +let config = open_out "lwt_config.h" +let config_ml = open_out "lwt_config.ml" + +let () = + fprintf config "\ +#ifndef __LWT_CONFIG_H +#define __LWT_CONFIG_H +" + +let not_available = ref [] + +let test_feature ?(do_check = true) name macro test = + if do_check then begin + printf "testing for %s:%!" name; + if test () then begin + if macro <> "" then begin + fprintf config "#define %s\n" macro; + fprintf config_ml "let _%s = true\n" macro + end; + printf " %s available\n%!" (String.make (34 - String.length name) '.') + end else begin + if macro <> "" then begin + fprintf config "//#define %s\n" macro; + fprintf config_ml "let _%s = false\n" macro + end; + printf " %s unavailable\n%!" (String.make (34 - String.length name) '.'); + not_available := name :: !not_available + end + end else begin + printf "not checking for %s\n%!" name; + if macro <> "" then begin + fprintf config "//#define %s\n" macro; + fprintf config_ml "let _%s = false\n" macro + end + end + +(* +-----------------------------------------------------------------+ + | pkg-config | + +-----------------------------------------------------------------+ *) + +let split str = + let rec skip_spaces i = + if i = String.length str then + [] + else + if str.[i] = ' ' then + skip_spaces (i + 1) + else + extract i (i + 1) + and extract i j = + if j = String.length str then + [String.sub str i (j - i)] + else + if str.[j] = ' ' then + String.sub str i (j - i) :: skip_spaces (j + 1) + else + extract i (j + 1) + in + skip_spaces 0 + +let pkg_config flags = + if ksprintf Sys.command "pkg-config %s > %s 2>&1" flags !log_file = 0 then begin + let ic = open_in !log_file in + let line = input_line ic in + close_in ic; + split line + end else + raise Exit + +let pkg_config_flags name = + try + (* Get compile flags. *) + let opt = ksprintf pkg_config "--cflags %s" name in + (* Get linking flags. *) + let lib = + if !ccomp_type = "msvc" then + (* With msvc we need to pass "glib-2.0.lib" instead of + "-lglib-2.0" otherwise executables will fail. *) + ksprintf pkg_config "--libs-only-L %s" name @ ksprintf pkg_config "--libs-only-l --msvc-syntax %s" name + else + ksprintf pkg_config "--libs %s" name + in + Some (opt, lib) + with Exit -> + None + +let lib_flags env_var_prefix fallback = + let get var = try Some (split (Sys.getenv var)) with Not_found -> None in + match get (env_var_prefix ^ "_CFLAGS"), get (env_var_prefix ^ "_LIBS") with + | Some opt, Some lib -> + (opt, lib) + | x -> + let opt, lib = fallback () in + match x with + | Some opt, Some lib -> + assert false + | Some opt, None -> + (opt, lib) + | None, Some lib -> + (opt, lib) + | None, None -> + (opt, lib) + +(* +-----------------------------------------------------------------+ + | Entry point | + +-----------------------------------------------------------------+ *) + +let arg_bool r = + Arg.Symbol (["true"; "false"], + function + | "true" -> r := true + | "false" -> r := false + | _ -> assert false) +let () = + let args = [ + "-ocamlc", Arg.Set_string ocamlc, " ocamlc"; + "-ext-obj", Arg.Set_string ext_obj, " C object files extension"; + "-exec-name", Arg.Set_string exec_name, " name of the executable produced by ocamlc"; + "-use-libev", arg_bool use_libev, " whether to check for libev"; + "-use-glib", arg_bool use_glib, " whether to check for glib"; + "-use-pthread", arg_bool use_pthread, " whether to use pthread"; + "-use-unix", arg_bool use_unix, " whether to build lwt.unix"; + "-os-type", Arg.Set_string os_type, " type of the target os"; + "-android-target", arg_bool android_target, " compiles for Android"; + "-ccomp-type", Arg.Set_string ccomp_type, " C compiler type"; + "-libev_default", arg_bool libev_default, " whether to use the libev backend by default"; + ] in + Arg.parse args ignore "check for external C libraries and available features\noptions are:"; + + (* Check nothing if we do not build lwt.unix. *) + if not !use_unix then exit 0; + + (* Put the caml code into a temporary file. *) + let file, oc = Filename.open_temp_file "lwt_caml" ".ml" in + caml_file := file; + output_string oc caml_code; + close_out oc; + + log_file := Filename.temp_file "lwt_output" ".log"; + + (* Cleanup things on exit. *) + at_exit (fun () -> + (try close_out config with _ -> ()); + (try close_out config_ml with _ -> ()); + safe_remove !log_file; + safe_remove !exec_name; + safe_remove !caml_file; + safe_remove (Filename.chop_extension !caml_file ^ ".cmi"); + safe_remove (Filename.chop_extension !caml_file ^ ".cmo")); + + let exit status = + if status <> 0 then begin + if !debug then printf " +See %s for more details. + " !log_file + else printf " +Run with DEBUG=y for more details. + "; + end; + exit status + in + + let setup_data = ref [] in + + (* Test for pkg-config. *) + test_feature ~do_check:(!use_libev || !use_glib) "pkg-config" "" + (fun () -> + ksprintf Sys.command "pkg-config --version > %s 2>&1" !log_file = 0); + + (* Not having pkg-config is not fatal. *) + let have_pkg_config = !not_available = [] in + not_available := []; + + let test_basic_compilation () = + test_code ([], []) trivial_code + in + + let test_libev () = + let opt, lib = + lib_flags "LIBEV" + (fun () -> + match if have_pkg_config then pkg_config_flags "libev" else None with + | Some (opt, lib) -> + (opt, lib) + | None -> + match search_header "ev.h" with + | Some (dir_i, dir_l) -> + (["-I" ^ dir_i], ["-L" ^ dir_l; "-lev"]) + | None -> + ([], ["-lev"])) + in + setup_data := ("libev_opt", opt) :: ("libev_lib", lib) :: !setup_data; + test_code (opt, lib) libev_code + in + + let test_pthread () = + let opt, lib = + if !android_target then ([], []) else + lib_flags "PTHREAD" (fun () -> ([], ["-lpthread"])) + in + setup_data := ("pthread_opt", opt) :: ("pthread_lib", lib) :: !setup_data; + test_code (opt, lib) pthread_code + in + + let test_glib () = + let opt, lib = + lib_flags "GLIB" + (fun () -> + match if have_pkg_config then pkg_config_flags "glib-2.0" else None with + | Some (opt, lib) -> + (opt, lib) + | None -> + ([], ["-lglib-2.0"])) + in + setup_data := ("glib_opt", opt) :: ("glib_lib", lib) :: !setup_data; + test_code (opt, lib) glib_code + in + + let test_nanosecond_stat () = + printf "testing for nanosecond stat support:%!"; + let conversions = [ + ("(buf, field) buf->st_##field##tim.tv_nsec", "*tim.tv_nsec"); + ("(buf, field) buf->st_##field##timespec.tv_nsec", "*timespec.tv_nsec"); + ("(buf, field) buf->st_##field##timensec", "*timensec"); + ] in + let fallback = "(buf, field) 0.0" in + let conversion = try + let (conversion, desc) = List.find (fun (conversion, _desc) -> + test_code ([], []) (struct_ns_code conversion) + ) conversions in + printf " %s %s\n%!" (String.make 11 '.') desc; + conversion + with Not_found -> begin + printf " %s unavailable\n%!" (String.make 11 '.'); + fprintf config "#define NANOSEC%s\n" fallback; + fallback + end in + fprintf config "#define NANOSEC%s\n" conversion + in + + if not (test_basic_compilation ()) then begin + printf " +Error: failed to compile a trivial ocaml toplevel. +You may be missing core components (compiler, ncurses, etc) +"; + exit 1 + end; + + test_feature ~do_check:!use_libev "libev" "HAVE_LIBEV" test_libev; + test_feature ~do_check:!use_pthread "pthread" "HAVE_PTHREAD" test_pthread; + test_feature ~do_check:!use_glib "glib" "" test_glib; + + if !not_available <> [] then begin + if not have_pkg_config then + printf "Warning: the 'pkg-config' command is not available."; + (* The missing library list should be printed on the last line, to avoid + being trimmed by OPAM. The whole message should be kept to 10 lines. See + https://github.com/ocsigen/lwt/issues/271. *) + printf " +Some required C libraries were not found. If a C library is installed in a +non-standard location, set _CFLAGS and _LIBS accordingly. You may also +try 'ocaml setup.ml -configure --disable-' to avoid compiling support for +it. For example, in the case of libev missing: + export LIBEV_CFLAGS=-I/opt/local/include + export LIBEV_LIBS='-L/opt/local/lib -lev' + (* or: *) ocaml setup.ml -configure --disable-libev + +Missing C libraries: %s +" (String.concat ", " !not_available); + exit 1 + end; + + if !os_type <> "Win32" && not !use_pthread then begin + printf " +No threading library available! + +One is needed if you want to build lwt.unix. + +Lwt can use pthread or the win32 API. +"; + exit 1 + end; + + let do_check = !os_type <> "Win32" in + test_feature ~do_check "eventfd" "HAVE_EVENTFD" (fun () -> test_code ([], []) eventfd_code); + test_feature ~do_check "fd passing" "HAVE_FD_PASSING" (fun () -> test_code ([], []) fd_passing_code); + test_feature ~do_check:(do_check && not !android_target) + "sched_getcpu" "HAVE_GETCPU" (fun () -> test_code ([], []) getcpu_code); + test_feature ~do_check:(do_check && not !android_target) + "affinity getting/setting" "HAVE_AFFINITY" (fun () -> test_code ([], []) affinity_code); + test_feature ~do_check "credentials getting (Linux)" "HAVE_GET_CREDENTIALS_LINUX" (fun () -> test_code ([], []) (get_credentials_code "ucred")); + test_feature ~do_check "credentials getting (NetBSD)" "HAVE_GET_CREDENTIALS_NETBSD" (fun () -> test_code ([], []) (get_credentials_code "sockcred")); + test_feature ~do_check "credentials getting (OpenBSD)" "HAVE_GET_CREDENTIALS_OPENBSD" (fun () -> test_code ([], []) (get_credentials_code "sockpeercred")); + test_feature ~do_check "credentials getting (FreeBSD)" "HAVE_GET_CREDENTIALS_FREEBSD" (fun () -> test_code ([], []) (get_credentials_code "cmsgcred")); + test_feature ~do_check "credentials getting (getpeereid)" "HAVE_GETPEEREID" (fun () -> test_code ([], []) get_peereid_code); + test_feature ~do_check "fdatasync" "HAVE_FDATASYNC" (fun () -> test_code ([], []) fdatasync_code); + test_feature ~do_check:(do_check && not !android_target) + "netdb_reentrant" "HAVE_NETDB_REENTRANT" (fun () -> test_code ([], []) netdb_reentrant_code); + test_feature ~do_check "reentrant gethost*" "HAVE_REENTRANT_HOSTENT" (fun () -> test_code ([], []) hostent_reentrant_code); + test_nanosecond_stat (); + test_feature ~do_check "BSD mincore" "HAVE_BSD_MINCORE" (fun () -> + test_code (["-Werror"], []) bsd_mincore_code); + + let get_cred_vars = [ + "HAVE_GET_CREDENTIALS_LINUX"; + "HAVE_GET_CREDENTIALS_NETBSD"; + "HAVE_GET_CREDENTIALS_OPENBSD"; + "HAVE_GET_CREDENTIALS_FREEBSD"; + "HAVE_GETPEEREID"; + ] in + + Printf.fprintf config "\ +#if %s +# define HAVE_GET_CREDENTIALS +#endif +" + (String.concat " || " (List.map (Printf.sprintf "defined(%s)") get_cred_vars)); + + Printf.fprintf config_ml + "let _HAVE_GET_CREDENTIALS = %s\n" + (String.concat " || " (List.map (fun s -> "_" ^ s) get_cred_vars)); + + if !os_type = "Win32" then begin + output_string config "#define LWT_ON_WINDOWS\n"; + end else begin + output_string config "//#define LWT_ON_WINDOWS\n"; + end; + if !android_target then begin + output_string config_ml "let android = true\n" + end else begin + output_string config_ml "let android = false\n" + end; + + let () = + let force_libev_default = + try Sys.getenv "LWT_FORCE_LIBEV_BY_DEFAULT" = "yes" + with Not_found -> false + in + let libev_default = !libev_default || force_libev_default in + Printf.fprintf config_ml "let libev_default = %b\n" libev_default + in + + fprintf config "#endif\n"; + + (* Our setup.data keys. *) + let setup_data_keys = [ + "libev_opt"; + "libev_lib"; + "pthread_lib"; + "pthread_opt"; + "glib_opt"; + "glib_lib"; + ] in + + (* Load setup.data *) + let setup_data_lines = + match try Some (open_in "setup.data") with Sys_error _ -> None with + | Some ic -> + let rec aux acc = + match try Some (input_line ic) with End_of_file -> None with + | None -> + close_in ic; + acc + | Some line -> + match try Some(String.index line '=') with Not_found -> None with + | Some idx -> + let key = String.sub line 0 idx in + if List.mem key setup_data_keys then + aux acc + else + aux (line :: acc) + | None -> + aux (line :: acc) + in + aux [] + | None -> + [] + in + + (* Add flags to setup.data *) + let setup_data_lines = + List.fold_left + (fun lines (name, args) -> + sprintf "%s=%S" name (String.concat " " args) :: lines) + setup_data_lines !setup_data + in + let oc = open_out "setup.data" in + List.iter + (fun str -> output_string oc str; output_char oc '\n') + (List.rev setup_data_lines); + close_out oc; + + close_out config; + close_out config_ml +(* + (* Generate stubs. *) + print_endline "Generating C stubs..."; + exit (Sys.command "ocaml src/unix/gen_stubs.ml") +*) + diff --git a/src/unix/config/jbuild b/src/unix/config/jbuild new file mode 100644 index 0000000000..fef112fe1c --- /dev/null +++ b/src/unix/config/jbuild @@ -0,0 +1,5 @@ +(jbuild_version 1) + +(executable + ((name discover))) + diff --git a/src/unix/jbuild b/src/unix/jbuild new file mode 100644 index 0000000000..210addd963 --- /dev/null +++ b/src/unix/jbuild @@ -0,0 +1,112 @@ +(jbuild_version 1) + +;; pre-processing cppo files + +(rule + ((targets (lwt_unix.ml)) + (deps (lwt_unix.cppo.ml)) + (action (run ${bin:cppo} -V OCAML:${ocaml_version} ${<} -o ${@})))) + +(rule + ((targets (lwt_unix.mli)) + (deps (lwt_unix.cppo.mli)) + (action (run ${bin:cppo} -V OCAML:${ocaml_version} ${<} -o ${@})))) + +;; lwt discover.ml + +(rule + ((targets (lwt_config.h lwt_config.ml)) + (deps (config/discover.exe)) + (action (run ${<} + -ext-obj .o ;; windows ... .obj? + -exec-name a.out ;; windows ... a.exe? + -use-libev ${lib-available:conf-libev} + -os-type Unix ;; ??? Win32 + -use-glib true ;; ??? optionally installed + -ccomp-type cc ;; ??? msvc + -use-pthread ${lib-available:threads} + -use-unix ${lib-available:unix} ;; but we are building for unix! + -android-target false ;; presumably modified in the android repository + -libev_default true ;; ??? if c library exists + )))) + +;; gen_stubs.ml + +(rule + ((targets ( + lwt_unix_job_access.c + lwt_unix_job_chdir.c + lwt_unix_job_chmod.c + lwt_unix_job_chown.c + lwt_unix_job_chroot.c + lwt_unix_job_close.c + lwt_unix_job_fchmod.c + lwt_unix_job_fchown.c + lwt_unix_job_fdatasync.c + lwt_unix_job_fsync.c + lwt_unix_job_ftruncate.c + lwt_unix_job_link.c + lwt_unix_job_lseek.c + lwt_unix_job_mkdir.c + lwt_unix_job_mkfifo.c + lwt_unix_job_rename.c + lwt_unix_job_rmdir.c + lwt_unix_job_symlink.c + lwt_unix_job_tcdrain.c + lwt_unix_job_tcflow.c + lwt_unix_job_tcflush.c + lwt_unix_job_tcsendbreak.c + lwt_unix_job_truncate.c + lwt_unix_job_unlink.c + lwt_unix_jobs_generated.ml + )) + (deps (stubs/gen_stubs.exe)) + (action (run ${<})))) + +;; main library +;; Lwt_unix_jobs_generated and Lwt_config should be hidden + +(library + ((name lwt_unix) + (public_name lwt.unix) + (wrapped false) + (libraries (lwt lwt.log unix bigarray)) + (c_names ( + lwt_unix_stubs + lwt_libev_stubs + lwt_process_stubs + lwt_unix_job_access + lwt_unix_job_chdir + lwt_unix_job_chmod + lwt_unix_job_chown + lwt_unix_job_chroot + lwt_unix_job_close + lwt_unix_job_fchmod + lwt_unix_job_fchown + lwt_unix_job_fdatasync + lwt_unix_job_fsync + lwt_unix_job_ftruncate + lwt_unix_job_link + lwt_unix_job_lseek + lwt_unix_job_mkdir + lwt_unix_job_mkfifo + lwt_unix_job_rename + lwt_unix_job_rmdir + lwt_unix_job_symlink + lwt_unix_job_tcdrain + lwt_unix_job_tcflow + lwt_unix_job_tcflush + lwt_unix_job_tcsendbreak + lwt_unix_job_truncate + lwt_unix_job_unlink + )) + (install_c_headers ( + lwt_config + lwt_unix + lwt_unix_unix + lwt_unix_windows + )) + (c_flags (-I.)) + (c_library_flags (-lpthread)) +)) + diff --git a/src/unix/lwt_unix_stubs.c b/src/unix/lwt_unix_stubs.c index 83d82fd266..4674e4ecbc 100644 --- a/src/unix/lwt_unix_stubs.c +++ b/src/unix/lwt_unix_stubs.c @@ -88,9 +88,9 @@ +-----------------------------------------------------------------+ */ #if defined(LWT_ON_WINDOWS) -# include "lwt_unix_windows.c" +# include "lwt_unix_windows.h" #else -# include "lwt_unix_unix.c" +# include "lwt_unix_unix.h" #endif /* +-----------------------------------------------------------------+ diff --git a/src/unix/lwt_unix_unix.c b/src/unix/lwt_unix_unix.h similarity index 100% rename from src/unix/lwt_unix_unix.c rename to src/unix/lwt_unix_unix.h diff --git a/src/unix/lwt_unix_windows.c b/src/unix/lwt_unix_windows.h similarity index 100% rename from src/unix/lwt_unix_windows.c rename to src/unix/lwt_unix_windows.h diff --git a/src/unix/gen_stubs.ml b/src/unix/stubs/gen_stubs.ml similarity index 99% rename from src/unix/gen_stubs.ml rename to src/unix/stubs/gen_stubs.ml index d21c8771d6..4a251c149f 100644 --- a/src/unix/gen_stubs.ml +++ b/src/unix/stubs/gen_stubs.ml @@ -731,7 +731,7 @@ end let gen job = let fname = "lwt_unix_job_" ^ job.name ^ ".c" in - let oc = open_out ("src/unix/jobs-unix/" ^ fname) in + let oc = open_out fname in let job64 = { job with params = ( @@ -778,7 +778,7 @@ let () = match Sys.argv with | [|_|] -> let fname = "lwt_unix_jobs_generated.ml" in - ml_oc := open_out ("src/unix/" ^ fname); + ml_oc := open_out fname; let pr_header oc fname = fprintf oc "\ (* @@ -805,7 +805,7 @@ module Make(Job : Job) = struct output_string !ml_oc "end\n"; close_out !ml_oc | [|_; "list-job-files"|] -> - StringMap.iter (fun name job -> printf "src/unix/jobs-unix/lwt_unix_job_%s.c\n" name) jobs + StringMap.iter (fun name job -> printf "lwt_unix_job_%s.c\n" name) jobs | [|_; "list-job-names"|] -> StringMap.iter (fun name job -> printf "%s\n" name) jobs | _ -> diff --git a/src/unix/stubs/jbuild b/src/unix/stubs/jbuild new file mode 100644 index 0000000000..8a44740c4b --- /dev/null +++ b/src/unix/stubs/jbuild @@ -0,0 +1,4 @@ +(jbuild_version 1) + +(executable + ((name gen_stubs))) diff --git a/tests/core/jbuild b/tests/core/jbuild new file mode 100644 index 0000000000..ba7d7f48d7 --- /dev/null +++ b/tests/core/jbuild @@ -0,0 +1,10 @@ +(jbuild_version 1) + +(executable + ((name main) + (libraries (lwttester)))) + +(alias + ((name runtest) + (action (run ${exe:main.exe})))) + diff --git a/tests/jbuild b/tests/jbuild new file mode 100644 index 0000000000..a28330f0fc --- /dev/null +++ b/tests/jbuild @@ -0,0 +1,7 @@ +(jbuild_version 1) + +(library + ((name "lwttester") + (wrapped false) + (libraries (lwt unix lwt.unix)))) + diff --git a/tests/ppx/jbuild b/tests/ppx/jbuild new file mode 100644 index 0000000000..1f01428890 --- /dev/null +++ b/tests/ppx/jbuild @@ -0,0 +1,12 @@ +(jbuild_version 1) + +(executable + ((name main) + (libraries (lwttester)) + (preprocess (pps (lwt.ppx))))) + +(alias + ((name runtest) + (action (run ${exe:main.exe})))) + + diff --git a/tests/preemptive/jbuild b/tests/preemptive/jbuild new file mode 100644 index 0000000000..199bf5b0ec --- /dev/null +++ b/tests/preemptive/jbuild @@ -0,0 +1,11 @@ +(jbuild_version 1) + +(executable + ((name main) + (libraries (lwt.preemptive lwttester)))) + +(alias + ((name runtest) + (action (run ${exe:main.exe})))) + + diff --git a/tests/react/jbuild b/tests/react/jbuild new file mode 100644 index 0000000000..23fb28a2d3 --- /dev/null +++ b/tests/react/jbuild @@ -0,0 +1,10 @@ +(jbuild_version 1) + +(executable + ((name main) + (libraries (lwt.react lwttester)))) + +(alias + ((name runtest) + (action (run ${exe:main.exe})))) + diff --git a/tests/test.ml b/tests/test.ml index c3a0f45afd..35746627e7 100644 --- a/tests/test.ml +++ b/tests/test.ml @@ -99,10 +99,10 @@ let temp_name = let rng = Random.State.make_self_init () in fun () -> let number = Random.State.int rng 10000 in - Printf.sprintf "_build/lwt-testing-%04d" number + Printf.sprintf (*"_build/"*)"lwt-testing-%04d" number let temp_file () = - Filename.temp_file ~temp_dir:"_build" "lwt-testing-" "" + Filename.temp_file (*~temp_dir:"_build"*) "lwt-testing-" "" let temp_directory () = let rec attempt () = diff --git a/tests/unix/jbuild b/tests/unix/jbuild new file mode 100644 index 0000000000..121435b4b5 --- /dev/null +++ b/tests/unix/jbuild @@ -0,0 +1,15 @@ +(jbuild_version 1) + +(rule + ((targets (test_lwt_unix.ml)) + (deps (test_lwt_unix.cppo.ml)) + (action (run ${bin:cppo} -V OCAML:${ocaml_version} ${<} -o ${@})))) + +(executable + ((name main) + (libraries (lwttester)))) + +(alias + ((name runtest) + (action (run ${exe:main.exe})))) + From 30b8a8002026f9b04c9b0a93b4d2ae6966703b90 Mon Sep 17 00:00:00 2001 From: andrewray Date: Tue, 23 May 2017 02:20:12 +0100 Subject: [PATCH 04/46] add configurator dep --- Makefile | 4 ++-- lwt.opam | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index d0cdc12072..893c9d3087 100644 --- a/Makefile +++ b/Makefile @@ -53,8 +53,8 @@ uninstall: $(SETUP) setup.data reinstall: $(SETUP) setup.data ./$(SETUP) -reinstall $(REINSTALLFLAGS) -clean: $(SETUP) clean-coverage - ./$(SETUP) -clean $(CLEANFLAGS) +clean: + rm -fr _build distclean: $(SETUP) ./$(SETUP) -distclean $(DISTCLEANFLAGS) diff --git a/lwt.opam b/lwt.opam index a72a4093a2..89aef5d953 100644 --- a/lwt.opam +++ b/lwt.opam @@ -27,6 +27,7 @@ depends: [ "result" "cppo" {build} + "configurator" "ocaml-migrate-parsetree" "ppx_tools_versioned" From de3d93119f1234c706fb2fac9fb8f8465302ab4e Mon Sep 17 00:00:00 2001 From: andrewray Date: Tue, 23 May 2017 09:57:13 +0100 Subject: [PATCH 05/46] opinionated reorganisation of packages jbuilder seems to prefer an opam file per package. An empty opam file `lwt.opam` depends on the usual suspects. It just installs a META files and reexports packages under their expected names. --- META.lwt.template | 38 ++++++++++++++++++++++++++++++++++++ Makefile | 1 + doc/examples/gtk/jbuild | 4 ++-- doc/examples/unix/jbuild | 4 ++-- lwt-core.opam | 25 ++++++++++++++++++++++++ lwt-log.opam | 25 ++++++++++++++++++++++++ lwt-ppx.opam | 29 +++++++++++++++++++++++++++ lwt-preemptive.opam | 27 ++++++++++++++++++++++++++ lwt-simple-top.opam | 27 ++++++++++++++++++++++++++ lwt-syntax.opam | 27 ++++++++++++++++++++++++++ lwt-unix.opam | 28 +++++++++++++++++++++++++++ lwt.opam | 42 ++++++---------------------------------- lwt_glib.opam | 28 +++++++++++++++++++++++++++ lwt_react.opam | 28 +++++++++++++++++++++++++++ lwt_ssl.opam | 28 +++++++++++++++++++++++++++ src/camlp4/jbuild | 10 +++++----- src/core/jbuild | 2 +- src/glib/jbuild | 4 ++-- src/logger/jbuild | 4 ++-- src/ppx/.merlin | 4 ++-- src/ppx/jbuild | 9 ++++----- src/preemptive/jbuild | 4 ++-- src/react/jbuild | 4 ++-- src/simple_top/jbuild | 4 ++-- src/ssl/jbuild | 4 ++-- src/unix/jbuild | 4 ++-- tests/core/jbuild | 1 + tests/jbuild | 2 +- tests/ppx/jbuild | 3 ++- tests/preemptive/jbuild | 3 ++- tests/react/jbuild | 3 ++- tests/unix/jbuild | 1 + 32 files changed, 356 insertions(+), 71 deletions(-) create mode 100644 META.lwt.template create mode 100644 lwt-core.opam create mode 100644 lwt-log.opam create mode 100644 lwt-ppx.opam create mode 100644 lwt-preemptive.opam create mode 100644 lwt-simple-top.opam create mode 100644 lwt-syntax.opam create mode 100644 lwt-unix.opam create mode 100644 lwt_glib.opam create mode 100644 lwt_react.opam create mode 100644 lwt_ssl.opam diff --git a/META.lwt.template b/META.lwt.template new file mode 100644 index 0000000000..e918c9178d --- /dev/null +++ b/META.lwt.template @@ -0,0 +1,38 @@ +# JBUILDER_GEN + +version = "dev" +description = "" +requires = "lwt-core" + +package "unix" ( + requires = "lwt-unix" +) + +package "log" ( + requires = "lwt-log" +) + +package "ppx" ( + requires = "lwt-ppx" +) + +package "preemptive" ( + requires = "lwt-preemptive" +) + +package "simple-top" ( + requires = "lwt-simple-top" +) + +package "syntax" ( + requires = "camlp4 lwt-syntax lwt.syntax.options" + + package "options" ( + requires = "lwt-syntax.options" + ) + + package "log" ( + requires = "lwt-syntax.log" + ) +) + diff --git a/Makefile b/Makefile index 893c9d3087..7dba1f62ff 100644 --- a/Makefile +++ b/Makefile @@ -55,6 +55,7 @@ reinstall: $(SETUP) setup.data clean: rm -fr _build + rm *.install distclean: $(SETUP) ./$(SETUP) -distclean $(DISTCLEANFLAGS) diff --git a/doc/examples/gtk/jbuild b/doc/examples/gtk/jbuild index 7cf29c886f..4392661ec7 100644 --- a/doc/examples/gtk/jbuild +++ b/doc/examples/gtk/jbuild @@ -2,5 +2,5 @@ (executable ((name connect) - (libraries (lwt.unix lwt.glib threads lablgtk2)) - (preprocess (pps (lwt.ppx))))) + (libraries (lwt-unix lwt_glib threads lablgtk2)) + (preprocess (pps (lwt-ppx))))) diff --git a/doc/examples/unix/jbuild b/doc/examples/unix/jbuild index 89c6ad6809..d69cc467a3 100644 --- a/doc/examples/unix/jbuild +++ b/doc/examples/unix/jbuild @@ -2,6 +2,6 @@ (executables ((names (logging relay parallelize)) - (libraries (lwt.unix)) - (preprocess (pps (lwt.ppx))))) + (libraries (lwt-unix)) + (preprocess (pps (lwt-ppx))))) diff --git a/lwt-core.opam b/lwt-core.opam new file mode 100644 index 0000000000..f4c5b68380 --- /dev/null +++ b/lwt-core.opam @@ -0,0 +1,25 @@ +opam-version: "1.2" +name: "lwt" +version: "dev" +maintainer: [ + "Anton Bachin " + "Mauricio Fernandez " + "Simon Cruanes " +] +authors: [ + "Jérôme Vouillon" + "Jérémie Dimino" +] +homepage: "https://github.com/ocsigen/lwt" +doc: "https://ocsigen.org/lwt/manual/" +bug-reports: "https://github.com/ocsigen/lwt/issues" +license: "LGPL with OpenSSL linking exception" +dev-repo: "https://github.com/ocsigen/lwt.git" +build: [ [ "jbuilder" "build" "-p" name "-j" jobs ] ] +build-test: [ [ "jbuilder" "runtest" ] ] +depends: [ + "ocamlfind" {build & >= "1.5.0"} + "jbuilder" { build & >= "1.0+beta9" } + "result" +] + diff --git a/lwt-log.opam b/lwt-log.opam new file mode 100644 index 0000000000..cf088dac66 --- /dev/null +++ b/lwt-log.opam @@ -0,0 +1,25 @@ +opam-version: "1.2" +name: "lwt" +version: "dev" +maintainer: [ + "Anton Bachin " + "Mauricio Fernandez " + "Simon Cruanes " +] +authors: [ + "Jérôme Vouillon" + "Jérémie Dimino" +] +homepage: "https://github.com/ocsigen/lwt" +doc: "https://ocsigen.org/lwt/manual/" +bug-reports: "https://github.com/ocsigen/lwt/issues" +license: "LGPL with OpenSSL linking exception" +dev-repo: "https://github.com/ocsigen/lwt.git" +build: [ [ "jbuilder" "build" "-p" name "-j" jobs ] ] +build-test: [ [ "jbuilder" "runtest" ] ] +depends: [ + "ocamlfind" {build & >= "1.5.0"} + "jbuilder" { build & >= "1.0+beta9" } + "lwt-core" +] + diff --git a/lwt-ppx.opam b/lwt-ppx.opam new file mode 100644 index 0000000000..c2b0ec5d3e --- /dev/null +++ b/lwt-ppx.opam @@ -0,0 +1,29 @@ +opam-version: "1.2" +name: "lwt" +version: "dev" +maintainer: [ + "Anton Bachin " + "Mauricio Fernandez " + "Simon Cruanes " +] +authors: [ + "Jérôme Vouillon" + "Jérémie Dimino" +] +homepage: "https://github.com/ocsigen/lwt" +doc: "https://ocsigen.org/lwt/manual/" +bug-reports: "https://github.com/ocsigen/lwt/issues" +license: "LGPL with OpenSSL linking exception" +dev-repo: "https://github.com/ocsigen/lwt.git" +build: [ [ "jbuilder" "build" "-p" name "-j" jobs ] ] +build-test: [ [ "jbuilder" "runtest" ] ] +depends: [ + "ocamlfind" {build & >= "1.5.0"} + "jbuilder" { build & >= "1.0+beta9" } + "lwt-core" # is this really needed, or only sensible? + "ppx_tools_versioned" + "ocaml-migrate-parsetree" +] + + + diff --git a/lwt-preemptive.opam b/lwt-preemptive.opam new file mode 100644 index 0000000000..b7b3c50974 --- /dev/null +++ b/lwt-preemptive.opam @@ -0,0 +1,27 @@ +opam-version: "1.2" +name: "lwt" +version: "dev" +maintainer: [ + "Anton Bachin " + "Mauricio Fernandez " + "Simon Cruanes " +] +authors: [ + "Jérôme Vouillon" + "Jérémie Dimino" +] +homepage: "https://github.com/ocsigen/lwt" +doc: "https://ocsigen.org/lwt/manual/" +bug-reports: "https://github.com/ocsigen/lwt/issues" +license: "LGPL with OpenSSL linking exception" +dev-repo: "https://github.com/ocsigen/lwt.git" +build: [ [ "jbuilder" "build" "-p" name "-j" jobs ] ] +build-test: [ [ "jbuilder" "runtest" ] ] +depends: [ + "ocamlfind" {build & >= "1.5.0"} + "jbuilder" { build & >= "1.0+beta9" } + "lwt-unix" + ("base-threads" | "conf-libev") # is this really for lwt-unix or lwt-preemptive +] + + diff --git a/lwt-simple-top.opam b/lwt-simple-top.opam new file mode 100644 index 0000000000..a8af69d39e --- /dev/null +++ b/lwt-simple-top.opam @@ -0,0 +1,27 @@ +opam-version: "1.2" +name: "lwt" +version: "dev" +maintainer: [ + "Anton Bachin " + "Mauricio Fernandez " + "Simon Cruanes " +] +authors: [ + "Jérôme Vouillon" + "Jérémie Dimino" +] +homepage: "https://github.com/ocsigen/lwt" +doc: "https://ocsigen.org/lwt/manual/" +bug-reports: "https://github.com/ocsigen/lwt/issues" +license: "LGPL with OpenSSL linking exception" +dev-repo: "https://github.com/ocsigen/lwt.git" +build: [ [ "jbuilder" "build" "-p" name "-j" jobs ] ] +build-test: [ [ "jbuilder" "runtest" ] ] +depends: [ + "ocamlfind" {build & >= "1.5.0"} + "jbuilder" { build & >= "1.0+beta9" } + "lwt-core" + "lwt-unix" +] + + diff --git a/lwt-syntax.opam b/lwt-syntax.opam new file mode 100644 index 0000000000..0ca1c79eed --- /dev/null +++ b/lwt-syntax.opam @@ -0,0 +1,27 @@ +opam-version: "1.2" +name: "lwt" +version: "dev" +maintainer: [ + "Anton Bachin " + "Mauricio Fernandez " + "Simon Cruanes " +] +authors: [ + "Jérôme Vouillon" + "Jérémie Dimino" +] +homepage: "https://github.com/ocsigen/lwt" +doc: "https://ocsigen.org/lwt/manual/" +bug-reports: "https://github.com/ocsigen/lwt/issues" +license: "LGPL with OpenSSL linking exception" +dev-repo: "https://github.com/ocsigen/lwt.git" +build: [ [ "jbuilder" "build" "-p" name "-j" jobs ] ] +build-test: [ [ "jbuilder" "runtest" ] ] +depends: [ + "ocamlfind" {build & >= "1.5.0"} + "jbuilder" { build & >= "1.0+beta9" } + "lwt-core" # is this really needed, or only sensible? + "camlp4" +] + + diff --git a/lwt-unix.opam b/lwt-unix.opam new file mode 100644 index 0000000000..67093de378 --- /dev/null +++ b/lwt-unix.opam @@ -0,0 +1,28 @@ +opam-version: "1.2" +name: "lwt" +version: "dev" +maintainer: [ + "Anton Bachin " + "Mauricio Fernandez " + "Simon Cruanes " +] +authors: [ + "Jérôme Vouillon" + "Jérémie Dimino" +] +homepage: "https://github.com/ocsigen/lwt" +doc: "https://ocsigen.org/lwt/manual/" +bug-reports: "https://github.com/ocsigen/lwt/issues" +license: "LGPL with OpenSSL linking exception" +dev-repo: "https://github.com/ocsigen/lwt.git" +build: [ [ "jbuilder" "build" "-p" name "-j" jobs ] ] +build-test: [ [ "jbuilder" "runtest" ] ] +depends: [ + "ocamlfind" {build & >= "1.5.0"} + "jbuilder" { build & >= "1.0+beta9" } + "base-unix" + "lwt-core" + "lwt-log" + ("base-threads" | "conf-libev") # is this really for lwt-unix or lwt-preemptive +] + diff --git a/lwt.opam b/lwt.opam index 89aef5d953..8ad6985b53 100644 --- a/lwt.opam +++ b/lwt.opam @@ -15,46 +15,16 @@ doc: "https://ocsigen.org/lwt/manual/" bug-reports: "https://github.com/ocsigen/lwt/issues" license: "LGPL with OpenSSL linking exception" dev-repo: "https://github.com/ocsigen/lwt.git" -build: [ - [ "jbuilder" "build" "-p" name "-j" jobs ] -] -build-test: [ - [ "jbuilder" "runtest" ] -] +build: [ [ "jbuilder" "build" "-p" name "-j" jobs ] ] depends: [ "ocamlfind" {build & >= "1.5.0"} "jbuilder" { build & >= "1.0+beta9" } - "result" - "cppo" {build} - - "configurator" - "ocaml-migrate-parsetree" - "ppx_tools_versioned" - - # XXX because most configuration is not enabled - "base-threads" - "base-unix" - "conf-libev" - "camlp4" + "lwt-core" + "lwt-log" + "lwt-unix" + "lwt-preemptive" + "lwt-simple-top" ] -#depopts: [ -# "base-threads" -# "base-unix" -# "conf-libev" -# "camlp4" -#] -#conflicts: [ -# "ppx_tools" {< "1.0.0" } -#] -available: [ocaml-version >= "4.02.0" & compiler != "4.02.1+BER"] -#messages: [ -# "For module Lwt_ssl, please install package lwt_ssl" -# {ssl:installed & !lwt_ssl:installed} -# "For module Lwt_glib, please install package lwt_glib" -# {lablgtk:installed & !lwt_glib:installed} -# "For module Lwt_react, please install package lwt_react" -# {react:installed & !lwt_react:installed} -#] post-messages: [ "Lwt+jbuilder has some major breaking changes!!!" ] diff --git a/lwt_glib.opam b/lwt_glib.opam new file mode 100644 index 0000000000..c6ff5d5497 --- /dev/null +++ b/lwt_glib.opam @@ -0,0 +1,28 @@ +opam-version: "1.2" +name: "lwt" +version: "dev" +maintainer: [ + "Anton Bachin " + "Mauricio Fernandez " + "Simon Cruanes " +] +authors: [ + "Jérôme Vouillon" + "Jérémie Dimino" +] +homepage: "https://github.com/ocsigen/lwt" +doc: "https://ocsigen.org/lwt/manual/" +bug-reports: "https://github.com/ocsigen/lwt/issues" +license: "LGPL with OpenSSL linking exception" +dev-repo: "https://github.com/ocsigen/lwt.git" +build: [ [ "jbuilder" "build" "-p" name "-j" jobs ] ] +build-test: [ [ "jbuilder" "runtest" ] ] +depends: [ + "ocamlfind" {build & >= "1.5.0"} + "jbuilder" { build & >= "1.0+beta9" } + "lwt-unix" + "configurator" + "lablgtk" +] + + diff --git a/lwt_react.opam b/lwt_react.opam new file mode 100644 index 0000000000..f19f76441a --- /dev/null +++ b/lwt_react.opam @@ -0,0 +1,28 @@ +opam-version: "1.2" +name: "lwt" +version: "dev" +maintainer: [ + "Anton Bachin " + "Mauricio Fernandez " + "Simon Cruanes " +] +authors: [ + "Jérôme Vouillon" + "Jérémie Dimino" +] +homepage: "https://github.com/ocsigen/lwt" +doc: "https://ocsigen.org/lwt/manual/" +bug-reports: "https://github.com/ocsigen/lwt/issues" +license: "LGPL with OpenSSL linking exception" +dev-repo: "https://github.com/ocsigen/lwt.git" +build: [ [ "jbuilder" "build" "-p" name "-j" jobs ] ] +build-test: [ [ "jbuilder" "runtest" ] ] +depends: [ + "ocamlfind" {build & >= "1.5.0"} + "jbuilder" { build & >= "1.0+beta9" } + "lwt-core" + "react" +] + + + diff --git a/lwt_ssl.opam b/lwt_ssl.opam new file mode 100644 index 0000000000..502dd3a8d8 --- /dev/null +++ b/lwt_ssl.opam @@ -0,0 +1,28 @@ +opam-version: "1.2" +name: "lwt" +version: "dev" +maintainer: [ + "Anton Bachin " + "Mauricio Fernandez " + "Simon Cruanes " +] +authors: [ + "Jérôme Vouillon" + "Jérémie Dimino" +] +homepage: "https://github.com/ocsigen/lwt" +doc: "https://ocsigen.org/lwt/manual/" +bug-reports: "https://github.com/ocsigen/lwt/issues" +license: "LGPL with OpenSSL linking exception" +dev-repo: "https://github.com/ocsigen/lwt.git" +build: [ [ "jbuilder" "build" "-p" name "-j" jobs ] ] +build-test: [ [ "jbuilder" "runtest" ] ] +depends: [ + "ocamlfind" {build & >= "1.5.0"} + "jbuilder" { build & >= "1.0+beta9" } + "ssl" + "lwt-unix" +] + + + diff --git a/src/camlp4/jbuild b/src/camlp4/jbuild index d9706a9982..4dcb0bbde3 100644 --- a/src/camlp4/jbuild +++ b/src/camlp4/jbuild @@ -1,23 +1,23 @@ (library ((name lwt_syntax_options) - (public_name lwt.syntax-options) + (public_name lwt-syntax.options) (modules pa_lwt_options) (wrapped false) (libraries (camlp4)))) (library ((name lwt_syntax) - (public_name lwt.syntax) + (public_name lwt-syntax) (modules pa_lwt) (wrapped false) - (libraries (camlp4.extend camlp4.quotations.o lwt.syntax-options)) + (libraries (camlp4 lwt-syntax.options)) (preprocess (action (run camlp4oof ${<}))))) (library ((name lwt_syntax_log) - (public_name lwt.syntax-log) + (public_name lwt-syntax.log) (modules pa_lwt_log) (wrapped false) - (libraries (camlp4.extend camlp4.quotations.o lwt.syntax-options)) + (libraries (camlp4 lwt-syntax.options)) (preprocess (action (run camlp4oof ${<}))))) diff --git a/src/core/jbuild b/src/core/jbuild index 82bdaf64f0..3e8841edb0 100644 --- a/src/core/jbuild +++ b/src/core/jbuild @@ -2,6 +2,6 @@ (library ((name lwt) - (public_name lwt) + (public_name lwt-core) (wrapped false) (libraries (bytes result)))) diff --git a/src/glib/jbuild b/src/glib/jbuild index d17fc4650b..e2736c5503 100644 --- a/src/glib/jbuild +++ b/src/glib/jbuild @@ -2,9 +2,9 @@ (library ((name lwt_glib) - (public_name lwt.glib) + (public_name lwt_glib) (wrapped false) - (libraries (lwt lwt.unix)) + (libraries (lwt-core lwt-unix)) (c_names (lwt_glib_stubs)) (c_flags (:include c_flags.sexp)) (c_library_flags (:include c_library_flags.sexp)))) diff --git a/src/logger/jbuild b/src/logger/jbuild index de12609b54..1c0351cae4 100644 --- a/src/logger/jbuild +++ b/src/logger/jbuild @@ -4,6 +4,6 @@ (library ((name lwt_log) - (public_name "lwt.log") + (public_name lwt-log) (wrapped false) - (libraries (lwt)))) + (libraries (lwt-core)))) diff --git a/src/ppx/.merlin b/src/ppx/.merlin index 0bfd90cf11..00caaa4da1 100644 --- a/src/ppx/.merlin +++ b/src/ppx/.merlin @@ -1,6 +1,6 @@ B ../../_build/default/src/ppx -FLG -open Ppx_js -w -40 -FLG -ppx "../../_build/default/.ppx/ppx_tools_versioned.metaquot_404/ppx.exe --as-ppx --cookie 'library-name="ppx_js"'" +FLG -ppx "../../_build/default/.ppx/ppx_tools_versioned.metaquot_404/ppx.exe --as-ppx --cookie 'library-name="ppx_lwt"'" +FLG -w -40 PKG compiler-libs PKG compiler-libs.common PKG ocaml-migrate-parsetree diff --git a/src/ppx/jbuild b/src/ppx/jbuild index 56f503eaad..ce0411c8cf 100644 --- a/src/ppx/jbuild +++ b/src/ppx/jbuild @@ -1,15 +1,14 @@ (jbuild_version 1) (library - ((name ppx_js) - (public_name lwt.ppx) + ((name ppx_lwt) + (public_name lwt-ppx) (synopsis "Lwt ppx") (modules (ppx_lwt)) (libraries (compiler-libs.common ocaml-migrate-parsetree ppx_tools_versioned)) - (ppx_runtime_libraries (lwt)) + (ppx_runtime_libraries (lwt-core)) (kind ppx_rewriter) - (preprocess (pps (ppx_tools_versioned.metaquot_404))) - )) + (preprocess (pps (ppx_tools_versioned.metaquot_404))))) diff --git a/src/preemptive/jbuild b/src/preemptive/jbuild index a9f90bc174..51b3b4eaf1 100644 --- a/src/preemptive/jbuild +++ b/src/preemptive/jbuild @@ -2,7 +2,7 @@ (library ((name lwt_preemptive) - (public_name lwt.preemptive) + (public_name lwt-preemptive) (wrapped false) - (libraries (lwt lwt.unix threads)))) + (libraries (lwt-core lwt-unix threads)))) diff --git a/src/react/jbuild b/src/react/jbuild index 213caf1735..ee7a571127 100644 --- a/src/react/jbuild +++ b/src/react/jbuild @@ -2,7 +2,7 @@ (library ((name lwt_react) - (public_name lwt.react) + (public_name lwt_react) (wrapped false) - (libraries (lwt react)))) + (libraries (lwt-core react)))) diff --git a/src/simple_top/jbuild b/src/simple_top/jbuild index f85b03e0c6..5cc1c08e13 100644 --- a/src/simple_top/jbuild +++ b/src/simple_top/jbuild @@ -2,7 +2,7 @@ (library ((name lwt_simple_top) - (public_name lwt.simple-top) + (public_name lwt-simple-top) (wrapped false) - (libraries (lwt lwt.unix compiler-libs.common)))) + (libraries (lwt-core lwt-unix compiler-libs.common)))) diff --git a/src/ssl/jbuild b/src/ssl/jbuild index cc0e6f5a31..1703000bdd 100644 --- a/src/ssl/jbuild +++ b/src/ssl/jbuild @@ -2,7 +2,7 @@ (library ((name lwt_ssl) - (public_name lwt.ssl) + (public_name lwt_ssl) (wrapped false) - (libraries (ssl lwt.unix)))) + (libraries (ssl lwt-unix)))) diff --git a/src/unix/jbuild b/src/unix/jbuild index 210addd963..0ca6b2656b 100644 --- a/src/unix/jbuild +++ b/src/unix/jbuild @@ -68,9 +68,9 @@ (library ((name lwt_unix) - (public_name lwt.unix) + (public_name lwt-unix) (wrapped false) - (libraries (lwt lwt.log unix bigarray)) + (libraries (lwt-core lwt-log unix bigarray)) (c_names ( lwt_unix_stubs lwt_libev_stubs diff --git a/tests/core/jbuild b/tests/core/jbuild index ba7d7f48d7..2662f313ce 100644 --- a/tests/core/jbuild +++ b/tests/core/jbuild @@ -6,5 +6,6 @@ (alias ((name runtest) + (package lwt-core) (action (run ${exe:main.exe})))) diff --git a/tests/jbuild b/tests/jbuild index a28330f0fc..81173baa89 100644 --- a/tests/jbuild +++ b/tests/jbuild @@ -3,5 +3,5 @@ (library ((name "lwttester") (wrapped false) - (libraries (lwt unix lwt.unix)))) + (libraries (lwt-core unix lwt-unix)))) diff --git a/tests/ppx/jbuild b/tests/ppx/jbuild index 1f01428890..abcb532a1f 100644 --- a/tests/ppx/jbuild +++ b/tests/ppx/jbuild @@ -3,10 +3,11 @@ (executable ((name main) (libraries (lwttester)) - (preprocess (pps (lwt.ppx))))) + (preprocess (pps (lwt-ppx))))) (alias ((name runtest) + (package lwt-ppx) (action (run ${exe:main.exe})))) diff --git a/tests/preemptive/jbuild b/tests/preemptive/jbuild index 199bf5b0ec..cf5c4f27d2 100644 --- a/tests/preemptive/jbuild +++ b/tests/preemptive/jbuild @@ -2,10 +2,11 @@ (executable ((name main) - (libraries (lwt.preemptive lwttester)))) + (libraries (lwt-preemptive lwttester)))) (alias ((name runtest) + (package lwt-preemptive) (action (run ${exe:main.exe})))) diff --git a/tests/react/jbuild b/tests/react/jbuild index 23fb28a2d3..e7574c7f3f 100644 --- a/tests/react/jbuild +++ b/tests/react/jbuild @@ -2,9 +2,10 @@ (executable ((name main) - (libraries (lwt.react lwttester)))) + (libraries (lwt_react lwttester)))) (alias ((name runtest) + (package lwt_react) (action (run ${exe:main.exe})))) diff --git a/tests/unix/jbuild b/tests/unix/jbuild index 121435b4b5..4c880d4f79 100644 --- a/tests/unix/jbuild +++ b/tests/unix/jbuild @@ -11,5 +11,6 @@ (alias ((name runtest) + (package lwt-unix) (action (run ${exe:main.exe})))) From 291f60536fb98864d87bf1e8bd68a605035fa2f1 Mon Sep 17 00:00:00 2001 From: andrewray Date: Tue, 23 May 2017 11:11:30 +0100 Subject: [PATCH 06/46] add lwt.ppx to lwt. notes on a few bad package builds --- bad_packages.md | 38 ++++++++++++++++++++++++++++++++++++++ lwt.opam | 1 + 2 files changed, 39 insertions(+) create mode 100644 bad_packages.md diff --git a/bad_packages.md b/bad_packages.md new file mode 100644 index 0000000000..091bcfd633 --- /dev/null +++ b/bad_packages.md @@ -0,0 +1,38 @@ +A few errors found by randomly installing some lwt packages. + +All seem to point to libraries using lwt.unix but only linking to lwt. + +# irmin_watcher + +``` +# File "src/irmin_watcher_polling.ml", line 94, characters 28-42: +# Error: Unbound module Lwt_unix +# Command exited with code 2. +``` + +# biocaml + +``` +# + ocamlfind ocamlc -annot -bin-annot -c -g -I lib -I lib/lwt -o lib/lwt/future_lwt.cmi -short-paths -thread -w A-4-33-41-42-44-45-48 -package camlzip,cfstream,core_kernel,lwt,lwt.ppx,ppx_compare,ppx_sexp_conv,re.perl,uri,xmlm lib/lwt/future_lwt.mli +# findlib: [WARNING] Interface topdirs.cmi occurs in several directories: /home/andyman/.opam/4.04.0/lib/ocaml/compiler-libs, /home/andyman/.opam/4.04.0/lib/ocaml +# File "lib/lwt/future_lwt.mli", line 7, characters 22-42: +# Error: Unbound module Lwt_io +# Command exited with code 2. +# _build/project.mk:17: recipe for target 'byte' failed +``` + +# mirage-profile + +``` +# File "lwt/dns_resolver_unix.ml", line 35, characters 2-10: +# Error: Unbound module Lwt_unix +# Command exited with code 2. +``` + +# dns + +``` +# File "lwt/dns_resolver_unix.ml", line 35, characters 2-10: +# Error: Unbound module Lwt_unix +``` + diff --git a/lwt.opam b/lwt.opam index 8ad6985b53..dde4c88c35 100644 --- a/lwt.opam +++ b/lwt.opam @@ -24,6 +24,7 @@ depends: [ "lwt-unix" "lwt-preemptive" "lwt-simple-top" + "lwt-ppx" ] post-messages: [ "Lwt+jbuilder has some major breaking changes!!!" From e721933e708ba2bf6263c43573df8e975d78922b Mon Sep 17 00:00:00 2001 From: andrewray Date: Wed, 24 May 2017 00:35:33 +0100 Subject: [PATCH 07/46] add parsing of ocamlc -config to discover.ml this should configure unix the same way as oasis did (by default). --- Makefile | 12 ++++-- lwt-unix.opam | 1 + src/unix/config/discover.ml | 79 +++++++++++++++++++++++++++---------- src/unix/jbuild | 20 +++++----- 4 files changed, 78 insertions(+), 34 deletions(-) diff --git a/Makefile b/Makefile index 7dba1f62ff..9e762ca085 100644 --- a/Makefile +++ b/Makefile @@ -30,11 +30,17 @@ setup.exe: setup.ml setup: $(SETUP) build: + jbuilder build \ + lwt-core.install \ + lwt-log.install \ + lwt-unix.install \ + lwt-preemptive.install \ + lwt-simple-top.install \ + lwt-ppx.install + +build-a: jbuilder build @install -doc: $(SETUP) setup.data build - ./$(SETUP) -doc $(DOCFLAGS) - doc-api: $(SETUP) setup.data build ./$(SETUP) -build lwt-api.docdir/index.html diff --git a/lwt-unix.opam b/lwt-unix.opam index 67093de378..b72bd36066 100644 --- a/lwt-unix.opam +++ b/lwt-unix.opam @@ -20,6 +20,7 @@ build-test: [ [ "jbuilder" "runtest" ] ] depends: [ "ocamlfind" {build & >= "1.5.0"} "jbuilder" { build & >= "1.0+beta9" } + "cppo" { build } "base-unix" "lwt-core" "lwt-log" diff --git a/src/unix/config/discover.ml b/src/unix/config/discover.ml index e036d14d64..9c1fa4f278 100644 --- a/src/unix/config/discover.ml +++ b/src/unix/config/discover.ml @@ -309,15 +309,16 @@ CAMLprim value lwt_test() +-----------------------------------------------------------------+ *) let ocamlc = ref "ocamlfind ocamlc" +let ocamlc_config = ref "" let ext_obj = ref ".o" let exec_name = ref "a.out" let use_libev = ref true -let use_glib = ref false -let use_pthread = ref true -let use_unix = ref true -let os_type = ref "Unix" +let use_glib = false (* glib configuration is external *) +let use_pthread = Sys.os_type <> "Win32" (* as per default in oasis file *) +let use_unix = true (* only called in the context of installing lwt-unix *) let android_target = ref false let ccomp_type = ref "cc" +let system = ref "" let libev_default = ref true let debug = ref (try Sys.getenv "DEBUG" = "y" with Not_found -> false) @@ -513,13 +514,10 @@ let arg_bool r = let () = let args = [ "-ocamlc", Arg.Set_string ocamlc, " ocamlc"; + "-ocamlc_config", Arg.Set_string ocamlc_config, " ocamlc config"; "-ext-obj", Arg.Set_string ext_obj, " C object files extension"; "-exec-name", Arg.Set_string exec_name, " name of the executable produced by ocamlc"; "-use-libev", arg_bool use_libev, " whether to check for libev"; - "-use-glib", arg_bool use_glib, " whether to check for glib"; - "-use-pthread", arg_bool use_pthread, " whether to use pthread"; - "-use-unix", arg_bool use_unix, " whether to build lwt.unix"; - "-os-type", Arg.Set_string os_type, " type of the target os"; "-android-target", arg_bool android_target, " compiles for Android"; "-ccomp-type", Arg.Set_string ccomp_type, " C compiler type"; "-libev_default", arg_bool libev_default, " whether to use the libev backend by default"; @@ -527,7 +525,7 @@ let () = Arg.parse args ignore "check for external C libraries and available features\noptions are:"; (* Check nothing if we do not build lwt.unix. *) - if not !use_unix then exit 0; + if not use_unix then exit 0; (* Put the caml code into a temporary file. *) let file, oc = Filename.open_temp_file "lwt_caml" ".ml" in @@ -547,6 +545,52 @@ let () = safe_remove (Filename.chop_extension !caml_file ^ ".cmi"); safe_remove (Filename.chop_extension !caml_file ^ ".cmo")); + (* read ocamlc -config file, if provided *) + let get_ocamlc_config () = + let f = open_in !ocamlc_config in + let cfg line = + let idx = String.index line ':' in + String.sub line 0 idx, + String.sub line (idx + 2) (String.length line - idx - 2) + in + let input_line () = try Some(input_line f) with End_of_file -> None in + let rec lines () = + match input_line () with + | None -> [] + | Some(x) -> cfg x :: lines () + in + let cfg = lines () in + let () = close_in f in + cfg + in + let ocamlc_configs = + try if !ocamlc_config <> "" then get_ocamlc_config () else [] + with _ -> + let () = printf "failed to read ocamlc -config\n" in + exit 1 + in + (* get params from ocamlc -config, if provided *) + let () = + if !ocamlc_config <> "" then begin + let set var name = + try + var := List.assoc name ocamlc_configs; + printf "found config var %s: %s %s\n" name (String.make (29 - String.length name) '.') !var + with Not_found -> + printf "Couldn't find var '%s' in ocamlc -config\n" name; + exit 1 + in + set ext_obj "ext_obj"; + set exec_name "default_executable_name"; + set ccomp_type "ccomp_type"; + set system "system"; + libev_default := List.mem !system (* from _oasis *) + ["linux"; "linux_elf"; "linux_aout"; "linux_eabi"; "linux_eabihf"]; + printf "system = %s\n" !system + end + in + + let exit status = if status <> 0 then begin if !debug then printf " @@ -562,7 +606,7 @@ Run with DEBUG=y for more details. let setup_data = ref [] in (* Test for pkg-config. *) - test_feature ~do_check:(!use_libev || !use_glib) "pkg-config" "" + test_feature ~do_check:(!use_libev || use_glib) "pkg-config" "" (fun () -> ksprintf Sys.command "pkg-config --version > %s 2>&1" !log_file = 0); @@ -646,8 +690,8 @@ You may be missing core components (compiler, ncurses, etc) end; test_feature ~do_check:!use_libev "libev" "HAVE_LIBEV" test_libev; - test_feature ~do_check:!use_pthread "pthread" "HAVE_PTHREAD" test_pthread; - test_feature ~do_check:!use_glib "glib" "" test_glib; + test_feature ~do_check:use_pthread "pthread" "HAVE_PTHREAD" test_pthread; + test_feature ~do_check:use_glib "glib" "" test_glib; if !not_available <> [] then begin if not have_pkg_config then @@ -669,7 +713,7 @@ Missing C libraries: %s exit 1 end; - if !os_type <> "Win32" && not !use_pthread then begin + if Sys.os_type <> "Win32" && not use_pthread then begin printf " No threading library available! @@ -680,7 +724,7 @@ Lwt can use pthread or the win32 API. exit 1 end; - let do_check = !os_type <> "Win32" in + let do_check = Sys.os_type <> "Win32" in test_feature ~do_check "eventfd" "HAVE_EVENTFD" (fun () -> test_code ([], []) eventfd_code); test_feature ~do_check "fd passing" "HAVE_FD_PASSING" (fun () -> test_code ([], []) fd_passing_code); test_feature ~do_check:(do_check && not !android_target) @@ -719,7 +763,7 @@ Lwt can use pthread or the win32 API. "let _HAVE_GET_CREDENTIALS = %s\n" (String.concat " || " (List.map (fun s -> "_" ^ s) get_cred_vars)); - if !os_type = "Win32" then begin + if Sys.os_type = "Win32" then begin output_string config "#define LWT_ON_WINDOWS\n"; end else begin output_string config "//#define LWT_ON_WINDOWS\n"; @@ -791,9 +835,4 @@ Lwt can use pthread or the win32 API. close_out config; close_out config_ml -(* - (* Generate stubs. *) - print_endline "Generating C stubs..."; - exit (Sys.command "ocaml src/unix/gen_stubs.ml") -*) diff --git a/src/unix/jbuild b/src/unix/jbuild index 0ca6b2656b..a6319f4335 100644 --- a/src/unix/jbuild +++ b/src/unix/jbuild @@ -14,20 +14,18 @@ ;; lwt discover.ml +(rule + ((targets (ocamlc_config)) + (action (with-stdout-to ${@} (run ${OCAMLC} -config))))) + (rule ((targets (lwt_config.h lwt_config.ml)) - (deps (config/discover.exe)) + (deps (config/discover.exe ocamlc_config)) (action (run ${<} - -ext-obj .o ;; windows ... .obj? - -exec-name a.out ;; windows ... a.exe? - -use-libev ${lib-available:conf-libev} - -os-type Unix ;; ??? Win32 - -use-glib true ;; ??? optionally installed - -ccomp-type cc ;; ??? msvc - -use-pthread ${lib-available:threads} - -use-unix ${lib-available:unix} ;; but we are building for unix! - -android-target false ;; presumably modified in the android repository - -libev_default true ;; ??? if c library exists + -ocamlc ${OCAMLC} ;; avoid call to ocamlfind + -ocamlc_config ocamlc_config ;; generated by the rule + -use-libev ${lib-available:conf-libev} ;; from installed world + -android-target false ;; XXX fixme )))) ;; gen_stubs.ml From a988946f0b8d2310dfa639a5918f9834abfb01ff Mon Sep 17 00:00:00 2001 From: andrewray Date: Wed, 24 May 2017 00:55:29 +0100 Subject: [PATCH 08/46] rename syntax to camlp4. Add -p to opam test commands --- META.lwt.template | 6 +++--- lwt-syntax.opam => lwt-camlp4.opam | 5 ++--- lwt-core.opam | 3 +-- lwt-log.opam | 3 +-- lwt-ppx.opam | 5 ++--- lwt-preemptive.opam | 5 ++--- lwt-simple-top.opam | 3 +-- lwt-unix.opam | 8 ++++---- lwt.opam | 1 - lwt_glib.opam | 3 +-- lwt_react.opam | 5 +---- lwt_ssl.opam | 3 +-- src/camlp4/jbuild | 16 ++++++++-------- 13 files changed, 27 insertions(+), 39 deletions(-) rename lwt-syntax.opam => lwt-camlp4.opam (78%) diff --git a/META.lwt.template b/META.lwt.template index e918c9178d..007f0a865c 100644 --- a/META.lwt.template +++ b/META.lwt.template @@ -25,14 +25,14 @@ package "simple-top" ( ) package "syntax" ( - requires = "camlp4 lwt-syntax lwt.syntax.options" + requires = "camlp4 lwt-camlp4 lwt.syntax.options" package "options" ( - requires = "lwt-syntax.options" + requires = "lwt-camlp4.options" ) package "log" ( - requires = "lwt-syntax.log" + requires = "lwt-camlp4.log" ) ) diff --git a/lwt-syntax.opam b/lwt-camlp4.opam similarity index 78% rename from lwt-syntax.opam rename to lwt-camlp4.opam index 0ca1c79eed..e092308cc0 100644 --- a/lwt-syntax.opam +++ b/lwt-camlp4.opam @@ -16,11 +16,10 @@ bug-reports: "https://github.com/ocsigen/lwt/issues" license: "LGPL with OpenSSL linking exception" dev-repo: "https://github.com/ocsigen/lwt.git" build: [ [ "jbuilder" "build" "-p" name "-j" jobs ] ] -build-test: [ [ "jbuilder" "runtest" ] ] +build-test: [ [ "jbuilder" "runtest" "-p" name ] ] depends: [ - "ocamlfind" {build & >= "1.5.0"} "jbuilder" { build & >= "1.0+beta9" } - "lwt-core" # is this really needed, or only sensible? + "lwt-core" "camlp4" ] diff --git a/lwt-core.opam b/lwt-core.opam index f4c5b68380..3bb8ca7f5a 100644 --- a/lwt-core.opam +++ b/lwt-core.opam @@ -16,9 +16,8 @@ bug-reports: "https://github.com/ocsigen/lwt/issues" license: "LGPL with OpenSSL linking exception" dev-repo: "https://github.com/ocsigen/lwt.git" build: [ [ "jbuilder" "build" "-p" name "-j" jobs ] ] -build-test: [ [ "jbuilder" "runtest" ] ] +build-test: [ [ "jbuilder" "runtest" "-p" name ] ] depends: [ - "ocamlfind" {build & >= "1.5.0"} "jbuilder" { build & >= "1.0+beta9" } "result" ] diff --git a/lwt-log.opam b/lwt-log.opam index cf088dac66..a88cb97267 100644 --- a/lwt-log.opam +++ b/lwt-log.opam @@ -16,9 +16,8 @@ bug-reports: "https://github.com/ocsigen/lwt/issues" license: "LGPL with OpenSSL linking exception" dev-repo: "https://github.com/ocsigen/lwt.git" build: [ [ "jbuilder" "build" "-p" name "-j" jobs ] ] -build-test: [ [ "jbuilder" "runtest" ] ] +build-test: [ [ "jbuilder" "runtest" "-p" name ] ] depends: [ - "ocamlfind" {build & >= "1.5.0"} "jbuilder" { build & >= "1.0+beta9" } "lwt-core" ] diff --git a/lwt-ppx.opam b/lwt-ppx.opam index c2b0ec5d3e..8ecb89fbe8 100644 --- a/lwt-ppx.opam +++ b/lwt-ppx.opam @@ -16,11 +16,10 @@ bug-reports: "https://github.com/ocsigen/lwt/issues" license: "LGPL with OpenSSL linking exception" dev-repo: "https://github.com/ocsigen/lwt.git" build: [ [ "jbuilder" "build" "-p" name "-j" jobs ] ] -build-test: [ [ "jbuilder" "runtest" ] ] +build-test: [ [ "jbuilder" "runtest" "-p" name ] ] depends: [ - "ocamlfind" {build & >= "1.5.0"} "jbuilder" { build & >= "1.0+beta9" } - "lwt-core" # is this really needed, or only sensible? + "lwt-core" # not needed to build, but is required at runtime "ppx_tools_versioned" "ocaml-migrate-parsetree" ] diff --git a/lwt-preemptive.opam b/lwt-preemptive.opam index b7b3c50974..81f9860a83 100644 --- a/lwt-preemptive.opam +++ b/lwt-preemptive.opam @@ -16,12 +16,11 @@ bug-reports: "https://github.com/ocsigen/lwt/issues" license: "LGPL with OpenSSL linking exception" dev-repo: "https://github.com/ocsigen/lwt.git" build: [ [ "jbuilder" "build" "-p" name "-j" jobs ] ] -build-test: [ [ "jbuilder" "runtest" ] ] +build-test: [ [ "jbuilder" "runtest" "-p" name ] ] depends: [ - "ocamlfind" {build & >= "1.5.0"} "jbuilder" { build & >= "1.0+beta9" } "lwt-unix" - ("base-threads" | "conf-libev") # is this really for lwt-unix or lwt-preemptive + "base-threads" ] diff --git a/lwt-simple-top.opam b/lwt-simple-top.opam index a8af69d39e..920be447d4 100644 --- a/lwt-simple-top.opam +++ b/lwt-simple-top.opam @@ -16,9 +16,8 @@ bug-reports: "https://github.com/ocsigen/lwt/issues" license: "LGPL with OpenSSL linking exception" dev-repo: "https://github.com/ocsigen/lwt.git" build: [ [ "jbuilder" "build" "-p" name "-j" jobs ] ] -build-test: [ [ "jbuilder" "runtest" ] ] +build-test: [ [ "jbuilder" "runtest" "-p" name ] ] depends: [ - "ocamlfind" {build & >= "1.5.0"} "jbuilder" { build & >= "1.0+beta9" } "lwt-core" "lwt-unix" diff --git a/lwt-unix.opam b/lwt-unix.opam index b72bd36066..8f6f31dcf3 100644 --- a/lwt-unix.opam +++ b/lwt-unix.opam @@ -16,14 +16,14 @@ bug-reports: "https://github.com/ocsigen/lwt/issues" license: "LGPL with OpenSSL linking exception" dev-repo: "https://github.com/ocsigen/lwt.git" build: [ [ "jbuilder" "build" "-p" name "-j" jobs ] ] -build-test: [ [ "jbuilder" "runtest" ] ] +build-test: [ [ "jbuilder" "runtest" "-p" name ] ] depends: [ - "ocamlfind" {build & >= "1.5.0"} "jbuilder" { build & >= "1.0+beta9" } "cppo" { build } "base-unix" "lwt-core" "lwt-log" - ("base-threads" | "conf-libev") # is this really for lwt-unix or lwt-preemptive ] - +depopts: [ + "conf-libev" +] diff --git a/lwt.opam b/lwt.opam index dde4c88c35..6cd2681fda 100644 --- a/lwt.opam +++ b/lwt.opam @@ -17,7 +17,6 @@ license: "LGPL with OpenSSL linking exception" dev-repo: "https://github.com/ocsigen/lwt.git" build: [ [ "jbuilder" "build" "-p" name "-j" jobs ] ] depends: [ - "ocamlfind" {build & >= "1.5.0"} "jbuilder" { build & >= "1.0+beta9" } "lwt-core" "lwt-log" diff --git a/lwt_glib.opam b/lwt_glib.opam index c6ff5d5497..61e8e9f7a5 100644 --- a/lwt_glib.opam +++ b/lwt_glib.opam @@ -16,9 +16,8 @@ bug-reports: "https://github.com/ocsigen/lwt/issues" license: "LGPL with OpenSSL linking exception" dev-repo: "https://github.com/ocsigen/lwt.git" build: [ [ "jbuilder" "build" "-p" name "-j" jobs ] ] -build-test: [ [ "jbuilder" "runtest" ] ] +build-test: [ [ "jbuilder" "runtest" "-p" name ] ] depends: [ - "ocamlfind" {build & >= "1.5.0"} "jbuilder" { build & >= "1.0+beta9" } "lwt-unix" "configurator" diff --git a/lwt_react.opam b/lwt_react.opam index f19f76441a..9adc3618cf 100644 --- a/lwt_react.opam +++ b/lwt_react.opam @@ -16,13 +16,10 @@ bug-reports: "https://github.com/ocsigen/lwt/issues" license: "LGPL with OpenSSL linking exception" dev-repo: "https://github.com/ocsigen/lwt.git" build: [ [ "jbuilder" "build" "-p" name "-j" jobs ] ] -build-test: [ [ "jbuilder" "runtest" ] ] +build-test: [ [ "jbuilder" "runtest" "-p" name ] ] depends: [ - "ocamlfind" {build & >= "1.5.0"} "jbuilder" { build & >= "1.0+beta9" } "lwt-core" "react" ] - - diff --git a/lwt_ssl.opam b/lwt_ssl.opam index 502dd3a8d8..db0ad6a4e6 100644 --- a/lwt_ssl.opam +++ b/lwt_ssl.opam @@ -16,9 +16,8 @@ bug-reports: "https://github.com/ocsigen/lwt/issues" license: "LGPL with OpenSSL linking exception" dev-repo: "https://github.com/ocsigen/lwt.git" build: [ [ "jbuilder" "build" "-p" name "-j" jobs ] ] -build-test: [ [ "jbuilder" "runtest" ] ] +build-test: [ [ "jbuilder" "runtest" "-p" name ] ] depends: [ - "ocamlfind" {build & >= "1.5.0"} "jbuilder" { build & >= "1.0+beta9" } "ssl" "lwt-unix" diff --git a/src/camlp4/jbuild b/src/camlp4/jbuild index 4dcb0bbde3..dfe0b55c6f 100644 --- a/src/camlp4/jbuild +++ b/src/camlp4/jbuild @@ -1,23 +1,23 @@ (library - ((name lwt_syntax_options) - (public_name lwt-syntax.options) + ((name lwt_camlp4_options) + (public_name lwt-camlp4.options) (modules pa_lwt_options) (wrapped false) (libraries (camlp4)))) (library - ((name lwt_syntax) - (public_name lwt-syntax) + ((name lwt_camlp4) + (public_name lwt-camlp4) (modules pa_lwt) (wrapped false) - (libraries (camlp4 lwt-syntax.options)) + (libraries (camlp4 lwt-camlp4.options)) (preprocess (action (run camlp4oof ${<}))))) (library - ((name lwt_syntax_log) - (public_name lwt-syntax.log) + ((name lwt_camlp4_log) + (public_name lwt-camlp4.log) (modules pa_lwt_log) (wrapped false) - (libraries (camlp4 lwt-syntax.options)) + (libraries (camlp4 lwt-camlp4.options)) (preprocess (action (run camlp4oof ${<}))))) From a38493370fda714a814dda40c08752b0938e3858 Mon Sep 17 00:00:00 2001 From: andrewray Date: Wed, 24 May 2017 00:56:33 +0100 Subject: [PATCH 09/46] missed a syntax->camlp4 conversion in META --- META.lwt.template | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/META.lwt.template b/META.lwt.template index 007f0a865c..7917e2d60b 100644 --- a/META.lwt.template +++ b/META.lwt.template @@ -25,7 +25,7 @@ package "simple-top" ( ) package "syntax" ( - requires = "camlp4 lwt-camlp4 lwt.syntax.options" + requires = "camlp4 lwt-camlp4 lwt.camlp4.options" package "options" ( requires = "lwt-camlp4.options" From 2da87644d8620d13ace361b8208d7c3ea647e65d Mon Sep 17 00:00:00 2001 From: andrewray Date: Wed, 24 May 2017 01:18:29 +0100 Subject: [PATCH 10/46] add proper configuration for glib --- Makefile | 2 +- lwt_glib.opam | 3 +- src/glib/config/discover.ml | 102 ++++++++++++++++++++++++++++++------ src/glib/config/jbuild | 2 +- src/glib/jbuild | 22 ++++---- 5 files changed, 102 insertions(+), 29 deletions(-) diff --git a/Makefile b/Makefile index 9e762ca085..64da8888a1 100644 --- a/Makefile +++ b/Makefile @@ -38,7 +38,7 @@ build: lwt-simple-top.install \ lwt-ppx.install -build-a: +build-all: jbuilder build @install doc-api: $(SETUP) setup.data build diff --git a/lwt_glib.opam b/lwt_glib.opam index 61e8e9f7a5..7be6e22987 100644 --- a/lwt_glib.opam +++ b/lwt_glib.opam @@ -20,7 +20,8 @@ build-test: [ [ "jbuilder" "runtest" "-p" name ] ] depends: [ "jbuilder" { build & >= "1.0+beta9" } "lwt-unix" - "configurator" + "base" { build } # needed for discover.ml + "stdio" { build } # ...but only to write the sexps "lablgtk" ] diff --git a/src/glib/config/discover.ml b/src/glib/config/discover.ml index e183546660..368c3ffe5b 100644 --- a/src/glib/config/discover.ml +++ b/src/glib/config/discover.ml @@ -1,24 +1,92 @@ open Base open Stdio -module C = Configurator -let write_sexp fn sexp = - Out_channel.write_all fn ~data:(Sexp.to_string sexp) +(* This is largely based on the Glib-related code in the main build system, + though rewritten somewhat. *) -let () = - C.main ~name:"glib-2.0" (fun c -> - let default : C.Pkg_config.package_conf = - { libs = ["-lglib-2.0"] - ; cflags = [] - } - in - let conf = - match C.Pkg_config.get c with - | None -> default - | Some pc -> - Option.value (C.Pkg_config.query pc ~package:"glib-2.0") ~default +let split = + let regexp = Str.regexp " +" in + fun s -> Str.split regexp s + +(* Runs pkg-config with the given arguments. *) +let pkg_config arguments = + (* Run the pkg-config command. *) + let command = Printf.sprintf "pkg-config %s" arguments in + let input_channel = Unix.open_process_in command in + let result = + try Caml.Pervasives.input_line input_channel + with End_of_file -> "" + in + let status = Unix.close_process_in input_channel in + + match status with + | Unix.WEXITED 0 -> + (* On success, split the output of pkg-config result (arguments for the + compiler) into tokens. *) + let result = split result in + + (* Then, look for any -Wl,-framework tokens. Replace them with -framework + tokens, and remove the prefix "-Wl," from the next token. This is + necessary because pkg-config emits options for the compiler to pass to + the linker, so they are prefixed with "-Wl,". However, ocamlmktop + expects the -framework options unprefixed. *) + let rec unprefix_framework_arguments acc = function + | [] -> List.rev acc + | "-Wl,-framework"::framework::rest -> + let framework = String.sub framework 4 (String.length framework - 4) in + unprefix_framework_arguments (framework::"-framework"::acc) rest + | argument::rest -> + unprefix_framework_arguments (argument::acc) rest in + let result = unprefix_framework_arguments [] result in + + result + + | _ -> + Caml.Printf.eprintf "Command failed: %s" command; + Caml.exit 1 + +(* read ocamlc -config file, if provided *) +let get_ocamlc_config name = + let open Caml in + let f = open_in name in + let cfg line = + let idx = String.index line ':' in + String.sub line 0 idx, + String.sub line (idx + 2) (String.length line - idx - 2) + in + let input_line () = try Some(input_line f) with End_of_file -> None in + let rec lines () = + match input_line () with + | None -> [] + | Some(x) -> cfg x :: lines () + in + let cfg = lines () in + let () = close_in f in + cfg + +let ccomp_type = + let open Caml in + try + let cfg = get_ocamlc_config Sys.argv.(1) in + List.assoc "ccomp_type" cfg + with _ -> + let () = Printf.eprintf "failed to read ccomp_type from ocamlc -config\n" in + exit 1 + +let cflags = pkg_config "--cflags glib-2.0" +let libs = + if String.compare ccomp_type "msvc" = 0 then + pkg_config "--libs-only-L glib-2.0" @ + pkg_config "--libs-only-l --msvc_syntax glib-2.0" + else + pkg_config "--libs glib-2.0" + + +let write_sexp fn sexp = Out_channel.write_all fn ~data:(Sexp.to_string sexp) + - write_sexp "c_flags.sexp" (sexp_of_list sexp_of_string conf.cflags); - write_sexp "c_library_flags.sexp" (sexp_of_list sexp_of_string conf.libs)) +let () = + write_sexp "glib_c_flags.sexp" (sexp_of_list sexp_of_string cflags); + write_sexp "glib_c_library_flags.sexp" (sexp_of_list sexp_of_string libs) diff --git a/src/glib/config/jbuild b/src/glib/config/jbuild index e9c1f41a3e..54d77565f8 100644 --- a/src/glib/config/jbuild +++ b/src/glib/config/jbuild @@ -2,4 +2,4 @@ (executables ((names (discover)) - (libraries (base stdio configurator)))) + (libraries (base stdio unix str)))) diff --git a/src/glib/jbuild b/src/glib/jbuild index e2736c5503..1cf4ca40cf 100644 --- a/src/glib/jbuild +++ b/src/glib/jbuild @@ -6,15 +6,19 @@ (wrapped false) (libraries (lwt-core lwt-unix)) (c_names (lwt_glib_stubs)) - (c_flags (:include c_flags.sexp)) - (c_library_flags (:include c_library_flags.sexp)))) + (c_flags (:include glib_c_flags.sexp)) + (c_library_flags (:include glib_c_library_flags.sexp)))) + +;; implements pkg-config logic from glib/myocamlbuild -;; -;; see src/glib/myocamlbuild.ml for functionality needed for windows -;; (rule - ((targets (c_flags.sexp - c_library_flags.sexp)) - (deps (config/discover.exe)) - (action (run ${<} -ocamlc ${OCAMLC})))) + ((targets (glib_c_flags.sexp + glib_c_library_flags.sexp)) + (deps (config/discover.exe ocamlc_config)) + (action (run ${<} ocamlc_config)))) + +;; create ocamlc -config file +(rule + ((targets (ocamlc_config)) + (action (with-stdout-to ${@} (run ${OCAMLC} -config))))) From e9f0907cae2d61e27ade0ddcecbf1b146eb68269 Mon Sep 17 00:00:00 2001 From: andrewray Date: Wed, 24 May 2017 02:20:10 +0100 Subject: [PATCH 11/46] add flag detection for lwt-unix parse `ocamlc -config` for parameters that used to come from oasis. adds base and stdio as dependancies --- lwt-unix.opam | 2 ++ src/glib/config/discover.ml | 1 - src/unix/config/discover.ml | 21 ++++++++++++++++++--- src/unix/config/jbuild | 4 ++-- src/unix/jbuild | 17 ++++++++++------- 5 files changed, 32 insertions(+), 13 deletions(-) diff --git a/lwt-unix.opam b/lwt-unix.opam index 8f6f31dcf3..c7d55a64a7 100644 --- a/lwt-unix.opam +++ b/lwt-unix.opam @@ -20,6 +20,8 @@ build-test: [ [ "jbuilder" "runtest" "-p" name ] ] depends: [ "jbuilder" { build & >= "1.0+beta9" } "cppo" { build } + "base" { build } + "stdio" { build } "base-unix" "lwt-core" "lwt-log" diff --git a/src/glib/config/discover.ml b/src/glib/config/discover.ml index 368c3ffe5b..50ecd0e911 100644 --- a/src/glib/config/discover.ml +++ b/src/glib/config/discover.ml @@ -85,7 +85,6 @@ let libs = let write_sexp fn sexp = Out_channel.write_all fn ~data:(Sexp.to_string sexp) - let () = write_sexp "glib_c_flags.sexp" (sexp_of_list sexp_of_string cflags); write_sexp "glib_c_library_flags.sexp" (sexp_of_list sexp_of_string libs) diff --git a/src/unix/config/discover.ml b/src/unix/config/discover.ml index 9c1fa4f278..15afa35056 100644 --- a/src/unix/config/discover.ml +++ b/src/unix/config/discover.ml @@ -584,9 +584,8 @@ let () = set exec_name "default_executable_name"; set ccomp_type "ccomp_type"; set system "system"; - libev_default := List.mem !system (* from _oasis *) + libev_default := List.mem !system (* as per _oasis *) ["linux"; "linux_elf"; "linux_aout"; "linux_eabi"; "linux_eabihf"]; - printf "system = %s\n" !system end in @@ -834,5 +833,21 @@ Lwt can use pthread or the win32 API. close_out oc; close_out config; - close_out config_ml + close_out config_ml; + + let open Base in + let open Stdio in + + let get_flags lib = + (try Caml.List.assoc (lib ^ "_opt") !setup_data with _ -> []), + (try Caml.List.assoc (lib ^ "_lib") !setup_data with _ -> []) + in + let cflags_ev, libs_ev = get_flags "libev" in + let cflags_pt, libs_pt = get_flags "pthread" in + let cflags = cflags_ev @ cflags_pt in + let libs = libs_ev @ libs_pt in + + let write_sexp fn sexp = Out_channel.write_all fn ~data:(Sexp.to_string sexp) in + write_sexp ("unix_c_flags.sexp") (sexp_of_list sexp_of_string ("-I."::cflags)); + write_sexp ("unix_c_library_flags.sexp") (sexp_of_list sexp_of_string (libs)) diff --git a/src/unix/config/jbuild b/src/unix/config/jbuild index fef112fe1c..2b19b9e428 100644 --- a/src/unix/config/jbuild +++ b/src/unix/config/jbuild @@ -1,5 +1,5 @@ (jbuild_version 1) (executable - ((name discover))) - + ((name discover) + (libraries (base stdio)))) diff --git a/src/unix/jbuild b/src/unix/jbuild index a6319f4335..0bea068c58 100644 --- a/src/unix/jbuild +++ b/src/unix/jbuild @@ -19,13 +19,16 @@ (action (with-stdout-to ${@} (run ${OCAMLC} -config))))) (rule - ((targets (lwt_config.h lwt_config.ml)) + ((targets (unix_c_flags.sexp + unix_c_library_flags.sexp + lwt_config.h + lwt_config.ml)) (deps (config/discover.exe ocamlc_config)) (action (run ${<} - -ocamlc ${OCAMLC} ;; avoid call to ocamlfind - -ocamlc_config ocamlc_config ;; generated by the rule - -use-libev ${lib-available:conf-libev} ;; from installed world - -android-target false ;; XXX fixme + -ocamlc ${OCAMLC} ;; avoid call to ocamlfind + -ocamlc_config ocamlc_config ;; generated above + -use-libev true ;; need some way to find out about conf-libev + -android-target false ;; XXX fixme )))) ;; gen_stubs.ml @@ -104,7 +107,7 @@ lwt_unix_unix lwt_unix_windows )) - (c_flags (-I.)) - (c_library_flags (-lpthread)) + (c_flags (:include unix_c_flags.sexp)) + (c_library_flags (:include unix_c_library_flags.sexp)) )) From 512d277e244c2095492d9a6fbc5343848d100a34 Mon Sep 17 00:00:00 2001 From: andrewray Date: Wed, 24 May 2017 02:47:15 +0100 Subject: [PATCH 12/46] new package lwt-xxx, map to old name lwt.xxx this isn't quite right for glib/ssl/react. maybe better to make the jbuild version use lwt_xxx throughout as that will be most compatible --- lwt_glib.opam => lwt-glib.opam | 0 lwt_react.opam => lwt-react.opam | 0 lwt_ssl.opam => lwt-ssl.opam | 0 src/ppx/.merlin | 8 -------- 4 files changed, 8 deletions(-) rename lwt_glib.opam => lwt-glib.opam (100%) rename lwt_react.opam => lwt-react.opam (100%) rename lwt_ssl.opam => lwt-ssl.opam (100%) delete mode 100644 src/ppx/.merlin diff --git a/lwt_glib.opam b/lwt-glib.opam similarity index 100% rename from lwt_glib.opam rename to lwt-glib.opam diff --git a/lwt_react.opam b/lwt-react.opam similarity index 100% rename from lwt_react.opam rename to lwt-react.opam diff --git a/lwt_ssl.opam b/lwt-ssl.opam similarity index 100% rename from lwt_ssl.opam rename to lwt-ssl.opam diff --git a/src/ppx/.merlin b/src/ppx/.merlin deleted file mode 100644 index 00caaa4da1..0000000000 --- a/src/ppx/.merlin +++ /dev/null @@ -1,8 +0,0 @@ -B ../../_build/default/src/ppx -FLG -ppx "../../_build/default/.ppx/ppx_tools_versioned.metaquot_404/ppx.exe --as-ppx --cookie 'library-name="ppx_lwt"'" -FLG -w -40 -PKG compiler-libs -PKG compiler-libs.common -PKG ocaml-migrate-parsetree -PKG ppx_tools_versioned -S . From e13bac72964e4a86ee6c98a37387c4c9164e071b Mon Sep 17 00:00:00 2001 From: andrewray Date: Wed, 24 May 2017 03:13:41 +0100 Subject: [PATCH 13/46] remove old build system --- .gitignore | 4 - META.lwt.template | 12 ++ Makefile | 54 ++--- _oasis | 441 ---------------------------------------- _tags | 35 ---- doc/examples/gtk/jbuild | 2 +- lwt-glib.opam | 3 +- lwt-ssl.opam | 4 +- lwt-unix.opam | 4 +- myocamlbuild.ml | 195 ------------------ setup.ml | 26 --- src/glib/_oasis | 25 --- src/glib/jbuild | 2 +- src/glib/opam | 30 --- src/react/_oasis | 20 -- src/react/jbuild | 3 +- src/react/opam | 28 --- src/ssl/_oasis | 20 -- src/ssl/jbuild | 2 +- src/ssl/opam | 30 --- tests/react/jbuild | 4 +- 21 files changed, 39 insertions(+), 905 deletions(-) delete mode 100644 _oasis delete mode 100644 _tags delete mode 100644 myocamlbuild.ml delete mode 100644 setup.ml delete mode 100644 src/glib/_oasis delete mode 100644 src/glib/opam delete mode 100644 src/react/_oasis delete mode 100644 src/react/opam delete mode 100644 src/ssl/_oasis delete mode 100644 src/ssl/opam diff --git a/.gitignore b/.gitignore index c64e2c8963..6413f53e41 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,4 @@ _build -src/unix/lwt_config.ml -src/unix/lwt_config.h -src/unix/lwt_unix_jobs_generated.ml -src/unix/jobs-unix/ setup.data setup.log setup.exe diff --git a/META.lwt.template b/META.lwt.template index 7917e2d60b..4e1d2acd5b 100644 --- a/META.lwt.template +++ b/META.lwt.template @@ -24,6 +24,18 @@ package "simple-top" ( requires = "lwt-simple-top" ) +package "glib" ( + requires = "lwt-glib" +) + +package "ssl" ( + requires = "lwt-ssl" +) + +package "react" ( + requires = "lwt-react" +) + package "syntax" ( requires = "camlp4 lwt-camlp4 lwt.camlp4.options" diff --git a/Makefile b/Makefile index 64da8888a1..25f8bc4081 100644 --- a/Makefile +++ b/Makefile @@ -9,26 +9,10 @@ OCAMLFIND_IGNORE_DUPS_IN = $(shell ocamlfind query compiler-libs) export OCAMLFIND_IGNORE_DUPS_IN -# Set to setup.exe for the release -SETUP := setup-dev.exe - # Default rule default: build -# Setup for the development version -setup-dev.exe: _oasis setup.ml - grep -v '^#' setup.ml > setup_dev.ml - ocamlfind ocamlopt -o $@ -linkpkg -package ocamlbuild,oasis.dynrun setup_dev.ml || \ - ocamlfind ocamlc -o $@ -linkpkg -package ocamlbuild,oasis.dynrun setup_dev.ml || true - rm -f setup_dev.* - -# Setup for the release -setup.exe: setup.ml - ocamlopt.opt -o $@ $< || ocamlopt -o $@ $< || ocamlc -o $@ $< - rm -f setup.cmx setup.cmi setup.o setup.obj setup.cmo - -setup: $(SETUP) - +# build the usual development packages build: jbuilder build \ lwt-core.install \ @@ -38,48 +22,38 @@ build: lwt-simple-top.install \ lwt-ppx.install -build-all: - jbuilder build @install - doc-api: $(SETUP) setup.data build ./$(SETUP) -build lwt-api.docdir/index.html +# run all tests test: jbuilder runtest -all: $(SETUP) - ./$(SETUP) -all $(ALLFLAGS) +# build everything +all: + jbuilder build @install -install: $(SETUP) setup.data - ./$(SETUP) -install $(INSTALLFLAGS) +install: + jbuilder install -uninstall: $(SETUP) setup.data - ./$(SETUP) -uninstall $(UNINSTALLFLAGS) +uninstall: + jbuilder uninstall -reinstall: $(SETUP) setup.data - ./$(SETUP) -reinstall $(REINSTALLFLAGS) +reinstall: + jbuilder uninstall + jbuilder install clean: rm -fr _build - rm *.install - -distclean: $(SETUP) - ./$(SETUP) -distclean $(DISTCLEANFLAGS) - rm -rf setup*.exe + rm -f *.install clean-coverage: rm -rf bisect*.out rm -rf _coverage/ -configure: $(SETUP) - ./$(SETUP) -configure $(CONFIGUREFLAGS) - -setup.data: $(SETUP) - ./$(SETUP) -configure $(CONFIGUREFLAGS) - coverage: test bisect-ppx-report -I _build/ -html _coverage/ bisect*.out bisect-ppx-report -text - -summary-only bisect*.out @echo See _coverage/index.html -.PHONY: default setup build doc test all install uninstall reinstall clean distclean configure coverage +.PHONY: default build doc test all install uninstall reinstall clean coverage diff --git a/_oasis b/_oasis deleted file mode 100644 index 43b2256997..0000000000 --- a/_oasis +++ /dev/null @@ -1,441 +0,0 @@ -# +-------------------------------------------------------------------+ -# | Package parameters | -# +-------------------------------------------------------------------+ - -OASISFormat: 0.4 -OCamlVersion: >= 4.02 -Name: lwt -Version: 3.0.0 -LicenseFile: COPYING -License: LGPL-2.1 with OCaml linking exception -Authors: - Jérôme Vouillon, - Vincent Balat, - Nataliya Guts, - Pierre Clairambault, - Stéphane Glondu, - Jérémie Dimino, - Warren Harris, - Pierre Chambart, - Mauricio Fernandez, - Grégoire Henri, - Gabriel Radanne, - Peter Zotov, - Hugo Heuzard, - Vincent Bernardoff, - Romain Slootmaekers -Homepage: http://ocsigen.org/lwt/ -BuildTools: ocamlbuild -Plugins: DevFiles (0.4), META (0.4) -XDevFilesEnableMakefile: false -PostConfCommand: ocaml src/util/discover.ml -ext-obj $ext_obj -exec-name $default_executable_name -use-libev $libev -os-type $os_type -use-glib $glib -ccomp-type $ccomp_type -use-pthread $pthread -use-unix $unix -android-target $android_target -libev_default $libev_default -PostDistCleanCommand: $rm src/unix/lwt_config.h src/unix/lwt_config.ml src/unix/lwt_unix_jobs_generated.ml src/unix/jobs-unix/* - -AlphaFeatures: pure_interface, ocamlbuild_more_args -XOCamlbuildPluginTags: package(cppo_ocamlbuild) - -Synopsis: Monadic promises and concurrent I/O -Description: - A promise is a value that may become determined in the future. Lwt provides - typed, composable promises. Promises that are resolved by I/O are resolved by - Lwt in parallel. Meanwhile, OCaml code, including code creating and waiting on - promises, runs in a single thread by default. This reduces the need for locks - or other nchronization primitives. Code can be run in parallel on an opt-in - basis. - - -# +-------------------------------------------------------------------+ -# | Flags | -# +-------------------------------------------------------------------+ - -Flag android_target - Description: Compiles for Android - Default: false - -Flag all - Description: build and install everything - Default: false - -Flag camlp4 - Description: Build the syntax extension - Default$: flag(all) - -Flag ppx - Description: Build the ppx syntax extension - Default$: flag(all) - -Flag unix - Description: Unix support - Default: true - -Flag react - Description: React helpers - Default$: flag(all) - -Flag glib - Description: GLib integration - Default$: flag(all) - -Flag ssl - Description: SSL support - Default$: flag(all) - -Flag preemptive - Description: Preemptive threads support - Default$: flag(unix) && !flag(android_target) - -Flag libev - Description: Compile with libev support - Default$: !os_type(Win32) && !flag(android_target) - -Flag libev_default - Description: Use the libev backend by default - Default$: system(linux) || system(linux_elf) || system(linux_aout) || system(linux_eabi) || system(linux_eabihf) - -Flag pthread - Description: Use pthread - Default$: !os_type(Win32) - -Flag coverage - Description: Instrument for coverage analysis - Default: false - -# +-------------------------------------------------------------------+ -# | Libraries | -# +-------------------------------------------------------------------+ - -Library "lwt" - Path: src/core - Modules: - Lwt_condition, - Lwt_list, - Lwt, - Lwt_mutex, - Lwt_mvar, - Lwt_pool, - Lwt_result, - Lwt_sequence, - Lwt_stream, - Lwt_switch, - Lwt_pqueue - BuildDepends: bytes, result - XMETADescription: Lightweight thread library for OCaml (core library) - -Library "lwt-log" - FindlibName: log - FindlibParent: lwt - Path: src/logger - Modules: Lwt_log_core, Lwt_log_rules - BuildDepends: lwt - XMETADescription: Logger for Lwt - -Library "lwt-unix" - Build$: flag(unix) || flag(all) - Install$: flag(unix) || flag(all) - FindlibName: unix - FindlibParent: lwt - Path: src/unix - Modules: - Lwt_chan, - Lwt_daemon, - Lwt_gc, - Lwt_io, - Lwt_log, - Lwt_main, - Lwt_process, - Lwt_throttle, - Lwt_timeout, - Lwt_unix, - Lwt_sys, - Lwt_engine, - Lwt_bytes - InternalModules: - Lwt_unix_jobs_generated, - Lwt_config - BuildDepends: lwt, lwt.log, unix, bigarray - XMETADescription: Unix support for Lwt - CSources: - lwt_config.h, - lwt_unix.h, - lwt_unix_stubs.c, - lwt_libev_stubs.c, - lwt_process_stubs.c, - jobs-unix/lwt_unix_job_access.c, - jobs-unix/lwt_unix_job_chdir.c, - jobs-unix/lwt_unix_job_chmod.c, - jobs-unix/lwt_unix_job_chown.c, - jobs-unix/lwt_unix_job_chroot.c, - jobs-unix/lwt_unix_job_close.c, - jobs-unix/lwt_unix_job_fchmod.c, - jobs-unix/lwt_unix_job_fchown.c, - jobs-unix/lwt_unix_job_fdatasync.c, - jobs-unix/lwt_unix_job_fsync.c, - jobs-unix/lwt_unix_job_ftruncate.c, - jobs-unix/lwt_unix_job_link.c, - jobs-unix/lwt_unix_job_lseek.c, - jobs-unix/lwt_unix_job_mkdir.c, - jobs-unix/lwt_unix_job_mkfifo.c, - jobs-unix/lwt_unix_job_rename.c, - jobs-unix/lwt_unix_job_rmdir.c, - jobs-unix/lwt_unix_job_symlink.c, - jobs-unix/lwt_unix_job_tcdrain.c, - jobs-unix/lwt_unix_job_tcflow.c, - jobs-unix/lwt_unix_job_tcflush.c, - jobs-unix/lwt_unix_job_tcsendbreak.c, - jobs-unix/lwt_unix_job_truncate.c, - jobs-unix/lwt_unix_job_unlink.c - if os_type(Win32) && ccomp_type(msvc) - CCLib+: ws2_32.lib - else if os_type(Win32) - CCLib+: -lws2_32 - -Library "lwt-simple-top" - Build$: flag(unix) || flag(all) - Install$: flag(unix) || flag(all) - FindlibName: simple-top - FindlibParent: lwt - Path: src/simple_top - InternalModules: Lwt_simple_top - BuildDepends: lwt, lwt.unix, compiler-libs.common - XMETADescription: Lwt-OCaml top level integration (deprecated; use utop) - -# This library is built through this build system only in development. For the -# release build system, see src/react/_oasis. -Library "lwt-react" - Build$: flag(react) || flag(all) - Install$: flag(react) || flag(all) - FindlibName: react - FindlibParent: lwt - Path: src/react - Modules: Lwt_react - BuildDepends: lwt, react - XMETADescription: Reactive programming helpers for Lwt (deprecated; use package lwt_react) - -Library "lwt-preemptive" - Build$: flag(preemptive) || flag(all) - Install$: flag(preemptive) || flag(all) - FindlibName: preemptive - FindlibParent: lwt - Path: src/preemptive - Modules: Lwt_preemptive - BuildDepends: lwt, lwt.unix, threads - XMETADescription: Preemptive thread support for Lwt - -# This library is built through this build system only in development. For the -# release build system, see src/glib/_oasis. -Library "lwt-glib" - Build$: flag(glib) || flag(all) - Install$: flag(glib) || flag(all) - FindlibName: glib - FindlibParent: lwt - Path: src/glib - Modules: Lwt_glib - CSources: lwt_glib_stubs.c - BuildDepends: lwt, lwt.unix - XMETADescription: GLib integration for Lwt (deprecated; use package lwt_glib) - -# This library is built through this build system only in development. For the -# release build system, see src/ssl/_oasis. -Library "lwt-ssl" - Build$: flag(ssl) || flag(all) - Install$: flag(ssl) || flag(all) - FindlibName: ssl - FindlibParent: lwt - Path: src/ssl - Modules: Lwt_ssl - BuildDepends: ssl, lwt.unix - XMETADescription: SSL support for Lwt (deprecated; use package lwt_ssl) - -Library "lwt-syntax" - Build$: flag(camlp4) || flag(all) - Install$: flag(camlp4) || flag(all) - FindlibName: syntax - FindlibParent: lwt - Path: src/camlp4 - Modules: Pa_lwt - BuildDepends: camlp4, camlp4.quotations.o, camlp4.extend - XMETAType: syntax - XMETADescription: Camlp4 syntax for Lwt (deprecated; use lwt.ppx) - XMETARequires: camlp4, lwt.syntax.options - -Library "lwt-syntax-options" - Build$: flag(camlp4) || flag(all) - Install$: flag(camlp4) || flag(all) - FindlibName: options - FindlibParent: lwt-syntax - Path: src/camlp4 - InternalModules: Pa_lwt_options - BuildDepends: camlp4 - XMETAType: syntax - XMETADescription: Options for Lwt Camlp4 syntax extension (deprecated; use lwt.ppx) - XMETARequires: camlp4 - -Library "lwt-syntax-log" - Build$: flag(camlp4) || flag(all) - Install$: flag(camlp4) || flag(all) - FindlibName: log - FindlibParent: lwt-syntax - Path: src/camlp4 - Modules: Pa_lwt_log - BuildDepends: camlp4, camlp4.quotations.o - XMETAType: syntax - XMETADescription: Camlp4 syntax for Lwt logging (deprecated; use lwt.ppx) - XMETARequires: camlp4, lwt.syntax.options - -Library "ppx" - Build$: flag(ppx) || flag(all) - Install$: flag(ppx) || flag(all) - FindlibName: ppx - FindlibParent: lwt - Path: src/ppx - Modules: Ppx_lwt_int, Ppx_lwt - BuildDepends: compiler-libs.common, ppx_tools_versioned, ppx_tools_versioned.metaquot_404, ocaml-migrate-parsetree - XMETADescription: Lwt PPX syntax extension - XMETARequires: lwt, ppx_tools_versioned, ocaml-migrate-parsetree - XMETAExtraLines: ppx = "ppx_lwt" - -Executable "ppx_lwt" - Build$: flag(ppx) || flag(all) - Install$: flag(ppx) || flag(all) - Path: src/ppx - MainIs: ppx_lwt_ex.ml - BuildDepends: compiler-libs.common, ppx_tools_versioned, ppx_tools_versioned.metaquot_404, ocaml-migrate-parsetree - CompiledObject: best - -# +-------------------------------------------------------------------+ -# | Doc | -# +-------------------------------------------------------------------+ - -Document "lwt-api" - Title: API reference for Lwt - Type: ocamlbuild (0.3) - Install: true - InstallDir: $htmldir/api - DataFiles: src/util/style.css - BuildTools: ocamldoc - XOCamlbuildPath: ./ - XOCamlbuildLibraries: - lwt, - lwt.glib, - lwt.preemptive, - lwt.react, - lwt.ssl, - lwt.log, - lwt.unix, - lwt.syntax, - lwt.syntax.log, - lwt.ppx - -# +-------------------------------------------------------------------+ -# | Examples | -# +-------------------------------------------------------------------+ - -Executable logging - Path: doc/examples/unix - Build$: flag(unix) && flag(ppx) - Install: false - MainIs: logging.ml - BuildDepends: lwt.unix, lwt.ppx - CompiledObject: best - -Executable relay - Path: doc/examples/unix - Build$: flag(unix) && flag(ppx) - Install: false - MainIs: relay.ml - BuildDepends: lwt.unix, lwt.ppx - CompiledObject: best - -Executable parallelize - Path: doc/examples/unix - Build$: flag(unix) && flag(ppx) - Install: false - MainIs: parallelize.ml - BuildDepends: lwt.unix, lwt.ppx - CompiledObject: best - -# +-------------------------------------------------------------------+ -# | Tests | -# +-------------------------------------------------------------------+ - -Library test - Path: tests - Modules: Test - Install: false - Build$: flag(tests) && (flag(unix) || flag(all)) - BuildDepends: lwt, unix, lwt.unix - -Executable test_core - Path: tests/core - Build$: flag(tests) && (flag(unix) || flag(all)) - Install: false - CompiledObject: best - MainIs: main.ml - BuildDepends: test, lwt, unix, lwt.unix - -Executable test_unix - Path: tests/unix - Build$: flag(tests) && (flag(unix) || flag(all)) - Install: false - CompiledObject: best - MainIs: main.ml - BuildDepends: test, lwt, unix, lwt.unix - -Executable test_react - Path: tests/react - Build$: flag(tests) && ((flag(unix) && flag(react)) || flag(all)) - Install: false - CompiledObject: best - MainIs: main.ml - BuildDepends: test, lwt, unix, lwt.unix, react, lwt.react - -Executable test_preemptive - Path: tests/preemptive - Build$: flag(tests) && ((flag(preemptive) && flag(unix)) || flag(all)) - Install: false - CompiledObject: best - MainIs: main.ml - BuildDepends: test, lwt, unix, lwt.unix, lwt.preemptive, threads - -Executable test_ppx - Path: tests/ppx - Build$: flag(tests) && ((flag(ppx) && flag(unix)) || flag(all)) - Install: false - CompiledObject: best - MainIs: main.ml - BuildTools: ppx_lwt - BuildDepends: test, lwt, lwt.unix - -Test core - Command: $test_core - TestTools: test_core - Run$: flag(tests) && (flag(unix) || flag(all)) - -Test unix - Command: $test_unix - TestTools: test_unix - Run$: flag(tests) && (flag(unix) || flag(all)) - -Test react - Command: $test_react - TestTools: test_react - Run$: flag(tests) && ((flag(unix) && flag(react)) || flag(all)) - -Test preemptive - Command: $test_preemptive - TestTools: test_preemptive - Run$: flag(tests) && ((flag(preemptive) && flag(unix)) || flag(all)) - -Test ppx - Command: $test_ppx - TestTools: test_ppx - Run$: flag(tests) && ((flag(ppx) && flag(unix)) || flag(all)) - -# +-------------------------------------------------------------------+ -# | Misc | -# +-------------------------------------------------------------------+ - -SourceRepository head - Type: git - Location: git://github.com/ocsigen/lwt - Browser: https://github.com/ocsigen/lwt diff --git a/_tags b/_tags deleted file mode 100644 index b9399e0da0..0000000000 --- a/_tags +++ /dev/null @@ -1,35 +0,0 @@ -# -*- conf -*- -not : safe_string - -# cppo pre-processing for OCaml (compiler/stdlib) compatibility workarounds -<**/*.ml>: cppo_V_OCAML -<**/*.mli>: cppo_V_OCAML - -# Warnings. The order is important. This is not fully legitimate as it appears -# to depend on how Ocamlbuild internally handles lists of warn() tags. - or : warn(-4) -: warn(-3) -<**/*>: warn(+A-29-58) - -# Syntax extension -: syntax(camlp4o) - -# Stubs -: use_C_libev, use_C_pthread -: use_C_glib -<**/*.c>: use_lwt_headers -<**/*.h>: use_lwt_headers - -# Ppx tests -: ppx_lwt - -# Examples -: ppx_lwt - -# Scratch directory -"scratch": -traverse - -: linkall - -# OASIS_START -# OASIS_STOP diff --git a/doc/examples/gtk/jbuild b/doc/examples/gtk/jbuild index 4392661ec7..3e41fb8b37 100644 --- a/doc/examples/gtk/jbuild +++ b/doc/examples/gtk/jbuild @@ -2,5 +2,5 @@ (executable ((name connect) - (libraries (lwt-unix lwt_glib threads lablgtk2)) + (libraries (lwt-unix lwt-glib threads lablgtk2)) (preprocess (pps (lwt-ppx))))) diff --git a/lwt-glib.opam b/lwt-glib.opam index 7be6e22987..ea8d67e1ef 100644 --- a/lwt-glib.opam +++ b/lwt-glib.opam @@ -22,7 +22,8 @@ depends: [ "lwt-unix" "base" { build } # needed for discover.ml "stdio" { build } # ...but only to write the sexps - "lablgtk" + "conf-pkg-config" {build} + "conf-glib-2" {build} ] diff --git a/lwt-ssl.opam b/lwt-ssl.opam index db0ad6a4e6..45c837fd8d 100644 --- a/lwt-ssl.opam +++ b/lwt-ssl.opam @@ -19,8 +19,8 @@ build: [ [ "jbuilder" "build" "-p" name "-j" jobs ] ] build-test: [ [ "jbuilder" "runtest" "-p" name ] ] depends: [ "jbuilder" { build & >= "1.0+beta9" } - "ssl" - "lwt-unix" + "ssl" { >= "0.5.0" } + "lwt-unix" { >= "3.0.0" } ] diff --git a/lwt-unix.opam b/lwt-unix.opam index c7d55a64a7..5dff4ab22c 100644 --- a/lwt-unix.opam +++ b/lwt-unix.opam @@ -20,8 +20,8 @@ build-test: [ [ "jbuilder" "runtest" "-p" name ] ] depends: [ "jbuilder" { build & >= "1.0+beta9" } "cppo" { build } - "base" { build } - "stdio" { build } + "base" { build } # needed for discover.ml + "stdio" { build } # ...but only to write the sexps "base-unix" "lwt-core" "lwt-log" diff --git a/myocamlbuild.ml b/myocamlbuild.ml deleted file mode 100644 index 2068c60424..0000000000 --- a/myocamlbuild.ml +++ /dev/null @@ -1,195 +0,0 @@ -(* OCaml promise library - * http://www.ocsigen.org/lwt - * Copyright (C) 2010 Jérémie Dimino - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, with linking exceptions; - * either version 2.1 of the License, or (at your option) any later - * version. See COPYING file for details. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. - *) - -(* OASIS_START *) -(* OASIS_STOP *) - -open Ocamlbuild_plugin - -let split str = - let rec skip_spaces i = - if i = String.length str then - [] - else - if str.[i] = ' ' then - skip_spaces (i + 1) - else - extract i (i + 1) - and extract i j = - if j = String.length str then - [String.sub str i (j - i)] - else - if str.[j] = ' ' then - String.sub str i (j - i) :: skip_spaces (j + 1) - else - extract i (j + 1) - in - skip_spaces 0 - -let c_library_tag name = Printf.sprintf "use_C_%s" name - -let define_c_library name env = - if BaseEnvLight.var_get name env = "true" then begin - let tag = c_library_tag name in - - let opt = - List.map - (fun x -> A x) - (split (BaseEnvLight.var_get (name ^ "_opt") env)) - and lib = - List.map - (fun x -> A x) - (split (BaseEnvLight.var_get (name ^ "_lib") env)) - in - - (* Add flags for linking with the C library: *) - flag ["ocamlmklib"; "c"; tag] & S lib; - - (* C stubs using the C library must be compiled with the library - specifics flags: *) - flag ["c"; "compile"; tag] & - S (List.map (fun arg -> S[A"-ccopt"; arg]) opt); - - (* OCaml libraries must depends on the C library: *) - flag ["link"; "ocaml"; tag] & - S (List.map (fun arg -> S[A"-cclib"; arg]) lib) - end - -let conditional_warnings_as_errors () = - match Sys.getenv "LWT_WARNINGS_AS_ERRORS" with - | "yes" -> - let flags = S [A "-warn-error"; A "+A"] in - flag ["ocaml"; "compile"] flags; - flag ["ocaml"; "link"] flags - | _ -> () - | exception Not_found -> () - -let () = dispatch begin fun hook -> - let env = - BaseEnvLight.load - ~allow_empty:true - ~filename:(Pathname.basename BaseEnvLight.default_filename) - () - in - - Ocamlbuild_cppo.dispatcher hook; - - dispatch_default hook; - - match hook with - | Before_options -> - Options.make_links := false - - | After_options -> - if BaseEnvLight.var_get "coverage" env = "true" then - Options.tag_lines := - [": package(bisect_ppx)"; - "<**/lwt_config.*>: -package(bisect_ppx)"; - " or : package(bisect_ppx)"; - ": package(bisect_ppx)"] - @ !Options.tag_lines - - | After_rules -> - (* Determine extension of CompiledObject: best *) - let native_suffix = - if BaseEnvLight.var_get "is_native" env = "true" - then "native" else "byte" - in - - flag ["ocaml"; "compile"; "ppx_lwt"] & - S [A "-ppx"; A ("src/ppx/ppx_lwt_ex." ^ native_suffix)]; - - (*tag_file "src/ppx/ppx.cmxa" ["linkme"]; - flag ["linkme"] & S[A"-linkall"];*) - - (* Use an introduction page with categories *) - tag_file "lwt-api.docdir/index.html" ["apiref"]; - dep ["apiref"] ["doc/apiref-intro"]; - flag ["apiref"] & S[A "-intro"; P "doc/apiref-intro"; A"-colorize-code"]; - - (* Stubs: *) - dep ["file:src/unix/lwt_unix_stubs.c"] - ["src/unix/lwt_unix_unix.c"; "src/unix/lwt_unix_windows.c"]; - - let c_libraries = ["glib"; "libev"; "pthread"] in - - (* Check for "unix" because other variables are not present in the - setup.data file if lwt.unix is disabled. *) - if BaseEnvLight.var_get "unix" env = "true" then begin - List.iter (fun name -> define_c_library name env) c_libraries; - flag ["c"; "compile"; "use_lwt_headers"] & S [A"-ccopt"; A"-Isrc/unix"]; - end; - - List.iter (fun name -> - mark_tag_used (c_library_tag name)) c_libraries; - - conditional_warnings_as_errors (); - - rule "Generate a cmxs from a cmxa" - ~dep:"%.cmxa" - ~prod:"%.cmxs" - ~insert:`top - (fun env _ -> - Cmd (S [ !Options.ocamlopt - ; A "-shared" - ; A "-linkall" - ; A "-I"; A (Pathname.dirname (env "%")) - ; A (env "%.cmxa") - ; A "-o" - ; A (env "%.cmxs") - ])) - | _ -> - () - end - -(* Compile the wiki version of the Ocamldoc. - - Thanks to Till Varoquaux on usenet: - http://www.digipedia.pl/usenet/thread/14273/231/ *) -let ocamldoc_wiki tags deps docout docdir = - let tags = tags -- "extension:html" in - Ocamlbuild_pack.Ocaml_tools.ocamldoc_l_dir tags deps docout docdir - -let () = - try - let wikidoc_dir = - let base = - Ocamlbuild_pack.My_unix.run_and_read - "ocamlfind query wikidoc 2> /dev/null" - in - String.sub base 0 (String.length base - 1) - in - - Ocamlbuild_pack.Rule.rule - "ocamldoc: document ocaml project odocl & *odoc -> wikidocdir" - ~insert:`top - ~prod:"%.wikidocdir/index.wiki" - ~stamp:"%.wikidocdir/wiki.stamp" - ~dep:"%.odocl" - (Ocamlbuild_pack.Ocaml_tools.document_ocaml_project - ~ocamldoc:ocamldoc_wiki - "%.odocl" "%.wikidocdir/index.wiki" "%.wikidocdir"); - - tag_file "lwt-api.wikidocdir/index.wiki" ["apiref";"wikidoc"]; - flag ["wikidoc"] & S[A"-i";A wikidoc_dir;A"-g";A"odoc_wiki.cma"] - - (* Silently fail if the package wikidoc isn't available *) - with Failure e -> () diff --git a/setup.ml b/setup.ml deleted file mode 100644 index 9438a7ce28..0000000000 --- a/setup.ml +++ /dev/null @@ -1,26 +0,0 @@ -(* - * setup.ml - * -------- - * Copyright : (c) 2011, Jérémie Dimino - * Licence : BSD3 - * - * This file is a part of lwt. - *) - -(* OASIS_START *) -#use "topfind";; -#require "oasis.dynrun";; -open OASISDynRun;; -(* OASIS_STOP *) - -let () = - InternalInstallPlugin.lib_hook := - fun (cs, bs, lib, dn) -> - match lib.OASISTypes.lib_findlib_name with - | Some "unix" -> - (cs, bs, lib, dn, ["src/unix/lwt_config.h"; "src/unix/lwt_unix.h"]) - | _ -> - (cs, bs, lib, dn, []) -;; - -let () = setup ();; diff --git a/src/glib/_oasis b/src/glib/_oasis deleted file mode 100644 index 3c3f3da57b..0000000000 --- a/src/glib/_oasis +++ /dev/null @@ -1,25 +0,0 @@ -# This is only for generating the release build system for this package. In -# development, the main Lwt build system is used. - -# To generate, run -# oasis setup -setup-update none - -OASISFormat: 0.4 -OCamlVersion: >= 4.02 -Name: lwt_glib -Version: 1.0.1 -Synopsis: GLib integration for Lwt -Authors: Jérémie Dimino -License: LGPL-2.1 -Plugins: DevFiles (0.4), META (0.4) - -AlphaFeatures: ocamlbuild_more_args -XOCamlbuildPluginTags: use_str - -Library lwt_glib - Path: . - BuildTools: ocamlbuild - Modules: Lwt_glib - CSources: lwt_glib_stubs.c - BuildDepends: lwt.unix - XMETADescription: GLib integration for Lwt diff --git a/src/glib/jbuild b/src/glib/jbuild index 1cf4ca40cf..7b72476053 100644 --- a/src/glib/jbuild +++ b/src/glib/jbuild @@ -2,7 +2,7 @@ (library ((name lwt_glib) - (public_name lwt_glib) + (public_name lwt-glib) (wrapped false) (libraries (lwt-core lwt-unix)) (c_names (lwt_glib_stubs)) diff --git a/src/glib/opam b/src/glib/opam deleted file mode 100644 index bcae082a04..0000000000 --- a/src/glib/opam +++ /dev/null @@ -1,30 +0,0 @@ -opam-version: "1.2" -name: "lwt_glib" -version: "1.0.1" -maintainer: [ - "Anton Bachin " -] -authors: [ - "Jérémie Dimino" -] -homepage: "https://github.com/ocsigen/lwt" -doc: "https://ocsigen.org/lwt/manual/" -dev-repo: "https://github.com/ocsigen/lwt.git" -bug-reports: "https://github.com/ocsigen/lwt/issues" -license: "LGPL with OpenSSL linking exception" -build: [ - [make "configure"] - [make "build"] -] -install: [ - [make "install"] -] -remove: [ - ["ocamlfind" "remove" "lwt_glib"] -] -depends: [ - "lwt" {>= "3.0.0"} - "base-unix" - "conf-pkg-config" {build} - "conf-glib-2" {build} -] diff --git a/src/react/_oasis b/src/react/_oasis deleted file mode 100644 index 4ac1217b08..0000000000 --- a/src/react/_oasis +++ /dev/null @@ -1,20 +0,0 @@ -# This is only for generating the release build system for this package. In -# development, the main Lwt build system is used. - -# To generate, run -# oasis setup -setup-update none - -OASISFormat: 0.4 -Name: lwt_react -Version: 1.0.1 -Synopsis: Helpers for using React with Lwt -Authors: Jérémie Dimino -License: LGPL-2.1 -Plugins: DevFiles (0.4), META (0.4) - -Library lwt_react - Path: . - BuildTools: ocamlbuild - Modules: Lwt_react - BuildDepends: lwt, react - XMETADescription: Helpers for using React with Lwt diff --git a/src/react/jbuild b/src/react/jbuild index ee7a571127..0fe63b2f65 100644 --- a/src/react/jbuild +++ b/src/react/jbuild @@ -2,7 +2,8 @@ (library ((name lwt_react) - (public_name lwt_react) + (public_name lwt-react) + (synopsis "Helpers for using React with Lwt") (wrapped false) (libraries (lwt-core react)))) diff --git a/src/react/opam b/src/react/opam deleted file mode 100644 index d88ae46f63..0000000000 --- a/src/react/opam +++ /dev/null @@ -1,28 +0,0 @@ -opam-version: "1.2" -name: "lwt_react" -version: "1.0.1" -maintainer: [ - "Anton Bachin " -] -authors: [ - "Jérémie Dimino" -] -homepage: "https://github.com/ocsigen/lwt" -doc: "https://ocsigen.org/lwt/manual/" -dev-repo: "https://github.com/ocsigen/lwt.git" -bug-reports: "https://github.com/ocsigen/lwt/issues" -license: "LGPL with OpenSSL linking exception" -build: [ - [make "configure"] - [make "build"] -] -install: [ - [make "install"] -] -remove: [ - ["ocamlfind" "remove" "lwt_react"] -] -depends: [ - "lwt" {>= "3.0.0"} - "react" {>= "1.0.0"} -] diff --git a/src/ssl/_oasis b/src/ssl/_oasis deleted file mode 100644 index fa393dedf2..0000000000 --- a/src/ssl/_oasis +++ /dev/null @@ -1,20 +0,0 @@ -# This is only for generating the release build system for this package. In -# development, the main Lwt build system is used. - -# To generate, run -# oasis setup -setup-update none - -OASISFormat: 0.4 -Name: lwt_ssl -Version: 1.0.1 -Synopsis: Lwt-friendly OpenSSL bindings -Authors: Jérémie Dimino -License: LGPL-2.1 -Plugins: DevFiles (0.4), META (0.4) - -Library lwt_ssl - Path: . - BuildTools: ocamlbuild - Modules: Lwt_ssl - BuildDepends: lwt.unix, ssl - XMETADescription: Lwt-friendly OpenSSL bindings diff --git a/src/ssl/jbuild b/src/ssl/jbuild index 1703000bdd..4c6e8725c2 100644 --- a/src/ssl/jbuild +++ b/src/ssl/jbuild @@ -2,7 +2,7 @@ (library ((name lwt_ssl) - (public_name lwt_ssl) + (public_name lwt-ssl) (wrapped false) (libraries (ssl lwt-unix)))) diff --git a/src/ssl/opam b/src/ssl/opam deleted file mode 100644 index c6a5dbe675..0000000000 --- a/src/ssl/opam +++ /dev/null @@ -1,30 +0,0 @@ -opam-version: "1.2" -name: "lwt_ssl" -version: "1.0.1" -maintainer: [ - "Anton Bachin " -] -authors: [ - "Jérôme Vouillon" - "Jérémie Dimino" -] -homepage: "https://github.com/ocsigen/lwt" -doc: "https://ocsigen.org/lwt/manual/" -dev-repo: "https://github.com/ocsigen/lwt.git" -bug-reports: "https://github.com/ocsigen/lwt/issues" -license: "LGPL with OpenSSL linking exception" -build: [ - [make "configure"] - [make "build"] -] -install: [ - [make "install"] -] -remove: [ - ["ocamlfind" "remove" "lwt_ssl"] -] -depends: [ - "lwt" {>= "3.0.0"} - "ssl" {>= "0.5.0"} - "base-unix" -] diff --git a/tests/react/jbuild b/tests/react/jbuild index e7574c7f3f..3acb14cd37 100644 --- a/tests/react/jbuild +++ b/tests/react/jbuild @@ -2,10 +2,10 @@ (executable ((name main) - (libraries (lwt_react lwttester)))) + (libraries (lwt-react lwttester)))) (alias ((name runtest) - (package lwt_react) + (package lwt-react) (action (run ${exe:main.exe})))) From 7b6d9d0b5ebd6a5963a2ddf1b648b57c7a2a4794 Mon Sep 17 00:00:00 2001 From: andrewray Date: Wed, 24 May 2017 03:33:42 +0100 Subject: [PATCH 14/46] add synopsis fields --- META.lwt.template | 10 +++++++++- src/camlp4/jbuild | 3 +++ src/core/jbuild | 1 + src/glib/jbuild | 1 + src/logger/jbuild | 1 + src/ppx/jbuild | 2 +- src/preemptive/jbuild | 1 + src/react/jbuild | 2 +- src/simple_top/jbuild | 1 + src/ssl/jbuild | 1 + src/unix/jbuild | 1 + 11 files changed, 21 insertions(+), 3 deletions(-) diff --git a/META.lwt.template b/META.lwt.template index 4e1d2acd5b..f0ffb0c27b 100644 --- a/META.lwt.template +++ b/META.lwt.template @@ -1,39 +1,47 @@ # JBUILDER_GEN version = "dev" -description = "" +description = "[compatibility] maps to lwt-core" requires = "lwt-core" package "unix" ( requires = "lwt-unix" + description = "[compatibility] maps to lwt-unix" ) package "log" ( requires = "lwt-log" + description = "[compatibility] maps to lwt-log" ) package "ppx" ( requires = "lwt-ppx" + description = "[compatibility] maps to lwt-ppx" ) package "preemptive" ( requires = "lwt-preemptive" + description = "[compatibility] maps to lwt-preemptive" ) package "simple-top" ( requires = "lwt-simple-top" + description = "[compatibility] maps to lwt-simple-top" ) package "glib" ( requires = "lwt-glib" + description = "[compatibility] maps to lwt-glib" ) package "ssl" ( requires = "lwt-ssl" + description = "[compatibility] maps to lwt-ssl" ) package "react" ( requires = "lwt-react" + description = "[compatibility] maps to lwt-react" ) package "syntax" ( diff --git a/src/camlp4/jbuild b/src/camlp4/jbuild index dfe0b55c6f..77186ccc14 100644 --- a/src/camlp4/jbuild +++ b/src/camlp4/jbuild @@ -1,6 +1,7 @@ (library ((name lwt_camlp4_options) (public_name lwt-camlp4.options) + (synopsis "Options for Lwt Camlp4 syntax extension (deprecated; use lwt.ppx)") (modules pa_lwt_options) (wrapped false) (libraries (camlp4)))) @@ -8,6 +9,7 @@ (library ((name lwt_camlp4) (public_name lwt-camlp4) + (synopsis "Camlp4 syntax for Lwt (deprecated; use lwt.ppx)") (modules pa_lwt) (wrapped false) (libraries (camlp4 lwt-camlp4.options)) @@ -16,6 +18,7 @@ (library ((name lwt_camlp4_log) (public_name lwt-camlp4.log) + (synopsis "Camlp4 syntax for Lwt logging (deprecated; use lwt.ppx)") (modules pa_lwt_log) (wrapped false) (libraries (camlp4 lwt-camlp4.options)) diff --git a/src/core/jbuild b/src/core/jbuild index 3e8841edb0..d65c7ea921 100644 --- a/src/core/jbuild +++ b/src/core/jbuild @@ -3,5 +3,6 @@ (library ((name lwt) (public_name lwt-core) + (synopsis "Monadic promises and concurrent I/O") (wrapped false) (libraries (bytes result)))) diff --git a/src/glib/jbuild b/src/glib/jbuild index 7b72476053..7023265e07 100644 --- a/src/glib/jbuild +++ b/src/glib/jbuild @@ -3,6 +3,7 @@ (library ((name lwt_glib) (public_name lwt-glib) + (synopsis "GLib integration for Lwt") (wrapped false) (libraries (lwt-core lwt-unix)) (c_names (lwt_glib_stubs)) diff --git a/src/logger/jbuild b/src/logger/jbuild index 1c0351cae4..8c68b77b34 100644 --- a/src/logger/jbuild +++ b/src/logger/jbuild @@ -5,5 +5,6 @@ (library ((name lwt_log) (public_name lwt-log) + (synopsis "Logger for Lwt") (wrapped false) (libraries (lwt-core)))) diff --git a/src/ppx/jbuild b/src/ppx/jbuild index ce0411c8cf..a77b120944 100644 --- a/src/ppx/jbuild +++ b/src/ppx/jbuild @@ -3,7 +3,7 @@ (library ((name ppx_lwt) (public_name lwt-ppx) - (synopsis "Lwt ppx") + (synopsis "Lwt PPX syntax extension") (modules (ppx_lwt)) (libraries (compiler-libs.common ocaml-migrate-parsetree diff --git a/src/preemptive/jbuild b/src/preemptive/jbuild index 51b3b4eaf1..eaf0d21bd9 100644 --- a/src/preemptive/jbuild +++ b/src/preemptive/jbuild @@ -3,6 +3,7 @@ (library ((name lwt_preemptive) (public_name lwt-preemptive) + (synopsis "Preemptive thread support for Lwt") (wrapped false) (libraries (lwt-core lwt-unix threads)))) diff --git a/src/react/jbuild b/src/react/jbuild index 0fe63b2f65..55a3261ee7 100644 --- a/src/react/jbuild +++ b/src/react/jbuild @@ -3,7 +3,7 @@ (library ((name lwt_react) (public_name lwt-react) - (synopsis "Helpers for using React with Lwt") + (synopsis "Reactive programming helpers for Lwt") (wrapped false) (libraries (lwt-core react)))) diff --git a/src/simple_top/jbuild b/src/simple_top/jbuild index 5cc1c08e13..2afafa4694 100644 --- a/src/simple_top/jbuild +++ b/src/simple_top/jbuild @@ -3,6 +3,7 @@ (library ((name lwt_simple_top) (public_name lwt-simple-top) + (synopsis "Lwt-OCaml top level integration (deprecated; use utop)") (wrapped false) (libraries (lwt-core lwt-unix compiler-libs.common)))) diff --git a/src/ssl/jbuild b/src/ssl/jbuild index 4c6e8725c2..e67edc6241 100644 --- a/src/ssl/jbuild +++ b/src/ssl/jbuild @@ -3,6 +3,7 @@ (library ((name lwt_ssl) (public_name lwt-ssl) + (synopsis "SSL support for Lwt") (wrapped false) (libraries (ssl lwt-unix)))) diff --git a/src/unix/jbuild b/src/unix/jbuild index 0bea068c58..9a3ce0a7bf 100644 --- a/src/unix/jbuild +++ b/src/unix/jbuild @@ -70,6 +70,7 @@ (library ((name lwt_unix) (public_name lwt-unix) + (synopsis "Unix support for Lwt") (wrapped false) (libraries (lwt-core lwt-log unix bigarray)) (c_names ( From 94383e4a133c0294e1366068d8b686af57b9c0ea Mon Sep 17 00:00:00 2001 From: andrewray Date: Wed, 24 May 2017 03:52:13 +0100 Subject: [PATCH 15/46] use exists_if in lwt META to only shadow installed packages looks in other packages directories to do this, which seems unclean but I dont know how else to do it. --- META.lwt.template | 11 +++++++++++ TODO.jbuild | 9 +++++++++ 2 files changed, 20 insertions(+) create mode 100644 TODO.jbuild diff --git a/META.lwt.template b/META.lwt.template index f0ffb0c27b..1f73fa3354 100644 --- a/META.lwt.template +++ b/META.lwt.template @@ -7,52 +7,63 @@ requires = "lwt-core" package "unix" ( requires = "lwt-unix" description = "[compatibility] maps to lwt-unix" + exists_if = "../lwt-unix/lwt_unix.cma" ) package "log" ( requires = "lwt-log" description = "[compatibility] maps to lwt-log" + exists_if = "../lwt-log/lwt_log.cma" ) package "ppx" ( requires = "lwt-ppx" description = "[compatibility] maps to lwt-ppx" + exists_if = "../lwt-ppx/ppx_lwt.cma" ) package "preemptive" ( requires = "lwt-preemptive" description = "[compatibility] maps to lwt-preemptive" + exists_if = "../lwt-preemptive/lwt_preemptive.cma" ) package "simple-top" ( requires = "lwt-simple-top" description = "[compatibility] maps to lwt-simple-top" + exists_if = "../lwt-simple-top/lwt_simple_top.cma" ) package "glib" ( requires = "lwt-glib" description = "[compatibility] maps to lwt-glib" + exists_if = "../lwt-glib/lwt_glib.cma" ) package "ssl" ( requires = "lwt-ssl" description = "[compatibility] maps to lwt-ssl" + exists_if = "../lwt-ssl/lwt_ssl.cma" ) package "react" ( requires = "lwt-react" description = "[compatibility] maps to lwt-react" + exists_if = "../lwt-react/lwt_react.cma" ) package "syntax" ( requires = "camlp4 lwt-camlp4 lwt.camlp4.options" + exists_if = "../lwt-camlp4/lwt_camlp4.cma" package "options" ( requires = "lwt-camlp4.options" + exists_if = "../lwt-camlp4/lwt_camlp4.cma" ) package "log" ( requires = "lwt-camlp4.log" + exists_if = "../lwt-camlp4/lwt_camlp4.cma" ) ) diff --git a/TODO.jbuild b/TODO.jbuild new file mode 100644 index 0000000000..3c19202f9e --- /dev/null +++ b/TODO.jbuild @@ -0,0 +1,9 @@ +- Internal modules exposed in lwt-unit + +- lwt-unix configuration params passed to discover.exe; + - use_libev (currently forced to true) + - how do we depend on an external opam package with no findlib library? + - android-target? + +- port names from lwt-xxx to lwt_xxx ?? + From b28726b25e3e0156f5770b417df08ad7cb6c3aec Mon Sep 17 00:00:00 2001 From: andrewray Date: Wed, 24 May 2017 10:15:21 +0100 Subject: [PATCH 16/46] note build problems on 4.03 --- Makefile | 8 ++------ TODO.jbuild | 9 +++++++++ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 25f8bc4081..7c56dd3e56 100644 --- a/Makefile +++ b/Makefile @@ -15,12 +15,8 @@ default: build # build the usual development packages build: jbuilder build \ - lwt-core.install \ - lwt-log.install \ - lwt-unix.install \ - lwt-preemptive.install \ - lwt-simple-top.install \ - lwt-ppx.install + --only-packages lwt-core,lwt-log,lwt-unix,lwt-preemptive,lwt-simple-top,lwt-ppx \ + @install doc-api: $(SETUP) setup.data build ./$(SETUP) -build lwt-api.docdir/index.html diff --git a/TODO.jbuild b/TODO.jbuild index 3c19202f9e..42c921fd40 100644 --- a/TODO.jbuild +++ b/TODO.jbuild @@ -7,3 +7,12 @@ - port names from lwt-xxx to lwt_xxx ?? +- lwt-unix 4.03.0 fails + - "Improve Android support in build system." adds -ccopt -o -ccopt which + doesnt work + - needs special case for andriod + +- no 4.02.0 because of Base and Stdio in discover system + - is there a simpler way to do the sexp generation so we can drop + this requirement? + From b8251209f2d5f07dcad0a6f8c7b2b0c79cabac6b Mon Sep 17 00:00:00 2001 From: andrewray Date: Thu, 25 May 2017 21:27:32 +0100 Subject: [PATCH 17/46] Refact libraries to match current lwt configuration The changes proposed in previous commits turn out to not be unnecessary. --- Makefile | 2 +- .../lwt-camlp4.opam | 0 lwt-core.opam => _opam-files/lwt-core.opam | 0 lwt-log.opam => _opam-files/lwt-log.opam | 0 lwt-ppx.opam => _opam-files/lwt-ppx.opam | 0 .../lwt-preemptive.opam | 0 .../lwt-simple-top.opam | 0 lwt-unix.opam => _opam-files/lwt-unix.opam | 0 _opam-files/lwt.opam | 30 +++++++++++++++++++ lwt.opam | 25 ++++++++++++---- lwt-glib.opam => lwt_glib.opam | 0 lwt-react.opam => lwt_react.opam | 0 lwt-ssl.opam => lwt_ssl.opam | 0 src/camlp4/jbuild | 19 +++++++----- src/core/jbuild | 2 +- src/glib/jbuild | 4 +-- src/logger/jbuild | 5 ++-- src/ppx/jbuild | 4 +-- src/preemptive/jbuild | 4 +-- src/react/jbuild | 4 +-- src/simple_top/jbuild | 5 ++-- src/ssl/jbuild | 4 +-- src/unix/jbuild | 5 ++-- tests/core/jbuild | 2 +- tests/jbuild | 2 +- tests/ppx/jbuild | 5 ++-- tests/preemptive/jbuild | 4 +-- tests/react/jbuild | 4 +-- tests/unix/jbuild | 2 +- 29 files changed, 90 insertions(+), 42 deletions(-) rename lwt-camlp4.opam => _opam-files/lwt-camlp4.opam (100%) rename lwt-core.opam => _opam-files/lwt-core.opam (100%) rename lwt-log.opam => _opam-files/lwt-log.opam (100%) rename lwt-ppx.opam => _opam-files/lwt-ppx.opam (100%) rename lwt-preemptive.opam => _opam-files/lwt-preemptive.opam (100%) rename lwt-simple-top.opam => _opam-files/lwt-simple-top.opam (100%) rename lwt-unix.opam => _opam-files/lwt-unix.opam (100%) create mode 100644 _opam-files/lwt.opam rename lwt-glib.opam => lwt_glib.opam (100%) rename lwt-react.opam => lwt_react.opam (100%) rename lwt-ssl.opam => lwt_ssl.opam (100%) diff --git a/Makefile b/Makefile index 7c56dd3e56..765a79a649 100644 --- a/Makefile +++ b/Makefile @@ -15,7 +15,7 @@ default: build # build the usual development packages build: jbuilder build \ - --only-packages lwt-core,lwt-log,lwt-unix,lwt-preemptive,lwt-simple-top,lwt-ppx \ + --only-packages lwt \ @install doc-api: $(SETUP) setup.data build diff --git a/lwt-camlp4.opam b/_opam-files/lwt-camlp4.opam similarity index 100% rename from lwt-camlp4.opam rename to _opam-files/lwt-camlp4.opam diff --git a/lwt-core.opam b/_opam-files/lwt-core.opam similarity index 100% rename from lwt-core.opam rename to _opam-files/lwt-core.opam diff --git a/lwt-log.opam b/_opam-files/lwt-log.opam similarity index 100% rename from lwt-log.opam rename to _opam-files/lwt-log.opam diff --git a/lwt-ppx.opam b/_opam-files/lwt-ppx.opam similarity index 100% rename from lwt-ppx.opam rename to _opam-files/lwt-ppx.opam diff --git a/lwt-preemptive.opam b/_opam-files/lwt-preemptive.opam similarity index 100% rename from lwt-preemptive.opam rename to _opam-files/lwt-preemptive.opam diff --git a/lwt-simple-top.opam b/_opam-files/lwt-simple-top.opam similarity index 100% rename from lwt-simple-top.opam rename to _opam-files/lwt-simple-top.opam diff --git a/lwt-unix.opam b/_opam-files/lwt-unix.opam similarity index 100% rename from lwt-unix.opam rename to _opam-files/lwt-unix.opam diff --git a/_opam-files/lwt.opam b/_opam-files/lwt.opam new file mode 100644 index 0000000000..6cd2681fda --- /dev/null +++ b/_opam-files/lwt.opam @@ -0,0 +1,30 @@ +opam-version: "1.2" +name: "lwt" +version: "dev" +maintainer: [ + "Anton Bachin " + "Mauricio Fernandez " + "Simon Cruanes " +] +authors: [ + "Jérôme Vouillon" + "Jérémie Dimino" +] +homepage: "https://github.com/ocsigen/lwt" +doc: "https://ocsigen.org/lwt/manual/" +bug-reports: "https://github.com/ocsigen/lwt/issues" +license: "LGPL with OpenSSL linking exception" +dev-repo: "https://github.com/ocsigen/lwt.git" +build: [ [ "jbuilder" "build" "-p" name "-j" jobs ] ] +depends: [ + "jbuilder" { build & >= "1.0+beta9" } + "lwt-core" + "lwt-log" + "lwt-unix" + "lwt-preemptive" + "lwt-simple-top" + "lwt-ppx" +] +post-messages: [ + "Lwt+jbuilder has some major breaking changes!!!" +] diff --git a/lwt.opam b/lwt.opam index 6cd2681fda..6ee2128b06 100644 --- a/lwt.opam +++ b/lwt.opam @@ -17,13 +17,26 @@ license: "LGPL with OpenSSL linking exception" dev-repo: "https://github.com/ocsigen/lwt.git" build: [ [ "jbuilder" "build" "-p" name "-j" jobs ] ] depends: [ + "ocamlfind" { build & >= "1.5.0" } "jbuilder" { build & >= "1.0+beta9" } - "lwt-core" - "lwt-log" - "lwt-unix" - "lwt-preemptive" - "lwt-simple-top" - "lwt-ppx" + "cppo" { build } + "base" { build } # needed for discover.ml + "stdio" { build } # ...but only to write the sexps + "result" +] +depopts: [ + "base-threads" + "base-unix" + "conf-libev" + "camlp4" +] +messages: [ + "For module Lwt_ssl, please install package lwt_ssl" + {ssl:installed & !lwt_ssl:installed} + "For module Lwt_glib, please install package lwt_glib" + {lablgtk:installed & !lwt_glib:installed} + "For module Lwt_react, please install package lwt_react" + {react:installed & !lwt_react:installed} ] post-messages: [ "Lwt+jbuilder has some major breaking changes!!!" diff --git a/lwt-glib.opam b/lwt_glib.opam similarity index 100% rename from lwt-glib.opam rename to lwt_glib.opam diff --git a/lwt-react.opam b/lwt_react.opam similarity index 100% rename from lwt-react.opam rename to lwt_react.opam diff --git a/lwt-ssl.opam b/lwt_ssl.opam similarity index 100% rename from lwt-ssl.opam rename to lwt_ssl.opam diff --git a/src/camlp4/jbuild b/src/camlp4/jbuild index 77186ccc14..5c17abab76 100644 --- a/src/camlp4/jbuild +++ b/src/camlp4/jbuild @@ -1,26 +1,29 @@ (library - ((name lwt_camlp4_options) - (public_name lwt-camlp4.options) + ((name lwt_syntax_options) + (public_name lwt.syntax.options) (synopsis "Options for Lwt Camlp4 syntax extension (deprecated; use lwt.ppx)") + (optional) (modules pa_lwt_options) (wrapped false) (libraries (camlp4)))) (library - ((name lwt_camlp4) - (public_name lwt-camlp4) + ((name lwt_syntax) + (public_name lwt.syntax) (synopsis "Camlp4 syntax for Lwt (deprecated; use lwt.ppx)") + (optional) (modules pa_lwt) (wrapped false) - (libraries (camlp4 lwt-camlp4.options)) + (libraries (camlp4 lwt.syntax.options)) (preprocess (action (run camlp4oof ${<}))))) (library - ((name lwt_camlp4_log) - (public_name lwt-camlp4.log) + ((name lwt_syntax_log) + (public_name lwt.syntax.log) (synopsis "Camlp4 syntax for Lwt logging (deprecated; use lwt.ppx)") + (optional) (modules pa_lwt_log) (wrapped false) - (libraries (camlp4 lwt-camlp4.options)) + (libraries (camlp4 lwt.syntax.options)) (preprocess (action (run camlp4oof ${<}))))) diff --git a/src/core/jbuild b/src/core/jbuild index d65c7ea921..79631cb392 100644 --- a/src/core/jbuild +++ b/src/core/jbuild @@ -2,7 +2,7 @@ (library ((name lwt) - (public_name lwt-core) + (public_name lwt) (synopsis "Monadic promises and concurrent I/O") (wrapped false) (libraries (bytes result)))) diff --git a/src/glib/jbuild b/src/glib/jbuild index 7023265e07..fb5ac4eeff 100644 --- a/src/glib/jbuild +++ b/src/glib/jbuild @@ -2,10 +2,10 @@ (library ((name lwt_glib) - (public_name lwt-glib) + (public_name lwt_glib) (synopsis "GLib integration for Lwt") (wrapped false) - (libraries (lwt-core lwt-unix)) + (libraries (lwt lwt.unix)) (c_names (lwt_glib_stubs)) (c_flags (:include glib_c_flags.sexp)) (c_library_flags (:include glib_c_library_flags.sexp)))) diff --git a/src/logger/jbuild b/src/logger/jbuild index 8c68b77b34..9921cbe3f7 100644 --- a/src/logger/jbuild +++ b/src/logger/jbuild @@ -4,7 +4,8 @@ (library ((name lwt_log) - (public_name lwt-log) + (public_name lwt.log) (synopsis "Logger for Lwt") + (optional) (wrapped false) - (libraries (lwt-core)))) + (libraries (lwt)))) diff --git a/src/ppx/jbuild b/src/ppx/jbuild index a77b120944..e537741e98 100644 --- a/src/ppx/jbuild +++ b/src/ppx/jbuild @@ -2,13 +2,13 @@ (library ((name ppx_lwt) - (public_name lwt-ppx) + (public_name lwt.ppx) (synopsis "Lwt PPX syntax extension") (modules (ppx_lwt)) (libraries (compiler-libs.common ocaml-migrate-parsetree ppx_tools_versioned)) - (ppx_runtime_libraries (lwt-core)) + (ppx_runtime_libraries (lwt)) (kind ppx_rewriter) (preprocess (pps (ppx_tools_versioned.metaquot_404))))) diff --git a/src/preemptive/jbuild b/src/preemptive/jbuild index eaf0d21bd9..b1547e534d 100644 --- a/src/preemptive/jbuild +++ b/src/preemptive/jbuild @@ -2,8 +2,8 @@ (library ((name lwt_preemptive) - (public_name lwt-preemptive) + (public_name lwt.preemptive) (synopsis "Preemptive thread support for Lwt") (wrapped false) - (libraries (lwt-core lwt-unix threads)))) + (libraries (lwt lwt.unix threads)))) diff --git a/src/react/jbuild b/src/react/jbuild index 55a3261ee7..d0ecb48c31 100644 --- a/src/react/jbuild +++ b/src/react/jbuild @@ -2,8 +2,8 @@ (library ((name lwt_react) - (public_name lwt-react) + (public_name lwt_react) (synopsis "Reactive programming helpers for Lwt") (wrapped false) - (libraries (lwt-core react)))) + (libraries (lwt react)))) diff --git a/src/simple_top/jbuild b/src/simple_top/jbuild index 2afafa4694..4f47b71f94 100644 --- a/src/simple_top/jbuild +++ b/src/simple_top/jbuild @@ -2,8 +2,9 @@ (library ((name lwt_simple_top) - (public_name lwt-simple-top) + (public_name lwt.simple-top) (synopsis "Lwt-OCaml top level integration (deprecated; use utop)") + (optional) (wrapped false) - (libraries (lwt-core lwt-unix compiler-libs.common)))) + (libraries (lwt lwt.unix compiler-libs.common)))) diff --git a/src/ssl/jbuild b/src/ssl/jbuild index e67edc6241..c5cef6867f 100644 --- a/src/ssl/jbuild +++ b/src/ssl/jbuild @@ -2,8 +2,8 @@ (library ((name lwt_ssl) - (public_name lwt-ssl) + (public_name lwt_ssl) (synopsis "SSL support for Lwt") (wrapped false) - (libraries (ssl lwt-unix)))) + (libraries (ssl lwt.unix)))) diff --git a/src/unix/jbuild b/src/unix/jbuild index 9a3ce0a7bf..eaf6667db8 100644 --- a/src/unix/jbuild +++ b/src/unix/jbuild @@ -69,10 +69,11 @@ (library ((name lwt_unix) - (public_name lwt-unix) + (public_name lwt.unix) (synopsis "Unix support for Lwt") + (optional) (wrapped false) - (libraries (lwt-core lwt-log unix bigarray)) + (libraries (lwt lwt.log unix bigarray)) (c_names ( lwt_unix_stubs lwt_libev_stubs diff --git a/tests/core/jbuild b/tests/core/jbuild index 2662f313ce..d2a15d5956 100644 --- a/tests/core/jbuild +++ b/tests/core/jbuild @@ -6,6 +6,6 @@ (alias ((name runtest) - (package lwt-core) + (package lwt) (action (run ${exe:main.exe})))) diff --git a/tests/jbuild b/tests/jbuild index 81173baa89..a28330f0fc 100644 --- a/tests/jbuild +++ b/tests/jbuild @@ -3,5 +3,5 @@ (library ((name "lwttester") (wrapped false) - (libraries (lwt-core unix lwt-unix)))) + (libraries (lwt unix lwt.unix)))) diff --git a/tests/ppx/jbuild b/tests/ppx/jbuild index abcb532a1f..dea7e0525e 100644 --- a/tests/ppx/jbuild +++ b/tests/ppx/jbuild @@ -3,11 +3,10 @@ (executable ((name main) (libraries (lwttester)) - (preprocess (pps (lwt-ppx))))) + (preprocess (pps (lwt.ppx))))) (alias ((name runtest) - (package lwt-ppx) + (package lwt) (action (run ${exe:main.exe})))) - diff --git a/tests/preemptive/jbuild b/tests/preemptive/jbuild index cf5c4f27d2..7ace1bd14b 100644 --- a/tests/preemptive/jbuild +++ b/tests/preemptive/jbuild @@ -2,11 +2,11 @@ (executable ((name main) - (libraries (lwt-preemptive lwttester)))) + (libraries (lwt.preemptive lwttester)))) (alias ((name runtest) - (package lwt-preemptive) + (package lwt) (action (run ${exe:main.exe})))) diff --git a/tests/react/jbuild b/tests/react/jbuild index 3acb14cd37..e7574c7f3f 100644 --- a/tests/react/jbuild +++ b/tests/react/jbuild @@ -2,10 +2,10 @@ (executable ((name main) - (libraries (lwt-react lwttester)))) + (libraries (lwt_react lwttester)))) (alias ((name runtest) - (package lwt-react) + (package lwt_react) (action (run ${exe:main.exe})))) diff --git a/tests/unix/jbuild b/tests/unix/jbuild index 4c880d4f79..c865a5386a 100644 --- a/tests/unix/jbuild +++ b/tests/unix/jbuild @@ -11,6 +11,6 @@ (alias ((name runtest) - (package lwt-unix) + (package lwt) (action (run ${exe:main.exe})))) From d99fb6d6ba8974d9d4bd1562d09bc7a88cfd21dc Mon Sep 17 00:00:00 2001 From: andrewray Date: Thu, 25 May 2017 22:00:36 +0100 Subject: [PATCH 18/46] Remove dependancy on Base and Stdio mainly because they are not available on 4.02.0. It means we somewhat hack generation of the sexps used to communicate C flags. Also, dont pass ocamlc to the unix discover script. The default uses "ocamlfind ocamlc", which makes us depend on ocamlfind, but this seems to be needed due to the way options are passed to ocamlc (-ccopt -o -ccopt ) which doesnt work on ocaml < 4.04 (without ocamlfind). --- src/glib/config/discover.ml | 26 ++++++++++++++++---------- src/glib/config/jbuild | 2 +- src/unix/config/discover.ml | 20 ++++++++++++++++---- src/unix/config/jbuild | 3 +-- src/unix/jbuild | 5 ++++- 5 files changed, 38 insertions(+), 18 deletions(-) diff --git a/src/glib/config/discover.ml b/src/glib/config/discover.ml index 50ecd0e911..0dd0ef658b 100644 --- a/src/glib/config/discover.ml +++ b/src/glib/config/discover.ml @@ -1,5 +1,3 @@ -open Base -open Stdio (* This is largely based on the Glib-related code in the main build system, though rewritten somewhat. *) @@ -14,7 +12,7 @@ let pkg_config arguments = let command = Printf.sprintf "pkg-config %s" arguments in let input_channel = Unix.open_process_in command in let result = - try Caml.Pervasives.input_line input_channel + try Pervasives.input_line input_channel with End_of_file -> "" in let status = Unix.close_process_in input_channel in @@ -43,12 +41,11 @@ let pkg_config arguments = result | _ -> - Caml.Printf.eprintf "Command failed: %s" command; - Caml.exit 1 + Printf.eprintf "Command failed: %s" command; + exit 1 (* read ocamlc -config file, if provided *) let get_ocamlc_config name = - let open Caml in let f = open_in name in let cfg line = let idx = String.index line ':' in @@ -66,7 +63,6 @@ let get_ocamlc_config name = cfg let ccomp_type = - let open Caml in try let cfg = get_ocamlc_config Sys.argv.(1) in List.assoc "ccomp_type" cfg @@ -82,10 +78,20 @@ let libs = else pkg_config "--libs glib-2.0" - -let write_sexp fn sexp = Out_channel.write_all fn ~data:(Sexp.to_string sexp) - +(* do sexps properly... let () = + let write_sexp fn sexp = Out_channel.write_all fn ~data:(Sexp.to_string sexp) in write_sexp "glib_c_flags.sexp" (sexp_of_list sexp_of_string cflags); write_sexp "glib_c_library_flags.sexp" (sexp_of_list sexp_of_string libs) +*) + +let () = + let write_sexp n x = + let f = open_out n in + output_string f ("(" ^ String.concat " " x ^ ")"); + close_out f + in + write_sexp ("glib_c_flags.sexp") cflags; + write_sexp ("glib_c_library_flags.sexp") libs + diff --git a/src/glib/config/jbuild b/src/glib/config/jbuild index 54d77565f8..4863fdeae3 100644 --- a/src/glib/config/jbuild +++ b/src/glib/config/jbuild @@ -2,4 +2,4 @@ (executables ((names (discover)) - (libraries (base stdio unix str)))) + (libraries (unix str)))) diff --git a/src/unix/config/discover.ml b/src/unix/config/discover.ml index 15afa35056..cfa81ccd78 100644 --- a/src/unix/config/discover.ml +++ b/src/unix/config/discover.ml @@ -835,19 +835,31 @@ Lwt can use pthread or the win32 API. close_out config; close_out config_ml; - let open Base in - let open Stdio in let get_flags lib = - (try Caml.List.assoc (lib ^ "_opt") !setup_data with _ -> []), - (try Caml.List.assoc (lib ^ "_lib") !setup_data with _ -> []) + (try List.assoc (lib ^ "_opt") !setup_data with _ -> []), + (try List.assoc (lib ^ "_lib") !setup_data with _ -> []) in let cflags_ev, libs_ev = get_flags "libev" in let cflags_pt, libs_pt = get_flags "pthread" in let cflags = cflags_ev @ cflags_pt in let libs = libs_ev @ libs_pt in + (* do sexps properly... + let open Base in + let open Stdio in + let write_sexp fn sexp = Out_channel.write_all fn ~data:(Sexp.to_string sexp) in write_sexp ("unix_c_flags.sexp") (sexp_of_list sexp_of_string ("-I."::cflags)); write_sexp ("unix_c_library_flags.sexp") (sexp_of_list sexp_of_string (libs)) + *) + + let write_sexp n x = + let f = open_out n in + output_string f ("(" ^ String.concat " " x ^ ")"); + close_out f + in + write_sexp ("unix_c_flags.sexp") ("-I."::cflags); + write_sexp ("unix_c_library_flags.sexp") libs + diff --git a/src/unix/config/jbuild b/src/unix/config/jbuild index 2b19b9e428..acaeec2a64 100644 --- a/src/unix/config/jbuild +++ b/src/unix/config/jbuild @@ -1,5 +1,4 @@ (jbuild_version 1) (executable - ((name discover) - (libraries (base stdio)))) + ((name discover))) diff --git a/src/unix/jbuild b/src/unix/jbuild index eaf6667db8..883b9f7ce5 100644 --- a/src/unix/jbuild +++ b/src/unix/jbuild @@ -18,6 +18,10 @@ ((targets (ocamlc_config)) (action (with-stdout-to ${@} (run ${OCAMLC} -config))))) +;; note; the call to (and dependancy on) ocamlfind is avoided by adding: +;; -ocamlc ${OCAMLC} +;; however, this only works on ocaml >= 4.04 due to passing options to ocamlc as +;; "-cclib -o -cclib " (rule ((targets (unix_c_flags.sexp unix_c_library_flags.sexp @@ -25,7 +29,6 @@ lwt_config.ml)) (deps (config/discover.exe ocamlc_config)) (action (run ${<} - -ocamlc ${OCAMLC} ;; avoid call to ocamlfind -ocamlc_config ocamlc_config ;; generated above -use-libev true ;; need some way to find out about conf-libev -android-target false ;; XXX fixme From 6c1705fb33dc200d2eb48a9daec362d4ec720521 Mon Sep 17 00:00:00 2001 From: andrewray Date: Thu, 25 May 2017 22:12:12 +0100 Subject: [PATCH 19/46] fix ppx so it builds on 4.02..04 jbuilder build --workspace jbuild-workspace.dev @install @runtest --only-packages lwt doesnt seem to work though. Hmmm. --- src/ppx/ppx_lwt.ml | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ppx/ppx_lwt.ml b/src/ppx/ppx_lwt.ml index 3609694057..cb997cb835 100644 --- a/src/ppx/ppx_lwt.ml +++ b/src/ppx/ppx_lwt.ml @@ -1,4 +1,5 @@ open Migrate_parsetree +open OCaml_404.Ast open Ast_mapper open Ast_helper open Asttypes From ffffdea2c5fc18a0e6a8fd9e2225318fce8be902 Mon Sep 17 00:00:00 2001 From: andrewray Date: Thu, 25 May 2017 23:29:01 +0100 Subject: [PATCH 20/46] fixup opam files and test across a few ocaml versions --- TODO.jbuild | 14 +++----------- META.lwt.template => _opam-files/META.lwt.template | 0 bad_packages.md | 9 +++++++-- lwt.opam | 2 -- lwt_glib.opam | 5 ++--- lwt_react.opam | 2 +- lwt_ssl.opam | 3 ++- 7 files changed, 15 insertions(+), 20 deletions(-) rename META.lwt.template => _opam-files/META.lwt.template (100%) diff --git a/TODO.jbuild b/TODO.jbuild index 42c921fd40..50a04bd380 100644 --- a/TODO.jbuild +++ b/TODO.jbuild @@ -5,14 +5,6 @@ - how do we depend on an external opam package with no findlib library? - android-target? -- port names from lwt-xxx to lwt_xxx ?? - -- lwt-unix 4.03.0 fails - - "Improve Android support in build system." adds -ccopt -o -ccopt which - doesnt work - - needs special case for andriod - -- no 4.02.0 because of Base and Stdio in discover system - - is there a simpler way to do the sexp generation so we can drop - this requirement? - +- multi-workspace builds dont work + - jbuilder build --workspace jbuild-workspace.dev @install @runtest --only-packages lwt + - problem with ppx diff --git a/META.lwt.template b/_opam-files/META.lwt.template similarity index 100% rename from META.lwt.template rename to _opam-files/META.lwt.template diff --git a/bad_packages.md b/bad_packages.md index 091bcfd633..76b3c874ea 100644 --- a/bad_packages.md +++ b/bad_packages.md @@ -17,8 +17,6 @@ All seem to point to libraries using lwt.unix but only linking to lwt. # findlib: [WARNING] Interface topdirs.cmi occurs in several directories: /home/andyman/.opam/4.04.0/lib/ocaml/compiler-libs, /home/andyman/.opam/4.04.0/lib/ocaml # File "lib/lwt/future_lwt.mli", line 7, characters 22-42: # Error: Unbound module Lwt_io -# Command exited with code 2. -# _build/project.mk:17: recipe for target 'byte' failed ``` # mirage-profile @@ -36,3 +34,10 @@ All seem to point to libraries using lwt.unix but only linking to lwt. # Error: Unbound module Lwt_unix ``` +# markup + +``` +# + ocamlfind ocamlc -c -g -w +A-4-9-44-45-48 -warn-error +A-3 -bin-annot -safe-string -package lwt -package uutf -I src -I doc -I test -I test/performance -I test/dependency -I test/js_of_ocaml -I test/pages -o src/markup_lwt_unix.cmi src/markup_lwt_unix.mli +# File "src/markup_lwt_unix.mli", line 20, characters 14-41: +# Error: Unbound module Lwt_io +``` diff --git a/lwt.opam b/lwt.opam index 6ee2128b06..f930ea28e6 100644 --- a/lwt.opam +++ b/lwt.opam @@ -20,8 +20,6 @@ depends: [ "ocamlfind" { build & >= "1.5.0" } "jbuilder" { build & >= "1.0+beta9" } "cppo" { build } - "base" { build } # needed for discover.ml - "stdio" { build } # ...but only to write the sexps "result" ] depopts: [ diff --git a/lwt_glib.opam b/lwt_glib.opam index ea8d67e1ef..4ecd812cd6 100644 --- a/lwt_glib.opam +++ b/lwt_glib.opam @@ -19,9 +19,8 @@ build: [ [ "jbuilder" "build" "-p" name "-j" jobs ] ] build-test: [ [ "jbuilder" "runtest" "-p" name ] ] depends: [ "jbuilder" { build & >= "1.0+beta9" } - "lwt-unix" - "base" { build } # needed for discover.ml - "stdio" { build } # ...but only to write the sexps + "base-unix" + "lwt" "conf-pkg-config" {build} "conf-glib-2" {build} ] diff --git a/lwt_react.opam b/lwt_react.opam index 9adc3618cf..e36e00fff1 100644 --- a/lwt_react.opam +++ b/lwt_react.opam @@ -19,7 +19,7 @@ build: [ [ "jbuilder" "build" "-p" name "-j" jobs ] ] build-test: [ [ "jbuilder" "runtest" "-p" name ] ] depends: [ "jbuilder" { build & >= "1.0+beta9" } - "lwt-core" + "lwt" "react" ] diff --git a/lwt_ssl.opam b/lwt_ssl.opam index 45c837fd8d..6db9dcdc25 100644 --- a/lwt_ssl.opam +++ b/lwt_ssl.opam @@ -19,8 +19,9 @@ build: [ [ "jbuilder" "build" "-p" name "-j" jobs ] ] build-test: [ [ "jbuilder" "runtest" "-p" name ] ] depends: [ "jbuilder" { build & >= "1.0+beta9" } + "lwt" { >= "3.0.0" } "ssl" { >= "0.5.0" } - "lwt-unix" { >= "3.0.0" } + "base-unix" ] From a926624303b3ea2df33e572c0000876c4d224965 Mon Sep 17 00:00:00 2001 From: andrewray Date: Fri, 26 May 2017 12:23:17 +0100 Subject: [PATCH 21/46] Fix top-level configuration A configure.ml script can be optionally called to set up libev, pthread and android support. This can also be called from opam so we can base configuration on the presence of conf-XXX packages. --- lwt.opam | 7 ++- src/unix/config/discover.ml | 101 ++++++++++++++++++++---------------- src/unix/jbuild | 25 +++++++-- src/util/configure.ml | 36 +++++++++++++ 4 files changed, 119 insertions(+), 50 deletions(-) create mode 100644 src/util/configure.ml diff --git a/lwt.opam b/lwt.opam index f930ea28e6..846c7b960c 100644 --- a/lwt.opam +++ b/lwt.opam @@ -15,10 +15,15 @@ doc: "https://ocsigen.org/lwt/manual/" bug-reports: "https://github.com/ocsigen/lwt/issues" license: "LGPL with OpenSSL linking exception" dev-repo: "https://github.com/ocsigen/lwt.git" -build: [ [ "jbuilder" "build" "-p" name "-j" jobs ] ] +build: [ + [ "ocaml" "src/utils/configure.ml" "-use-libev" "%{conf-libev:installed}" ] + [ "jbuilder" "build" "-p" name "-j" jobs ] +] depends: [ "ocamlfind" { build & >= "1.5.0" } "jbuilder" { build & >= "1.0+beta9" } + "ocaml-migrate-parsetree" + "ppx_tools_versioned" "cppo" { build } "result" ] diff --git a/src/unix/config/discover.ml b/src/unix/config/discover.ml index cfa81ccd78..ac8540bcaa 100644 --- a/src/unix/config/discover.ml +++ b/src/unix/config/discover.ml @@ -310,16 +310,18 @@ CAMLprim value lwt_test() let ocamlc = ref "ocamlfind ocamlc" let ocamlc_config = ref "" +let lwt_config = ref "" let ext_obj = ref ".o" let exec_name = ref "a.out" let use_libev = ref true -let use_glib = false (* glib configuration is external *) -let use_pthread = Sys.os_type <> "Win32" (* as per default in oasis file *) -let use_unix = true (* only called in the context of installing lwt-unix *) +let use_glib = ref false +let use_pthread = ref true +let use_unix = ref true +let os_type = ref "Unix" let android_target = ref false let ccomp_type = ref "cc" -let system = ref "" let libev_default = ref true +let system = ref "" let debug = ref (try Sys.getenv "DEBUG" = "y" with Not_found -> false) let dprintf fmt = @@ -514,18 +516,13 @@ let arg_bool r = let () = let args = [ "-ocamlc", Arg.Set_string ocamlc, " ocamlc"; - "-ocamlc_config", Arg.Set_string ocamlc_config, " ocamlc config"; - "-ext-obj", Arg.Set_string ext_obj, " C object files extension"; - "-exec-name", Arg.Set_string exec_name, " name of the executable produced by ocamlc"; - "-use-libev", arg_bool use_libev, " whether to check for libev"; - "-android-target", arg_bool android_target, " compiles for Android"; - "-ccomp-type", Arg.Set_string ccomp_type, " C compiler type"; - "-libev_default", arg_bool libev_default, " whether to use the libev backend by default"; + "-ocamlc-config", Arg.Set_string ocamlc_config, " ocamlc config"; + "-lwt-config", Arg.Set_string lwt_config, " lwt config"; ] in Arg.parse args ignore "check for external C libraries and available features\noptions are:"; (* Check nothing if we do not build lwt.unix. *) - if not use_unix then exit 0; + if not !use_unix then exit 0; (* Put the caml code into a temporary file. *) let file, oc = Filename.open_temp_file "lwt_caml" ".ml" in @@ -545,9 +542,10 @@ let () = safe_remove (Filename.chop_extension !caml_file ^ ".cmi"); safe_remove (Filename.chop_extension !caml_file ^ ".cmo")); - (* read ocamlc -config file, if provided *) - let get_ocamlc_config () = - let f = open_in !ocamlc_config in + (* read ocamlc -config and lwt config files. + The former must exist, but we can apply defaults for the later. *) + let read_config config filename = + let f = open_in filename in let cfg line = let idx = String.index line ':' in String.sub line 0 idx, @@ -563,30 +561,45 @@ let () = let () = close_in f in cfg in - let ocamlc_configs = - try if !ocamlc_config <> "" then get_ocamlc_config () else [] - with _ -> - let () = printf "failed to read ocamlc -config\n" in - exit 1 - in - (* get params from ocamlc -config, if provided *) + let () = if !ocamlc_config = "" then begin + printf "Configuration file for 'ocamlc -config' does not exist\n"; + exit 1; + end in + let ocamlc_config = read_config "ocamlc" !ocamlc_config in + let lwt_config = try read_config "lwt" !lwt_config with _ -> [] in + (* get params from configuration files *) let () = - if !ocamlc_config <> "" then begin - let set var name = - try - var := List.assoc name ocamlc_configs; - printf "found config var %s: %s %s\n" name (String.make (29 - String.length name) '.') !var - with Not_found -> - printf "Couldn't find var '%s' in ocamlc -config\n" name; - exit 1 - in - set ext_obj "ext_obj"; - set exec_name "default_executable_name"; - set ccomp_type "ccomp_type"; - set system "system"; - libev_default := List.mem !system (* as per _oasis *) - ["linux"; "linux_elf"; "linux_aout"; "linux_eabi"; "linux_eabihf"]; - end + let get var name = + try + var := List.assoc name ocamlc_config; + printf "found config var %s: %s %s\n" name (String.make (29 - String.length name) '.') !var + with Not_found -> + printf "Couldn't find value '%s' in 'ocamlc -config'\n" name; + exit 1 + in + get ext_obj "ext_obj"; + get exec_name "default_executable_name"; + get ccomp_type "ccomp_type"; + get system "system"; + let get var name default = + try + let () = + match List.assoc name lwt_config with + | "true" -> var := true + | "false" -> var := false + | _ -> raise Not_found + in + printf "found config var %s: %s %b\n" name (String.make (29 - String.length name) '.') !var + with Not_found -> + var := default + in + (* set up the defaults as per the original _oasis file *) + get android_target "android_target" false; + get use_pthread "use_pthread" (!os_type <> "Win32"); + get use_libev "use_libev" (!os_type <> "Win32" && !android_target = false); + get libev_default "libev_default" + (List.mem !system (* as per _oasis *) + ["linux"; "linux_elf"; "linux_aout"; "linux_eabi"; "linux_eabihf"]); in @@ -605,7 +618,7 @@ Run with DEBUG=y for more details. let setup_data = ref [] in (* Test for pkg-config. *) - test_feature ~do_check:(!use_libev || use_glib) "pkg-config" "" + test_feature ~do_check:(!use_libev || !use_glib) "pkg-config" "" (fun () -> ksprintf Sys.command "pkg-config --version > %s 2>&1" !log_file = 0); @@ -689,8 +702,8 @@ You may be missing core components (compiler, ncurses, etc) end; test_feature ~do_check:!use_libev "libev" "HAVE_LIBEV" test_libev; - test_feature ~do_check:use_pthread "pthread" "HAVE_PTHREAD" test_pthread; - test_feature ~do_check:use_glib "glib" "" test_glib; + test_feature ~do_check:!use_pthread "pthread" "HAVE_PTHREAD" test_pthread; + test_feature ~do_check:!use_glib "glib" "" test_glib; if !not_available <> [] then begin if not have_pkg_config then @@ -712,7 +725,7 @@ Missing C libraries: %s exit 1 end; - if Sys.os_type <> "Win32" && not use_pthread then begin + if !os_type <> "Win32" && not !use_pthread then begin printf " No threading library available! @@ -723,7 +736,7 @@ Lwt can use pthread or the win32 API. exit 1 end; - let do_check = Sys.os_type <> "Win32" in + let do_check = !os_type <> "Win32" in test_feature ~do_check "eventfd" "HAVE_EVENTFD" (fun () -> test_code ([], []) eventfd_code); test_feature ~do_check "fd passing" "HAVE_FD_PASSING" (fun () -> test_code ([], []) fd_passing_code); test_feature ~do_check:(do_check && not !android_target) @@ -762,7 +775,7 @@ Lwt can use pthread or the win32 API. "let _HAVE_GET_CREDENTIALS = %s\n" (String.concat " || " (List.map (fun s -> "_" ^ s) get_cred_vars)); - if Sys.os_type = "Win32" then begin + if !os_type = "Win32" then begin output_string config "#define LWT_ON_WINDOWS\n"; end else begin output_string config "//#define LWT_ON_WINDOWS\n"; diff --git a/src/unix/jbuild b/src/unix/jbuild index 883b9f7ce5..34b37274ac 100644 --- a/src/unix/jbuild +++ b/src/unix/jbuild @@ -12,12 +12,28 @@ (deps (lwt_unix.cppo.mli)) (action (run ${bin:cppo} -V OCAML:${ocaml_version} ${<} -o ${@})))) -;; lwt discover.ml +;; lwt feature discovery +;; +;; we use 2 config files +;; +;; - ocamlc_config which is generated here from calling 'ocamlc -config' +;; - lwt_config which is optionally generated by src/utils/configure.ml +;; and contains configuration options for libev, pthread, android etc. +;; +;; The later configration file can be used for development and by opam +;; to enable features based on the system configuration. +;; run ocamlc -config (rule ((targets (ocamlc_config)) (action (with-stdout-to ${@} (run ${OCAMLC} -config))))) +;; generate an empty lwt_config if it doesn't exist. +;; the discover script will generate defaults as appropriate. +(rule + ((targets (lwt_config)) + (action (with-stdout-to lwt_config (echo ""))))) + ;; note; the call to (and dependancy on) ocamlfind is avoided by adding: ;; -ocamlc ${OCAMLC} ;; however, this only works on ocaml >= 4.04 due to passing options to ocamlc as @@ -27,11 +43,10 @@ unix_c_library_flags.sexp lwt_config.h lwt_config.ml)) - (deps (config/discover.exe ocamlc_config)) + (deps (config/discover.exe ocamlc_config lwt_config)) (action (run ${<} - -ocamlc_config ocamlc_config ;; generated above - -use-libev true ;; need some way to find out about conf-libev - -android-target false ;; XXX fixme + -ocamlc-config ocamlc_config ;; generated above + -lwt-config lwt_config )))) ;; gen_stubs.ml diff --git a/src/util/configure.ml b/src/util/configure.ml new file mode 100644 index 0000000000..550faf882c --- /dev/null +++ b/src/util/configure.ml @@ -0,0 +1,36 @@ +(* top-level lwt feature configuration *) + +let use_libev = ref None +let use_pthread = ref None +let android_target = ref None +let libev_default = ref None + +let arg_bool r = + Arg.Symbol (["true"; "false"], + function + | "true" -> r := Some true + | "false" -> r := Some false + | _ -> assert false) +let args = [ + "-use-libev", arg_bool use_libev, " whether to check for libev"; + "-use-pthread", arg_bool use_pthread, " whether to use pthread"; + "-android-target", arg_bool android_target, " compile for Android"; + "-libev-default", arg_bool libev_default, " whether to use the libev backend by default"; +] + +let main () = + Arg.parse args ignore "enable lwt unix features\noptions are:"; + let f = open_out "src/unix/lwt_config" in + let print name var = + match var with + | None -> () + | Some var -> Printf.fprintf f "%s: %b\n" name var + in + print"use_libev" !use_libev; + print"use_pthread" !use_pthread; + print"android_target" !android_target; + print"libev_default" !libev_default; + close_out f + +let () = main () + From 3b2953408992304d110eaceb73a8814513e458f5 Mon Sep 17 00:00:00 2001 From: andrewray Date: Fri, 26 May 2017 12:40:53 +0100 Subject: [PATCH 22/46] fix lwt.opam typo --- lwt.opam | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lwt.opam b/lwt.opam index 846c7b960c..65f83b3ede 100644 --- a/lwt.opam +++ b/lwt.opam @@ -16,7 +16,7 @@ bug-reports: "https://github.com/ocsigen/lwt/issues" license: "LGPL with OpenSSL linking exception" dev-repo: "https://github.com/ocsigen/lwt.git" build: [ - [ "ocaml" "src/utils/configure.ml" "-use-libev" "%{conf-libev:installed}" ] + [ "ocaml" "src/util/configure.ml" "-use-libev" "%{conf-libev:installed}%" ] [ "jbuilder" "build" "-p" name "-j" jobs ] ] depends: [ From 49d909abd967a1322fbfedad9dcc773cb0871267 Mon Sep 17 00:00:00 2001 From: andrewray Date: Fri, 26 May 2017 13:25:16 +0100 Subject: [PATCH 23/46] fix error message in discover.ml --- src/unix/config/discover.ml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/unix/config/discover.ml b/src/unix/config/discover.ml index ac8540bcaa..4a917ae514 100644 --- a/src/unix/config/discover.ml +++ b/src/unix/config/discover.ml @@ -714,11 +714,11 @@ You may be missing core components (compiler, ncurses, etc) printf " Some required C libraries were not found. If a C library is installed in a non-standard location, set _CFLAGS and _LIBS accordingly. You may also -try 'ocaml setup.ml -configure --disable-' to avoid compiling support for +try 'ocaml src/utils/configure.ml -use- false' to avoid compiling support for it. For example, in the case of libev missing: export LIBEV_CFLAGS=-I/opt/local/include export LIBEV_LIBS='-L/opt/local/lib -lev' - (* or: *) ocaml setup.ml -configure --disable-libev + (* or: *) ocaml src/utils/configure.ml -use-libev false Missing C libraries: %s " (String.concat ", " !not_available); From cd1e12c7cf1943621b9ca38c42936c1c53697270 Mon Sep 17 00:00:00 2001 From: andrewray Date: Fri, 26 May 2017 14:31:23 +0100 Subject: [PATCH 24/46] add workspace file. works with current jbuilder master --- jbuild-workspace.dev | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 jbuild-workspace.dev diff --git a/jbuild-workspace.dev b/jbuild-workspace.dev new file mode 100644 index 0000000000..645ed73de4 --- /dev/null +++ b/jbuild-workspace.dev @@ -0,0 +1,3 @@ +(context ((switch 4.02.3))) +(context ((switch 4.03.0))) +(context ((switch 4.04.0))) From 5a044c6a25dd9b80f3f80d96341a40d8e5da0602 Mon Sep 17 00:00:00 2001 From: andrewray Date: Fri, 26 May 2017 14:51:24 +0100 Subject: [PATCH 25/46] have a go at updating the travis script --- jbuild-workspace.dev | 2 +- src/util/travis.sh | 13 +++++-------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/jbuild-workspace.dev b/jbuild-workspace.dev index 645ed73de4..b004872c61 100644 --- a/jbuild-workspace.dev +++ b/jbuild-workspace.dev @@ -1,3 +1,3 @@ (context ((switch 4.02.3))) (context ((switch 4.03.0))) -(context ((switch 4.04.0))) +(context ((switch 4.04.1))) diff --git a/src/util/travis.sh b/src/util/travis.sh index 2814336209..7238f66738 100644 --- a/src/util/travis.sh +++ b/src/util/travis.sh @@ -117,7 +117,7 @@ fi # Pin Lwt, install dependencies, and then install Lwt. Lwt is installed # separately because we want to keep the build directory for running the tests. -opam pin add -y --no-action . +opam pin add -y --no-action lwt . opam install -y --deps-only lwt opam install -y camlp4 @@ -128,14 +128,12 @@ fi opam install --keep-build-dir --verbose lwt -# Pin additional packages, generate their build systems, and install them. There +# Pin additional packages and install them. There # aren't any specific tests for these packages. Installation itself is the only -# test. Build system generation requires OASIS; this should have been installed -# while installing dependencies of Lwt. +# test. install_extra_package () { PACKAGE=$1 - ( cd src/$PACKAGE/ && oasis setup -setup-update none ) - opam pin add -y --no-action src/$PACKAGE/ + opam pin add -y --no-action $PACKAGE . opam install -y --verbose lwt_$PACKAGE } @@ -146,7 +144,6 @@ install_extra_package glib # Build and run the tests. opam install -y ounit cd `opam config var lib`/../build/lwt.* -ocaml setup.ml -configure --enable-tests make test @@ -157,5 +154,5 @@ then ! opam list -i conf-libev fi -opam list -i ppx_tools +opam list -i ppx_tools_versioned ! opam list -i batteries From a17ec270f2dd6599fb2f2257669cb9299fedcaab Mon Sep 17 00:00:00 2001 From: andrewray Date: Fri, 26 May 2017 15:25:41 +0100 Subject: [PATCH 26/46] try to fix travis script (part 2 of many...) --- src/util/travis.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util/travis.sh b/src/util/travis.sh index 7238f66738..34a53a656d 100644 --- a/src/util/travis.sh +++ b/src/util/travis.sh @@ -133,7 +133,7 @@ opam install --keep-build-dir --verbose lwt # test. install_extra_package () { PACKAGE=$1 - opam pin add -y --no-action $PACKAGE . + opam pin add -y --no-action lwt_$PACKAGE . opam install -y --verbose lwt_$PACKAGE } From c13e28a5654ff0fc46c9c81d72456bd3257db822 Mon Sep 17 00:00:00 2001 From: andrewray Date: Fri, 26 May 2017 16:05:16 +0100 Subject: [PATCH 27/46] try to fix appveyor --- README.md | 2 +- src/util/appveyor-build.sh | 13 ++++++------- src/util/appveyor-install.sh | 8 +++----- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 56386cbfe9..b89a10a866 100644 --- a/README.md +++ b/README.md @@ -119,7 +119,7 @@ version, opam source --dev-repo --pin lwt ``` -This will also install the development dependency OASIS. +This will also install the development dependency jbuilder. A list of [project suggestions][projects] and a [roadmap][roadmap] can be found on the wiki. diff --git a/src/util/appveyor-build.sh b/src/util/appveyor-build.sh index 8553888e90..91c7f37d8f 100644 --- a/src/util/appveyor-build.sh +++ b/src/util/appveyor-build.sh @@ -3,14 +3,13 @@ set -x if [ "$SYSTEM" = cygwin ] then - PACKAGES="lwt lwt_react lwt_ssl" + opam install -y --keep-build-dir --verbose lwt lwt_react lwt_ssl + cd `opam config var lib`/../build/lwt.* + jbuilder runtest --only-packages lwt,lwt_react,lwt_ssl else - PACKAGES="lwt lwt_react" + opam install -y --keep-build-dir --verbose lwt lwt_react + cd `opam config var lib`/../build/lwt.* + jbuilder runtest --only-packages lwt,lwt_react fi -opam install -y --keep-build-dir --verbose $PACKAGES -cd `opam config var lib`/../build/lwt.* -ocaml setup.ml -configure --enable-tests -make test - ! opam list -i batteries diff --git a/src/util/appveyor-install.sh b/src/util/appveyor-install.sh index f02673278d..1fb6ee8aa1 100644 --- a/src/util/appveyor-install.sh +++ b/src/util/appveyor-install.sh @@ -11,8 +11,7 @@ CACHE=$DIRECTORY/../opam-cache-$SYSTEM-$COMPILER-$LIBEV.tar pin_extra_package () { PACKAGE=$1 - ( cd src/$PACKAGE/ && oasis setup -setup-update none ) - opam pin add -y --no-action src/$PACKAGE/ + opam pin add -y --no-action lwt_$PACKAGE } if [ ! -f $CACHE ] @@ -20,9 +19,8 @@ then opam init -y --auto-setup eval `opam config env` - # Pin Lwt and install its dependencies. This also installs OASIS, which is - # needed later to generate the build systems of extra packages.s - opam pin add -y --no-action . + # Pin Lwt and install its dependencies. + opam pin add -y --no-action lwt . opam install -y --deps-only lwt opam install -y camlp4 if [ "$LIBEV" = yes ] From 20a979dbb2d89ec1f76f77f6ccc26fdd40524dab Mon Sep 17 00:00:00 2001 From: andrewray Date: Fri, 26 May 2017 16:13:31 +0100 Subject: [PATCH 28/46] try to fix appveyor script --- src/util/appveyor-install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util/appveyor-install.sh b/src/util/appveyor-install.sh index 1fb6ee8aa1..d9b2a93952 100644 --- a/src/util/appveyor-install.sh +++ b/src/util/appveyor-install.sh @@ -11,7 +11,7 @@ CACHE=$DIRECTORY/../opam-cache-$SYSTEM-$COMPILER-$LIBEV.tar pin_extra_package () { PACKAGE=$1 - opam pin add -y --no-action lwt_$PACKAGE + opam pin add -y --no-action lwt_$PACKAGE . } if [ ! -f $CACHE ] From 358f33325c49381d8d81970b8cd4b0911c700faf Mon Sep 17 00:00:00 2001 From: andrewray Date: Fri, 26 May 2017 18:21:31 +0100 Subject: [PATCH 29/46] set os_type correctly in discover.ml --- src/unix/config/discover.ml | 1 + 1 file changed, 1 insertion(+) diff --git a/src/unix/config/discover.ml b/src/unix/config/discover.ml index 4a917ae514..737cd6e67e 100644 --- a/src/unix/config/discover.ml +++ b/src/unix/config/discover.ml @@ -581,6 +581,7 @@ let () = get exec_name "default_executable_name"; get ccomp_type "ccomp_type"; get system "system"; + get os_type "os_type"; let get var name default = try let () = From 4973a51a545f5dae29ddb6e41e21436c40fdd5dd Mon Sep 17 00:00:00 2001 From: andrewray Date: Fri, 26 May 2017 18:44:06 +0100 Subject: [PATCH 30/46] and finally link with ws2_32 library --- src/unix/config/discover.ml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/unix/config/discover.ml b/src/unix/config/discover.ml index 737cd6e67e..6b62ac8cb9 100644 --- a/src/unix/config/discover.ml +++ b/src/unix/config/discover.ml @@ -868,6 +868,15 @@ Lwt can use pthread or the win32 API. write_sexp ("unix_c_library_flags.sexp") (sexp_of_list sexp_of_string (libs)) *) + (* add Win32 linker flags *) + let libs = + if !os_type = "Win32" then + if !ccomp_type = "msvc" then libs @ ["ws2_32.lib"] + else libs @ ["-lws2_32"] + else + libs + in + let write_sexp n x = let f = open_out n in output_string f ("(" ^ String.concat " " x ^ ")"); From 353f5019829ec6feae10a1adb79168b357e16d08 Mon Sep 17 00:00:00 2001 From: andrewray Date: Sat, 27 May 2017 15:32:56 +0100 Subject: [PATCH 31/46] for appveryor, run the tests through opam instead. --- lwt.opam | 1 + src/util/appveyor-build.sh | 9 +++------ 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/lwt.opam b/lwt.opam index 65f83b3ede..5bd124e6e4 100644 --- a/lwt.opam +++ b/lwt.opam @@ -19,6 +19,7 @@ build: [ [ "ocaml" "src/util/configure.ml" "-use-libev" "%{conf-libev:installed}%" ] [ "jbuilder" "build" "-p" name "-j" jobs ] ] +build-test: [ [ "jbuilder" "runtest" "-p" name ] ] depends: [ "ocamlfind" { build & >= "1.5.0" } "jbuilder" { build & >= "1.0+beta9" } diff --git a/src/util/appveyor-build.sh b/src/util/appveyor-build.sh index 91c7f37d8f..2b724812c1 100644 --- a/src/util/appveyor-build.sh +++ b/src/util/appveyor-build.sh @@ -1,15 +1,12 @@ set -e set -x +# install packages and run tests if [ "$SYSTEM" = cygwin ] then - opam install -y --keep-build-dir --verbose lwt lwt_react lwt_ssl - cd `opam config var lib`/../build/lwt.* - jbuilder runtest --only-packages lwt,lwt_react,lwt_ssl + opam install -y -t --verbose lwt lwt_react lwt_ssl else - opam install -y --keep-build-dir --verbose lwt lwt_react - cd `opam config var lib`/../build/lwt.* - jbuilder runtest --only-packages lwt,lwt_react + opam install -y -t --verbose lwt lwt_react fi ! opam list -i batteries From b9ff5dc00c957a4cefc4aef7a63ef3b9dafd393b Mon Sep 17 00:00:00 2001 From: andrewray Date: Sat, 27 May 2017 17:38:33 +0100 Subject: [PATCH 32/46] add jbuilder odoc target, disable 4.05 on travis pin jbuilder to dev to see if issue #101 causes the travis timeout --- .travis.yml | 4 ++-- Makefile | 15 ++++++++++----- src/util/travis.sh | 4 +++- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/.travis.yml b/.travis.yml index a6addab363..76b65b0bfa 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,8 +8,8 @@ matrix: env: COMPILER=4.03 - os: linux env: COMPILER=4.04 - - os: linux - env: COMPILER=4.05 + #- os: linux + # env: COMPILER=4.05 - os: linux env: COMPILER=4.04 FLAMBDA=yes - os: linux diff --git a/Makefile b/Makefile index 765a79a649..9839e4b4a5 100644 --- a/Makefile +++ b/Makefile @@ -18,16 +18,21 @@ build: --only-packages lwt \ @install -doc-api: $(SETUP) setup.data build - ./$(SETUP) -build lwt-api.docdir/index.html +# build everything +all: + jbuilder build @install # run all tests test: jbuilder runtest -# build everything -all: - jbuilder build @install +# Use jbuilder/odoc to generate static html documentation. +# Requires ocaml 4.03.0 to install odoc currently. +doc: + jbuilder build @doc + +doc-api: $(SETUP) setup.data build + ./$(SETUP) -build lwt-api.docdir/index.html install: jbuilder install diff --git a/src/util/travis.sh b/src/util/travis.sh index 34a53a656d..ace0d0dbb2 100644 --- a/src/util/travis.sh +++ b/src/util/travis.sh @@ -113,7 +113,9 @@ then echo Expected OCaml $OCAML_VERSION, but $ACTUAL_COMPILER is installed fi - +# XXX Temporary - pin jbuild to dev repo to check if #101 is causing the +# travis error on 4.02.3+libev +opam pin add -y --no-action jbuilder -k git https://github.com/janestreet/jbuilder # Pin Lwt, install dependencies, and then install Lwt. Lwt is installed # separately because we want to keep the build directory for running the tests. From 890ccc29ab2632a168401b0c268def8230ece214 Mon Sep 17 00:00:00 2001 From: andrewray Date: Sat, 27 May 2017 19:05:24 +0100 Subject: [PATCH 33/46] print each tests to see whats failing on travis also, remove jbuilder pin - wasn't that. --- src/util/travis.sh | 4 ---- tests/test.ml | 12 ++++++------ 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/util/travis.sh b/src/util/travis.sh index ace0d0dbb2..93ff9173dd 100644 --- a/src/util/travis.sh +++ b/src/util/travis.sh @@ -113,10 +113,6 @@ then echo Expected OCaml $OCAML_VERSION, but $ACTUAL_COMPILER is installed fi -# XXX Temporary - pin jbuild to dev repo to check if #101 is causing the -# travis error on 4.02.3+libev -opam pin add -y --no-action jbuilder -k git https://github.com/janestreet/jbuilder - # Pin Lwt, install dependencies, and then install Lwt. Lwt is installed # separately because we want to keep the build directory for running the tests. opam pin add -y --no-action lwt . diff --git a/tests/test.ml b/tests/test.ml index 35746627e7..6ff0230090 100644 --- a/tests/test.ml +++ b/tests/test.ml @@ -51,9 +51,9 @@ let run name suites = match suites with | [] -> if failures = 0 then - Printf.printf "\r\027[JDone. %d test(s) skipped.\n%!" skipped + Printf.printf "Done. %d test(s) skipped.\n%!" skipped else begin - Printf.printf "\r\027[JDone. %d of %d tests failed.\n%!" failures total; + Printf.printf "Done. %d of %d tests failed.\n%!" failures total; exit 1 end | suite :: suites -> @@ -67,27 +67,27 @@ let run name suites = loop_suites failures skipped number suites | test :: tests -> if not (test.only_if ()) then begin - Printf.printf "\r\027[J(%d/%d) Skipping test %S from suite %S%!" + Printf.printf "(%d/%d) Skipping test %S from suite %S\b%!" number total test.name suite_name; loop_tests failures (skipped + 1) suite_name (number + 1) suites tests end else begin - Printf.printf "\r\027[J(%d/%d) Running test %S from suite %S%!" + Printf.printf "(%d/%d) Running test %S from suite %S\n%!" number total test.name suite_name; try if test.run () then loop_tests failures skipped suite_name (number + 1) suites tests else begin Printf.printf - "\r\027[J\027[31;1mTest %S from suite %S failed.\027[0m\n%!" + "Test %S from suite %S failed.\n%!" test.name suite_name; loop_tests (failures + 1) skipped suite_name (number + 1) suites tests end with exn -> Printf.printf - "\r\027[J\027[31;1mTest %S from suite %S failed. It raised: %S.\027[0m\n%!" + "Test %S from suite %S failed. It raised: %S.\n%!" test.name suite_name (Printexc.to_string exn); loop_tests (failures + 1) skipped suite_name (number + 1) suites tests From d827388f0779b1fef11d5349b67db1ffa64e6555 Mon Sep 17 00:00:00 2001 From: andrewray Date: Sat, 27 May 2017 23:23:39 +0100 Subject: [PATCH 34/46] add makefile for wikidoc and ocamldoc generation this isn't integrated into the rather mysterious jenkins build infrastructure, though. --- Makefile | 14 +- doc/Makefile | 51 +++ doc/examples/gtk/Makefile | 2 - src/util/discover.ml | 796 -------------------------------------- 4 files changed, 62 insertions(+), 801 deletions(-) create mode 100644 doc/Makefile delete mode 100644 doc/examples/gtk/Makefile delete mode 100644 src/util/discover.ml diff --git a/Makefile b/Makefile index 9839e4b4a5..14ee0e4675 100644 --- a/Makefile +++ b/Makefile @@ -27,12 +27,19 @@ test: jbuilder runtest # Use jbuilder/odoc to generate static html documentation. -# Requires ocaml 4.03.0 to install odoc currently. +# Currenty requires ocaml 4.03.0 to install odoc. doc: jbuilder build @doc -doc-api: $(SETUP) setup.data build - ./$(SETUP) -build lwt-api.docdir/index.html +# Build HTML documentation with ocamldoc +doc-api-html: all + make -C doc api/html/index.html + +# Build wiki documentation with wikidoc +# requires ocaml 4.03.0 and pinning the repo +# https://github.com/ocsigen/wikidoc +doc-api-wiki: all + make -C doc api/wiki/index.wiki install: jbuilder install @@ -47,6 +54,7 @@ reinstall: clean: rm -fr _build rm -f *.install + rm -fr doc/api clean-coverage: rm -rf bisect*.out diff --git a/doc/Makefile b/doc/Makefile new file mode 100644 index 0000000000..44a9a4a0f7 --- /dev/null +++ b/doc/Makefile @@ -0,0 +1,51 @@ +BLD=../_build/default/src +SRC=../src + +PKGS=\ + -package bytes -package result \ + -package bigarray -package unix -package camlp4 \ + -package ocaml-migrate-parsetree -package ppx_tools_versioned \ + -package react -package ssl + +INCS=\ + -I ${BLD}/camlp4 \ + -I ${BLD}/core \ + -I ${BLD}/glib \ + -I ${BLD}/logger \ + -I ${BLD}/ppx \ + -I ${BLD}/preemptive \ + -I ${BLD}/react \ + -I ${BLD}/simple_top \ + -I ${BLD}/ssl \ + -I ${BLD}/unix + +MLIS=\ + $(wildcard ${SRC}/camlp4/*.mli) \ + $(wildcard ${SRC}/core/*.mli) \ + $(wildcard ${SRC}/glib/*.mli) \ + $(wildcard ${SRC}/logger/*.mli) \ + $(wildcard ${SRC}/ppx/*.mli) \ + $(wildcard ${SRC}/preemptive/*.mli) \ + $(wildcard ${SRC}/react/*.mli) \ + $(wildcard ${SRC}/simple_top/*.mli) \ + $(wildcard ${SRC}/ssl/*.mli) \ + $(filter-out ${BLD}/unix/lwt_unix.cppo.mli,$(wildcard ${BLD}/unix/*.mli)) + +DOCOPT := -colorize-code -short-functors -charset utf-8 + +.PHONY: doc wikidoc +doc: api/html/index.html +api/html/index.html: ${MLIS} apiref-intro + mkdir -p api/html + ocamlfind ocamldoc ${DOCOPT} -package ocamlbuild,uchar ${PKGS} ${INCS} -intro apiref-intro -html \ + -d api/html \ + ${MLIS} + +wikidoc: api/wiki/index.wiki +api/wiki/index.wiki: ${MLIS} apiref-intro + mkdir -p api/wiki + ocamlfind ocamldoc ${DOCOPT} -package ocamlbuild,uchar ${PKGS} ${INCS} -intro apiref-intro \ + -d api/wiki \ + -i $(shell ocamlfind query wikidoc) -g odoc_wiki.cma \ + ${MLIS} + diff --git a/doc/examples/gtk/Makefile b/doc/examples/gtk/Makefile deleted file mode 100644 index bfc1eaf1e4..0000000000 --- a/doc/examples/gtk/Makefile +++ /dev/null @@ -1,2 +0,0 @@ -all: - ocamlbuild -use-ocamlfind -classic-display -package lwt.unix,lwt.glib,lwt.ppx,lablgtk2 connect.byte diff --git a/src/util/discover.ml b/src/util/discover.ml deleted file mode 100644 index fcc8597752..0000000000 --- a/src/util/discover.ml +++ /dev/null @@ -1,796 +0,0 @@ -(* OCaml promise library - * http://www.ocsigen.org/lwt - * Copyright (C) 2010 Jérémie Dimino - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, with linking exceptions; - * either version 2.1 of the License, or (at your option) any later - * version. See COPYING file for details. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. - *) - -(* Discover available features *) - -open Printf - -(* +-----------------------------------------------------------------+ - | Search path | - +-----------------------------------------------------------------+ *) - -(* List of search paths for header files, mostly for MacOS - users. libev is installed by port systems into non-standard - locations by default on MacOS. - - We use a hardcorded list of path + the ones from C_INCLUDE_PATH and - LIBRARY_PATH. -*) - -let ( // ) = Filename.concat - -let default_search_paths = - List.map (fun dir -> (dir // "include", dir // "lib")) [ - "/usr"; - "/usr/local"; - "/usr/pkg"; - "/opt"; - "/opt/local"; - "/sw"; - "/mingw"; - ] - -let path_sep = if Sys.os_type = "Win32" then ';' else ':' - -let split_path str = - let len = String.length str in - let rec aux i = - if i >= len then - [] - else - let j = try String.index_from str i path_sep with Not_found -> len in - String.sub str i (j - i) :: aux (j + 1) - in - aux 0 - -let rec replace_last path ~patt ~repl = - let comp = Filename.basename path - and parent = Filename.dirname path in - if comp = patt then - parent // repl - else if parent = path then - path - else - (replace_last parent ~patt ~repl) // comp - -let search_paths = - let get var f = - try - List.map f (split_path (Sys.getenv var)) - with Not_found -> - [] - in - List.flatten [ - get "C_INCLUDE_PATH" (fun dir -> (dir, replace_last dir ~patt:"include" ~repl:"lib")); - get "LIBRARY_PATH" (fun dir -> (replace_last dir ~patt:"lib" ~repl:"include", dir)); - default_search_paths; - ] - -(* +-----------------------------------------------------------------+ - | Test codes | - +-----------------------------------------------------------------+ *) - -let caml_code = " -external test : unit -> unit = \"lwt_test\" -let () = test () -" - -let trivial_code = " -#include - -CAMLprim value lwt_test(value Unit) -{ - return Val_unit; -} -" - -let pthread_code = " -#include -#include - -CAMLprim value lwt_test(value Unit) -{ - pthread_create(0, 0, 0, 0); - return Val_unit; -} -" - -let libev_code = " -#include -#include - -CAMLprim value lwt_test(value Unit) -{ - ev_default_loop(0); - return Val_unit; -} -" - -let fd_passing_code = " -#include -#include -#include - -CAMLprim value lwt_test(value Unit) -{ - struct msghdr msg; - msg.msg_controllen = 0; - msg.msg_control = 0; - return Val_unit; -} -" - -let getcpu_code = " -#include -#define _GNU_SOURCE -#include - -CAMLprim value lwt_test(value Unit) -{ - sched_getcpu(); - return Val_unit; -} -" - -let affinity_code = " -#include -#define _GNU_SOURCE -#include - -CAMLprim value lwt_test(value Unit) -{ - sched_getaffinity(0, 0, 0); - return Val_unit; -} -" - -let eventfd_code = " -#include -#include - -CAMLprim value lwt_test(value Unit) -{ - eventfd(0, 0); - return Val_unit; -} -" - -let get_credentials_code struct_name = " -#define _GNU_SOURCE -#include -#include -#include - -CAMLprim value lwt_test(value Unit) -{ - struct " ^ struct_name ^ " cred; - socklen_t cred_len = sizeof(cred); - getsockopt(0, SOL_SOCKET, SO_PEERCRED, &cred, &cred_len); - return Val_unit; -} -" - -let get_peereid_code = " -#include -#include -#include - -CAMLprim value lwt_test(value Unit) -{ - uid_t euid; - gid_t egid; - getpeereid(0, &euid, &egid); - return Val_unit; -} -" - -let fdatasync_code = " -#include -#include - -CAMLprim value lwt_test(value Unit) -{ - int (*fdatasyncp)(int) = fdatasync; - fdatasyncp(0); - return Val_unit; -} -" - -let glib_code = " -#include -#include - -CAMLprim value lwt_test(value Unit) -{ - g_main_context_dispatch(0); - return Val_unit; -} -" - -let netdb_reentrant_code = " -#define _POSIX_PTHREAD_SEMANTICS -#include -#include -#include - -CAMLprim value lwt_test(value Unit) -{ - struct hostent *he; - struct servent *se; - he = gethostbyname_r((const char *)NULL, (struct hostent *)NULL,(char *)NULL, (int)0, (struct hostent **)NULL, (int *)NULL); - he = gethostbyaddr_r((const char *)NULL, (int)0, (int)0,(struct hostent *)NULL, (char *)NULL, (int)0, (struct hostent **)NULL,(int *)NULL); - se = getservbyname_r((const char *)NULL, (const char *)NULL,(struct servent *)NULL, (char *)NULL, (int)0, (struct servent **)NULL); - se = getservbyport_r((int)0, (const char *)NULL,(struct servent *)NULL, (char *)NULL, (int)0, (struct servent **)NULL); - pr = getprotoent_r((struct protoent *)NULL, (char *)NULL, (int)0, (struct protoent **)NULL); - pr = getprotobyname_r((const char *)NULL, (struct protoent *)NULL, (char *)NULL, (int)0, (struct protoent **)NULL); - pr = getprotobynumber_r((int)0, (struct protoent *)NULL, (char *)NULL, (int)0, (struct protoent **)NULL); - - return Val_unit; -} -" - -let hostent_reentrant_code = " -#define _GNU_SOURCE -#include -#include -#include -/* Helper functions for not re-entrant functions */ -#if !defined(HAS_GETHOSTBYADDR_R) || (HAS_GETHOSTBYADDR_R != 7 && HAS_GETHOSTBYADDR_R != 8) -#define NON_R_GETHOSTBYADDR 1 -#endif - -#if !defined(HAS_GETHOSTBYNAME_R) || (HAS_GETHOSTBYNAME_R != 5 && HAS_GETHOSTBYNAME_R != 6) -#define NON_R_GETHOSTBYNAME 1 -#endif - -CAMLprim value lwt_test(value u) -{ - (void)u; -#if defined(NON_R_GETHOSTBYNAME) || defined(NON_R_GETHOSTBYNAME) -#error \"not available\" -#else - return Val_unit; -#endif -} -" - -let struct_ns_code conversion = " -#define _GNU_SOURCE -#include -#include -#include -#include - -#define NANOSEC" ^ conversion ^ " - -CAMLprim value lwt_test() { - struct stat *buf; - double a, m, c; - a = (double)NANOSEC(buf, a); - m = (double)NANOSEC(buf, m); - c = (double)NANOSEC(buf, c); - return Val_unit; -} -" - -let bsd_mincore_code = " -#include -#include -#include - -CAMLprim value lwt_test() -{ - int (*mincore_ptr)(const void*, size_t, char*) = mincore; - return Val_int(mincore_ptr == mincore_ptr); -} -" - -(* +-----------------------------------------------------------------+ - | Compilation | - +-----------------------------------------------------------------+ *) - -let ocamlc = ref "ocamlfind ocamlc" -let ext_obj = ref ".o" -let exec_name = ref "a.out" -let use_libev = ref true -let use_glib = ref false -let use_pthread = ref true -let use_unix = ref true -let os_type = ref "Unix" -let android_target = ref false -let ccomp_type = ref "cc" -let libev_default = ref true -let debug = ref (try Sys.getenv "DEBUG" = "y" with Not_found -> false) - -let dprintf fmt = - if !debug then - ( - eprintf "DBG: "; - kfprintf (fun oc -> fprintf oc "\n%!") stderr fmt - ) - else ifprintf stderr fmt - -let log_file = ref "" -let caml_file = ref "" - -(* Search for a header file in standard directories. *) -let search_header header = - let rec loop = function - | [] -> - None - | (dir_include, dir_lib) :: dirs -> - if Sys.file_exists (dir_include // header) then - Some (dir_include, dir_lib) - else - loop dirs - in - loop search_paths - -(* CFLAGS should not be passed to the linker. *) -let compile (opt, lib) stub_file = - let cmd fmt = ksprintf (fun s -> - dprintf "RUN: %s" s; - Sys.command s = 0) fmt in - let obj_file = Filename.chop_suffix stub_file ".c" ^ !ext_obj - in - (* First compile the .c file using -ocamlc and CFLAGS (opt) *) - (cmd - "%s -c %s %s -ccopt -o -ccopt %s >> %s 2>&1" - !ocamlc - (String.concat " " (List.map (fun x -> "-ccopt " ^ x) (List.map Filename.quote opt))) - (Filename.quote stub_file) - (Filename.quote obj_file) - (Filename.quote !log_file)) - && - (* Now link the resulting .o with the LDFLAGS (lib) *) - (cmd - "%s -custom %s %s %s >> %s 2>&1" - !ocamlc - (Filename.quote obj_file) - (Filename.quote !caml_file) - (String.concat " " (List.map (sprintf "-cclib %s") lib)) - (Filename.quote !log_file)) - -let safe_remove file_name = - if !debug then - dprintf "DEBUG: Not removing %s\n" file_name - else - try - Sys.remove file_name - with exn -> - () - -let test_code args stub_code = - let stub_file, oc = Filename.open_temp_file "lwt_stub" ".c" in - let cleanup () = - safe_remove stub_file; - safe_remove (Filename.chop_extension stub_file ^ !ext_obj) - in - try - output_string oc stub_code; - flush oc; - close_out oc; - let result = compile args stub_file in - cleanup (); - result - with exn -> - (try close_out oc with _ -> ()); - cleanup (); - raise exn - -let config = open_out "src/unix/lwt_config.h" -let config_ml = open_out "src/unix/lwt_config.ml" - -let () = - fprintf config "\ -#ifndef __LWT_CONFIG_H -#define __LWT_CONFIG_H -" - -let not_available = ref [] - -let test_feature ?(do_check = true) name macro test = - if do_check then begin - printf "testing for %s:%!" name; - if test () then begin - if macro <> "" then begin - fprintf config "#define %s\n" macro; - fprintf config_ml "let _%s = true\n" macro - end; - printf " %s available\n%!" (String.make (34 - String.length name) '.') - end else begin - if macro <> "" then begin - fprintf config "//#define %s\n" macro; - fprintf config_ml "let _%s = false\n" macro - end; - printf " %s unavailable\n%!" (String.make (34 - String.length name) '.'); - not_available := name :: !not_available - end - end else begin - printf "not checking for %s\n%!" name; - if macro <> "" then begin - fprintf config "//#define %s\n" macro; - fprintf config_ml "let _%s = false\n" macro - end - end - -(* +-----------------------------------------------------------------+ - | pkg-config | - +-----------------------------------------------------------------+ *) - -let split str = - let rec skip_spaces i = - if i = String.length str then - [] - else - if str.[i] = ' ' then - skip_spaces (i + 1) - else - extract i (i + 1) - and extract i j = - if j = String.length str then - [String.sub str i (j - i)] - else - if str.[j] = ' ' then - String.sub str i (j - i) :: skip_spaces (j + 1) - else - extract i (j + 1) - in - skip_spaces 0 - -let pkg_config flags = - if ksprintf Sys.command "pkg-config %s > %s 2>&1" flags !log_file = 0 then begin - let ic = open_in !log_file in - let line = input_line ic in - close_in ic; - split line - end else - raise Exit - -let pkg_config_flags name = - try - (* Get compile flags. *) - let opt = ksprintf pkg_config "--cflags %s" name in - (* Get linking flags. *) - let lib = - if !ccomp_type = "msvc" then - (* With msvc we need to pass "glib-2.0.lib" instead of - "-lglib-2.0" otherwise executables will fail. *) - ksprintf pkg_config "--libs-only-L %s" name @ ksprintf pkg_config "--libs-only-l --msvc-syntax %s" name - else - ksprintf pkg_config "--libs %s" name - in - Some (opt, lib) - with Exit -> - None - -let lib_flags env_var_prefix fallback = - let get var = try Some (split (Sys.getenv var)) with Not_found -> None in - match get (env_var_prefix ^ "_CFLAGS"), get (env_var_prefix ^ "_LIBS") with - | Some opt, Some lib -> - (opt, lib) - | x -> - let opt, lib = fallback () in - match x with - | Some opt, Some lib -> - assert false - | Some opt, None -> - (opt, lib) - | None, Some lib -> - (opt, lib) - | None, None -> - (opt, lib) - -(* +-----------------------------------------------------------------+ - | Entry point | - +-----------------------------------------------------------------+ *) - -let arg_bool r = - Arg.Symbol (["true"; "false"], - function - | "true" -> r := true - | "false" -> r := false - | _ -> assert false) -let () = - let args = [ - "-ocamlc", Arg.Set_string ocamlc, " ocamlc"; - "-ext-obj", Arg.Set_string ext_obj, " C object files extension"; - "-exec-name", Arg.Set_string exec_name, " name of the executable produced by ocamlc"; - "-use-libev", arg_bool use_libev, " whether to check for libev"; - "-use-glib", arg_bool use_glib, " whether to check for glib"; - "-use-pthread", arg_bool use_pthread, " whether to use pthread"; - "-use-unix", arg_bool use_unix, " whether to build lwt.unix"; - "-os-type", Arg.Set_string os_type, " type of the target os"; - "-android-target", arg_bool android_target, " compiles for Android"; - "-ccomp-type", Arg.Set_string ccomp_type, " C compiler type"; - "-libev_default", arg_bool libev_default, " whether to use the libev backend by default"; - ] in - Arg.parse args ignore "check for external C libraries and available features\noptions are:"; - - (* Check nothing if we do not build lwt.unix. *) - if not !use_unix then exit 0; - - (* Put the caml code into a temporary file. *) - let file, oc = Filename.open_temp_file "lwt_caml" ".ml" in - caml_file := file; - output_string oc caml_code; - close_out oc; - - log_file := Filename.temp_file "lwt_output" ".log"; - - (* Cleanup things on exit. *) - at_exit (fun () -> - (try close_out config with _ -> ()); - (try close_out config_ml with _ -> ()); - safe_remove !log_file; - safe_remove !exec_name; - safe_remove !caml_file; - safe_remove (Filename.chop_extension !caml_file ^ ".cmi"); - safe_remove (Filename.chop_extension !caml_file ^ ".cmo")); - - let exit status = - if status <> 0 then begin - if !debug then printf " -See %s for more details. - " !log_file - else printf " -Run with DEBUG=y for more details. - "; - end; - exit status - in - - let setup_data = ref [] in - - (* Test for pkg-config. *) - test_feature ~do_check:(!use_libev || !use_glib) "pkg-config" "" - (fun () -> - ksprintf Sys.command "pkg-config --version > %s 2>&1" !log_file = 0); - - (* Not having pkg-config is not fatal. *) - let have_pkg_config = !not_available = [] in - not_available := []; - - let test_basic_compilation () = - test_code ([], []) trivial_code - in - - let test_libev () = - let opt, lib = - lib_flags "LIBEV" - (fun () -> - match if have_pkg_config then pkg_config_flags "libev" else None with - | Some (opt, lib) -> - (opt, lib) - | None -> - match search_header "ev.h" with - | Some (dir_i, dir_l) -> - (["-I" ^ dir_i], ["-L" ^ dir_l; "-lev"]) - | None -> - ([], ["-lev"])) - in - setup_data := ("libev_opt", opt) :: ("libev_lib", lib) :: !setup_data; - test_code (opt, lib) libev_code - in - - let test_pthread () = - let opt, lib = - if !android_target then ([], []) else - lib_flags "PTHREAD" (fun () -> ([], ["-lpthread"])) - in - setup_data := ("pthread_opt", opt) :: ("pthread_lib", lib) :: !setup_data; - test_code (opt, lib) pthread_code - in - - let test_glib () = - let opt, lib = - lib_flags "GLIB" - (fun () -> - match if have_pkg_config then pkg_config_flags "glib-2.0" else None with - | Some (opt, lib) -> - (opt, lib) - | None -> - ([], ["-lglib-2.0"])) - in - setup_data := ("glib_opt", opt) :: ("glib_lib", lib) :: !setup_data; - test_code (opt, lib) glib_code - in - - let test_nanosecond_stat () = - printf "testing for nanosecond stat support:%!"; - let conversions = [ - ("(buf, field) buf->st_##field##tim.tv_nsec", "*tim.tv_nsec"); - ("(buf, field) buf->st_##field##timespec.tv_nsec", "*timespec.tv_nsec"); - ("(buf, field) buf->st_##field##timensec", "*timensec"); - ] in - let fallback = "(buf, field) 0.0" in - let conversion = try - let (conversion, desc) = List.find (fun (conversion, _desc) -> - test_code ([], []) (struct_ns_code conversion) - ) conversions in - printf " %s %s\n%!" (String.make 11 '.') desc; - conversion - with Not_found -> begin - printf " %s unavailable\n%!" (String.make 11 '.'); - fprintf config "#define NANOSEC%s\n" fallback; - fallback - end in - fprintf config "#define NANOSEC%s\n" conversion - in - - if not (test_basic_compilation ()) then begin - printf " -Error: failed to compile a trivial ocaml toplevel. -You may be missing core components (compiler, ncurses, etc) -"; - exit 1 - end; - - test_feature ~do_check:!use_libev "libev" "HAVE_LIBEV" test_libev; - test_feature ~do_check:!use_pthread "pthread" "HAVE_PTHREAD" test_pthread; - test_feature ~do_check:!use_glib "glib" "" test_glib; - - if !not_available <> [] then begin - if not have_pkg_config then - printf "Warning: the 'pkg-config' command is not available."; - (* The missing library list should be printed on the last line, to avoid - being trimmed by OPAM. The whole message should be kept to 10 lines. See - https://github.com/ocsigen/lwt/issues/271. *) - printf " -Some required C libraries were not found. If a C library is installed in a -non-standard location, set _CFLAGS and _LIBS accordingly. You may also -try 'ocaml setup.ml -configure --disable-' to avoid compiling support for -it. For example, in the case of libev missing: - export LIBEV_CFLAGS=-I/opt/local/include - export LIBEV_LIBS='-L/opt/local/lib -lev' - (* or: *) ocaml setup.ml -configure --disable-libev - -Missing C libraries: %s -" (String.concat ", " !not_available); - exit 1 - end; - - if !os_type <> "Win32" && not !use_pthread then begin - printf " -No threading library available! - -One is needed if you want to build lwt.unix. - -Lwt can use pthread or the win32 API. -"; - exit 1 - end; - - let do_check = !os_type <> "Win32" in - test_feature ~do_check "eventfd" "HAVE_EVENTFD" (fun () -> test_code ([], []) eventfd_code); - test_feature ~do_check "fd passing" "HAVE_FD_PASSING" (fun () -> test_code ([], []) fd_passing_code); - test_feature ~do_check:(do_check && not !android_target) - "sched_getcpu" "HAVE_GETCPU" (fun () -> test_code ([], []) getcpu_code); - test_feature ~do_check:(do_check && not !android_target) - "affinity getting/setting" "HAVE_AFFINITY" (fun () -> test_code ([], []) affinity_code); - test_feature ~do_check "credentials getting (Linux)" "HAVE_GET_CREDENTIALS_LINUX" (fun () -> test_code ([], []) (get_credentials_code "ucred")); - test_feature ~do_check "credentials getting (NetBSD)" "HAVE_GET_CREDENTIALS_NETBSD" (fun () -> test_code ([], []) (get_credentials_code "sockcred")); - test_feature ~do_check "credentials getting (OpenBSD)" "HAVE_GET_CREDENTIALS_OPENBSD" (fun () -> test_code ([], []) (get_credentials_code "sockpeercred")); - test_feature ~do_check "credentials getting (FreeBSD)" "HAVE_GET_CREDENTIALS_FREEBSD" (fun () -> test_code ([], []) (get_credentials_code "cmsgcred")); - test_feature ~do_check "credentials getting (getpeereid)" "HAVE_GETPEEREID" (fun () -> test_code ([], []) get_peereid_code); - test_feature ~do_check "fdatasync" "HAVE_FDATASYNC" (fun () -> test_code ([], []) fdatasync_code); - test_feature ~do_check:(do_check && not !android_target) - "netdb_reentrant" "HAVE_NETDB_REENTRANT" (fun () -> test_code ([], []) netdb_reentrant_code); - test_feature ~do_check "reentrant gethost*" "HAVE_REENTRANT_HOSTENT" (fun () -> test_code ([], []) hostent_reentrant_code); - test_nanosecond_stat (); - test_feature ~do_check "BSD mincore" "HAVE_BSD_MINCORE" (fun () -> - test_code (["-Werror"], []) bsd_mincore_code); - - let get_cred_vars = [ - "HAVE_GET_CREDENTIALS_LINUX"; - "HAVE_GET_CREDENTIALS_NETBSD"; - "HAVE_GET_CREDENTIALS_OPENBSD"; - "HAVE_GET_CREDENTIALS_FREEBSD"; - "HAVE_GETPEEREID"; - ] in - - Printf.fprintf config "\ -#if %s -# define HAVE_GET_CREDENTIALS -#endif -" - (String.concat " || " (List.map (Printf.sprintf "defined(%s)") get_cred_vars)); - - Printf.fprintf config_ml - "let _HAVE_GET_CREDENTIALS = %s\n" - (String.concat " || " (List.map (fun s -> "_" ^ s) get_cred_vars)); - - if !os_type = "Win32" then begin - output_string config "#define LWT_ON_WINDOWS\n"; - end else begin - output_string config "//#define LWT_ON_WINDOWS\n"; - end; - if !android_target then begin - output_string config_ml "let android = true\n" - end else begin - output_string config_ml "let android = false\n" - end; - - let () = - let force_libev_default = - try Sys.getenv "LWT_FORCE_LIBEV_BY_DEFAULT" = "yes" - with Not_found -> false - in - let libev_default = !libev_default || force_libev_default in - Printf.fprintf config_ml "let libev_default = %b\n" libev_default - in - - fprintf config "#endif\n"; - - (* Our setup.data keys. *) - let setup_data_keys = [ - "libev_opt"; - "libev_lib"; - "pthread_lib"; - "pthread_opt"; - "glib_opt"; - "glib_lib"; - ] in - - (* Load setup.data *) - let setup_data_lines = - match try Some (open_in "setup.data") with Sys_error _ -> None with - | Some ic -> - let rec aux acc = - match try Some (input_line ic) with End_of_file -> None with - | None -> - close_in ic; - acc - | Some line -> - match try Some(String.index line '=') with Not_found -> None with - | Some idx -> - let key = String.sub line 0 idx in - if List.mem key setup_data_keys then - aux acc - else - aux (line :: acc) - | None -> - aux (line :: acc) - in - aux [] - | None -> - [] - in - - (* Add flags to setup.data *) - let setup_data_lines = - List.fold_left - (fun lines (name, args) -> - sprintf "%s=%S" name (String.concat " " args) :: lines) - setup_data_lines !setup_data - in - let oc = open_out "setup.data" in - List.iter - (fun str -> output_string oc str; output_char oc '\n') - (List.rev setup_data_lines); - close_out oc; - - close_out config; - close_out config_ml; - - (* Generate stubs. *) - print_endline "Generating C stubs..."; - exit (Sys.command "ocaml src/unix/gen_stubs.ml") From ef6021c99f4013a7d9fa8625d8c7a14835b07d7b Mon Sep 17 00:00:00 2001 From: andrewray Date: Sun, 28 May 2017 22:22:56 +0100 Subject: [PATCH 35/46] jenkins documentation build --- .jenkins.sh | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.jenkins.sh b/.jenkins.sh index 0e96b3f2de..ca6ed0e758 100644 --- a/.jenkins.sh +++ b/.jenkins.sh @@ -5,10 +5,12 @@ opam install --deps-only lwt opam install --verbose lwt do_build_doc () { - rm -rf _build/lwt-api.wikidocdir - ./setup-dev.exe -build lwt-api.wikidocdir/index.wiki + rm -rf doc/api + # generate wikidoc documentation + make doc-api-wiki + # copy manual pages and api documentation cp -Rf doc/*.wiki ${MANUAL_SRC_DIR} - cp -Rf _build/lwt-api.wikidocdir/*.wiki ${API_DIR} + cp -Rf doc/api/wiki/*.wiki ${API_DIR} } do_remove () { From b1201970ac31d4248d9dee148bc82d684d7c5a02 Mon Sep 17 00:00:00 2001 From: andrewray Date: Sun, 28 May 2017 22:31:26 +0100 Subject: [PATCH 36/46] install uchar and ocamlbuild deps for jenkins --- .jenkins.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/.jenkins.sh b/.jenkins.sh index ca6ed0e758..ffa8fce56e 100644 --- a/.jenkins.sh +++ b/.jenkins.sh @@ -1,6 +1,7 @@ opam pin add --no-action lwt . opam install camlp4 opam install ssl lablgtk react conf-libev +opam install ocamlbuild uchar opam install --deps-only lwt opam install --verbose lwt From ddc6330f1403fdbaf7b0d3e9d6229b570b4141d3 Mon Sep 17 00:00:00 2001 From: andrewray Date: Wed, 7 Jun 2017 09:09:37 +0100 Subject: [PATCH 37/46] address jbuilder code review issues 1. remove unused files; TODO, _opam, bad_packages 2. fix library description (thread->promise) in discover.ml 3. update .gitignore 4. remove jbuilder line in readme 5. update opam file post install message and remove ocaml-migrate-parsetree dep, revert post install message 6. get build to work without presence of camlp4 according to janestreet/jbuilder#51 we need to move the 3 camlp4 packages into seperate directories. I note a general opam packing issue where if a system installed camlp4 is in the PATH when ocamlfind is installed, it adds a META file which pretends those packages are available and compatible with any current OPAM switch, which it is not! I think this is an upstream camlp4 packaging issue 7. Add a custom META file This is only to support the correct syntax predicates for camlp4 and ocamlfind. Also requires various exists_if clauses --- .gitignore | 7 +- .merlin | 9 -- META.lwt.template | 135 +++++++++++++++++++++ README.md | 2 - TODO.jbuild | 10 -- _opam-files/META.lwt.template | 69 ----------- _opam-files/lwt-camlp4.opam | 26 ---- _opam-files/lwt-core.opam | 24 ---- _opam-files/lwt-log.opam | 24 ---- _opam-files/lwt-ppx.opam | 28 ----- _opam-files/lwt-preemptive.opam | 26 ---- _opam-files/lwt-simple-top.opam | 26 ---- _opam-files/lwt-unix.opam | 31 ----- _opam-files/lwt.opam | 30 ----- bad_packages.md | 43 ------- lwt.opam | 4 +- src/camlp4/jbuild | 20 --- src/camlp4/log/jbuild | 10 ++ src/camlp4/{ => log}/pa_lwt_log.ml | 0 src/camlp4/{ => log}/pa_lwt_log.mli | 0 src/camlp4/options/jbuild | 8 ++ src/camlp4/{ => options}/pa_lwt_options.ml | 0 src/unix/config/discover.ml | 3 +- 23 files changed, 158 insertions(+), 377 deletions(-) delete mode 100644 .merlin create mode 100644 META.lwt.template delete mode 100644 TODO.jbuild delete mode 100644 _opam-files/META.lwt.template delete mode 100644 _opam-files/lwt-camlp4.opam delete mode 100644 _opam-files/lwt-core.opam delete mode 100644 _opam-files/lwt-log.opam delete mode 100644 _opam-files/lwt-ppx.opam delete mode 100644 _opam-files/lwt-preemptive.opam delete mode 100644 _opam-files/lwt-simple-top.opam delete mode 100644 _opam-files/lwt-unix.opam delete mode 100644 _opam-files/lwt.opam delete mode 100644 bad_packages.md create mode 100644 src/camlp4/log/jbuild rename src/camlp4/{ => log}/pa_lwt_log.ml (100%) rename src/camlp4/{ => log}/pa_lwt_log.mli (100%) create mode 100644 src/camlp4/options/jbuild rename src/camlp4/{ => options}/pa_lwt_options.ml (100%) diff --git a/.gitignore b/.gitignore index 6413f53e41..c7a96983b2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,5 @@ _build -setup.data -setup.log -setup.exe -setup-dev.exe -_opam +src/unix/lwt_config # Coverage analysis. bisect*.out @@ -12,6 +8,7 @@ _coverage/ # For local work, tests, etc. scratch/ +# Autogenerated by jbuider .merlin *.install diff --git a/.merlin b/.merlin deleted file mode 100644 index eea11d3a18..0000000000 --- a/.merlin +++ /dev/null @@ -1,9 +0,0 @@ -S src/** - -B _build/** - -S tests/ -S doc/examples/ - -PKG result -PKG bytes diff --git a/META.lwt.template b/META.lwt.template new file mode 100644 index 0000000000..9769199b7d --- /dev/null +++ b/META.lwt.template @@ -0,0 +1,135 @@ +# +# This file has been copied from _build/default/META.lwt then +# modified to add exists_if clauses to support optional +# compilation and the camlp4 syntax extension packages have +# been given appropriate predicates. +# + +version = "dev" +description = "Monadic promises and concurrent I/O" +requires = "bytes result" +archive(byte) = "lwt.cma" +archive(native) = "lwt.cmxa" +plugin(byte) = "lwt.cma" +plugin(native) = "lwt.cmxs" +package "log" ( + directory = "log" + version = "dev" + description = "Logger for Lwt" + requires = "bytes lwt result" + archive(byte) = "lwt_log.cma" + archive(native) = "lwt_log.cmxa" + plugin(byte) = "lwt_log.cma" + plugin(native) = "lwt_log.cmxs" + exists_if = "lwt_log.cma" +) +package "ppx" ( + directory = "ppx" + version = "dev" + description = "Lwt PPX syntax extension" + requires(ppx_driver) = "compiler-libs + compiler-libs.common + ocaml-migrate-parsetree + ppx_tools_versioned" + archive(ppx_driver,byte) = "ppx_lwt.cma" + archive(ppx_driver,native) = "ppx_lwt.cmxa" + plugin(ppx_driver,byte) = "ppx_lwt.cma" + plugin(ppx_driver,native) = "ppx_lwt.cmxs" + exists_if = "ppx_lwt.cma" + # This is what jbuilder uses to find out the runtime dependencies of + # a preprocessor + ppx_runtime_deps = "bytes lwt result" + # This line makes things transparent for people mixing preprocessors + # and normal dependencies + requires(-ppx_driver) = "lwt.ppx.deprecated-ppx-method" + package "deprecated-ppx-method" ( + version = "dev" + description = "glue package for the deprecated method of using ppx" + requires = "bytes lwt result" + ppx(-ppx_driver,-custom_ppx) = "./ppx.exe --as-ppx" + exists_if = "ppx_lwt.cma" + ) +) +package "preemptive" ( + directory = "preemptive" + version = "dev" + description = "Preemptive thread support for Lwt" + requires = "bigarray + bytes + lwt + lwt.log + lwt.unix + result + threads + threads.posix + unix" + archive(byte) = "lwt_preemptive.cma" + archive(native) = "lwt_preemptive.cmxa" + plugin(byte) = "lwt_preemptive.cma" + plugin(native) = "lwt_preemptive.cmxs" + exists_if = "lwt_preemptive.cma" +) +package "simple-top" ( + directory = "simple-top" + version = "dev" + description = "Lwt-OCaml top level integration (deprecated; use utop)" + requires = "bigarray + bytes + compiler-libs + compiler-libs.common + lwt + lwt.log + lwt.unix + result + unix" + archive(byte) = "lwt_simple_top.cma" + archive(native) = "lwt_simple_top.cmxa" + plugin(byte) = "lwt_simple_top.cma" + plugin(native) = "lwt_simple_top.cmxs" + exists_if = "lwt_simple_top.cma" +) +package "syntax" ( + directory = "syntax" + version = "dev" + description = "Camlp4 syntax for Lwt (deprecated; use lwt.ppx)" + requires = "camlp4 lwt.syntax.options" + archive(syntax, preprocessor) = "lwt_syntax.cma" + archive(syntax, toploop) = "lwt_syntax.cma" + archive(syntax, preprocessor, native) = "lwt_syntax.cmxa" + archive(syntax, preprocessor, native, plugin) = "lwt_syntax.cmxs" + exists_if = "lwt_syntax.cma" + package "log" ( + directory = "log" + version = "dev" + description = "Camlp4 syntax for Lwt logging (deprecated; use lwt.ppx)" + requires = "camlp4 lwt.syntax.options" + archive(syntax, preprocessor) = "lwt_syntax_log.cma" + archive(syntax, toploop) = "lwt_syntax_log.cma" + archive(syntax, preprocessor, native) = "lwt_syntax_log.cmxa" + archive(syntax, preprocessor, native, plugin) = "lwt_syntax_log.cmxs" + exists_if = "lwt_syntax_log.cma" + ) + package "options" ( + directory = "options" + version = "dev" + description = "Options for Lwt Camlp4 syntax extension (deprecated; use lwt.ppx)" + requires = "camlp4" + archive(syntax, preprocessor) = "lwt_syntax_options.cma" + archive(syntax, toploop) = "lwt_syntax_options.cma" + archive(syntax, preprocessor, native) = "lwt_syntax_options.cmxa" + archive(syntax, preprocessor, native, plugin) = "lwt_syntax_options.cmxs" + exists_if = "lwt_syntax_options.cma" + ) +) +package "unix" ( + directory = "unix" + version = "dev" + description = "Unix support for Lwt" + requires = "bigarray bytes lwt lwt.log result unix" + archive(byte) = "lwt_unix.cma" + archive(native) = "lwt_unix.cmxa" + plugin(byte) = "lwt_unix.cma" + plugin(native) = "lwt_unix.cmxs" + exists_if = "lwt_unix.cma" +) + diff --git a/README.md b/README.md index b89a10a866..680833010f 100644 --- a/README.md +++ b/README.md @@ -119,8 +119,6 @@ version, opam source --dev-repo --pin lwt ``` -This will also install the development dependency jbuilder. - A list of [project suggestions][projects] and a [roadmap][roadmap] can be found on the wiki. diff --git a/TODO.jbuild b/TODO.jbuild deleted file mode 100644 index 50a04bd380..0000000000 --- a/TODO.jbuild +++ /dev/null @@ -1,10 +0,0 @@ -- Internal modules exposed in lwt-unit - -- lwt-unix configuration params passed to discover.exe; - - use_libev (currently forced to true) - - how do we depend on an external opam package with no findlib library? - - android-target? - -- multi-workspace builds dont work - - jbuilder build --workspace jbuild-workspace.dev @install @runtest --only-packages lwt - - problem with ppx diff --git a/_opam-files/META.lwt.template b/_opam-files/META.lwt.template deleted file mode 100644 index 1f73fa3354..0000000000 --- a/_opam-files/META.lwt.template +++ /dev/null @@ -1,69 +0,0 @@ -# JBUILDER_GEN - -version = "dev" -description = "[compatibility] maps to lwt-core" -requires = "lwt-core" - -package "unix" ( - requires = "lwt-unix" - description = "[compatibility] maps to lwt-unix" - exists_if = "../lwt-unix/lwt_unix.cma" -) - -package "log" ( - requires = "lwt-log" - description = "[compatibility] maps to lwt-log" - exists_if = "../lwt-log/lwt_log.cma" -) - -package "ppx" ( - requires = "lwt-ppx" - description = "[compatibility] maps to lwt-ppx" - exists_if = "../lwt-ppx/ppx_lwt.cma" -) - -package "preemptive" ( - requires = "lwt-preemptive" - description = "[compatibility] maps to lwt-preemptive" - exists_if = "../lwt-preemptive/lwt_preemptive.cma" -) - -package "simple-top" ( - requires = "lwt-simple-top" - description = "[compatibility] maps to lwt-simple-top" - exists_if = "../lwt-simple-top/lwt_simple_top.cma" -) - -package "glib" ( - requires = "lwt-glib" - description = "[compatibility] maps to lwt-glib" - exists_if = "../lwt-glib/lwt_glib.cma" -) - -package "ssl" ( - requires = "lwt-ssl" - description = "[compatibility] maps to lwt-ssl" - exists_if = "../lwt-ssl/lwt_ssl.cma" -) - -package "react" ( - requires = "lwt-react" - description = "[compatibility] maps to lwt-react" - exists_if = "../lwt-react/lwt_react.cma" -) - -package "syntax" ( - requires = "camlp4 lwt-camlp4 lwt.camlp4.options" - exists_if = "../lwt-camlp4/lwt_camlp4.cma" - - package "options" ( - requires = "lwt-camlp4.options" - exists_if = "../lwt-camlp4/lwt_camlp4.cma" - ) - - package "log" ( - requires = "lwt-camlp4.log" - exists_if = "../lwt-camlp4/lwt_camlp4.cma" - ) -) - diff --git a/_opam-files/lwt-camlp4.opam b/_opam-files/lwt-camlp4.opam deleted file mode 100644 index e092308cc0..0000000000 --- a/_opam-files/lwt-camlp4.opam +++ /dev/null @@ -1,26 +0,0 @@ -opam-version: "1.2" -name: "lwt" -version: "dev" -maintainer: [ - "Anton Bachin " - "Mauricio Fernandez " - "Simon Cruanes " -] -authors: [ - "Jérôme Vouillon" - "Jérémie Dimino" -] -homepage: "https://github.com/ocsigen/lwt" -doc: "https://ocsigen.org/lwt/manual/" -bug-reports: "https://github.com/ocsigen/lwt/issues" -license: "LGPL with OpenSSL linking exception" -dev-repo: "https://github.com/ocsigen/lwt.git" -build: [ [ "jbuilder" "build" "-p" name "-j" jobs ] ] -build-test: [ [ "jbuilder" "runtest" "-p" name ] ] -depends: [ - "jbuilder" { build & >= "1.0+beta9" } - "lwt-core" - "camlp4" -] - - diff --git a/_opam-files/lwt-core.opam b/_opam-files/lwt-core.opam deleted file mode 100644 index 3bb8ca7f5a..0000000000 --- a/_opam-files/lwt-core.opam +++ /dev/null @@ -1,24 +0,0 @@ -opam-version: "1.2" -name: "lwt" -version: "dev" -maintainer: [ - "Anton Bachin " - "Mauricio Fernandez " - "Simon Cruanes " -] -authors: [ - "Jérôme Vouillon" - "Jérémie Dimino" -] -homepage: "https://github.com/ocsigen/lwt" -doc: "https://ocsigen.org/lwt/manual/" -bug-reports: "https://github.com/ocsigen/lwt/issues" -license: "LGPL with OpenSSL linking exception" -dev-repo: "https://github.com/ocsigen/lwt.git" -build: [ [ "jbuilder" "build" "-p" name "-j" jobs ] ] -build-test: [ [ "jbuilder" "runtest" "-p" name ] ] -depends: [ - "jbuilder" { build & >= "1.0+beta9" } - "result" -] - diff --git a/_opam-files/lwt-log.opam b/_opam-files/lwt-log.opam deleted file mode 100644 index a88cb97267..0000000000 --- a/_opam-files/lwt-log.opam +++ /dev/null @@ -1,24 +0,0 @@ -opam-version: "1.2" -name: "lwt" -version: "dev" -maintainer: [ - "Anton Bachin " - "Mauricio Fernandez " - "Simon Cruanes " -] -authors: [ - "Jérôme Vouillon" - "Jérémie Dimino" -] -homepage: "https://github.com/ocsigen/lwt" -doc: "https://ocsigen.org/lwt/manual/" -bug-reports: "https://github.com/ocsigen/lwt/issues" -license: "LGPL with OpenSSL linking exception" -dev-repo: "https://github.com/ocsigen/lwt.git" -build: [ [ "jbuilder" "build" "-p" name "-j" jobs ] ] -build-test: [ [ "jbuilder" "runtest" "-p" name ] ] -depends: [ - "jbuilder" { build & >= "1.0+beta9" } - "lwt-core" -] - diff --git a/_opam-files/lwt-ppx.opam b/_opam-files/lwt-ppx.opam deleted file mode 100644 index 8ecb89fbe8..0000000000 --- a/_opam-files/lwt-ppx.opam +++ /dev/null @@ -1,28 +0,0 @@ -opam-version: "1.2" -name: "lwt" -version: "dev" -maintainer: [ - "Anton Bachin " - "Mauricio Fernandez " - "Simon Cruanes " -] -authors: [ - "Jérôme Vouillon" - "Jérémie Dimino" -] -homepage: "https://github.com/ocsigen/lwt" -doc: "https://ocsigen.org/lwt/manual/" -bug-reports: "https://github.com/ocsigen/lwt/issues" -license: "LGPL with OpenSSL linking exception" -dev-repo: "https://github.com/ocsigen/lwt.git" -build: [ [ "jbuilder" "build" "-p" name "-j" jobs ] ] -build-test: [ [ "jbuilder" "runtest" "-p" name ] ] -depends: [ - "jbuilder" { build & >= "1.0+beta9" } - "lwt-core" # not needed to build, but is required at runtime - "ppx_tools_versioned" - "ocaml-migrate-parsetree" -] - - - diff --git a/_opam-files/lwt-preemptive.opam b/_opam-files/lwt-preemptive.opam deleted file mode 100644 index 81f9860a83..0000000000 --- a/_opam-files/lwt-preemptive.opam +++ /dev/null @@ -1,26 +0,0 @@ -opam-version: "1.2" -name: "lwt" -version: "dev" -maintainer: [ - "Anton Bachin " - "Mauricio Fernandez " - "Simon Cruanes " -] -authors: [ - "Jérôme Vouillon" - "Jérémie Dimino" -] -homepage: "https://github.com/ocsigen/lwt" -doc: "https://ocsigen.org/lwt/manual/" -bug-reports: "https://github.com/ocsigen/lwt/issues" -license: "LGPL with OpenSSL linking exception" -dev-repo: "https://github.com/ocsigen/lwt.git" -build: [ [ "jbuilder" "build" "-p" name "-j" jobs ] ] -build-test: [ [ "jbuilder" "runtest" "-p" name ] ] -depends: [ - "jbuilder" { build & >= "1.0+beta9" } - "lwt-unix" - "base-threads" -] - - diff --git a/_opam-files/lwt-simple-top.opam b/_opam-files/lwt-simple-top.opam deleted file mode 100644 index 920be447d4..0000000000 --- a/_opam-files/lwt-simple-top.opam +++ /dev/null @@ -1,26 +0,0 @@ -opam-version: "1.2" -name: "lwt" -version: "dev" -maintainer: [ - "Anton Bachin " - "Mauricio Fernandez " - "Simon Cruanes " -] -authors: [ - "Jérôme Vouillon" - "Jérémie Dimino" -] -homepage: "https://github.com/ocsigen/lwt" -doc: "https://ocsigen.org/lwt/manual/" -bug-reports: "https://github.com/ocsigen/lwt/issues" -license: "LGPL with OpenSSL linking exception" -dev-repo: "https://github.com/ocsigen/lwt.git" -build: [ [ "jbuilder" "build" "-p" name "-j" jobs ] ] -build-test: [ [ "jbuilder" "runtest" "-p" name ] ] -depends: [ - "jbuilder" { build & >= "1.0+beta9" } - "lwt-core" - "lwt-unix" -] - - diff --git a/_opam-files/lwt-unix.opam b/_opam-files/lwt-unix.opam deleted file mode 100644 index 5dff4ab22c..0000000000 --- a/_opam-files/lwt-unix.opam +++ /dev/null @@ -1,31 +0,0 @@ -opam-version: "1.2" -name: "lwt" -version: "dev" -maintainer: [ - "Anton Bachin " - "Mauricio Fernandez " - "Simon Cruanes " -] -authors: [ - "Jérôme Vouillon" - "Jérémie Dimino" -] -homepage: "https://github.com/ocsigen/lwt" -doc: "https://ocsigen.org/lwt/manual/" -bug-reports: "https://github.com/ocsigen/lwt/issues" -license: "LGPL with OpenSSL linking exception" -dev-repo: "https://github.com/ocsigen/lwt.git" -build: [ [ "jbuilder" "build" "-p" name "-j" jobs ] ] -build-test: [ [ "jbuilder" "runtest" "-p" name ] ] -depends: [ - "jbuilder" { build & >= "1.0+beta9" } - "cppo" { build } - "base" { build } # needed for discover.ml - "stdio" { build } # ...but only to write the sexps - "base-unix" - "lwt-core" - "lwt-log" -] -depopts: [ - "conf-libev" -] diff --git a/_opam-files/lwt.opam b/_opam-files/lwt.opam deleted file mode 100644 index 6cd2681fda..0000000000 --- a/_opam-files/lwt.opam +++ /dev/null @@ -1,30 +0,0 @@ -opam-version: "1.2" -name: "lwt" -version: "dev" -maintainer: [ - "Anton Bachin " - "Mauricio Fernandez " - "Simon Cruanes " -] -authors: [ - "Jérôme Vouillon" - "Jérémie Dimino" -] -homepage: "https://github.com/ocsigen/lwt" -doc: "https://ocsigen.org/lwt/manual/" -bug-reports: "https://github.com/ocsigen/lwt/issues" -license: "LGPL with OpenSSL linking exception" -dev-repo: "https://github.com/ocsigen/lwt.git" -build: [ [ "jbuilder" "build" "-p" name "-j" jobs ] ] -depends: [ - "jbuilder" { build & >= "1.0+beta9" } - "lwt-core" - "lwt-log" - "lwt-unix" - "lwt-preemptive" - "lwt-simple-top" - "lwt-ppx" -] -post-messages: [ - "Lwt+jbuilder has some major breaking changes!!!" -] diff --git a/bad_packages.md b/bad_packages.md deleted file mode 100644 index 76b3c874ea..0000000000 --- a/bad_packages.md +++ /dev/null @@ -1,43 +0,0 @@ -A few errors found by randomly installing some lwt packages. - -All seem to point to libraries using lwt.unix but only linking to lwt. - -# irmin_watcher - -``` -# File "src/irmin_watcher_polling.ml", line 94, characters 28-42: -# Error: Unbound module Lwt_unix -# Command exited with code 2. -``` - -# biocaml - -``` -# + ocamlfind ocamlc -annot -bin-annot -c -g -I lib -I lib/lwt -o lib/lwt/future_lwt.cmi -short-paths -thread -w A-4-33-41-42-44-45-48 -package camlzip,cfstream,core_kernel,lwt,lwt.ppx,ppx_compare,ppx_sexp_conv,re.perl,uri,xmlm lib/lwt/future_lwt.mli -# findlib: [WARNING] Interface topdirs.cmi occurs in several directories: /home/andyman/.opam/4.04.0/lib/ocaml/compiler-libs, /home/andyman/.opam/4.04.0/lib/ocaml -# File "lib/lwt/future_lwt.mli", line 7, characters 22-42: -# Error: Unbound module Lwt_io -``` - -# mirage-profile - -``` -# File "lwt/dns_resolver_unix.ml", line 35, characters 2-10: -# Error: Unbound module Lwt_unix -# Command exited with code 2. -``` - -# dns - -``` -# File "lwt/dns_resolver_unix.ml", line 35, characters 2-10: -# Error: Unbound module Lwt_unix -``` - -# markup - -``` -# + ocamlfind ocamlc -c -g -w +A-4-9-44-45-48 -warn-error +A-3 -bin-annot -safe-string -package lwt -package uutf -I src -I doc -I test -I test/performance -I test/dependency -I test/js_of_ocaml -I test/pages -o src/markup_lwt_unix.cmi src/markup_lwt_unix.mli -# File "src/markup_lwt_unix.mli", line 20, characters 14-41: -# Error: Unbound module Lwt_io -``` diff --git a/lwt.opam b/lwt.opam index 5bd124e6e4..cbde34ef79 100644 --- a/lwt.opam +++ b/lwt.opam @@ -23,7 +23,6 @@ build-test: [ [ "jbuilder" "runtest" "-p" name ] ] depends: [ "ocamlfind" { build & >= "1.5.0" } "jbuilder" { build & >= "1.0+beta9" } - "ocaml-migrate-parsetree" "ppx_tools_versioned" "cppo" { build } "result" @@ -43,5 +42,6 @@ messages: [ {react:installed & !lwt_react:installed} ] post-messages: [ - "Lwt+jbuilder has some major breaking changes!!!" + "Lwt 3.0.0 made some minor breaking changes, announced in 2.7.0. See + https://github.com/ocsigen/lwt/issues/308" ] diff --git a/src/camlp4/jbuild b/src/camlp4/jbuild index 5c17abab76..b788341034 100644 --- a/src/camlp4/jbuild +++ b/src/camlp4/jbuild @@ -1,28 +1,8 @@ -(library - ((name lwt_syntax_options) - (public_name lwt.syntax.options) - (synopsis "Options for Lwt Camlp4 syntax extension (deprecated; use lwt.ppx)") - (optional) - (modules pa_lwt_options) - (wrapped false) - (libraries (camlp4)))) - (library ((name lwt_syntax) (public_name lwt.syntax) (synopsis "Camlp4 syntax for Lwt (deprecated; use lwt.ppx)") (optional) - (modules pa_lwt) - (wrapped false) - (libraries (camlp4 lwt.syntax.options)) - (preprocess (action (run camlp4oof ${<}))))) - -(library - ((name lwt_syntax_log) - (public_name lwt.syntax.log) - (synopsis "Camlp4 syntax for Lwt logging (deprecated; use lwt.ppx)") - (optional) - (modules pa_lwt_log) (wrapped false) (libraries (camlp4 lwt.syntax.options)) (preprocess (action (run camlp4oof ${<}))))) diff --git a/src/camlp4/log/jbuild b/src/camlp4/log/jbuild new file mode 100644 index 0000000000..778fe749c9 --- /dev/null +++ b/src/camlp4/log/jbuild @@ -0,0 +1,10 @@ +(library + ((name lwt_syntax_log) + (public_name lwt.syntax.log) + (synopsis "Camlp4 syntax for Lwt logging (deprecated; use lwt.ppx)") + (optional) + (wrapped false) + (libraries (camlp4 lwt.syntax.options)) + (preprocess (action (run camlp4oof ${<}))))) + + diff --git a/src/camlp4/pa_lwt_log.ml b/src/camlp4/log/pa_lwt_log.ml similarity index 100% rename from src/camlp4/pa_lwt_log.ml rename to src/camlp4/log/pa_lwt_log.ml diff --git a/src/camlp4/pa_lwt_log.mli b/src/camlp4/log/pa_lwt_log.mli similarity index 100% rename from src/camlp4/pa_lwt_log.mli rename to src/camlp4/log/pa_lwt_log.mli diff --git a/src/camlp4/options/jbuild b/src/camlp4/options/jbuild new file mode 100644 index 0000000000..c22926740c --- /dev/null +++ b/src/camlp4/options/jbuild @@ -0,0 +1,8 @@ +(library + ((name lwt_syntax_options) + (public_name lwt.syntax.options) + (synopsis "Options for Lwt Camlp4 syntax extension (deprecated; use lwt.ppx)") + (optional) + (wrapped false) + (libraries (camlp4)))) + diff --git a/src/camlp4/pa_lwt_options.ml b/src/camlp4/options/pa_lwt_options.ml similarity index 100% rename from src/camlp4/pa_lwt_options.ml rename to src/camlp4/options/pa_lwt_options.ml diff --git a/src/unix/config/discover.ml b/src/unix/config/discover.ml index 6b62ac8cb9..3781396d2d 100644 --- a/src/unix/config/discover.ml +++ b/src/unix/config/discover.ml @@ -1,6 +1,5 @@ -(* Lightweight thread library for OCaml +(* OCaml promise library * http://www.ocsigen.org/lwt - * Program discover * Copyright (C) 2010 Jérémie Dimino * * This program is free software; you can redistribute it and/or modify From b0551ea46df2cc27a0716a96aa08e5b26b105085 Mon Sep 17 00:00:00 2001 From: andrewray Date: Wed, 7 Jun 2017 22:26:25 +0100 Subject: [PATCH 38/46] work around for camlp4 issue. ...where it's not really installed but ocamlfind pretends it is. Add a configuration option to enable/disable lwt.syntax subpackage based on availability of the camlp4 opam package. The subpackage is disabled by writing a jbuild-ignore file listing the src/camlp4 directory thus making jbuilder ignore it. --- lwt.opam | 3 ++- src/util/configure.ml | 15 ++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/lwt.opam b/lwt.opam index cbde34ef79..6e2d1cb234 100644 --- a/lwt.opam +++ b/lwt.opam @@ -16,7 +16,8 @@ bug-reports: "https://github.com/ocsigen/lwt/issues" license: "LGPL with OpenSSL linking exception" dev-repo: "https://github.com/ocsigen/lwt.git" build: [ - [ "ocaml" "src/util/configure.ml" "-use-libev" "%{conf-libev:installed}%" ] + [ "ocaml" "src/util/configure.ml" "-use-libev" "%{conf-libev:installed}%" + "-use-camlp4" "%{camlp4:installed}%" ] [ "jbuilder" "build" "-p" name "-j" jobs ] ] build-test: [ [ "jbuilder" "runtest" "-p" name ] ] diff --git a/src/util/configure.ml b/src/util/configure.ml index 550faf882c..447b6f83df 100644 --- a/src/util/configure.ml +++ b/src/util/configure.ml @@ -4,6 +4,7 @@ let use_libev = ref None let use_pthread = ref None let android_target = ref None let libev_default = ref None +let use_camlp4 = ref None let arg_bool r = Arg.Symbol (["true"; "false"], @@ -16,10 +17,11 @@ let args = [ "-use-pthread", arg_bool use_pthread, " whether to use pthread"; "-android-target", arg_bool android_target, " compile for Android"; "-libev-default", arg_bool libev_default, " whether to use the libev backend by default"; + "-use-camlp4", arg_bool use_camlp4, " when false instruct jbuilder to ignore camlp4"; ] let main () = - Arg.parse args ignore "enable lwt unix features\noptions are:"; + Arg.parse args ignore "enable lwt.unix and camlp4 features\noptions are:"; let f = open_out "src/unix/lwt_config" in let print name var = match var with @@ -30,6 +32,17 @@ let main () = print"use_pthread" !use_pthread; print"android_target" !android_target; print"libev_default" !libev_default; + close_out f; + (* '-use-camlp4 false' will write a jbuild-ignore file directing jbuilder to ignore + * the camlp4 directory. + * '-use-camlp4 true' (or none) will write an empty file which does nothing + * except to potentially overwrite any previous version. + * + * This is a workaround required to overcome some weird camlp4 packaging behaviour + * where ocamlfind sometimes installs a dummy META file for it even though it's + * not actually installed. *) + let f = open_out "src/jbuild-ignore" in + (if !use_camlp4 = Some(false) then Printf.fprintf f "camlp4" else ()); close_out f let () = main () From 67a34aceb992462e51cace82d0cc7d6a13fcfae6 Mon Sep 17 00:00:00 2001 From: andrewray Date: Thu, 8 Jun 2017 01:12:31 +0100 Subject: [PATCH 39/46] add configuration check to makefile Compilation will proceed without configuration, but the makefile will display a message. A default-config target is also provided which should work most places. Also, ensure all jbuild files are appropriately versioned. --- .gitignore | 1 + Makefile | 17 +++++++++++------ src/camlp4/jbuild | 2 ++ src/camlp4/log/jbuild | 2 ++ src/camlp4/options/jbuild | 2 ++ src/util/config-warn | 20 ++++++++++++++++++++ src/util/configure.ml | 9 ++++----- 7 files changed, 42 insertions(+), 11 deletions(-) create mode 100644 src/util/config-warn diff --git a/.gitignore b/.gitignore index c7a96983b2..e8dab84d42 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ _build src/unix/lwt_config +src/jbuild-ignore # Coverage analysis. bisect*.out diff --git a/Makefile b/Makefile index 14ee0e4675..144beee9e9 100644 --- a/Makefile +++ b/Makefile @@ -13,19 +13,26 @@ export OCAMLFIND_IGNORE_DUPS_IN default: build # build the usual development packages -build: +build: check-config jbuilder build \ --only-packages lwt \ @install # build everything -all: +all: check-config jbuilder build @install # run all tests -test: +test: check-config jbuilder runtest +# configuration +check-config: + @[ -f src/jbuild-ignore ] && [ -f src/unix/lwt_config ] && echo "LWT configuration OK" || cat src/util/config-warn + +default-config: + ocaml src/util/configure.ml -use-libev false -use-camlp4 false + # Use jbuilder/odoc to generate static html documentation. # Currenty requires ocaml 4.03.0 to install odoc. doc: @@ -41,9 +48,6 @@ doc-api-html: all doc-api-wiki: all make -C doc api/wiki/index.wiki -install: - jbuilder install - uninstall: jbuilder uninstall @@ -55,6 +59,7 @@ clean: rm -fr _build rm -f *.install rm -fr doc/api + rm -f src/jbuild-ignore src/unix/lwt_config clean-coverage: rm -rf bisect*.out diff --git a/src/camlp4/jbuild b/src/camlp4/jbuild index b788341034..e291e2d1cd 100644 --- a/src/camlp4/jbuild +++ b/src/camlp4/jbuild @@ -1,3 +1,5 @@ +(jbuild_version 1) + (library ((name lwt_syntax) (public_name lwt.syntax) diff --git a/src/camlp4/log/jbuild b/src/camlp4/log/jbuild index 778fe749c9..1b64b40be1 100644 --- a/src/camlp4/log/jbuild +++ b/src/camlp4/log/jbuild @@ -1,3 +1,5 @@ +(jbuild_version 1) + (library ((name lwt_syntax_log) (public_name lwt.syntax.log) diff --git a/src/camlp4/options/jbuild b/src/camlp4/options/jbuild index c22926740c..f0e0dece7b 100644 --- a/src/camlp4/options/jbuild +++ b/src/camlp4/options/jbuild @@ -1,3 +1,5 @@ +(jbuild_version 1) + (library ((name lwt_syntax_options) (public_name lwt.syntax.options) diff --git a/src/util/config-warn b/src/util/config-warn new file mode 100644 index 0000000000..72fcffd028 --- /dev/null +++ b/src/util/config-warn @@ -0,0 +1,20 @@ +=========================================================== + +LWT configuration is incomplete and compilation will +proceed with default values. + +Consider running 'ocaml src/util/configure.ml' or +'make default-config' to complete configuration. + +$ ocaml src/util/configure.ml -help +enable lwt.unix and camlp4 features +options are: + -use-libev {true|false} whether to check for libev + -use-pthread {true|false} whether to use pthread + -android-target {true|false} compile for Android + -libev-default {true|false} whether to use the libev backend by default + -use-camlp4 {true|false} when true enable camlp4 syntax extension + -help Display this list of options + --help Display this list of options + +=========================================================== diff --git a/src/util/configure.ml b/src/util/configure.ml index 447b6f83df..34f1b435a0 100644 --- a/src/util/configure.ml +++ b/src/util/configure.ml @@ -17,7 +17,7 @@ let args = [ "-use-pthread", arg_bool use_pthread, " whether to use pthread"; "-android-target", arg_bool android_target, " compile for Android"; "-libev-default", arg_bool libev_default, " whether to use the libev backend by default"; - "-use-camlp4", arg_bool use_camlp4, " when false instruct jbuilder to ignore camlp4"; + "-use-camlp4", arg_bool use_camlp4, " when true enable camlp4 syntax extension"; ] let main () = @@ -33,16 +33,15 @@ let main () = print"android_target" !android_target; print"libev_default" !libev_default; close_out f; - (* '-use-camlp4 false' will write a jbuild-ignore file directing jbuilder to ignore + (* '-use-camlp4 false' (or none) will write a jbuild-ignore file directing jbuilder to ignore * the camlp4 directory. - * '-use-camlp4 true' (or none) will write an empty file which does nothing - * except to potentially overwrite any previous version. + * '-use-camlp4 true' will write an empty file which does nothing * * This is a workaround required to overcome some weird camlp4 packaging behaviour * where ocamlfind sometimes installs a dummy META file for it even though it's * not actually installed. *) let f = open_out "src/jbuild-ignore" in - (if !use_camlp4 = Some(false) then Printf.fprintf f "camlp4" else ()); + (if !use_camlp4 = Some(true) then () else Printf.fprintf f "camlp4"); close_out f let () = main () From 455fe571d7e01ca8117c5e71ba34708e59ac4e00 Mon Sep 17 00:00:00 2001 From: andrewray Date: Thu, 8 Jun 2017 01:21:45 +0100 Subject: [PATCH 40/46] didn't mean to remove the install target from the Makefile --- Makefile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Makefile b/Makefile index 144beee9e9..9aa51e76ad 100644 --- a/Makefile +++ b/Makefile @@ -48,6 +48,9 @@ doc-api-html: all doc-api-wiki: all make -C doc api/wiki/index.wiki +install: + jbuilder install + uninstall: jbuilder uninstall From c075a63df683bbf8ad0325b204f234287e4df11f Mon Sep 17 00:00:00 2001 From: Anton Bachin Date: Thu, 8 Jun 2017 10:45:25 -0500 Subject: [PATCH 41/46] Fix up lwt_react, lwt_ssl, lwt_glib opam files Mostly editing whitespace to restore lines to their former state; this makes it easier for git to identify which file was renamed from where. See https://github.com/ocsigen/lwt/pull/374#issuecomment-306967527 Also restored constraints on lwt_react, and restored package names. --- lwt_glib.opam | 2 +- lwt_react.opam | 6 +++--- lwt_ssl.opam | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lwt_glib.opam b/lwt_glib.opam index 4ecd812cd6..417675712e 100644 --- a/lwt_glib.opam +++ b/lwt_glib.opam @@ -1,5 +1,5 @@ opam-version: "1.2" -name: "lwt" +name: "lwt_glib" version: "dev" maintainer: [ "Anton Bachin " diff --git a/lwt_react.opam b/lwt_react.opam index e36e00fff1..2fbc92197c 100644 --- a/lwt_react.opam +++ b/lwt_react.opam @@ -1,5 +1,5 @@ opam-version: "1.2" -name: "lwt" +name: "lwt_react" version: "dev" maintainer: [ "Anton Bachin " @@ -19,7 +19,7 @@ build: [ [ "jbuilder" "build" "-p" name "-j" jobs ] ] build-test: [ [ "jbuilder" "runtest" "-p" name ] ] depends: [ "jbuilder" { build & >= "1.0+beta9" } - "lwt" - "react" + "lwt" {>= "3.0.0"} + "react" {>= "1.0.0"} ] diff --git a/lwt_ssl.opam b/lwt_ssl.opam index 6db9dcdc25..7f580233cc 100644 --- a/lwt_ssl.opam +++ b/lwt_ssl.opam @@ -1,5 +1,5 @@ opam-version: "1.2" -name: "lwt" +name: "lwt_ssl" version: "dev" maintainer: [ "Anton Bachin " @@ -19,8 +19,8 @@ build: [ [ "jbuilder" "build" "-p" name "-j" jobs ] ] build-test: [ [ "jbuilder" "runtest" "-p" name ] ] depends: [ "jbuilder" { build & >= "1.0+beta9" } - "lwt" { >= "3.0.0" } - "ssl" { >= "0.5.0" } + "lwt" {>= "3.0.0"} + "ssl" {>= "0.5.0"} "base-unix" ] From dacbef89684784205d197a867914248457170c12 Mon Sep 17 00:00:00 2001 From: Anton Bachin Date: Thu, 8 Jun 2017 10:57:25 -0500 Subject: [PATCH 42/46] Fix up lwt.opam Mainly to reduce the net diff, but also to keep the OCaml version constraint. We shouldn't rely on jbuilder requiring 4.02.3 as a lower bound. Even though jbuilder is not likely to support 4.02.0, it's better to keep the inherent 4.02.0 constraint of Lwt in its own opam file, for now. --- lwt.opam | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lwt.opam b/lwt.opam index 6e2d1cb234..a0be996e44 100644 --- a/lwt.opam +++ b/lwt.opam @@ -22,7 +22,7 @@ build: [ ] build-test: [ [ "jbuilder" "runtest" "-p" name ] ] depends: [ - "ocamlfind" { build & >= "1.5.0" } + "ocamlfind" {build & >= "1.5.0"} "jbuilder" { build & >= "1.0+beta9" } "ppx_tools_versioned" "cppo" { build } @@ -34,6 +34,9 @@ depopts: [ "conf-libev" "camlp4" ] +# In practice, Lwt requires OCaml >= 4.02.3, as that is a constraint of the +# dependency jbuilder. +available: [ocaml-version >= "4.02.0" & compiler != "4.02.1+BER"] messages: [ "For module Lwt_ssl, please install package lwt_ssl" {ssl:installed & !lwt_ssl:installed} From 0a33c4990cfec9e4c933704b22fde63e6e064721 Mon Sep 17 00:00:00 2001 From: Anton Bachin Date: Thu, 8 Jun 2017 11:00:56 -0500 Subject: [PATCH 43/46] Revert change to README.md Since we decided not to change it in this PR :) This reduces the net diff slightly. More importantly, it eliminates the merge conflict, allowing the CI builds to run again without having to do a merge or rebase first. --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 680833010f..56386cbfe9 100644 --- a/README.md +++ b/README.md @@ -119,6 +119,8 @@ version, opam source --dev-repo --pin lwt ``` +This will also install the development dependency OASIS. + A list of [project suggestions][projects] and a [roadmap][roadmap] can be found on the wiki. From 7ca76aaf4ff65b3eb30b598f6d55cb3a48235b6a Mon Sep 17 00:00:00 2001 From: Anton Bachin Date: Thu, 8 Jun 2017 11:07:41 -0500 Subject: [PATCH 44/46] More fixing up of lwt_react, lwt_ssl, lwt_glib - Restore authors. As far as I know, they were accurate. - Avoid moving the dev-repo field. We can move it later, if needed. - Restore constraint on Lwt in lwt_glib. --- lwt_glib.opam | 5 ++--- lwt_react.opam | 3 +-- lwt_ssl.opam | 2 +- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/lwt_glib.opam b/lwt_glib.opam index 417675712e..56f9afdb43 100644 --- a/lwt_glib.opam +++ b/lwt_glib.opam @@ -7,20 +7,19 @@ maintainer: [ "Simon Cruanes " ] authors: [ - "Jérôme Vouillon" "Jérémie Dimino" ] homepage: "https://github.com/ocsigen/lwt" doc: "https://ocsigen.org/lwt/manual/" +dev-repo: "https://github.com/ocsigen/lwt.git" bug-reports: "https://github.com/ocsigen/lwt/issues" license: "LGPL with OpenSSL linking exception" -dev-repo: "https://github.com/ocsigen/lwt.git" build: [ [ "jbuilder" "build" "-p" name "-j" jobs ] ] build-test: [ [ "jbuilder" "runtest" "-p" name ] ] depends: [ "jbuilder" { build & >= "1.0+beta9" } + "lwt" {>= "3.0.0"} "base-unix" - "lwt" "conf-pkg-config" {build} "conf-glib-2" {build} ] diff --git a/lwt_react.opam b/lwt_react.opam index 2fbc92197c..e7202fdebe 100644 --- a/lwt_react.opam +++ b/lwt_react.opam @@ -7,14 +7,13 @@ maintainer: [ "Simon Cruanes " ] authors: [ - "Jérôme Vouillon" "Jérémie Dimino" ] homepage: "https://github.com/ocsigen/lwt" doc: "https://ocsigen.org/lwt/manual/" +dev-repo: "https://github.com/ocsigen/lwt.git" bug-reports: "https://github.com/ocsigen/lwt/issues" license: "LGPL with OpenSSL linking exception" -dev-repo: "https://github.com/ocsigen/lwt.git" build: [ [ "jbuilder" "build" "-p" name "-j" jobs ] ] build-test: [ [ "jbuilder" "runtest" "-p" name ] ] depends: [ diff --git a/lwt_ssl.opam b/lwt_ssl.opam index 7f580233cc..3e46e09d28 100644 --- a/lwt_ssl.opam +++ b/lwt_ssl.opam @@ -12,9 +12,9 @@ authors: [ ] homepage: "https://github.com/ocsigen/lwt" doc: "https://ocsigen.org/lwt/manual/" +dev-repo: "https://github.com/ocsigen/lwt.git" bug-reports: "https://github.com/ocsigen/lwt/issues" license: "LGPL with OpenSSL linking exception" -dev-repo: "https://github.com/ocsigen/lwt.git" build: [ [ "jbuilder" "build" "-p" name "-j" jobs ] ] build-test: [ [ "jbuilder" "runtest" "-p" name ] ] depends: [ From e0077c310f7cda2ebb2dad406a6215bac485c32c Mon Sep 17 00:00:00 2001 From: Anton Bachin Date: Thu, 8 Jun 2017 11:39:50 -0500 Subject: [PATCH 45/46] Nits: remove some trailing whitespace Doing this before the squash because it is harmful to do it in a separate commit to master afterwards: it will pollute the blame. [skip ci] --- .gitignore | 1 - META.lwt.template | 1 - Makefile | 8 ++++---- doc/Makefile | 7 +++---- doc/examples/unix/jbuild | 3 +-- jbuild | 10 ++++------ lwt.opam | 6 +++--- lwt_glib.opam | 2 -- lwt_react.opam | 1 - lwt_ssl.opam | 3 --- src/camlp4/jbuild | 1 - src/camlp4/log/jbuild | 2 -- src/camlp4/options/jbuild | 1 - src/core/jbuild | 2 +- src/glib/config/discover.ml | 26 ++++++++++++-------------- src/glib/jbuild | 2 +- src/ppx/jbuild | 1 - src/ppx/ppx_lwt.ml | 6 ++---- src/ppx/ppx_lwt.mli | 1 - src/preemptive/jbuild | 3 +-- src/react/jbuild | 3 +-- src/simple_top/jbuild | 3 +-- src/ssl/jbuild | 3 +-- src/unix/config/discover.ml | 36 +++++++++++++++++------------------- src/unix/config/jbuild | 2 +- src/unix/jbuild | 7 +++---- src/util/appveyor-install.sh | 2 +- src/util/config-warn | 4 ++-- src/util/configure.ml | 15 +++++++-------- src/util/travis.sh | 4 +++- tests/core/jbuild | 3 +-- tests/jbuild | 5 ++--- tests/ppx/jbuild | 3 +-- tests/preemptive/jbuild | 4 +--- tests/react/jbuild | 3 +-- tests/unix/jbuild | 3 +-- 36 files changed, 76 insertions(+), 111 deletions(-) diff --git a/.gitignore b/.gitignore index e8dab84d42..e28d012e35 100644 --- a/.gitignore +++ b/.gitignore @@ -12,4 +12,3 @@ scratch/ # Autogenerated by jbuider .merlin *.install - diff --git a/META.lwt.template b/META.lwt.template index 9769199b7d..f53e6d385e 100644 --- a/META.lwt.template +++ b/META.lwt.template @@ -132,4 +132,3 @@ package "unix" ( plugin(native) = "lwt_unix.cmxs" exists_if = "lwt_unix.cma" ) - diff --git a/Makefile b/Makefile index 9aa51e76ad..487dc7afdd 100644 --- a/Makefile +++ b/Makefile @@ -48,17 +48,17 @@ doc-api-html: all doc-api-wiki: all make -C doc api/wiki/index.wiki -install: +install: jbuilder install -uninstall: +uninstall: jbuilder uninstall -reinstall: +reinstall: jbuilder uninstall jbuilder install -clean: +clean: rm -fr _build rm -f *.install rm -fr doc/api diff --git a/doc/Makefile b/doc/Makefile index 44a9a4a0f7..ec4ed687d6 100644 --- a/doc/Makefile +++ b/doc/Makefile @@ -5,7 +5,7 @@ PKGS=\ -package bytes -package result \ -package bigarray -package unix -package camlp4 \ -package ocaml-migrate-parsetree -package ppx_tools_versioned \ - -package react -package ssl + -package react -package ssl INCS=\ -I ${BLD}/camlp4 \ @@ -29,7 +29,7 @@ MLIS=\ $(wildcard ${SRC}/react/*.mli) \ $(wildcard ${SRC}/simple_top/*.mli) \ $(wildcard ${SRC}/ssl/*.mli) \ - $(filter-out ${BLD}/unix/lwt_unix.cppo.mli,$(wildcard ${BLD}/unix/*.mli)) + $(filter-out ${BLD}/unix/lwt_unix.cppo.mli,$(wildcard ${BLD}/unix/*.mli)) DOCOPT := -colorize-code -short-functors -charset utf-8 @@ -41,11 +41,10 @@ api/html/index.html: ${MLIS} apiref-intro -d api/html \ ${MLIS} -wikidoc: api/wiki/index.wiki +wikidoc: api/wiki/index.wiki api/wiki/index.wiki: ${MLIS} apiref-intro mkdir -p api/wiki ocamlfind ocamldoc ${DOCOPT} -package ocamlbuild,uchar ${PKGS} ${INCS} -intro apiref-intro \ -d api/wiki \ -i $(shell ocamlfind query wikidoc) -g odoc_wiki.cma \ ${MLIS} - diff --git a/doc/examples/unix/jbuild b/doc/examples/unix/jbuild index d69cc467a3..4c74b2bdf8 100644 --- a/doc/examples/unix/jbuild +++ b/doc/examples/unix/jbuild @@ -1,7 +1,6 @@ (jbuild_version 1) -(executables +(executables ((names (logging relay parallelize)) (libraries (lwt-unix)) (preprocess (pps (lwt-ppx))))) - diff --git a/jbuild b/jbuild index e76d21a2db..e960b5250f 100644 --- a/jbuild +++ b/jbuild @@ -1,13 +1,11 @@ (jbuild_version 1) -(alias - ((name unix-examples) +(alias + ((name unix-examples) (deps (doc/examples/unix/logging.exe doc/examples/unix/relay.exe doc/examples/unix/parallelize.exe)))) - + (alias - ((name gtk-example) + ((name gtk-example) (deps (doc/examples/gtk/connect.exe)))) - - diff --git a/lwt.opam b/lwt.opam index a0be996e44..2bbb1c9df5 100644 --- a/lwt.opam +++ b/lwt.opam @@ -15,16 +15,16 @@ doc: "https://ocsigen.org/lwt/manual/" bug-reports: "https://github.com/ocsigen/lwt/issues" license: "LGPL with OpenSSL linking exception" dev-repo: "https://github.com/ocsigen/lwt.git" -build: [ +build: [ [ "ocaml" "src/util/configure.ml" "-use-libev" "%{conf-libev:installed}%" "-use-camlp4" "%{camlp4:installed}%" ] - [ "jbuilder" "build" "-p" name "-j" jobs ] + [ "jbuilder" "build" "-p" name "-j" jobs ] ] build-test: [ [ "jbuilder" "runtest" "-p" name ] ] depends: [ "ocamlfind" {build & >= "1.5.0"} "jbuilder" { build & >= "1.0+beta9" } - "ppx_tools_versioned" + "ppx_tools_versioned" "cppo" { build } "result" ] diff --git a/lwt_glib.opam b/lwt_glib.opam index 56f9afdb43..4ab92fe1f4 100644 --- a/lwt_glib.opam +++ b/lwt_glib.opam @@ -23,5 +23,3 @@ depends: [ "conf-pkg-config" {build} "conf-glib-2" {build} ] - - diff --git a/lwt_react.opam b/lwt_react.opam index e7202fdebe..947748ad6b 100644 --- a/lwt_react.opam +++ b/lwt_react.opam @@ -21,4 +21,3 @@ depends: [ "lwt" {>= "3.0.0"} "react" {>= "1.0.0"} ] - diff --git a/lwt_ssl.opam b/lwt_ssl.opam index 3e46e09d28..a7956ee4ca 100644 --- a/lwt_ssl.opam +++ b/lwt_ssl.opam @@ -23,6 +23,3 @@ depends: [ "ssl" {>= "0.5.0"} "base-unix" ] - - - diff --git a/src/camlp4/jbuild b/src/camlp4/jbuild index e291e2d1cd..88b66a0653 100644 --- a/src/camlp4/jbuild +++ b/src/camlp4/jbuild @@ -8,4 +8,3 @@ (wrapped false) (libraries (camlp4 lwt.syntax.options)) (preprocess (action (run camlp4oof ${<}))))) - diff --git a/src/camlp4/log/jbuild b/src/camlp4/log/jbuild index 1b64b40be1..beda303cc1 100644 --- a/src/camlp4/log/jbuild +++ b/src/camlp4/log/jbuild @@ -8,5 +8,3 @@ (wrapped false) (libraries (camlp4 lwt.syntax.options)) (preprocess (action (run camlp4oof ${<}))))) - - diff --git a/src/camlp4/options/jbuild b/src/camlp4/options/jbuild index f0e0dece7b..19696ba965 100644 --- a/src/camlp4/options/jbuild +++ b/src/camlp4/options/jbuild @@ -7,4 +7,3 @@ (optional) (wrapped false) (libraries (camlp4)))) - diff --git a/src/core/jbuild b/src/core/jbuild index 79631cb392..01e6696ef1 100644 --- a/src/core/jbuild +++ b/src/core/jbuild @@ -1,6 +1,6 @@ (jbuild_version 1) -(library +(library ((name lwt) (public_name lwt) (synopsis "Monadic promises and concurrent I/O") diff --git a/src/glib/config/discover.ml b/src/glib/config/discover.ml index 0dd0ef658b..3524289d33 100644 --- a/src/glib/config/discover.ml +++ b/src/glib/config/discover.ml @@ -45,15 +45,15 @@ let pkg_config arguments = exit 1 (* read ocamlc -config file, if provided *) -let get_ocamlc_config name = +let get_ocamlc_config name = let f = open_in name in - let cfg line = + let cfg line = let idx = String.index line ':' in String.sub line 0 idx, - String.sub line (idx + 2) (String.length line - idx - 2) + String.sub line (idx + 2) (String.length line - idx - 2) in let input_line () = try Some(input_line f) with End_of_file -> None in - let rec lines () = + let rec lines () = match input_line () with | None -> [] | Some(x) -> cfg x :: lines () @@ -62,15 +62,15 @@ let get_ocamlc_config name = let () = close_in f in cfg -let ccomp_type = - try +let ccomp_type = + try let cfg = get_ocamlc_config Sys.argv.(1) in List.assoc "ccomp_type" cfg - with _ -> + with _ -> let () = Printf.eprintf "failed to read ccomp_type from ocamlc -config\n" in exit 1 - -let cflags = pkg_config "--cflags glib-2.0" + +let cflags = pkg_config "--cflags glib-2.0" let libs = if String.compare ccomp_type "msvc" = 0 then pkg_config "--libs-only-L glib-2.0" @ @@ -79,19 +79,17 @@ let libs = pkg_config "--libs glib-2.0" (* do sexps properly... -let () = +let () = let write_sexp fn sexp = Out_channel.write_all fn ~data:(Sexp.to_string sexp) in write_sexp "glib_c_flags.sexp" (sexp_of_list sexp_of_string cflags); write_sexp "glib_c_library_flags.sexp" (sexp_of_list sexp_of_string libs) *) -let () = - let write_sexp n x = +let () = + let write_sexp n x = let f = open_out n in output_string f ("(" ^ String.concat " " x ^ ")"); close_out f in write_sexp ("glib_c_flags.sexp") cflags; write_sexp ("glib_c_library_flags.sexp") libs - - diff --git a/src/glib/jbuild b/src/glib/jbuild index fb5ac4eeff..e142b9dff7 100644 --- a/src/glib/jbuild +++ b/src/glib/jbuild @@ -1,6 +1,6 @@ (jbuild_version 1) -(library +(library ((name lwt_glib) (public_name lwt_glib) (synopsis "GLib integration for Lwt") diff --git a/src/ppx/jbuild b/src/ppx/jbuild index e537741e98..8f1ee64e32 100644 --- a/src/ppx/jbuild +++ b/src/ppx/jbuild @@ -11,4 +11,3 @@ (ppx_runtime_libraries (lwt)) (kind ppx_rewriter) (preprocess (pps (ppx_tools_versioned.metaquot_404))))) - diff --git a/src/ppx/ppx_lwt.ml b/src/ppx/ppx_lwt.ml index cb997cb835..886388712c 100644 --- a/src/ppx/ppx_lwt.ml +++ b/src/ppx/ppx_lwt.ml @@ -365,7 +365,7 @@ let mapper = } -let args = +let args = Arg.([ "-no-debug", Clear debug, "disable debug mode"; "-log", Set log, "enable logging"; @@ -374,8 +374,6 @@ let args = "-no-strict-sequence", Clear strict_seq, "allow non-unit sequence operations"; ]) -let () = +let () = Driver.register ~name:"ppx_lwt" ~args Versions.ocaml_404 (fun _config _cookies -> mapper) - - diff --git a/src/ppx/ppx_lwt.mli b/src/ppx/ppx_lwt.mli index 69d7f8d216..2dd976441d 100644 --- a/src/ppx/ppx_lwt.mli +++ b/src/ppx/ppx_lwt.mli @@ -241,4 +241,3 @@ else val mapper : Migrate_parsetree.OCaml_404.Ast.Ast_mapper.mapper - diff --git a/src/preemptive/jbuild b/src/preemptive/jbuild index b1547e534d..d5102eb1de 100644 --- a/src/preemptive/jbuild +++ b/src/preemptive/jbuild @@ -1,9 +1,8 @@ (jbuild_version 1) -(library +(library ((name lwt_preemptive) (public_name lwt.preemptive) (synopsis "Preemptive thread support for Lwt") (wrapped false) (libraries (lwt lwt.unix threads)))) - diff --git a/src/react/jbuild b/src/react/jbuild index d0ecb48c31..80e21655fb 100644 --- a/src/react/jbuild +++ b/src/react/jbuild @@ -1,9 +1,8 @@ (jbuild_version 1) -(library +(library ((name lwt_react) (public_name lwt_react) (synopsis "Reactive programming helpers for Lwt") (wrapped false) (libraries (lwt react)))) - diff --git a/src/simple_top/jbuild b/src/simple_top/jbuild index 4f47b71f94..f54fa846d2 100644 --- a/src/simple_top/jbuild +++ b/src/simple_top/jbuild @@ -1,10 +1,9 @@ (jbuild_version 1) -(library +(library ((name lwt_simple_top) (public_name lwt.simple-top) (synopsis "Lwt-OCaml top level integration (deprecated; use utop)") (optional) (wrapped false) (libraries (lwt lwt.unix compiler-libs.common)))) - diff --git a/src/ssl/jbuild b/src/ssl/jbuild index c5cef6867f..d983c270f8 100644 --- a/src/ssl/jbuild +++ b/src/ssl/jbuild @@ -1,9 +1,8 @@ (jbuild_version 1) -(library +(library ((name lwt_ssl) (public_name lwt_ssl) (synopsis "SSL support for Lwt") (wrapped false) (libraries (ssl lwt.unix)))) - diff --git a/src/unix/config/discover.ml b/src/unix/config/discover.ml index 3781396d2d..69604bcf77 100644 --- a/src/unix/config/discover.ml +++ b/src/unix/config/discover.ml @@ -541,17 +541,17 @@ let () = safe_remove (Filename.chop_extension !caml_file ^ ".cmi"); safe_remove (Filename.chop_extension !caml_file ^ ".cmo")); - (* read ocamlc -config and lwt config files. + (* read ocamlc -config and lwt config files. The former must exist, but we can apply defaults for the later. *) - let read_config config filename = + let read_config config filename = let f = open_in filename in - let cfg line = + let cfg line = let idx = String.index line ':' in String.sub line 0 idx, - String.sub line (idx + 2) (String.length line - idx - 2) + String.sub line (idx + 2) (String.length line - idx - 2) in let input_line () = try Some(input_line f) with End_of_file -> None in - let rec lines () = + let rec lines () = match input_line () with | None -> [] | Some(x) -> cfg x :: lines () @@ -567,12 +567,12 @@ let () = let ocamlc_config = read_config "ocamlc" !ocamlc_config in let lwt_config = try read_config "lwt" !lwt_config with _ -> [] in (* get params from configuration files *) - let () = - let get var name = - try + let () = + let get var name = + try var := List.assoc name ocamlc_config; printf "found config var %s: %s %s\n" name (String.make (29 - String.length name) '.') !var - with Not_found -> + with Not_found -> printf "Couldn't find value '%s' in 'ocamlc -config'\n" name; exit 1 in @@ -581,23 +581,23 @@ let () = get ccomp_type "ccomp_type"; get system "system"; get os_type "os_type"; - let get var name default = - try - let () = + let get var name default = + try + let () = match List.assoc name lwt_config with | "true" -> var := true | "false" -> var := false | _ -> raise Not_found in printf "found config var %s: %s %b\n" name (String.make (29 - String.length name) '.') !var - with Not_found -> + with Not_found -> var := default in (* set up the defaults as per the original _oasis file *) get android_target "android_target" false; get use_pthread "use_pthread" (!os_type <> "Win32"); get use_libev "use_libev" (!os_type <> "Win32" && !android_target = false); - get libev_default "libev_default" + get libev_default "libev_default" (List.mem !system (* as per _oasis *) ["linux"; "linux_elf"; "linux_aout"; "linux_eabi"; "linux_eabihf"]); in @@ -849,7 +849,7 @@ Lwt can use pthread or the win32 API. close_out config_ml; - let get_flags lib = + let get_flags lib = (try List.assoc (lib ^ "_opt") !setup_data with _ -> []), (try List.assoc (lib ^ "_lib") !setup_data with _ -> []) in @@ -868,7 +868,7 @@ Lwt can use pthread or the win32 API. *) (* add Win32 linker flags *) - let libs = + let libs = if !os_type = "Win32" then if !ccomp_type = "msvc" then libs @ ["ws2_32.lib"] else libs @ ["-lws2_32"] @@ -876,12 +876,10 @@ Lwt can use pthread or the win32 API. libs in - let write_sexp n x = + let write_sexp n x = let f = open_out n in output_string f ("(" ^ String.concat " " x ^ ")"); close_out f in write_sexp ("unix_c_flags.sexp") ("-I."::cflags); write_sexp ("unix_c_library_flags.sexp") libs - - diff --git a/src/unix/config/jbuild b/src/unix/config/jbuild index acaeec2a64..fb28bc378a 100644 --- a/src/unix/config/jbuild +++ b/src/unix/config/jbuild @@ -1,4 +1,4 @@ (jbuild_version 1) -(executable +(executable ((name discover))) diff --git a/src/unix/jbuild b/src/unix/jbuild index 34b37274ac..abdb3843c4 100644 --- a/src/unix/jbuild +++ b/src/unix/jbuild @@ -14,7 +14,7 @@ ;; lwt feature discovery ;; -;; we use 2 config files +;; we use 2 config files ;; ;; - ocamlc_config which is generated here from calling 'ocamlc -config' ;; - lwt_config which is optionally generated by src/utils/configure.ml @@ -41,7 +41,7 @@ (rule ((targets (unix_c_flags.sexp unix_c_library_flags.sexp - lwt_config.h + lwt_config.h lwt_config.ml)) (deps (config/discover.exe ocamlc_config lwt_config)) (action (run ${<} @@ -120,7 +120,7 @@ lwt_unix_job_tcsendbreak lwt_unix_job_truncate lwt_unix_job_unlink - )) + )) (install_c_headers ( lwt_config lwt_unix @@ -130,4 +130,3 @@ (c_flags (:include unix_c_flags.sexp)) (c_library_flags (:include unix_c_library_flags.sexp)) )) - diff --git a/src/util/appveyor-install.sh b/src/util/appveyor-install.sh index d9b2a93952..cd7c94a536 100644 --- a/src/util/appveyor-install.sh +++ b/src/util/appveyor-install.sh @@ -19,7 +19,7 @@ then opam init -y --auto-setup eval `opam config env` - # Pin Lwt and install its dependencies. + # Pin Lwt and install its dependencies. opam pin add -y --no-action lwt . opam install -y --deps-only lwt opam install -y camlp4 diff --git a/src/util/config-warn b/src/util/config-warn index 72fcffd028..50fa42b333 100644 --- a/src/util/config-warn +++ b/src/util/config-warn @@ -1,9 +1,9 @@ =========================================================== -LWT configuration is incomplete and compilation will +LWT configuration is incomplete and compilation will proceed with default values. -Consider running 'ocaml src/util/configure.ml' or +Consider running 'ocaml src/util/configure.ml' or 'make default-config' to complete configuration. $ ocaml src/util/configure.ml -help diff --git a/src/util/configure.ml b/src/util/configure.ml index 34f1b435a0..8da874accf 100644 --- a/src/util/configure.ml +++ b/src/util/configure.ml @@ -18,12 +18,12 @@ let args = [ "-android-target", arg_bool android_target, " compile for Android"; "-libev-default", arg_bool libev_default, " whether to use the libev backend by default"; "-use-camlp4", arg_bool use_camlp4, " when true enable camlp4 syntax extension"; -] +] -let main () = +let main () = Arg.parse args ignore "enable lwt.unix and camlp4 features\noptions are:"; let f = open_out "src/unix/lwt_config" in - let print name var = + let print name var = match var with | None -> () | Some var -> Printf.fprintf f "%s: %b\n" name var @@ -34,15 +34,14 @@ let main () = print"libev_default" !libev_default; close_out f; (* '-use-camlp4 false' (or none) will write a jbuild-ignore file directing jbuilder to ignore - * the camlp4 directory. - * '-use-camlp4 true' will write an empty file which does nothing - * + * the camlp4 directory. + * '-use-camlp4 true' will write an empty file which does nothing + * * This is a workaround required to overcome some weird camlp4 packaging behaviour - * where ocamlfind sometimes installs a dummy META file for it even though it's + * where ocamlfind sometimes installs a dummy META file for it even though it's * not actually installed. *) let f = open_out "src/jbuild-ignore" in (if !use_camlp4 = Some(true) then () else Printf.fprintf f "camlp4"); close_out f let () = main () - diff --git a/src/util/travis.sh b/src/util/travis.sh index 93ff9173dd..45fcb6fb3b 100644 --- a/src/util/travis.sh +++ b/src/util/travis.sh @@ -113,6 +113,8 @@ then echo Expected OCaml $OCAML_VERSION, but $ACTUAL_COMPILER is installed fi + + # Pin Lwt, install dependencies, and then install Lwt. Lwt is installed # separately because we want to keep the build directory for running the tests. opam pin add -y --no-action lwt . @@ -128,7 +130,7 @@ opam install --keep-build-dir --verbose lwt # Pin additional packages and install them. There # aren't any specific tests for these packages. Installation itself is the only -# test. +# test. install_extra_package () { PACKAGE=$1 opam pin add -y --no-action lwt_$PACKAGE . diff --git a/tests/core/jbuild b/tests/core/jbuild index d2a15d5956..9f5f445764 100644 --- a/tests/core/jbuild +++ b/tests/core/jbuild @@ -1,6 +1,6 @@ (jbuild_version 1) -(executable +(executable ((name main) (libraries (lwttester)))) @@ -8,4 +8,3 @@ ((name runtest) (package lwt) (action (run ${exe:main.exe})))) - diff --git a/tests/jbuild b/tests/jbuild index a28330f0fc..53fc8b7b41 100644 --- a/tests/jbuild +++ b/tests/jbuild @@ -1,7 +1,6 @@ (jbuild_version 1) - -(library + +(library ((name "lwttester") (wrapped false) (libraries (lwt unix lwt.unix)))) - diff --git a/tests/ppx/jbuild b/tests/ppx/jbuild index dea7e0525e..a625d3ad15 100644 --- a/tests/ppx/jbuild +++ b/tests/ppx/jbuild @@ -1,6 +1,6 @@ (jbuild_version 1) -(executable +(executable ((name main) (libraries (lwttester)) (preprocess (pps (lwt.ppx))))) @@ -9,4 +9,3 @@ ((name runtest) (package lwt) (action (run ${exe:main.exe})))) - diff --git a/tests/preemptive/jbuild b/tests/preemptive/jbuild index 7ace1bd14b..2c3c8ee332 100644 --- a/tests/preemptive/jbuild +++ b/tests/preemptive/jbuild @@ -1,6 +1,6 @@ (jbuild_version 1) -(executable +(executable ((name main) (libraries (lwt.preemptive lwttester)))) @@ -8,5 +8,3 @@ ((name runtest) (package lwt) (action (run ${exe:main.exe})))) - - diff --git a/tests/react/jbuild b/tests/react/jbuild index e7574c7f3f..5b36992722 100644 --- a/tests/react/jbuild +++ b/tests/react/jbuild @@ -1,6 +1,6 @@ (jbuild_version 1) -(executable +(executable ((name main) (libraries (lwt_react lwttester)))) @@ -8,4 +8,3 @@ ((name runtest) (package lwt_react) (action (run ${exe:main.exe})))) - diff --git a/tests/unix/jbuild b/tests/unix/jbuild index c865a5386a..0fce9092e0 100644 --- a/tests/unix/jbuild +++ b/tests/unix/jbuild @@ -5,7 +5,7 @@ (deps (test_lwt_unix.cppo.ml)) (action (run ${bin:cppo} -V OCAML:${ocaml_version} ${<} -o ${@})))) -(executable +(executable ((name main) (libraries (lwttester)))) @@ -13,4 +13,3 @@ ((name runtest) (package lwt) (action (run ${exe:main.exe})))) - From 9fb2f5de5798901e9d610f86ee158fc51fc31141 Mon Sep 17 00:00:00 2001 From: Anton Bachin Date: Thu, 8 Jun 2017 12:02:40 -0500 Subject: [PATCH 46/46] One last trailing whitespace nit! [skip ci] --- lwt.opam | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lwt.opam b/lwt.opam index 2bbb1c9df5..6af2df8ebc 100644 --- a/lwt.opam +++ b/lwt.opam @@ -16,7 +16,7 @@ bug-reports: "https://github.com/ocsigen/lwt/issues" license: "LGPL with OpenSSL linking exception" dev-repo: "https://github.com/ocsigen/lwt.git" build: [ - [ "ocaml" "src/util/configure.ml" "-use-libev" "%{conf-libev:installed}%" + [ "ocaml" "src/util/configure.ml" "-use-libev" "%{conf-libev:installed}%" "-use-camlp4" "%{camlp4:installed}%" ] [ "jbuilder" "build" "-p" name "-j" jobs ] ]