ソースを参照

Merge pull request #1458 from ferd/survive-edoc-crashes

Survive EDoc crashes
pull/1459/head
Fred Hebert 8年前
committed by GitHub
コミット
9f4017f6d3
14個のファイルの変更320行の追加10行の削除
  1. +27
    -9
      src/rebar_prv_edoc.erl
  2. +21
    -1
      test/rebar_edoc_SUITE.erl
  3. +16
    -0
      test/rebar_edoc_SUITE_data/bad/apps/bar1/src/bar1.app.src
  4. +9
    -0
      test/rebar_edoc_SUITE_data/bad/apps/bar1/src/bar1.erl
  5. +26
    -0
      test/rebar_edoc_SUITE_data/bad/apps/bar1/src/bar1_app.erl
  6. +35
    -0
      test/rebar_edoc_SUITE_data/bad/apps/bar1/src/bar1_sup.erl
  7. +16
    -0
      test/rebar_edoc_SUITE_data/bad/apps/bar2/src/bar2.app.src
  8. +12
    -0
      test/rebar_edoc_SUITE_data/bad/apps/bar2/src/bar2.erl
  9. +26
    -0
      test/rebar_edoc_SUITE_data/bad/apps/bar2/src/bar2_app.erl
  10. +35
    -0
      test/rebar_edoc_SUITE_data/bad/apps/bar2/src/bar2_sup.erl
  11. +17
    -0
      test/rebar_edoc_SUITE_data/bad/apps/foo/src/foo.app.src
  12. +19
    -0
      test/rebar_edoc_SUITE_data/bad/apps/foo/src/foo.erl
  13. +26
    -0
      test/rebar_edoc_SUITE_data/bad/apps/foo/src/foo_app.erl
  14. +35
    -0
      test/rebar_edoc_SUITE_data/bad/apps/foo/src/foo_sup.erl

+ 27
- 9
src/rebar_prv_edoc.erl ファイルの表示

@ -7,6 +7,7 @@
format_error/1]).
-include("rebar.hrl").
-include_lib("providers/include/providers.hrl").
-define(PROVIDER, edoc).
-define(DEPS, [compile]).
@ -28,7 +29,8 @@ init(State) ->
{profiles, [docs]}])),
{ok, State1}.
-spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}.
-spec do(rebar_state:t()) ->
{ok, rebar_state:t()} | {error, string()} | {error, {module(), any()}}.
do(State) ->
code:add_pathsa(rebar_state:code_paths(State, all_deps)),
ProjectApps = rebar_state:project_apps(State),
@ -37,26 +39,42 @@ do(State) ->
ShouldAccPaths = not has_configured_paths(EdocOpts),
Cwd = rebar_state:dir(State),
rebar_hooks:run_all_hooks(Cwd, pre, ?PROVIDER, Providers, State),
lists:foldl(fun(AppInfo, EdocOptsAcc) ->
Res = try
lists:foldl(fun(AppInfo, EdocOptsAcc) ->
rebar_hooks:run_all_hooks(Cwd, pre, ?PROVIDER, Providers, AppInfo, State),
AppName = ec_cnv:to_list(rebar_app_info:name(AppInfo)),
?INFO("Running edoc for ~s", [AppName]),
AppDir = rebar_app_info:dir(AppInfo),
ok = edoc:application(list_to_atom(AppName), AppDir, EdocOptsAcc),
AppRes = (catch edoc:application(list_to_atom(AppName), AppDir, EdocOptsAcc)),
rebar_hooks:run_all_hooks(Cwd, post, ?PROVIDER, Providers, AppInfo, State),
case ShouldAccPaths of
true ->
case {AppRes, ShouldAccPaths} of
{ok, true} ->
%% edoc wants / on all OSes
add_to_paths(EdocOptsAcc, AppDir++"/doc");
false ->
EdocOptsAcc
{ok, false} ->
EdocOptsAcc;
{{'EXIT', error}, _} ->
%% EDoc is not very descriptive
%% in terms of failures
throw({app_failed, AppName})
end
end, EdocOpts, ProjectApps),
end, EdocOpts, ProjectApps)
catch
{app_failed, AppName} ->
{app_failed, AppName}
end,
rebar_hooks:run_all_hooks(Cwd, post, ?PROVIDER, Providers, State),
rebar_utils:cleanup_code_path(rebar_state:code_paths(State, default)),
{ok, State}.
case Res of
{app_failed, App} ->
?PRV_ERROR({app_failed, App});
_ ->
{ok, State}
end.
-spec format_error(any()) -> iolist().
format_error({app_failed, AppName}) ->
io_lib:format("Failed to generate documentation for app '~s'", [AppName]);
format_error(Reason) ->
io_lib:format("~p", [Reason]).

+ 21
- 1
test/rebar_edoc_SUITE.erl ファイルの表示

