-
Notifications
You must be signed in to change notification settings - Fork 412
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
enabled_if #819
enabled_if #819
Conversation
this boolean language looks quite simple and during development all expressions should be evaluated on every run, so runtime checks will do. Currently we already keep the type of variable expansion (string or path). We can add a version type |
Okay, makes sense. I'm wondering how we should organize things however. |
Maybe a new |
@diml now that we have a Value module, I'd like to move this along. One question is how to handle expressions like : |
Yes, a runtime error seems fine for now. These expressions are very simple and will be evaluated often during development, so there is no need for heavy machinery. |
Okay. One last point is that we might be closing the door on things like |
That seems fine, but if we add support for reading environment variables like this, then |
Okay, this PR has been revived and seems to be in a good enough form for a v1 of the feature. The only thing that remains is to make sure that the field is available only for |
I added support for the |
This PR is a pre-req as well for #924. |
Ok, could you write the documentation for this feature? I'd like to read the semantic of boolean expressions before reading the code that implements it. |
Okay, will add that to the TODO list. As a tl;dr:
I considered introducing |
Thanks, that seems reasonable |
src/blang.ml
Outdated
| Or of 'a t list | ||
| Compare of Op.t * 'a * 'a | ||
|
||
let compare_vals ~dir (x : Value.t) (y : Value.t) = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about putting this in Value.L
?
src/simple_rules.ml
Outdated
~targets:Alias | ||
~targets_dir:dir | ||
~scope) | ||
let add_alias () = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this code would be slightly clearer if written this way:
let enabled =
match alias_conf.enabled_if with
| None -> true
| Some blang -> ...
in
if enabled then
add_alias sctx ...
src/stdune/sexp.ml
Outdated
@@ -81,6 +81,11 @@ module Of_sexp = struct | |||
Printf.ksprintf (fun msg -> | |||
of_sexp_error loc ?hint ("No variables allowed " ^ msg)) fmt | |||
|
|||
let _fix f = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not modify the type of fix
instead of adding this function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just an artefact from the rebase. Removed.
src/jbuild.ml
Outdated
Compare (op, x, y)))) | ||
in | ||
let t = | ||
fix begin fun (t : String_with_vars.t Blang.t Sexp.Of_sexp.t) -> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indentation looks wrong
src/jbuild.ml
Outdated
[ "or", repeat t >>| (fun x -> Or x) | ||
; "and", repeat t >>| (fun x -> And x) | ||
] @ ops | ||
|> sum ~rest:(String_with_vars.t >>| fun v -> Expr v) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm dubious about this rest
argument. I feel like it's going to make error messages worse. Could you use if_list
instead?
@diml I've addressed all your comments. Actually, |
doc/dune-files.rst
Outdated
|
||
expr := (and <expr>+) | ||
| (or <expr>+) | ||
| (compare <op> <template> <template>) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be: (<op> <template> <template>)
src/value.ml
Outdated
let compare x y = | ||
match x, y with | ||
| String x, String y -> String.compare x y | ||
| Path x, Path y -> Path.compare x y |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Dir x, Dir y
case is missing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, we don't need this function anyway. I got rid of it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
f7a9dc8
to
bf89dee
Compare
Looks good, but it seems that the doc comment I added on |
@diml oops, the subsequent commit removed it during the rebase. The doc is now back. |
This field controls whether the alias/test will be run or not. Boolean expressions are defined using the Blang.t type. This type represents simple boolean expressions that become useful when we allow to interpolate variables into them. Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
Squashed & Rebased. Also added a change log entry. |
CHANGES: - Fix lookup of command line specified files when `--root` is given. Previously, passing in `--root` in conjunction with `--workspace` or `--config` would not work correctly (ocaml/dune#997, @rgrinberg) - Add support for customizing env nodes in workspace files. The `env` stanza is now allowed in toplevel position in the workspace file, or for individual contexts. This feature requires `(dune lang 1.1)` (ocaml/dune#1038, @rgrinberg) - Add `enabled_if` field for aliases and tests. This field controls whether the test will be ran using a boolean expression language. (ocaml/dune#819, @rgrinberg) - Make `name`, `names` fields optional when a `public_name`, `public_names` field is provided. (ocaml/dune#1041, fix ocaml/dune#1000, @rgrinberg) - Interpret `X` in `--libdir X` as relative to `PREFIX` when `X` is relative (ocaml/dune#1072, fix ocaml/dune#1070, @diml) - Add support for multi directory libraries by writing `(include_subdirs unqualified)` (ocaml/dune#1034, @diml) - Add `(staged_pps ...)` to support staged ppx rewriters such as ones using the OCaml typer like `ppx_import` (ocaml/dune#1080, fix ocaml/dune#193, @diml) - Use `-opaque` in the `dev` profile. This option trades off binary quality for compilation speed when compiling .cmx files. (ocaml/dune#1079, fix ocaml/dune#1058, @rgrinberg) - Fix placeholders in `dune subst` documentation (ocaml/dune#1090, @emillon, thanks @trefis for the bug report) - Add locations to errors when a missing binary in PATH comes from a dune file (ocaml/dune#1096, fixes ocaml/dune#1095, @rgrinberg)
Problem
The problem this PR is trying to solve is a bit specific to dune, but it's likely that it will be encountered by other projects as well. Currently, dune has a complicated script for generating test definitions that make sure tests run only in environments which support them. For example, some tests may not run on win32. A mechanism to enable tests conditionally would fix these problems.
Proposal
Add an
enabled_if
field to aliases to toggle the execution of the alias. This field will be valued by a little EDSL for expressing boolean expressions. Here's an example of the kind of conditions we'd express with it:Progress
This stalled a bit since I'm not sure how to do handle type safety here. Ideally, we only allow numbers and versions to be compared with
>=
,<
, etc. I guess we really need to annotate which variables are comparable and making sure that we don't compare numbers to strings or versions.