...
 
Commits (2)
......@@ -41,6 +41,10 @@ module Shell_script = struct
let return_false = exec ["sh"; "-c"; "exit 42"]
let silently u =
let dev_null = string "/dev/null" in
write_output ~stdout:dev_null ~stderr:dev_null u
let seq_succeeds_or
?dependencies ?(silent = true) ~name ?(clean_up = [fail]) cmds =
let content =
......@@ -186,6 +190,7 @@ module Prepare_environment = struct
root_device: string;
root_password: string option;
run: Shell_script.t;
local_dependencies: [ `Command of string ] list;
} [@@deriving fields]
let make ?(ssh_port = 10_000) =
......@@ -212,6 +217,7 @@ module Prepare_environment = struct
root_device = "/dev/mmcblk0p1";
root_password = None;
run = compile_recipe ~ssh_port (setup @ recipe);
local_dependencies = [ `Command "qemu-system-arm" ];
}
| {environment = Qemu (Arm, Debian_wheezy); recipe} ->
(**
......@@ -230,6 +236,10 @@ module Prepare_environment = struct
root_device = "/dev/mmcblk0p2";
root_password;
run = compile_recipe ?root_password ~ssh_port recipe;
local_dependencies = [
`Command "qemu-system-arm";
`Command "sshpass";
];
}
let local_name_of_file =
......@@ -306,6 +316,40 @@ module Prepare_environment = struct
]
]
let configure (Qemu_ssh {local_dependencies}) =
let open Shell_script in
let open Genspio.EDSL in
let report = tmp_file "configure-report.md" in
let there_was_a_failure = tmp_file "bool-failure" in
let cmds =
[
report#set (string "Configuration Report\n\
====================\n\n");
there_was_a_failure#set (bool false |> Bool.to_string);
] @ List.map local_dependencies ~f:begin function
| `Command name ->
if_seq (exec ["which"; name] |> silently |> succeeds)
~t:[
report#append (ksprintf string "* `%s`: found.\n" name);
]
~e:[
report#append (ksprintf string "* `%s`: NOT FOUND!\n" name);
there_was_a_failure#set (bool true |> Bool.to_string);
]
end
@ [
call [string "cat"; report#path];
if_seq (there_was_a_failure#get |> Bool.of_string)
~t:[
exec ["printf"; "\\nThere were *failures* :(\\n"];
return_false
]
~e:[
exec ["printf"; "\\n*Success!*\\n"];
];
]
in
seq_succeeds_or ~silent:false ~name:(sprintf "Configuring local host") cmds
let setup_dir_content
(Qemu_ssh {ssh_port; root_password;
......@@ -338,6 +382,8 @@ module Prepare_environment = struct
@ List.concat_map dependencies ~f:begin fun (base, deps, cmd) ->
make_script_entry ~deps base cmd
end
@ make_script_entry ~phony:true "configure" (configure qssh)
~doc:"Configure this local-host (i.e. check for requirements)."
@ make_script_entry ~deps:start_deps ~phony:true "start"
~doc:"Start the Qemu VM (this grabs the terminal)."
(start_qemu_vm qssh)
......
......@@ -9,22 +9,20 @@ let dbg fmt = ksprintf (eprintf "Hadbg: %s\n%!") fmt
let examples =
[
"owrttpd",
Build_definition.{
environment = Environment.(qemu_arm openwrt);
recipe = Action.[
Exec ["opkg"; "install"; "lighttpd"];
Get_file ("/usr/sbin/lighttpd", "lighttpd-armv7l-bin");
]
};
Build_definition.Construct.(
within (qemu_arm openwrt) [
exec ["opkg"; "install"; "lighttpd"];
get_file "/usr/sbin/lighttpd" "lighttpd-armv7l-bin";
]
);
"debzymacs",
Build_definition.{
environment = Environment.(qemu_arm debian_wheezy);
recipe = Action.[
Exec ["apt-get"; "update"];
Exec ["apt-get"; "install"; "--yes"; "emacs23"];
Get_file ("/usr/bin/emacs", "emacs-armv7l-bin");
]
}
Build_definition.Construct.(
within (qemu_arm debian_wheezy) [
exec ["apt-get"; "update"];
exec ["apt-get"; "install"; "--yes"; "emacs23"];
get_file "/usr/bin/emacs" ~as_file:"emacs-armv7l-bin";
]
)
]
let usage () =
......
......@@ -5,9 +5,6 @@ open Astring
include Build_format_t
module Environment = struct
type t = environment
let openwrt = Openwrt
let debian_wheezy = Debian_wheezy
let qemu_arm v = Qemu (Arm, v)
let to_string_hum =
function
| Qemu (_,Openwrt ) -> "Qemu-arm-owrt"
......@@ -21,6 +18,8 @@ module Action = struct
| Get_file (p, a) -> strf "get: '%s' as '%s'" p a
end
type t = build
let make environment recipe =
{ environment; recipe}
let serialize: t -> string = Build_format_j.string_of_build
let deserialize_exn: string -> t = Build_format_j.build_of_string
......@@ -29,4 +28,14 @@ let to_string_hum {environment; recipe} =
strf "On %s, [%s]"
(Environment.to_string_hum environment)
(String.concat ~sep:"; " (List.map ~f:Action.to_string_hum recipe))
module Construct = struct
open Environment
open Action
let openwrt = Openwrt
let debian_wheezy = Debian_wheezy
let qemu_arm v = Qemu (Arm, v)
let within = make
let exec l = Exec l
let get_file f ~as_file = Get_file (f, as_file)
end