-
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
Variables for artifacts #2417
Variables for artifacts #2417
Conversation
So far the following are working:
Next I will try to implement virtual targets to be used in the command line. This will make the whole thing very easy to test as well. |
1af1042
to
b94fdfe
Compare
b391dd2
to
ef1c19b
Compare
0fd1944
to
07e1c38
Compare
This is ready for review. In order to keep it as simple as possible (both for the user as for the implementation), I made a series of simplifications with respect to the discussion in #2416, which I find fit nicely with the purpose of these variables and the fact that they are intended for advanced users:
One other interesting change is that I now use the parser for the dependency specification to parse the command line (in the non-alias case), opening the door to |
26 | (alias | ||
27 | (name t3) | ||
28 | (deps %{cmo:xxxx})) | ||
Error: No rule found for xxxx.cmo |
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.
When the object being referred to (here, a module named xxxx
in the current directory), the macro expands anyway to a fictitious filename (here, xxxx.cmo
) which then fails but with a message that is a bit misleading and does not mention the initial macro.
The problem is that it is not currently possible (as far as I can see) to propagate an error that occurs during expansion of a macro.
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.
Do you mean to propagate the location?
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.
nervermind, I see what you mean. Currently, the best is to error out while expanding the macro
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, yh, we do need to allow reporting proper error when expanding macros. The result of expand_var
is actually a bit misleading. We return Error <expansion>
for things that need to be expanded later. Instead of returning a result
, we should return something like this:
type expanded = Static of Value.t list | Dynamic of Pform.Expansion.t | Error of User_message.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.
I am trying to see how far the error case needs to be propagated inside the existing infrastructure.
Does it sound reasonable that the result of String_with_vars.expand
would be a (Value.t list, User_message.t) result
or maybe even (Value.t, User_message.t) result list
?
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 seems right. We could also use the Or_exn.t
type here since we use it for the same purpose in other places. Not too sure which of the two types you propose is better though.
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.
Thanks for the hint, will look into 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.
I think this is now fixed, thanks.
bin/target.ml
Outdated
(Dune.Dir_contents.artifacts (Dune.Dir_contents.get sctx ~dir)) name | ||
in | ||
let expander = Dune.Expander.set_lookup_module expander ~lookup_module in | ||
let expander = Dune.Expander.set_lookup_library expander ~lookup_library in |
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 would be better to set these lookup functions inside the function Super_context.expander
but Dir_contents
depends on Super_context
so there is a dependency issue.
Could you add some doc in the manual for this feature? |
b27af32
to
b93868d
Compare
bin/target.ml
Outdated
Dune.Dune_file.Dep_conf.decode | ||
in | ||
Dune_lang.Decoder.parse parser Univ_map.empty | ||
(Dune_lang.parse_string ~fname:"command line" ~mode:Dune_lang.Parser.Mode.Single s) |
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.
Could you move this parsing into a cmdliner Arg.conv
value? i.e. like the path
value in bin/arg.ml
. The idea would be to have:
val Arg.dep : Dune.Dune_file.Dep_conf.t Arg.conv
Then the error would be reported by cmdliner while parsing the command line, which seems nicer to me.
Since the parsing reports User_error.E
exception, you will need to extract the error message from the User_message.t
value. You can use this (from .../sexp_tests.ml
) for that:
let extract_error_message (msg : User_message.t) =
Format.asprintf "%a"
Pp.render_ignore_tags
(User_message.pp { msg with loc = None })
|> String.drop_prefix ~prefix:"Error: "
|> Option.value_exn
|> String.trim
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.
Good idea, will do.
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 now done.
b93868d
to
ea3ef79
Compare
ea3ef79
to
ef9badb
Compare
ef9badb
to
d062055
Compare
70c31f6
to
d54b5af
Compare
Done. I think all other issues have been addressed so this is again ready for review :) |
bin/arg.ml
Outdated
match parse_alias s with | ||
| None -> x | ||
| Some (true, s) -> alias_rec s | ||
| Some (false, s) -> alias s |
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 believe this function is parsing (file @foo)
as Alias_rec "foo"
. We should probably call parse_alias
before
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.
You are right, I had missed that; will fix.
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 fixed now, thanks.
I agree; I removed |
Planning to merge this after CI passes. |
84cc293
to
dffa1f8
Compare
Actually, there is still an outstanding issue : currently these variables cannot be used in the I don't think there is any fundamental problem here, as the variables do not declare targets so it is "just" a matter of delaying their expansion until after the I am looking int this. If it looks like it requires some work, maybe we can merge this as-is, since it already adds some new functionality (command-line convenience targets), and then do the remaining work on a follow-up PR. |
@diml @rgrinberg I would appreciate your opinion on the last commit ( The idea is to separate the computation of the targets of Right now the I am duplicating the setup of the build arrow for |
Would it be enough to make the expansion of the artifact variables dynamic? That should break the cycle |
1988562
to
fc09300
Compare
Thanks for the hint! I gave it a try (commit "Expand artifact variables dynamically") and now it works, but am not 100% sure about the implementation. Could you take a look and let me know if it looks like it is in the right direction? |
;; (rule | ||
;; (targets my2.cmxs) | ||
;; (deps %{cmx:x2}) | ||
;; (action (run %{ocamlopt} -shared -o %{targets} %{cmxa:plugin} %{cmx:x3}))) |
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.
You might as well make this a separate failing test I believe. Should be quite useful down the line and this way we won't forget to uncomment it if someone adds support
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.
Good idea, will do.
I approved because I don't think it's a good idea to delay this PR further. We can resolve whatever issues come up in separate PR's. Let's just make sure the test suite is extensive. |
61f2c86
to
f73e157
Compare
Signed-off-by: Nicolás Ojeda Bär <n.oje.bar@gmail.com>
Signed-off-by: Nicolás Ojeda Bär <n.oje.bar@gmail.com>
cbd9d9a
to
38fe098
Compare
Signed-off-by: Nicolás Ojeda Bär <n.oje.bar@gmail.com>
Signed-off-by: Nicolás Ojeda Bär <n.oje.bar@gmail.com>
38fe098
to
737e6e7
Compare
OK, planning to merge once the CI passes. Thanks! |
Signed-off-by: Nicolás Ojeda Bär <n.oje.bar@gmail.com>
Signed-off-by: Nicolás Ojeda Bär <n.oje.bar@gmail.com>
737e6e7
to
a50ae68
Compare
Merged. Thanks everyone for the help! |
I just had a quick look and it looks good to me! |
This PR implements #2416, closes #2416, closes #1630, closes #1544