summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Sloughter <t@crashfast.com>2014-09-01 12:38:02 -0500
committerTristan Sloughter <t@crashfast.com>2014-09-01 12:38:02 -0500
commitb8785e654189f8d41636337c1b8a5c7a6bde22ef (patch)
tree7d856dcc191ebc5ab197d060f132f21366638581
parent3ff5e0c06f459a7e16a6413fee6b0eb7a4587259 (diff)
add first test
-rw-r--r--.gitignore4
-rw-r--r--src/rebar.erl15
-rw-r--r--src/rebar_app_discover.erl4
-rw-r--r--src/rebar_app_info.erl27
-rw-r--r--src/rebar_state.erl7
-rw-r--r--test/rebar_install_deps_SUITE.erl113
6 files changed, 159 insertions, 11 deletions
diff --git a/.gitignore b/.gitignore
index 86ef6aa..43286b2 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,6 @@
-/ebin/*.beam
+*.beam
+test/*_data
+logs
/rebar
*~
*.orig
diff --git a/src/rebar.erl b/src/rebar.erl
index 48a3ac6..3560772 100644
--- a/src/rebar.erl
+++ b/src/rebar.erl
@@ -30,7 +30,8 @@
run/2,
help/0,
parse_args/1,
- version/0]).
+ version/0,
+ log_level/1]).
-include("rebar.hrl").
@@ -69,7 +70,6 @@ main(Args) ->
%% Erlang-API entry point
run(BaseConfig, Commands) ->
_ = application:load(rebar),
- ok = rebar_log:init(api, BaseConfig),
run_aux(BaseConfig, Commands).
%% ====================================================================
@@ -156,12 +156,12 @@ init_config({Options, _NonOptArgs}) ->
init_config1(BaseConfig) ->
%% Determine the location of the rebar executable; important for pulling
%% resources out of the escript
- ScriptName = filename:absname(escript:script_name()),
- BaseConfig1 = rebar_state:set(BaseConfig, escript, ScriptName),
- ?DEBUG("Rebar location: ~p\n", [ScriptName]),
+ %ScriptName = filename:absname(escript:script_name()),
+ %BaseConfig1 = rebar_state:set(BaseConfig, escript, ScriptName),
+ %?DEBUG("Rebar location: ~p\n", [ScriptName]),
%% Note the top-level directory for reference
AbsCwd = filename:absname(rebar_utils:get_cwd()),
- rebar_state:set(BaseConfig1, base_dir, AbsCwd).
+ rebar_state:set(BaseConfig, base_dir, AbsCwd).
run_aux(BaseConfig, Commands) ->
%% Make sure crypto is running
@@ -176,9 +176,10 @@ run_aux(BaseConfig, Commands) ->
[Command | Args] = Commands,
CommandAtom = list_to_atom(Command),
- BaseConfig1 = init_config1(BaseConfig),
+ %BaseConfig1 = init_config1(BaseConfig),
%% Process each command, resetting any state between each one
+ BaseConfig1 = rebar_state:set(BaseConfig, base_dir, filename:absname(rebar_state:dir(BaseConfig))),
{ok, Providers} = application:get_env(rebar, providers),
BaseConfig2 = rebar_state:create_logic_providers(Providers, BaseConfig1),
rebar_core:process_command(rebar_state:command_args(BaseConfig2, Args), CommandAtom),
diff --git a/src/rebar_app_discover.erl b/src/rebar_app_discover.erl
index 12193b5..b256889 100644
--- a/src/rebar_app_discover.erl
+++ b/src/rebar_app_discover.erl
@@ -6,7 +6,9 @@
find_apps/2]).
do(State, LibDirs) ->
- Apps = find_apps(LibDirs, all),
+ BaseDir = rebar_state:dir(State),
+ Dirs = [filename:join(BaseDir, LibDir) || LibDir <- LibDirs],
+ Apps = find_apps(Dirs, all),
ProjectDeps = rebar_state:deps_names(State),
lists:foldl(fun(AppInfo, StateAcc) ->
rebar_state:project_apps(StateAcc, rebar_app_info:deps(AppInfo, ProjectDeps))
diff --git a/src/rebar_app_info.erl b/src/rebar_app_info.erl
index 698ebd7..8f0cc69 100644
--- a/src/rebar_app_info.erl
+++ b/src/rebar_app_info.erl
@@ -4,6 +4,7 @@
new/1,
new/2,
new/3,
+ new/4,
name/1,
name/2,
config/1,
@@ -22,7 +23,9 @@
dir/1,
dir/2,
source/1,
- source/2]).
+ source/2,
+ valid/1,
+ valid/2]).
-export_type([t/0]).
@@ -34,7 +37,8 @@
app_details :: list(),
deps=[] :: list(),
dir :: file:name(),
- source :: string() | undefined}).
+ source :: string() | undefined,
+ valid :: boolean()}).
%%============================================================================
%% types
@@ -69,6 +73,15 @@ new(AppName, Vsn, Dir) ->
original_vsn=Vsn,
dir=Dir}}.
+%% @doc build a complete version of the app info with all fields set.
+-spec new(atom() | binary() | string(), string(), file:name(), list()) ->
+ {ok, t()}.
+new(AppName, Vsn, Dir, Deps) ->
+ {ok, #app_info_t{name=ec_cnv:to_binary(AppName),
+ original_vsn=Vsn,
+ dir=Dir,
+ deps=Deps}}.
+
-spec name(t()) -> atom().
name(#app_info_t{name=Name}) ->
Name.
@@ -160,3 +173,13 @@ source(AppInfo=#app_info_t{}, Source) ->
-spec source(t()) -> string().
source(#app_info_t{source=Source}) ->
Source.
+
+-spec valid(t()) -> boolean().
+valid(#app_info_t{dir=Dir, valid=undefined}) ->
+ true;
+valid(#app_info_t{valid=Valid}) ->
+ Valid.
+
+-spec valid(t(), boolean()) -> t().
+valid(AppInfo=#app_info_t{}, Valid) ->
+ AppInfo#app_info_t{valid=Valid}.
diff --git a/src/rebar_state.erl b/src/rebar_state.erl
index a1aefab..fa9aa96 100644
--- a/src/rebar_state.erl
+++ b/src/rebar_state.erl
@@ -4,6 +4,7 @@
get/2, get/3, set/3,
command_args/1, command_args/2,
+ dir/1, dir/2,
set_skip_dir/2, is_skip_dir/2, reset_skip_dirs/1,
create_logic_providers/2,
@@ -106,6 +107,12 @@ command_args(#state_t{command_args=CmdArgs}) ->
command_args(State, CmdArgs) ->
State#state_t{command_args=CmdArgs}.
+dir(#state_t{dir=Dir}) ->
+ Dir.
+
+dir(State=#state_t{}, Dir) ->
+ State#state_t{dir=filename:absname(Dir)}.
+
deps_names(State) ->
Deps = rebar_state:get(State, deps, []),
lists:map(fun(Dep) when is_tuple(Dep) ->
diff --git a/test/rebar_install_deps_SUITE.erl b/test/rebar_install_deps_SUITE.erl
new file mode 100644
index 0000000..6b2b3bf
--- /dev/null
+++ b/test/rebar_install_deps_SUITE.erl
@@ -0,0 +1,113 @@
+-module(rebar_install_deps_SUITE).
+
+-export([suite/0,
+ init_per_suite/1,
+ end_per_suite/1,
+ init_per_testcase/2,
+ all/0,
+ build_basic_app/1]).
+
+-include_lib("common_test/include/ct.hrl").
+-include_lib("eunit/include/eunit.hrl").
+-include_lib("kernel/include/file.hrl").
+-include_lib("kernel/include/file.hrl").
+
+suite() ->
+ [].
+
+init_per_suite(Config) ->
+ Config.
+
+end_per_suite(_Config) ->
+ ok.
+
+init_per_testcase(_, Config) ->
+ DataDir = proplists:get_value(data_dir, Config),
+ AppsDir = filename:join([DataDir, create_random_name("apps_dir1_")]),
+ ok = ec_file:mkdir_p(AppsDir),
+ Verbosity = rebar:log_level([]),
+ rebar_log:init(command_line, Verbosity),
+ State = rebar_state:new(),
+ [{apps, AppsDir}, {state, State} | Config].
+
+all() ->
+ [built_basic_app].
+
+build_basic_app(Config) ->
+ AppDir = proplists:get_value(apps, Config),
+ State = proplists:get_value(state, Config),
+
+ Name = create_random_name("app1_"),
+ Vsn = create_random_vsn(),
+ create_app(AppDir, Name, Vsn, [kernel, stdlib]),
+
+ ConfigFile = filename:join([AppDir, "rebar.config"]),
+ write_config(ConfigFile, []),
+ rebar:run(rebar_state:new(State, [], AppDir), ["compile"]),
+
+ %% Verify app was built
+ [App] = rebar_app_discover:find_apps([AppDir]),
+
+ ?assertEqual(Name, ec_cnv:to_list(rebar_app_info:name(App))).
+
+%%%===================================================================
+%%% Helper Functions
+%%%===================================================================
+
+create_app(AppDir, Name, Vsn, Deps) ->
+ write_src_file(AppDir, Name),
+ write_app_src_file(AppDir, Name, Vsn, Deps),
+ rebar_app_info:new(Name, Vsn, AppDir, Deps).
+
+create_empty_app(AppDir, Name, Vsn, Deps) ->
+ write_app_file(AppDir, Name, Vsn, Deps),
+ rebar_app_info:new(Name, Vsn, AppDir, Deps).
+
+write_beam_file(Dir, Name) ->
+ Beam = filename:join([Dir, "ebin", "not_a_real_beam" ++ Name ++ ".beam"]),
+ ok = filelib:ensure_dir(Beam),
+ ok = ec_file:write_term(Beam, testing_purposes_only).
+
+write_src_file(Dir, Name) ->
+ Erl = filename:join([Dir, "src", "not_a_real_src" ++ Name ++ ".erl"]),
+ ok = filelib:ensure_dir(Erl),
+ ok = ec_file:write(Erl, erl_src_file("not_a_real_src" ++ Name ++ ".erl")).
+
+write_app_file(Dir, Name, Version, Deps) ->
+ Filename = filename:join([Dir, "ebin", Name ++ ".app"]),
+ ok = filelib:ensure_dir(Filename),
+ ok = ec_file:write_term(Filename, get_app_metadata(ec_cnv:to_list(Name), Version, Deps)).
+
+write_app_src_file(Dir, Name, Version, Deps) ->
+ Filename = filename:join([Dir, "src", Name ++ ".app.src"]),
+ ok = filelib:ensure_dir(Filename),
+ ok = ec_file:write_term(Filename, get_app_metadata(ec_cnv:to_list(Name), Version, Deps)).
+
+get_app_metadata(Name, Vsn, Deps) ->
+ {application, erlang:list_to_atom(Name),
+ [{description, ""},
+ {vsn, Vsn},
+ {modules, []},
+ {included_applications, []},
+ {registered, []},
+ {applications, Deps}]}.
+
+create_random_name(Name) ->
+ random:seed(erlang:now()),
+ Name ++ erlang:integer_to_list(random:uniform(1000000)).
+
+create_random_vsn() ->
+ random:seed(erlang:now()),
+ lists:flatten([erlang:integer_to_list(random:uniform(100)),
+ ".", erlang:integer_to_list(random:uniform(100)),
+ ".", erlang:integer_to_list(random:uniform(100))]).
+
+write_config(Filename, Values) ->
+ ok = filelib:ensure_dir(Filename),
+ ok = ec_file:write(Filename,
+ [io_lib:format("~p.\n", [Val]) || Val <- Values]).
+
+erl_src_file(Name) ->
+ io_lib:format("-module(~s).\n"
+ "-export([main/0]).\n"
+ "main() -> ok.\n", [filename:basename(Name, ".erl")]).