diff options
author | Björn Gustavsson <[email protected]> | 2014-03-25 05:38:28 +0100 |
---|---|---|
committer | Björn Gustavsson <[email protected]> | 2014-03-25 05:38:28 +0100 |
commit | a6e415279913338f175f84400dcc99c16bba572b (patch) | |
tree | f6f09fe0acab42fa8ce5feaaa4eabc58c5a05f1d /lib/asn1/src/asn1ct_gen.erl | |
parent | 05432fb0eec53cab53670e053f22aa3c3ad61d97 (diff) | |
parent | dfd97aa734fe07b4885d37d255b6e5debfcb5783 (diff) | |
download | otp-a6e415279913338f175f84400dcc99c16bba572b.tar.gz otp-a6e415279913338f175f84400dcc99c16bba572b.tar.bz2 otp-a6e415279913338f175f84400dcc99c16bba572b.zip |
Merge branch 'bjorn/asn1/ifndef-protected-hrls/OTP-11804'
* bjorn/asn1/ifndef-protected-hrls/OTP-11804:
Protect generated .hrl files from multiple inclusions
Diffstat (limited to 'lib/asn1/src/asn1ct_gen.erl')
-rw-r--r-- | lib/asn1/src/asn1ct_gen.erl | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/lib/asn1/src/asn1ct_gen.erl b/lib/asn1/src/asn1ct_gen.erl index 4707e517b4..44b050e59d 100644 --- a/lib/asn1/src/asn1ct_gen.erl +++ b/lib/asn1/src/asn1ct_gen.erl @@ -1125,7 +1125,22 @@ pgen_info() -> open_hrl(OutFile,Module) -> File = lists:concat([OutFile,".hrl"]), _ = open_output_file(File), - gen_hrlhead(Module). + gen_hrlhead(Module), + Protector = hrl_protector(OutFile), + emit(["-ifndef(",Protector,").\n", + "-define(",Protector,", true).\n" + "\n"]). + +hrl_protector(OutFile) -> + BaseName = filename:basename(OutFile), + P = "_" ++ string:to_upper(BaseName) ++ "_HRL_", + [if + $A =< C, C =< $Z -> C; + $a =< C, C =< $a -> C; + $0 =< C, C =< $9 -> C; + true -> $_ + end || C <- P]. + %% EMIT functions ************************ %% *************************************** @@ -1232,6 +1247,8 @@ pgen_hrl(Erules,Module,TypeOrVal,Options,_Indent) -> 0 -> 0; Y -> + Protector = hrl_protector(get(outfile)), + emit(["-endif. %% ",Protector,"\n"]), close_output_file(), asn1ct:verbose("--~p--~n", [{generated,lists:concat([get(outfile),".hrl"])}], |