text
stringlengths
0
601k
let subst env rule = let subst_resources = List . map ( Resource . subst env ) in let subst_resource_patterns = List . map ( Resource . subst_pattern env ) in let finder next_finder p = next_finder ( Resource . subst_any env p ) in let stamp = match rule . stamp with None -> None | Some x -> Some ( Resource . subst_pat...
let can_produce target rule = try List . iter begin fun resource -> match Resource . matchit resource target with | Some env -> raise ( Can_produce ( subst env rule ) ) | None -> ( ) end rule . prods ; None with Can_produce r -> Some r
let digest_prods r = List . fold_right begin fun p acc -> let f = Pathname . to_string ( Resource . in_build_dir p ) in if sys_file_exists f then ( f , Digest . file f ) :: acc else acc end r . prods [ ]
let digest_deps r dyndeps = let buf = Buffer . create 1024 in let add_resource r = Buffer . add_string buf ( Digest . to_hex ( Resource . digest r ) ) in Buffer . add_string buf " deps " ; : List . iter add_resource r . deps ; Buffer . add_string buf " dyndeps " ; : Resources . iter add_resource dyndeps ; Digest . to_h...
let digest_rule r dyndeps action = let buf = Buffer . create 1024 in Buffer . add_string buf action . digest ; let add_resource r = Buffer . add_string buf ( Resource . digest r ) in Buffer . add_string buf " prods " ; : List . iter add_resource r . prods ; Buffer . add_string buf " deps " ; : List . iter add_resource ...
let cached_digest r = try Some ( Digest_cache . get ( " Rule : " ^ r . name ) ) with Not_found -> None
let store_digest r digest = Digest_cache . put ( " Rule : " ^ r . name ) digest
let print_digest f x = pp_print_string f ( Digest . to_hex x )
let exists2 find p rs = try Some ( find p rs ) with Not_found -> None
let build_deps_of_tags builder tags = match Command . deps_of_tags tags with | [ ] -> [ ] | deps -> List . map Outcome . good ( builder ( List . map ( fun x -> [ x ] ) deps ) )
let build_deps_of_tags_on_cmd builder = Command . iter_tags begin fun tags -> match Command . deps_of_tags tags with | [ ] -> ( ) | deps -> List . iter ignore_good ( builder ( List . map ( fun x -> [ x ] ) deps ) ) end
let call builder r = let dyndeps = ref Resources . empty in let builder rs = let results = builder rs in List . map begin fun res -> match res with | Good res ' -> let ( ) = dprintf 10 " new dyndep for % S ( % a ) : % S " r . name print_resource_list r . prods res ' in dyndeps := Resources . add res ' ! dyndeps ; List ...
let ( get_rules , add_rule ) = let rules = ref [ ] in ( fun ( ) -> ! rules ) , begin fun pos r -> try let _ = List . find ( fun x -> x . name = r . name ) ! rules in raise ( Exit_rule_error ( sbprintf " Rule . add_rule : already exists : ( % a ) " print r ) ) with Not_found -> match pos with | ` bottom -> rules := ! ru...
let rule name ( ? tags [ ] ) = ( ? prods [ ] ) = ( ? deps [ ] ) = ? prod ? dep ? stamp ( ? insert = ` bottom ) code = let res_add import xs xopt = let init = match xopt with | None -> [ ] | Some r -> [ import r ] in List . fold_right begin fun x acc -> let r = import x in if List . mem r acc then failwith ( sprintf " i...
module Common_commands = struct open Command let mv src dest = Cmd ( S [ A " mv " ; P src ; Px dest ] ) let cp src dest = Cmd ( S [ A " cp " ; P src ; Px dest ] ) let cp_p src dest = Cmd ( S [ A " cp " ; A " - p " ; P src ; Px dest ] ) let ln_f pointed pointer = Cmd ( S [ A " ln " ; A " - f " ; P pointed ; Px pointer ]...
let copy_rule name ? insert src dest = rule name ? insert ~ prod : dest ~ dep : src begin fun env _ -> let src = env src and dest = env dest in Shell . mkdir_p ( Pathname . dirname dest ) ; cp_p src dest end
module Addr = struct type t = addr let compare = Pervasives . compare end
module AddrSet = Set . Make ( Addr )
module AddrMap = Map . Make ( Addr )
let keys m = AddrMap . fold ( fun k _ s -> AddrSet . add k s ) m AddrSet . empty
let map_of_list l = List . fold_left ( fun m ( k , x ) -> AddrMap . add k x m ) AddrMap . empty l
type rule = addr * mty -> mty AddrMap . t
type rulemap = Normalised_instr . t -> rule
let checked = ref AddrSet . empty
let tocheck = ref ( AddrMap . empty : mty AddrMap . t )
let check rulemap code pc = let merge pc t t ' = Some ( merge_mty t t ' ) in if AddrSet . mem pc ! checked then ( ) else if not ( AddrMap . mem pc ! tocheck ) then invalid_arg " initial type missing " else let t = AddrMap . find pc ! tocheck in let m = rulemap code . ( pc ) ( pc , t ) in tocheck := AddrMap . union merg...
let require condition = if condition then ( ) else invalid_arg " rule requirement unmet "
let rules globals cfuns closures instr ( pc , t ) = let err msg = raise ( Type_error ( pc , msg ) ) in let open AddrMap in let branch = map_of_list in let next t = branch [ pc + 1 , t ] in match instr with | ACC n -> next { t with acc = List . nth t . stack n } | PUSH -> next { t with stack = t . acc :: t . stack } | P...
let checkcode globals cfuns funs code = checked := AddrSet . empty ; tocheck := AddrMap . empty ; for pc = 0 to Array . length code - 1 do check ( rules globals cfuns funs ) ( Normalised_code . of_code code ) pc done
module Domain = struct type static_information = { global_static_information : Analyzer_headers . global_static_information ; domain_static_information : unit } type local_dynamic_information = bool Ckappa_sig . Rule_nearly_Inf_Int_storage_Imperatif . t type dynamic_information = { local : local_dynamic_information ; g...
module Result = struct type ( ' hit , ' miss ) t = | Hit of ' hit | Miss of ' miss end
module Workspace_local = struct module Database = struct module Entry = struct type t = { rule_digest : Digest . t ; dynamic_deps_stages : ( Action_exec . Dynamic_dep . Set . t * Digest . t ) list ; targets_digest : Digest . t } let to_dyn { rule_digest ; dynamic_deps_stages ; targets_digest } = Dyn . Record [ ( " rule...
module Shared = struct let shared_cache_key_string_for_log ~ rule_digest ~ head_target = sprintf " [ % s ] ( % s ) " ( Digest . to_string rule_digest ) ( Path . Build . to_string head_target ) module Miss_reason = struct type t = | Cache_disabled | Cannot_go_in_shared_cache | Rerunning_for_reproducibility_check | Not_f...
module Visitor : Traversal_utils . VisitorSig = struct open Traversal_utils open Source_pos open Graphql_ast open Schema type arg_pos = Directive of string | Field of string * string type known_args = ( arg_pos * argument_meta list ) option type t = known_args ref include Traversal_utils . AbstractVisitor let make_self...
module Visitor : Traversal_utils . VisitorSig = struct open Traversal_utils open Graphql_ast open Source_pos open Type_utils . Generic include AbstractVisitor type t = { variable_types : ( string , tree ) Hashtbl . t ; mutable arg_type : ( string spanning * tree ) option ; } let make_self ( ) = { variable_types = Hasht...
module Visitor : Traversal_utils . VisitorSig = struct open Traversal_utils open Graphql_ast open Source_pos open Type_utils . Generic include AbstractVisitor type t = { variable_types : ( string , tree ) Hashtbl . t } let make_self ( ) = { variable_types = Hashtbl . create 0 } let enter_operation_definition self ctx d...
module Visitor : Traversal_utils . VisitorSig = struct open Traversal_utils open Source_pos open Graphql_ast include AbstractVisitor type t = ( string , span ) Hashtbl . t let make_self ( ) = Hashtbl . create 0 let enter_fragment_definition self _ def = let ( ) = Hashtbl . clear self in match def . item . fg_variable_d...
let show = ref false
let showall = ref false
let top = ref false
let debug = ref false
let showpervasives = ref false
let printer = ref " simple "
let width = ref 80
let show_simple_arithmetic = ref true
let debugtiny = ref false
let debugtinyall = ref false
let debugpp = ref false
let prompt = ref false
let step = ref 0 . 0
let fastcurry = ref false
let noifbool = ref false
let novarlookup = ref false
type mode = FromFile of string
let source = ref [ ]
let setfile s = source := ( modname_of_filename s , FromFile s ) ::! source ; Ocamliprim . exe := ( Bytes . of_string s )
let settext ( ? modname " " ) = s = source := ( modname , FromText s ) ::! source
let remove_recs = ref [ ]
let add_remove_rec x = remove_recs := x ::! remove_recs
let remove_rec_all = ref false
let rec load_code = function ( _ , FromFile s ) -> load_file s | ( _ , FromText s ) -> s
let load_modules mods = Eval . lib := Ocamlilib . load_library_modules ( List . map ( function ( n , FromFile s ) -> ( n , load_file s ) | ( n , FromText s ) -> ( n , s ) ) mods )
let load_code ( ) = match ! source with [ ] -> None | h :: t -> load_modules ( List . rev t ) ; Some ( load_code h )
let string_of_tiny ~ preamble ( ? codes = true ) x = let x = Tinyocamlutil . remove_named_recursive_functions ! remove_rec_all ! remove_recs x in let temp = ! Pptinyocaml . syntax in Pptinyocaml . syntax := codes && ! Pptinyocaml . syntax ; let r = Pptinyocaml . to_string ~ preamble x in Pptinyocaml . syntax := temp ; ...
let string_of_op = function Arith -> " Arith "
let string_of_ops ops = List . fold_left ( fun a b -> a ^ " " ^ b ) " " ( List . map string_of_op ops )
let debug_last_next last next = Printf . printf " LAST : % s \ n " ( string_of_ops last ) ; Printf . printf " NEXT : % s \ n " ( string_of_ops next )
let show_this_stage last next prevstate currstate = if ! noifbool && List . mem IfBool next then false else if ! novarlookup && List . mem VarLookup last then false else let r = Tinyocamlutil . is_value prevstate || Tinyocamlutil . is_value currstate || not ( List . mem Arith last ) || not ( List . mem Arith next ) in ...
let show_this_pervasive_stage last = not ( List . mem InsidePervasive last )
let skipped = ref false
let call_editor ( current_state : Eval . t ) = let editor = match Sys . getenv_opt " EDITOR " with Some x -> x | None -> " vim " in let fname = Filename . temp_file " ocamli " " editcall " in let temp = open_out fname in output_string temp ( Pptinyocaml . to_string current_state ) ; close_out temp ; let newtext = match...
let rec wait_for_enter ( current_state : Eval . t ) = Printf . printf " \ n " ; ?%! match input_line stdin with " " -> None | " edit " -> Some ( call_editor current_state ) | " back " -> begin match Eval . pop_state ( ) with None -> None | Some x -> Some x end | _ -> Printf . printf " unknown command \ n " ; %! wait_fo...
let print_string x = print_string x ; flush stdout
let extract_expression = function [ { pstr_desc = Pstr_eval ( e , _ ) } ] -> e
let extract_tiny = function Tinyocaml . Struct ( _ , [ x ] ) -> x
let eval_string_to_ast ( ? stdlib = true ) ( ? filename " " ) = s = if stdlib then Ocamlilib . load_library ( ) ; let state = Eval . init ( snd ( Tinyocamlrw . of_real_ocaml [ ] ( ast ~ filename s ) ) ) in let rec eval_inner state = match Eval . next state with | Next state -> eval_inner state | IsValue -> extract_expr...
let eval_string ( ? stdlib = true ) ( ? filename " " ) = s = if stdlib then Ocamlilib . load_library ( ) ; let state = Eval . init ( snd ( Tinyocamlrw . of_real_ocaml [ ] ( ast ~ filename s ) ) ) in let rec eval_inner state = match Eval . next state with | Next state -> eval_inner state | IsValue -> Pptinyocaml . to_st...
let to_http service region req = let uri = Uri . add_query_params ( Uri . of_string ( Aws . Util . of_option_exn ( Endpoints . url_of service region ) ) ) ( List . append [ ( " Version " , [ " 2016 - 11 - 15 " ] ) ; ( " Action " , [ " RunInstances " ] ) ] ( Util . drop_empty ( Uri . query_of_encoded ( Query . render ( ...
let of_http body = try let xml = Ezxmlm . from_string body in let resp = Xml . member " RunInstancesResponse " ( snd xml ) in try Util . or_error ( Util . option_bind resp Reservation . parse ) ( let open Error in BadResponse { body ; message = " Could not find well formed Reservation . " } ) with | Xml . RequiredField...
let parse_error code err = let errors = [ ] @ Errors_internal . common in match Errors_internal . of_string err with | Some var -> if ( List . mem var errors ) && ( ( match Errors_internal . to_http_code var with | Some var -> var = code | None -> true ) ) then Some var else None | None -> None
let time f = let t1 = Sys . time ( ) in let r = f ( ) in let t2 = Sys . time ( ) in Printf . printf " [ time ] . % 04f sec \ n " %! ( t2 . - t1 ) ; r
let rec replicate f = function | 0 -> [ ] | n -> let x = f ( ) in x :: replicate f ( pred n )
let rec forever f = ( ignore @@ f ( ) ; forever f )
let on_stdin fn = lwt input = Lwt_io . ( read stdin ) in let res = fn ( Cstruct . of_string input ) in let b = Buffer . create 16 in Cstruct . hexdump_to_buffer b res ; Lwt_io . printl ( Buffer . contents b )
let main ( ) = match List . tl ( Array . to_list Sys . argv ) with | [ " md5 " ] -> on_stdin Hash . MD5 . digest | [ " sha1 " ] -> on_stdin Hash . SHA1 . digest | [ " hmac_md5 " ; k ] -> on_stdin @@ Hash . MD5 . hmac ~ key ( : cs_of_s k ) | [ " hmac_sha1 " ; k ] -> on_stdin @@ Hash . SHA1 . hmac ~ key ( : cs_of_s k ) |...
let time_fortuna_generation ( ) = let g = Fortuna . create ( ) in Fortuna . reseed g ( Cstruct . of_string " \ 001 \ 002 \ 003 \ 004 " ) ; let _ = time @@ fun ( ) -> for i = 1 to 10 do ignore @@ Fortuna . generate g ( int_of_float @@ 10 . . * ( 2 . ** 20 . ) ) done in ( )
let time_intgen_with_misses ( ) = Rng . reseed ( Cstruct . of_string " \ 001 \ 002 \ 003 \ 004 " ) ; let _ = time @@ fun ( ) -> for i = 1 to 1000000 do ignore @@ Rng . Int . gen 0x2000000000000001 done in ( )
let time_z_of_bits ( ) = Rng . reseed ( Cstruct . of_string " \ 001 \ 002 \ 003 \ 004 " ) ; let items = 10000000 in let cs = time @@ fun ( ) -> Rng . generate ( items * 8 ) in time @@ fun ( ) -> let rec loop cs = function | 0 -> ( ) | n -> ignore ( Numeric . Z . of_cstruct_be ~ bits ( : 7 * 8 + 3 ) cs ) ; loop ( Cstruc...
let time_rsa_generate ( ) = Rng . reseed ( Cstruct . of_string " \ 001 \ 002 \ 003 \ 004 " ) ; let items = 100 in time @@ fun ( ) -> for i = 1 to items do ignore @@ Rsa . generate 2048 done
let rsa_feedback bits = let open Cstruct in let open Rsa in let def_e = Z . of_int 0x10001 in let m = Rng . generate ( bits / 8 - 1 ) in Cstruct . ( set_uint8 m 0 ( max 1 ( get_uint8 m 0 ) ) ) ; hexdump m ; let e = if Z . ( pow ~$ 2 bits < def_e ) then Z . of_int 3 else def_e in let key = Printf . printf " + generating...
let dh_feedback bits = let p = Dh . gen_group bits in let ( s1 , m1 ) = Dh . gen_secret p and ( s2 , m2 ) = Dh . gen_secret p in let sh1 = Dh . shared p s1 m2 and sh2 = Dh . shared p s2 m1 in assert ( Cstruct . equal sh1 sh2 ) ; Cstruct . hexdump sh1
type t = { id : int ; address : string ; ssh_alias : string option ; ssh_user : string option ; ssh_port : int option ; ssh_id : string option ; }
let local_public_ip = ref " 127 . 0 . 0 . 1 "
let get_local_public_ip ( ) = ! local_public_ip
let set_local_public_ip ip = local_public_ip := ip
let next_id = ref 0
let create ? ssh_alias ? ssh_user ? ssh_port ? ssh_id ~ address ( ) = let id = ! next_id in incr next_id ; { id ; address ; ssh_alias ; ssh_user ; ssh_port ; ssh_id }
let address ( ? hostname = false ) ? from runner = match ( from , runner ) with | ( None , None ) -> if hostname then " localhost " else " 127 . 0 . 0 . 1 " | ( None , Some host ) -> host . address | ( Some _peer , None ) -> get_local_public_ip ( ) | ( Some peer , Some host ) -> if peer . address = host . address then ...
let ssh_env ( ) = match ( Sys . getenv_opt " SSH_AGENT_PID " , Sys . getenv_opt " SSH_AUTH_SOCK " ) with | ( Some agent , Some sock ) -> [ " | SSH_AGENT_PID " = ^ agent ; " SSH_AUTH_SOCK " = ^ sock ] | | _ -> [ ] ||
module Shell = struct type command = { local_env : ( string * string ) list ; name : string ; arguments : string list ; } type t = | Cmd of command | Seq of t * t | Echo_pid | Redirect_stdout of t * string | Redirect_stderr of t * string | Or_echo_false of t let string_of_env env = List . fold_right ( fun ( var , value...