From c5d877a934e793947eb0140ad3b42a6988fe593d Mon Sep 17 00:00:00 2001 From: Jon Meredith Date: Mon, 30 Nov 2009 11:12:25 -0700 Subject: 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 --- ebin/rebar.app | 15 +++-- src/rebar_app_installer.erl | 90 --------------------------- src/rebar_otp_app.erl | 146 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 156 insertions(+), 95 deletions(-) delete mode 100644 src/rebar_app_installer.erl create mode 100644 src/rebar_otp_app.erl 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_app_installer.erl deleted file mode 100644 index e860d6a..0000000 --- a/src/rebar_app_installer.erl +++ /dev/null @@ -1,90 +0,0 @@ -%% ------------------------------------------------------------------- -%% -%% rebar: Erlang Build Tools -%% -%% Copyright (c) 2009 Dave Smith (dizzyd@dizzyd.com) -%% -%% Permission is hereby granted, free of charge, to any person obtaining a copy -%% of this software and associated documentation files (the "Software"), to deal -%% in the Software without restriction, including without limitation the rights -%% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -%% copies of the Software, and to permit persons to whom the Software is -%% furnished to do so, subject to the following conditions: -%% -%% The above copyright notice and this permission notice shall be included in -%% all copies or substantial portions of the Software. -%% -%% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -%% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -%% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -%% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -%% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -%% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -%% THE SOFTWARE. -%% ------------------------------------------------------------------- --module(rebar_app_installer). - --export([install/2]). - --include("rebar.hrl"). - -%% =================================================================== -%% Public API -%% =================================================================== - -install(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), - Vsn = proplists:get_value(vsn, AppData), - AppId = ?FMT("~s-~s", [AppName, Vsn]), - ?CONSOLE("Installing: ~s\n", [AppId]), - - %% Check the erlang lib directory to see if this app identifier - %% is already present. - AppDir = filename:join([code:lib_dir(), AppId]), - case filelib:is_dir(AppDir) of - true -> - %% Already exists -- check for force=1 global flag and only - %% continue if it's set - case rebar_config:get_global(force, "0") of - "0" -> - ?ERROR("~s already exists. Installation failed.\n", [AppId]), - ?FAIL; - "1" -> - ?WARN("~s already exists, but forcibly overwriting.\n", [AppId]) - end; - false -> - ok - end, - - %% Wipe out any previous versions - ok = rebar_file_utils:rm_rf(AppDir), - - %% Re-create target - ok = rebar_file_utils:mkdir_p(AppDir), - - %% By default we copy the ebin, include, src and priv directories - ok = rebar_file_utils:cp_r(["ebin", "src", "priv", "include"], - AppDir), - - %% Check the config to see if we have any binaries that need to be - %% linked into the erlang path - case rebar_config:get_list(Config, app_bin, []) of - [] -> - ok; - List -> - ok - end. - - -%% =================================================================== -%% Internal functions -%% =================================================================== - -install_binaries([], _AppDir, _BinDir) -> - ok; -install_binaries([Bin | Rest], AppDir, BinDir) -> - FqBin = filename:join([Bin, AppDir]), - rebar_file_utils:ln_sf(FqBin, BinDir), - install_binaries(Rest, AppDir, BinDir). diff --git a/src/rebar_otp_app.erl b/src/rebar_otp_app.erl new file mode 100644 index 0000000..b6c8ea4 --- /dev/null +++ b/src/rebar_otp_app.erl @@ -0,0 +1,146 @@ +%% ------------------------------------------------------------------- +%% +%% rebar: Erlang Build Tools +%% +%% Copyright (c) 2009 Dave Smith (dizzyd@dizzyd.com) +%% +%% Permission is hereby granted, free of charge, to any person obtaining a copy +%% of this software and associated documentation files (the "Software"), to deal +%% in the Software without restriction, including without limitation the rights +%% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +%% copies of the Software, and to permit persons to whom the Software is +%% furnished to do so, subject to the following conditions: +%% +%% The above copyright notice and this permission notice shall be included in +%% all copies or substantial portions of the Software. +%% +%% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +%% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +%% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +%% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +%% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +%% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +%% THE SOFTWARE. +%% ------------------------------------------------------------------- +-module(rebar_otp_app). + +-export([compile/2, + install/2]). + +-include("rebar.hrl"). + +%% =================================================================== +%% 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 + {ok, AppName, AppData} = rebar_app_utils:load_app_file(File), + Vsn = proplists:get_value(vsn, AppData), + AppId = ?FMT("~s-~s", [AppName, Vsn]), + ?CONSOLE("Installing: ~s\n", [AppId]), + + %% Check the erlang lib directory to see if this app identifier + %% is already present. + AppDir = filename:join([code:lib_dir(), AppId]), + case filelib:is_dir(AppDir) of + true -> + %% Already exists -- check for force=1 global flag and only + %% continue if it's set + case rebar_config:get_global(force, "0") of + "0" -> + ?ERROR("~s already exists. Installation failed.\n", [AppId]), + ?FAIL; + "1" -> + ?WARN("~s already exists, but forcibly overwriting.\n", [AppId]) + end; + false -> + ok + end, + + %% Wipe out any previous versions + ok = rebar_file_utils:rm_rf(AppDir), + + %% Re-create target + ok = rebar_file_utils:mkdir_p(AppDir), + + %% By default we copy the ebin, include, src and priv directories + ok = rebar_file_utils:cp_r(["ebin", "src", "priv", "include"], + AppDir), + + %% Check the config to see if we have any binaries that need to be + %% linked into the erlang path + case rebar_config:get_list(Config, app_bin, []) of + [] -> + ok; + List -> + ok + end. + + +%% =================================================================== +%% Internal functions +%% =================================================================== + +install_binaries([], _AppDir, _BinDir) -> + ok; +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")). -- cgit v1.1 From 8e91e1014e665e74138228cf6c8361c196c26268 Mon Sep 17 00:00:00 2001 From: Jon Meredith Date: Mon, 30 Nov 2009 12:02:09 -0700 Subject: Connected up symlinking the list of progs in rebar.config/app_bin to the OTP bin dir. --- rebar.config | 1 + src/rebar_file_utils.erl | 3 ++- src/rebar_otp_app.erl | 7 +++++-- 3 files changed, 8 insertions(+), 3 deletions(-) create mode 100644 rebar.config diff --git a/rebar.config b/rebar.config new file mode 100644 index 0000000..a43eacb --- /dev/null +++ b/rebar.config @@ -0,0 +1 @@ +{app_bin, ["priv/rebar"]}. diff --git a/src/rebar_file_utils.erl b/src/rebar_file_utils.erl index af47ea8..60b6a59 100644 --- a/src/rebar_file_utils.erl +++ b/src/rebar_file_utils.erl @@ -26,7 +26,8 @@ -export([rm_rf/1, mkdir_p/1, - cp_r/2]). + cp_r/2, + ln_sf/2]). -include("rebar.hrl"). diff --git a/src/rebar_otp_app.erl b/src/rebar_otp_app.erl index b6c8ea4..8b72baa 100644 --- a/src/rebar_otp_app.erl +++ b/src/rebar_otp_app.erl @@ -84,7 +84,10 @@ install(Config, File) -> [] -> ok; List -> - ok + %% code:root_dir() gives $OTPROOT/lib/erlang on a stock install + %% so find the bin dir relative to that. + BinDir = filename:join([code:root_dir(), "..", "..", "bin"]), + install_binaries(List, AppDir, BinDir) end. @@ -95,7 +98,7 @@ install(Config, File) -> install_binaries([], _AppDir, _BinDir) -> ok; install_binaries([Bin | Rest], AppDir, BinDir) -> - FqBin = filename:join([Bin, AppDir]), + FqBin = filename:join([AppDir, Bin]), rebar_file_utils:ln_sf(FqBin, BinDir), install_binaries(Rest, AppDir, BinDir). -- cgit v1.1