@ -3,7 +3,7 @@
-include_lib("eunit/include/eunit.hrl").
-compile(export_all).
all() -> [multiapp].
all() -> [multiapp, error_survival].
init_per_testcase(multiapp, Config) ->
application:load(rebar),
@ -14,6 +14,18 @@ init_per_testcase(multiapp, Config) ->
ec_file:copy(filename:join([DataDir, "foo"]), AppsDir, [recursive]),
Verbosity = rebar3:log_level(),
rebar_log:init(command_line, Verbosity),
State = rebar_state:new([{base_dir, filename:join([AppsDir, "_build"])}
,{root_dir, AppsDir}]),
[{apps, AppsDir}, {state, State}, {name, Name} | Config];
init_per_testcase(error_survival, Config) ->
application:load(rebar),
DataDir = ?config(data_dir, Config),
PrivDir = ?config(priv_dir, Config),
Name = rebar_test_utils:create_random_name("error_survival"),
AppsDir = filename:join([PrivDir, rebar_test_utils:create_random_name(Name)]),
ec_file:copy(filename:join([DataDir, "bad"]), AppsDir, [recursive]),
Verbosity = rebar3:log_level(),
rebar_log:init(command_line, Verbosity),
State = rebar_state:new([{base_dir, filename:join([AppsDir, "_build"])}
,{root_dir, AppsDir}]),
[{apps, AppsDir}, {state, State}, {name, Name} | Config].
@ -42,6 +54,14 @@ multiapp(Config) ->
filename:join([AppsDir, "apps", "foo", "doc", "foo.html"]),
"apps/bar1/doc/bar1.html")).
error_survival(Config) ->
RebarConfig = [],
rebar_test_utils:run_and_check(
Config, RebarConfig, ["edoc"],
{error,{rebar_prv_edoc,{app_failed,"bar2"}}}
),
ok.
file_content_matches(Path, Regex) ->
case file:read_file(Path) of

+ 16
- 0
test/rebar_edoc_SUITE_data/bad/apps/bar1/src/bar1.app.src ファイルの表示

@ -0,0 +1,16 @@
{application, bar1,
[{description, "An OTP application"},
{vsn, "0.1.0"},
{registered, []},
{mod, { bar1_app, []}},
{applications,
[kernel,
stdlib
]},
{env,[]},
{modules, []},
{maintainers, []},
{licenses, []},
{links, []}
]}.

+ 9
- 0
test/rebar_edoc_SUITE_data/bad/apps/bar1/src/bar1.erl ファイルの表示

@ -0,0 +1,9 @@
-module(bar1).
-export([bar1/0]).
-export_type([barer1/0]).
-type barer1() :: string().
% @doc Bar1 bars the bar.
-spec bar1() -> barer1().
bar1() -> "Barer1".

+ 26
- 0
test/rebar_edoc_SUITE_data/bad/apps/bar1/src/bar1_app.erl ファイルの表示

@ -0,0 +1,26 @@
%%%-------------------------------------------------------------------
%% @doc bar1 public API
%% @end
%%%-------------------------------------------------------------------
-module(bar1_app).
-behaviour(application).
%% Application callbacks
-export([start/2, stop/1]).
%%====================================================================
%% API
%%====================================================================
start(_StartType, _StartArgs) ->
bar1_sup:start_link().
%%--------------------------------------------------------------------
stop(_State) ->
ok.
%%====================================================================
%% Internal functions
%%====================================================================

+ 35
- 0
test/rebar_edoc_SUITE_data/bad/apps/bar1/src/bar1_sup.erl ファイルの表示

@ -0,0 +1,35 @@
%%%-------------------------------------------------------------------
%% @doc bar1 top level supervisor.
%% @end
%%%-------------------------------------------------------------------
-module(bar1_sup).
-behaviour(supervisor).
%% API
-export([start_link/0]).
%% Supervisor callbacks
-export([init/1]).
-define(SERVER, ?MODULE).
%%====================================================================
%% API functions
%%====================================================================
start_link() ->
supervisor:start_link({local, ?SERVER}, ?MODULE, []).
%%====================================================================
%% Supervisor callbacks
%%====================================================================
%% Child :: {Id,StartFunc,Restart,Shutdown,Type,Modules}
init([]) ->
{ok, { {one_for_all, 0, 1}, []} }.
%%====================================================================
%% Internal functions
%%====================================================================

+ 16
- 0
test/rebar_edoc_SUITE_data/bad/apps/bar2/src/bar2.app.src ファイルの表示

@ -0,0 +1,16 @@
{application, bar2,
[{description, "An OTP application"},
{vsn, "0.1.0"},
{registered, []},
{mod, { bar2_app, []}},
{applications,
[kernel,
stdlib
]},
{env,[]},
{modules, []},
{maintainers, []},
{licenses, []},
{links, []}
]}.

