diff options
author | simonxu72 <simon.xu72@gmail.com> | 2018-10-16 18:37:28 +0800 |
---|---|---|
committer | simonxu72 <simon.xu72@gmail.com> | 2018-10-16 18:37:28 +0800 |
commit | 41d133856bf199034b0eeb0903bedc2071fba7e1 (patch) | |
tree | 15135eaf1501e016ec1b91b275356a0cfd92d867 /src/rebar_compiler_xrl.erl | |
parent | b81871c61809a9e5c09f54d6c8298908d18a760c (diff) | |
parent | 7bfc8110d1736d2cbf61e19d2fc16dc8e854b460 (diff) |
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'src/rebar_compiler_xrl.erl')
-rw-r--r-- | src/rebar_compiler_xrl.erl | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/src/rebar_compiler_xrl.erl b/src/rebar_compiler_xrl.erl new file mode 100644 index 0000000..5c023f0 --- /dev/null +++ b/src/rebar_compiler_xrl.erl @@ -0,0 +1,50 @@ +-module(rebar_compiler_xrl). + +-behaviour(rebar_compiler). + +-export([context/1, + needed_files/3, + dependencies/3, + compile/4, + clean/2]). + +context(AppInfo) -> + Dir = rebar_app_info:dir(AppInfo), + Mappings = [{".erl", filename:join([Dir, "src"])}], + #{src_dirs => ["src"], + include_dirs => [], + src_ext => ".xrl", + out_mappings => Mappings}. + +needed_files(_, FoundFiles, AppInfo) -> + FirstFiles = [], + + %% Remove first files from found files + RestFiles = [Source || Source <- FoundFiles, not lists:member(Source, FirstFiles)], + + Opts = rebar_opts:get(rebar_app_info:opts(AppInfo), xrl_opts, []), + + {{FirstFiles, Opts}, {RestFiles, Opts}}. + +dependencies(_, _, _) -> + []. + +compile(Source, [{_, OutDir}], _, Opts) -> + BaseName = filename:basename(Source), + Target = filename:join([OutDir, BaseName]), + AllOpts = [{parserfile, Target} | Opts], + AllOpts1 = [{includefile, filename:join(OutDir, I)} || {includefile, I} <- AllOpts, + filename:pathtype(I) =:= relative], + case leex:file(Source, AllOpts1 ++ [{return, true}]) of + {ok, _} -> + ok; + {ok, _Mod, Ws} -> + rebar_compiler:ok_tuple(Source, Ws); + {error, Es, Ws} -> + rebar_compiler:error_tuple(Source, Es, Ws, AllOpts1) + end. + +clean(XrlFiles, _AppInfo) -> + rebar_file_utils:delete_each( + [rebar_utils:to_list(re:replace(F, "\\.xrl$", ".erl", [unicode])) + || F <- XrlFiles]). |