text stringlengths 12 786k |
|---|
let flatten ls = let rec push acc = function v :: vs -> push ( v :: acc ) acc vs | [ ] -> acc in let rec loop acc = function | l :: ls -> loop ( push acc l ) l ls | [ ] -> acc in loop [ ] ls |
let split_ext s = match Topkg_string . cut ~ rev : true s ~ sep : ' . ' with |
let bin_drop_exts native = if native then [ ] else Topkg_fexts . ext " . native " |
let lib_drop_exts native native_dynlink supports_shared_libraries = match native with | false -> Topkg_fexts ( . c_library @ exts [ " . cmx " ; " . cmxa " ; " . cmxs ] ) " | true -> match supports_shared_libraries with | false -> ` Dll :: Topkg_fexts . ext " . cmxs " | true -> ma... |
let to_build ? header c os i = let bdir = Topkg_conf . build_dir c in let debugger_support = Topkg_conf . debugger_support c in let build_tests = Topkg_conf . build_tests c in let ocaml_conf = Topkg_conf . OCaml . v c os in let native = Topkg_conf . OCaml . native ocaml_conf in let native_dylink = Topkg_co... |
type field = ? force : bool -> ? built : bool -> ? cond : bool -> ? exts : Topkg_fexts . t -> ? dst : string -> string -> t |
let _field field ( ? debugger_support = false ) false ( ? auto = true ) true ( ? force = false ) false ( ? built = true ) true ( ? cond = true ) true ( ? exts = [ ] ) ? dst src = if not cond then [ ] else let dst = match dst with | None -> Topkg_fpath . basename src |... |
let field field = _field ~ debugger_support : false ~ auto : false field |
let field_exec field ? auto ? force ? built ? cond ? exts ? dst src = _field field ~ debugger_support : false ? auto ? force ? built ? cond ? exts ? dst src |
let bin = field_exec ` Bin |
let doc = field ` Doc |
let etc = field ` Etc |
let lib = field ` Lib |
let lib_root = field ` Lib_root |
let libexec = field_exec ` Libexec |
let libexec_root = field_exec ` Libexec_root |
let man = field ` Man |
let misc = field ` Misc |
let sbin = field_exec ` Sbin |
let share = field ` Share |
let share_root = field ` Share_root |
let stublibs = field ` Stublibs |
let toplevel = field ` Toplevel |
let unknown name = field ( ` Unknown name ) name |
let test ( ? run = true ) true ? dir ( ? args = Topkg_cmd . empty ) empty = field_exec ( ` Test ( run , dir , args ) args ) args |
let parse_mllib contents = let lines = Topkg_string . cuts ~ sep : ' \ n ' contents in let add_mod acc l = let path = String . trim @@ match Topkg_string . cut ~ sep : ' # ' l with | None -> l | Some ( p , _ ) -> p in if path = " " then acc else let mod_name = Topkg_string . capital... |
let field_of_field field = match ( List . hd ( field ) ) " " . field with | ` Test ( run , dir , args ) args -> assert false | # Topkg_opam . Install . field as field -> field |
let mllib ( ? field = lib ) lib ( ? cond = true ) true ( ? cma = true ) true ( ? cmxa = true ) true ( ? cmxs = true ) true ? api ? dst_dir mllib = if not cond then [ ] else let debugger_support_field = _field ~ debugger_support : true ~ auto : false ( field_of_field field ) ... |
let parse_clib contents = let lines = Topkg_string . cuts ~ sep : ' \ n ' contents in let add_obj_path acc l = let path = String . trim @@ match Topkg_string . cut ~ sep : ' # ' l with | None -> l | Some ( p , _ ) -> p in if path = " " then acc else path :: acc in List . fold_left ... |
let clib ( ? dllfield = stublibs ) stublibs ( ? libfield = lib ) lib ( ? cond = true ) true ? lib_dst_dir clib = if not cond then [ ] else let debugger_support_field = _field ~ debugger_support : true ~ auto : false ( field_of_field lib ) lib in let lib_dir = Topkg_fpath . dirname cl... |
let codec : t Topkg_codec . t = let fields = ( fun _ -> ( ) ) , ( fun ( ) -> [ ] ) in Topkg_codec . version 0 @@ Topkg_codec ( . view ~ kind " : install " fields unit ) unit |
type ' a t = { cmd : Topkg_cmd . t ; codec : ' a Topkg_codec . t ; answer : Topkg_fpath . t ; } |
let v ? answer cmd codec = let answer = match answer with | Some a -> a | None -> ( Topkg_os . File . tmp ( ) ) |> R . reword_error_msg ~ replace : true ( fun m -> R . msgf " Could not create IPC answer file : % s , using stdout " m ) m |> Topkg_log . on_error_msg ~ use ( : fu... |
let cmd ipc = ipc . cmd |
let codec ipc = ipc . codec |
let answer ipc = ipc . answer |
let error_args args = R . error_msgf " IPC : % a , unknown arguments " Topkg_cmd . dump ( Topkg_cmd . of_list args ) args |
let pkg ( ) = v Topkg_cmd ( . v " pkg ) " Topkg_pkg . codec |
let answer_pkg answer p = Topkg_codec . write answer Topkg_pkg . codec p |
let lint_custom_codec = Topkg_codec ( . option @@ list @@ result_error_msg @@ msg ) msg |
let lint_custom ( ) = let cmd = Topkg_cmd ( . v " lint " % " custom ) " in v cmd lint_custom_codec |
let answer_lint_custom answer p = let custom_run = match ( Topkg_pkg . lint_custom p ) p with | None -> None | Some custom -> Some ( custom ( ) ) in Topkg_codec . write answer lint_custom_codec custom_run |
let distrib_prepared_codec = Topkg_codec . version 0 @@ Topkg_codec ( . with_kind " prepared " @@ result_error_msg ( list fpath ) fpath ) fpath |
let distrib_prepare ~ dist_build_dir ~ name ~ version ~ opam ~ opam_adds = let cmd = Topkg_cmd ( . v " distrib " % " prepare " % " dist - build - dir " % dist_build_dir % " name " % name % " version " % version % " opam " % opam % " opam - adds " % opam_adds ) opam... |
let answer_distrib_prepare answer p ~ dist_build_dir ~ name ~ version ~ opam ~ opam_adds = Topkg_codec . write answer distrib_prepared_codec @@ Topkg_pkg . distrib_prepare p ~ dist_build_dir ~ name ~ version ~ opam ~ opam_adds |
let write_answer cmd p = match Topkg_cmd . to_list cmd with answer_pkg answer p answer_lint_custom answer p " dist - build - dir " :: dist_build_dir :: " name " :: name :: " version " :: version :: " opam " :: opam :: " opam - adds " :: opam_adds :: [ ] -> answer_distrib_prepare ... |
type level = App | Error | Warning | Info | Debug |
let exec = match Array . length Sys . argv with |
let _level = let default = Some Warning in let init = try match Sys . getenv " TOPKG_VERBOSITY " with | l when Topkg_string . is_prefix ~ affix " : quiet " l -> None | l when Topkg_string . is_prefix ~ affix " : error " l -> Some Error | l when Topkg_string . is_prefix ~ affix " : warning " ... |
let level ( ) = ! _level |
let set_level l = _level := l |
type ' a msgf = ( ? header : string -> ( ' a , Format . formatter , unit ) unit format -> ' a ) ' a -> unit |
let _err_count = ref 0 |
let err_count ( ) = ! _err_count |
let _warn_count = ref 0 |
let warn_count ( ) = ! _warn_count |
let pp_level_header ppf ( h , l ) l = match h with Format . pp_print_string ppf begin match l with | App -> " " | Error -> [ " ERROR ] ERROR " | Warning -> [ " WARNING ] WARNING " | Info -> [ " INFO ] INFO " | Debug -> [ " DEBUG ] DEBUG " end |
let msg level msgf = match ! _level with if level = Error then incr _err_count else if level = Warning then incr _warn_count else ( ) ( if level = Error then incr _err_count else if level = Warning then incr _warn_count else ( ) ) ; let pr = if level = App then Format . printf else Format . ... |
let app msgf = msg App msgf |
let err msgf = msg Error msgf |
let warn msgf = msg Warning msgf |
let info msgf = msg Info msgf |
let debug msgf = msg Debug msgf |
let on_error_msg ( ? level = Error ) Error ~ use = function |
let exec = match Array . length Sys . argv with |
let usage ( ) = Topkg_string . strf " Usage : % s COMMAND [ OPTION ] OPTION . . . " exec |
let try_help ( ) = Topkg_string . strf " % s \ nTry ` % s -- help ' for more information . " ( usage ( ) ) exec |
let pp_help ppf ( ) = let prf = Format . fprintf in prf ppf [ " @< v , " ; >@ prf ppf " Commands , " ; :@ prf ppf " build [ OPTION ] OPTION . . . , " ; @ prf ppf " [ @ Build the package , see ` Build options ' below ] . , " ; @@ prf ppf " test [ OPTION ] OPTION . . . [ TEST ... |
let help_cmd pkg = let pr = Format . printf in let name = Topkg_pkg . name pkg in pr " % s ' s % s - Describes the % s package . . " @ name exec name ; pr " % s . " @ ( usage ( ) ) ; pr " % a . " @ pp_help ( ) ; Ok 0 |
let version_cmd pkg = print_endline " topkg %% VERSION " ; %% Ok 0 |
let build_cmd pkg kind args = let log_conf c = Topkg_log . info ( fun m -> m " Build configuration :@\ n % a " Topkg_conf . dump c ) c in let adjust_pkg_to_conf pkg c = let name = Topkg_conf . pkg_name c in let build_dir = Topkg_conf . build_dir c in Topkg_pkg . with_name_and_build_dir pkg ~ name ... |
let test_cmd pkg name build_dir list tests args = let pkg = Topkg_pkg . with_name_and_build_dir ? name ? build_dir pkg in Topkg_pkg . test pkg ~ list ~ tests ~ args |
let clean_cmd pkg name build_dir = let pkg = Topkg_pkg . with_name_and_build_dir ? name ? build_dir pkg in Topkg_pkg . clean pkg ` Host_os |
let ipc_cmd pkg args = Topkg_ipc . write_answer ( Topkg_cmd . of_list args ) args pkg >>= fun ( ) -> Ok 0 |
let run_cmd pkg cmd args = match cmd with test_cmd pkg pkg_name bdir list tests args |
let default_verb = Topkg_log . level ( ) |
let is_opt s = Topkg_string ( . is_prefix ~ affix " " :- s || is_prefix ~ affix " " :-- s ) s |
let parse_cli_help_version_verbosity args = let is_help = function " - h " | " -- help " | " - help " -> true | _ -> false in let is_verb = function " - v " | " -- verbose " -> true | _ -> false in let is_quiet = function " - q " | " -- quiet " -> true | _ -> false in let is_ver... |
let parse_build_args args = let rec loop dry_run raws acc = function | ( " - r " | " -- raw " as opt ) opt :: args -> if args = [ ] then R . error_msgf " option ` % s ' : missing argument " opt else loop dry_run ( List . hd args :: raws ) raws acc ( List . tl args ) args | ( ... |
let parse_test_args args = let rec loop pkg_name build_dir list tests = function | ( " " -- :: args ) args -> Ok ( pkg_name , build_dir , list , List . rev tests , Some ( Topkg_cmd . of_list args ) args ) args | [ ] -> Ok ( pkg_name , build_dir , list , List . rev tests , N... |
let parse_clean_args args = let rec loop pkg_name build_dir = function | " -- build - dir " :: bdir :: args -> loop pkg_name ( Some bdir ) bdir args | ( " - n " | " -- pkg - name ) " :: n :: args -> loop ( Some n ) n build_dir args | [ ] -> Ok ( pkg_name , build_dir ) build... |
let parse_ipc_args args = begin match args with | [ ] -> R . error_msg " missing verbosity and IPC arguments " | verbosity :: args -> Topkg_log . level_of_string verbosity >>= fun verbosity -> match args with | [ ] -> R . error_msg " no IPC arguments specified " | args -> Ok ( verbosity... |
let parse_cli ( ) = let args = List . tl ( Array . to_list Sys . argv ) argv in begin match args with | " ipc " :: args -> parse_ipc_args args >>= fun ( verb , args ) args -> Ok ( ` Ipc , verb , args ) args | args -> match parse_cli_help_version_verbosity args with | ` Help ... |
let check_log ret = let msg = format_of_string " Package description has % d % s , see log above . " in let log kind count = if count > 0 then match kind with | ` Errs -> Topkg_log . err ( fun m -> m msg count " error ( errors ) errors ) " | ` Warns -> Topkg_log . warn ( fun m -> ... |
let setup_log_level level = Topkg_log . set_level level ; Topkg_log . info ( fun m -> m " topkg %% VERSION , %% running main ) " ; Ok ( ) |
let main pkg = begin parse_cli ( ) >>= fun ( cmd , log_level , args ) args -> setup_log_level log_level >>= fun ( ) -> run_cmd pkg cmd args >>= fun ret -> match cmd with | ` Build _ -> ( check_log ret ) ret | _ -> Ok ret end |> Topkg_log . on_error_msg ~ use ( : fun ( ) -> ... |
let must_run_main = ref true |
let disable ( ) = must_run_main := false |
let pkg = ref None |
let describe ? delegate ? readmes ? licenses ? change_logs ? metas ? opams ? lint_files ? lint_custom ? distrib ? publish ? build name installs = match ! pkg with | Some _ -> invalid_arg " Topkg . Pkg . describe already called once " | None -> let p = Topkg_pkg . v ? delegate ? readmes ? ... |
let check_something_useful_happened ( ) = if ! must_run_main then Topkg_log . err ( fun m -> m " % a " Topkg_string . pp_text " No package description found . A syntax error may have \ occured or did you forget to call Topkg . Pkg . describe ) " ? |
let ( ) = at_exit check_something_useful_happened |
module File = struct type t = ( string * string list ) list list let codec = Topkg_codec . version 0 @@ Topkg_codec . with_kind " opam fields " @@ Topkg_codec ( . list ( pair string ( list string ) string ) string ) string let topkg_cmd = Topkg_cmd . v " topkg " let topkg_cmd_availa... |
module Install = struct type field = [ ` Bin | ` Doc | ` Etc | ` Lib | ` Lib_root | ` Libexec | ` Libexec_root | ` Man | ` Misc | ` Sbin | ` Share | ` Share_root | ` Stublibs | ` Toplevel | ` Unknown of string ] let field_to_string = function | ` Bin -> " bin " ... |
module Env = struct let var name = try Some ( Sys . getenv name ) name with Not_found -> None let opt_var name ~ absent = match var name with None -> absent | Some v -> v end |
module Dir = struct let exists dir = try Ok ( Sys ( . file_exists dir && is_directory dir ) dir ) dir with | Sys_error e -> R . error_msgf " % s : % s " dir e let must_exist dir = exists dir >>= function | true -> Ok dir | false -> R . error_msgf " % s : no such directory " dir let curre... |
module File = struct let null = match Sys . os_type with | " Win32 " -> " NUL " | _ -> " / dev / null " let dash = " " - let exists f = try Ok ( Sys ( . file_exists f && not ( is_directory f ) f ) f ) f with | Sys_error e -> R . error_msgf " % s : % s " f e let must_exist f... |
module Cmd = struct let err_empty_line = " no command , empty command line " let line ? stdout ? stderr cmd = let strf = Printf . sprintf in if Topkg_cmd . is_empty cmd then failwith err_empty_line else let cmd = List . rev_map Filename . quote ( Topkg_cmd . to_rev_list cmd ) cmd in let cmd = St... |
type std_file = Topkg_fpath . t * bool |
let std_file ( ? install = true ) true file = file , install |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.