Skip to content

Commit

Permalink
Merge branch 'ta/werror' into dev
Browse files Browse the repository at this point in the history
* ta/werror:
  snmp: extend warnings_as_errors test
  systools: add warnings_as_errors option
  asn1ct: add warnings_as_errors option
  leex: optimize werror/1
  yecc: optimize werror/1
  yecc: use more descriptive name: 'werror'
  leex: use more descriptive name: 'werror'
  compile: optimize werror/1
  compile: log warnings as errors if -Werror is enabled
  yecc: log warnings as errors if -Werror is enabled
  leex: log warnings as errors if -Werror is enabled
  yecc: honour -Werror passed from erlc
  leex: honour -Werror passed from erlc
  Do not write beam file if Werr and warnings /= []
  parsetools: test if warnings_as_errors writes file

OTP-9536
  • Loading branch information
proxyles committed Sep 13, 2011
2 parents a406554 + bbdc6a3 commit e9e118a
Show file tree
Hide file tree
Showing 18 changed files with 472 additions and 192 deletions.
2 changes: 1 addition & 1 deletion erts/test/erlc_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ compile_erl(Config) when is_list(Config) ->

?line run(Config, Cmd, FileName, "-Werror",
["compile: warnings being treated as errors\$",
"Warning: function foo/0 is unused\$",
"function foo/0 is unused\$",
"_ERROR_"]),

%% Check a bad file.
Expand Down
6 changes: 5 additions & 1 deletion lib/asn1/doc/src/asn1ct.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
<v>Option = ber_bin | per_bin | uper_bin | der | compact_bit_string |
noobj | {n2n,EnumTypeName} |{outdir,Dir} | {i,IncludeDir} | optimize |
driver | asn1config | undec_rest | {inline,OutputName} | inline |
{macro_name_prefix, Prefix} | {record_name_prefix, Prefix} | verbose</v>
{macro_name_prefix, Prefix} | {record_name_prefix, Prefix} | verbose | warnings_as_errors</v>
<v>OldOption = ber | per</v>
<v>Reason = term()</v>
<v>Prefix = string()</v>
Expand Down Expand Up @@ -289,6 +289,10 @@ Binary = binary()
<p>Causes more verbose information from the compiler
describing what it is doing.</p>
</item>
<tag><c>warnings_as_errors</c></tag>
<item>
<p>Causes warnings to be treated as errors.</p>
</item>
</taglist>
<p>Any additional option that is applied will be passed to
the final step when the generated .erl file is compiled.
Expand Down
29 changes: 24 additions & 5 deletions lib/asn1/src/asn1ct.erl
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
add_tobe_refed_func/1,add_generated_refed_func/1,
maybe_rename_function/3,latest_sindex/0,current_sindex/0,
set_current_sindex/1,next_sindex/0,maybe_saved_sindex/2,
parse_and_save/2,verbose/3,warning/3,error/3]).
parse_and_save/2,verbose/3,warning/3,warning/4,error/3]).

-include("asn1_records.hrl").
-include_lib("stdlib/include/erl_compile.hrl").
Expand Down Expand Up @@ -825,10 +825,13 @@ generate({true,{M,_Module,GenTOrV}},OutFile,EncodingRule,Options) ->
case catch specialized_decode_prepare(EncodingRule,M,GenTOrV,Options) of
{error, enoent} -> ok;
{error, Reason} -> warning("Error in configuration "
"file: ~n~p~n",[Reason],Options);
"file: ~n~p~n",[Reason],Options,
"Error in configuration file");
{'EXIT',Reason} -> warning("Internal error when "
"analyzing configuration "
"file: ~n~p~n",[Reason],Options);
"file: ~n~p~n",[Reason],Options,
"Internal error when "
"analyzing configuration");
_ -> ok
end,

