Skip to content

Commit

Permalink
Merge pull request #1431 from reynir/err-no-dev
Browse files Browse the repository at this point in the history
app_has_no_arguments: also catch when behind `if'
  • Loading branch information
hannesm committed Jun 20, 2023
2 parents 3bfbf38 + d6bca2d commit 0b51cb2
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/functoria/impl.ml
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@ and 'a device = ('a, abstract) Device.t

let abstract t = Abstract t

let app_has_no_arguments = function
let rec app_has_no_arguments = function
| App { args = Cons _; _ } | Dev { args = Cons _; _ } -> false
| App _ | Dev _ -> true
| If _ -> false
| If { cond = _; branches; default } ->
app_has_no_arguments default ||
List.exists (fun (_, branch) -> app_has_no_arguments branch) branches

(* Devices *)

Expand Down
9 changes: 9 additions & 0 deletions test/mirage/job-no-device-behind-if/config.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
open Mirage

let main = main "App" job

let key =
let doc = Key.Arg.info ~doc:"How to say hello." [ "hello" ] in
Key.(create "hello" Arg.(opt string "Hello World!" doc))

let () = register ~keys:[ Key.v key ] ~src:`None "noop" [ if_impl Key.is_solo5 main main ]
6 changes: 6 additions & 0 deletions test/mirage/job-no-device-behind-if/configure.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
$ export MIRAGE_DEFAULT_TARGET=unix

Configure
$ ./config.exe configure
Fatal error: exception Invalid_argument("Your configuration includes a job without arguments. Please add a dependency in your config.ml: use `let main = Mirage.main \"Unikernel.hello\" (job @-> job) register \"hello\" [ main $ noop ]` instead of `.. job .. [ main ]`.")
[2]
7 changes: 7 additions & 0 deletions test/mirage/job-no-device-behind-if/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
(executable
(name config)
(libraries mirage))

(cram
(package mirage)
(deps config.exe))

0 comments on commit 0b51cb2

Please sign in to comment.