diff options
| author | Stuart Thackray <stuart.thackray@gmail.com> | 2018-12-11 08:53:29 +0200 |
|---|---|---|
| committer | Stuart Thackray <stuart.thackray@gmail.com> | 2018-12-11 08:53:29 +0200 |
| commit | ebfa797c1f5d038b99beaf658757d974412a15c7 (patch) | |
| tree | 9765880a7f0119c265d85f8bac7afea8d9542080 /src/rebar_compiler_yrl.erl | |
| parent | 71187514dabdd94aa333495d92df84a2e750099f (diff) | |
| parent | 8e28561d4e14ea85d42d17ab5a0f17f5f1c696d2 (diff) | |
Update from Upstream
Diffstat (limited to 'src/rebar_compiler_yrl.erl')
| -rw-r--r-- | src/rebar_compiler_yrl.erl | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/rebar_compiler_yrl.erl b/src/rebar_compiler_yrl.erl new file mode 100644 index 0000000..8e52d0e --- /dev/null +++ b/src/rebar_compiler_yrl.erl @@ -0,0 +1,51 @@ +-module(rebar_compiler_yrl). + +-behaviour(rebar_compiler). + +-export([context/1, + needed_files/4, + 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 => ".yrl", + out_mappings => Mappings}. + +needed_files(_, FoundFiles, Mappings, AppInfo) -> + FirstFiles = [], + + %% Remove first files from found files + RestFiles = [Source || Source <- FoundFiles, + not lists:member(Source, FirstFiles), + rebar_compiler:needs_compile(Source, ".erl", Mappings)], + + Opts = rebar_opts:get(rebar_app_info:opts(AppInfo), yrl_opts, []), + Opts1 = rebar_compiler_xrl:update_opts(Opts, AppInfo), + + {{FirstFiles, Opts1}, {RestFiles, Opts1}}. + +dependencies(_, _, _) -> + []. + +compile(Source, [{_, OutDir}], _, Opts) -> + BaseName = filename:basename(Source, ".yrl"), + Target = filename:join([OutDir, BaseName]), + AllOpts = [{parserfile, Target}, {return, true} | Opts], + case yecc:file(Source, AllOpts) of + {ok, _} -> + ok; + {ok, _Mod, Ws} -> + rebar_compiler:ok_tuple(Source, Ws); + {error, Es, Ws} -> + rebar_compiler:error_tuple(Source, Es, Ws, AllOpts) + end. + +clean(YrlFiles, _AppInfo) -> + rebar_file_utils:delete_each( + [rebar_utils:to_list(re:replace(F, "\\.yrl$", ".erl", [unicode])) + || F <- YrlFiles]). |
