<div dir="ltr">Hi!<div><br></div><div>This is a shout of pain we got while preparing our project for upcoming OTP release.<br><div><br></div><div>The problem:</div><div> * We compile our code for production using warnings_as_errors option. This helps us to keep the code tidy.</div><div> * OTP21 deprecates some functions (erlang:get_stacktrace/0, ssl:ssl_accept/0, may be more)</div><div> * OTP20 does not support new API (catch C:R:S, ssl:handshake/2)<br><br>So, to be able to go with both OTP20 and OTP21, we need some hacks.</div><div><br></div><div>First thought: let's pass {nowarn_deprecated_function, [...]} with Emakefile, letting old code</div><div>compile smootly in newer OTP.</div><div>But that cannot be done — this option is only recognized when given in files.<br><br>Second thought: OK, let's just add this option to all affected files.</div><div>But "Warning: erlang:get_stacktrace/0 is not a deprecated function"</div><div><br></div><div>So, we needed to implement some preprocessor logic which adds nowarn only when compiling with OTP21.</div><div>Luckily, there is a OTP_RELEASE var defined in OTP21:</div><div><div>-ifdef(OTP_RELEASE).</div><div>-compile({nowarn_deprecated_function, [{erlang, get_stacktrace, 0}]}).<br></div><div>-endif.<br></div></div><div><br></div><div>Adding that to tens of files (large project, lots of dependencies in-tree) seemed too ugly,</div><div>so we implemented a parse_transform which can be added to Emakefile.</div><div><br></div><div>Parse transform itself: <a href="https://gist.github.com/stolen/6a55221ffb906bde712cd939a729718d">https://gist.github.com/stolen/6a55221ffb906bde712cd939a729718d</a></div><div><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr"><div><font face="'courier new', monospace">Danil Zagoskin | <a href="mailto:z@gosk.in" target="_blank">z@gosk.in</a></font></div></div></div></div></div></div>