diff options
Diffstat (limited to 'src/rebar_neotoma_compiler.erl')
-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 + ). |