[eeps] New - EEP 44: Additional preprocessor directives
Björn Gustavsson
bjorn@REDACTED
Wed Oct 14 12:43:36 CEST 2015
On Tue, Oct 13, 2015 at 11:31 AM, Vlad Dumitrescu <vladdu55@REDACTED> wrote:
> Hi!
>
> While I think that the proposed changes are good and will improve the
> preprocessor, I am worried about the effect it will have on how code is
> build and on code that may run on unspecified OTP versions (escripts). If I
> understand correctly, these are some of the effects:
Actually, an escript with source included as text (as opposed to
pre-compiled) is ideal for the new extensions; because the escript
is executed immediately after compilation you are guaranteed that
the compilation environment and run-time environment are the
same.
> * one will now be forced to compile within an environment identical to the
> target - so that all the preprocessor conditions resolve to the right
> values. This includes having all dependencies (even transitive?) installed
> in the development environment and the build server, not only OTP. Is the
> application descriptor enough to define that, or does it need to be
> extended? Maybe the new package manager is supposed to help here?
No one is forcing anyone here. You are not forced to use new features
if they are not useful to you. This new feature is not meant to solve
cross-compiling problems or supporting several releases of OTP with
one set of compiled beam files.
Also, some uses of conditional compilation can be useful even if you
need to support several releases at once. For example, if you want
to continue to use a deprecated function, but don't want any warnings
you might want to do:
-ifdef(NOW_DEPRECATED).
-compile({nowarn_deprecated_function,[{erlang,now,0}]}).
-endif.
> * if one targets multiple versions, then the set-up of the development
> environment is unwieldy unless one needs to use something like kerl to
> manage the multiple environments. It feels a bit wrong to have OTP depend
> indirectly on a third party application... I think that OTP should provide
> tools to help with that.
Again, this is not an issue that this EEP is intended to solve.
> * if not deploying an OTP application or a full system, one can't know if
> the target will fulfill the expected conditions - what about compiled
> escripts?
You could solve it in the way you have solved it before, ignoring the
new features.
Or you could put the conditional compilation into the cleartext part of
the escript. For example:
main(Args) ->
Env = setup(),
precompiled_stuff(Args, Env).
-if ?OTP_RELEASE == 19.
setup() ->
fun(...) -> ... end.
-elif ?OTP_RELEASE == 20.
setup() ->
fun(...) -> ... end.
-endif.
/Björn
--
Björn Gustavsson, Erlang/OTP, Ericsson AB
More information about the eeps
mailing list