From fb499f15b8b372c8eeb5cf0c4b4af0e109a51ceb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= Date: Tue, 15 Dec 2009 14:42:26 +0100 Subject: compile.erl: remove trailing whitespace --- lib/compiler/src/compile.erl | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/compiler/src/compile.erl b/lib/compiler/src/compile.erl index e725083a9f..a10c75c9da 100644 --- a/lib/compiler/src/compile.erl +++ b/lib/compiler/src/compile.erl @@ -302,7 +302,7 @@ os_process_size() -> list_to_integer(lib:nonl(Size)); _ -> 0 - end. + end. run_tc({Name,Fun}, St) -> Before0 = statistics(runtime), @@ -344,18 +344,18 @@ comp_ret_err(#compile{warnings=Warn0,errors=Err0,options=Opts}=St) -> messages_per_file(Ms) -> T = lists:sort([{File,M} || {File,Messages} <- Ms, M <- Messages]), PrioMs = [erl_scan, epp, erl_parse], - {Prio0, Rest} = + {Prio0, Rest} = lists:mapfoldl(fun(M, A) -> lists:partition(fun({_,{_,Mod,_}}) -> Mod =:= M; (_) -> false end, A) end, T, PrioMs), - Prio = lists:sort(fun({_,{L1,_,_}}, {_,{L2,_,_}}) -> L1 =< L2 end, + Prio = lists:sort(fun({_,{L1,_,_}}, {_,{L2,_,_}}) -> L1 =< L2 end, lists:append(Prio0)), flatmap(fun mpf/1, [Prio, Rest]). mpf(Ms) -> - [{File,[M || {F,M} <- Ms, F =:= File]} || + [{File,[M || {F,M} <- Ms, F =:= File]} || File <- lists:usort([F || {F,_} <- Ms])]. %% passes(form|file, [Option]) -> [{Name,PassFun}] @@ -495,14 +495,14 @@ select_passes([List|Ps], Opts) when is_list(List) -> select_cond(Flag, ShouldBe, Pass, Ps, Opts) -> ShouldNotBe = not ShouldBe, - case member(Flag, Opts) of + case member(Flag, Opts) of ShouldBe -> select_passes([Pass|Ps], Opts); ShouldNotBe -> select_passes(Ps, Opts) end. %% select_list_passes([Pass], Opts) -> {done,[Pass]} | {not_done,[Pass]} %% Evaluate all conditions having to do with listings in the list of -%% passes. +%% passes. select_list_passes(Ps, Opts) -> select_list_passes_1(Ps, Opts, []). @@ -782,7 +782,7 @@ clean_parse_transforms_1([F|Fs], Acc) -> clean_parse_transforms_1(Fs, [F|Acc]); clean_parse_transforms_1([], Acc) -> reverse(Acc). -transforms(Os) -> [ M || {parse_transform,M} <- Os ]. +transforms(Os) -> [ M || {parse_transform,M} <- Os ]. transform_module(#compile{options=Opt,code=Code0}=St0) -> %% Extract compile options from code into options field. @@ -815,7 +815,7 @@ foldl_transform(St, [T|Ts]) -> end; foldl_transform(St, []) -> {ok,St}. -get_core_transforms(Opts) -> [M || {core_transform,M} <- Opts]. +get_core_transforms(Opts) -> [M || {core_transform,M} <- Opts]. core_transforms(St) -> %% The options field holds the complete list of options at this @@ -1264,7 +1264,7 @@ listing(Ext, St) -> listing(LFun, Ext, St) -> Lfile = outfile(St#compile.base, Ext, St#compile.options), case file:open(Lfile, [write,delayed_write]) of - {ok,Lf} -> + {ok,Lf} -> Code = restore_expanded_types(Ext, St#compile.code), LFun(Lf, Code), ok = file:close(Lf), -- cgit v1.2.3 From 5fdb43ee9adb9081998a2428ba2e5b001c067393 Mon Sep 17 00:00:00 2001 From: Christopher Faulet Date: Thu, 10 Dec 2009 22:21:18 +0100 Subject: compile: add flag warnings_as_errors to treat warnings as errors With this flag, warnings are treated as errors, like gcc flag '-Werror'. --- lib/compiler/doc/src/compile.xml | 6 ++++++ lib/compiler/src/compile.erl | 35 ++++++++++++++++++++++++----------- lib/compiler/test/error_SUITE.erl | 20 ++++++++++++++++++-- 3 files changed, 48 insertions(+), 13 deletions(-) diff --git a/lib/compiler/doc/src/compile.xml b/lib/compiler/doc/src/compile.xml index c39c9b25eb..d6e81165d8 100644 --- a/lib/compiler/doc/src/compile.xml +++ b/lib/compiler/doc/src/compile.xml @@ -212,6 +212,12 @@ success.

+ warnings_as_errors + +

Causes warnings to be treated as errors. This option is supported + since R13B04.

+
+ return

This is a short form for both return_errors and diff --git a/lib/compiler/src/compile.erl b/lib/compiler/src/compile.erl index a10c75c9da..8dd7cea38c 100644 --- a/lib/compiler/src/compile.erl +++ b/lib/compiler/src/compile.erl @@ -318,17 +318,30 @@ run_tc({Name,Fun}, St) -> Val. comp_ret_ok(#compile{code=Code,warnings=Warn0,module=Mod,options=Opts}=St) -> - Warn = messages_per_file(Warn0), - report_warnings(St#compile{warnings = Warn}), - Ret1 = case member(binary, Opts) andalso not member(no_code_generation, Opts) of - true -> [Code]; - false -> [] - end, - Ret2 = case member(return_warnings, Opts) of - true -> Ret1 ++ [Warn]; - false -> Ret1 - end, - list_to_tuple([ok,Mod|Ret2]). + case member(warnings_as_errors, Opts) andalso length(Warn0) > 0 of + true -> + case member(report_warnings, Opts) of + true -> + io:format("~p: warnings being treated as errors\n", + [?MODULE]); + false -> + ok + end, + comp_ret_err(St); + false -> + Warn = messages_per_file(Warn0), + report_warnings(St#compile{warnings = Warn}), + Ret1 = case member(binary, Opts) andalso + not member(no_code_generation, Opts) of + true -> [Code]; + false -> [] + end, + Ret2 = case member(return_warnings, Opts) of + true -> Ret1 ++ [Warn]; + false -> Ret1 + end, + list_to_tuple([ok,Mod|Ret2]) + end. comp_ret_err(#compile{warnings=Warn0,errors=Err0,options=Opts}=St) -> Warn = messages_per_file(Warn0), diff --git a/lib/compiler/test/error_SUITE.erl b/lib/compiler/test/error_SUITE.erl index 477730c3ac..757e1c5725 100644 --- a/lib/compiler/test/error_SUITE.erl +++ b/lib/compiler/test/error_SUITE.erl @@ -21,11 +21,11 @@ -include("test_server.hrl"). -export([all/1, - head_mismatch_line/1,r11b_binaries/1]). + head_mismatch_line/1,r11b_binaries/1,warnings_as_errors/1]). all(suite) -> test_lib:recompile(?MODULE), - [head_mismatch_line,r11b_binaries]. + [head_mismatch_line,r11b_binaries,warnings_as_errors]. %% Tests that a head mismatch is reported on the correct line (OTP-2125). head_mismatch_line(Config) when is_list(Config) -> @@ -73,6 +73,20 @@ r11b_binaries(Config) when is_list(Config) -> ?line [] = run(Config, Ts), ok. +warnings_as_errors(Config) when is_list(Config) -> + Ts = [{warnings_as_errors, + <<" + t() -> + A = unused, + ok. + ">>, + [warnings_as_errors], + {error, + [], + [{3,erl_lint,{unused_var,'A'}}]} }], + ?line [] = run(Config, Ts), + ok. + run(Config, Tests) -> F = fun({N,P,Ws,E}, BadL) -> @@ -104,6 +118,8 @@ run_test(Conf, Test0, Warnings) -> %% Test result of compilation. ?line Res = case compile:file(File, Opts) of {error,[{_File,Es}],Ws} -> + {error,Es,Ws}; + {error,Es,[{_File,Ws}]} -> {error,Es,Ws} end, file:delete(File), -- cgit v1.2.3 From 96773ebcef2fe5949695a4fd923343ec4b049087 Mon Sep 17 00:00:00 2001 From: Christopher Faulet Date: Tue, 15 Dec 2009 16:56:13 +0100 Subject: Add option -Werror in erlc(1) Like in gcc, this option treats warnings as errors. --- erts/doc/src/erlc.xml | 4 ++++ erts/etc/common/erlc.c | 3 +++ erts/test/erlc_SUITE.erl | 7 +++++++ 3 files changed, 14 insertions(+) diff --git a/erts/doc/src/erlc.xml b/erts/doc/src/erlc.xml index 3859ac8365..395daa87e7 100644 --- a/erts/doc/src/erlc.xml +++ b/erts/doc/src/erlc.xml @@ -104,6 +104,10 @@ must be quoted. Terms which contain spaces must be quoted on all platforms.

+ -Werror + +

Makes all warnings into errors.

+
-Wnumber

Sets warning level to number. Default is . diff --git a/erts/etc/common/erlc.c b/erts/etc/common/erlc.c index c958fed741..216ff7f40e 100644 --- a/erts/etc/common/erlc.c +++ b/erts/etc/common/erlc.c @@ -310,6 +310,8 @@ main(int argc, char** argv) case 'W': /* Enable warnings. */ if (strcmp(argv[1]+2, "all") == 0) { PUSH2("@warn", "999"); + } else if (strcmp(argv[1]+2, "error") == 0) { + PUSH2("@option", "warnings_as_errors"); } else if (isdigit((int)argv[1][2])) { PUSH2("@warn", argv[1]+2); } else { @@ -566,6 +568,7 @@ usage(void) {"-pz path", "add path to the end of Erlang's code path"}, {"-smp", "compile using SMP emulator"}, {"-v", "verbose compiler output"}, + {"-Werror", "make all warnings into errors"}, {"-W0", "disable warnings"}, {"-Wnumber", "set warning level to number"}, {"-Wall", "enable all warnings"}, diff --git a/erts/test/erlc_SUITE.erl b/erts/test/erlc_SUITE.erl index 1d944811aa..c91471e412 100644 --- a/erts/test/erlc_SUITE.erl +++ b/erts/test/erlc_SUITE.erl @@ -56,6 +56,13 @@ compile_erl(Config) when is_list(Config) -> ?line run(Config, Cmd, FileName, "-W0", ["_OK_"]), + %% Try treating warnings as errors. + + ?line run(Config, Cmd, FileName, "-Werror", + ["compile: warnings being treated as errors\$", + "Warning: function foo/0 is unused\$", + "_ERROR_"]), + %% Check a bad file. ?line BadFile = filename:join(SrcDir, "erl_test_bad.erl"), -- cgit v1.2.3