PageRenderTime 42ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 1ms

/setup.ml

https://github.com/heidi-ann/ocaml-re
OCaml | 6112 lines | 5163 code | 681 blank | 268 comment | 214 complexity | 819dd0d65f23b880bfc9d345798d7118 MD5 | raw file
Possible License(s): LGPL-2.1
  1. (* setup.ml generated for the first time by OASIS v0.2.1~alpha1 *)
  2. (* OASIS_START *)
  3. (* DO NOT EDIT (digest: eccd7b71565885073005f0f309bb6a8a) *)
  4. (*
  5. Regenerated by OASIS v0.3.0
  6. Visit http://oasis.forge.ocamlcore.org for more information and
  7. documentation about functions used in this file.
  8. *)
  9. module OASISGettext = struct
  10. (* # 21 "/Users/avsm/.opam/system/build/oasis.0.3.0/src/oasis/OASISGettext.ml" *)
  11. let ns_ str =
  12. str
  13. let s_ str =
  14. str
  15. let f_ (str : ('a, 'b, 'c, 'd) format4) =
  16. str
  17. let fn_ fmt1 fmt2 n =
  18. if n = 1 then
  19. fmt1^^""
  20. else
  21. fmt2^^""
  22. let init =
  23. []
  24. end
  25. module OASISContext = struct
  26. (* # 21 "/Users/avsm/.opam/system/build/oasis.0.3.0/src/oasis/OASISContext.ml" *)
  27. open OASISGettext
  28. type level =
  29. [ `Debug
  30. | `Info
  31. | `Warning
  32. | `Error]
  33. type t =
  34. {
  35. quiet: bool;
  36. info: bool;
  37. debug: bool;
  38. ignore_plugins: bool;
  39. ignore_unknown_fields: bool;
  40. printf: level -> string -> unit;
  41. }
  42. let printf lvl str =
  43. let beg =
  44. match lvl with
  45. | `Error -> s_ "E: "
  46. | `Warning -> s_ "W: "
  47. | `Info -> s_ "I: "
  48. | `Debug -> s_ "D: "
  49. in
  50. prerr_endline (beg^str)
  51. let default =
  52. ref
  53. {
  54. quiet = false;
  55. info = false;
  56. debug = false;
  57. ignore_plugins = false;
  58. ignore_unknown_fields = false;
  59. printf = printf;
  60. }
  61. let quiet =
  62. {!default with quiet = true}
  63. let args () =
  64. ["-quiet",
  65. Arg.Unit (fun () -> default := {!default with quiet = true}),
  66. (s_ " Run quietly");
  67. "-info",
  68. Arg.Unit (fun () -> default := {!default with info = true}),
  69. (s_ " Display information message");
  70. "-debug",
  71. Arg.Unit (fun () -> default := {!default with debug = true}),
  72. (s_ " Output debug message")]
  73. end
  74. module OASISString = struct
  75. (* # 1 "/Users/avsm/.opam/system/build/oasis.0.3.0/src/oasis/OASISString.ml" *)
  76. (** Various string utilities.
  77. Mostly inspired by extlib and batteries ExtString and BatString libraries.
  78. @author Sylvain Le Gall
  79. *)
  80. let nsplitf str f =
  81. if str = "" then
  82. []
  83. else
  84. let buf = Buffer.create 13 in
  85. let lst = ref [] in
  86. let push () =
  87. lst := Buffer.contents buf :: !lst;
  88. Buffer.clear buf
  89. in
  90. let str_len = String.length str in
  91. for i = 0 to str_len - 1 do
  92. if f str.[i] then
  93. push ()
  94. else
  95. Buffer.add_char buf str.[i]
  96. done;
  97. push ();
  98. List.rev !lst
  99. (** [nsplit c s] Split the string [s] at char [c]. It doesn't include the
  100. separator.
  101. *)
  102. let nsplit str c =
  103. nsplitf str ((=) c)
  104. let find ~what ?(offset=0) str =
  105. let what_idx = ref 0 in
  106. let str_idx = ref offset in
  107. while !str_idx < String.length str &&
  108. !what_idx < String.length what do
  109. if str.[!str_idx] = what.[!what_idx] then
  110. incr what_idx
  111. else
  112. what_idx := 0;
  113. incr str_idx
  114. done;
  115. if !what_idx <> String.length what then
  116. raise Not_found
  117. else
  118. !str_idx - !what_idx
  119. let sub_start str len =
  120. let str_len = String.length str in
  121. if len >= str_len then
  122. ""
  123. else
  124. String.sub str len (str_len - len)
  125. let sub_end ?(offset=0) str len =
  126. let str_len = String.length str in
  127. if len >= str_len then
  128. ""
  129. else
  130. String.sub str 0 (str_len - len)
  131. let starts_with ~what ?(offset=0) str =
  132. let what_idx = ref 0 in
  133. let str_idx = ref offset in
  134. let ok = ref true in
  135. while !ok &&
  136. !str_idx < String.length str &&
  137. !what_idx < String.length what do
  138. if str.[!str_idx] = what.[!what_idx] then
  139. incr what_idx
  140. else
  141. ok := false;
  142. incr str_idx
  143. done;
  144. if !what_idx = String.length what then
  145. true
  146. else
  147. false
  148. let strip_starts_with ~what str =
  149. if starts_with ~what str then
  150. sub_start str (String.length what)
  151. else
  152. raise Not_found
  153. let ends_with ~what ?(offset=0) str =
  154. let what_idx = ref ((String.length what) - 1) in
  155. let str_idx = ref ((String.length str) - 1) in
  156. let ok = ref true in
  157. while !ok &&
  158. offset <= !str_idx &&
  159. 0 <= !what_idx do
  160. if str.[!str_idx] = what.[!what_idx] then
  161. decr what_idx
  162. else
  163. ok := false;
  164. decr str_idx
  165. done;
  166. if !what_idx = -1 then
  167. true
  168. else
  169. false
  170. let strip_ends_with ~what str =
  171. if ends_with ~what str then
  172. sub_end str (String.length what)
  173. else
  174. raise Not_found
  175. let replace_chars f s =
  176. let buf = String.make (String.length s) 'X' in
  177. for i = 0 to String.length s - 1 do
  178. buf.[i] <- f s.[i]
  179. done;
  180. buf
  181. end
  182. module OASISUtils = struct
  183. (* # 21 "/Users/avsm/.opam/system/build/oasis.0.3.0/src/oasis/OASISUtils.ml" *)
  184. open OASISGettext
  185. module MapString = Map.Make(String)
  186. let map_string_of_assoc assoc =
  187. List.fold_left
  188. (fun acc (k, v) -> MapString.add k v acc)
  189. MapString.empty
  190. assoc
  191. module SetString = Set.Make(String)
  192. let set_string_add_list st lst =
  193. List.fold_left
  194. (fun acc e -> SetString.add e acc)
  195. st
  196. lst
  197. let set_string_of_list =
  198. set_string_add_list
  199. SetString.empty
  200. let compare_csl s1 s2 =
  201. String.compare (String.lowercase s1) (String.lowercase s2)
  202. module HashStringCsl =
  203. Hashtbl.Make
  204. (struct
  205. type t = string
  206. let equal s1 s2 =
  207. (String.lowercase s1) = (String.lowercase s2)
  208. let hash s =
  209. Hashtbl.hash (String.lowercase s)
  210. end)
  211. let varname_of_string ?(hyphen='_') s =
  212. if String.length s = 0 then
  213. begin
  214. invalid_arg "varname_of_string"
  215. end
  216. else
  217. begin
  218. let buf =
  219. OASISString.replace_chars
  220. (fun c ->
  221. if ('a' <= c && c <= 'z')
  222. ||
  223. ('A' <= c && c <= 'Z')
  224. ||
  225. ('0' <= c && c <= '9') then
  226. c
  227. else
  228. hyphen)
  229. s;
  230. in
  231. let buf =
  232. (* Start with a _ if digit *)
  233. if '0' <= s.[0] && s.[0] <= '9' then
  234. "_"^buf
  235. else
  236. buf
  237. in
  238. String.lowercase buf
  239. end
  240. let varname_concat ?(hyphen='_') p s =
  241. let what = String.make 1 hyphen in
  242. let p =
  243. try
  244. OASISString.strip_ends_with ~what p
  245. with Not_found ->
  246. p
  247. in
  248. let s =
  249. try
  250. OASISString.strip_starts_with ~what s
  251. with Not_found ->
  252. s
  253. in
  254. p^what^s
  255. let is_varname str =
  256. str = varname_of_string str
  257. let failwithf fmt = Printf.ksprintf failwith fmt
  258. end
  259. module PropList = struct
  260. (* # 21 "/Users/avsm/.opam/system/build/oasis.0.3.0/src/oasis/PropList.ml" *)
  261. open OASISGettext
  262. type name = string
  263. exception Not_set of name * string option
  264. exception No_printer of name
  265. exception Unknown_field of name * name
  266. let () =
  267. Printexc.register_printer
  268. (function
  269. | Not_set (nm, Some rsn) ->
  270. Some
  271. (Printf.sprintf (f_ "Field '%s' is not set: %s") nm rsn)
  272. | Not_set (nm, None) ->
  273. Some
  274. (Printf.sprintf (f_ "Field '%s' is not set") nm)
  275. | No_printer nm ->
  276. Some
  277. (Printf.sprintf (f_ "No default printer for value %s") nm)
  278. | Unknown_field (nm, schm) ->
  279. Some
  280. (Printf.sprintf (f_ "Field %s is not defined in schema %s") nm schm)
  281. | _ ->
  282. None)
  283. module Data =
  284. struct
  285. type t =
  286. (name, unit -> unit) Hashtbl.t
  287. let create () =
  288. Hashtbl.create 13
  289. let clear t =
  290. Hashtbl.clear t
  291. (* # 71 "/Users/avsm/.opam/system/build/oasis.0.3.0/src/oasis/PropList.ml" *)
  292. end
  293. module Schema =
  294. struct
  295. type ('ctxt, 'extra) value =
  296. {
  297. get: Data.t -> string;
  298. set: Data.t -> ?context:'ctxt -> string -> unit;
  299. help: (unit -> string) option;
  300. extra: 'extra;
  301. }
  302. type ('ctxt, 'extra) t =
  303. {
  304. name: name;
  305. fields: (name, ('ctxt, 'extra) value) Hashtbl.t;
  306. order: name Queue.t;
  307. name_norm: string -> string;
  308. }
  309. let create ?(case_insensitive=false) nm =
  310. {
  311. name = nm;
  312. fields = Hashtbl.create 13;
  313. order = Queue.create ();
  314. name_norm =
  315. (if case_insensitive then
  316. String.lowercase
  317. else
  318. fun s -> s);
  319. }
  320. let add t nm set get extra help =
  321. let key =
  322. t.name_norm nm
  323. in
  324. if Hashtbl.mem t.fields key then
  325. failwith
  326. (Printf.sprintf
  327. (f_ "Field '%s' is already defined in schema '%s'")
  328. nm t.name);
  329. Hashtbl.add
  330. t.fields
  331. key
  332. {
  333. set = set;
  334. get = get;
  335. help = help;
  336. extra = extra;
  337. };
  338. Queue.add nm t.order
  339. let mem t nm =
  340. Hashtbl.mem t.fields nm
  341. let find t nm =
  342. try
  343. Hashtbl.find t.fields (t.name_norm nm)
  344. with Not_found ->
  345. raise (Unknown_field (nm, t.name))
  346. let get t data nm =
  347. (find t nm).get data
  348. let set t data nm ?context x =
  349. (find t nm).set
  350. data
  351. ?context
  352. x
  353. let fold f acc t =
  354. Queue.fold
  355. (fun acc k ->
  356. let v =
  357. find t k
  358. in
  359. f acc k v.extra v.help)
  360. acc
  361. t.order
  362. let iter f t =
  363. fold
  364. (fun () -> f)
  365. ()
  366. t
  367. let name t =
  368. t.name
  369. end
  370. module Field =
  371. struct
  372. type ('ctxt, 'value, 'extra) t =
  373. {
  374. set: Data.t -> ?context:'ctxt -> 'value -> unit;
  375. get: Data.t -> 'value;
  376. sets: Data.t -> ?context:'ctxt -> string -> unit;
  377. gets: Data.t -> string;
  378. help: (unit -> string) option;
  379. extra: 'extra;
  380. }
  381. let new_id =
  382. let last_id =
  383. ref 0
  384. in
  385. fun () -> incr last_id; !last_id
  386. let create ?schema ?name ?parse ?print ?default ?update ?help extra =
  387. (* Default value container *)
  388. let v =
  389. ref None
  390. in
  391. (* If name is not given, create unique one *)
  392. let nm =
  393. match name with
  394. | Some s -> s
  395. | None -> Printf.sprintf "_anon_%d" (new_id ())
  396. in
  397. (* Last chance to get a value: the default *)
  398. let default () =
  399. match default with
  400. | Some d -> d
  401. | None -> raise (Not_set (nm, Some (s_ "no default value")))
  402. in
  403. (* Get data *)
  404. let get data =
  405. (* Get value *)
  406. try
  407. (Hashtbl.find data nm) ();
  408. match !v with
  409. | Some x -> x
  410. | None -> default ()
  411. with Not_found ->
  412. default ()
  413. in
  414. (* Set data *)
  415. let set data ?context x =
  416. let x =
  417. match update with
  418. | Some f ->
  419. begin
  420. try
  421. f ?context (get data) x
  422. with Not_set _ ->
  423. x
  424. end
  425. | None ->
  426. x
  427. in
  428. Hashtbl.replace
  429. data
  430. nm
  431. (fun () -> v := Some x)
  432. in
  433. (* Parse string value, if possible *)
  434. let parse =
  435. match parse with
  436. | Some f ->
  437. f
  438. | None ->
  439. fun ?context s ->
  440. failwith
  441. (Printf.sprintf
  442. (f_ "Cannot parse field '%s' when setting value %S")
  443. nm
  444. s)
  445. in
  446. (* Set data, from string *)
  447. let sets data ?context s =
  448. set ?context data (parse ?context s)
  449. in
  450. (* Output value as string, if possible *)
  451. let print =
  452. match print with
  453. | Some f ->
  454. f
  455. | None ->
  456. fun _ -> raise (No_printer nm)
  457. in
  458. (* Get data, as a string *)
  459. let gets data =
  460. print (get data)
  461. in
  462. begin
  463. match schema with
  464. | Some t ->
  465. Schema.add t nm sets gets extra help
  466. | None ->
  467. ()
  468. end;
  469. {
  470. set = set;
  471. get = get;
  472. sets = sets;
  473. gets = gets;
  474. help = help;
  475. extra = extra;
  476. }
  477. let fset data t ?context x =
  478. t.set data ?context x
  479. let fget data t =
  480. t.get data
  481. let fsets data t ?context s =
  482. t.sets data ?context s
  483. let fgets data t =
  484. t.gets data
  485. end
  486. module FieldRO =
  487. struct
  488. let create ?schema ?name ?parse ?print ?default ?update ?help extra =
  489. let fld =
  490. Field.create ?schema ?name ?parse ?print ?default ?update ?help extra
  491. in
  492. fun data -> Field.fget data fld
  493. end
  494. end
  495. module OASISMessage = struct
  496. (* # 21 "/Users/avsm/.opam/system/build/oasis.0.3.0/src/oasis/OASISMessage.ml" *)
  497. open OASISGettext
  498. open OASISContext
  499. let generic_message ~ctxt lvl fmt =
  500. let cond =
  501. if ctxt.quiet then
  502. false
  503. else
  504. match lvl with
  505. | `Debug -> ctxt.debug
  506. | `Info -> ctxt.info
  507. | _ -> true
  508. in
  509. Printf.ksprintf
  510. (fun str ->
  511. if cond then
  512. begin
  513. ctxt.printf lvl str
  514. end)
  515. fmt
  516. let debug ~ctxt fmt =
  517. generic_message ~ctxt `Debug fmt
  518. let info ~ctxt fmt =
  519. generic_message ~ctxt `Info fmt
  520. let warning ~ctxt fmt =
  521. generic_message ~ctxt `Warning fmt
  522. let error ~ctxt fmt =
  523. generic_message ~ctxt `Error fmt
  524. end
  525. module OASISVersion = struct
  526. (* # 21 "/Users/avsm/.opam/system/build/oasis.0.3.0/src/oasis/OASISVersion.ml" *)
  527. open OASISGettext
  528. type s = string
  529. type t = string
  530. type comparator =
  531. | VGreater of t
  532. | VGreaterEqual of t
  533. | VEqual of t
  534. | VLesser of t
  535. | VLesserEqual of t
  536. | VOr of comparator * comparator
  537. | VAnd of comparator * comparator
  538. (* Range of allowed characters *)
  539. let is_digit c =
  540. '0' <= c && c <= '9'
  541. let is_alpha c =
  542. ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z')
  543. let is_special =
  544. function
  545. | '.' | '+' | '-' | '~' -> true
  546. | _ -> false
  547. let rec version_compare v1 v2 =
  548. if v1 <> "" || v2 <> "" then
  549. begin
  550. (* Compare ascii string, using special meaning for version
  551. * related char
  552. *)
  553. let val_ascii c =
  554. if c = '~' then -1
  555. else if is_digit c then 0
  556. else if c = '\000' then 0
  557. else if is_alpha c then Char.code c
  558. else (Char.code c) + 256
  559. in
  560. let len1 = String.length v1 in
  561. let len2 = String.length v2 in
  562. let p = ref 0 in
  563. (** Compare ascii part *)
  564. let compare_vascii () =
  565. let cmp = ref 0 in
  566. while !cmp = 0 &&
  567. !p < len1 && !p < len2 &&
  568. not (is_digit v1.[!p] && is_digit v2.[!p]) do
  569. cmp := (val_ascii v1.[!p]) - (val_ascii v2.[!p]);
  570. incr p
  571. done;
  572. if !cmp = 0 && !p < len1 && !p = len2 then
  573. val_ascii v1.[!p]
  574. else if !cmp = 0 && !p = len1 && !p < len2 then
  575. - (val_ascii v2.[!p])
  576. else
  577. !cmp
  578. in
  579. (** Compare digit part *)
  580. let compare_digit () =
  581. let extract_int v p =
  582. let start_p = !p in
  583. while !p < String.length v && is_digit v.[!p] do
  584. incr p
  585. done;
  586. let substr =
  587. String.sub v !p ((String.length v) - !p)
  588. in
  589. let res =
  590. match String.sub v start_p (!p - start_p) with
  591. | "" -> 0
  592. | s -> int_of_string s
  593. in
  594. res, substr
  595. in
  596. let i1, tl1 = extract_int v1 (ref !p) in
  597. let i2, tl2 = extract_int v2 (ref !p) in
  598. i1 - i2, tl1, tl2
  599. in
  600. match compare_vascii () with
  601. | 0 ->
  602. begin
  603. match compare_digit () with
  604. | 0, tl1, tl2 ->
  605. if tl1 <> "" && is_digit tl1.[0] then
  606. 1
  607. else if tl2 <> "" && is_digit tl2.[0] then
  608. -1
  609. else
  610. version_compare tl1 tl2
  611. | n, _, _ ->
  612. n
  613. end
  614. | n ->
  615. n
  616. end
  617. else
  618. begin
  619. 0
  620. end
  621. let version_of_string str = str
  622. let string_of_version t = t
  623. let chop t =
  624. try
  625. let pos =
  626. String.rindex t '.'
  627. in
  628. String.sub t 0 pos
  629. with Not_found ->
  630. t
  631. let rec comparator_apply v op =
  632. match op with
  633. | VGreater cv ->
  634. (version_compare v cv) > 0
  635. | VGreaterEqual cv ->
  636. (version_compare v cv) >= 0
  637. | VLesser cv ->
  638. (version_compare v cv) < 0
  639. | VLesserEqual cv ->
  640. (version_compare v cv) <= 0
  641. | VEqual cv ->
  642. (version_compare v cv) = 0
  643. | VOr (op1, op2) ->
  644. (comparator_apply v op1) || (comparator_apply v op2)
  645. | VAnd (op1, op2) ->
  646. (comparator_apply v op1) && (comparator_apply v op2)
  647. let rec string_of_comparator =
  648. function
  649. | VGreater v -> "> "^(string_of_version v)
  650. | VEqual v -> "= "^(string_of_version v)
  651. | VLesser v -> "< "^(string_of_version v)
  652. | VGreaterEqual v -> ">= "^(string_of_version v)
  653. | VLesserEqual v -> "<= "^(string_of_version v)
  654. | VOr (c1, c2) ->
  655. (string_of_comparator c1)^" || "^(string_of_comparator c2)
  656. | VAnd (c1, c2) ->
  657. (string_of_comparator c1)^" && "^(string_of_comparator c2)
  658. let rec varname_of_comparator =
  659. let concat p v =
  660. OASISUtils.varname_concat
  661. p
  662. (OASISUtils.varname_of_string
  663. (string_of_version v))
  664. in
  665. function
  666. | VGreater v -> concat "gt" v
  667. | VLesser v -> concat "lt" v
  668. | VEqual v -> concat "eq" v
  669. | VGreaterEqual v -> concat "ge" v
  670. | VLesserEqual v -> concat "le" v
  671. | VOr (c1, c2) ->
  672. (varname_of_comparator c1)^"_or_"^(varname_of_comparator c2)
  673. | VAnd (c1, c2) ->
  674. (varname_of_comparator c1)^"_and_"^(varname_of_comparator c2)
  675. let version_0_3_or_after t =
  676. comparator_apply t (VGreaterEqual (string_of_version "0.3"))
  677. end
  678. module OASISLicense = struct
  679. (* # 21 "/Users/avsm/.opam/system/build/oasis.0.3.0/src/oasis/OASISLicense.ml" *)
  680. (** License for _oasis fields
  681. @author Sylvain Le Gall
  682. *)
  683. type license = string
  684. type license_exception = string
  685. type license_version =
  686. | Version of OASISVersion.t
  687. | VersionOrLater of OASISVersion.t
  688. | NoVersion
  689. type license_dep_5_unit =
  690. {
  691. license: license;
  692. excption: license_exception option;
  693. version: license_version;
  694. }
  695. type license_dep_5 =
  696. | DEP5Unit of license_dep_5_unit
  697. | DEP5Or of license_dep_5 list
  698. | DEP5And of license_dep_5 list
  699. type t =
  700. | DEP5License of license_dep_5
  701. | OtherLicense of string (* URL *)
  702. end
  703. module OASISExpr = struct
  704. (* # 21 "/Users/avsm/.opam/system/build/oasis.0.3.0/src/oasis/OASISExpr.ml" *)
  705. open OASISGettext
  706. type test = string
  707. type flag = string
  708. type t =
  709. | EBool of bool
  710. | ENot of t
  711. | EAnd of t * t
  712. | EOr of t * t
  713. | EFlag of flag
  714. | ETest of test * string
  715. type 'a choices = (t * 'a) list
  716. let eval var_get t =
  717. let rec eval' =
  718. function
  719. | EBool b ->
  720. b
  721. | ENot e ->
  722. not (eval' e)
  723. | EAnd (e1, e2) ->
  724. (eval' e1) && (eval' e2)
  725. | EOr (e1, e2) ->
  726. (eval' e1) || (eval' e2)
  727. | EFlag nm ->
  728. let v =
  729. var_get nm
  730. in
  731. assert(v = "true" || v = "false");
  732. (v = "true")
  733. | ETest (nm, vl) ->
  734. let v =
  735. var_get nm
  736. in
  737. (v = vl)
  738. in
  739. eval' t
  740. let choose ?printer ?name var_get lst =
  741. let rec choose_aux =
  742. function
  743. | (cond, vl) :: tl ->
  744. if eval var_get cond then
  745. vl
  746. else
  747. choose_aux tl
  748. | [] ->
  749. let str_lst =
  750. if lst = [] then
  751. s_ "<empty>"
  752. else
  753. String.concat
  754. (s_ ", ")
  755. (List.map
  756. (fun (cond, vl) ->
  757. match printer with
  758. | Some p -> p vl
  759. | None -> s_ "<no printer>")
  760. lst)
  761. in
  762. match name with
  763. | Some nm ->
  764. failwith
  765. (Printf.sprintf
  766. (f_ "No result for the choice list '%s': %s")
  767. nm str_lst)
  768. | None ->
  769. failwith
  770. (Printf.sprintf
  771. (f_ "No result for a choice list: %s")
  772. str_lst)
  773. in
  774. choose_aux (List.rev lst)
  775. end
  776. module OASISTypes = struct
  777. (* # 21 "/Users/avsm/.opam/system/build/oasis.0.3.0/src/oasis/OASISTypes.ml" *)
  778. type name = string
  779. type package_name = string
  780. type url = string
  781. type unix_dirname = string
  782. type unix_filename = string
  783. type host_dirname = string
  784. type host_filename = string
  785. type prog = string
  786. type arg = string
  787. type args = string list
  788. type command_line = (prog * arg list)
  789. type findlib_name = string
  790. type findlib_full = string
  791. type compiled_object =
  792. | Byte
  793. | Native
  794. | Best
  795. type dependency =
  796. | FindlibPackage of findlib_full * OASISVersion.comparator option
  797. | InternalLibrary of name
  798. type tool =
  799. | ExternalTool of name
  800. | InternalExecutable of name
  801. type vcs =
  802. | Darcs
  803. | Git
  804. | Svn
  805. | Cvs
  806. | Hg
  807. | Bzr
  808. | Arch
  809. | Monotone
  810. | OtherVCS of url
  811. type plugin_kind =
  812. [ `Configure
  813. | `Build
  814. | `Doc
  815. | `Test
  816. | `Install
  817. | `Extra
  818. ]
  819. type plugin_data_purpose =
  820. [ `Configure
  821. | `Build
  822. | `Install
  823. | `Clean
  824. | `Distclean
  825. | `Install
  826. | `Uninstall
  827. | `Test
  828. | `Doc
  829. | `Extra
  830. | `Other of string
  831. ]
  832. type 'a plugin = 'a * name * OASISVersion.t option
  833. type all_plugin = plugin_kind plugin
  834. type plugin_data = (all_plugin * plugin_data_purpose * (unit -> unit)) list
  835. (* # 102 "/Users/avsm/.opam/system/build/oasis.0.3.0/src/oasis/OASISTypes.ml" *)
  836. type 'a conditional = 'a OASISExpr.choices
  837. type custom =
  838. {
  839. pre_command: (command_line option) conditional;
  840. post_command: (command_line option) conditional;
  841. }
  842. type common_section =
  843. {
  844. cs_name: name;
  845. cs_data: PropList.Data.t;
  846. cs_plugin_data: plugin_data;
  847. }
  848. type build_section =
  849. {
  850. bs_build: bool conditional;
  851. bs_install: bool conditional;
  852. bs_path: unix_dirname;
  853. bs_compiled_object: compiled_object;
  854. bs_build_depends: dependency list;
  855. bs_build_tools: tool list;
  856. bs_c_sources: unix_filename list;
  857. bs_data_files: (unix_filename * unix_filename option) list;
  858. bs_ccopt: args conditional;
  859. bs_cclib: args conditional;
  860. bs_dlllib: args conditional;
  861. bs_dllpath: args conditional;
  862. bs_byteopt: args conditional;
  863. bs_nativeopt: args conditional;
  864. }
  865. type library =
  866. {
  867. lib_modules: string list;
  868. lib_pack: bool;
  869. lib_internal_modules: string list;
  870. lib_findlib_parent: findlib_name option;
  871. lib_findlib_name: findlib_name option;
  872. lib_findlib_containers: findlib_name list;
  873. }
  874. type executable =
  875. {
  876. exec_custom: bool;
  877. exec_main_is: unix_filename;
  878. }
  879. type flag =
  880. {
  881. flag_description: string option;
  882. flag_default: bool conditional;
  883. }
  884. type source_repository =
  885. {
  886. src_repo_type: vcs;
  887. src_repo_location: url;
  888. src_repo_browser: url option;
  889. src_repo_module: string option;
  890. src_repo_branch: string option;
  891. src_repo_tag: string option;
  892. src_repo_subdir: unix_filename option;
  893. }
  894. type test =
  895. {
  896. test_type: [`Test] plugin;
  897. test_command: command_line conditional;
  898. test_custom: custom;
  899. test_working_directory: unix_filename option;
  900. test_run: bool conditional;
  901. test_tools: tool list;
  902. }
  903. type doc_format =
  904. | HTML of unix_filename
  905. | DocText
  906. | PDF
  907. | PostScript
  908. | Info of unix_filename
  909. | DVI
  910. | OtherDoc
  911. type doc =
  912. {
  913. doc_type: [`Doc] plugin;
  914. doc_custom: custom;
  915. doc_build: bool conditional;
  916. doc_install: bool conditional;
  917. doc_install_dir: unix_filename;
  918. doc_title: string;
  919. doc_authors: string list;
  920. doc_abstract: string option;
  921. doc_format: doc_format;
  922. doc_data_files: (unix_filename * unix_filename option) list;
  923. doc_build_tools: tool list;
  924. }
  925. type section =
  926. | Library of common_section * build_section * library
  927. | Executable of common_section * build_section * executable
  928. | Flag of common_section * flag
  929. | SrcRepo of common_section * source_repository
  930. | Test of common_section * test
  931. | Doc of common_section * doc
  932. type section_kind =
  933. [ `Library | `Executable | `Flag | `SrcRepo | `Test | `Doc ]
  934. type package =
  935. {
  936. oasis_version: OASISVersion.t;
  937. ocaml_version: OASISVersion.comparator option;
  938. findlib_version: OASISVersion.comparator option;
  939. name: package_name;
  940. version: OASISVersion.t;
  941. license: OASISLicense.t;
  942. license_file: unix_filename option;
  943. copyrights: string list;
  944. maintainers: string list;
  945. authors: string list;
  946. homepage: url option;
  947. synopsis: string;
  948. description: string option;
  949. categories: url list;
  950. conf_type: [`Configure] plugin;
  951. conf_custom: custom;
  952. build_type: [`Build] plugin;
  953. build_custom: custom;
  954. install_type: [`Install] plugin;
  955. install_custom: custom;
  956. uninstall_custom: custom;
  957. clean_custom: custom;
  958. distclean_custom: custom;
  959. files_ab: unix_filename list;
  960. sections: section list;
  961. plugins: [`Extra] plugin list;
  962. schema_data: PropList.Data.t;
  963. plugin_data: plugin_data;
  964. }
  965. end
  966. module OASISUnixPath = struct
  967. (* # 21 "/Users/avsm/.opam/system/build/oasis.0.3.0/src/oasis/OASISUnixPath.ml" *)
  968. type unix_filename = string
  969. type unix_dirname = string
  970. type host_filename = string
  971. type host_dirname = string
  972. let current_dir_name = "."
  973. let parent_dir_name = ".."
  974. let is_current_dir fn =
  975. fn = current_dir_name || fn = ""
  976. let concat f1 f2 =
  977. if is_current_dir f1 then
  978. f2
  979. else
  980. let f1' =
  981. try OASISString.strip_ends_with ~what:"/" f1 with Not_found -> f1
  982. in
  983. f1'^"/"^f2
  984. let make =
  985. function
  986. | hd :: tl ->
  987. List.fold_left
  988. (fun f p -> concat f p)
  989. hd
  990. tl
  991. | [] ->
  992. invalid_arg "OASISUnixPath.make"
  993. let dirname f =
  994. try
  995. String.sub f 0 (String.rindex f '/')
  996. with Not_found ->
  997. current_dir_name
  998. let basename f =
  999. try
  1000. let pos_start =
  1001. (String.rindex f '/') + 1
  1002. in
  1003. String.sub f pos_start ((String.length f) - pos_start)
  1004. with Not_found ->
  1005. f
  1006. let chop_extension f =
  1007. try
  1008. let last_dot =
  1009. String.rindex f '.'
  1010. in
  1011. let sub =
  1012. String.sub f 0 last_dot
  1013. in
  1014. try
  1015. let last_slash =
  1016. String.rindex f '/'
  1017. in
  1018. if last_slash < last_dot then
  1019. sub
  1020. else
  1021. f
  1022. with Not_found ->
  1023. sub
  1024. with Not_found ->
  1025. f
  1026. let capitalize_file f =
  1027. let dir = dirname f in
  1028. let base = basename f in
  1029. concat dir (String.capitalize base)
  1030. let uncapitalize_file f =
  1031. let dir = dirname f in
  1032. let base = basename f in
  1033. concat dir (String.uncapitalize base)
  1034. end
  1035. module OASISHostPath = struct
  1036. (* # 21 "/Users/avsm/.opam/system/build/oasis.0.3.0/src/oasis/OASISHostPath.ml" *)
  1037. open Filename
  1038. module Unix = OASISUnixPath
  1039. let make =
  1040. function
  1041. | [] ->
  1042. invalid_arg "OASISHostPath.make"
  1043. | hd :: tl ->
  1044. List.fold_left Filename.concat hd tl
  1045. let of_unix ufn =
  1046. if Sys.os_type = "Unix" then
  1047. ufn
  1048. else
  1049. make
  1050. (List.map
  1051. (fun p ->
  1052. if p = Unix.current_dir_name then
  1053. current_dir_name
  1054. else if p = Unix.parent_dir_name then
  1055. parent_dir_name
  1056. else
  1057. p)
  1058. (OASISString.nsplit ufn '/'))
  1059. end
  1060. module OASISSection = struct
  1061. (* # 21 "/Users/avsm/.opam/system/build/oasis.0.3.0/src/oasis/OASISSection.ml" *)
  1062. open OASISTypes
  1063. let section_kind_common =
  1064. function
  1065. | Library (cs, _, _) ->
  1066. `Library, cs
  1067. | Executable (cs, _, _) ->
  1068. `Executable, cs
  1069. | Flag (cs, _) ->
  1070. `Flag, cs
  1071. | SrcRepo (cs, _) ->
  1072. `SrcRepo, cs
  1073. | Test (cs, _) ->
  1074. `Test, cs
  1075. | Doc (cs, _) ->
  1076. `Doc, cs
  1077. let section_common sct =
  1078. snd (section_kind_common sct)
  1079. let section_common_set cs =
  1080. function
  1081. | Library (_, bs, lib) -> Library (cs, bs, lib)
  1082. | Executable (_, bs, exec) -> Executable (cs, bs, exec)
  1083. | Flag (_, flg) -> Flag (cs, flg)
  1084. | SrcRepo (_, src_repo) -> SrcRepo (cs, src_repo)
  1085. | Test (_, tst) -> Test (cs, tst)
  1086. | Doc (_, doc) -> Doc (cs, doc)
  1087. (** Key used to identify section
  1088. *)
  1089. let section_id sct =
  1090. let k, cs =
  1091. section_kind_common sct
  1092. in
  1093. k, cs.cs_name
  1094. let string_of_section sct =
  1095. let k, nm =
  1096. section_id sct
  1097. in
  1098. (match k with
  1099. | `Library -> "library"
  1100. | `Executable -> "executable"
  1101. | `Flag -> "flag"
  1102. | `SrcRepo -> "src repository"
  1103. | `Test -> "test"
  1104. | `Doc -> "doc")
  1105. ^" "^nm
  1106. let section_find id scts =
  1107. List.find
  1108. (fun sct -> id = section_id sct)
  1109. scts
  1110. module CSection =
  1111. struct
  1112. type t = section
  1113. let id = section_id
  1114. let compare t1 t2 =
  1115. compare (id t1) (id t2)
  1116. let equal t1 t2 =
  1117. (id t1) = (id t2)
  1118. let hash t =
  1119. Hashtbl.hash (id t)
  1120. end
  1121. module MapSection = Map.Make(CSection)
  1122. module SetSection = Set.Make(CSection)
  1123. end
  1124. module OASISBuildSection = struct
  1125. (* # 21 "/Users/avsm/.opam/system/build/oasis.0.3.0/src/oasis/OASISBuildSection.ml" *)
  1126. end
  1127. module OASISExecutable = struct
  1128. (* # 21 "/Users/avsm/.opam/system/build/oasis.0.3.0/src/oasis/OASISExecutable.ml" *)
  1129. open OASISTypes
  1130. let unix_exec_is (cs, bs, exec) is_native ext_dll suffix_program =
  1131. let dir =
  1132. OASISUnixPath.concat
  1133. bs.bs_path
  1134. (OASISUnixPath.dirname exec.exec_main_is)
  1135. in
  1136. let is_native_exec =
  1137. match bs.bs_compiled_object with
  1138. | Native -> true
  1139. | Best -> is_native ()
  1140. | Byte -> false
  1141. in
  1142. OASISUnixPath.concat
  1143. dir
  1144. (cs.cs_name^(suffix_program ())),
  1145. if not is_native_exec &&
  1146. not exec.exec_custom &&
  1147. bs.bs_c_sources <> [] then
  1148. Some (dir^"/dll"^cs.cs_name^"_stubs"^(ext_dll ()))
  1149. else
  1150. None
  1151. end
  1152. module OASISLibrary = struct
  1153. (* # 21 "/Users/avsm/.opam/system/build/oasis.0.3.0/src/oasis/OASISLibrary.ml" *)
  1154. open OASISTypes
  1155. open OASISUtils
  1156. open OASISGettext
  1157. open OASISSection
  1158. type library_name = name
  1159. type findlib_part_name = name
  1160. type 'a map_of_findlib_part_name = 'a OASISUtils.MapString.t
  1161. exception InternalLibraryNotFound of library_name
  1162. exception FindlibPackageNotFound of findlib_name
  1163. type group_t =
  1164. | Container of findlib_name * group_t list
  1165. | Package of (findlib_name *
  1166. common_section *
  1167. build_section *
  1168. library *
  1169. group_t list)
  1170. (* Look for a module file, considering capitalization or not. *)
  1171. let find_module source_file_exists (cs, bs, lib) modul =
  1172. let possible_base_fn =
  1173. List.map
  1174. (OASISUnixPath.concat bs.bs_path)
  1175. [modul;
  1176. OASISUnixPath.uncapitalize_file modul;
  1177. OASISUnixPath.capitalize_file modul]
  1178. in
  1179. (* TODO: we should be able to be able to determine the source for every
  1180. * files. Hence we should introduce a Module(source: fn) for the fields
  1181. * Modules and InternalModules
  1182. *)
  1183. List.fold_left
  1184. (fun acc base_fn ->
  1185. match acc with
  1186. | `No_sources _ ->
  1187. begin
  1188. let file_found =
  1189. List.fold_left
  1190. (fun acc ext ->
  1191. if source_file_exists (base_fn^ext) then
  1192. (base_fn^ext) :: acc
  1193. else
  1194. acc)
  1195. []
  1196. [".ml"; ".mli"; ".mll"; ".mly"]
  1197. in
  1198. match file_found with
  1199. | [] ->
  1200. acc
  1201. | lst ->
  1202. `Sources (base_fn, lst)
  1203. end
  1204. | `Sources _ ->
  1205. acc)
  1206. (`No_sources possible_base_fn)
  1207. possible_base_fn
  1208. let source_unix_files ~ctxt (cs, bs, lib) source_file_exists =
  1209. List.fold_left
  1210. (fun acc modul ->
  1211. match find_module source_file_exists (cs, bs, lib) modul with
  1212. | `Sources (base_fn, lst) ->
  1213. (base_fn, lst) :: acc
  1214. | `No_sources _ ->
  1215. OASISMessage.warning
  1216. ~ctxt
  1217. (f_ "Cannot find source file matching \
  1218. module '%s' in library %s")
  1219. modul cs.cs_name;
  1220. acc)
  1221. []
  1222. (lib.lib_modules @ lib.lib_internal_modules)
  1223. let generated_unix_files
  1224. ~ctxt
  1225. ~is_native
  1226. ~has_native_dynlink
  1227. ~ext_lib
  1228. ~ext_dll
  1229. ~source_file_exists
  1230. (cs, bs, lib) =
  1231. let find_modules lst ext =
  1232. let find_module modul =
  1233. match find_module source_file_exists (cs, bs, lib) modul with
  1234. | `Sources (base_fn, _) ->
  1235. [base_fn]
  1236. | `No_sources lst ->
  1237. OASISMessage.warning
  1238. ~ctxt
  1239. (f_ "Cannot find source file matching \
  1240. module '%s' in library %s")
  1241. modul cs.cs_name;
  1242. lst
  1243. in
  1244. List.map
  1245. (fun nm ->
  1246. List.map
  1247. (fun base_fn -> base_fn ^"."^ext)
  1248. (find_module nm))
  1249. lst
  1250. in
  1251. (* The headers that should be compiled along *)
  1252. let headers =
  1253. if lib.lib_pack then
  1254. []
  1255. else
  1256. find_modules
  1257. lib.lib_modules
  1258. "cmi"
  1259. in
  1260. (* The .cmx that be compiled along *)
  1261. let cmxs =
  1262. let should_be_built =
  1263. (not lib.lib_pack) && (* Do not install .cmx packed submodules *)
  1264. match bs.bs_compiled_object with
  1265. | Native -> true
  1266. | Best -> is_native
  1267. | Byte -> false
  1268. in
  1269. if should_be_built then
  1270. find_modules
  1271. (lib.lib_modules @ lib.lib_internal_modules)
  1272. "cmx"
  1273. else
  1274. []
  1275. in
  1276. let acc_nopath =
  1277. []
  1278. in
  1279. (* Compute what libraries should be built *)
  1280. let acc_nopath =
  1281. (* Add the packed header file if required *)
  1282. let add_pack_header acc =
  1283. if lib.lib_pack then
  1284. [cs.cs_name^".cmi"] :: acc
  1285. else
  1286. acc
  1287. in
  1288. let byte acc =
  1289. add_pack_header ([cs.cs_name^".cma"] :: acc)
  1290. in
  1291. let native acc =
  1292. let acc =
  1293. add_pack_header
  1294. (if has_native_dynlink then
  1295. [cs.cs_name^".cmxs"] :: acc
  1296. else acc)
  1297. in
  1298. [cs.cs_name^".cmxa"] :: [cs.cs_name^ext_lib] :: acc
  1299. in
  1300. match bs.bs_compiled_object with
  1301. | Native ->
  1302. byte (native acc_nopath)
  1303. | Best when is_native ->
  1304. byte (native acc_nopath)
  1305. | Byte | Best ->
  1306. byte acc_nopath
  1307. in
  1308. (* Add C library to be built *)
  1309. let acc_nopath =
  1310. if bs.bs_c_sources <> [] then
  1311. begin
  1312. ["lib"^cs.cs_name^"_stubs"^ext_lib]
  1313. ::
  1314. ["dll"^cs.cs_name^"_stubs"^ext_dll]
  1315. ::
  1316. acc_nopath
  1317. end
  1318. else
  1319. acc_nopath
  1320. in
  1321. (* All the files generated *)
  1322. List.rev_append
  1323. (List.rev_map
  1324. (List.rev_map
  1325. (OASISUnixPath.concat bs.bs_path))
  1326. acc_nopath)
  1327. (headers @ cmxs)
  1328. type data = common_section * build_section * library
  1329. type tree =
  1330. | Node of (data option) * (tree MapString.t)
  1331. | Leaf of data
  1332. let findlib_mapping pkg =
  1333. (* Map from library name to either full findlib name or parts + parent. *)
  1334. let fndlb_parts_of_lib_name =
  1335. let fndlb_parts cs lib =
  1336. let name =
  1337. match lib.lib_findlib_name with
  1338. | Some nm -> nm
  1339. | None -> cs.cs_name
  1340. in
  1341. let name =
  1342. String.concat "." (lib.lib_findlib_containers @ [name])
  1343. in
  1344. name
  1345. in
  1346. List.fold_left
  1347. (fun mp ->
  1348. function
  1349. | Library (cs, _, lib) ->
  1350. begin
  1351. let lib_name = cs.cs_name in
  1352. let fndlb_parts = fndlb_parts cs lib in
  1353. if MapString.mem lib_name mp then
  1354. failwithf
  1355. (f_ "The library name '%s' is used more than once.")
  1356. lib_name;
  1357. match lib.lib_findlib_parent with
  1358. | Some lib_name_parent ->
  1359. MapString.add
  1360. lib_name
  1361. (`Unsolved (lib_name_parent, fndlb_parts))
  1362. mp
  1363. | None ->
  1364. MapString.add
  1365. lib_name
  1366. (`Solved fndlb_parts)
  1367. mp
  1368. end
  1369. | Executable _ | Test _ | Flag _ | SrcRepo _ | Doc _ ->
  1370. mp)
  1371. MapString.empty
  1372. pkg.sections
  1373. in
  1374. (* Solve the above graph to be only library name to full findlib name. *)
  1375. let fndlb_name_of_lib_name =
  1376. let rec solve visited mp lib_name lib_name_child =
  1377. if SetString.mem lib_name visited then
  1378. failwithf
  1379. (f_ "Library '%s' is involved in a cycle \
  1380. with regard to findlib naming.")
  1381. lib_name;
  1382. let visited = SetString.add lib_name visited in
  1383. try
  1384. match MapString.find lib_name mp with
  1385. | `Solved fndlb_nm ->
  1386. fndlb_nm, mp
  1387. | `Unsolved (lib_nm_parent, post_fndlb_nm) ->
  1388. let pre_fndlb_nm, mp =
  1389. solve visited mp lib_nm_parent lib_name
  1390. in
  1391. let fndlb_nm = pre_fndlb_nm^"."^post_fndlb_nm in
  1392. fndlb_nm, MapString.add lib_name (`Solved fndlb_nm) mp
  1393. with Not_found ->
  1394. failwithf
  1395. (f_ "Library '%s', which is defined as the findlib parent of \
  1396. library '%s', doesn't exist.")
  1397. lib_name lib_name_child
  1398. in
  1399. let mp =
  1400. MapString.fold
  1401. (fun lib_name status mp ->
  1402. match status with
  1403. | `Solved _ ->
  1404. (* Solved initialy, no need to go further *)
  1405. mp
  1406. | `Unsolved _ ->
  1407. let _, mp = solve SetString.empty mp lib_name "<none>" in
  1408. mp)
  1409. fndlb_parts_of_lib_name
  1410. fndlb_parts_of_lib_name
  1411. in
  1412. MapString.map
  1413. (function
  1414. | `Solved fndlb_nm -> fndlb_nm
  1415. | `Unsolved _ -> assert false)
  1416. mp
  1417. in
  1418. (* Convert an internal library name to a findlib name. *)
  1419. let findlib_name_of_library_name lib_nm =
  1420. try
  1421. MapString.find lib_nm fndlb_name_of_lib_name
  1422. with Not_found ->
  1423. raise (InternalLibraryNotFound lib_nm)
  1424. in
  1425. (* Add a library to the tree.
  1426. *)
  1427. let add sct mp =
  1428. let fndlb_fullname =
  1429. let cs, _, _ = sct in
  1430. let lib_name = cs.cs_name in
  1431. findlib_name_of_library_name lib_name
  1432. in
  1433. let rec add_children nm_lst (children : tree MapString.t) =
  1434. match nm_lst with
  1435. | (hd :: tl) ->
  1436. begin
  1437. let node =
  1438. try
  1439. add_node tl (MapString.find hd children)
  1440. with Not_found ->
  1441. (* New node *)
  1442. new_node tl
  1443. in
  1444. MapString.add hd node children
  1445. end
  1446. | [] ->
  1447. (* Should not have a nameless library. *)
  1448. assert false
  1449. and add_node tl node =
  1450. if tl = [] then
  1451. begin
  1452. match node with
  1453. | Node (None, children) ->
  1454. Node (Some sct, children)
  1455. | Leaf (cs', _, _) | Node (Some (cs', _, _), _) ->
  1456. (* TODO: allow to merge Package, i.e.
  1457. * archive(byte) = "foo.cma foo_init.cmo"
  1458. *)
  1459. let cs, _, _ = sct in
  1460. failwithf
  1461. (f_ "Library '%s' and '%s' have the same findlib name '%s'")
  1462. cs.cs_name cs'.cs_name fndlb_fullname
  1463. end
  1464. else
  1465. begin
  1466. match node with
  1467. | Leaf data ->
  1468. Node (Some data, add_children tl MapString.empty)
  1469. | Node (data_opt, children) ->
  1470. Node (data_opt, add_children tl children)
  1471. end
  1472. and new_node =
  1473. function
  1474. | [] ->
  1475. Leaf sct
  1476. | hd :: tl ->
  1477. Node (None, MapString.add hd (new_node tl) MapString.empty)
  1478. in
  1479. add_children (OASISString.nsplit fndlb_fullname '.') mp
  1480. in
  1481. let rec group_of_tree mp =
  1482. MapString.fold
  1483. (fun nm node acc ->
  1484. let cur =
  1485. match node with
  1486. | Node (Some (cs, bs, lib), children) ->
  1487. Package (nm, cs, bs, lib, group_of_tree children)
  1488. | Node (None, children) ->
  1489. Container (nm, group_of_tree children)
  1490. | Leaf (cs, bs, lib) ->
  1491. Package (nm, cs, bs, lib, [])
  1492. in
  1493. cur :: acc)
  1494. mp []
  1495. in
  1496. let group_mp =
  1497. List.fold_left
  1498. (fun mp ->
  1499. function
  1500. | Library (cs, bs, lib) ->
  1501. add (cs, bs, lib) mp
  1502. | _ ->
  1503. mp)
  1504. MapString.empty
  1505. pkg.sections
  1506. in
  1507. let groups =
  1508. group_of_tree group_mp
  1509. in
  1510. let library_name_of_findlib_name =
  1511. Lazy.lazy_from_fun
  1512. (fun () ->
  1513. (* Revert findlib_name_of_library_name. *)
  1514. MapString.fold
  1515. (fun k v mp -> MapString.add v k mp)
  1516. fndlb_name_of_lib_name
  1517. MapString.empty)
  1518. in
  1519. let library_name_of_findlib_name fndlb_nm =
  1520. try
  1521. MapString.find fndlb_nm (Lazy.force library_name_of_findlib_name)
  1522. with Not_found ->
  1523. raise (FindlibPackageNotFound fndlb_nm)
  1524. in
  1525. groups,
  1526. findlib_name_of_library_name,
  1527. library_name_of_findlib_name
  1528. let findlib_of_group =
  1529. function
  1530. | Container (fndlb_nm, _)
  1531. | Package (fndlb_nm, _, _, _, _) -> fndlb_nm
  1532. let root_of_group grp =
  1533. let rec root_lib_aux =
  1534. (* We do a DFS in the group. *)
  1535. function
  1536. | Container (_, children) ->
  1537. List.fold_left
  1538. (fun res grp ->
  1539. if res = None then
  1540. root_lib_aux grp
  1541. else
  1542. res)
  1543. None
  1544. children
  1545. | Package (_, cs, bs, lib, _) ->
  1546. Some (cs, bs, lib)
  1547. in
  1548. match root_lib_aux grp with
  1549. | Some res ->
  1550. res
  1551. | None ->
  1552. failwithf
  1553. (f_ "Unable to determine root library of findlib library '%s'")
  1554. (findlib_of_group grp)
  1555. end
  1556. module OASISFlag = struct
  1557. (* # 21 "/Users/avsm/.opam/system/build/oasis.0.3.0/src/oasis/OASISFlag.ml" *)
  1558. end
  1559. module OASISPackage = struct
  1560. (* # 21 "/Users/avsm/.opam/system/build/oasis.0.3.0/src/oasis/OASISPackage.ml" *)
  1561. end
  1562. module OASISSourceRepository = struct
  1563. (* # 21 "/Users/avsm/.opam/system/build/oasis.0.3.0/src/oasis/OASISSourceRepository.ml" *)
  1564. end
  1565. module OASISTest = struct
  1566. (* # 21 "/Users/avsm/.opam/system/build/oasis.0.3.0/src/oasis/OASISTest.ml" *)
  1567. end
  1568. module OASISDocument = struct
  1569. (* # 21 "/Users/avsm/.opam/system/build/oasis.0.3.0/src/oasis/OASISDocument.ml" *)
  1570. end
  1571. module OASISExec = struct
  1572. (* # 21 "/Users/avsm/.opam/system/build/oasis.0.3.0/src/oasis/OASISExec.ml" *)
  1573. open OASISGettext
  1574. open OASISUtils
  1575. open OASISMessage
  1576. (* TODO: I don't like this quote, it is there because $(rm) foo expands to
  1577. * 'rm -f' foo...
  1578. *)
  1579. let run ~ctxt ?f_exit_code ?(quote=true) cmd args =
  1580. let cmd =
  1581. if quote then
  1582. if Sys.os_type = "Win32" then
  1583. if String.contains cmd ' ' then
  1584. (* Double the 1st double quote... win32... sigh *)
  1585. "\""^(Filename.quote cmd)
  1586. else
  1587. cmd
  1588. else
  1589. Filename.quote cmd
  1590. else
  1591. cmd
  1592. in
  1593. let cmdline =
  1594. String.concat " " (cmd :: args)
  1595. in
  1596. info ~ctxt (f_ "Running command '%s'") cmdline;
  1597. match f_exit_code, Sys.command cmdline with
  1598. | None, 0 -> ()
  1599. | None, i ->
  1600. failwithf
  1601. (f_ "Command '%s' terminated with error code %d")
  1602. cmdline i
  1603. | Some f, i ->
  1604. f i
  1605. let run_read_output ~ctxt ?f_exit_code cmd args =
  1606. let fn =
  1607. Filename.temp_file "oasis-" ".txt"
  1608. in
  1609. try
  1610. begin
  1611. let () =
  1612. run ~ctxt ?f_exit_code cmd (args @ [">"; Filename.quote fn])
  1613. in
  1614. let chn =
  1615. open_in fn
  1616. in
  1617. let routput =
  1618. ref []
  1619. in
  1620. begin
  1621. try
  1622. while true do
  1623. routput := (input_line chn) :: !routput
  1624. done
  1625. with End_of_file ->
  1626. ()
  1627. end;
  1628. close_in chn;
  1629. Sys.remove fn;
  1630. List.rev !routput
  1631. end
  1632. with e ->
  1633. (try Sys.remove fn with _ -> ());
  1634. raise e
  1635. let run_read_one_line ~ctxt ?f_exit_code cmd args =
  1636. match run_read_output ~ctxt ?f_exit_code cmd args with
  1637. | [fst] ->
  1638. fst
  1639. | lst ->
  1640. failwithf
  1641. (f_ "Command return unexpected output %S")
  1642. (String.concat "\n" lst)
  1643. end
  1644. module OASISFileUtil = struct
  1645. (* # 21 "/Users/avsm/.opam/system/build/oasis.0.3.0/src/oasis/OASISFileUtil.ml" *)
  1646. open OASISGettext
  1647. let file_exists_case fn =
  1648. let dirname = Filename.dirname fn in
  1649. let basename = Filename.basename fn in
  1650. if Sys.file_exists dirname then
  1651. if basename = Filename.current_dir_name then
  1652. true
  1653. else
  1654. List.mem
  1655. basename
  1656. (Array.to_list (Sys.readdir dirname))
  1657. else
  1658. false
  1659. let find_file ?(case_sensitive=true) paths exts =
  1660. (* Cardinal product of two list *)
  1661. let ( * ) lst1 lst2 =
  1662. List.flatten
  1663. (List.map
  1664. (fun a ->
  1665. List.map
  1666. (fun b -> a,b)
  1667. lst2)
  1668. lst1)
  1669. in
  1670. let rec combined_paths lst =
  1671. match lst with
  1672. | p1 :: p2 :: tl ->
  1673. let acc =
  1674. (List.map
  1675. (fun (a,b) -> Filename.concat a b)
  1676. (p1 * p2))
  1677. in
  1678. combined_paths (acc :: tl)
  1679. | [e] ->
  1680. e
  1681. | [] ->
  1682. []
  1683. in
  1684. let alternatives =
  1685. List.map
  1686. (fun (p,e) ->
  1687. if String.length e > 0 && e.[0] <> '.' then
  1688. p ^ "." ^ e
  1689. else
  1690. p ^ e)
  1691. ((combined_paths paths) * exts)
  1692. in
  1693. List.find
  1694. (if case_sensitive then
  1695. file_exists_case
  1696. else
  1697. Sys.file_exists)
  1698. alternatives
  1699. let which ~ctxt prg =
  1700. let path_sep =
  1701. match Sys.os_type with
  1702. | "Win32" ->
  1703. ';'
  1704. | _ ->
  1705. ':'
  1706. in
  1707. let path_lst = OASISString.nsplit (Sys.getenv "PATH") path_sep in
  1708. let exec_ext =
  1709. match Sys.os_type with
  1710. | "Win32" ->
  1711. "" :: (OASISString.nsplit (Sys.getenv "PATHEXT") path_sep)
  1712. | _ ->
  1713. [""]
  1714. in
  1715. find_file ~case_sensitive:false [path_lst; [prg]] exec_ext
  1716. (**/**)
  1717. let rec fix_dir dn =
  1718. (* Windows hack because Sys.file_exists "src\\" = false when
  1719. * Sys.file_exists "src" = true
  1720. *)
  1721. let ln =
  1722. String.length dn
  1723. in
  1724. if Sys.os_type = "Win32" && ln > 0 && dn.[ln - 1] = '\\' then
  1725. fix_dir (String.sub dn 0 (ln - 1))
  1726. else
  1727. dn
  1728. let q = Filename.quote
  1729. (**/**)
  1730. let cp ~ctxt ?(recurse=false) src tgt =
  1731. if recurse then
  1732. match Sys.os_type with
  1733. | "Win32" ->
  1734. OASISExec.run ~ctxt
  1735. "xcopy" [q src; q tgt; "/E"]
  1736. | _ ->
  1737. OASISExec.run ~ctxt
  1738. "cp" ["-r"; q src; q tgt]
  1739. else
  1740. OASISExec.run ~ctxt
  1741. (match Sys.os_type with
  1742. | "Win32" -> "copy"
  1743. | _ -> "cp")
  1744. [q src; q tgt]
  1745. let mkdir ~ctxt tgt =
  1746. OASISExec.run ~ctxt
  1747. (match Sys.os_type with
  1748. | "Win32" -> "md"
  1749. | _ -> "mkdir")
  1750. [q tgt]
  1751. let rec mkdir_parent ~ctxt f tgt =
  1752. let tgt =
  1753. fix_dir tgt
  1754. in
  1755. if Sys.file_exists tgt then
  1756. begin
  1757. if not (Sys.is_directory tgt) then
  1758. OASISUtils.failwithf
  1759. (f_ "Cannot create directory '%s', a file of the same name already \
  1760. exists")
  1761. tgt
  1762. end
  1763. else
  1764. begin
  1765. mkdir_parent ~ctxt f (Filename.dirname tgt);
  1766. if not (Sys.file_exists tgt) then
  1767. begin
  1768. f tgt;
  1769. mkdir ~ctxt tgt
  1770. end
  1771. end
  1772. let rmdir ~ctxt tgt =
  1773. if Sys.readdir tgt = [||] then
  1774. begin
  1775. match Sys.os_type with
  1776. | "Win32" ->
  1777. OASISExec.run ~ctxt "rd" [q tgt]
  1778. | _ ->
  1779. OASISExec.run ~ctxt "rm" ["-r"; q tgt]
  1780. end
  1781. let glob ~ctxt fn =
  1782. let basename =
  1783. Filename.basename fn
  1784. in
  1785. if String.length basename >= 2 &&
  1786. basename.[0] = '*' &&
  1787. basename.[1] = '.' then
  1788. begin
  1789. let ext_len =
  1790. (String.length basename) - 2
  1791. in
  1792. let ext =
  1793. String.sub basename 2 ext_len
  1794. in
  1795. let dirname =
  1796. Filename.dirname fn
  1797. in
  1798. Array.fold_left
  1799. (fun acc fn ->
  1800. try
  1801. let fn_ext =
  1802. String.sub
  1803. fn
  1804. ((String.length fn) - ext_len)
  1805. ext_len
  1806. in
  1807. if fn_ext = ext then
  1808. (Filename.concat dirname fn) :: acc
  1809. else
  1810. acc
  1811. with Invalid_argument _ ->
  1812. acc)
  1813. []
  1814. (Sys.readdir dirname)
  1815. end
  1816. else
  1817. begin
  1818. if file_exists_case fn then
  1819. [fn]
  1820. else
  1821. []
  1822. end
  1823. end
  1824. # 2142 "setup.ml"
  1825. module BaseEnvLight = struct
  1826. (* # 21 "/Users/avsm/.opam/system/build/oasis.0.3.0/src/base/BaseEnvLight.ml" *)
  1827. module MapString = Map.Make(String)
  1828. type t = string MapString.t
  1829. let default_filename =
  1830. Filename.concat
  1831. (Sys.getcwd ())
  1832. "setup.data"
  1833. let load ?(allow_empty=false) ?(filename=default_filename) () =
  1834. if Sys.file_exists filename then
  1835. begin
  1836. let chn =
  1837. open_in_bin filename
  1838. in
  1839. let st =
  1840. Stream.of_channel chn
  1841. in
  1842. let line =
  1843. ref 1
  1844. in
  1845. let st_line =
  1846. Stream.from
  1847. (fun _ ->
  1848. try
  1849. match Stream.next st with
  1850. | '\n' -> incr line; Some '\n'
  1851. | c -> Some c
  1852. with Stream.Failure -> None)
  1853. in
  1854. let lexer =
  1855. Genlex.make_lexer ["="] st_line
  1856. in
  1857. let rec read_file mp =
  1858. match Stream.npeek 3 lexer with
  1859. | [Genlex.Ident nm; Genlex.Kwd "="; Genlex.String value] ->
  1860. Stream.junk lexer;
  1861. Stream.junk lexer;
  1862. Stream.junk lexer;
  1863. read_file (MapString.add nm value mp)
  1864. | [] ->
  1865. mp
  1866. | _ ->
  1867. failwith
  1868. (Printf.sprintf
  1869. "Malformed data file '%s' line %d"
  1870. filename !line)
  1871. in
  1872. let mp =
  1873. read_file MapString.empty
  1874. in
  1875. close_in chn;
  1876. mp
  1877. end
  1878. else if allow_empty then
  1879. begin
  1880. MapString.empty
  1881. end
  1882. else
  1883. begin
  1884. failwith
  1885. (Printf.sprintf
  1886. "Unable to load environment, the file '%s' doesn't exist."
  1887. filename)
  1888. end
  1889. let var_get name env =
  1890. let rec var_expand str =
  1891. let buff =
  1892. Buffer.create ((String.length str) * 2)
  1893. in
  1894. Buffer.add_substitute
  1895. buff
  1896. (fun var ->
  1897. try
  1898. var_expand (MapString.find var env)
  1899. with Not_found ->
  1900. failwith
  1901. (Printf.sprintf
  1902. "No variable %s defined when trying to expand %S."
  1903. var
  1904. str))
  1905. str;
  1906. Buffer.contents buff
  1907. in
  1908. var_expand (MapString.find name env)
  1909. let var_choose lst env =
  1910. OASISExpr.choose
  1911. (fun nm -> var_get nm env)
  1912. lst
  1913. end
  1914. # 2240 "setup.ml"
  1915. module BaseContext = struct
  1916. (* # 21 "/Users/avsm/.opam/system/build/oasis.0.3.0/src/base/BaseContext.ml" *)
  1917. open OASISContext
  1918. let args = args
  1919. let default = default
  1920. end
  1921. module BaseMessage = struct
  1922. (* # 21 "/Users/avsm/.opam/system/build/oasis.0.3.0/src/base/BaseMessage.ml" *)
  1923. (** Message to user, overrid for Base
  1924. @author Sylvain Le Gall
  1925. *)
  1926. open OASISMessage
  1927. open BaseContext
  1928. let debug fmt = debug ~ctxt:!default fmt
  1929. let info fmt = info ~ctxt:!default fmt
  1930. let warning fmt = warning ~ctxt:!default fmt
  1931. let error fmt = error ~ctxt:!default fmt
  1932. end
  1933. module BaseEnv = struct
  1934. (* # 21 "/Users/avsm/.opam/system/build/oasis.0.3.0/src/base/BaseEnv.ml" *)
  1935. open OASISGettext
  1936. open OASISUtils
  1937. open PropList
  1938. module MapString = BaseEnvLight.MapString
  1939. type origin_t =
  1940. | ODefault
  1941. | OGetEnv
  1942. | OFileLoad
  1943. | OCommandLine
  1944. type cli_handle_t =
  1945. | CLINone
  1946. | CLIAuto
  1947. | CLIWith
  1948. | CLIEnable
  1949. | CLIUser of (Arg.key * Arg.spec * Arg.doc) list
  1950. type definition_t =
  1951. {
  1952. hide: bool;
  1953. dump: bool;
  1954. cli: cli_handle_t;
  1955. arg_help: string option;
  1956. group: string option;
  1957. }
  1958. let schema =
  1959. Schema.create "environment"
  1960. (* Environment data *)
  1961. let env =
  1962. Data.create ()
  1963. (* Environment data from file *)
  1964. let env_from_file =
  1965. ref MapString.empty
  1966. (* Lexer for var *)
  1967. let var_lxr =
  1968. Genlex.make_lexer []
  1969. let rec var_expand str =
  1970. let buff =
  1971. Buffer.create ((String.length str) * 2)
  1972. in
  1973. Buffer.add_substitute
  1974. buff
  1975. (fun var ->
  1976. try
  1977. (* TODO: this is a quick hack to allow calling Test.Command
  1978. * without defining executable name really. I.e. if there is
  1979. * an exec Executable toto, then $(toto) should be replace
  1980. * by its real name. It is however useful to have this function
  1981. * for other variable that depend on the host and should be
  1982. * written better than that.
  1983. *)
  1984. let st =
  1985. var_lxr (Stream.of_string var)
  1986. in
  1987. match Stream.npeek 3 st with
  1988. | [Genlex.Ident "utoh"; Genlex.Ident nm] ->
  1989. OASISHostPath.of_unix (var_get nm)
  1990. | [Genlex.Ident "utoh"; Genlex.String s] ->
  1991. OASISHostPath.of_unix s
  1992. | [Genlex.Ident "ocaml_escaped"; Genlex.Ident nm] ->
  1993. String.escaped (var_get nm)
  1994. | [Genlex.Ident "ocaml_escaped"; Genlex.String s] ->
  1995. String.escaped s
  1996. | [Genlex.Ident nm] ->
  1997. var_get nm
  1998. | _ ->
  1999. failwithf
  2000. (f_ "Unknown expression '%s' in variable expansion of %s.")
  2001. var
  2002. str
  2003. with
  2004. | Unknown_field (_, _) ->
  2005. failwithf
  2006. (f_ "No variable %s defined when trying to expand %S.")
  2007. var
  2008. str
  2009. | Stream.Error e ->
  2010. failwithf
  2011. (f_ "Syntax error when parsing '%s' when trying to \
  2012. expand %S: %s")
  2013. var
  2014. str
  2015. e)
  2016. str;
  2017. Buffer.contents buff
  2018. and var_get name =
  2019. let vl =
  2020. try
  2021. Schema.get schema env name
  2022. with Unknown_field _ as e ->
  2023. begin
  2024. try
  2025. MapString.find name !env_from_file
  2026. with Not_found ->
  2027. raise e
  2028. end
  2029. in
  2030. var_expand vl
  2031. let var_choose ?printer ?name lst =
  2032. OASISExpr.choose
  2033. ?printer
  2034. ?name
  2035. var_get
  2036. lst
  2037. let var_protect vl =
  2038. let buff =
  2039. Buffer.create (String.length vl)
  2040. in
  2041. String.iter
  2042. (function
  2043. | '$' -> Buffer.add_string buff "\\$"
  2044. | c -> Buffer.add_char buff c)
  2045. vl;
  2046. Buffer.contents buff
  2047. let var_define
  2048. ?(hide=false)
  2049. ?(dump=true)
  2050. ?short_desc
  2051. ?(cli=CLINone)
  2052. ?arg_help
  2053. ?group
  2054. name (* TODO: type constraint on the fact that name must be a valid OCaml
  2055. id *)
  2056. dflt =
  2057. let default =
  2058. [
  2059. OFileLoad, (fun () -> MapString.find name !env_from_file);
  2060. ODefault, dflt;
  2061. OGetEnv, (fun () -> Sys.getenv name);
  2062. ]
  2063. in
  2064. let extra =
  2065. {
  2066. hide = hide;
  2067. dump = dump;
  2068. cli = cli;
  2069. arg_help = arg_help;
  2070. group = group;
  2071. }
  2072. in
  2073. (* Try to find a value that can be defined
  2074. *)
  2075. let var_get_low lst =
  2076. let errors, res =
  2077. List.fold_left
  2078. (fun (errors, res) (o, v) ->
  2079. if res = None then
  2080. begin
  2081. try
  2082. errors, Some (v ())
  2083. with
  2084. | Not_found ->
  2085. errors, res
  2086. | Failure rsn ->
  2087. (rsn :: errors), res
  2088. | e ->
  2089. (Printexc.to_string e) :: errors, res
  2090. end
  2091. else
  2092. errors, res)
  2093. ([], None)
  2094. (List.sort
  2095. (fun (o1, _) (o2, _) ->
  2096. Pervasives.compare o2 o1)
  2097. lst)
  2098. in
  2099. match res, errors with
  2100. | Some v, _ ->
  2101. v
  2102. | None, [] ->
  2103. raise (Not_set (name, None))
  2104. | None, lst ->
  2105. raise (Not_set (name, Some (String.concat (s_ ", ") lst)))
  2106. in
  2107. let help =
  2108. match short_desc with
  2109. | Some fs -> Some fs
  2110. | None -> None
  2111. in
  2112. let var_get_lst =
  2113. FieldRO.create
  2114. ~schema
  2115. ~name
  2116. ~parse:(fun ?(context=ODefault) s -> [context, fun () -> s])
  2117. ~print:var_get_low
  2118. ~default
  2119. ~update:(fun ?context x old_x -> x @ old_x)
  2120. ?help
  2121. extra
  2122. in
  2123. fun () ->
  2124. var_expand (var_get_low (var_get_lst env))
  2125. let var_redefine
  2126. ?hide
  2127. ?dump
  2128. ?short_desc
  2129. ?cli
  2130. ?arg_help
  2131. ?group
  2132. name
  2133. dflt =
  2134. if Schema.mem schema name then
  2135. begin
  2136. (* TODO: look suspsicious, we want to memorize dflt not dflt () *)
  2137. Schema.set schema env ~context:ODefault name (dflt ());
  2138. fun () -> var_get name
  2139. end
  2140. else
  2141. begin
  2142. var_define
  2143. ?hide
  2144. ?dump
  2145. ?short_desc
  2146. ?cli
  2147. ?arg_help
  2148. ?group
  2149. name
  2150. dflt
  2151. end
  2152. let var_ignore (e : unit -> string) =
  2153. ()
  2154. let print_hidden =
  2155. var_define
  2156. ~hide:true
  2157. ~dump:false
  2158. ~cli:CLIAuto
  2159. ~arg_help:"Print even non-printable variable. (debug)"
  2160. "print_hidden"
  2161. (fun () -> "false")
  2162. let var_all () =
  2163. List.rev
  2164. (Schema.fold
  2165. (fun acc nm def _ ->
  2166. if not def.hide || bool_of_string (print_hidden ()) then
  2167. nm :: acc
  2168. else
  2169. acc)
  2170. []
  2171. schema)
  2172. let default_filename =
  2173. BaseEnvLight.default_filename
  2174. let load ?allow_empty ?filename () =
  2175. env_from_file := BaseEnvLight.load ?allow_empty ?filename ()
  2176. let unload () =
  2177. env_from_file := MapString.empty;
  2178. Data.clear env
  2179. let dump ?(filename=default_filename) () =
  2180. let chn =
  2181. open_out_bin filename
  2182. in
  2183. let output nm value =
  2184. Printf.fprintf chn "%s=%S\n" nm value
  2185. in
  2186. let mp_todo =
  2187. (* Dump data from schema *)
  2188. Schema.fold
  2189. (fun mp_todo nm def _ ->
  2190. if def.dump then
  2191. begin
  2192. try
  2193. let value =
  2194. Schema.get
  2195. schema
  2196. env
  2197. nm
  2198. in
  2199. output nm value
  2200. with Not_set _ ->
  2201. ()
  2202. end;
  2203. MapString.remove nm mp_todo)
  2204. !env_from_file
  2205. schema
  2206. in
  2207. (* Dump data defined outside of schema *)
  2208. MapString.iter output mp_todo;
  2209. (* End of the dump *)
  2210. close_out chn
  2211. let print () =
  2212. let printable_vars =
  2213. Schema.fold
  2214. (fun acc nm def short_descr_opt ->
  2215. if not def.hide || bool_of_string (print_hidden ()) then
  2216. begin
  2217. try
  2218. let value =
  2219. Schema.get
  2220. schema
  2221. env
  2222. nm
  2223. in
  2224. let txt =
  2225. match short_descr_opt with
  2226. | Some s -> s ()
  2227. | None -> nm
  2228. in
  2229. (txt, value) :: acc
  2230. with Not_set _ ->
  2231. acc
  2232. end
  2233. else
  2234. acc)
  2235. []
  2236. schema
  2237. in
  2238. let max_length =
  2239. List.fold_left max 0
  2240. (List.rev_map String.length
  2241. (List.rev_map fst printable_vars))
  2242. in
  2243. let dot_pad str =
  2244. String.make ((max_length - (String.length str)) + 3) '.'
  2245. in
  2246. Printf.printf "\nConfiguration: \n";
  2247. List.iter
  2248. (fun (name,value) ->
  2249. Printf.printf "%s: %s %s\n" name (dot_pad name) value)
  2250. (List.rev printable_vars);
  2251. Printf.printf "\n%!"
  2252. let args () =
  2253. let arg_concat =
  2254. OASISUtils.varname_concat ~hyphen:'-'
  2255. in
  2256. [
  2257. "--override",
  2258. Arg.Tuple
  2259. (
  2260. let rvr = ref ""
  2261. in
  2262. let rvl = ref ""
  2263. in
  2264. [
  2265. Arg.Set_string rvr;
  2266. Arg.Set_string rvl;
  2267. Arg.Unit
  2268. (fun () ->
  2269. Schema.set
  2270. schema
  2271. env
  2272. ~context:OCommandLine
  2273. !rvr
  2274. !rvl)
  2275. ]
  2276. ),
  2277. "var+val Override any configuration variable.";
  2278. ]
  2279. @
  2280. List.flatten
  2281. (Schema.fold
  2282. (fun acc name def short_descr_opt ->
  2283. let var_set s =
  2284. Schema.set
  2285. schema
  2286. env
  2287. ~context:OCommandLine
  2288. name
  2289. s
  2290. in
  2291. let arg_name =
  2292. OASISUtils.varname_of_string ~hyphen:'-' name
  2293. in
  2294. let hlp =
  2295. match short_descr_opt with
  2296. | Some txt -> txt ()
  2297. | None -> ""
  2298. in
  2299. let arg_hlp =
  2300. match def.arg_help with
  2301. | Some s -> s
  2302. | None -> "str"
  2303. in
  2304. let default_value =
  2305. try
  2306. Printf.sprintf
  2307. (f_ " [%s]")
  2308. (Schema.get
  2309. schema
  2310. env
  2311. name)
  2312. with Not_set _ ->
  2313. ""
  2314. in
  2315. let args =
  2316. match def.cli with
  2317. | CLINone ->
  2318. []
  2319. | CLIAuto ->
  2320. [
  2321. arg_concat "--" arg_name,
  2322. Arg.String var_set,
  2323. Printf.sprintf (f_ "%s %s%s") arg_hlp hlp default_value
  2324. ]
  2325. | CLIWith ->
  2326. [
  2327. arg_concat "--with-" arg_name,
  2328. Arg.String var_set,
  2329. Printf.sprintf (f_ "%s %s%s") arg_hlp hlp default_value
  2330. ]
  2331. | CLIEnable ->
  2332. let dflt =
  2333. if default_value = " [true]" then
  2334. s_ " [default: enabled]"
  2335. else
  2336. s_ " [default: disabled]"
  2337. in
  2338. [
  2339. arg_concat "--enable-" arg_name,
  2340. Arg.Unit (fun () -> var_set "true"),
  2341. Printf.sprintf (f_ " %s%s") hlp dflt;
  2342. arg_concat "--disable-" arg_name,
  2343. Arg.Unit (fun () -> var_set "false"),
  2344. Printf.sprintf (f_ " %s%s") hlp dflt
  2345. ]
  2346. | CLIUser lst ->
  2347. lst
  2348. in
  2349. args :: acc)
  2350. []
  2351. schema)
  2352. end
  2353. module BaseArgExt = struct
  2354. (* # 21 "/Users/avsm/.opam/system/build/oasis.0.3.0/src/base/BaseArgExt.ml" *)
  2355. open OASISUtils
  2356. open OASISGettext
  2357. let parse argv args =
  2358. (* Simulate command line for Arg *)
  2359. let current =
  2360. ref 0
  2361. in
  2362. try
  2363. Arg.parse_argv
  2364. ~current:current
  2365. (Array.concat [[|"none"|]; argv])
  2366. (Arg.align args)
  2367. (failwithf (f_ "Don't know what to do with arguments: '%s'"))
  2368. (s_ "configure options:")
  2369. with
  2370. | Arg.Help txt ->
  2371. print_endline txt;
  2372. exit 0
  2373. | Arg.Bad txt ->
  2374. prerr_endline txt;
  2375. exit 1
  2376. end
  2377. module BaseCheck = struct
  2378. (* # 21 "/Users/avsm/.opam/system/build/oasis.0.3.0/src/base/BaseCheck.ml" *)
  2379. open BaseEnv
  2380. open BaseMessage
  2381. open OASISUtils
  2382. open OASISGettext
  2383. let prog_best prg prg_lst =
  2384. var_redefine
  2385. prg
  2386. (fun () ->
  2387. let alternate =
  2388. List.fold_left
  2389. (fun res e ->
  2390. match res with
  2391. | Some _ ->
  2392. res
  2393. | None ->
  2394. try
  2395. Some (OASISFileUtil.which ~ctxt:!BaseContext.default e)
  2396. with Not_found ->
  2397. None)
  2398. None
  2399. prg_lst
  2400. in
  2401. match alternate with
  2402. | Some prg -> prg
  2403. | None -> raise Not_found)
  2404. let prog prg =
  2405. prog_best prg [prg]
  2406. let prog_opt prg =
  2407. prog_best prg [prg^".opt"; prg]
  2408. let ocamlfind =
  2409. prog "ocamlfind"
  2410. let version
  2411. var_prefix
  2412. cmp
  2413. fversion
  2414. () =
  2415. (* Really compare version provided *)
  2416. let var =
  2417. var_prefix^"_version_"^(OASISVersion.varname_of_comparator cmp)
  2418. in
  2419. var_redefine
  2420. ~hide:true
  2421. var
  2422. (fun () ->
  2423. let version_str =
  2424. match fversion () with
  2425. | "[Distributed with OCaml]" ->
  2426. begin
  2427. try
  2428. (var_get "ocaml_version")
  2429. with Not_found ->
  2430. warning
  2431. (f_ "Variable ocaml_version not defined, fallback \
  2432. to default");
  2433. Sys.ocaml_version
  2434. end
  2435. | res ->
  2436. res
  2437. in
  2438. let version =
  2439. OASISVersion.version_of_string version_str
  2440. in
  2441. if OASISVersion.comparator_apply version cmp then
  2442. version_str
  2443. else
  2444. failwithf
  2445. (f_ "Cannot satisfy version constraint on %s: %s (version: %s)")
  2446. var_prefix
  2447. (OASISVersion.string_of_comparator cmp)
  2448. version_str)
  2449. ()
  2450. let package_version pkg =
  2451. OASISExec.run_read_one_line ~ctxt:!BaseContext.default
  2452. (ocamlfind ())
  2453. ["query"; "-format"; "%v"; pkg]
  2454. let package ?version_comparator pkg () =
  2455. let var =
  2456. OASISUtils.varname_concat
  2457. "pkg_"
  2458. (OASISUtils.varname_of_string pkg)
  2459. in
  2460. let findlib_dir pkg =
  2461. let dir =
  2462. OASISExec.run_read_one_line ~ctxt:!BaseContext.default
  2463. (ocamlfind ())
  2464. ["query"; "-format"; "%d"; pkg]
  2465. in
  2466. if Sys.file_exists dir && Sys.is_directory dir then
  2467. dir
  2468. else
  2469. failwithf
  2470. (f_ "When looking for findlib package %s, \
  2471. directory %s return doesn't exist")
  2472. pkg dir
  2473. in
  2474. let vl =
  2475. var_redefine
  2476. var
  2477. (fun () -> findlib_dir pkg)
  2478. ()
  2479. in
  2480. (
  2481. match version_comparator with
  2482. | Some ver_cmp ->
  2483. ignore
  2484. (version
  2485. var
  2486. ver_cmp
  2487. (fun _ -> package_version pkg)
  2488. ())
  2489. | None ->
  2490. ()
  2491. );
  2492. vl
  2493. end
  2494. module BaseOCamlcConfig = struct
  2495. (* # 21 "/Users/avsm/.opam/system/build/oasis.0.3.0/src/base/BaseOCamlcConfig.ml" *)
  2496. open BaseEnv
  2497. open OASISUtils
  2498. open OASISGettext
  2499. module SMap = Map.Make(String)
  2500. let ocamlc =
  2501. BaseCheck.prog_opt "ocamlc"
  2502. let ocamlc_config_map =
  2503. (* Map name to value for ocamlc -config output
  2504. (name ^": "^value)
  2505. *)
  2506. let rec split_field mp lst =
  2507. match lst with
  2508. | line :: tl ->
  2509. let mp =
  2510. try
  2511. let pos_semicolon =
  2512. String.index line ':'
  2513. in
  2514. if pos_semicolon > 1 then
  2515. (
  2516. let name =
  2517. String.sub line 0 pos_semicolon
  2518. in
  2519. let linelen =
  2520. String.length line
  2521. in
  2522. let value =
  2523. if linelen > pos_semicolon + 2 then
  2524. String.sub
  2525. line
  2526. (pos_semicolon + 2)
  2527. (linelen - pos_semicolon - 2)
  2528. else
  2529. ""
  2530. in
  2531. SMap.add name value mp
  2532. )
  2533. else
  2534. (
  2535. mp
  2536. )
  2537. with Not_found ->
  2538. (
  2539. mp
  2540. )
  2541. in
  2542. split_field mp tl
  2543. | [] ->
  2544. mp
  2545. in
  2546. let cache =
  2547. lazy
  2548. (var_protect
  2549. (Marshal.to_string
  2550. (split_field
  2551. SMap.empty
  2552. (OASISExec.run_read_output
  2553. ~ctxt:!BaseContext.default
  2554. (ocamlc ()) ["-config"]))
  2555. []))
  2556. in
  2557. var_redefine
  2558. "ocamlc_config_map"
  2559. ~hide:true
  2560. ~dump:false
  2561. (fun () ->
  2562. (* TODO: update if ocamlc change !!! *)
  2563. Lazy.force cache)
  2564. let var_define nm =
  2565. (* Extract data from ocamlc -config *)
  2566. let avlbl_config_get () =
  2567. Marshal.from_string
  2568. (ocamlc_config_map ())
  2569. 0
  2570. in
  2571. let chop_version_suffix s =
  2572. try
  2573. String.sub s 0 (String.index s '+')
  2574. with _ ->
  2575. s
  2576. in
  2577. let nm_config, value_config =
  2578. match nm with
  2579. | "ocaml_version" ->
  2580. "version", chop_version_suffix
  2581. | _ -> nm, (fun x -> x)
  2582. in
  2583. var_redefine
  2584. nm
  2585. (fun () ->
  2586. try
  2587. let map =
  2588. avlbl_config_get ()
  2589. in
  2590. let value =
  2591. SMap.find nm_config map
  2592. in
  2593. value_config value
  2594. with Not_found ->
  2595. failwithf
  2596. (f_ "Cannot find field '%s' in '%s -config' output")
  2597. nm
  2598. (ocamlc ()))
  2599. end
  2600. module BaseStandardVar = struct
  2601. (* # 21 "/Users/avsm/.opam/system/build/oasis.0.3.0/src/base/BaseStandardVar.ml" *)
  2602. open OASISGettext
  2603. open OASISTypes
  2604. open OASISExpr
  2605. open BaseCheck
  2606. open BaseEnv
  2607. let ocamlfind = BaseCheck.ocamlfind
  2608. let ocamlc = BaseOCamlcConfig.ocamlc
  2609. let ocamlopt = prog_opt "ocamlopt"
  2610. let ocamlbuild = prog "ocamlbuild"
  2611. (**/**)
  2612. let rpkg =
  2613. ref None
  2614. let pkg_get () =
  2615. match !rpkg with
  2616. | Some pkg -> pkg
  2617. | None -> failwith (s_ "OASIS Package is not set")
  2618. let var_cond = ref []
  2619. let var_define_cond ~since_version f dflt =
  2620. let holder = ref (fun () -> dflt) in
  2621. let since_version =
  2622. OASISVersion.VGreaterEqual (OASISVersion.version_of_string since_version)
  2623. in
  2624. var_cond :=
  2625. (fun ver ->
  2626. if OASISVersion.comparator_apply ver since_version then
  2627. holder := f ()) :: !var_cond;
  2628. fun () -> !holder ()
  2629. (**/**)
  2630. let pkg_name =
  2631. var_define
  2632. ~short_desc:(fun () -> s_ "Package name")
  2633. "pkg_name"
  2634. (fun () -> (pkg_get ()).name)
  2635. let pkg_version =
  2636. var_define
  2637. ~short_desc:(fun () -> s_ "Package version")
  2638. "pkg_version"
  2639. (fun () ->
  2640. (OASISVersion.string_of_version (pkg_get ()).version))
  2641. let c = BaseOCamlcConfig.var_define
  2642. let os_type = c "os_type"
  2643. let system = c "system"
  2644. let architecture = c "architecture"
  2645. let ccomp_type = c "ccomp_type"
  2646. let ocaml_version = c "ocaml_version"
  2647. (* TODO: Check standard variable presence at runtime *)
  2648. let standard_library_default = c "standard_library_default"
  2649. let standard_library = c "standard_library"
  2650. let standard_runtime = c "standard_runtime"
  2651. let bytecomp_c_compiler = c "bytecomp_c_compiler"
  2652. let native_c_compiler = c "native_c_compiler"
  2653. let model = c "model"
  2654. let ext_obj = c "ext_obj"
  2655. let ext_asm = c "ext_asm"
  2656. let ext_lib = c "ext_lib"
  2657. let ext_dll = c "ext_dll"
  2658. let default_executable_name = c "default_executable_name"
  2659. let systhread_supported = c "systhread_supported"
  2660. let flexlink =
  2661. BaseCheck.prog "flexlink"
  2662. let flexdll_version =
  2663. var_define
  2664. ~short_desc:(fun () -> "FlexDLL version (Win32)")
  2665. "flexdll_version"
  2666. (fun () ->
  2667. let lst =
  2668. OASISExec.run_read_output ~ctxt:!BaseContext.default
  2669. (flexlink ()) ["-help"]
  2670. in
  2671. match lst with
  2672. | line :: _ ->
  2673. Scanf.sscanf line "FlexDLL version %s" (fun ver -> ver)
  2674. | [] ->
  2675. raise Not_found)
  2676. (**/**)
  2677. let p name hlp dflt =
  2678. var_define
  2679. ~short_desc:hlp
  2680. ~cli:CLIAuto
  2681. ~arg_help:"dir"
  2682. name
  2683. dflt
  2684. let (/) a b =
  2685. if os_type () = Sys.os_type then
  2686. Filename.concat a b
  2687. else if os_type () = "Unix" then
  2688. OASISUnixPath.concat a b
  2689. else
  2690. OASISUtils.failwithf (f_ "Cannot handle os_type %s filename concat")
  2691. (os_type ())
  2692. (**/**)
  2693. let prefix =
  2694. p "prefix"
  2695. (fun () -> s_ "Install architecture-independent files dir")
  2696. (fun () ->
  2697. match os_type () with
  2698. | "Win32" ->
  2699. let program_files =
  2700. Sys.getenv "PROGRAMFILES"
  2701. in
  2702. program_files/(pkg_name ())
  2703. | _ ->
  2704. "/usr/local")
  2705. let exec_prefix =
  2706. p "exec_prefix"
  2707. (fun () -> s_ "Install architecture-dependent files in dir")
  2708. (fun () -> "$prefix")
  2709. let bindir =
  2710. p "bindir"
  2711. (fun () -> s_ "User executables")
  2712. (fun () -> "$exec_prefix"/"bin")
  2713. let sbindir =
  2714. p "sbindir"
  2715. (fun () -> s_ "System admin executables")
  2716. (fun () -> "$exec_prefix"/"sbin")
  2717. let libexecdir =
  2718. p "libexecdir"
  2719. (fun () -> s_ "Program executables")
  2720. (fun () -> "$exec_prefix"/"libexec")
  2721. let sysconfdir =
  2722. p "sysconfdir"
  2723. (fun () -> s_ "Read-only single-machine data")
  2724. (fun () -> "$prefix"/"etc")
  2725. let sharedstatedir =
  2726. p "sharedstatedir"
  2727. (fun () -> s_ "Modifiable architecture-independent data")
  2728. (fun () -> "$prefix"/"com")
  2729. let localstatedir =
  2730. p "localstatedir"
  2731. (fun () -> s_ "Modifiable single-machine data")
  2732. (fun () -> "$prefix"/"var")
  2733. let libdir =
  2734. p "libdir"
  2735. (fun () -> s_ "Object code libraries")
  2736. (fun () -> "$exec_prefix"/"lib")
  2737. let datarootdir =
  2738. p "datarootdir"
  2739. (fun () -> s_ "Read-only arch-independent data root")
  2740. (fun () -> "$prefix"/"share")
  2741. let datadir =
  2742. p "datadir"
  2743. (fun () -> s_ "Read-only architecture-independent data")
  2744. (fun () -> "$datarootdir")
  2745. let infodir =
  2746. p "infodir"
  2747. (fun () -> s_ "Info documentation")
  2748. (fun () -> "$datarootdir"/"info")
  2749. let localedir =
  2750. p "localedir"
  2751. (fun () -> s_ "Locale-dependent data")
  2752. (fun () -> "$datarootdir"/"locale")
  2753. let mandir =
  2754. p "mandir"
  2755. (fun () -> s_ "Man documentation")
  2756. (fun () -> "$datarootdir"/"man")
  2757. let docdir =
  2758. p "docdir"
  2759. (fun () -> s_ "Documentation root")
  2760. (fun () -> "$datarootdir"/"doc"/"$pkg_name")
  2761. let htmldir =
  2762. p "htmldir"
  2763. (fun () -> s_ "HTML documentation")
  2764. (fun () -> "$docdir")
  2765. let dvidir =
  2766. p "dvidir"
  2767. (fun () -> s_ "DVI documentation")
  2768. (fun () -> "$docdir")
  2769. let pdfdir =
  2770. p "pdfdir"
  2771. (fun () -> s_ "PDF documentation")
  2772. (fun () -> "$docdir")
  2773. let psdir =
  2774. p "psdir"
  2775. (fun () -> s_ "PS documentation")
  2776. (fun () -> "$docdir")
  2777. let destdir =
  2778. p "destdir"
  2779. (fun () -> s_ "Prepend a path when installing package")
  2780. (fun () ->
  2781. raise
  2782. (PropList.Not_set
  2783. ("destdir",
  2784. Some (s_ "undefined by construct"))))
  2785. let findlib_version =
  2786. var_define
  2787. "findlib_version"
  2788. (fun () ->
  2789. BaseCheck.package_version "findlib")
  2790. let is_native =
  2791. var_define
  2792. "is_native"
  2793. (fun () ->
  2794. try
  2795. let _s : string =
  2796. ocamlopt ()
  2797. in
  2798. "true"
  2799. with PropList.Not_set _ ->
  2800. let _s : string =
  2801. ocamlc ()
  2802. in
  2803. "false")
  2804. let ext_program =
  2805. var_define
  2806. "suffix_program"
  2807. (fun () ->
  2808. match os_type () with
  2809. | "Win32" -> ".exe"
  2810. | _ -> "")
  2811. let rm =
  2812. var_define
  2813. ~short_desc:(fun () -> s_ "Remove a file.")
  2814. "rm"
  2815. (fun () ->
  2816. match os_type () with
  2817. | "Win32" -> "del"
  2818. | _ -> "rm -f")
  2819. let rmdir =
  2820. var_define
  2821. ~short_desc:(fun () -> s_ "Remove a directory.")
  2822. "rmdir"
  2823. (fun () ->
  2824. match os_type () with
  2825. | "Win32" -> "rd"
  2826. | _ -> "rm -rf")
  2827. let debug =
  2828. var_define
  2829. ~short_desc:(fun () -> s_ "Turn ocaml debug flag on")
  2830. ~cli:CLIEnable
  2831. "debug"
  2832. (fun () -> "true")
  2833. let profile =
  2834. var_define
  2835. ~short_desc:(fun () -> s_ "Turn ocaml profile flag on")
  2836. ~cli:CLIEnable
  2837. "profile"
  2838. (fun () -> "false")
  2839. let tests =
  2840. var_define_cond ~since_version:"0.3"
  2841. (fun () ->
  2842. var_define
  2843. ~short_desc:(fun () ->
  2844. s_ "Compile tests executable and library and run them")
  2845. ~cli:CLIEnable
  2846. "tests"
  2847. (fun () -> "false"))
  2848. "true"
  2849. let docs =
  2850. var_define_cond ~since_version:"0.3"
  2851. (fun () ->
  2852. var_define
  2853. ~short_desc:(fun () -> s_ "Create documentations")
  2854. ~cli:CLIEnable
  2855. "docs"
  2856. (fun () -> "true"))
  2857. "true"
  2858. let native_dynlink =
  2859. var_define
  2860. ~short_desc:(fun () -> s_ "Compiler support generation of .cmxs.")
  2861. ~cli:CLINone
  2862. "native_dynlink"
  2863. (fun () ->
  2864. let res =
  2865. let ocaml_lt_312 () =
  2866. OASISVersion.comparator_apply
  2867. (OASISVersion.version_of_string (ocaml_version ()))
  2868. (OASISVersion.VLesser
  2869. (OASISVersion.version_of_string "3.12.0"))
  2870. in
  2871. let flexdll_lt_030 () =
  2872. OASISVersion.comparator_apply
  2873. (OASISVersion.version_of_string (flexdll_version ()))
  2874. (OASISVersion.VLesser
  2875. (OASISVersion.version_of_string "0.30"))
  2876. in
  2877. let has_native_dynlink =
  2878. let ocamlfind = ocamlfind () in
  2879. try
  2880. let fn =
  2881. OASISExec.run_read_one_line
  2882. ~ctxt:!BaseContext.default
  2883. ocamlfind
  2884. ["query"; "-predicates"; "native"; "dynlink";
  2885. "-format"; "%d/%a"]
  2886. in
  2887. Sys.file_exists fn
  2888. with _ ->
  2889. false
  2890. in
  2891. if not has_native_dynlink then
  2892. false
  2893. else if ocaml_lt_312 () then
  2894. false
  2895. else if (os_type () = "Win32" || os_type () = "Cygwin")
  2896. && flexdll_lt_030 () then
  2897. begin
  2898. BaseMessage.warning
  2899. (f_ ".cmxs generation disabled because FlexDLL needs to be \
  2900. at least 0.30. Please upgrade FlexDLL from %s to 0.30.")
  2901. (flexdll_version ());
  2902. false
  2903. end
  2904. else
  2905. true
  2906. in
  2907. string_of_bool res)
  2908. let init pkg =
  2909. rpkg := Some pkg;
  2910. List.iter (fun f -> f pkg.oasis_version) !var_cond
  2911. end
  2912. module BaseFileAB = struct
  2913. (* # 21 "/Users/avsm/.opam/system/build/oasis.0.3.0/src/base/BaseFileAB.ml" *)
  2914. open BaseEnv
  2915. open OASISGettext
  2916. open BaseMessage
  2917. let to_filename fn =
  2918. let fn =
  2919. OASISHostPath.of_unix fn
  2920. in
  2921. if not (Filename.check_suffix fn ".ab") then
  2922. warning
  2923. (f_ "File '%s' doesn't have '.ab' extension")
  2924. fn;
  2925. Filename.chop_extension fn
  2926. let replace fn_lst =
  2927. let buff =
  2928. Buffer.create 13
  2929. in
  2930. List.iter
  2931. (fun fn ->
  2932. let fn =
  2933. OASISHostPath.of_unix fn
  2934. in
  2935. let chn_in =
  2936. open_in fn
  2937. in
  2938. let chn_out =
  2939. open_out (to_filename fn)
  2940. in
  2941. (
  2942. try
  2943. while true do
  2944. Buffer.add_string buff (var_expand (input_line chn_in));
  2945. Buffer.add_char buff '\n'
  2946. done
  2947. with End_of_file ->
  2948. ()
  2949. );
  2950. Buffer.output_buffer chn_out buff;
  2951. Buffer.clear buff;
  2952. close_in chn_in;
  2953. close_out chn_out)
  2954. fn_lst
  2955. end
  2956. module BaseLog = struct
  2957. (* # 21 "/Users/avsm/.opam/system/build/oasis.0.3.0/src/base/BaseLog.ml" *)
  2958. open OASISUtils
  2959. let default_filename =
  2960. Filename.concat
  2961. (Filename.dirname BaseEnv.default_filename)
  2962. "setup.log"
  2963. module SetTupleString =
  2964. Set.Make
  2965. (struct
  2966. type t = string * string
  2967. let compare (s11, s12) (s21, s22) =
  2968. match String.compare s11 s21 with
  2969. | 0 -> String.compare s12 s22
  2970. | n -> n
  2971. end)
  2972. let load () =
  2973. if Sys.file_exists default_filename then
  2974. begin
  2975. let chn =
  2976. open_in default_filename
  2977. in
  2978. let scbuf =
  2979. Scanf.Scanning.from_file default_filename
  2980. in
  2981. let rec read_aux (st, lst) =
  2982. if not (Scanf.Scanning.end_of_input scbuf) then
  2983. begin
  2984. let acc =
  2985. try
  2986. Scanf.bscanf scbuf "%S %S\n"
  2987. (fun e d ->
  2988. let t =
  2989. e, d
  2990. in
  2991. if SetTupleString.mem t st then
  2992. st, lst
  2993. else
  2994. SetTupleString.add t st,
  2995. t :: lst)
  2996. with Scanf.Scan_failure _ ->
  2997. failwith
  2998. (Scanf.bscanf scbuf
  2999. "%l"
  3000. (fun line ->
  3001. Printf.sprintf
  3002. "Malformed log file '%s' at line %d"
  3003. default_filename
  3004. line))
  3005. in
  3006. read_aux acc
  3007. end
  3008. else
  3009. begin
  3010. close_in chn;
  3011. List.rev lst
  3012. end
  3013. in
  3014. read_aux (SetTupleString.empty, [])
  3015. end
  3016. else
  3017. begin
  3018. []
  3019. end
  3020. let register event data =
  3021. let chn_out =
  3022. open_out_gen [Open_append; Open_creat; Open_text] 0o644 default_filename
  3023. in
  3024. Printf.fprintf chn_out "%S %S\n" event data;
  3025. close_out chn_out
  3026. let unregister event data =
  3027. if Sys.file_exists default_filename then
  3028. begin
  3029. let lst =
  3030. load ()
  3031. in
  3032. let chn_out =
  3033. open_out default_filename
  3034. in
  3035. let write_something =
  3036. ref false
  3037. in
  3038. List.iter
  3039. (fun (e, d) ->
  3040. if e <> event || d <> data then
  3041. begin
  3042. write_something := true;
  3043. Printf.fprintf chn_out "%S %S\n" e d
  3044. end)
  3045. lst;
  3046. close_out chn_out;
  3047. if not !write_something then
  3048. Sys.remove default_filename
  3049. end
  3050. let filter events =
  3051. let st_events =
  3052. List.fold_left
  3053. (fun st e ->
  3054. SetString.add e st)
  3055. SetString.empty
  3056. events
  3057. in
  3058. List.filter
  3059. (fun (e, _) -> SetString.mem e st_events)
  3060. (load ())
  3061. let exists event data =
  3062. List.exists
  3063. (fun v -> (event, data) = v)
  3064. (load ())
  3065. end
  3066. module BaseBuilt = struct
  3067. (* # 21 "/Users/avsm/.opam/system/build/oasis.0.3.0/src/base/BaseBuilt.ml" *)
  3068. open OASISTypes
  3069. open OASISGettext
  3070. open BaseStandardVar
  3071. open BaseMessage
  3072. type t =
  3073. | BExec (* Executable *)
  3074. | BExecLib (* Library coming with executable *)
  3075. | BLib (* Library *)
  3076. | BDoc (* Document *)
  3077. let to_log_event_file t nm =
  3078. "built_"^
  3079. (match t with
  3080. | BExec -> "exec"
  3081. | BExecLib -> "exec_lib"
  3082. | BLib -> "lib"
  3083. | BDoc -> "doc")^
  3084. "_"^nm
  3085. let to_log_event_done t nm =
  3086. "is_"^(to_log_event_file t nm)
  3087. let register t nm lst =
  3088. BaseLog.register
  3089. (to_log_event_done t nm)
  3090. "true";
  3091. List.iter
  3092. (fun alt ->
  3093. let registered =
  3094. List.fold_left
  3095. (fun registered fn ->
  3096. if OASISFileUtil.file_exists_case fn then
  3097. begin
  3098. BaseLog.register
  3099. (to_log_event_file t nm)
  3100. (if Filename.is_relative fn then
  3101. Filename.concat (Sys.getcwd ()) fn
  3102. else
  3103. fn);
  3104. true
  3105. end
  3106. else
  3107. registered)
  3108. false
  3109. alt
  3110. in
  3111. if not registered then
  3112. warning
  3113. (f_ "Cannot find an existing alternative files among: %s")
  3114. (String.concat (s_ ", ") alt))
  3115. lst
  3116. let unregister t nm =
  3117. List.iter
  3118. (fun (e, d) ->
  3119. BaseLog.unregister e d)
  3120. (BaseLog.filter
  3121. [to_log_event_file t nm;
  3122. to_log_event_done t nm])
  3123. let fold t nm f acc =
  3124. List.fold_left
  3125. (fun acc (_, fn) ->
  3126. if OASISFileUtil.file_exists_case fn then
  3127. begin
  3128. f acc fn
  3129. end
  3130. else
  3131. begin
  3132. warning
  3133. (f_ "File '%s' has been marked as built \
  3134. for %s but doesn't exist")
  3135. fn
  3136. (Printf.sprintf
  3137. (match t with
  3138. | BExec | BExecLib ->
  3139. (f_ "executable %s")
  3140. | BLib ->
  3141. (f_ "library %s")
  3142. | BDoc ->
  3143. (f_ "documentation %s"))
  3144. nm);
  3145. acc
  3146. end)
  3147. acc
  3148. (BaseLog.filter
  3149. [to_log_event_file t nm])
  3150. let is_built t nm =
  3151. List.fold_left
  3152. (fun is_built (_, d) ->
  3153. (try
  3154. bool_of_string d
  3155. with _ ->
  3156. false))
  3157. false
  3158. (BaseLog.filter
  3159. [to_log_event_done t nm])
  3160. let of_executable ffn (cs, bs, exec) =
  3161. let unix_exec_is, unix_dll_opt =
  3162. OASISExecutable.unix_exec_is
  3163. (cs, bs, exec)
  3164. (fun () ->
  3165. bool_of_string
  3166. (is_native ()))
  3167. ext_dll
  3168. ext_program
  3169. in
  3170. let evs =
  3171. (BExec, cs.cs_name, [[ffn unix_exec_is]])
  3172. ::
  3173. (match unix_dll_opt with
  3174. | Some fn ->
  3175. [BExecLib, cs.cs_name, [[ffn fn]]]
  3176. | None ->
  3177. [])
  3178. in
  3179. evs,
  3180. unix_exec_is,
  3181. unix_dll_opt
  3182. let of_library ffn (cs, bs, lib) =
  3183. let unix_lst =
  3184. OASISLibrary.generated_unix_files
  3185. ~ctxt:!BaseContext.default
  3186. ~source_file_exists:(fun fn ->
  3187. OASISFileUtil.file_exists_case (OASISHostPath.of_unix fn))
  3188. ~is_native:(bool_of_string (is_native ()))
  3189. ~has_native_dynlink:(bool_of_string (native_dynlink ()))
  3190. ~ext_lib:(ext_lib ())
  3191. ~ext_dll:(ext_dll ())
  3192. (cs, bs, lib)
  3193. in
  3194. let evs =
  3195. [BLib,
  3196. cs.cs_name,
  3197. List.map (List.map ffn) unix_lst]
  3198. in
  3199. evs, unix_lst
  3200. end
  3201. module BaseCustom = struct
  3202. (* # 21 "/Users/avsm/.opam/system/build/oasis.0.3.0/src/base/BaseCustom.ml" *)
  3203. open BaseEnv
  3204. open BaseMessage
  3205. open OASISTypes
  3206. open OASISGettext
  3207. let run cmd args extra_args =
  3208. OASISExec.run ~ctxt:!BaseContext.default ~quote:false
  3209. (var_expand cmd)
  3210. (List.map
  3211. var_expand
  3212. (args @ (Array.to_list extra_args)))
  3213. let hook ?(failsafe=false) cstm f e =
  3214. let optional_command lst =
  3215. let printer =
  3216. function
  3217. | Some (cmd, args) -> String.concat " " (cmd :: args)
  3218. | None -> s_ "No command"
  3219. in
  3220. match
  3221. var_choose
  3222. ~name:(s_ "Pre/Post Command")
  3223. ~printer
  3224. lst with
  3225. | Some (cmd, args) ->
  3226. begin
  3227. try
  3228. run cmd args [||]
  3229. with e when failsafe ->
  3230. warning
  3231. (f_ "Command '%s' fail with error: %s")
  3232. (String.concat " " (cmd :: args))
  3233. (match e with
  3234. | Failure msg -> msg
  3235. | e -> Printexc.to_string e)
  3236. end
  3237. | None ->
  3238. ()
  3239. in
  3240. let res =
  3241. optional_command cstm.pre_command;
  3242. f e
  3243. in
  3244. optional_command cstm.post_command;
  3245. res
  3246. end
  3247. module BaseDynVar = struct
  3248. (* # 21 "/Users/avsm/.opam/system/build/oasis.0.3.0/src/base/BaseDynVar.ml" *)
  3249. open OASISTypes
  3250. open OASISGettext
  3251. open BaseEnv
  3252. open BaseBuilt
  3253. let init pkg =
  3254. (* TODO: disambiguate exec vs other variable by adding exec_VARNAME. *)
  3255. (* TODO: provide compile option for library libary_byte_args_VARNAME... *)
  3256. List.iter
  3257. (function
  3258. | Executable (cs, bs, exec) ->
  3259. if var_choose bs.bs_build then
  3260. var_ignore
  3261. (var_redefine
  3262. (* We don't save this variable *)
  3263. ~dump:false
  3264. ~short_desc:(fun () ->
  3265. Printf.sprintf
  3266. (f_ "Filename of executable '%s'")
  3267. cs.cs_name)
  3268. (OASISUtils.varname_of_string cs.cs_name)
  3269. (fun () ->
  3270. let fn_opt =
  3271. fold
  3272. BExec cs.cs_name
  3273. (fun _ fn -> Some fn)
  3274. None
  3275. in
  3276. match fn_opt with
  3277. | Some fn -> fn
  3278. | None ->
  3279. raise
  3280. (PropList.Not_set
  3281. (cs.cs_name,
  3282. Some (Printf.sprintf
  3283. (f_ "Executable '%s' not yet built.")
  3284. cs.cs_name)))))
  3285. | Library _ | Flag _ | Test _ | SrcRepo _ | Doc _ ->
  3286. ())
  3287. pkg.sections
  3288. end
  3289. module BaseTest = struct
  3290. (* # 21 "/Users/avsm/.opam/system/build/oasis.0.3.0/src/base/BaseTest.ml" *)
  3291. open BaseEnv
  3292. open BaseMessage
  3293. open OASISTypes
  3294. open OASISExpr
  3295. open OASISGettext
  3296. let test lst pkg extra_args =
  3297. let one_test (failure, n) (test_plugin, cs, test) =
  3298. if var_choose
  3299. ~name:(Printf.sprintf
  3300. (f_ "test %s run")
  3301. cs.cs_name)
  3302. ~printer:string_of_bool
  3303. test.test_run then
  3304. begin
  3305. let () =
  3306. info (f_ "Running test '%s'") cs.cs_name
  3307. in
  3308. let back_cwd =
  3309. match test.test_working_directory with
  3310. | Some dir ->
  3311. let cwd =
  3312. Sys.getcwd ()
  3313. in
  3314. let chdir d =
  3315. info (f_ "Changing directory to '%s'") d;
  3316. Sys.chdir d
  3317. in
  3318. chdir dir;
  3319. fun () -> chdir cwd
  3320. | None ->
  3321. fun () -> ()
  3322. in
  3323. try
  3324. let failure_percent =
  3325. BaseCustom.hook
  3326. test.test_custom
  3327. (test_plugin pkg (cs, test))
  3328. extra_args
  3329. in
  3330. back_cwd ();
  3331. (failure_percent +. failure, n + 1)
  3332. with e ->
  3333. begin
  3334. back_cwd ();
  3335. raise e
  3336. end
  3337. end
  3338. else
  3339. begin
  3340. info (f_ "Skipping test '%s'") cs.cs_name;
  3341. (failure, n)
  3342. end
  3343. in
  3344. let (failed, n) =
  3345. List.fold_left
  3346. one_test
  3347. (0.0, 0)
  3348. lst
  3349. in
  3350. let failure_percent =
  3351. if n = 0 then
  3352. 0.0
  3353. else
  3354. failed /. (float_of_int n)
  3355. in
  3356. let msg =
  3357. Printf.sprintf
  3358. (f_ "Tests had a %.2f%% failure rate")
  3359. (100. *. failure_percent)
  3360. in
  3361. if failure_percent > 0.0 then
  3362. failwith msg
  3363. else
  3364. info "%s" msg;
  3365. (* Possible explanation why the tests where not run. *)
  3366. if OASISVersion.version_0_3_or_after pkg.oasis_version &&
  3367. not (bool_of_string (BaseStandardVar.tests ())) &&
  3368. lst <> [] then
  3369. BaseMessage.warning
  3370. "Tests are turned off, consider enabling with \
  3371. 'ocaml setup.ml -configure --enable-tests'"
  3372. end
  3373. module BaseDoc = struct
  3374. (* # 21 "/Users/avsm/.opam/system/build/oasis.0.3.0/src/base/BaseDoc.ml" *)
  3375. open BaseEnv
  3376. open BaseMessage
  3377. open OASISTypes
  3378. open OASISGettext
  3379. let doc lst pkg extra_args =
  3380. let one_doc (doc_plugin, cs, doc) =
  3381. if var_choose
  3382. ~name:(Printf.sprintf
  3383. (f_ "documentation %s build")
  3384. cs.cs_name)
  3385. ~printer:string_of_bool
  3386. doc.doc_build then
  3387. begin
  3388. info (f_ "Building documentation '%s'") cs.cs_name;
  3389. BaseCustom.hook
  3390. doc.doc_custom
  3391. (doc_plugin pkg (cs, doc))
  3392. extra_args
  3393. end
  3394. in
  3395. List.iter one_doc lst;
  3396. if OASISVersion.version_0_3_or_after pkg.oasis_version &&
  3397. not (bool_of_string (BaseStandardVar.docs ())) &&
  3398. lst <> [] then
  3399. BaseMessage.warning
  3400. "Docs are turned off, consider enabling with \
  3401. 'ocaml setup.ml -configure --enable-docs'"
  3402. end
  3403. module BaseSetup = struct
  3404. (* # 21 "/Users/avsm/.opam/system/build/oasis.0.3.0/src/base/BaseSetup.ml" *)
  3405. open BaseEnv
  3406. open BaseMessage
  3407. open OASISTypes
  3408. open OASISSection
  3409. open OASISGettext
  3410. open OASISUtils
  3411. type std_args_fun =
  3412. package -> string array -> unit
  3413. type ('a, 'b) section_args_fun =
  3414. name * (package -> (common_section * 'a) -> string array -> 'b)
  3415. type t =
  3416. {
  3417. configure: std_args_fun;
  3418. build: std_args_fun;
  3419. doc: ((doc, unit) section_args_fun) list;
  3420. test: ((test, float) section_args_fun) list;
  3421. install: std_args_fun;
  3422. uninstall: std_args_fun;
  3423. clean: std_args_fun list;
  3424. clean_doc: (doc, unit) section_args_fun list;
  3425. clean_test: (test, unit) section_args_fun list;
  3426. distclean: std_args_fun list;
  3427. distclean_doc: (doc, unit) section_args_fun list;
  3428. distclean_test: (test, unit) section_args_fun list;
  3429. package: package;
  3430. oasis_fn: string option;
  3431. oasis_version: string;
  3432. oasis_digest: Digest.t option;
  3433. oasis_exec: string option;
  3434. oasis_setup_args: string list;
  3435. setup_update: bool;
  3436. }
  3437. (* Associate a plugin function with data from package *)
  3438. let join_plugin_sections filter_map lst =
  3439. List.rev
  3440. (List.fold_left
  3441. (fun acc sct ->
  3442. match filter_map sct with
  3443. | Some e ->
  3444. e :: acc
  3445. | None ->
  3446. acc)
  3447. []
  3448. lst)
  3449. (* Search for plugin data associated with a section name *)
  3450. let lookup_plugin_section plugin action nm lst =
  3451. try
  3452. List.assoc nm lst
  3453. with Not_found ->
  3454. failwithf
  3455. (f_ "Cannot find plugin %s matching section %s for %s action")
  3456. plugin
  3457. nm
  3458. action
  3459. let configure t args =
  3460. (* Run configure *)
  3461. BaseCustom.hook
  3462. t.package.conf_custom
  3463. (fun () ->
  3464. (* Reload if preconf has changed it *)
  3465. begin
  3466. try
  3467. unload ();
  3468. load ();
  3469. with _ ->
  3470. ()
  3471. end;
  3472. (* Run plugin's configure *)
  3473. t.configure t.package args;
  3474. (* Dump to allow postconf to change it *)
  3475. dump ())
  3476. ();
  3477. (* Reload environment *)
  3478. unload ();
  3479. load ();
  3480. (* Save environment *)
  3481. print ();
  3482. (* Replace data in file *)
  3483. BaseFileAB.replace t.package.files_ab
  3484. let build t args =
  3485. BaseCustom.hook
  3486. t.package.build_custom
  3487. (t.build t.package)
  3488. args
  3489. let doc t args =
  3490. BaseDoc.doc
  3491. (join_plugin_sections
  3492. (function
  3493. | Doc (cs, e) ->
  3494. Some
  3495. (lookup_plugin_section
  3496. "documentation"
  3497. (s_ "build")
  3498. cs.cs_name
  3499. t.doc,
  3500. cs,
  3501. e)
  3502. | _ ->
  3503. None)
  3504. t.package.sections)
  3505. t.package
  3506. args
  3507. let test t args =
  3508. BaseTest.test
  3509. (join_plugin_sections
  3510. (function
  3511. | Test (cs, e) ->
  3512. Some
  3513. (lookup_plugin_section
  3514. "test"
  3515. (s_ "run")
  3516. cs.cs_name
  3517. t.test,
  3518. cs,
  3519. e)
  3520. | _ ->
  3521. None)
  3522. t.package.sections)
  3523. t.package
  3524. args
  3525. let all t args =
  3526. let rno_doc =
  3527. ref false
  3528. in
  3529. let rno_test =
  3530. ref false
  3531. in
  3532. Arg.parse_argv
  3533. ~current:(ref 0)
  3534. (Array.of_list
  3535. ((Sys.executable_name^" all") ::
  3536. (Array.to_list args)))
  3537. [
  3538. "-no-doc",
  3539. Arg.Set rno_doc,
  3540. s_ "Don't run doc target";
  3541. "-no-test",
  3542. Arg.Set rno_test,
  3543. s_ "Don't run test target";
  3544. ]
  3545. (failwithf (f_ "Don't know what to do with '%s'"))
  3546. "";
  3547. info "Running configure step";
  3548. configure t [||];
  3549. info "Running build step";
  3550. build t [||];
  3551. (* Load setup.log dynamic variables *)
  3552. BaseDynVar.init t.package;
  3553. if not !rno_doc then
  3554. begin
  3555. info "Running doc step";
  3556. doc t [||];
  3557. end
  3558. else
  3559. begin
  3560. info "Skipping doc step"
  3561. end;
  3562. if not !rno_test then
  3563. begin
  3564. info "Running test step";
  3565. test t [||]
  3566. end
  3567. else
  3568. begin
  3569. info "Skipping test step"
  3570. end
  3571. let install t args =
  3572. BaseCustom.hook
  3573. t.package.install_custom
  3574. (t.install t.package)
  3575. args
  3576. let uninstall t args =
  3577. BaseCustom.hook
  3578. t.package.uninstall_custom
  3579. (t.uninstall t.package)
  3580. args
  3581. let reinstall t args =
  3582. uninstall t args;
  3583. install t args
  3584. let clean, distclean =
  3585. let failsafe f a =
  3586. try
  3587. f a
  3588. with e ->
  3589. warning
  3590. (f_ "Action fail with error: %s")
  3591. (match e with
  3592. | Failure msg -> msg
  3593. | e -> Printexc.to_string e)
  3594. in
  3595. let generic_clean t cstm mains docs tests args =
  3596. BaseCustom.hook
  3597. ~failsafe:true
  3598. cstm
  3599. (fun () ->
  3600. (* Clean section *)
  3601. List.iter
  3602. (function
  3603. | Test (cs, test) ->
  3604. let f =
  3605. try
  3606. List.assoc cs.cs_name tests
  3607. with Not_found ->
  3608. fun _ _ _ -> ()
  3609. in
  3610. failsafe
  3611. (f t.package (cs, test))
  3612. args
  3613. | Doc (cs, doc) ->
  3614. let f =
  3615. try
  3616. List.assoc cs.cs_name docs
  3617. with Not_found ->
  3618. fun _ _ _ -> ()
  3619. in
  3620. failsafe
  3621. (f t.package (cs, doc))
  3622. args
  3623. | Library _
  3624. | Executable _
  3625. | Flag _
  3626. | SrcRepo _ ->
  3627. ())
  3628. t.package.sections;
  3629. (* Clean whole package *)
  3630. List.iter
  3631. (fun f ->
  3632. failsafe
  3633. (f t.package)
  3634. args)
  3635. mains)
  3636. ()
  3637. in
  3638. let clean t args =
  3639. generic_clean
  3640. t
  3641. t.package.clean_custom
  3642. t.clean
  3643. t.clean_doc
  3644. t.clean_test
  3645. args
  3646. in
  3647. let distclean t args =
  3648. (* Call clean *)
  3649. clean t args;
  3650. (* Call distclean code *)
  3651. generic_clean
  3652. t
  3653. t.package.distclean_custom
  3654. t.distclean
  3655. t.distclean_doc
  3656. t.distclean_test
  3657. args;
  3658. (* Remove generated file *)
  3659. List.iter
  3660. (fun fn ->
  3661. if Sys.file_exists fn then
  3662. begin
  3663. info (f_ "Remove '%s'") fn;
  3664. Sys.remove fn
  3665. end)
  3666. (BaseEnv.default_filename
  3667. ::
  3668. BaseLog.default_filename
  3669. ::
  3670. (List.rev_map BaseFileAB.to_filename t.package.files_ab))
  3671. in
  3672. clean, distclean
  3673. let version t _ =
  3674. print_endline t.oasis_version
  3675. let update_setup_ml, no_update_setup_ml_cli =
  3676. let b = ref true in
  3677. b,
  3678. ("-no-update-setup-ml",
  3679. Arg.Clear b,
  3680. s_ " Don't try to update setup.ml, even if _oasis has changed.")
  3681. let update_setup_ml t =
  3682. let oasis_fn =
  3683. match t.oasis_fn with
  3684. | Some fn -> fn
  3685. | None -> "_oasis"
  3686. in
  3687. let oasis_exec =
  3688. match t.oasis_exec with
  3689. | Some fn -> fn
  3690. | None -> "oasis"
  3691. in
  3692. let ocaml =
  3693. Sys.executable_name
  3694. in
  3695. let setup_ml, args =
  3696. match Array.to_list Sys.argv with
  3697. | setup_ml :: args ->
  3698. setup_ml, args
  3699. | [] ->
  3700. failwith
  3701. (s_ "Expecting non-empty command line arguments.")
  3702. in
  3703. let ocaml, setup_ml =
  3704. if Sys.executable_name = Sys.argv.(0) then
  3705. (* We are not running in standard mode, probably the script
  3706. * is precompiled.
  3707. *)
  3708. "ocaml", "setup.ml"
  3709. else
  3710. ocaml, setup_ml
  3711. in
  3712. let no_update_setup_ml_cli, _, _ = no_update_setup_ml_cli in
  3713. let do_update () =
  3714. let oasis_exec_version =
  3715. OASISExec.run_read_one_line
  3716. ~ctxt:!BaseContext.default
  3717. ~f_exit_code:
  3718. (function
  3719. | 0 ->
  3720. ()
  3721. | 1 ->
  3722. failwithf
  3723. (f_ "Executable '%s' is probably an old version \
  3724. of oasis (< 0.3.0), please update to version \
  3725. v%s.")
  3726. oasis_exec t.oasis_version
  3727. | 127 ->
  3728. failwithf
  3729. (f_ "Cannot find executable '%s', please install \
  3730. oasis v%s.")
  3731. oasis_exec t.oasis_version
  3732. | n ->
  3733. failwithf
  3734. (f_ "Command '%s version' exited with code %d.")
  3735. oasis_exec n)
  3736. oasis_exec ["version"]
  3737. in
  3738. if OASISVersion.comparator_apply
  3739. (OASISVersion.version_of_string oasis_exec_version)
  3740. (OASISVersion.VGreaterEqual
  3741. (OASISVersion.version_of_string t.oasis_version)) then
  3742. begin
  3743. (* We have a version >= for the executable oasis, proceed with
  3744. * update.
  3745. *)
  3746. (* TODO: delegate this check to 'oasis setup'. *)
  3747. if Sys.os_type = "Win32" then
  3748. failwithf
  3749. (f_ "It is not possible to update the running script \
  3750. setup.ml on Windows. Please update setup.ml by \
  3751. running '%s'.")
  3752. (String.concat " " (oasis_exec :: "setup" :: t.oasis_setup_args))
  3753. else
  3754. begin
  3755. OASISExec.run
  3756. ~ctxt:!BaseContext.default
  3757. ~f_exit_code:
  3758. (function
  3759. | 0 ->
  3760. ()
  3761. | n ->
  3762. failwithf
  3763. (f_ "Unable to update setup.ml using '%s', \
  3764. please fix the problem and retry.")
  3765. oasis_exec)
  3766. oasis_exec ("setup" :: t.oasis_setup_args);
  3767. OASISExec.run ~ctxt:!BaseContext.default ocaml (setup_ml :: args)
  3768. end
  3769. end
  3770. else
  3771. failwithf
  3772. (f_ "The version of '%s' (v%s) doesn't match the version of \
  3773. oasis used to generate the %s file. Please install at \
  3774. least oasis v%s.")
  3775. oasis_exec oasis_exec_version setup_ml t.oasis_version
  3776. in
  3777. if !update_setup_ml then
  3778. begin
  3779. try
  3780. match t.oasis_digest with
  3781. | Some dgst ->
  3782. if Sys.file_exists oasis_fn && dgst <> Digest.file "_oasis" then
  3783. begin
  3784. do_update ();
  3785. true
  3786. end
  3787. else
  3788. false
  3789. | None ->
  3790. false
  3791. with e ->
  3792. error
  3793. (f_ "Error when updating setup.ml. If you want to avoid this error, \
  3794. you can bypass the update of %s by running '%s %s %s %s'")
  3795. setup_ml ocaml setup_ml no_update_setup_ml_cli
  3796. (String.concat " " args);
  3797. raise e
  3798. end
  3799. else
  3800. false
  3801. let setup t =
  3802. let catch_exn =
  3803. ref true
  3804. in
  3805. try
  3806. let act_ref =
  3807. ref (fun _ ->
  3808. failwithf
  3809. (f_ "No action defined, run '%s %s -help'")
  3810. Sys.executable_name
  3811. Sys.argv.(0))
  3812. in
  3813. let extra_args_ref =
  3814. ref []
  3815. in
  3816. let allow_empty_env_ref =
  3817. ref false
  3818. in
  3819. let arg_handle ?(allow_empty_env=false) act =
  3820. Arg.Tuple
  3821. [
  3822. Arg.Rest (fun str -> extra_args_ref := str :: !extra_args_ref);
  3823. Arg.Unit
  3824. (fun () ->
  3825. allow_empty_env_ref := allow_empty_env;
  3826. act_ref := act);
  3827. ]
  3828. in
  3829. Arg.parse
  3830. (Arg.align
  3831. ([
  3832. "-configure",
  3833. arg_handle ~allow_empty_env:true configure,
  3834. s_ "[options*] Configure the whole build process.";
  3835. "-build",
  3836. arg_handle build,
  3837. s_ "[options*] Build executables and libraries.";
  3838. "-doc",
  3839. arg_handle doc,
  3840. s_ "[options*] Build documents.";
  3841. "-test",
  3842. arg_handle test,
  3843. s_ "[options*] Run tests.";
  3844. "-all",
  3845. arg_handle ~allow_empty_env:true all,
  3846. s_ "[options*] Run configure, build, doc and test targets.";
  3847. "-install",
  3848. arg_handle install,
  3849. s_ "[options*] Install libraries, data, executables \
  3850. and documents.";
  3851. "-uninstall",
  3852. arg_handle uninstall,
  3853. s_ "[options*] Uninstall libraries, data, executables \
  3854. and documents.";
  3855. "-reinstall",
  3856. arg_handle reinstall,
  3857. s_ "[options*] Uninstall and install libraries, data, \
  3858. executables and documents.";
  3859. "-clean",
  3860. arg_handle ~allow_empty_env:true clean,
  3861. s_ "[options*] Clean files generated by a build.";
  3862. "-distclean",
  3863. arg_handle ~allow_empty_env:true distclean,
  3864. s_ "[options*] Clean files generated by a build and configure.";
  3865. "-version",
  3866. arg_handle ~allow_empty_env:true version,
  3867. s_ " Display version of OASIS used to generate this setup.ml.";
  3868. "-no-catch-exn",
  3869. Arg.Clear catch_exn,
  3870. s_ " Don't catch exception, useful for debugging.";
  3871. ]
  3872. @
  3873. (if t.setup_update then
  3874. [no_update_setup_ml_cli]
  3875. else
  3876. [])
  3877. @ (BaseContext.args ())))
  3878. (failwithf (f_ "Don't know what to do with '%s'"))
  3879. (s_ "Setup and run build process current package\n");
  3880. (* Build initial environment *)
  3881. load ~allow_empty:!allow_empty_env_ref ();
  3882. (** Initialize flags *)
  3883. List.iter
  3884. (function
  3885. | Flag (cs, {flag_description = hlp;
  3886. flag_default = choices}) ->
  3887. begin
  3888. let apply ?short_desc () =
  3889. var_ignore
  3890. (var_define
  3891. ~cli:CLIEnable
  3892. ?short_desc
  3893. (OASISUtils.varname_of_string cs.cs_name)
  3894. (fun () ->
  3895. string_of_bool
  3896. (var_choose
  3897. ~name:(Printf.sprintf
  3898. (f_ "default value of flag %s")
  3899. cs.cs_name)
  3900. ~printer:string_of_bool
  3901. choices)))
  3902. in
  3903. match hlp with
  3904. | Some hlp ->
  3905. apply ~short_desc:(fun () -> hlp) ()
  3906. | None ->
  3907. apply ()
  3908. end
  3909. | _ ->
  3910. ())
  3911. t.package.sections;
  3912. BaseStandardVar.init t.package;
  3913. BaseDynVar.init t.package;
  3914. if t.setup_update && update_setup_ml t then
  3915. ()
  3916. else
  3917. !act_ref t (Array.of_list (List.rev !extra_args_ref))
  3918. with e when !catch_exn ->
  3919. error "%s" (Printexc.to_string e);
  3920. exit 1
  3921. end
  3922. # 4480 "setup.ml"
  3923. module InternalConfigurePlugin = struct
  3924. (* # 21 "/Users/avsm/.opam/system/build/oasis.0.3.0/src/plugins/internal/InternalConfigurePlugin.ml" *)
  3925. (** Configure using internal scheme
  3926. @author Sylvain Le Gall
  3927. *)
  3928. open BaseEnv
  3929. open OASISTypes
  3930. open OASISUtils
  3931. open OASISGettext
  3932. open BaseMessage
  3933. (** Configure build using provided series of check to be done
  3934. * and then output corresponding file.
  3935. *)
  3936. let configure pkg argv =
  3937. let var_ignore_eval var =
  3938. let _s : string =
  3939. var ()
  3940. in
  3941. ()
  3942. in
  3943. let errors =
  3944. ref SetString.empty
  3945. in
  3946. let buff =
  3947. Buffer.create 13
  3948. in
  3949. let add_errors fmt =
  3950. Printf.kbprintf
  3951. (fun b ->
  3952. errors := SetString.add (Buffer.contents b) !errors;
  3953. Buffer.clear b)
  3954. buff
  3955. fmt
  3956. in
  3957. let warn_exception e =
  3958. warning "%s" (Printexc.to_string e)
  3959. in
  3960. (* Check tools *)
  3961. let check_tools lst =
  3962. List.iter
  3963. (function
  3964. | ExternalTool tool ->
  3965. begin
  3966. try
  3967. var_ignore_eval (BaseCheck.prog tool)
  3968. with e ->
  3969. warn_exception e;
  3970. add_errors (f_ "Cannot find external tool '%s'") tool
  3971. end
  3972. | InternalExecutable nm1 ->
  3973. (* Check that matching tool is built *)
  3974. List.iter
  3975. (function
  3976. | Executable ({cs_name = nm2},
  3977. {bs_build = build},
  3978. _) when nm1 = nm2 ->
  3979. if not (var_choose build) then
  3980. add_errors
  3981. (f_ "Cannot find buildable internal executable \
  3982. '%s' when checking build depends")
  3983. nm1
  3984. | _ ->
  3985. ())
  3986. pkg.sections)
  3987. lst
  3988. in
  3989. let build_checks sct bs =
  3990. if var_choose bs.bs_build then
  3991. begin
  3992. if bs.bs_compiled_object = Native then
  3993. begin
  3994. try
  3995. var_ignore_eval BaseStandardVar.ocamlopt
  3996. with e ->
  3997. warn_exception e;
  3998. add_errors
  3999. (f_ "Section %s requires native compilation")
  4000. (OASISSection.string_of_section sct)
  4001. end;
  4002. (* Check tools *)
  4003. check_tools bs.bs_build_tools;
  4004. (* Check depends *)
  4005. List.iter
  4006. (function
  4007. | FindlibPackage (findlib_pkg, version_comparator) ->
  4008. begin
  4009. try
  4010. var_ignore_eval
  4011. (BaseCheck.package ?version_comparator findlib_pkg)
  4012. with e ->
  4013. warn_exception e;
  4014. match version_comparator with
  4015. | None ->
  4016. add_errors
  4017. (f_ "Cannot find findlib package %s")
  4018. findlib_pkg
  4019. | Some ver_cmp ->
  4020. add_errors
  4021. (f_ "Cannot find findlib package %s (%s)")
  4022. findlib_pkg
  4023. (OASISVersion.string_of_comparator ver_cmp)
  4024. end
  4025. | InternalLibrary nm1 ->
  4026. (* Check that matching library is built *)
  4027. List.iter
  4028. (function
  4029. | Library ({cs_name = nm2},
  4030. {bs_build = build},
  4031. _) when nm1 = nm2 ->
  4032. if not (var_choose build) then
  4033. add_errors
  4034. (f_ "Cannot find buildable internal library \
  4035. '%s' when checking build depends")
  4036. nm1
  4037. | _ ->
  4038. ())
  4039. pkg.sections)
  4040. bs.bs_build_depends
  4041. end
  4042. in
  4043. (* Parse command line *)
  4044. BaseArgExt.parse argv (BaseEnv.args ());
  4045. (* OCaml version *)
  4046. begin
  4047. match pkg.ocaml_version with
  4048. | Some ver_cmp ->
  4049. begin
  4050. try
  4051. var_ignore_eval
  4052. (BaseCheck.version
  4053. "ocaml"
  4054. ver_cmp
  4055. BaseStandardVar.ocaml_version)
  4056. with e ->
  4057. warn_exception e;
  4058. add_errors
  4059. (f_ "OCaml version %s doesn't match version constraint %s")
  4060. (BaseStandardVar.ocaml_version ())
  4061. (OASISVersion.string_of_comparator ver_cmp)
  4062. end
  4063. | None ->
  4064. ()
  4065. end;
  4066. (* Findlib version *)
  4067. begin
  4068. match pkg.findlib_version with
  4069. | Some ver_cmp ->
  4070. begin
  4071. try
  4072. var_ignore_eval
  4073. (BaseCheck.version
  4074. "findlib"
  4075. ver_cmp
  4076. BaseStandardVar.findlib_version)
  4077. with e ->
  4078. warn_exception e;
  4079. add_errors
  4080. (f_ "Findlib version %s doesn't match version constraint %s")
  4081. (BaseStandardVar.findlib_version ())
  4082. (OASISVersion.string_of_comparator ver_cmp)
  4083. end
  4084. | None ->
  4085. ()
  4086. end;
  4087. (* FlexDLL *)
  4088. if BaseStandardVar.os_type () = "Win32" ||
  4089. BaseStandardVar.os_type () = "Cygwin" then
  4090. begin
  4091. try
  4092. var_ignore_eval BaseStandardVar.flexlink
  4093. with e ->
  4094. warn_exception e;
  4095. add_errors (f_ "Cannot find 'flexlink'")
  4096. end;
  4097. (* Check build depends *)
  4098. List.iter
  4099. (function
  4100. | Executable (_, bs, _)
  4101. | Library (_, bs, _) as sct ->
  4102. build_checks sct bs
  4103. | Doc (_, doc) ->
  4104. if var_choose doc.doc_build then
  4105. check_tools doc.doc_build_tools
  4106. | Test (_, test) ->
  4107. if var_choose test.test_run then
  4108. check_tools test.test_tools
  4109. | _ ->
  4110. ())
  4111. pkg.sections;
  4112. (* Check if we need native dynlink (presence of libraries that compile to
  4113. * native)
  4114. *)
  4115. begin
  4116. let has_cmxa =
  4117. List.exists
  4118. (function
  4119. | Library (_, bs, _) ->
  4120. var_choose bs.bs_build &&
  4121. (bs.bs_compiled_object = Native ||
  4122. (bs.bs_compiled_object = Best &&
  4123. bool_of_string (BaseStandardVar.is_native ())))
  4124. | _ ->
  4125. false)
  4126. pkg.sections
  4127. in
  4128. if has_cmxa then
  4129. var_ignore_eval BaseStandardVar.native_dynlink
  4130. end;
  4131. (* Check errors *)
  4132. if SetString.empty != !errors then
  4133. begin
  4134. List.iter
  4135. (fun e -> error "%s" e)
  4136. (SetString.elements !errors);
  4137. failwithf
  4138. (fn_
  4139. "%d configuration error"
  4140. "%d configuration errors"
  4141. (SetString.cardinal !errors))
  4142. (SetString.cardinal !errors)
  4143. end
  4144. end
  4145. module InternalInstallPlugin = struct
  4146. (* # 21 "/Users/avsm/.opam/system/build/oasis.0.3.0/src/plugins/internal/InternalInstallPlugin.ml" *)
  4147. (** Install using internal scheme
  4148. @author Sylvain Le Gall
  4149. *)
  4150. open BaseEnv
  4151. open BaseStandardVar
  4152. open BaseMessage
  4153. open OASISTypes
  4154. open OASISLibrary
  4155. open OASISGettext
  4156. open OASISUtils
  4157. let exec_hook =
  4158. ref (fun (cs, bs, exec) -> cs, bs, exec)
  4159. let lib_hook =
  4160. ref (fun (cs, bs, lib) -> cs, bs, lib, [])
  4161. let doc_hook =
  4162. ref (fun (cs, doc) -> cs, doc)
  4163. let install_file_ev =
  4164. "install-file"
  4165. let install_dir_ev =
  4166. "install-dir"
  4167. let install_findlib_ev =
  4168. "install-findlib"
  4169. let win32_max_command_line_length = 8000
  4170. let split_install_command ocamlfind findlib_name meta files =
  4171. if Sys.os_type = "Win32" then
  4172. (* Arguments for the first command: *)
  4173. let first_args = ["install"; findlib_name; meta] in
  4174. (* Arguments for remaining commands: *)
  4175. let other_args = ["install"; findlib_name; "-add"] in
  4176. (* Extract as much files as possible from [files], [len] is
  4177. the current command line length: *)
  4178. let rec get_files len acc files =
  4179. match files with
  4180. | [] ->
  4181. (List.rev acc, [])
  4182. | file :: rest ->
  4183. let len = len + 1 + String.length file in
  4184. if len > win32_max_command_line_length then
  4185. (List.rev acc, files)
  4186. else
  4187. get_files len (file :: acc) rest
  4188. in
  4189. (* Split the command into several commands. *)
  4190. let rec split args files =
  4191. match files with
  4192. | [] ->
  4193. []
  4194. | _ ->
  4195. (* Length of "ocamlfind install <lib> [META|-add]" *)
  4196. let len =
  4197. List.fold_left
  4198. (fun len arg ->
  4199. len + 1 (* for the space *) + String.length arg)
  4200. (String.length ocamlfind)
  4201. args
  4202. in
  4203. match get_files len [] files with
  4204. | ([], _) ->
  4205. failwith (s_ "Command line too long.")
  4206. | (firsts, others) ->
  4207. let cmd = args @ firsts in
  4208. (* Use -add for remaining commands: *)
  4209. let () =
  4210. let findlib_ge_132 =
  4211. OASISVersion.comparator_apply
  4212. (OASISVersion.version_of_string
  4213. (BaseStandardVar.findlib_version ()))
  4214. (OASISVersion.VGreaterEqual
  4215. (OASISVersion.version_of_string "1.3.2"))
  4216. in
  4217. if not findlib_ge_132 then
  4218. failwithf
  4219. (f_ "Installing the library %s require to use the flag \
  4220. '-add' of ocamlfind because the command line is too \
  4221. long. This flag is only available for findlib 1.3.2. \
  4222. Please upgrade findlib from %s to 1.3.2")
  4223. findlib_name (BaseStandardVar.findlib_version ())
  4224. in
  4225. let cmds = split other_args others in
  4226. cmd :: cmds
  4227. in
  4228. (* The first command does not use -add: *)
  4229. split first_args files
  4230. else
  4231. ["install" :: findlib_name :: meta :: files]
  4232. let install pkg argv =
  4233. let in_destdir =
  4234. try
  4235. let destdir =
  4236. destdir ()
  4237. in
  4238. (* Practically speaking destdir is prepended
  4239. * at the beginning of the target filename
  4240. *)
  4241. fun fn -> destdir^fn
  4242. with PropList.Not_set _ ->
  4243. fun fn -> fn
  4244. in
  4245. let install_file ?tgt_fn src_file envdir =
  4246. let tgt_dir =
  4247. in_destdir (envdir ())
  4248. in
  4249. let tgt_file =
  4250. Filename.concat
  4251. tgt_dir
  4252. (match tgt_fn with
  4253. | Some fn ->
  4254. fn
  4255. | None ->
  4256. Filename.basename src_file)
  4257. in
  4258. (* Create target directory if needed *)
  4259. OASISFileUtil.mkdir_parent
  4260. ~ctxt:!BaseContext.default
  4261. (fun dn ->
  4262. info (f_ "Creating directory '%s'") dn;
  4263. BaseLog.register install_dir_ev dn)
  4264. tgt_dir;
  4265. (* Really install files *)
  4266. info (f_ "Copying file '%s' to '%s'") src_file tgt_file;
  4267. OASISFileUtil.cp ~ctxt:!BaseContext.default src_file tgt_file;
  4268. BaseLog.register install_file_ev tgt_file
  4269. in
  4270. (* Install data into defined directory *)
  4271. let install_data srcdir lst tgtdir =
  4272. let tgtdir =
  4273. OASISHostPath.of_unix (var_expand tgtdir)
  4274. in
  4275. List.iter
  4276. (fun (src, tgt_opt) ->
  4277. let real_srcs =
  4278. OASISFileUtil.glob
  4279. ~ctxt:!BaseContext.default
  4280. (Filename.concat srcdir src)
  4281. in
  4282. if real_srcs = [] then
  4283. failwithf
  4284. (f_ "Wildcard '%s' doesn't match any files")
  4285. src;
  4286. List.iter
  4287. (fun fn ->
  4288. install_file
  4289. fn
  4290. (fun () ->
  4291. match tgt_opt with
  4292. | Some s ->
  4293. OASISHostPath.of_unix (var_expand s)
  4294. | None ->
  4295. tgtdir))
  4296. real_srcs)
  4297. lst
  4298. in
  4299. (** Install all libraries *)
  4300. let install_libs pkg =
  4301. let files_of_library (f_data, acc) data_lib =
  4302. let cs, bs, lib, lib_extra =
  4303. !lib_hook data_lib
  4304. in
  4305. if var_choose bs.bs_install &&
  4306. BaseBuilt.is_built BaseBuilt.BLib cs.cs_name then
  4307. begin
  4308. let acc =
  4309. (* Start with acc + lib_extra *)
  4310. List.rev_append lib_extra acc
  4311. in
  4312. let acc =
  4313. (* Add uncompiled header from the source tree *)
  4314. let path =
  4315. OASISHostPath.of_unix bs.bs_path
  4316. in
  4317. List.fold_left
  4318. (fun acc modul ->
  4319. try
  4320. List.find
  4321. OASISFileUtil.file_exists_case
  4322. (List.map
  4323. (Filename.concat path)
  4324. [modul^".mli";
  4325. modul^".ml";
  4326. String.uncapitalize modul^".mli";
  4327. String.capitalize modul^".mli";
  4328. String.uncapitalize modul^".ml";
  4329. String.capitalize modul^".ml"])
  4330. :: acc
  4331. with Not_found ->
  4332. begin
  4333. warning
  4334. (f_ "Cannot find source header for module %s \
  4335. in library %s")
  4336. modul cs.cs_name;
  4337. acc
  4338. end)
  4339. acc
  4340. lib.lib_modules
  4341. in
  4342. let acc =
  4343. (* Get generated files *)
  4344. BaseBuilt.fold
  4345. BaseBuilt.BLib
  4346. cs.cs_name
  4347. (fun acc fn -> fn :: acc)
  4348. acc
  4349. in
  4350. let f_data () =
  4351. (* Install data associated with the library *)
  4352. install_data
  4353. bs.bs_path
  4354. bs.bs_data_files
  4355. (Filename.concat
  4356. (datarootdir ())
  4357. pkg.name);
  4358. f_data ()
  4359. in
  4360. (f_data, acc)
  4361. end
  4362. else
  4363. begin
  4364. (f_data, acc)
  4365. end
  4366. in
  4367. (* Install one group of library *)
  4368. let install_group_lib grp =
  4369. (* Iterate through all group nodes *)
  4370. let rec install_group_lib_aux data_and_files grp =
  4371. let data_and_files, children =
  4372. match grp with
  4373. | Container (_, children) ->
  4374. data_and_files, children
  4375. | Package (_, cs, bs, lib, children) ->
  4376. files_of_library data_and_files (cs, bs, lib), children
  4377. in
  4378. List.fold_left
  4379. install_group_lib_aux
  4380. data_and_files
  4381. children
  4382. in
  4383. (* Findlib name of the root library *)
  4384. let findlib_name =
  4385. findlib_of_group grp
  4386. in
  4387. (* Determine root library *)
  4388. let root_lib =
  4389. root_of_group grp
  4390. in
  4391. (* All files to install for this library *)
  4392. let f_data, files =
  4393. install_group_lib_aux (ignore, []) grp
  4394. in
  4395. (* Really install, if there is something to install *)
  4396. if files = [] then
  4397. begin
  4398. warning
  4399. (f_ "Nothing to install for findlib library '%s'")
  4400. findlib_name
  4401. end
  4402. else
  4403. begin
  4404. let meta =
  4405. (* Search META file *)
  4406. let (_, bs, _) =
  4407. root_lib
  4408. in
  4409. let res =
  4410. Filename.concat bs.bs_path "META"
  4411. in
  4412. if not (OASISFileUtil.file_exists_case res) then
  4413. failwithf
  4414. (f_ "Cannot find file '%s' for findlib library %s")
  4415. res
  4416. findlib_name;
  4417. res
  4418. in
  4419. let files =
  4420. (* Make filename shorter to avoid hitting command max line length
  4421. * too early, esp. on Windows.
  4422. *)
  4423. let remove_prefix p n =
  4424. let plen = String.length p in
  4425. let nlen = String.length n in
  4426. if plen <= nlen && String.sub n 0 plen = p then
  4427. begin
  4428. let fn_sep =
  4429. if Sys.os_type = "Win32" then
  4430. '\\'
  4431. else
  4432. '/'
  4433. in
  4434. let cutpoint = plen +
  4435. (if plen < nlen && n.[plen] = fn_sep then
  4436. 1
  4437. else
  4438. 0)
  4439. in
  4440. String.sub n cutpoint (nlen - cutpoint)
  4441. end
  4442. else
  4443. n
  4444. in
  4445. List.map (remove_prefix (Sys.getcwd ())) files
  4446. in
  4447. info
  4448. (f_ "Installing findlib library '%s'")
  4449. findlib_name;
  4450. let ocamlfind = ocamlfind () in
  4451. let commands =
  4452. split_install_command
  4453. ocamlfind
  4454. findlib_name
  4455. meta
  4456. files
  4457. in
  4458. List.iter
  4459. (OASISExec.run ~ctxt:!BaseContext.default ocamlfind)
  4460. commands;
  4461. BaseLog.register install_findlib_ev findlib_name
  4462. end;
  4463. (* Install data files *)
  4464. f_data ();
  4465. in
  4466. let group_libs, _, _ =
  4467. findlib_mapping pkg
  4468. in
  4469. (* We install libraries in groups *)
  4470. List.iter install_group_lib group_libs
  4471. in
  4472. let install_execs pkg =
  4473. let install_exec data_exec =
  4474. let (cs, bs, exec) =
  4475. !exec_hook data_exec
  4476. in
  4477. if var_choose bs.bs_install &&
  4478. BaseBuilt.is_built BaseBuilt.BExec cs.cs_name then
  4479. begin
  4480. let exec_libdir () =
  4481. Filename.concat
  4482. (libdir ())
  4483. pkg.name
  4484. in
  4485. BaseBuilt.fold
  4486. BaseBuilt.BExec
  4487. cs.cs_name
  4488. (fun () fn ->
  4489. install_file
  4490. ~tgt_fn:(cs.cs_name ^ ext_program ())
  4491. fn
  4492. bindir)
  4493. ();
  4494. BaseBuilt.fold
  4495. BaseBuilt.BExecLib
  4496. cs.cs_name
  4497. (fun () fn ->
  4498. install_file
  4499. fn
  4500. exec_libdir)
  4501. ();
  4502. install_data
  4503. bs.bs_path
  4504. bs.bs_data_files
  4505. (Filename.concat
  4506. (datarootdir ())
  4507. pkg.name)
  4508. end
  4509. in
  4510. List.iter
  4511. (function
  4512. | Executable (cs, bs, exec)->
  4513. install_exec (cs, bs, exec)
  4514. | _ ->
  4515. ())
  4516. pkg.sections
  4517. in
  4518. let install_docs pkg =
  4519. let install_doc data =
  4520. let (cs, doc) =
  4521. !doc_hook data
  4522. in
  4523. if var_choose doc.doc_install &&
  4524. BaseBuilt.is_built BaseBuilt.BDoc cs.cs_name then
  4525. begin
  4526. let tgt_dir =
  4527. OASISHostPath.of_unix (var_expand doc.doc_install_dir)
  4528. in
  4529. BaseBuilt.fold
  4530. BaseBuilt.BDoc
  4531. cs.cs_name
  4532. (fun () fn ->
  4533. install_file
  4534. fn
  4535. (fun () -> tgt_dir))
  4536. ();
  4537. install_data
  4538. Filename.current_dir_name
  4539. doc.doc_data_files
  4540. doc.doc_install_dir
  4541. end
  4542. in
  4543. List.iter
  4544. (function
  4545. | Doc (cs, doc) ->
  4546. install_doc (cs, doc)
  4547. | _ ->
  4548. ())
  4549. pkg.sections
  4550. in
  4551. install_libs pkg;
  4552. install_execs pkg;
  4553. install_docs pkg
  4554. (* Uninstall already installed data *)
  4555. let uninstall _ argv =
  4556. List.iter
  4557. (fun (ev, data) ->
  4558. if ev = install_file_ev then
  4559. begin
  4560. if OASISFileUtil.file_exists_case data then
  4561. begin
  4562. info
  4563. (f_ "Removing file '%s'")
  4564. data;
  4565. Sys.remove data
  4566. end
  4567. else
  4568. begin
  4569. warning
  4570. (f_ "File '%s' doesn't exist anymore")
  4571. data
  4572. end
  4573. end
  4574. else if ev = install_dir_ev then
  4575. begin
  4576. if Sys.file_exists data && Sys.is_directory data then
  4577. begin
  4578. if Sys.readdir data = [||] then
  4579. begin
  4580. info
  4581. (f_ "Removing directory '%s'")
  4582. data;
  4583. OASISFileUtil.rmdir ~ctxt:!BaseContext.default data
  4584. end
  4585. else
  4586. begin
  4587. warning
  4588. (f_ "Directory '%s' is not empty (%s)")
  4589. data
  4590. (String.concat
  4591. ", "
  4592. (Array.to_list
  4593. (Sys.readdir data)))
  4594. end
  4595. end
  4596. else
  4597. begin
  4598. warning
  4599. (f_ "Directory '%s' doesn't exist anymore")
  4600. data
  4601. end
  4602. end
  4603. else if ev = install_findlib_ev then
  4604. begin
  4605. info (f_ "Removing findlib library '%s'") data;
  4606. OASISExec.run ~ctxt:!BaseContext.default
  4607. (ocamlfind ()) ["remove"; data]
  4608. end
  4609. else
  4610. failwithf (f_ "Unknown log event '%s'") ev;
  4611. BaseLog.unregister ev data)
  4612. (* We process event in reverse order *)
  4613. (List.rev
  4614. (BaseLog.filter
  4615. [install_file_ev;
  4616. install_dir_ev;
  4617. install_findlib_ev;]))
  4618. end
  4619. # 5233 "setup.ml"
  4620. module OCamlbuildCommon = struct
  4621. (* # 21 "/Users/avsm/.opam/system/build/oasis.0.3.0/src/plugins/ocamlbuild/OCamlbuildCommon.ml" *)
  4622. (** Functions common to OCamlbuild build and doc plugin
  4623. *)
  4624. open OASISGettext
  4625. open BaseEnv
  4626. open BaseStandardVar
  4627. let ocamlbuild_clean_ev =
  4628. "ocamlbuild-clean"
  4629. let ocamlbuildflags =
  4630. var_define
  4631. ~short_desc:(fun () -> "OCamlbuild additional flags")
  4632. "ocamlbuildflags"
  4633. (fun () -> "")
  4634. (** Fix special arguments depending on environment *)
  4635. let fix_args args extra_argv =
  4636. List.flatten
  4637. [
  4638. if (os_type ()) = "Win32" then
  4639. [
  4640. "-classic-display";
  4641. "-no-log";
  4642. "-no-links";
  4643. "-install-lib-dir";
  4644. (Filename.concat (standard_library ()) "ocamlbuild")
  4645. ]
  4646. else
  4647. [];
  4648. if not (bool_of_string (is_native ())) || (os_type ()) = "Win32" then
  4649. [
  4650. "-byte-plugin"
  4651. ]
  4652. else
  4653. [];
  4654. args;
  4655. if bool_of_string (debug ()) then
  4656. ["-tag"; "debug"]
  4657. else
  4658. [];
  4659. if bool_of_string (profile ()) then
  4660. ["-tag"; "profile"]
  4661. else
  4662. [];
  4663. OASISString.nsplit (ocamlbuildflags ()) ' ';
  4664. Array.to_list extra_argv;
  4665. ]
  4666. (** Run 'ocamlbuild -clean' if not already done *)
  4667. let run_clean extra_argv =
  4668. let extra_cli =
  4669. String.concat " " (Array.to_list extra_argv)
  4670. in
  4671. (* Run if never called with these args *)
  4672. if not (BaseLog.exists ocamlbuild_clean_ev extra_cli) then
  4673. begin
  4674. OASISExec.run ~ctxt:!BaseContext.default
  4675. (ocamlbuild ()) (fix_args ["-clean"] extra_argv);
  4676. BaseLog.register ocamlbuild_clean_ev extra_cli;
  4677. at_exit
  4678. (fun () ->
  4679. try
  4680. BaseLog.unregister ocamlbuild_clean_ev extra_cli
  4681. with _ ->
  4682. ())
  4683. end
  4684. (** Run ocamlbuild, unregister all clean events *)
  4685. let run_ocamlbuild args extra_argv =
  4686. (* TODO: enforce that target in args must be UNIX encoded i.e. toto/index.html
  4687. *)
  4688. OASISExec.run ~ctxt:!BaseContext.default
  4689. (ocamlbuild ()) (fix_args args extra_argv);
  4690. (* Remove any clean event, we must run it again *)
  4691. List.iter
  4692. (fun (e, d) -> BaseLog.unregister e d)
  4693. (BaseLog.filter [ocamlbuild_clean_ev])
  4694. (** Determine real build directory *)
  4695. let build_dir extra_argv =
  4696. let rec search_args dir =
  4697. function
  4698. | "-build-dir" :: dir :: tl ->
  4699. search_args dir tl
  4700. | _ :: tl ->
  4701. search_args dir tl
  4702. | [] ->
  4703. dir
  4704. in
  4705. search_args "_build" (fix_args [] extra_argv)
  4706. end
  4707. module OCamlbuildPlugin = struct
  4708. (* # 21 "/Users/avsm/.opam/system/build/oasis.0.3.0/src/plugins/ocamlbuild/OCamlbuildPlugin.ml" *)
  4709. (** Build using ocamlbuild
  4710. @author Sylvain Le Gall
  4711. *)
  4712. open OASISTypes
  4713. open OASISGettext
  4714. open OASISUtils
  4715. open BaseEnv
  4716. open OCamlbuildCommon
  4717. open BaseStandardVar
  4718. open BaseMessage
  4719. let cond_targets_hook =
  4720. ref (fun lst -> lst)
  4721. let build pkg argv =
  4722. (* Return the filename in build directory *)
  4723. let in_build_dir fn =
  4724. Filename.concat
  4725. (build_dir argv)
  4726. fn
  4727. in
  4728. (* Return the unix filename in host build directory *)
  4729. let in_build_dir_of_unix fn =
  4730. in_build_dir (OASISHostPath.of_unix fn)
  4731. in
  4732. let cond_targets =
  4733. List.fold_left
  4734. (fun acc ->
  4735. function
  4736. | Library (cs, bs, lib) when var_choose bs.bs_build ->
  4737. begin
  4738. let evs, unix_files =
  4739. BaseBuilt.of_library
  4740. in_build_dir_of_unix
  4741. (cs, bs, lib)
  4742. in
  4743. let ends_with nd fn =
  4744. let nd_len =
  4745. String.length nd
  4746. in
  4747. (String.length fn >= nd_len)
  4748. &&
  4749. (String.sub
  4750. fn
  4751. (String.length fn - nd_len)
  4752. nd_len) = nd
  4753. in
  4754. let tgts =
  4755. List.flatten
  4756. (List.filter
  4757. (fun l -> l <> [])
  4758. (List.map
  4759. (List.filter
  4760. (fun fn ->
  4761. ends_with ".cma" fn
  4762. || ends_with ".cmxs" fn
  4763. || ends_with ".cmxa" fn
  4764. || ends_with (ext_lib ()) fn
  4765. || ends_with (ext_dll ()) fn))
  4766. unix_files))
  4767. in
  4768. match tgts with
  4769. | _ :: _ ->
  4770. (evs, tgts) :: acc
  4771. | [] ->
  4772. failwithf
  4773. (f_ "No possible ocamlbuild targets for library %s")
  4774. cs.cs_name
  4775. end
  4776. | Executable (cs, bs, exec) when var_choose bs.bs_build ->
  4777. begin
  4778. let evs, unix_exec_is, unix_dll_opt =
  4779. BaseBuilt.of_executable
  4780. in_build_dir_of_unix
  4781. (cs, bs, exec)
  4782. in
  4783. let target ext =
  4784. let unix_tgt =
  4785. (OASISUnixPath.concat
  4786. bs.bs_path
  4787. (OASISUnixPath.chop_extension
  4788. exec.exec_main_is))^ext
  4789. in
  4790. let evs =
  4791. (* Fix evs, we want to use the unix_tgt, without copying *)
  4792. List.map
  4793. (function
  4794. | BaseBuilt.BExec, nm, lst when nm = cs.cs_name ->
  4795. BaseBuilt.BExec, nm, [[in_build_dir_of_unix unix_tgt]]
  4796. | ev ->
  4797. ev)
  4798. evs
  4799. in
  4800. evs, [unix_tgt]
  4801. in
  4802. (* Add executable *)
  4803. let acc =
  4804. match bs.bs_compiled_object with
  4805. | Native ->
  4806. (target ".native") :: acc
  4807. | Best when bool_of_string (is_native ()) ->
  4808. (target ".native") :: acc
  4809. | Byte
  4810. | Best ->
  4811. (target ".byte") :: acc
  4812. in
  4813. acc
  4814. end
  4815. | Library _ | Executable _ | Test _
  4816. | SrcRepo _ | Flag _ | Doc _ ->
  4817. acc)
  4818. []
  4819. (* Keep the pkg.sections ordered *)
  4820. (List.rev pkg.sections);
  4821. in
  4822. (* Check and register built files *)
  4823. let check_and_register (bt, bnm, lst) =
  4824. List.iter
  4825. (fun fns ->
  4826. if not (List.exists OASISFileUtil.file_exists_case fns) then
  4827. failwithf
  4828. (f_ "No one of expected built files %s exists")
  4829. (String.concat (s_ ", ") (List.map (Printf.sprintf "'%s'") fns)))
  4830. lst;
  4831. (BaseBuilt.register bt bnm lst)
  4832. in
  4833. let cond_targets =
  4834. (* Run the hook *)
  4835. !cond_targets_hook cond_targets
  4836. in
  4837. (* Run a list of target... *)
  4838. run_ocamlbuild
  4839. (List.flatten
  4840. (List.map snd cond_targets))
  4841. argv;
  4842. (* ... and register events *)
  4843. List.iter
  4844. check_and_register
  4845. (List.flatten (List.map fst cond_targets))
  4846. let clean pkg extra_args =
  4847. run_clean extra_args;
  4848. List.iter
  4849. (function
  4850. | Library (cs, _, _) ->
  4851. BaseBuilt.unregister BaseBuilt.BLib cs.cs_name
  4852. | Executable (cs, _, _) ->
  4853. BaseBuilt.unregister BaseBuilt.BExec cs.cs_name;
  4854. BaseBuilt.unregister BaseBuilt.BExecLib cs.cs_name
  4855. | _ ->
  4856. ())
  4857. pkg.sections
  4858. end
  4859. module OCamlbuildDocPlugin = struct
  4860. (* # 21 "/Users/avsm/.opam/system/build/oasis.0.3.0/src/plugins/ocamlbuild/OCamlbuildDocPlugin.ml" *)
  4861. (* Create documentation using ocamlbuild .odocl files
  4862. @author Sylvain Le Gall
  4863. *)
  4864. open OASISTypes
  4865. open OASISGettext
  4866. open OASISMessage
  4867. open OCamlbuildCommon
  4868. open BaseStandardVar
  4869. let doc_build path pkg (cs, doc) argv =
  4870. let index_html =
  4871. OASISUnixPath.make
  4872. [
  4873. path;
  4874. cs.cs_name^".docdir";
  4875. "index.html";
  4876. ]
  4877. in
  4878. let tgt_dir =
  4879. OASISHostPath.make
  4880. [
  4881. build_dir argv;
  4882. OASISHostPath.of_unix path;
  4883. cs.cs_name^".docdir";
  4884. ]
  4885. in
  4886. run_ocamlbuild [index_html] argv;
  4887. List.iter
  4888. (fun glb ->
  4889. BaseBuilt.register
  4890. BaseBuilt.BDoc
  4891. cs.cs_name
  4892. [OASISFileUtil.glob ~ctxt:!BaseContext.default
  4893. (Filename.concat tgt_dir glb)])
  4894. ["*.html"; "*.css"]
  4895. let doc_clean t pkg (cs, doc) argv =
  4896. run_clean argv;
  4897. BaseBuilt.unregister BaseBuilt.BDoc cs.cs_name
  4898. end
  4899. # 5558 "setup.ml"
  4900. module CustomPlugin = struct
  4901. (* # 21 "/Users/avsm/.opam/system/build/oasis.0.3.0/src/plugins/custom/CustomPlugin.ml" *)
  4902. (** Generate custom configure/build/doc/test/install system
  4903. @author
  4904. *)
  4905. open BaseEnv
  4906. open OASISGettext
  4907. open OASISTypes
  4908. type t =
  4909. {
  4910. cmd_main: command_line conditional;
  4911. cmd_clean: (command_line option) conditional;
  4912. cmd_distclean: (command_line option) conditional;
  4913. }
  4914. let run = BaseCustom.run
  4915. let main t _ extra_args =
  4916. let cmd, args =
  4917. var_choose
  4918. ~name:(s_ "main command")
  4919. t.cmd_main
  4920. in
  4921. run cmd args extra_args
  4922. let clean t pkg extra_args =
  4923. match var_choose t.cmd_clean with
  4924. | Some (cmd, args) ->
  4925. run cmd args extra_args
  4926. | _ ->
  4927. ()
  4928. let distclean t pkg extra_args =
  4929. match var_choose t.cmd_distclean with
  4930. | Some (cmd, args) ->
  4931. run cmd args extra_args
  4932. | _ ->
  4933. ()
  4934. module Build =
  4935. struct
  4936. let main t pkg extra_args =
  4937. main t pkg extra_args;
  4938. List.iter
  4939. (fun sct ->
  4940. let evs =
  4941. match sct with
  4942. | Library (cs, bs, lib) when var_choose bs.bs_build ->
  4943. begin
  4944. let evs, _ =
  4945. BaseBuilt.of_library
  4946. OASISHostPath.of_unix
  4947. (cs, bs, lib)
  4948. in
  4949. evs
  4950. end
  4951. | Executable (cs, bs, exec) when var_choose bs.bs_build ->
  4952. begin
  4953. let evs, _, _ =
  4954. BaseBuilt.of_executable
  4955. OASISHostPath.of_unix
  4956. (cs, bs, exec)
  4957. in
  4958. evs
  4959. end
  4960. | _ ->
  4961. []
  4962. in
  4963. List.iter
  4964. (fun (bt, bnm, lst) -> BaseBuilt.register bt bnm lst)
  4965. evs)
  4966. pkg.sections
  4967. let clean t pkg extra_args =
  4968. clean t pkg extra_args;
  4969. (* TODO: this seems to be pretty generic (at least wrt to ocamlbuild
  4970. * considering moving this to BaseSetup?
  4971. *)
  4972. List.iter
  4973. (function
  4974. | Library (cs, _, _) ->
  4975. BaseBuilt.unregister BaseBuilt.BLib cs.cs_name
  4976. | Executable (cs, _, _) ->
  4977. BaseBuilt.unregister BaseBuilt.BExec cs.cs_name;
  4978. BaseBuilt.unregister BaseBuilt.BExecLib cs.cs_name
  4979. | _ ->
  4980. ())
  4981. pkg.sections
  4982. let distclean t pkg extra_args =
  4983. distclean t pkg extra_args
  4984. end
  4985. module Test =
  4986. struct
  4987. let main t pkg (cs, test) extra_args =
  4988. try
  4989. main t pkg extra_args;
  4990. 0.0
  4991. with Failure s ->
  4992. BaseMessage.warning
  4993. (f_ "Test '%s' fails: %s")
  4994. cs.cs_name
  4995. s;
  4996. 1.0
  4997. let clean t pkg (cs, test) extra_args =
  4998. clean t pkg extra_args
  4999. let distclean t pkg (cs, test) extra_args =
  5000. distclean t pkg extra_args
  5001. end
  5002. module Doc =
  5003. struct
  5004. let main t pkg (cs, _) extra_args =
  5005. main t pkg extra_args;
  5006. BaseBuilt.register BaseBuilt.BDoc cs.cs_name []
  5007. let clean t pkg (cs, _) extra_args =
  5008. clean t pkg extra_args;
  5009. BaseBuilt.unregister BaseBuilt.BDoc cs.cs_name
  5010. let distclean t pkg (cs, _) extra_args =
  5011. distclean t pkg extra_args
  5012. end
  5013. end
  5014. # 5694 "setup.ml"
  5015. open OASISTypes;;
  5016. let setup_t =
  5017. {
  5018. BaseSetup.configure = InternalConfigurePlugin.configure;
  5019. build = OCamlbuildPlugin.build;
  5020. test =
  5021. [
  5022. ("re_match",
  5023. CustomPlugin.Test.main
  5024. {
  5025. CustomPlugin.cmd_main =
  5026. [(OASISExpr.EBool true, ("$re_match", []))];
  5027. cmd_clean = [(OASISExpr.EBool true, None)];
  5028. cmd_distclean = [(OASISExpr.EBool true, None)];
  5029. })
  5030. ];
  5031. doc = [("re-api", OCamlbuildDocPlugin.doc_build "./lib")];
  5032. install = InternalInstallPlugin.install;
  5033. uninstall = InternalInstallPlugin.uninstall;
  5034. clean = [OCamlbuildPlugin.clean];
  5035. clean_test =
  5036. [
  5037. ("re_match",
  5038. CustomPlugin.Test.clean
  5039. {
  5040. CustomPlugin.cmd_main =
  5041. [(OASISExpr.EBool true, ("$re_match", []))];
  5042. cmd_clean = [(OASISExpr.EBool true, None)];
  5043. cmd_distclean = [(OASISExpr.EBool true, None)];
  5044. })
  5045. ];
  5046. clean_doc = [("re-api", OCamlbuildDocPlugin.doc_clean "./lib")];
  5047. distclean = [];
  5048. distclean_test =
  5049. [
  5050. ("re_match",
  5051. CustomPlugin.Test.distclean
  5052. {
  5053. CustomPlugin.cmd_main =
  5054. [(OASISExpr.EBool true, ("$re_match", []))];
  5055. cmd_clean = [(OASISExpr.EBool true, None)];
  5056. cmd_distclean = [(OASISExpr.EBool true, None)];
  5057. })
  5058. ];
  5059. distclean_doc = [];
  5060. package =
  5061. {
  5062. oasis_version = "0.3";
  5063. ocaml_version = None;
  5064. findlib_version = None;
  5065. name = "re";
  5066. version = "1.2.1";
  5067. license =
  5068. OASISLicense.DEP5License
  5069. (OASISLicense.DEP5Unit
  5070. {
  5071. OASISLicense.license = "LGPL";
  5072. excption = Some "OCaml linking";
  5073. version = OASISLicense.Version "2.0";
  5074. });
  5075. license_file = None;
  5076. copyrights = [];
  5077. maintainers = [];
  5078. authors =
  5079. ["Jerome Vouillon"; "Thomas Gazagnaire"; "Anil Madhavapeddy"];
  5080. homepage = None;
  5081. synopsis = "Pure OCaml regular expression library";
  5082. description = None;
  5083. categories = [];
  5084. conf_type = (`Configure, "internal", Some "0.3");
  5085. conf_custom =
  5086. {
  5087. pre_command = [(OASISExpr.EBool true, None)];
  5088. post_command = [(OASISExpr.EBool true, None)];
  5089. };
  5090. build_type = (`Build, "ocamlbuild", Some "0.3");
  5091. build_custom =
  5092. {
  5093. pre_command = [(OASISExpr.EBool true, None)];
  5094. post_command = [(OASISExpr.EBool true, None)];
  5095. };
  5096. install_type = (`Install, "internal", Some "0.3");
  5097. install_custom =
  5098. {
  5099. pre_command = [(OASISExpr.EBool true, None)];
  5100. post_command = [(OASISExpr.EBool true, None)];
  5101. };
  5102. uninstall_custom =
  5103. {
  5104. pre_command = [(OASISExpr.EBool true, None)];
  5105. post_command = [(OASISExpr.EBool true, None)];
  5106. };
  5107. clean_custom =
  5108. {
  5109. pre_command = [(OASISExpr.EBool true, None)];
  5110. post_command = [(OASISExpr.EBool true, None)];
  5111. };
  5112. distclean_custom =
  5113. {
  5114. pre_command = [(OASISExpr.EBool true, None)];
  5115. post_command = [(OASISExpr.EBool true, None)];
  5116. };
  5117. files_ab = [];
  5118. sections =
  5119. [
  5120. Library
  5121. ({
  5122. cs_name = "re";
  5123. cs_data = PropList.Data.create ();
  5124. cs_plugin_data = [];
  5125. },
  5126. {
  5127. bs_build = [(OASISExpr.EBool true, true)];
  5128. bs_install = [(OASISExpr.EBool true, true)];
  5129. bs_path = "lib";
  5130. bs_compiled_object = Best;
  5131. bs_build_depends = [];
  5132. bs_build_tools = [ExternalTool "ocamlbuild"];
  5133. bs_c_sources = [];
  5134. bs_data_files = [];
  5135. bs_ccopt = [(OASISExpr.EBool true, [])];
  5136. bs_cclib = [(OASISExpr.EBool true, [])];
  5137. bs_dlllib = [(OASISExpr.EBool true, [])];
  5138. bs_dllpath = [(OASISExpr.EBool true, [])];
  5139. bs_byteopt = [(OASISExpr.EBool true, [])];
  5140. bs_nativeopt = [(OASISExpr.EBool true, [])];
  5141. },
  5142. {
  5143. lib_modules = ["Re"];
  5144. lib_pack = false;
  5145. lib_internal_modules = ["Cset"; "Automata"];
  5146. lib_findlib_parent = None;
  5147. lib_findlib_name = Some "re";
  5148. lib_findlib_containers = [];
  5149. });
  5150. Library
  5151. ({
  5152. cs_name = "re_emacs";
  5153. cs_data = PropList.Data.create ();
  5154. cs_plugin_data = [];
  5155. },
  5156. {
  5157. bs_build = [(OASISExpr.EBool true, true)];
  5158. bs_install = [(OASISExpr.EBool true, true)];
  5159. bs_path = "lib";
  5160. bs_compiled_object = Best;
  5161. bs_build_depends = [InternalLibrary "re"];
  5162. bs_build_tools = [ExternalTool "ocamlbuild"];
  5163. bs_c_sources = [];
  5164. bs_data_files = [];
  5165. bs_ccopt = [(OASISExpr.EBool true, [])];
  5166. bs_cclib = [(OASISExpr.EBool true, [])];
  5167. bs_dlllib = [(OASISExpr.EBool true, [])];
  5168. bs_dllpath = [(OASISExpr.EBool true, [])];
  5169. bs_byteopt = [(OASISExpr.EBool true, [])];
  5170. bs_nativeopt = [(OASISExpr.EBool true, [])];
  5171. },
  5172. {
  5173. lib_modules = ["Re_emacs"];
  5174. lib_pack = false;
  5175. lib_internal_modules = [];
  5176. lib_findlib_parent = Some "re";
  5177. lib_findlib_name = Some "emacs";
  5178. lib_findlib_containers = [];
  5179. });
  5180. Library
  5181. ({
  5182. cs_name = "re_str";
  5183. cs_data = PropList.Data.create ();
  5184. cs_plugin_data = [];
  5185. },
  5186. {
  5187. bs_build = [(OASISExpr.EBool true, true)];
  5188. bs_install = [(OASISExpr.EBool true, true)];
  5189. bs_path = "lib";
  5190. bs_compiled_object = Best;
  5191. bs_build_depends =
  5192. [InternalLibrary "re"; InternalLibrary "re_emacs"];
  5193. bs_build_tools = [ExternalTool "ocamlbuild"];
  5194. bs_c_sources = [];
  5195. bs_data_files = [];
  5196. bs_ccopt = [(OASISExpr.EBool true, [])];
  5197. bs_cclib = [(OASISExpr.EBool true, [])];
  5198. bs_dlllib = [(OASISExpr.EBool true, [])];
  5199. bs_dllpath = [(OASISExpr.EBool true, [])];
  5200. bs_byteopt = [(OASISExpr.EBool true, [])];
  5201. bs_nativeopt = [(OASISExpr.EBool true, [])];
  5202. },
  5203. {
  5204. lib_modules = ["Re_str"];
  5205. lib_pack = false;
  5206. lib_internal_modules = [];
  5207. lib_findlib_parent = Some "re";
  5208. lib_findlib_name = Some "str";
  5209. lib_findlib_containers = [];
  5210. });
  5211. Library
  5212. ({
  5213. cs_name = "re_posix";
  5214. cs_data = PropList.Data.create ();
  5215. cs_plugin_data = [];
  5216. },
  5217. {
  5218. bs_build = [(OASISExpr.EBool true, true)];
  5219. bs_install = [(OASISExpr.EBool true, true)];
  5220. bs_path = "lib";
  5221. bs_compiled_object = Best;
  5222. bs_build_depends = [InternalLibrary "re"];
  5223. bs_build_tools = [ExternalTool "ocamlbuild"];
  5224. bs_c_sources = [];
  5225. bs_data_files = [];
  5226. bs_ccopt = [(OASISExpr.EBool true, [])];
  5227. bs_cclib = [(OASISExpr.EBool true, [])];
  5228. bs_dlllib = [(OASISExpr.EBool true, [])];
  5229. bs_dllpath = [(OASISExpr.EBool true, [])];
  5230. bs_byteopt = [(OASISExpr.EBool true, [])];
  5231. bs_nativeopt = [(OASISExpr.EBool true, [])];
  5232. },
  5233. {
  5234. lib_modules = ["Re_posix"];
  5235. lib_pack = false;
  5236. lib_internal_modules = [];
  5237. lib_findlib_parent = Some "re";
  5238. lib_findlib_name = Some "posix";
  5239. lib_findlib_containers = [];
  5240. });
  5241. Library
  5242. ({
  5243. cs_name = "re_glob";
  5244. cs_data = PropList.Data.create ();
  5245. cs_plugin_data = [];
  5246. },
  5247. {
  5248. bs_build = [(OASISExpr.EBool true, true)];
  5249. bs_install = [(OASISExpr.EBool true, true)];
  5250. bs_path = "lib";
  5251. bs_compiled_object = Best;
  5252. bs_build_depends = [InternalLibrary "re"];
  5253. bs_build_tools = [ExternalTool "ocamlbuild"];
  5254. bs_c_sources = [];
  5255. bs_data_files = [];
  5256. bs_ccopt = [(OASISExpr.EBool true, [])];
  5257. bs_cclib = [(OASISExpr.EBool true, [])];
  5258. bs_dlllib = [(OASISExpr.EBool true, [])];
  5259. bs_dllpath = [(OASISExpr.EBool true, [])];
  5260. bs_byteopt = [(OASISExpr.EBool true, [])];
  5261. bs_nativeopt = [(OASISExpr.EBool true, [])];
  5262. },
  5263. {
  5264. lib_modules = ["Re_glob"];
  5265. lib_pack = false;
  5266. lib_internal_modules = [];
  5267. lib_findlib_parent = Some "re";
  5268. lib_findlib_name = Some "glob";
  5269. lib_findlib_containers = [];
  5270. });
  5271. Library
  5272. ({
  5273. cs_name = "re_perl";
  5274. cs_data = PropList.Data.create ();
  5275. cs_plugin_data = [];
  5276. },
  5277. {
  5278. bs_build = [(OASISExpr.EBool true, true)];
  5279. bs_install = [(OASISExpr.EBool true, true)];
  5280. bs_path = "lib";
  5281. bs_compiled_object = Best;
  5282. bs_build_depends = [InternalLibrary "re"];
  5283. bs_build_tools = [ExternalTool "ocamlbuild"];
  5284. bs_c_sources = [];
  5285. bs_data_files = [];
  5286. bs_ccopt = [(OASISExpr.EBool true, [])];
  5287. bs_cclib = [(OASISExpr.EBool true, [])];
  5288. bs_dlllib = [(OASISExpr.EBool true, [])];
  5289. bs_dllpath = [(OASISExpr.EBool true, [])];
  5290. bs_byteopt = [(OASISExpr.EBool true, [])];
  5291. bs_nativeopt = [(OASISExpr.EBool true, [])];
  5292. },
  5293. {
  5294. lib_modules = ["Re_perl"];
  5295. lib_pack = false;
  5296. lib_internal_modules = [];
  5297. lib_findlib_parent = Some "re";
  5298. lib_findlib_name = Some "perl";
  5299. lib_findlib_containers = [];
  5300. });
  5301. Library
  5302. ({
  5303. cs_name = "re_pcre";
  5304. cs_data = PropList.Data.create ();
  5305. cs_plugin_data = [];
  5306. },
  5307. {
  5308. bs_build = [(OASISExpr.EBool true, true)];
  5309. bs_install = [(OASISExpr.EBool true, true)];
  5310. bs_path = "lib";
  5311. bs_compiled_object = Best;
  5312. bs_build_depends =
  5313. [InternalLibrary "re"; InternalLibrary "re_perl"];
  5314. bs_build_tools = [ExternalTool "ocamlbuild"];
  5315. bs_c_sources = [];
  5316. bs_data_files = [];
  5317. bs_ccopt = [(OASISExpr.EBool true, [])];
  5318. bs_cclib = [(OASISExpr.EBool true, [])];
  5319. bs_dlllib = [(OASISExpr.EBool true, [])];
  5320. bs_dllpath = [(OASISExpr.EBool true, [])];
  5321. bs_byteopt = [(OASISExpr.EBool true, [])];
  5322. bs_nativeopt = [(OASISExpr.EBool true, [])];
  5323. },
  5324. {
  5325. lib_modules = ["Re_pcre"];
  5326. lib_pack = false;
  5327. lib_internal_modules = [];
  5328. lib_findlib_parent = Some "re";
  5329. lib_findlib_name = Some "pcre";
  5330. lib_findlib_containers = [];
  5331. });
  5332. Executable
  5333. ({
  5334. cs_name = "re_match";
  5335. cs_data = PropList.Data.create ();
  5336. cs_plugin_data = [];
  5337. },
  5338. {
  5339. bs_build =
  5340. [
  5341. (OASISExpr.EBool true, false);
  5342. (OASISExpr.EFlag "tests", true)
  5343. ];
  5344. bs_install = [(OASISExpr.EBool true, false)];
  5345. bs_path = "lib_test";
  5346. bs_compiled_object = Best;
  5347. bs_build_depends = [InternalLibrary "re"];
  5348. bs_build_tools = [ExternalTool "ocamlbuild"];
  5349. bs_c_sources = [];
  5350. bs_data_files = [];
  5351. bs_ccopt = [(OASISExpr.EBool true, [])];
  5352. bs_cclib = [(OASISExpr.EBool true, [])];
  5353. bs_dlllib = [(OASISExpr.EBool true, [])];
  5354. bs_dllpath = [(OASISExpr.EBool true, [])];
  5355. bs_byteopt = [(OASISExpr.EBool true, [])];
  5356. bs_nativeopt = [(OASISExpr.EBool true, [])];
  5357. },
  5358. {exec_custom = true; exec_main_is = "re_match.ml"; });
  5359. Test
  5360. ({
  5361. cs_name = "re_match";
  5362. cs_data = PropList.Data.create ();
  5363. cs_plugin_data = [];
  5364. },
  5365. {
  5366. test_type = (`Test, "custom", Some "0.3");
  5367. test_command =
  5368. [(OASISExpr.EBool true, ("$re_match", []))];
  5369. test_custom =
  5370. {
  5371. pre_command = [(OASISExpr.EBool true, None)];
  5372. post_command = [(OASISExpr.EBool true, None)];
  5373. };
  5374. test_working_directory = Some "lib_test";
  5375. test_run =
  5376. [
  5377. (OASISExpr.ENot (OASISExpr.EFlag "tests"), false);
  5378. (OASISExpr.EFlag "tests", false);
  5379. (OASISExpr.EAnd
  5380. (OASISExpr.EFlag "tests",
  5381. OASISExpr.EFlag "tests"),
  5382. true)
  5383. ];
  5384. test_tools = [ExternalTool "ocamlbuild"];
  5385. });
  5386. Doc
  5387. ({
  5388. cs_name = "re-api";
  5389. cs_data = PropList.Data.create ();
  5390. cs_plugin_data = [];
  5391. },
  5392. {
  5393. doc_type = (`Doc, "ocamlbuild", Some "0.3");
  5394. doc_custom =
  5395. {
  5396. pre_command = [(OASISExpr.EBool true, None)];
  5397. post_command = [(OASISExpr.EBool true, None)];
  5398. };
  5399. doc_build =
  5400. [
  5401. (OASISExpr.ENot (OASISExpr.EFlag "docs"), false);
  5402. (OASISExpr.EFlag "docs", true)
  5403. ];
  5404. doc_install = [(OASISExpr.EBool true, true)];
  5405. doc_install_dir = "$htmldir/api";
  5406. doc_title = "API reference for Re";
  5407. doc_authors = [];
  5408. doc_abstract = None;
  5409. doc_format = OtherDoc;
  5410. doc_data_files = [];
  5411. doc_build_tools =
  5412. [ExternalTool "ocamlbuild"; ExternalTool "ocamldoc"];
  5413. })
  5414. ];
  5415. plugins = [(`Extra, "META", Some "0.3")];
  5416. schema_data = PropList.Data.create ();
  5417. plugin_data = [];
  5418. };
  5419. oasis_fn = Some "_oasis";
  5420. oasis_version = "0.3.0";
  5421. oasis_digest = Some "ímźm-\149§3eá\003SŐ 5\143";
  5422. oasis_exec = None;
  5423. oasis_setup_args = [];
  5424. setup_update = false;
  5425. };;
  5426. let setup () = BaseSetup.setup setup_t;;
  5427. # 6111 "setup.ml"
  5428. (* OASIS_STOP *)
  5429. let () = setup ();;