From 18b39d7382ca1cd8ba5cb108142590f8ce824c33 Mon Sep 17 00:00:00 2001 From: Rob Ashton Date: Tue, 23 Jul 2019 09:26:23 +0000 Subject: De-dup inside parse_attr function itself --- src/rebar_compiler_erl.erl | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/rebar_compiler_erl.erl b/src/rebar_compiler_erl.erl index 26ccd6e..da4a1b0 100644 --- a/src/rebar_compiler_erl.erl +++ b/src/rebar_compiler_erl.erl @@ -78,7 +78,7 @@ needed_files(Graph, FoundFiles, _, AppInfo) -> dependencies(Source, SourceDir, Dirs) -> case file:open(Source, [read]) of {ok, Fd} -> - Incls = lists:usort(parse_attrs(Fd, [], SourceDir)), + Incls = parse_attrs(Fd, [], SourceDir), AbsIncls = expand_file_names(Incls, Dirs), ok = file:close(Fd), AbsIncls; @@ -245,20 +245,21 @@ module_to_erl(Mod) -> atom_to_list(Mod) ++ ".erl". parse_attrs(Fd, Includes, Dir) -> - case io:parse_erl_form(Fd, "") of - {ok, Form, _Line} -> - case erl_syntax:type(Form) of - attribute -> - NewIncludes = process_attr(Form, Includes, Dir), - parse_attrs(Fd, NewIncludes, Dir); - _ -> - parse_attrs(Fd, Includes, Dir) - end; - {eof, _} -> - Includes; - _Err -> - parse_attrs(Fd, Includes, Dir) - end. + DupIncludes = case io:parse_erl_form(Fd, "") of + {ok, Form, _Line} -> + case erl_syntax:type(Form) of + attribute -> + NewIncludes = process_attr(Form, Includes, Dir), + parse_attrs(Fd, NewIncludes, Dir); + _ -> + parse_attrs(Fd, Includes, Dir) + end; + {eof, _} -> + Includes; + _Err -> + parse_attrs(Fd, Includes, Dir) + end, + lists:usort(DupIncludes). process_attr(Form, Includes, Dir) -> AttrName = erl_syntax:atom_value(erl_syntax:attribute_name(Form)), -- cgit v1.1