text stringlengths 12 786k |
|---|
let readmes p = match p . readmes with |
let readme p = readmes p >>= function |
let opam p = match p . opam with name p >>= fun name -> pkg p >>| Topkg . Private . Pkg . opam ~ name >>= Fpath . of_string |
let opam_field_descr p = opam_field p " synopsis " >>= function | None -> Ok None | Some syn -> opam_field p " description " >>= function | None -> Ok None | Some descr -> Ok ( Some ( List . hd syn , List . hd descr ) descr ) descr |
let opam_descr p = let descr_file_for_opam opam = if Fpath . has_ext " . opam " opam then Fpath ( . rem_ext opam + " . descr ) " else Fpath ( . parent opam / " descr ) " in let read f = OS . File . read f >>= fun c -> Topkg_care_opam . Descr . of_string c >>| fun d -> d , false in ... |
let change_logs p = match p . change_logs with |
let change_log p = change_logs p >>= function |
let licenses p = match p . licenses with |
let distrib_uri ( ? raw = false ) false p = let subst_uri p uri = uri >>= fun uri -> name p >>= fun name -> version p >>= fun version -> Ok ( Topkg . String . drop_initial_v version ) version >>= fun version_num -> let defs = String . Map ( . empty |> add " NAME " name |> add " VE... |
let distrib_filename ( ? opam = false ) false p = let sep = if opam then ' . ' else ' - ' in name p >>= fun name -> version p >>= fun version -> Ok ( Topkg . String . drop_initial_v version ) version >>= fun version_num -> Fpath . of_string ( strf " % s % c % s " name sep versio... |
let distrib_archive_path p = build_dir p >>= fun build_dir -> distrib_filename ~ opam : false p >>| fun b -> Fpath ( . build_dir // b + " . tbz ) " |
let distrib_file p = match p . distrib_file with ( distrib_archive_path p >>= fun f -> OS . File . must_exist f ) f |> R . reword_error_msg ( fun _ -> R . msgf " Did you forget to call ' topkg distrib ' ) " ? |
let publish_msg p = match p . publish_msg with change_log p >>= fun change_log -> Topkg_care_text . change_log_file_last_entry change_log >>= fun ( _ , ( h , txt ) txt ) txt -> Ok ( strf " % s \ n % s " h txt ) txt |
let publish_artefacts p = match p . publish_artefacts with |
let v ? name ? version ? delegate ? build_dir ? opam : opam_file ? opam_descr ? readme ? change_log ? license ? distrib_uri ? distrib_file ? publish_msg ? publish_artefacts pkg_file = let readmes = match readme with Some r -> Some [ r ] r | None -> None in let change_logs = match change_log with... |
let distrib_prepare_ipc p ~ dist_build_dir ~ name ~ version ~ opam ~ opam_adds = let dist_build_dir = Fpath . to_string dist_build_dir in let opam = Fpath . to_string opam in R . join @@ Topkg_care_ipc . ask ~ pkg_file : p . pkg_file ( Topkg . Private . Ipc . distrib_prepare ~ dist_build_dir ... |
let distrib_archive p ~ keep_dir = Topkg_care_archive . ensure_bzip2 ( ) >>= fun ( ) -> name p >>= fun name -> build_dir p >>= fun build_dir -> version p >>= fun version -> opam p >>= fun opam -> distrib_filename p >>= fun root -> Ok Fpath ( . build_dir // root + " . build ) " >>= fu... |
let run p ~ dir cmd ~ args ~ out = let pkg_file = p . pkg_file in let cmd = Cmd ( . v " ocaml " % p pkg_file % cmd %% args ) args in let run ( ) = OS . Cmd . run_out cmd |> out in R . join @@ OS . Dir . with_current dir run ( ) |
let test p ~ dir ~ args ~ out = run p ~ dir " test " ~ args ~ out |
let build p ~ dir ~ args ~ out = run p ~ dir " build " ~ args ~ out |
let clean p ~ dir ~ args ~ out = run p ~ dir " clean " ~ args ~ out |
let lint_log msg = Logs . info ( fun m -> m ~ header " : LINT " " % a " Fmt . text msg ) msg ; 0 |
let lint_disabled test = Logs . info ( fun m -> m ~ header " : LINT " " Package @ disabled @ % a . " Fmt . text test ) test ; 0 |
let lint_custom p = let report errs res = let status , msg , errs = match res with | Ok ( ` Msg msg ) msg -> ` Ok , msg , errs | Error ( ` Msg msg ) msg -> ` Fail , msg , errs + 1 in Logs . app ( fun m -> m " % a [ @% a ] " @ pp_status status Fmt . text msg ) msg ; e... |
let lint_std_files p = let lint_exists file errs = let report exists = let status , errs = if exists then ` Ok , errs else ` Fail , errs + 1 in Logs . app ( fun m -> m " % a [ @ File % a @ is @ present ] . " @ pp_status status pp_path file ) file ; errs in ( OS . File . exists fi... |
let lint_file_with_cmd file_kind ~ cmd file errs handle_exit = let run_linter cmd file ~ exists = if not exists then Ok ( ` Fail ( strf " % a : No such file " Fpath . pp file ) file ) file else OS . Cmd ( . run_out ~ err : err_run_out Cmd ( . cmd % p file ) file |> out_string ) out_... |
let lint_metas p = begin pkg p >>= fun p -> match Topkg . Private . Pkg . lint_metas p with | [ ] -> Ok ( lint_log " No ocamlfind META file to lint ) " | metas -> let cmd = Cmd ( . Topkg_care_ocamlfind . cmd % " lint ) " in let handle_exit status out = match status with | ` Exited ... |
let lint_opams p = begin pkg p >>= fun p -> match Topkg . Private . Pkg . lint_opams p with | [ ] -> Ok ( lint_log " No opam file to lint ) " | opams -> let cmd = Cmd ( . Topkg_care_opam . cmd % " lint ) " in let handle_exit file status out = match status , out with | ` Exited 0 ... |
let lint_deps_default_excludes = let exclude = [ " ocamlfind " ; " ocamlbuild " ; " topkg " ; " ocaml ] " in Topkg_care_ocamlfind . base_packages |> String . Set . union Topkg_care_opam . ocaml_base_packages |> String . Set . union ( String . Set . of_list exclude ) exclude |
let lint_opam_deps errs ( opam , _ , exclude ) exclude = let pp_deps_mismatches ppf ( opam_only , tags_only ) tags_only = let pp_miss present absent ppf id = Fmt . pf ppf [ " @% a : % a present but % a absent ] " @ Fmt ( . styled ` Underline string ) string id Fmt ( . styled ` ... |
let lint_deps p = begin pkg p >>= fun p -> match Topkg . Private . Pkg . lint_opams p with | [ ] -> Ok ( lint_log " No opam file to dependency lint ) " | opams -> Ok ( List . fold_left lint_opam_deps 0 opams ) opams end |> Logs . on_error_msg ~ use ( : fun ( ) -> 1 ) 1 |
type lint = [ ` Custom | ` Std_files | ` Meta | ` Opam | ` Deps ] |
let lints = [ ` Custom , lint_custom ; ` Std_files , lint_std_files ; ` Meta , lint_metas ; ` Opam , lint_opams ; ` Deps , lint_deps ] |
let lint_all = List . map fst lints |
let lint ( ? ignore_pkg = false ) false p ~ dir todo = let lint pkg = let do_lint acc ( l , f ) f = acc + if List . mem l todo then f pkg else 0 in match List . fold_left do_lint 0 lints with | 0 -> Logs . app ( fun m -> m " % a lint @ % a % a " pp_status ` Ok pp_path dir ( Fmt . ... |
type flavour = [ ` Markdown | ` Asciidoc ] |
let flavour_of_fpath f = match String . Ascii . lowercase ( Fpath . get_ext f ) f with |
let rec drop_blanks = function " " :: ls -> drop_blanks ls | ls -> ls |
let last_line = function [ ] -> None | l :: rev_ls -> Some l |
let simple_header hchar l before rest = match String ( . length @@ take ~ sat ( : Char . equal hchar ) hchar l ) l with | 0 -> None | n -> Some ( n , l , before , rest ) rest |
let underline_header n uchar l before rest = let is_underline_header uchar l = String ( . length @@ take ~ sat ( : Char . equal uchar ) uchar l ) l >= 2 in if not ( is_underline_header uchar l ) l then None else match last_line before with | None -> None | Some t -> Some ( n , strf " % s... |
let rec find_markdown_header before = function match simple_header ' # ' l before ls with | Some _ as h -> h | None -> match underline_header 1 ' = ' l before ls with | Some _ as h -> h | None -> match underline_header 2 ' - ' l before ls with | Some _ as h -> h | None -> find_markdown_... |
let rec find_asciidoc_header before = function match simple_header ' = ' l before ls with | Some _ as h -> h | None -> match underline_header 1 ' - ' l before ls with | Some _ as h -> h | None -> match underline_header 2 ' ~ ' l before ls with | Some _ as h -> h | None -> match underlin... |
let head find_header text = let lines = String . cuts ~ sep " :\ n " text in let ret h acc = let contents = String . concat ~ sep " :\ n " ( List . rev @@ drop_blanks acc ) acc in Some ( h , contents ) contents in match find_header [ ] lines with | None -> None | Some ( n , first ,... |
let head ( ? flavour = ` Markdown ) Markdown text = match flavour with |
let header_title ( ? flavour = ` Markdown ) Markdown h = match String . cuts ~ sep " :\ n " h with begin match flavour with | ` Markdown -> String ( . trim @@ drop ~ sat ( : Char . equal ' # ' ) ' h ) h | ` Asciidoc -> String ( . trim @@ drop ~ sat ( : Char . equal... |
let change_log_last_entry ? flavour text = match head ? flavour text with let title = header_title ? flavour h in match String . take ~ sat : Char . Ascii . is_graphic title with | " " -> Logs . app ( fun m -> m " % S % S " h changes ) changes ; None | version -> Some ( version , ( h... |
let change_log_file_last_entry file = let flavour = flavour_of_fpath file in OS . File . read file >>= fun text -> match change_log_last_entry ? flavour text with | None -> R . error_msgf " % a : Could not parse change log . " Fpath . pp file | Some ( version , ( header , changes ) changes ) ... |
let split_uri ( ? rel = false ) false uri = match String ( . cut ~ sep " " :// ( trim uri ) uri ) uri with match String . cut ~ sep " " :/ rest with | None -> Some ( scheme , rest , ) " " | Some ( host , path ) path -> let path = if rel then path else " " / ^ path in Some ( ... |
let find_pager ~ don ' t = if don ' t then Ok None else match OS . Env . var " TERM " with | Some " dumb " | None -> Ok None | _ -> let add_env v cmds = match OS . Env ( . value v ( some cmd ) cmd ~ absent : None ) None with | None -> cmds | Some cmd -> cmd :: cmds in let cmds = ... |
let edit_file f = match OS . Env ( . value " EDITOR " ( some cmd ) cmd ~ absent : None ) None with OS . Cmd . exists editor >>= function | false -> R . error_msgf " Editor % a not in search path " Cmd . pp editor | true -> OS . Cmd ( . run_status Cmd ( . editor % p f ) f ) ... |
module Pp = struct let name = Fmt ( . styled ` Bold string ) string let version = Fmt ( . styled ` Cyan string ) string let commit = Fmt ( . styled ` Yellow string ) string let dirty = Fmt ( . styled_unit ` Red " dirty ) " let path = Fmt ( . styled ` Bold Fpath . pp ) ... |
type t = string list |
let is_empty = function [ ] -> true | _ -> false |
let v a = [ a ] a |
let ( % ) l a = a :: l |
let ( %% ) l0 l1 = List . rev_append ( List . rev l1 ) l1 l0 |
let add_arg l a = l % a |
let add_args l a = l %% a |
let on bool l = if bool then l else [ ] |
let p f = f |
let equal l l ' = l = l ' |
let compare l l ' = compare l l ' |
let to_rev_list line = line |
let to_list line = List . rev line |
let of_list ? slip line = match slip with |
let dump ppf cmd = let pp_elt ppf s = Format . fprintf ppf " % s " ( Filename . quote s ) s in let rec loop = function | [ ] -> ( ) | v :: vs -> if vs = [ ] then pp_elt ppf v else ( Format . fprintf ppf " % a @ " pp_elt v ; loop vs ) vs in Format . fprintf ppf [ " @< 1 [ ... |
type error = Corrupted of ( string * string ) string | Version of int * int |
let pp_error ppf = function Format . fprintf ppf " corrupted % s in % S " kind v Format . fprintf ppf " version mismatch , expected % d found % d " exp fnd |
let err ~ kind v = raise ( Error ( Corrupted ( kind , v ) v ) v ) v |
let err_version ~ exp ~ fnd = raise ( Error ( Version ( exp , fnd ) fnd ) fnd ) fnd |
type ' a t = { kind : string ; enc : ' a -> string ; dec : string -> ' a ; } |
let v ~ kind ~ enc ~ dec = { kind ; enc ; dec } |
let kind c = c . kind |
let enc c = c . enc |
let dec c = c . dec |
let with_kind kind c = { c with kind } |
let dec_result c s = try Ok ( dec c s ) s with R . error_msgf " Decode % s : % a Input data : % S " ( kind c ) c pp_error err s |
let write file c v = Topkg_os . File . write file ( enc c v ) v |> R . reword_error_msg ~ replace : true ( fun err -> R . msgf " Encode % s to % s : % s " ( kind c ) c file err ) err |
let read file c = Topkg_os . File . read file >>= fun s -> try Ok ( dec c s ) s with | Error e -> R . error_msgf " Decode % s from % s : % a " ( kind c ) c file pp_error e |
let tail s = Topkg_string . with_index_range ~ first : 1 s |
let unit = let kind = " unit " in let enc = function ( ) -> " \ x00 " in let dec = function " \ x00 " -> ( ) | s -> err ~ kind s in v ~ kind ~ enc ~ dec |
let const c = let kind = " const " in let enc = function _ -> " " in let dec = function " " -> c | s -> err ~ kind s in v ~ kind ~ enc ~ dec |
let bool = let kind = " bool " in let enc = function false -> " \ x00 " | true -> " \ x01 " in let dec = function " \ x00 " -> false | " \ x01 " -> true | s -> err ~ kind s in v ~ kind ~ enc ~ dec |
let int = let kind = " int " in let enc = string_of_int in let dec s = try int_of_string s with Failure _ -> err ~ kind s in v ~ kind ~ enc ~ dec |
let string = let kind = " string " in let enc s = s in let dec s = s in v ~ kind ~ enc ~ dec |
let option some = let kind = Printf . sprintf ( " % s ) s option " ( kind some ) some in let enc = function None -> " \ x00 " | Some v -> " \ x01 " ^ ( enc some v ) v in let dec s = match Topkg_string . head s with | Some ' \ x00 ' -> None | Some ' \ x01 ' -> Some ( dec so... |
let result ~ ok ~ error = let kind = Printf . sprintf ( " % s , % s ) s result " ( kind ok ) ok ( kind error ) error in let enc = function | Ok v -> " \ x00 " ^ ( enc ok v ) v | Error e -> " \ x01 " ^ ( enc error e ) e in let dec s = match Topkg_string . head s with | Some... |
let list el = let kind = Printf . sprintf ( " % s ) s list " ( kind el ) el in let enc vs = let b = Buffer . create 255 in let rec loop = function | [ ] -> Buffer . add_char b ' \ x00 ' | v :: vs -> let venc = ( enc el ) el v in let venc_len = String . length venc in Buffer . ad... |
let seq = list string |
let pair c0 c1 = let kind = Printf . sprintf " % s * % s " ( kind c0 ) c0 ( kind c1 ) c1 in let enc ( v0 , v1 ) v1 = enc seq [ enc c0 v0 ; enc c1 v1 ] v1 in let dec s = match dec seq s with | [ lenc ; renc ] renc -> ( dec c0 lenc ) lenc , ( dec c1 renc ) renc | _ -> er... |
let t3 c0 c1 c2 = let kind = Printf . sprintf " % s * % s * % s " ( kind c0 ) c0 ( kind c1 ) c1 ( kind c2 ) c2 in let seq = list string in let enc ( v0 , v1 , v2 ) v2 = enc seq [ enc c0 v0 ; enc c1 v1 ; enc c2 v2 ] v2 in let dec s = match ( dec seq ) seq s with | [ v0 ; ... |
let t4 c0 c1 c2 c3 = let kind = Printf . sprintf " % s * % s * % s * % s " ( kind c0 ) c0 ( kind c1 ) c1 ( kind c2 ) c2 ( kind c3 ) c3 in let seq = list string in let enc ( v0 , v1 , v2 , v3 ) v3 = enc seq [ enc c0 v0 ; enc c1 v1 ; enc c2 v2 ; enc c3 v3 ] v3 in let dec ... |
let t5 c0 c1 c2 c3 c4 = let kind = Printf . sprintf " % s * % s * % s * % s * % s " ( kind c0 ) c0 ( kind c1 ) c1 ( kind c2 ) c2 ( kind c3 ) c3 ( kind c4 ) c4 in let seq = list string in let enc ( v0 , v1 , v2 , v3 , v4 ) v4 = enc seq [ enc c0 v0 ; enc c1 v1 ; enc c... |
let alt ~ kind tag cs = let l = Array . length cs in if l > 256 then invalid_arg @@ Topkg_string . strf " too many codecs ( % d ) d " l ; let enc v = let tag = tag v in Printf . sprintf " % c % s " ( Char . chr tag ) tag ( enc cs ( . tag ) tag v ) v in let dec s = match Topkg_... |
let version version = let enc_version = string_of_int version in fun c -> let kind = Printf . sprintf ( " % s ) s v % s " ( kind c ) c enc_version in let enc v = String . concat " \ x00 " [ enc_version ; enc c v ] v in let dec s = match Topkg_string . cut ~ sep : ' \ x00 ' s with |... |
let view ? kind : k ( inj , proj ) proj c = let kind = match k with None -> kind c | Some k -> k in let enc v = enc c ( inj v ) v in let dec s = proj ( dec c s ) s in v ~ kind ~ enc ~ dec |
let msg = let msg = ( fun ( ` Msg m ) m -> m ) m , ( fun m -> ` Msg m ) m in view msg string |
let result_error_msg ok = result ~ ok ~ error : msg |
let cmd = let cmd = ( fun cmd -> Topkg_cmd . to_list cmd ) cmd , ( fun l -> Topkg_cmd . of_list l ) l in view cmd ( list string ) string |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.