diff options
-rw-r--r-- | src/rebar_erlc_compiler.erl | 70 | ||||
-rw-r--r-- | test/rebar_compile_SUITE.erl | 6 |
2 files changed, 45 insertions, 31 deletions
diff --git a/src/rebar_erlc_compiler.erl b/src/rebar_erlc_compiler.erl index c6eb2c1..50e61f3 100644 --- a/src/rebar_erlc_compiler.erl +++ b/src/rebar_erlc_compiler.erl @@ -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,44 @@ 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), + IncludeDir = filename:join(Dir, "include"), + + Mib = filename:rootname(Target), + HrlFilename = Mib ++ ".hrl", + Hrl = filename:basename(HrlFilename), + + AppInclude = filename:join([rebar_app_info:dir(AppInfo), "include"]), + + ok = filelib:ensure_dir(Target), + ok = filelib:ensure_dir(filename:join([IncludeDir, "dummy.hrl"])), + 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, IncludeDir), + rebar_file_utils:symlink_or_copy(filename:join([IncludeDir, Hrl]), + filename:join([AppInclude, Hrl])), + ok; + {error, compilation_failed} -> + ?FAIL + end end. -spec compile_xrl(file:filename(), file:filename(), diff --git a/test/rebar_compile_SUITE.erl b/test/rebar_compile_SUITE.erl index 3e7e015..1170a44 100644 --- a/test/rebar_compile_SUITE.erl +++ b/test/rebar_compile_SUITE.erl @@ -1025,6 +1025,9 @@ mib_test(Config) -> %% 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"])). @@ -1075,6 +1078,9 @@ umbrella_mib_first_test(Config) -> %% 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"])). |