Browse Source

Merge pull request #967 from talentdeficit/mib_include_fix

symlink mib hrl output in apps `include' directories
pull/974/head
Fred Hebert 9 years ago
parent
commit
21ae3145df
2 changed files with 37 additions and 35 deletions
  1. +33
    -31
      src/rebar_erlc_compiler.erl
  2. +4
    -4
      test/rebar_compile_SUITE.erl

+ 33
- 31
src/rebar_erlc_compiler.erl View File

@ -116,7 +116,7 @@ compile(AppInfo, CompileOpts) when element(1, AppInfo) == app_info_t ->
check_files([filename:join(Dir, File)
|| File <- rebar_opts:get(RebarOpts, mib_first_files, [])]),
filename:join(Dir, "mibs"), ".mib", filename:join([Dir, "priv", "mibs"]), ".bin",
fun compile_mib/3),
compile_mib(AppInfo)),
SrcDirs = lists:map(fun(SrcDir) -> filename:join(Dir, SrcDir) end,
rebar_dir:src_dirs(RebarOpts, ["src"])),
@ -516,36 +516,38 @@ internal_erl_compile(_Opts, Dir, Module, OutDir, ErlOpts) ->
target_base(OutDir, Source) ->
filename:join(OutDir, filename:basename(Source, ".erl")).
-spec compile_mib(file:filename(), file:filename(),
rebar_dict()) -> 'ok'.
compile_mib(Source, Target, Opts) ->
Dir = filename:dirname(Target),
IncludeDir = filename:join(Dir, "include"),
Mib = filename:rootname(Target),
HrlFilename = Mib ++ ".hrl",
ok = filelib:ensure_dir(Target),
ok = filelib:ensure_dir(filename:join([IncludeDir, "dummy.hrl"])),
AllOpts = [{outdir, Dir}
,{i, [Dir]}] ++
rebar_opts:get(Opts, mib_opts, []),
case snmpc:compile(Source, AllOpts) of
{ok, _} ->
MibToHrlOpts =
case proplists:get_value(verbosity, AllOpts, undefined) of
undefined ->
#options{specific = []};
Verbosity ->
#options{specific = [{verbosity, Verbosity}]}
end,
ok = snmpc:mib_to_hrl(Mib, Mib, MibToHrlOpts),
rebar_file_utils:mv(HrlFilename, IncludeDir),
ok;
{error, compilation_failed} ->
?FAIL
-spec compile_mib(rebar_app_info:t()) ->
fun((file:filename(), file:filename(), rebar_dict()) -> 'ok').
compile_mib(AppInfo) ->
fun(Source, Target, Opts) ->
Dir = filename:dirname(Target),
Mib = filename:rootname(Target),
HrlFilename = Mib ++ ".hrl",
AppInclude = filename:join([rebar_app_info:dir(AppInfo), "include"]),
ok = filelib:ensure_dir(Target),
ok = filelib:ensure_dir(filename:join([AppInclude, "dummy.hrl"])),
AllOpts = [{outdir, Dir}
,{i, [Dir]}] ++
rebar_opts:get(Opts, mib_opts, []),
case snmpc:compile(Source, AllOpts) of
{ok, _} ->
MibToHrlOpts =
case proplists:get_value(verbosity, AllOpts, undefined) of
undefined ->
#options{specific = []};
Verbosity ->
#options{specific = [{verbosity, Verbosity}]}
end,
ok = snmpc:mib_to_hrl(Mib, Mib, MibToHrlOpts),
rebar_file_utils:mv(HrlFilename, AppInclude),
ok;
{error, compilation_failed} ->
?FAIL
end
end.
-spec compile_xrl(file:filename(), file:filename(),

+ 4
- 4
test/rebar_compile_SUITE.erl View File

@ -1022,8 +1022,8 @@ mib_test(Config) ->
PrivMibsDir = filename:join([AppDir, "_build", "default", "lib", Name, "priv", "mibs"]),
true = filelib:is_file(filename:join([PrivMibsDir, "SIMPLE-MIB.bin"])),
%% check a hrl corresponding to the mib in the mibs dir exists in priv/mibs/include
true = filelib:is_file(filename:join([PrivMibsDir, "include", "SIMPLE-MIB.hrl"])),
%% check a hrl corresponding to the mib in the mibs dir exists in include
true = filelib:is_file(filename:join([AppDir, "include", "SIMPLE-MIB.hrl"])),
%% check the mibs dir was linked into the _build dir
true = filelib:is_dir(filename:join([AppDir, "_build", "default", "lib", Name, "mibs"])).
@ -1072,8 +1072,8 @@ umbrella_mib_first_test(Config) ->
PrivMibsDir = filename:join([AppsDir, "_build", "default", "lib", Name, "priv", "mibs"]),
true = filelib:is_file(filename:join([PrivMibsDir, "SIMPLE-MIB.bin"])),
%% check a hrl corresponding to the mib in the mibs dir exists in priv/mibs/include
true = filelib:is_file(filename:join([PrivMibsDir, "include", "SIMPLE-MIB.hrl"])),
%% check a hrl corresponding to the mib in the mibs dir exists in include
true = filelib:is_file(filename:join([AppDir, "include", "SIMPLE-MIB.hrl"])),
%% check the mibs dir was linked into the _build dir
true = filelib:is_dir(filename:join([AppsDir, "_build", "default", "lib", Name, "mibs"])).

Loading…
Cancel
Save