From d9ae98e4d8d4e8773d7db96e1d977ca8eff08472 Mon Sep 17 00:00:00 2001 From: alisdair sullivan Date: Sun, 6 Dec 2015 23:14:25 -0800 Subject: symlink mib hrl output in apps `include' directories this restores compatibility with rebar2 and erlang.mk --- src/rebar_erlc_compiler.erl | 70 +++++++++++++++++++++++++-------------------- 1 file changed, 39 insertions(+), 31 deletions(-) (limited to 'src') 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(), -- cgit v1.1 From 6f70b7fc881dc02e06d51ed9204c6a128f2d49e7 Mon Sep 17 00:00:00 2001 From: alisdair sullivan Date: Tue, 8 Dec 2015 08:48:42 -0800 Subject: remove mib header file in `priv/mibs/include' --- src/rebar_erlc_compiler.erl | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'src') diff --git a/src/rebar_erlc_compiler.erl b/src/rebar_erlc_compiler.erl index 50e61f3..162ed07 100644 --- a/src/rebar_erlc_compiler.erl +++ b/src/rebar_erlc_compiler.erl @@ -521,16 +521,12 @@ target_base(OutDir, Source) -> 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} @@ -547,9 +543,7 @@ compile_mib(AppInfo) -> #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])), + rebar_file_utils:mv(HrlFilename, AppInclude), ok; {error, compilation_failed} -> ?FAIL -- cgit v1.1