Expand Down Expand Up @@ -2524,14 +2527,14 @@ type_check(#'Externaltypereference'{}) ->
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Report functions.
%%
%% Errors messages are controlled with the 'errors' compiler option
%% Error messages are controlled with the 'errors' compiler option
%% Warning messages are controlled with the 'warnings' compiler option
%% Verbose messages are controlled with the 'verbose' compiler option

error(Format, Args, S) ->
case is_error(S) of
true ->
io:format("Error: " ++ Format, Args);
io:format(Format, Args);
false ->
ok
end.
Expand All @@ -2544,6 +2547,17 @@ warning(Format, Args, S) ->
ok
end.

warning(Format, Args, S, Reason) ->
case {is_werr(S), is_error(S), is_warning(S)} of
{true, true, _} ->
io:format(Format, Args),
throw({error, Reason});
{false, _, true} ->
io:format(Format, Args);
_ ->
ok
end.

verbose(Format, Args, S) ->
case is_verbose(S) of
true ->
Expand All @@ -2566,3 +2580,8 @@ is_verbose(S) when is_record(S, state) ->
is_verbose(S#state.options);
is_verbose(O) ->
lists:member(verbose, O).

is_werr(S) when is_record(S, state) ->
is_werr(S#state.options);
is_werr(O) ->
lists:member(warnings_as_errors, O).
50 changes: 32 additions & 18 deletions lib/asn1/src/asn1ct_check.erl
Original file line number Diff line number Diff line change
Expand Up @@ -2031,7 +2031,7 @@ get_objectset_def2(_S,T = #typedef{typespec=#'ObjectSet'{}},_CField) ->
T;
get_objectset_def2(S,T,_CField) ->
asn1ct:warning("get_objectset_def2: uncontrolled object set structure:~n~p~n",
[T],S).
[T],S,"get_objectset_def2: uncontrolled object set structure").

type_name(S,#type{def=Def}) ->
CurrMod = S#state.mname,
Expand Down Expand Up @@ -2705,7 +2705,7 @@ normalize_value(S,Type,{'DEFAULT',Value},NameList) ->
normalize_objectclassfieldvalue(S,Value,NL);
Err ->
asn1ct:warning("could not check default value ~p~nType:~n~p~nNameList:~n~p~n",
[Value,Type,Err],S),
[Value,Type,Err],S,"could not check default value"),
Value
end;
normalize_value(S,Type,Val,NameList) ->
Expand Down Expand Up @@ -2791,22 +2791,27 @@ normalize_bitstring(S,Value,Type)->
case catch lists:map(F,RecList) of
{error,Reason} ->
asn1ct:warning("default value not "
"compatible with type definition ~p~n",
[Reason],S),
"compatible with type definition ~p~n",
[Reason],S,
"default value not "
"compatible with type definition"),
Value;
NewList ->
NewList
end;
_ ->
asn1ct:warning("default value not "
"compatible with type definition ~p~n",
[RecList],S),
"compatible with type definition ~p~n",
[RecList],S,
"default value not "
"compatible with type definition"),
Value
end;
{Name,String} when is_atom(Name) ->
normalize_bitstring(S,String,Type);
Other ->
asn1ct:warning("illegal default value ~p~n",[Other],S),
asn1ct:warning("illegal default value ~p~n",[Other],S,
"illegal default value"),
Value
end.

Expand Down Expand Up @@ -2846,12 +2851,14 @@ normalize_octetstring(S,Value,CType) ->
lists:map(fun([])-> ok;
(H)when H > 255->
asn1ct:warning("not legal octet value ~p in OCTET STRING, ~p~n",
[H,List],S);
[H,List],S,
"not legal octet value ~p in OCTET STRING");
(_)-> ok
end, List),
List;
Other ->
asn1ct:warning("unknown default value ~p~n",[Other],S),
asn1ct:warning("unknown default value ~p~n",[Other],S,
"unknown default value"),
Value
end.

Expand Down Expand Up @@ -2908,13 +2915,15 @@ normalize_enumerated(S,{Name,EnumV},CType) when is_atom(Name) ->
normalize_enumerated(S,Value,{CType1,CType2}) when is_list(CType1), is_list(CType2)->
normalize_enumerated(S,Value,CType1++CType2);
normalize_enumerated(S,V,CType) ->
asn1ct:warning("Enumerated unknown type ~p~n",[CType],S),
asn1ct:warning("Enumerated unknown type ~p~n",[CType],S,
"Enumerated unknown type"),
V.
normalize_enumerated2(S,V,Enum) ->
case lists:keysearch(V,1,Enum) of
{value,{Val,_}} -> Val;
_ ->
asn1ct:warning("Enumerated value is not correct ~p~n",[V],S),
asn1ct:warning("enumerated value is not correct ~p~n",[V],S,
"enumerated value is not correct"),
V
end.

Expand All @@ -2925,7 +2934,8 @@ normalize_choice(S,{'CHOICE',{C,V}},CType,NameList) when is_atom(C) ->
{C,normalize_value(S,CT,{'DEFAULT',V},
[Name|NameList])};
Other ->
asn1ct:warning("Wrong format of type/value ~p/~p~n",[Other,V],S),
asn1ct:warning("Wrong format of type/value ~p/~p~n",[Other,V],S,
"Wrong format of type/value"),
{C,V}
end;
normalize_choice(S,{'DEFAULT',ValueList},CType,NameList) when is_list(ValueList) ->
Expand Down Expand Up @@ -3101,7 +3111,8 @@ normalize_s_of(SorS,S,Value,Type,NameList) when is_list(Value) ->
List when is_list(List) ->
List;
_ ->
asn1ct:warning("~p could not handle value ~p~n",[SorS,Value],S),
asn1ct:warning("~p could not handle value ~p~n",[SorS,Value],S,
"could not handle value"),
Value
end;
normalize_s_of(SorS,S,Value,Type,NameList)
Expand Down Expand Up @@ -3159,7 +3170,8 @@ get_normalized_value(S,Val,Type,Func,AddArg) ->
V2 = sort_val_if_set(AddArg,NewVal,Type),
call_Func(update_state(S,ExtM),V2,Type,Func,AddArg);
_ ->
asn1ct:warning("default value not comparable ~p~n",[Val],S),
asn1ct:warning("default value not comparable ~p~n",[Val],S,
"default value not comparable"),
Val
end.

