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
Add when
action available in lockfiles
#8443
Conversation
25f6b1d
to
8bbf622
Compare
Why not expand them to |
I thought about doing that but it felt like a hack and that it would be clearer to make it a separate type of action_exec. Happy to change it if that's the consensus though. |
There is obviously some overlap with I think we will need to choose one of them as otherwise we will have too many ways of doing the same thing. |
doc/reference/actions.rst
Outdated
(progn | ||
(echo "You're using ") | ||
(when (= %{system} linux) (echo "Linux!")) | ||
(when (= %{system} macosx) (echo "MacOS!"))) |
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.
At first I thought this could be a simpler replacement for case
and cond
, but upon further inspection we lose the ability to stop at the first branch. Also another way to write this would be to use concurrent
(on the last two args anyway). That way you wouldn't have to sequentially do all the checks.
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.
It's deliberately much simpler than case
and cond
and it's supposed to behave like the when
keyword in many lisp languages. In practice it's going to be used to filter out opam commands. It might not be practically useful to expose this in non-pkg files, at least for now. Possibly this example is misleading as it makes it look like a case statement when it isn't one. @rgrinberg what do you think?
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.
Also another way to write this would be to use
concurrent
(on the last two args anyway). That way you wouldn't have to sequentially do all the checks.
Do you just mean as an optimization?
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.
Possibly this example is misleading as it makes it look like a case statement when it isn't one. @rgrinberg what do you think?
I'd rather introduce whatever is needed to keep lock files as small and as readable as possible.
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.
To clarify I was asking whether it makes sense for when
to be available in dune
files or only in lock files.
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.
At the moment? There's no need to make it available. Eventually, yes the plan is to completely unify dune and lock files.
I don't think a |
8bbf622
to
94f68b4
Compare
It would be better to avoid changing it. |
Note that the |
In that case I'd find it clearer to not add E.g. when specifying dependencies you only need parens for packages with constraints
Though of course there are also counter examples to this such as |
Ah I didn't realize that the logic for expanding actions in lockfiles is in a different place to expanding actions in |
Staying true to lisp (scheme rather) isn't my only motivation. It's just that in dune bare words are already interchangeable with strings in all contexts. So |
fe1cc21
to
c445133
Compare
when
and nothing
actionswhen
action availabel in lockfiles
when
action availabel in lockfileswhen
action available in lockfiles
I've removed the |
c45e3f7
to
a5bb60e
Compare
@rgrinberg I added a test with a single conditional action whose condition is false and I get this error:
It seems to happen whenever a rule's action is effectively |
a5bb60e
to
f309a25
Compare
The point of this error is to prevent you from sandboxing rules that don't require sandboxing. Although looking at this again, it really just makes things difficult for no reason. I think dune should just not sandbox anything if there's no sandboxing required in such cases. |
For now you can workaround but always including something that needs sandboxing in the action. E.g. |
Agreed. Will workaround for now. |
f309a25
to
73da3a0
Compare
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 code looks quite good, the comment about system
does too (however I am a bit worried about running true
on Windows - as @rgrinberg says, this this restriction can be lifted in a separate PR).
src/dune_rules/pkg_rules.ml
Outdated
(* An action which has no effect. Note that we can't use [Action.Progn []] | ||
here because currently every rule must have at least one action that | ||
requires sandboxing. *) | ||
let action_noop = Action.System "true" |
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.
Instead of adding the hack in the code, you could just add it in the test. E.g.
(progn
(system "true")
(when ...))
All real builds are going to have at least 1 run action, so this limitation isn't going to matter much.
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.
That wouldn't test anything not already tested in the previous test so I'll just remove the empty case then.
73da3a0
to
0f48ed4
Compare
> (run echo e)))) | ||
> EOF | ||
|
||
$ dune build .pkg/test/target/ |
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 will be used to implement opam filters on commands. Signed-off-by: Stephen Sherratt <stephen@sherra.tt>
0f48ed4
to
66088be
Compare
The
when
action will be used in package management to implement build commands which are conditional on some filter (this is a feature of opam we need to copy). Thenothing
action does nothing and is used internally to handle the case whenwhen
's condition is false. Thenothing
action is exposed as it can be handy when writing dune files to be able to temporarily create an action which does nothing when you're not sure which action to use but you need the file to parse correctly to test some other stanza (currently it's possible to get the same effect by using(progn)
with no arguments but this is a hack).