Skip to content

Commit 80e2f7c

Browse files
committed
Fix rebar.config.script when the src dir doesn't exist
This can happen when compiling a project that uses this library as a dependency and has no `src/` directory, arguably an edge case though. The intend of the script is to prepare sections in ex_doc according to the directories, so that metric modules are grouped into a metrics section, etc.
1 parent 36387e6 commit 80e2f7c

File tree

1 file changed

+40
-35
lines changed

1 file changed

+40
-35
lines changed

rebar.config.script

Lines changed: 40 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -21,45 +21,50 @@ ErlOpts =
2121
end,
2222

2323
SrcDir = "src/",
24-
{ok, SrcDirList} = file:list_dir(SrcDir),
25-
Dirs = lists:filter(
26-
fun(F) -> not filelib:is_regular(filename:join(SrcDir, F)) end,
27-
SrcDirList
28-
),
2924

30-
ModulesInDir = fun M(Dir) ->
31-
{ok, FileList} = file:list_dir(Dir),
32-
lists:flatmap(
33-
fun(File) ->
34-
case filename:extension(File) of
35-
".erl" ->
36-
Module = filename:basename(File, ".erl"),
37-
[list_to_atom(Module)];
38-
_ ->
39-
case filelib:is_dir(filename:join(Dir, File)) of
40-
true ->
41-
M(filename:join(Dir, File));
42-
false ->
43-
[]
25+
case file:list_dir(SrcDir) of
26+
{ok, SrcDirList} ->
27+
Dirs = lists:filter(
28+
fun(F) -> not filelib:is_regular(filename:join(SrcDir, F)) end,
29+
SrcDirList
30+
),
31+
32+
ModulesInDir = fun M(Dir) ->
33+
{ok, FileList} = file:list_dir(Dir),
34+
lists:flatmap(
35+
fun(File) ->
36+
case filename:extension(File) of
37+
".erl" ->
38+
Module = filename:basename(File, ".erl"),
39+
[list_to_atom(Module)];
40+
_ ->
41+
case filelib:is_dir(filename:join(Dir, File)) of
42+
true ->
43+
M(filename:join(Dir, File));
44+
false ->
45+
[]
46+
end
4447
end
45-
end
48+
end,
49+
FileList
50+
)
4651
end,
47-
FileList
48-
)
49-
end,
5052

51-
DirsInDir = fun(Dir) ->
52-
{ok, DirList} = file:list_dir(Dir),
53-
lists:filter(fun(F) -> not filelib:is_regular(filename:join(Dir, F)) end, DirList)
54-
end,
53+
DirsInDir = fun(Dir) ->
54+
{ok, DirList} = file:list_dir(Dir),
55+
lists:filter(fun(F) -> not filelib:is_regular(filename:join(Dir, F)) end, DirList)
56+
end,
5557

56-
GroupModules = lists:map(
57-
fun(Dir) ->
58-
{list_to_binary(Dir), lists:flatten(ModulesInDir(filename:join(SrcDir, Dir)))}
59-
end,
60-
Dirs
61-
),
58+
GroupModules = lists:map(
59+
fun(Dir) ->
60+
{list_to_binary(Dir), lists:flatten(ModulesInDir(filename:join(SrcDir, Dir)))}
61+
end,
62+
Dirs
63+
),
6264

63-
ExDoc = [{groups_for_modules, GroupModules} | ExDoc0],
65+
ExDoc = [{groups_for_modules, GroupModules} | ExDoc0],
6466

65-
[{ex_doc, ExDoc}, {erl_opts, ErlOpts} | Config1].
67+
[{ex_doc, ExDoc}, {erl_opts, ErlOpts} | Config1];
68+
{error, _} ->
69+
[{erl_opts, ErlOpts} | Config0]
70+
end.

0 commit comments

Comments
 (0)