Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Branch: master
Fetching contributors…

Cannot retrieve contributors at this time

executable file 92 lines (74 sloc) 3.35 kB
#!/usr/bin/env jocaml
#load "str.cma"
#load "ospecl.cma"
let (|>) x f = f x
let map_with_any workers items =
def inputs(item::rest_items) & available(worker::rest_workers) =
finished(worker, worker item) & inputs(rest_items) & available(rest_workers)
or finished(worker, result) & inputs(item::rest_items) & available([]) & outputs(results) & num_remaining(n) =
finished(worker, worker item) & inputs(rest_items) & available([]) & outputs(result::results) & num_remaining(n-1)
or finished(worker, result) & inputs([]) & outputs(results) & num_remaining(n) =
outputs(result::results) & inputs([]) & num_remaining(n-1)
or inputs([]) & outputs(results) & num_remaining(0) & wait () =
reply results to wait
in
spawn inputs(items) & outputs([]) & available(workers) & num_remaining(List.length items);
wait ()
let fire handlers event =
handlers |> List.iter (fun handle -> handle event);
flush stdout
let execute handlers spec_files addresses =
let module Event = Ospecl.Spec.Exec in
def handle_event (event) =
(match event with
| Event.Execution_finished | Event.Execution_started -> () (* skip these *)
| event -> fire handlers event);
reply to handle_event
in
fire handlers Event.Execution_started;
let spec_runners : ((string * Event.handler) -> unit) list =
addresses
|> map_with_any [Join.Ns.of_sockaddr]
|> map_with_any [fun name_server -> Join.Ns.lookup name_server "run_spec_file"]
in
let files_with_event_handler = spec_files |> List.map (fun file -> (file, handle_event)) in
ignore (map_with_any spec_runners files_with_event_handler);
fire handlers Event.Execution_finished
let _ =
let usage_message =
let this_file = (Filename.basename Sys.argv.(0)) in
Printf.sprintf "usage: %s [options] [spec files... ]
Connects to a running ospecl_server at the given address, and sends each spec file name to be executed there, handling the execution events as they are sent back. The supplied spec files should be source files which define a single top level value - (specs : Ospecl.Spec.t list).
" this_file
in
let color = ref false in
let address_strings = ref [] in
let spec_files = ref [] in
let append_to list_ref value =
list_ref := !list_ref @ [value]
in
let formatter = ref Ospecl.Handlers.Terminal.progress in
let formatters = [
("p", Ospecl.Handlers.Terminal.progress);
("progress", Ospecl.Handlers.Terminal.progress);
("d", Ospecl.Handlers.Terminal.documentation);
("documentation", Ospecl.Handlers.Terminal.documentation);
]
in
let choose_format f =
formatter := List.assoc f formatters
in
Arg.parse (Arg.align [
("-address", Arg.String (append_to address_strings), "IP:PORT of a server to run the specs on");
("-color", Arg.Set color, " enable color in the output");
("-format", Arg.Symbol (fst (List.split formatters), choose_format), " choose a formatter");
]) (append_to spec_files) usage_message;
let addresses = !address_strings
|> List.map (Str.split (Str.regexp ":"))
|> List.map (function
| [ip; port] -> Unix.ADDR_INET (Unix.inet_addr_of_string ip, int_of_string port)
| _ -> failwith "Addresses must be of the form <ip>:<port>"
)
in
let handlers = !formatter ~color:!color in
execute handlers !spec_files addresses
Jump to Line
Something went wrong with that request. Please try again.