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

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


Hi!

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

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
files.

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:
-ifdef(OTP_RELEASE).
-compile({nowarn_deprecated_function, [{erlang, get_stacktrace, 0}]}).
-endif.

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:
https://gist.github.com/stolen/6a55221ffb906bde712cd939a729718d

-- 
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