text stringlengths 0 601k |
|---|
let get_ncpus ( ) = let on_fail ( ) = 1 in let decode_int = Topkg_codec ( . dec_result int ) int in if Sys . win32 then match Topkg_os . Env . var " NUMBER_OF_PROCESSORS " with | Some s -> decode_int s |> Topkg_log . on_error_msg ~ level : Topkg_log . Debug ~ use : on_fail | None -> on_fail ( ) else let run_tool name a... |
let jobs = let doc = " Allow to run ( $ docv ) docv commands at once when building . " in let absent ( ) = Ok None in discovered_key " jobs " ( some int ) int ~ absent ~ doc ~ docv " : JOBS " |
let jobs c = match value c jobs with match build_context c with | ` Dev -> get_ncpus ( ) | _ -> default_jobs |
module OCaml = struct type conf = t let conf fmt = " OCaml % s conf : " ^^ fmt let conf_key fmt = conf ( " key % s : " ^^ fmt ) fmt type t = { os : os ; mutable conf : ( string * string ) string list ; } let empty os = { os ; conf = [ ] } let read_config c os = let parse_line acc l = match Topkg_string . cut ~ sep : ' ... |
type watermark = string * [ ` String of string | ` Name | ` Version | ` Version_num | ` Vcs of [ ` Commit_id ] | ` Opam of Topkg_fpath . t option * string * string ] |
let opam_fields file = ( Topkg_opam . File . fields file ) file |> R . reword_error_msg ~ replace : true ( fun msg -> R . msgf " Watermarks : % s " msg ) msg |> Topkg_log . on_error_msg ~ level : Topkg_log . Warning ~ use ( : fun ( ) -> [ ] ) |
let opam_field = let find k m = try Some ( List . assoc k m ) m with Not_found -> None in let opam_memo = ref [ ] in let rec opam_field file field = match find file ! opam_memo with | None -> opam_memo := ( file , ( opam_fields file ) file ) file :: ! opam_memo ; opam_field file field | Some fields -> match find field ... |
let vcs_commit_id ( ) = ( Topkg_vcs . get ( ) >>= fun repo -> Topkg_vcs . head ~ dirty : true repo ) repo |> R . reword_error_msg ~ replace : true ( fun msg -> R . msgf " Watermarks : VCS commit id determination : % s " msg ) msg |> Topkg_log . on_error_msg ~ level : Topkg_log . Warning ~ use ( : fun ( ) -> " UNDEFINED... |
let define_watermarks ~ name ~ version ~ opam watermarks = let define ( id , v ) v = let ( id , v as def ) def = match v with | ` String s -> ( id , s ) s | ` Version -> ( id , version ) version | ` Version_num -> ( id , Topkg_string . drop_initial_v version ) version | ` Name -> ( id , name ) name | ` Vcs ` Commit_id ... |
let watermark_file ws file = Topkg_os . File . read file >>= fun content -> Topkg_os . File . write_subst file ws content >>= fun ( ) -> Topkg_log . info ( fun m -> m " Watermarked % s " file ) file ; Ok ( ) |
let rec watermark_files ws = function |
let default_watermarks = let space = " " in let comma = " , " in [ " NAME " , ` Name ; " VERSION " , ` Version ; " VERSION_NUM " , ` Version_num ; " VCS_COMMIT_ID " , ` Vcs ` Commit_id ; " PKG_MAINTAINER " , ` Opam ( None , " maintainer " , comma ) comma ; " PKG_AUTHORS " , ` Opam ( None , " authors " , comma ) comma ;... |
let default_files_to_watermark = let is_file f = Topkg_os . File . exists f |> Topkg_log . on_error_msg ~ use ( : fun _ -> false ) false in let is_binary_ext ext = let module Set = Set . Make ( String ) String in let exts = Set ( . empty |> add " . eps " |> add " . flv " |> add " . gif " |> add " . ico " |> add " . jpe... |
let default_massage ( ) = Ok ( ) |
let default_exclude_paths ( ) = Ok [ " . git " ; " . gitignore " ; " . gitattributes " ; " . hg " ; " . hgignore " ; " build " ; " Makefile " ; " _build ] " |
type t = { watermarks : watermark list ; files_to_watermark : unit -> Topkg_fpath . t list result ; massage : unit -> unit result ; exclude_paths : unit -> Topkg_fpath . t list result ; uri : string option ; } |
let v ( ? watermarks = default_watermarks ) default_watermarks ( ? files_to_watermark = default_files_to_watermark ) default_files_to_watermark ( ? massage = fun ( ) -> Ok ( ) ) ( ? exclude_paths = default_exclude_paths ) default_exclude_paths ? uri ( ) = { watermarks ; files_to_watermark ; massage ; exclude_paths ; ur... |
let watermarks d = d . watermarks |
let files_to_watermark d = d . files_to_watermark |
let massage d = d . massage |
let exclude_paths d = d . exclude_paths |
let uri d = d . uri |
let codec = let uri = Topkg_codec ( . with_kind " uri " @@ option string ) string in let fields = let stub ( ) = invalid_arg " not executable outside package definition " in ( fun d -> d . uri ) uri , ( fun uri -> { watermarks = [ ] ; files_to_watermark = stub ; massage = stub ; exclude_paths = stub ; uri } ) in Topkg_... |
let dir_sep_prefix s = Topkg_string . is_prefix ~ affix : Filename . dir_sep s || ( String . length s > 0 && s [ . 0 ] 0 = ' / ' ) ' |
let dir_sep_suffix s = Topkg_string . is_suffix ~ affix : Filename . dir_sep s || ( String . length s > 0 && s [ . String . length s - 1 ] 1 = ' / ' ) ' |
let append = fun p q -> match p with | " " -> q | p -> match q with | " " -> p | q -> if dir_sep_prefix q then q else if dir_sep_suffix p then ( p ^ q ) q else ( p ^ " " / ^ q ) q |
let ( // ) = append |
let is_dir_path p = match p with let is_suffix affix = Topkg_string . is_suffix ~ affix p in List . exists is_suffix [ " " ; / " . . " ; / ] " . " / |
let is_file_path p = not ( is_dir_path p ) p |
let basename s = Filename . basename s |
let dirname s = Filename . dirname s |
let last_dot_index s = try Some ( String . rindex s ' . ' ) ' with Not_found -> None |
let get_ext s = match last_dot_index s with |
let has_ext e p = Topkg_string . is_suffix ~ affix : e p |
let rem_ext s = match last_dot_index s with |
type move_scheme = { field : [ ` Test of bool * Topkg_fpath . t option * Topkg_cmd . t | Topkg_opam . Install . field ] ; auto_bin : bool ; force : bool ; built : bool ; exts : Topkg_fexts . t ; src : string ; dst : string ; debugger_support : bool ; } |
type t = move_scheme list |
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 -> match native_dynlink with | false -> Topkg... |
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_conf . OCaml . ... |
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 | Some dst -> if Topkg_fpath . is_file_path dst then ... |
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 . capitalize_ascii @@ Topkg_fpath . basename p... |
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 ) field in let lib_dir = Topkg_fpath . dirname ... |
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 add_obj_path [ ] lines |
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 clib in let lib_base = let base = Topk... |
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 ( : fun ( ) -> Topkg_os . File . dash ) dash in l... |
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_adds in v cmd distrib_prepared_codec |
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 answer p ~ dist_build_dir ~ name ~ versi... |
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 " l -> Some Warning | l when T... |
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 . eprintf in msgf @@ ( fun ? h... |
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 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.