diff options
author | John R. Daily <git@epep.us> | 2015-08-03 10:40:39 -0400 |
---|---|---|
committer | Luis Rascão <luis.rascao@gmail.com> | 2016-02-13 12:19:16 +0000 |
commit | 52b31d8da539805fb6db7a8829e1b60f46865427 (patch) | |
tree | 250d063ec748f77bae9c2a9975fa51628b7d9cb2 /src | |
parent | f5bc6df43989e53e60536674bf3c0f212b8962b9 (diff) | |
download | rebar-52b31d8da539805fb6db7a8829e1b60f46865427.tar.gz |
Automatically clean neotoma-generated erl files
Add myself to THANKS
Diffstat (limited to 'src')
-rw-r--r-- | src/rebar_neotoma_compiler.erl | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/src/rebar_neotoma_compiler.erl b/src/rebar_neotoma_compiler.erl index 5549dc4..f93d492 100644 --- a/src/rebar_neotoma_compiler.erl +++ b/src/rebar_neotoma_compiler.erl @@ -40,7 +40,7 @@ %% source_ext: extension of peg source files -module(rebar_neotoma_compiler). --export([compile/2]). +-export([compile/2, clean/2]). %% for internal use only -export([info/2]). @@ -59,6 +59,20 @@ compile(Config, _AppFile) -> option(module_ext, NeoOpts) ++ ".erl", fun compile_neo/3, [{check_last_mod, true}]). +-spec clean(rebar_config:config(), file:filename()) -> 'ok'. +clean(Config, _AppFile) -> + NeoOpts = neotoma_opts(Config), + GeneratedFiles = neotoma_generated_files( + option(out_dir, NeoOpts), + option(module_ext, NeoOpts), + neotoma_source_files( + option(doc_root, NeoOpts), + option(source_ext, NeoOpts) + ) + ), + ok = rebar_file_utils:delete_each(GeneratedFiles), + ok. + %% ============================================================================ %% Internal functions %% ============================================================================ @@ -161,3 +175,20 @@ referenced_pegs1(Step, Config, Seen) -> _ -> referenced_pegs1(sets:to_list(New), Config, sets:union(New, Seen)) end. + +neotoma_source_files(SrcDir, Ext) -> + lists:map( + fun filename:basename/1, + filelib:wildcard(filename:join([SrcDir, "*" ++ Ext])) + ). + + +neotoma_generated_files(OutDir, ModExt, SourceFiles) -> + lists:map( + fun(PegFile) -> + Base = filename:rootname(PegFile), + NewName = Base ++ ModExt ++ ".erl", + filename:join(OutDir, NewName) + end, + SourceFiles + ). |