Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename Runtime_key to Runtime_arg #1501

Merged
merged 1 commit into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* API changes:
- There is no more `~stage` parameter for `Key.Arg.info`.
- `Key` now define configure-time keys only.
- There is a new module `Runtime_key` to define runtime keys.
- There is a new module `Runtime_arg` to define runtime keys.
- As there are no more keys type `'Both`, users are now expected to create
two separated keys in that case (one for configure-time, one for runtime)
or decide if the key is useful at runtime of configure-time.
Expand All @@ -26,7 +26,7 @@
- Similar keys will produce reproducible binaries to be uploaded to artifact
repositories like Docker Hub or https://builds.robur.coop/.

* Intended use of runtime keys (values of type `a runtime_key`):
* Intended use of runtime keys (values of type `a runtime_arg`):
- Allow users to customize deployments by changing device
configuration, like IP addresses, secrets, block device names,
etc., post downloading of binaries.
Expand Down Expand Up @@ -59,6 +59,7 @@
- Configure-time keys are not registerd anymore. This means that
they are not available `key_gen.ml` anymore. As a consequence,
`Key_gen.target` has been removed.

- 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`
Expand Down
6 changes: 3 additions & 3 deletions lib/functoria/DSL.ml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*)

type 'a key = 'a Key.key
type 'a runtime_key = 'a Runtime_key.key
type 'a runtime_arg = 'a Runtime_arg.arg
type 'a value = 'a Key.value
type abstract_key = Key.t
type package = Package.t
Expand All @@ -40,10 +40,10 @@ let dep = Impl.abstract
let if_impl = Impl.if_
let match_impl = Impl.match_

let impl ?packages ?packages_v ?install ?install_v ?keys ?runtime_keys
let impl ?packages ?packages_v ?install ?install_v ?keys ?runtime_args
?extra_deps ?connect ?dune ?configure ?files module_name module_type =
of_device
@@ Device.v ?packages ?packages_v ?install ?install_v ?keys ?runtime_keys
@@ Device.v ?packages ?packages_v ?install ?install_v ?keys ?runtime_args
?extra_deps ?connect ?dune ?configure ?files module_name module_type

let main ?packages ?packages_v ?extra_deps module_name ty =
Expand Down
4 changes: 2 additions & 2 deletions lib/functoria/DSL.mli
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ val dep : 'a impl -> abstract_impl
type 'a key = 'a Key.key
(** The type for command-line parameters. *)

type 'a runtime_key = 'a Runtime_key.key
type 'a runtime_arg = 'a Runtime_arg.arg
(** The type for command-line parameters. *)

type abstract_key = Key.t
Expand Down Expand Up @@ -165,7 +165,7 @@ val impl :
?install:(Info.t -> Install.t) ->
?install_v:(Info.t -> Install.t Key.value) ->
?keys:Key.t list ->
?runtime_keys:Runtime_key.t list ->
?runtime_args:Runtime_arg.t list ->
?extra_deps:abstract_impl list ->
?connect:(info -> string -> string list -> string) ->
?dune:(info -> Dune.stanza list) ->
Expand Down
8 changes: 4 additions & 4 deletions lib/functoria/device.ml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type ('a, 'impl) t = {
module_name : string;
module_type : 'a Type.t;
keys : Key.t list;
runtime_keys : Runtime_key.t list;
runtime_args : Runtime_arg.t list;
packages : package list value;
install : info -> Install.t value;
connect : info -> string -> string list -> 'a code;
Expand Down Expand Up @@ -76,7 +76,7 @@ let merge_packages = merge [] List.append
let merge_install = merge Install.empty Install.union

let v ?packages ?packages_v ?install ?install_v ?(keys = [])
?(runtime_keys = []) ?(extra_deps = []) ?(connect = default_connect)
?(runtime_args = []) ?(extra_deps = []) ?(connect = default_connect)
?(dune = nil) ?(configure = niet) ?files module_name module_type =
let id = Typeid.gen () in
let packages = merge_packages packages packages_v in
Expand All @@ -89,7 +89,7 @@ let v ?packages ?packages_v ?install ?install_v ?(keys = [])
id;
module_name;
keys;
runtime_keys;
runtime_args;
connect;
packages;
install;
Expand All @@ -115,7 +115,7 @@ let files t i =

let dune t = t.dune
let keys t = t.keys
let runtime_keys t = t.runtime_keys
let runtime_args t = t.runtime_args
let extra_deps t = t.extra_deps

let start impl_name args =
Expand Down
10 changes: 5 additions & 5 deletions lib/functoria/device.mli
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ val files : ('a, 'b) t -> Info.t -> Fpath.Set.t
(** [files t info s] is the list of files generated configure-time. *)

val keys : ('a, 'b) t -> Key.t list
(** [keys t] is the list of command-line keys which can be used to configure
[t]. *)
(** [keys t] is the list of keys which can be used to configure [t]. *)

val runtime_keys : ('a, 'b) t -> Runtime_key.t list
(** [keys t] is the list of command-line keys which can be used to run [t]. *)
val runtime_args : ('a, 'b) t -> Runtime_arg.t list
(** [runtime_args t] is the list of command-line arguments which can be used to
configure [t] at runtime. *)

(** {1 Code Generation} *)

Expand Down Expand Up @@ -109,7 +109,7 @@ val v :
?install:(Info.t -> Install.t) ->
?install_v:(Info.t -> Install.t Key.value) ->
?keys:Key.t list ->
?runtime_keys:Runtime_key.t list ->
?runtime_args:Runtime_arg.t list ->
?extra_deps:'b list ->
?connect:(Info.t -> string -> string list -> 'a code) ->
?dune:(Info.t -> Dune.stanza list) ->
Expand Down
39 changes: 26 additions & 13 deletions lib/functoria/engine.ml
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,35 @@ let if_keys x =
x

module Keys = struct
type t = Key.Set.t * Runtime_key.Set.t
type t = Key.Set.t

let union (a, b) (c, d) = (Key.Set.union a c, Runtime_key.Set.union b d)
let empty = (Key.Set.empty, Runtime_key.Set.empty)
let union a b = Key.Set.union a b
let empty = Key.Set.empty
end

let all_keys x =
let keys x =
Impl.collect
(module Keys)
(function
| Dev c ->
let keys = Device.keys c in
let runtime_keys = Device.runtime_keys c in
(Key.Set.of_list keys, Runtime_key.Set.of_list runtime_keys)
| If cond -> (Key.deps cond, Runtime_key.Set.empty)
| App -> (Key.Set.empty, Runtime_key.Set.empty))
| Dev c -> Key.Set.of_list (Device.keys c)
| If cond -> Key.deps cond
| App -> Keys.empty)
x

module Runtime_args = struct
type t = Runtime_arg.Set.t

let union a b = Runtime_arg.Set.union a b
let empty = Runtime_arg.Set.empty
end

let runtime_args x =
Impl.collect
(module Runtime_args)
(function
| Dev c -> Runtime_arg.Set.of_list (Device.runtime_args c)
| If _ -> Runtime_args.empty
| App -> Runtime_args.empty)
x

module Packages = struct
Expand All @@ -58,13 +71,13 @@ let packages t =
let aux = function
| Dev c ->
let pkgs = Device.packages c in
let runtime_keys = Device.runtime_keys c in
let runtime_args = Device.runtime_args c in
let extra_pkgs =
List.fold_left
(fun acc k ->
let pkgs = Runtime_key.packages k in
let pkgs = Runtime_arg.packages k in
Package.Set.(union acc (of_list pkgs)))
Package.Set.empty runtime_keys
Package.Set.empty runtime_args
in
let aux x = Package.Set.(union (of_list x) extra_pkgs) in
Key.(pure aux $ pkgs)
Expand Down
7 changes: 5 additions & 2 deletions lib/functoria/engine.mli
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@
val if_keys : Impl.abstract -> Key.Set.t
(** [if_keys t] is the set of [if] keys in the graph [t]. *)

val all_keys : Impl.abstract -> Key.Set.t * Runtime_key.Set.t
(** [all_keys t] is the set of keys in the graph [t]. *)
val keys : Impl.abstract -> Key.Set.t
(** [keys t] is the set of keys in the graph [t]. *)

val runtime_args : Impl.abstract -> Runtime_arg.Set.t
(** [runtime_args t] is the set of runtime arguments in the graph [t]. *)

val packages : Impl.abstract -> Package.t list Key.value
(** [packages t] is the set of packages in the graph [t]. *)
Expand Down
12 changes: 6 additions & 6 deletions lib/functoria/functoria.ml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

module Context = Context
module Key = Key
module Runtime_key = Runtime_key
module Runtime_arg = Runtime_arg
module Package = Package
module Info = Info
module Type = Type
Expand All @@ -44,11 +44,11 @@ module type KEY =
and type t = Key.t
and type Set.t = Key.Set.t

module type RUNTIME_KEY =
module type of Runtime_key
with type 'a key = 'a Runtime_key.key
and type t = Runtime_key.t
and type Set.t = Runtime_key.Set.t
module type RUNTIME_ARG =
module type of Runtime_arg
with type 'a arg = 'a Runtime_arg.arg
and type t = Runtime_arg.t
and type Set.t = Runtime_arg.Set.t

(** Devices *)

Expand Down
12 changes: 6 additions & 6 deletions lib/functoria/functoria.mli
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,11 @@ module type KEY =
and type Set.t = Key.Set.t

(** The signature for run-time command-line keys. *)
module type RUNTIME_KEY =
module type of Runtime_key
with type 'a key = 'a Runtime_key.key
and type t = Runtime_key.t
and type Set.t = Runtime_key.Set.t
module type RUNTIME_ARG =
module type of Runtime_arg
with type 'a arg = 'a Runtime_arg.arg
and type t = Runtime_arg.t
and type Set.t = Runtime_arg.Set.t

module Package = Package
module Info = Info
Expand Down Expand Up @@ -172,7 +172,7 @@ module Type = Type
module Impl = Impl
module Context = Context
module Key = Key
module Runtime_key = Runtime_key
module Runtime_arg = Runtime_arg
module Opam = Opam
module Lib = Lib
module Tool = Tool
Expand Down
12 changes: 6 additions & 6 deletions lib/functoria/info.ml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type t = {
name : string;
output : string option;
keys : Key.Set.t;
runtime_keys : Runtime_key.Set.t;
runtime_args : Runtime_arg.Set.t;
context : Context.t;
packages : Package.t String.Map.t;
opam :
Expand Down Expand Up @@ -62,13 +62,13 @@ let pins packages =
[] packages

let keys t = Key.Set.elements t.keys
let runtime_keys t = Runtime_key.Set.elements t.runtime_keys
let runtime_args t = Runtime_arg.Set.elements t.runtime_args
let context t = t.context

let v ?(config_file = Fpath.v "config.ml") ~packages ~keys ~runtime_keys
let v ?(config_file = Fpath.v "config.ml") ~packages ~keys ~runtime_args
~context ?configure_cmd ?pre_build_cmd ?lock_location ~build_cmd ~src name =
let keys = Key.Set.of_list keys in
let runtime_keys = Runtime_key.Set.of_list runtime_keys in
let runtime_args = Runtime_arg.Set.of_list runtime_args in
let opam ~extra_repo ~install ~opam_name =
Opam.v ~depends:packages ~install ~pins:(pins packages) ~extra_repo
?configure:configure_cmd ?pre_build:pre_build_cmd ?lock_location
Expand All @@ -90,7 +90,7 @@ let v ?(config_file = Fpath.v "config.ml") ~packages ~keys ~runtime_keys
config_file;
name;
keys;
runtime_keys;
runtime_args;
packages;
context;
output = None;
Expand Down Expand Up @@ -121,7 +121,7 @@ let pp verbose ppf ({ name; keys; context; output; _ } as t) =

let t =
let i =
v ~config_file:(Fpath.v "config.ml") ~packages:[] ~keys:[] ~runtime_keys:[]
v ~config_file:(Fpath.v "config.ml") ~packages:[] ~keys:[] ~runtime_args:[]
~build_cmd:"dummy" ~context:Context.empty ~src:`None "dummy"
in
Type.v i
10 changes: 5 additions & 5 deletions lib/functoria/info.mli
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ val opam :
(** [opam scope t] is [t]'opam file to install in the [scope] context.*)

val keys : t -> Key.t list
(** [keys t] are the configure-time keys declared by the project. *)
(** [keys t] is the list of keys which can be used to configure [t]. *)

val runtime_keys : t -> Runtime_key.t list
(** [keys t] are the runtime keys declared by the project and used by the
declared devices. *)
val runtime_args : t -> Runtime_arg.t list
(** [runtime_args t] is the list of command-line arguments which can be used to
configure [t] at runtime. *)

val context : t -> Context.t
(** [parsed t] is a value representing the command-line argument being parsed. *)
Expand All @@ -67,7 +67,7 @@ val v :
?config_file:Fpath.t ->
packages:Package.t list ->
keys:Key.t list ->
runtime_keys:Runtime_key.t list ->
runtime_args:Runtime_arg.t list ->
context:Context.t ->
?configure_cmd:string ->
?pre_build_cmd:(Fpath.t option -> string) ->
Expand Down
8 changes: 4 additions & 4 deletions lib/functoria/job.ml
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,23 @@ module Keys = 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 ->
let keys = Runtime_key.Set.of_list @@ Info.runtime_keys i in
let keys = Runtime_arg.Set.of_list @@ Info.runtime_args i in
Fmt.pf ppf "@[<v>%a@]@."
Fmt.(iter Runtime_key.Set.iter Runtime_key.serialize)
Fmt.(iter Runtime_arg.Set.iter Runtime_arg.serialize)
keys)
end

let keys ?(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_key.module_name 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 files _ = [ file ] in
let connect info _ = function
| [ argv ] ->
Fmt.str "return %s.(with_argv (runtime_keys ()) %S %s)" runtime_modname
Fmt.str "return %s.(with_argv (runtime_args ()) %S %s)" runtime_modname
(Info.name info) argv
| _ -> failwith "The keys connect should receive exactly one argument."
in
Expand Down