Closed ghost closed 4 years ago
I feel that using the profile to encode information is a bad pattern. We have for example multiple profiles that are equivalent to release. The ppx has no way to guess that those other profiles should be treated like release.
That makes sense. I suppose we could have a new parameter drop-inline-tests
. It would default to (= %{profile} release)
, but you could manually set it for other profiles.
In that case, we don't even need to implement the full generic proposal right now, we can only pass drop-inline-tests
manually as we do for library-name
and leave the general solution for later since it is a bit more work.
I thought about this a bit more, and I'm wondering if this is at all necessary with link time code gen. We can very easily create a little dune library that dune can generate on every build with information such as profile
, context
etc. That seems like a useful feature for other tools invoked at build time as well.
That's a good point.
The feature described in this issues has been added to dune BTW, so we can safely close it.
In retrospect, using link time code gen is a bad idea here. We don't want to rebuild the ppx binary just because context/profile changed. I'd much prefer if there was a simple way to pass these values at runtime.
This proposal describes a way to pass more information from dune to ppx rewriters.
Description
We extend the
ppx_rewriter
andppx_deriver
library kinds to take acookies
parameter. This parameters describe a list of cookies that dune should pass to the ppx rewriter. The argument ofcookies
is a list of cookie definition of the form(<name> <string-with-variables>)
, such as(profile %{profile})
.For instance:
When invoking the final ppx driver that links all the ppx rewriter, dune will collect all the cookies requested by the various ppx rewriters and pass them via the command line as follow:
When two ppx rewriters request the same cookie, the associated value must be equal. Otherwise dune will error out.
To match the current behavior, dune will also add the following cookie to this list:
(library-name \"%{library-name}\")
.