diff options
-rw-r--r-- | src/rebar_erlc_compiler.erl | 7 | ||||
-rw-r--r-- | src/rebar_prv_compile.erl | 13 | ||||
-rw-r--r-- | test/rebar_compile_SUITE.erl | 52 |
3 files changed, 67 insertions, 5 deletions
diff --git a/src/rebar_erlc_compiler.erl b/src/rebar_erlc_compiler.erl index b9072a3..87cf352 100644 --- a/src/rebar_erlc_compiler.erl +++ b/src/rebar_erlc_compiler.erl @@ -404,10 +404,13 @@ target_base(OutDir, Source) -> -spec compile_mib(file:filename(), file:filename(), rebar_state:t()) -> 'ok'. compile_mib(Source, Target, Config) -> + Dir = rebar_state:dir(Config), ok = filelib:ensure_dir(Target), - ok = filelib:ensure_dir(filename:join("include", "dummy.hrl")), - Opts = [{outdir, "priv/mibs"}, {i, ["priv/mibs"]}] ++ + ok = filelib:ensure_dir(filename:join([Dir, "include", "dummy.hrl"])), + Opts = [{outdir, filename:join([Dir, "priv", "mibs"])} + ,{i, [filename:join([Dir, "priv", "mibs"])]}] ++ rebar_state:get(Config, mib_opts, []), + case snmpc:compile(Source, Opts) of {ok, _} -> Mib = filename:rootname(Target), diff --git a/src/rebar_prv_compile.erl b/src/rebar_prv_compile.erl index 6eb8a4f..25d5193 100644 --- a/src/rebar_prv_compile.erl +++ b/src/rebar_prv_compile.erl @@ -126,7 +126,20 @@ copy_app_dirs(State, OldAppDir, AppDir) -> false -> ok end, + filelib:ensure_dir(filename:join(AppDir, "dummy")), + + %% link or copy mibs if it exists + case filelib:is_dir(filename:join(OldAppDir, "mibs")) of + true -> + %% If mibs exist it means we must ensure priv exists. + %% mibs files are compiled to priv/mibs/ + filelib:ensure_dir(filename:join([OldAppDir, "priv", "dummy"])), + symlink_or_copy(OldAppDir, AppDir, "mibs"); + false -> + ok + end, + %% link to src_dirs to be adjacent to ebin is needed for R15 use of cover/xref SrcDirs = rebar_dir:all_src_dirs(State, ["src"], ["test"]), [symlink_or_copy(OldAppDir, AppDir, Dir) || Dir <- ["priv", "include"] ++ SrcDirs]; diff --git a/test/rebar_compile_SUITE.erl b/test/rebar_compile_SUITE.erl index 8dca46c..3f95e4f 100644 --- a/test/rebar_compile_SUITE.erl +++ b/test/rebar_compile_SUITE.erl @@ -20,7 +20,8 @@ checkout_priority/1, highest_version_of_pkg_dep/1, parse_transform_test/1, - erl_first_files_test/1]). + erl_first_files_test/1, + mib_test/1]). -include_lib("common_test/include/ct.hrl"). -include_lib("eunit/include/eunit.hrl"). @@ -48,7 +49,7 @@ all() -> recompile_when_opts_change, dont_recompile_when_opts_dont_change, dont_recompile_yrl_or_xrl, delete_beam_if_source_deleted, deps_in_path, checkout_priority, highest_version_of_pkg_dep, - parse_transform_test, erl_first_files_test]. + parse_transform_test, erl_first_files_test, mib_test]. build_basic_app(Config) -> AppDir = ?config(apps, Config), @@ -308,7 +309,7 @@ deps_in_path(Config) -> ?assertEqual([], [Path || Path <- code:get_path(), {match, _} <- [re:run(Path, DepName)]]), %% Hope not to find pkg name in there - + ?assertEqual([], [Path || Path <- code:get_path(), {match, _} <- [re:run(Path, PkgName)]]), %% Build things @@ -485,3 +486,48 @@ erl_first_files_test(Config) -> D = proplists:get_value(number, d:module_info(attributes)), E = proplists:get_value(number, e:module_info(attributes)), ?assertEqual([B,D,A,E], lists:sort([A,B,D,E])). + +mib_test(Config) -> + AppDir = ?config(apps, Config), + + RebarConfig = [], + + Name = rebar_test_utils:create_random_name("app1_"), + Vsn = rebar_test_utils:create_random_vsn(), + rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]), + + MibsSrc = <<"-- SIMPLE-MIB.\n" +"-- This is just a simple MIB used for testing!\n" +"--\n" +"SIMPLE-MIB DEFINITIONS ::= BEGIN\n" +"IMPORTS\n" +" MODULE-IDENTITY, enterprises\n" +" FROM SNMPv2-SMI;\n" +"\n" +"ericsson MODULE-IDENTITY\n" +" LAST-UPDATED\n" +" \"201403060000Z\"\n" +" ORGANIZATION\n" +" \"rebar\"\n" +" CONTACT-INFO\n" +" \"rebar <rebar@example.com>\n" +" or\n" +" whoever is currently responsible for the SIMPLE\n" +" enterprise MIB tree branch (enterprises.999).\"\n" +" DESCRIPTION\n" +" \"This very small module is made available\n" +" for mib-compilation testing.\"\n" +" ::= { enterprises 999 }\n" +"END\n">>, + + ok = filelib:ensure_dir(filename:join([AppDir, "mibs", "dummy"])), + ok = file:write_file(filename:join([AppDir, "mibs", "SIMPLE-MIB.mib"]), MibsSrc), + + rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], {ok, [{app, Name}]}), + + %% check a beam corresponding to the src in the extra src_dir exists in ebin + PrivMibsDir = filename:join([AppDir, "_build", "default", "lib", Name, "priv", "mibs"]), + true = filelib:is_file(filename:join([PrivMibsDir, "SIMPLE-MIB.bin"])), + + %% check the extra src_dir was linked into the _build dir + true = filelib:is_dir(filename:join([AppDir, "_build", "default", "lib", Name, "mibs"])). |