From 135e629bc0fc095f37c0712323850d28fe23abe2 Mon Sep 17 00:00:00 2001 From: Tomas Abrahamsson Date: Wed, 31 Dec 2014 04:16:33 +0100 Subject: [PATCH] Use rebar_utils:find_files_by_ext/2,3 --- src/rebar_appups.erl | 4 ++-- src/rebar_erlc_compiler.erl | 15 ++++++--------- src/rebar_proto_compiler.erl | 4 ++-- src/rebar_qc.erl | 2 +- src/rebar_templater.erl | 9 ++++----- 5 files changed, 15 insertions(+), 19 deletions(-) diff --git a/src/rebar_appups.erl b/src/rebar_appups.erl index 38e7b72..88ea705 100644 --- a/src/rebar_appups.erl +++ b/src/rebar_appups.erl @@ -69,8 +69,8 @@ {_Added, _Removed, Upgraded} = get_apps(Name, OldVerPath, NewVerPath), %% Get a list of any appup files that exist in the new release - NewAppUpFiles = rebar_utils:find_files( - filename:join([NewVerPath, "lib"]), "^[^._].*.appup$"), + NewAppUpFiles = rebar_utils:find_files_by_ext( + filename:join([NewVerPath, "lib"]), ".appup"), %% Convert the list of appup files into app names AppUpApps = [file_to_name(File) || File <- NewAppUpFiles], diff --git a/src/rebar_erlc_compiler.erl b/src/rebar_erlc_compiler.erl index e4abd3d..c4cd7b1 100644 --- a/src/rebar_erlc_compiler.erl +++ b/src/rebar_erlc_compiler.erl @@ -47,8 +47,6 @@ info = {[], []} :: erlc_info() }). --define(RE_PREFIX, "^[^._]"). - -ifdef(namespaced_types). %% digraph:graph() exists starting from Erlang 17. -type rebar_digraph() :: digraph:graph(). @@ -112,14 +110,14 @@ compile(Config, _AppFile) -> -spec clean(rebar_config:config(), file:filename()) -> 'ok'. clean(Config, _AppFile) -> - MibFiles = rebar_utils:find_files("mibs", ?RE_PREFIX".*\\.mib\$"), + MibFiles = rebar_utils:find_files_by_ext("mibs", ".mib"), MIBs = [filename:rootname(filename:basename(MIB)) || MIB <- MibFiles], rebar_file_utils:delete_each( [filename:join(["include",MIB++".hrl"]) || MIB <- MIBs]), lists:foreach(fun(F) -> ok = rebar_file_utils:rm_rf(F) end, ["ebin/*.beam", "priv/mibs/*.bin"]), - YrlFiles = rebar_utils:find_files("src", ?RE_PREFIX".*\\.[x|y]rl\$"), + YrlFiles = rebar_utils:find_files_by_ext("src", ".[x|y]rl"), rebar_file_utils:delete_each( [ binary_to_list(iolist_to_binary(re:replace(F, "\\.[x|y]rl$", ".erl"))) || F <- YrlFiles ]), @@ -131,7 +129,7 @@ clean(Config, _AppFile) -> %% directory structure in ebin with .beam files within. As such, we want %% to scan whatever is left in the ebin/ directory for sub-dirs which %% satisfy our criteria. - BeamFiles = rebar_utils:find_files("ebin", ?RE_PREFIX".*\\.beam\$"), + BeamFiles = rebar_utils:find_files_by_ext("ebin", ".beam"), rebar_file_utils:delete_each(BeamFiles), lists:foreach(fun(Dir) -> delete_dir(Dir, dirs(Dir)) end, dirs("ebin")), ok. @@ -142,7 +140,7 @@ clean(Config, _AppFile) -> test_compile(Config, Cmd, OutDir) -> %% Obtain all the test modules for inclusion in the compile stage. - TestErls = rebar_utils:find_files("test", ?RE_PREFIX".*\\.erl\$"), + TestErls = rebar_utils:find_files_by_ext("test", ".erl"), ErlOpts = rebar_utils:erl_opts(Config), {Config1, ErlOpts1} = test_compile_config_and_opts(Config, ErlOpts, Cmd), @@ -153,8 +151,7 @@ test_compile(Config, Cmd, OutDir) -> SrcDirs = rebar_utils:src_dirs(proplists:append_values(src_dirs, ErlOpts1)), SrcErls = lists:foldl( fun(Dir, Acc) -> - Files = rebar_utils:find_files( - Dir, ?RE_PREFIX".*\\.erl\$"), + Files = rebar_utils:find_files_by_ext(Dir, ".erl"), lists:append(Acc, Files) end, [], SrcDirs), @@ -649,7 +646,7 @@ gather_src([], Srcs) -> Srcs; gather_src([Dir|Rest], Srcs) -> gather_src( - Rest, Srcs ++ rebar_utils:find_files(Dir, ?RE_PREFIX".*\\.erl\$")). + Rest, Srcs ++ rebar_utils:find_files_by_ext(Dir, ".erl")). -spec dirs(file:filename()) -> [file:filename()]. dirs(Dir) -> diff --git a/src/rebar_proto_compiler.erl b/src/rebar_proto_compiler.erl index 61871bd..bed9ced 100644 --- a/src/rebar_proto_compiler.erl +++ b/src/rebar_proto_compiler.erl @@ -44,7 +44,7 @@ %% =================================================================== compile(Config, AppFile) -> - case rebar_utils:find_files("src", "^[^._].*\\.proto$") of + case rebar_utils:find_files_by_ext("src", ".proto", true) of [] -> ok; Protos -> @@ -56,7 +56,7 @@ compile(Config, AppFile) -> clean(Config, AppFile) -> %% Get a list of generated .beam and .hrl files and then delete them - Protos = rebar_utils:find_files("src", "^[^._].*\\.proto$"), + Protos = rebar_utils:find_files_by_ext("src", ".proto", true), case Protos of [] -> ok; diff --git a/src/rebar_qc.erl b/src/rebar_qc.erl index 5ec6110..80b2102 100644 --- a/src/rebar_qc.erl +++ b/src/rebar_qc.erl @@ -211,7 +211,7 @@ qc_module(QC=eqc, [], M) -> QC:module(M); qc_module(QC=eqc, QCOpts, M) -> QC:module(QCOpts, M). find_prop_mods() -> - Beams = rebar_utils:find_files(?QC_DIR, "^[^._].*\\.beam\$"), + Beams = rebar_utils:find_files_by_ext(?QC_DIR, ".beam"), [M || M <- [rebar_utils:erl_to_mod(Beam) || Beam <- Beams], has_prop(M)]. has_prop(Mod) -> diff --git a/src/rebar_templater.erl b/src/rebar_templater.erl index dd89f3a..085ac1c 100644 --- a/src/rebar_templater.erl +++ b/src/rebar_templater.erl @@ -242,11 +242,10 @@ find_escript_templates(Files) -> find_disk_templates(Config) -> OtherTemplates = find_other_templates(Config), - HomeFiles = rebar_utils:find_files(filename:join([os:getenv("HOME"), - ".rebar", "templates"]), - ?TEMPLATE_RE), + HomeTemplates = filename:join([os:getenv("HOME"), ".rebar", "templates"]), + HomeFiles = rebar_utils:find_files_by_ext(HomeTemplates, ".template"), Recursive = rebar_config:is_recursive(Config), - LocalFiles = rebar_utils:find_files(".", ?TEMPLATE_RE, Recursive), + LocalFiles = rebar_utils:find_files_by_ext(".", ".template", Recursive), [{file, F} || F <- OtherTemplates ++ HomeFiles ++ LocalFiles]. find_other_templates(Config) -> @@ -254,7 +253,7 @@ find_other_templates(Config) -> undefined -> []; TemplateDir -> - rebar_utils:find_files(TemplateDir, ?TEMPLATE_RE) + rebar_utils:find_files_by_ext(TemplateDir, ".template") end. select_template([], Template) ->