+ 12
- 0
test/rebar_edoc_SUITE_data/bad/apps/bar2/src/bar2.erl ファイルの表示

@ -0,0 +1,12 @@
%% @doc one docline is fine
%% @doc a second docline causes a failure
%% @doc if not, then a & causes a bad ref error.
-module(bar2).
-export([bar2/0]).
-export_type([barer2/0]).
-type barer2() :: string().
% @doc Bar2 bars the bar2.
-spec bar2() -> barer2().
bar2() -> "Barer2".

+ 26
- 0
test/rebar_edoc_SUITE_data/bad/apps/bar2/src/bar2_app.erl ファイルの表示

@ -0,0 +1,26 @@
%%%-------------------------------------------------------------------
%% @doc bar2 public API
%% @end
%%%-------------------------------------------------------------------
-module(bar2_app).
-behaviour(application).
%% Application callbacks
-export([start/2, stop/1]).
%%====================================================================
%% API
%%====================================================================
start(_StartType, _StartArgs) ->
bar2_sup:start_link().
%%--------------------------------------------------------------------
stop(_State) ->
ok.
%%====================================================================
%% Internal functions
%%====================================================================

+ 35
- 0
test/rebar_edoc_SUITE_data/bad/apps/bar2/src/bar2_sup.erl ファイルの表示

@ -0,0 +1,35 @@
%%%-------------------------------------------------------------------
%% @doc bar2 top level supervisor.
%% @end
%%%-------------------------------------------------------------------
-module(bar2_sup).
-behaviour(supervisor).
%% API
-export([start_link/0]).
%% Supervisor callbacks
-export([init/1]).
-define(SERVER, ?MODULE).
%%====================================================================
%% API functions
%%====================================================================
start_link() ->
supervisor:start_link({local, ?SERVER}, ?MODULE, []).
%%====================================================================
%% Supervisor callbacks
%%====================================================================
%% Child :: {Id,StartFunc,Restart,Shutdown,Type,Modules}
init([]) ->
{ok, { {one_for_all, 0, 1}, []} }.
%%====================================================================
%% Internal functions
%%====================================================================

+ 17
- 0
test/rebar_edoc_SUITE_data/bad/apps/foo/src/foo.app.src ファイルの表示

@ -0,0 +1,17 @@
{application, foo,
[{description, "An OTP application"},
{vsn, "0.1.0"},
{registered, []},
{mod, { foo_app, []}},
{applications,
[kernel,
stdlib,
bar1, bar2
]},
{env,[]},
{modules, []},
{maintainers, []},
{licenses, []},
{links, []}
]}.

+ 19
- 0
test/rebar_edoc_SUITE_data/bad/apps/foo/src/foo.erl ファイルの表示

@ -0,0 +1,19 @@
-module(foo).
-export([foo/0, bar1/0, bar2/0]).
-export_type([fooer/0]).
-type fooer() :: string().
% @doc Foo function returns fooer.
-spec foo() -> fooer().
foo() -> "fooer".
% @doc Bar1 function returns barer1.
-spec bar1() -> bar1:barer1().
bar1() -> bar1:bar1().
% @doc Bar2 functions returns barer2.
-spec bar2() -> bar2:barer2().
bar2() -> bar2:bar2().

+ 26
- 0
test/rebar_edoc_SUITE_data/bad/apps/foo/src/foo_app.erl ファイルの表示

@ -0,0 +1,26 @@
%%%-------------------------------------------------------------------
%% @doc foo public API
%% @end
%%%-------------------------------------------------------------------
-module(foo_app).
-behaviour(application).
%% Application callbacks
-export([start/2, stop/1]).
%%====================================================================
%% API
%%====================================================================
start(_StartType, _StartArgs) ->
foo_sup:start_link().
%%--------------------------------------------------------------------
stop(_State) ->
ok.
%%====================================================================
%% Internal functions
%%====================================================================

+ 35
- 0
test/rebar_edoc_SUITE_data/bad/apps/foo/src/foo_sup.erl ファイルの表示

@ -0,0 +1,35 @@
%%%-------------------------------------------------------------------
%% @doc foo top level supervisor.
%% @end
%%%-------------------------------------------------------------------
-module(foo_sup).
-behaviour(supervisor).
%% API
-export([start_link/0]).
%% Supervisor callbacks
-export([init/1]).
-define(SERVER, ?MODULE).
%%====================================================================
%% API functions
%%====================================================================
start_link() ->
supervisor:start_link({local, ?SERVER}, ?MODULE, []).
%%====================================================================
%% Supervisor callbacks
%%====================================================================
%% Child :: {Id,StartFunc,Restart,Shutdown,Type,Modules}
init([]) ->
{ok, { {one_for_all, 0, 1}, []} }.
%%====================================================================
%% Internal functions
%%====================================================================

読み込み中…
キャンセル
保存