Expand Down Expand Up @@ -5756,17 +5768,19 @@ ascending_order_check1(S,TypeName,
[C1 = #'ComponentType'{tags=[{_,T}|_]},
C2 = #'ComponentType'{tags=[{_,T}|_]}|Rest]) ->
asn1ct:warning("Indistinct tag ~p in SET ~p, components ~p and ~p~n",
[T,TypeName,C1#'ComponentType'.name,C2#'ComponentType'.name],S),
[T,TypeName,C1#'ComponentType'.name,C2#'ComponentType'.name],S,
"Indistinct tag in SET"),
ascending_order_check1(S,TypeName,[C2|Rest]);
ascending_order_check1(S,TypeName,
[C1 = #'ComponentType'{tags=[{'UNIVERSAL',T1}|_]},
C2 = #'ComponentType'{tags=[{'UNIVERSAL',T2}|_]}|Rest]) ->
case (decode_type(T1) == decode_type(T2)) of
true ->
asn1ct:warning("Indistinct tags ~p and ~p in"
" SET ~p, components ~p and ~p~n",
[T1,T2,TypeName,C1#'ComponentType'.name,
C2#'ComponentType'.name],S),
" SET ~p, components ~p and ~p~n",
[T1,T2,TypeName,C1#'ComponentType'.name,
C2#'ComponentType'.name],S,
"Indistinct tags and in SET"),
ascending_order_check1(S,TypeName,[C2|Rest]);
_ ->
ascending_order_check1(S,TypeName,[C2|Rest])
Expand Down
4 changes: 3 additions & 1 deletion lib/asn1/test/asn1_SUITE.erl.src
Original file line number Diff line number Diff line change
Expand Up @@ -2236,8 +2236,10 @@ test_compile_options(Config) ->
?line ok = test_compile_options:path(Config),
?line ok = test_compile_options:noobj(Config),
?line ok = test_compile_options:record_name_prefix(Config),
?line ok = test_compile_options:verbose(Config)
?line ok = test_compile_options:verbose(Config),
?line ok = test_compile_options:warnings_as_errors(Config)
end.

testDoubleEllipses(suite) -> [];
testDoubleEllipses(Config) ->
?line testDoubleEllipses:compile(Config,?BER,[]),
Expand Down
39 changes: 38 additions & 1 deletion lib/asn1/test/test_compile_options.erl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@


-export([wrong_path/1,comp/2,path/1,ticket_6143/1,noobj/1,
record_name_prefix/1,verbose/1]).
record_name_prefix/1,verbose/1,warnings_as_errors/1]).

%% OTP-5689
wrong_path(Config) ->
Expand Down Expand Up @@ -141,6 +141,43 @@ verbose(Config) when is_list(Config) ->
?line [] = test_server:capture_get(),
ok.

warnings_as_errors(Config) when is_list(Config) ->
PrivDir = ?config(priv_dir,Config),
Asn1File = filename:join([PrivDir,"WERROR.asn1"]),
OutFile = filename:join([PrivDir,"WERROR.erl"]),
Opts = [{outdir,PrivDir},noobj,verbose],

%% Generate WERR.asn to emit warning
%% Warning: Wrong format of type/value
%% false/{'Externalvaluereference',_,'WERR',noInvokeId}
Warn = <<"WERROR DEFINITIONS IMPLICIT TAGS ::=\n"
"\n"
"BEGIN\n"
"\n"
"InvokeId ::= CHOICE\n"
"{\n"
" present INTEGER,\n"
" absent NULL\n"
"}\n"
"\n"
"noInvokeId InvokeId ::= absent:NULL\n"
"\n"
"NoInvokeId InvokeId ::= {noInvokeId}\n"
"\n"
"END -- end of useful definitions.\n">>,
?line ok = file:write_file(Asn1File, Warn),

%% Test warnings_as_errors compile
?line false = filelib:is_regular(OutFile),
?line {error, _} = asn1ct:compile(Asn1File, [warnings_as_errors|Opts]),
?line false = filelib:is_regular(OutFile),

%% Test normal compile
?line ok = asn1ct:compile(Asn1File, Opts),
?line true = filelib:is_regular(OutFile),
?line ok = file:delete(OutFile),
ok.

outfiles_check(OutDir) ->
outfiles_check(OutDir,outfiles1()).

Expand Down
Loading

0 comments on commit e9e118a

Please sign in to comment.