text stringlengths 12 786k |
|---|
type ' a conv = { parse : ( string -> ' a result ) result ; print : ( Format . formatter -> ' a -> unit ) unit ; docv : string ; } |
let conv ( ? docv = " VALUE ) " parse print = { parse ; print ; docv } |
let conv_parser conv = conv . parse |
let conv_printer conv = conv . print |
let conv_docv conv = conv . docv |
let conv_with_docv conv ~ docv = { conv with docv } |
let bool = let parse s = try Ok ( bool_of_string s ) s with | Invalid_argument _ -> R . error_msgf " % S : Can ' t parse boolean value " s in conv ~ docv " : BOOL " parse Format . pp_print_bool |
let int = let parse s = try Ok ( int_of_string s ) s with | Failure _ -> R . error_msgf " % S : Can ' t parse integer value " s in conv ~ docv " : INT " parse Format . pp_print_int |
let string = conv ~ docv " : STRING " ( fun s -> Ok s ) s Format . pp_print_string |
let fpath = conv_with_docv string ~ docv " : PATH " |
let some ( ? none = ) " " conv = let parse s = match conv . parse s with | Ok v -> Ok ( Some v ) v | Error _ as e -> e in let print ppf = function | None -> Format . pp_print_string ppf none | Some v -> conv . print ppf v in { conv with parse ; print } |
let univ ( type s ) s ( ) = let module M = struct exception E of s option end in ( fun x -> M . E ( Some x ) x ) x , ( function M . E x -> x | _ -> None ) None |
let key_id = let count = ref ( - 1 ) 1 in fun ( ) -> incr count ; ! count |
type ' a absent = Value of ' a | Discover of ( unit -> ' a result ) result |
type ' a key = { id : int ; name : string ; conv : ' a conv ; absent : ' a absent ; env : string option ; to_univ : ' a -> univ ; of_univ : univ -> ' a option ; doc : string ; } |
module Key = struct type t = V : ' a key -> t let compare ( V k0 ) k0 ( V k1 ) k1 = ( compare : int -> int -> int ) int k0 . id k1 . id end |
module Kset = Set . Make ( Key ) Key |
module Kmap = Map . Make ( Key ) Key |
let key_index = ref Kset . empty |
let cli_opts_of_key_index ( ) = let add_key ( Key . V k as key ) key acc = ( " " -- ^ k . name , key ) key :: acc in Kset . fold add_key ! key_index [ ] |
let _key ? docv ( ? doc = " Undocumented ) " ? env name conv absent = let id = key_id ( ) in let to_univ , of_univ = univ ( ) in let conv = match docv with | None -> conv | Some docv -> conv_with_docv conv ~ docv in let key = { id ; name ; conv ; absent ; env ; to_univ ; o... |
let key ? docv ? doc ? env name conv ~ absent = _key ? docv ? doc ? env name conv ( Value absent ) absent |
let discovered_key ? docv ? doc ? env name conv ~ absent = _key ? docv ? doc ? env name conv ( Discover absent ) absent |
let key_absent_value k = let absent_field k = match k . absent with | Value v -> v | Discover discover -> match discover ( ) with | Ok v -> v | Error ( ` Msg m ) m -> failwith ( Topkg_string . strf " key % s : % s " k . name m ) m in match k . env with | None -> absent_field k | S... |
let with_pkg ( ? default = true ) true pkg = let doc = Topkg_string . strf " true if package % s is installed . " pkg in key ( " with " - ^ pkg ) pkg bool ~ absent : default ~ doc |
let pkg_name = let doc = " The name ( $ docv ) docv of the package ( and hence the opam install \ file ) file . If absent provided by the package description . " in let absent ( ) = assert false in discovered_key " pkg - name " string ~ absent ~ doc ~ docv " : NAME " |
let build_dir = let doc = " Specifies the build directory ( $ docv ) docv . " in let absent ( ) = assert false in discovered_key " build - dir " string ~ absent ~ doc ~ docv " : BUILD_DIR " |
let vcs = let doc = " Specifies if the package directory is VCS managed . " in let absent ( ) = Topkg_vcs . find ~ dir " . " : ( ) >>= function | None -> Ok false | Some _ -> Ok true in discovered_key " vcs " bool ~ absent ~ doc |
let pinned = let doc = " Deprecated , use -- dev - pkg . The semantics is the same . " in key " pinned " bool ~ absent : false ~ doc |
let dev_pkg = let doc = " Specifies that the build is a dev package build ( e . g . in opam ) opam . " in key " dev - pkg " bool ~ absent : false ~ doc |
let tests = let doc = " Specifies whether tests should be built . If absent depends \ on the build context , true for development and false otherwise . " in let absent ( ) = Ok None in discovered_key " tests " ( some bool ) bool ~ absent ~ doc |
let debug = let doc = " Debug build . Save debugging information in build artefacts . This \ key should not be specified explicitly in your package build \ instructions . " in key " debug " bool ~ env " : TOPKG_CONF_DEBUG " ~ absent : true ~ doc |
let debugger_support = let doc = " Debugger support . Build and install build artefacts needed \ by debuggers . This key should not be specified explicitly in \ your package build instructions . " in key " debugger - support " bool ~ env " : TOPKG_CONF_DEBUGGER_SUPPORT " ~ absent : false ~ doc |
let profile = let doc = " Profiling build . Include run - time profiling support in build \ artefacts . This key should not be specified explicitly \ in your package build instructions . " in key " profile " bool ~ env " : TOPKG_CONF_PROFILE " ~ absent : false ~ doc |
let toolchain = let doc = " Specifies the ocamlfind toolchain . " in key " toolchain " ( some string ) string ~ env " : TOPKG_CONF_TOOLCHAIN " ~ absent : None ~ doc |
let pp_cli_opt ppf opt_name absent env doc docv = let prf = Format . fprintf in let pp_doc ppf doc = let subst = function " docv " -> docv | s -> Topkg_string . strf ( " $% s ) s " s in let b = Buffer . create 244 in let doc = try Buffer . add_substitute b subst doc ; Buffer . contents b wit... |
let pp_key ppf k = let absent = match k . absent with | Discover _ -> " discovered " | Value v -> Topkg_string . strf [ " @< h >% a ] " @ ( conv_printer k . conv ) conv v in let opt_name = match k . name with | " pkg - name " -> " - n NAME , -- pkg - name " | n -> Topkg_strin... |
let pp_keys_cli_opts ppf ( ) = let pp_key is_first ( Key . V k ) k = if is_first then ( ) else Format . pp_print_cut ppf ( ) ; pp_key ppf k ; false in let by_name ( Key . V k ) k ( Key . V k ' ) k ' = compare k . name k ' . name in let keys = List . sort by_name ( Kset... |
type t = univ Kmap . t |
let mem k c = Kmap . mem ( Key . V k ) k c |
let add k v c = Kmap . add ( Key . V k ) k ( k . to_univ v ) v c |
let rem k c = Kmap . remove ( Key . V k ) k c |
let find k c = try k . of_univ ( Kmap . find ( Key . V k ) k c ) c with Not_found -> None |
let value c k = match find k c with invalid_arg ( Topkg_string . strf " configuration key % s undefined , did you create a key after the call to Pkg . describe " ? k . name ) name |
let pp_value c ppf k = k . conv . print ppf ( value c k ) k |
let dump ppf c = let dump_binding ( Key . V k ) k v is_first = if is_first then ( ) else Format . pp_print_cut ppf ( ) ; match k . of_univ v with | None -> assert false | Some v -> Format . fprintf ppf " % s : [ @% a ] " @ k . name ( conv_printer k . conv ) conv v ; false in Fo... |
let of_cli_args ~ pkg_name : name ~ build_dir : bdir args = let cli_opts = cli_opts_of_key_index ( ) in let cli_opts = ( " - n " , Key . V pkg_name ) pkg_name :: cli_opts in let strf = Topkg_string . strf in let rec parse_keys conf = function | key :: def :: defs -> begin match try Some ( L... |
let pkg_name c = value c pkg_name |
let build_dir c = value c build_dir |
let toolchain c = value c toolchain |
let vcs c = value c vcs |
let pinned c = value c pinned |
let dev_pkg c = value c dev_pkg |
type build_context = [ ` Dev | ` Distrib | ` Pin ] |
let build_context c = if not ( vcs c ) c then ` Distrib else if ( pinned c || dev_pkg c ) c then ` Pin else ` Dev |
let build_tests c = match value c tests with match build_context c with | ` Dev -> true | _ -> false |
let debug c = value c debug |
let debugger_support c = value c debugger_support |
let profile c = value c profile |
type os = [ ` Build_os | ` Host_os ] |
let os_tool_env name os = let pre = match os with ` Build_os -> " BUILD_OS_ " | ` Host_os -> " HOST_OS_ " in pre ^ Topkg_string . uppercase_ascii name |
let ocamlfindable ? conf name os = match name with let toolchain = match conf with | None -> Topkg_cmd . empty | Some c -> match os , toolchain c with | ` Host_os , Some toolchain -> Topkg_cmd ( . v " - toolchain " % toolchain ) toolchain | _ -> Topkg_cmd . empty in Some Topkg_cmd ( . ... |
let tool ? conf name os = match Topkg_os . Env . var ( os_tool_env name os ) os with match Topkg_os . Env . var ( os_bin_dir_env os ) os with | Some path -> Topkg_cmd . v Topkg_fpath ( . path // name ) name | None -> match Topkg_os . Env . var ( os_suff_env os ) os with | Some suff -> Top... |
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 -> ... |
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 par... |
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 ... |
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 .... |
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 |... |
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 ; ... |
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 " . ... |
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_... |
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 =... |
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 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.