From c19b8ac0031877101d162294b1009a9d3e7829ec Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Wed, 28 Apr 2010 08:44:06 -0600 Subject: [PATCH 1/3] Refactoring app file access to be via rebar_app_utils in prep for supporting .app.src --- src/rebar_app_utils.erl | 45 ++++++++++++++++++++++++++++++++----- src/rebar_deps.erl | 12 +++++----- src/rebar_dialyzer.erl | 7 +++--- src/rebar_escripter.erl | 2 +- src/rebar_port_compiler.erl | 9 +++----- 5 files changed, 52 insertions(+), 23 deletions(-) diff --git a/src/rebar_app_utils.erl b/src/rebar_app_utils.erl index dbd085e..7f48ffd 100644 --- a/src/rebar_app_utils.erl +++ b/src/rebar_app_utils.erl @@ -27,7 +27,11 @@ -module(rebar_app_utils). -export([is_app_dir/0, is_app_dir/1, - load_app_file/1]). + app_name/1, + app_applications/1, + app_vsn/1]). + +-export([load_app_file/1]). % TEMPORARY -include("rebar.hrl"). @@ -47,14 +51,45 @@ is_app_dir(Dir) -> false end. +app_name(AppFile) -> + case load_app_file(AppFile) of + {ok, AppName, _} -> + AppName; + {error, Reason} -> + ?ABORT("Failed to extract name from ~s: ~p\n", + [AppFile, Reason]) + end. + +app_applications(AppFile) -> + case load_app_file(AppFile) of + {ok, _, AppInfo} -> + proplists:get_value(applications, AppInfo); + {error, Reason} -> + ?ABORT("Failed to extract applications from ~s: ~p\n", + [AppFile, Reason]) + end. + +app_vsn(AppFile) -> + case load_app_file(AppFile) of + {ok, _, AppInfo} -> + proplists:get_value(vsn, AppInfo); + {error, Reason} -> + ?ABORT("Failed to extract vsn from ~s: ~p\n", + [AppFile, Reason]) + end. + + + +%% =================================================================== +%% Internal functions +%% =================================================================== + load_app_file(Filename) -> case file:consult(Filename) of {ok, [{application, AppName, AppData}]} -> {ok, AppName, AppData}; {error, Reason} -> - ?ERROR("Failed to load app file from ~s: ~p\n", [Filename, Reason]), - ?FAIL; + {error, Reason}; Other -> - ?ERROR("Unexpected terms from app file ~s: ~p\n", [Filename, Other]), - ?FAIL + {error, {unexpected_terms, Other}} end. diff --git a/src/rebar_deps.erl b/src/rebar_deps.erl index 0ccd7ce..ec74e27 100644 --- a/src/rebar_deps.erl +++ b/src/rebar_deps.erl @@ -195,9 +195,9 @@ is_app_available(App, VsnRegex) -> is_app_available(App, VsnRegex, Path) -> case rebar_app_utils:is_app_dir(Path) of {true, AppFile} -> - case rebar_app_utils:load_app_file(AppFile) of - {ok, App, AppData} -> - {vsn, Vsn} = lists:keyfind(vsn, 1, AppData), + case rebar_app_utils:app_name(AppFile) of + App -> + Vsn = rebar_app_utils:app_vsn(AppFile), ?INFO("Looking for ~s-~s ; found ~s-~s at ~s\n", [App, VsnRegex, App, Vsn, Path]), case re:run(Vsn, VsnRegex, [{capture, none}]) of @@ -208,11 +208,9 @@ is_app_available(App, VsnRegex, Path) -> [AppFile, Vsn, VsnRegex]), false end; - {ok, OtherApp, _} -> + OtherApp -> ?WARN("~s has application id ~p; expected ~p\n", [AppFile, OtherApp, App]), - false; - {error, Reason} -> - ?ABORT("Failed to parse ~s: ~p\n", [AppFile, Reason]) + false end; false -> ?WARN("Expected ~s to be an app dir (containing ebin/*.app), but no .app found.\n", diff --git a/src/rebar_dialyzer.erl b/src/rebar_dialyzer.erl index 35bb201..49edfb6 100644 --- a/src/rebar_dialyzer.erl +++ b/src/rebar_dialyzer.erl @@ -85,9 +85,8 @@ analyze(Config, File) -> build_plt(Config, File) -> Plt = plt_path(Config, File), - {ok, _AppName, AppData} = rebar_app_utils:load_app_file(File), - Apps = proplists:get_value(applications, AppData), - + Apps = rebar_app_utils:app_applications(File), + Warnings = dialyzer:run([{analysis_type, plt_build}, {files_rec, app_dirs(Apps)}, {output_plt, Plt}]), @@ -140,7 +139,7 @@ output_warnings(Warnings) -> %% @spec plt_path(Config::#config{}, File::string()) -> string() -spec(plt_path(Config::#config{}, File::string()) -> string()). plt_path(Config, File) -> - {ok, AppName, _AppData} = rebar_app_utils:load_app_file(File), + AppName = rebar_app_utils:app_name(File), DialyzerOpts = rebar_config:get(Config, dialyzer_opts, []), case proplists:get_value(plt, DialyzerOpts) of undefined -> diff --git a/src/rebar_escripter.erl b/src/rebar_escripter.erl index 19101b6..84747c1 100644 --- a/src/rebar_escripter.erl +++ b/src/rebar_escripter.erl @@ -37,7 +37,7 @@ escriptize(_Config, AppFile) -> %% Extract the application name from the archive -- this will be be what %% we call the output script - {ok, AppName, _AppData} = rebar_app_utils:load_app_file(AppFile), + AppName = rebar_app_utils:app_name(AppFile), %% Construct the archive of everything in ebin/ dir -- put it on the %% top-level of the zip file so that code loading works properly. diff --git a/src/rebar_port_compiler.erl b/src/rebar_port_compiler.erl index dace112..14f88a9 100644 --- a/src/rebar_port_compiler.erl +++ b/src/rebar_port_compiler.erl @@ -325,12 +325,9 @@ so_name(Config, AppFile) -> undefined -> %% Get the app name, which we'll use to %% generate the linked port driver name - case rebar_app_utils:load_app_file(AppFile) of - {ok, AppName, _} -> - lists:concat([AppName, "_drv.so"]); - error -> - ?FAIL - end; + AppName = rebar_app_utils:app_name(AppFile), + lists:concat([AppName, "_drv.so"]); + Soname -> Soname end, From f81cf34bb9d29c72cfdaba4cd0e64aafcf34d355 Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Wed, 28 Apr 2010 09:31:38 -0600 Subject: [PATCH 2/3] Add default CFLAGS for platforms where there can be variation of 32/64 bit Erlang VMs --- src/rebar_port_compiler.erl | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/rebar_port_compiler.erl b/src/rebar_port_compiler.erl index 14f88a9..b2ff24e 100644 --- a/src/rebar_port_compiler.erl +++ b/src/rebar_port_compiler.erl @@ -300,7 +300,8 @@ os_env() -> [list_to_tuple(re:split(S, "=", [{return, list}, {parts, 2}])) || S <- os:getenv()]. default_env() -> - [{"CC", "gcc"}, + [ + {"CC", "gcc"}, {"CXX", "g++"}, {"ERL_CFLAGS", lists:concat([" -I", code:lib_dir(erl_interface, include), " -I", filename:join(erts_dir(), include), @@ -311,7 +312,17 @@ default_env() -> {"DRV_LDFLAGS", "-shared $ERL_LDFLAGS"}, {"darwin", "DRV_LDFLAGS", "-bundle -flat_namespace -undefined suppress $ERL_LDFLAGS"}, {"ERLANG_ARCH", integer_to_list(8 * erlang:system_info(wordsize))}, - {"ERLANG_TARGET", rebar_utils:get_arch()}]. + {"ERLANG_TARGET", rebar_utils:get_arch()}, + + {"solaris.*-64$", "CFLAGS", "-D_REENTRANT -m64"}, % Solaris specific flags + {"solaris.*-64$", "LDFLAGS", "-m64"}, + + {"darwin9.*-64$", "CFLAGS", "-m64"}, % OS X Leopard flags for 64-bit + {"darwin9.*-64$", "LDFLAGS", "-arch x86_64"}, + + {"darwin10.*-32", "CFLAGS", "-m32"}, % OS X Snow Leopard flags for 32-bit + {"darwin10.*-32", "LDFLAGS", "-arch i386"} + ]. From c28a16258cec1fac8471793b33f4183fa8f07df1 Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Wed, 28 Apr 2010 13:02:51 -0600 Subject: [PATCH 3/3] Add caching of app file --- src/rebar_app_utils.erl | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/rebar_app_utils.erl b/src/rebar_app_utils.erl index 7f48ffd..744af4c 100644 --- a/src/rebar_app_utils.erl +++ b/src/rebar_app_utils.erl @@ -85,11 +85,17 @@ app_vsn(AppFile) -> %% =================================================================== load_app_file(Filename) -> - case file:consult(Filename) of - {ok, [{application, AppName, AppData}]} -> - {ok, AppName, AppData}; - {error, Reason} -> - {error, Reason}; - Other -> - {error, {unexpected_terms, Other}} + case erlang:get({app_file, Filename}) of + undefined -> + case file:consult(Filename) of + {ok, [{application, AppName, AppData}]} -> + erlang:put({app_file, Filename}, {AppName, AppData}), + {ok, AppName, AppData}; + {error, Reason} -> + {error, Reason}; + Other -> + {error, {unexpected_terms, Other}} + end; + {AppName, AppData} -> + {ok, AppName, AppData} end.