diff options
author | Anders Nygren <anygren@aggregatum.com> | 2011-08-03 08:37:21 -0500 |
---|---|---|
committer | Tuncer Ayaz <tuncer.ayaz@gmail.com> | 2011-08-05 17:07:23 +0200 |
commit | 2632cbc2cfcf6f90725035a14f610b947cf3a1bd (patch) | |
tree | f76be0e732e0ccfe753fbdd33287e6bdef7a700d | |
parent | f08f13d1037a8ea17e63b79e2980b348154861b1 (diff) |
Generate .hrl file from .mib
Generate .hrl files into include from SNMP MIB files.
Change the order of so .mib files are built before .erl
This is necessary since .hrl files are generated from
the .mib files.
The generated .bin and .hrl files are deleted by clean.
This is a cleaned up version of a patch originally
sent to the rebar mailing list by David Nonnenmacher.
-rw-r--r-- | src/rebar_erlc_compiler.erl | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/src/rebar_erlc_compiler.erl b/src/rebar_erlc_compiler.erl index 8b63321..335283d 100644 --- a/src/rebar_erlc_compiler.erl +++ b/src/rebar_erlc_compiler.erl @@ -87,15 +87,19 @@ compile(Config, _AppFile) -> Config, yrl_first_files, [])), "src", ".yrl", "src", ".erl", fun compile_yrl/3), - doterl_compile(Config, "ebin"), rebar_base_compiler:run(Config, check_files(rebar_config:get_local( Config, mib_first_files, [])), "mibs", ".mib", "priv/mibs", ".bin", - fun compile_mib/3). + fun compile_mib/3), + doterl_compile(Config, "ebin"). -spec clean(Config::rebar_config:config(), AppFile::file:filename()) -> 'ok'. clean(_Config, _AppFile) -> + MibFiles = rebar_utils:find_files("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"]), @@ -270,6 +274,10 @@ compile_mib(Source, Target, Config) -> rebar_config:get(Config, mib_opts, []), case snmpc:compile(Source, Opts) of {ok, _} -> + Mib = filename:rootname(Target), + ok = snmpc:mib_to_hrl(Mib), + Hrl_filename = Mib ++ ".hrl", + rebar_file_utils:mv(Hrl_filename,"include"), ok; {error, compilation_failed} -> ?FAIL |