diff options
author | Fred Hebert <mononcqc@ferd.ca> | 2015-12-08 14:33:29 -0500 |
---|---|---|
committer | Fred Hebert <mononcqc@ferd.ca> | 2015-12-08 14:33:29 -0500 |
commit | 21ae3145dfd9f24af9df962fcbf00fdb55d9b923 (patch) | |
tree | f5ab39718420444564cf5aaea81e3ff9c04967ab | |
parent | 540a5c354aa1947722b1aa20f697a8a478d0fe31 (diff) | |
parent | 6f70b7fc881dc02e06d51ed9204c6a128f2d49e7 (diff) |
Merge pull request #967 from talentdeficit/mib_include_fix
symlink mib hrl output in apps `include' directories
-rw-r--r-- | src/rebar_erlc_compiler.erl | 64 | ||||
-rw-r--r-- | test/rebar_compile_SUITE.erl | 8 |
2 files changed, 37 insertions, 35 deletions
diff --git a/src/rebar_erlc_compiler.erl b/src/rebar_erlc_compiler.erl index c6eb2c1..162ed07 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,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(), diff --git a/test/rebar_compile_SUITE.erl b/test/rebar_compile_SUITE.erl index 3e7e015..ef9cf97 100644 --- a/test/rebar_compile_SUITE.erl +++ b/test/rebar_compile_SUITE.erl @@ -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"])). |