Skip to content

Commit 55e8520

Browse files
bjorngtomas-abrahamsson
authored andcommitted
epp: Add the pre-defined macro OTP_RELEASE
Add a new pre-defined macro called OTP_RELEASE that will expand to an integer being the OTP version. Thus, in OTP 19 the value will be the integer 19. The OTP_RELEASE macro is particularly useful in order to have different source code depending on new language features or new features in the type specification syntax. Those features are only introduced in major versions of OTP. To be truly useful, the -if preprocessor directive need to be implemented. That is the purpose of the next commit. Code that will need to work in both OTP 18 and OTP 19 can be structured in the following way: -ifdef(OTP_RELEASE). %% Code that only works in OTP 19 and later. -else. %% Code that will work in OTP 18. -endif.
1 parent 5a4112b commit 55e8520

2 files changed

Lines changed: 5 additions & 2 deletions

File tree

lib/stdlib/src/epp.erl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,7 @@ init_server(Pid, Name, Options, St0) ->
571571
predef_macros(File) ->
572572
Machine = list_to_atom(erlang:system_info(machine)),
573573
Anno = line1(),
574+
OtpVersion = list_to_integer(erlang:system_info(otp_release)),
574575
Defs = [{'FILE', {none,[{string,Anno,File}]}},
575576
{'FUNCTION_NAME', undefined},
576577
{'FUNCTION_ARITY', undefined},
@@ -580,7 +581,8 @@ predef_macros(File) ->
580581
{'BASE_MODULE', undefined},
581582
{'BASE_MODULE_STRING', undefined},
582583
{'MACHINE', {none,[{atom,Anno,Machine}]}},
583-
{Machine, {none,[{atom,Anno,true}]}}
584+
{Machine, {none,[{atom,Anno,true}]}},
585+
{'OTP_RELEASE', {none,[{integer,Anno,OtpVersion}]}}
584586
],
585587
maps:from_list(Defs).
586588

lib/stdlib/test/epp_SUITE.erl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,8 @@ otp_8130(Config) when is_list(Config) ->
799799
PreDefMacs = macs(Epp),
800800
['BASE_MODULE','BASE_MODULE_STRING','BEAM','FILE',
801801
'FUNCTION_ARITY','FUNCTION_NAME',
802-
'LINE','MACHINE','MODULE','MODULE_STRING'] = PreDefMacs,
802+
'LINE','MACHINE','MODULE','MODULE_STRING',
803+
'OTP_RELEASE'] = PreDefMacs,
803804
{ok,[{'-',_},{atom,_,file}|_]} = epp:scan_erl_form(Epp),
804805
{ok,[{'-',_},{atom,_,module}|_]} = epp:scan_erl_form(Epp),
805806
{ok,[{atom,_,t}|_]} = epp:scan_erl_form(Epp),

0 commit comments

Comments
 (0)