Skip to content

Commit

Permalink
Merge pull request #1506 from samoht/keys-runtime_args
Browse files Browse the repository at this point in the history
Rename DSL.keys to DSL.runtime_args
  • Loading branch information
samoht committed Mar 7, 2024
2 parents 77e38d0 + ab193bf commit 37a8955
Show file tree
Hide file tree
Showing 12 changed files with 33 additions and 29 deletions.
20 changes: 11 additions & 9 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,20 @@
they are not available `key_gen.ml` anymore. As a consequence,
`Key_gen.target` has been removed.

- BREAKING: remove `foreign` from the DSL. Use `main` instead (#1505, @samoht)
- BREAKING: `main` does not take a `?extra_deps` parameter anymore
- BREAKING: `Mirage.keys` is renamed to `Mirage.runtime_args` (#1506, @samoht)
- BREAKING: remove `Mirage.foreign. Use `Mirage.main` instead (#1505, @samoht)
- BREAKING: `Mirage.main` does not take a `?extra_deps` parameter anymore
(#1505, @samoht)
- BREAKING: the `connect` functions passed to create devices (with `impl`) now
take values of type `code` instead of `string`. Value of type `code` are
created using a new `code` function, that takes `~pos:__POS__` as parameter.
This is used to generate better locations in the generated code, leading to
better error messages (#1504, @samoht)
- BREAKING: the `Mirage.connect` functions passed to create devices
(with `Mirage.impl`) now take values of type `'a Mirage.code` instead
of `string`. Value of type `code` are created using a new `Mirage.code`
function, that takes `~pos:__POS__` as parameter. This is used to generate
better locations in the generated code, leading to better error messages
(#1504, @samoht)
- BUGFIX: fix `mirage describe` output (#1446 @samoht), add test (#1458 @samoht)
- Remove ipaddr from runtime (#1437 @samoht, #1465 @hannesm)
- BREAKING: Mirage.register (and Functoria.register) no longer have `?packages`
and `?keys` arguments (#1433, #1434 @hannesm)
- BREAKING: `Mirage.register` no longer have `?packages` and `?keys` arguments
(#1433, #1434 @hannesm)
- BREAKING: Remove deprecated bindings and types (#1461 @hannesm)
- BREAKING: Remove `mirage build` subcommand, use `dune build` in Makefile
(#1404 @hannesm), put `--profile release` in Makefile instead of
Expand Down
4 changes: 2 additions & 2 deletions lib/functoria/functoria.ml
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ include DSL
let job = Job.t
let noop = Job.noop

let keys ?runtime_package ?runtime_modname x =
Job.keys ?runtime_package ?runtime_modname x
let runtime_args ?runtime_package ?runtime_modname x =
Job.runtime_args ?runtime_package ?runtime_modname x

type argv = Argv.t

Expand Down
4 changes: 2 additions & 2 deletions lib/functoria/functoria.mli
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,9 @@ val argv : argv typ
val sys_argv : argv impl
(** [sys_argv] is a device providing command-line arguments by using [Sys.argv]. *)

val keys :
val runtime_args :
?runtime_package:string -> ?runtime_modname:string -> argv impl -> job impl
(** [keys a] is an implementation of {!type-job} that holds the parsed
(** [runtinme_args a] is an implementation of {!type-job} that holds the parsed
command-line arguments. By default [runtime_package] is
["functoria-runtime"] and [runtime_modname] is ["Functoria_runtime"]. *)

Expand Down
6 changes: 3 additions & 3 deletions lib/functoria/job.ml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ let t = Type.v JOB
(* Noop, the job that does nothing. *)
let noop = Impl.v "Unit" t

module Keys = struct
module Args = struct
let configure ~file i =
Log.info (fun m -> m "Generating: %a (keys)" Fpath.pp file);
Action.with_output ~path:file ~purpose:"key_gen file" (fun ppf ->
Expand All @@ -38,13 +38,13 @@ module Keys = struct
keys)
end

let keys ?(runtime_package = "functoria-runtime")
let runtime_args ?(runtime_package = "functoria-runtime")
?(runtime_modname = "Functoria_runtime") (argv : Argv.t Impl.t) =
let packages = [ Package.v runtime_package ] in
let extra_deps = [ Impl.abstract argv ] in
let key_gen = Runtime_arg.module_name in
let file = Fpath.(v (String.Ascii.lowercase key_gen) + "ml") in
let configure = Keys.configure ~file in
let configure = Args.configure ~file in
let files _ = [ file ] in
let connect info _ = function
| [ argv ] ->
Expand Down
6 changes: 3 additions & 3 deletions lib/functoria/job.mli
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ val noop : t Impl.t
(** [noop] is an implementation of {!Functoria.job} that holds no state, does
nothing and has no dependency. *)

val keys :
val runtime_args :
?runtime_package:string ->
?runtime_modname:string ->
Argv.t Impl.t ->
t Impl.t
(** [keys a] is an implementation of {!Functoria.job} that holds the parsed
command-line arguments. *)
(** [runtime_args a] is an implementation of {!Functoria.job} that holds the
parsed command-line arguments. *)
2 changes: 1 addition & 1 deletion lib/functoria/lib.ml
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ end
module Make (P : S) = struct
module Filegen = Filegen.Make (P)

let default_init = [ Job.keys Argv.sys_argv ]
let default_init = [ Job.runtime_args Argv.sys_argv ]
let build_dir args = Fpath.parent args.Cli.config_file
let config_file args = args.Cli.config_file
let mirage_dir args = Fpath.(build_dir args / P.name)
Expand Down
8 changes: 5 additions & 3 deletions lib/mirage/mirage.ml
Original file line number Diff line number Diff line change
Expand Up @@ -475,8 +475,8 @@ let gc_control =

(** Custom registration *)

let keys argv =
Functoria.keys ~runtime_package:"mirage-runtime"
let runtime_args argv =
Functoria.runtime_args ~runtime_package:"mirage-runtime"
~runtime_modname:"Mirage_runtime" argv

let ( ++ ) acc x =
Expand All @@ -493,7 +493,9 @@ let register ?(argv = default_argv) ?(reporter = default_reporter ()) ?src name
dependency in your config.ml: use `let main = Mirage.main \
\"Unikernel.hello\" (job @-> job) register \"hello\" [ main $ noop ]` \
instead of `.. job .. [ main ]`.";
let first = [ keys argv; backtrace; randomize_hashtables; gc_control ] in
let first =
[ runtime_args argv; backtrace; randomize_hashtables; gc_control ]
in
let reporter = if reporter == no_reporter then None else Some reporter in
let init = Some first ++ Some delay_startup ++ reporter in
register ?init ?src name jobs
Expand Down
4 changes: 2 additions & 2 deletions lib/mirage/mirage.mli
Original file line number Diff line number Diff line change
Expand Up @@ -1041,8 +1041,8 @@ val job : job typ
val noop : job impl
(** [noop] is a job that does nothing, has no dependency and returns [()] *)

val keys : argv impl -> job impl
(** [keys argv] is a job that loads argv. *)
val runtime_args : argv impl -> job impl
(** [runtime_args argv] is a job that loads argv. *)

(** {2 Application registering} *)

Expand Down
2 changes: 1 addition & 1 deletion test/functoria/gen-1/test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ open Functoria
let test () =
let context = Context.empty in
let sigs = job @-> job in
let job = main "App.Make" sigs $ keys sys_argv in
let job = main "App.Make" sigs $ runtime_args sys_argv in
Functoria_test.run context job

let () =
Expand Down
2 changes: 1 addition & 1 deletion test/functoria/gen-2/test.ml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
open Functoria

let test () =
let i1 = keys sys_argv in
let i1 = runtime_args sys_argv in
let i2 = noop in
let context = Context.empty in
let sigs = job @-> job @-> job in
Expand Down
2 changes: 1 addition & 1 deletion test/mirage/info_gen/test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ open Mirage
let test () =
let context = Key.add_to_context Key.target `Unix Context.empty in
let sigs = job @-> job in
let job = main "App.Make" sigs $ keys default_argv in
let job = main "App.Make" sigs $ runtime_args default_argv in
Functoria_test.run ~project_name:"mirage"
~keys:[ Key.v Key.target ]
context job
Expand Down
2 changes: 1 addition & 1 deletion test/mirage/random-unix/test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ let test () =
let stackv4v6 =
direct_stackv4v6 ~ipv4_only ~ipv6_only network etif arp ipv4 ipv6
in
let init = Functoria.(keys sys_argv) in
let init = Functoria.(runtime_args sys_argv) in
let job =
main "App.Make" sigs $ conduit_direct ~tls:true stackv4v6 $ default_random
in
Expand Down

0 comments on commit 37a8955

Please sign in to comment.