[erlang-questions] Deprecation warnings: OTP20 and OTP21 compatible code

Danil Zagoskin z@REDACTED
Tue Jun 5 14:21:36 CEST 2018


This is a shout of pain we got while preparing our project for upcoming OTP

The problem:
 * We compile our code for production using warnings_as_errors option. This
helps us to keep the code tidy.
 * OTP21 deprecates some functions (erlang:get_stacktrace/0,
ssl:ssl_accept/0, may be more)
 * OTP20 does not support new API (catch C:R:S, ssl:handshake/2)

So, to be able to go with both OTP20 and OTP21, we need some hacks.

First thought: let's pass {nowarn_deprecated_function, [...]} with
Emakefile, letting old code
compile smootly in newer OTP.
But that cannot be done — this option is only recognized when given in

Second thought: OK, let's just add this option to all affected files.
But "Warning: erlang:get_stacktrace/0 is not a deprecated function"

So, we needed to implement some preprocessor logic which adds nowarn only
when compiling with OTP21.
Luckily, there is a OTP_RELEASE var defined in OTP21:
-compile({nowarn_deprecated_function, [{erlang, get_stacktrace, 0}]}).

Adding that to tens of files (large project, lots of dependencies in-tree)
seemed too ugly,
so we implemented a parse_transform which can be added to Emakefile.

Parse transform itself:

Danil Zagoskin | z@REDACTED
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20180605/81e4f912/attachment.htm>

More information about the erlang-questions mailing list