summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon Meredith <jon.hg@jonmeredith.com>2009-11-30 11:12:25 -0700
committerJon Meredith <jon.hg@jonmeredith.com>2009-11-30 11:12:25 -0700
commitc5d877a934e793947eb0140ad3b42a6988fe593d (patch)
treebb3cdc037418867473128e91b5b73f0393066926
parent961c95b419ca0aa1e1c8ff6520450fe8e3368de5 (diff)
Renamed app_installer to otp_app.
Added compile check for app name. Added compile check for app modules --HG-- rename : src/rebar_app_installer.erl => src/rebar_otp_app.erl
-rw-r--r--ebin/rebar.app15
-rw-r--r--src/rebar_otp_app.erl (renamed from src/rebar_app_installer.erl)62
2 files changed, 69 insertions, 8 deletions
diff --git a/ebin/rebar.app b/ebin/rebar.app
index e900fbf..085f847 100644
--- a/ebin/rebar.app
+++ b/ebin/rebar.app
@@ -1,11 +1,16 @@
{application, rebar,
[{description, "Rebar: Erlang Build Tool"},
{vsn, "1"},
- {modules, [ rebar_config,
- rebar_utils,
- rebar_app_utils,
+ {modules, [ rebar_app_utils,
+ rebar_config,
+ rebar_core,
+ rebar_erlc_compiler,
+ rebar_file_utils,
+ rebar_log,
+ rebar_otp_app,
+ rebar_protobuffs_compiler,
rebar_rel_utils,
- rebar_erlc_compiler]},
+ rebar_utils ]},
{registered, []},
{applications, [kernel,
stdlib,
@@ -19,7 +24,7 @@
{default_config, [
{app_modules, [ rebar_protobuffs_compiler,
rebar_erlc_compiler,
- rebar_app_installer ]}
+ rebar_otp_app ]}
]}
]}
]}.
diff --git a/src/rebar_app_installer.erl b/src/rebar_otp_app.erl
index e860d6a..b6c8ea4 100644
--- a/src/rebar_app_installer.erl
+++ b/src/rebar_otp_app.erl
@@ -22,9 +22,10 @@
%% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
%% THE SOFTWARE.
%% -------------------------------------------------------------------
--module(rebar_app_installer).
+-module(rebar_otp_app).
--export([install/2]).
+-export([compile/2,
+ install/2]).
-include("rebar.hrl").
@@ -32,6 +33,15 @@
%% Public API
%% ===================================================================
+compile(Config, File) ->
+ %% Load the app name and version from the .app file and construct
+ %% the app identifier
+ {ok, AppName, AppData} = rebar_app_utils:load_app_file(File),
+ validate_name(AppName, File),
+ validate_modules(AppName, proplists:get_value(modules, AppData)),
+ ok.
+
+
install(Config, File) ->
%% Load the app name and version from the .app file and construct
%% the app identifier
@@ -74,7 +84,7 @@ install(Config, File) ->
[] ->
ok;
List ->
- ok
+ ok
end.
@@ -88,3 +98,49 @@ install_binaries([Bin | Rest], AppDir, BinDir) ->
FqBin = filename:join([Bin, AppDir]),
rebar_file_utils:ln_sf(FqBin, BinDir),
install_binaries(Rest, AppDir, BinDir).
+
+validate_name(AppName, File) ->
+ %% Convert the .app file name to an atom -- check it against the identifier within the file
+ ExpApp = list_to_atom(filename:basename(File, ".app")),
+ case ExpApp == AppName of
+ true ->
+ ok;
+ false ->
+ ?ERROR("Invalid ~s: name of application (~p) must match filename.\n", [File, AppName]),
+ ?FAIL
+ end.
+
+validate_modules(AppName, undefined) ->
+ ?ERROR("Missing modules declaration in~p.app:\n~s", [AppName]),
+ ?FAIL;
+
+validate_modules(AppName, Mods) ->
+ %% Construct two sets -- one for the actual .beam files in ebin/ and one for the modules
+ %% listed in the .app file
+ EbinSet = ordsets:from_list([beam_to_mod(N) || N <- filelib:wildcard("ebin/*.beam")]),
+ ModSet = ordsets:from_list(Mods),
+
+ %% Identify .beam files listed in the .app, but not present in ebin/
+ case ordsets:subtract(ModSet, EbinSet) of
+ [] ->
+ ok;
+ MissingBeams ->
+ Msg1 = lists:flatten([io_lib:format("\t* ~p\n", [M]) || M <- MissingBeams]),
+ ?ERROR("One or more modules listed in ~p.app are not present in ebin/*.beam:\n~s",
+ [AppName, Msg1]),
+ ?FAIL
+ end,
+
+ %% Identify .beam files NOT list in the .app, but present in ebin/
+ case ordsets:subtract(EbinSet, ModSet) of
+ [] ->
+ ok;
+ MissingMods ->
+ Msg2 = lists:flatten([io_lib:format("\t* ~p\n", [M]) || M <- MissingMods]),
+ ?ERROR("On or more .beam files exist that are not listed in ~p.app:\n~s",
+ [AppName, Msg2]),
+ ?FAIL
+ end.
+
+beam_to_mod(Filename) ->
+ list_to_atom(filename:basename(Filename, ".beam")).