aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric <[email protected]>2012-12-10 15:04:12 -0500
committerEric <[email protected]>2012-12-10 15:07:25 -0500
commitc3e728afb67101480d0c7b52c51bc522f08fb08f (patch)
treef1fe9d5c6ddcf6626c84b9121ce1d334d776556e
parent902d2f4718f4eec674252cb5643c0dd137d741e0 (diff)
downloadrelx-c3e728afb67101480d0c7b52c51bc522f08fb08f.tar.gz
relx-c3e728afb67101480d0c7b52c51bc522f08fb08f.tar.bz2
relx-c3e728afb67101480d0c7b52c51bc522f08fb08f.zip
if no config is specified search for a `relcool.config` in the path
-rw-r--r--src/rcl_prv_config.erl50
-rw-r--r--src/rcl_state.erl5
-rw-r--r--test/rclt_command_SUITE.erl15
-rw-r--r--test/rclt_release_SUITE.erl45
4 files changed, 97 insertions, 18 deletions
diff --git a/src/rcl_prv_config.erl b/src/rcl_prv_config.erl
index ee1c770..7ea9a77 100644
--- a/src/rcl_prv_config.erl
+++ b/src/rcl_prv_config.erl
@@ -29,8 +29,12 @@ init(State) ->
%% populating the state as a result.
-spec do(rcl_state:t()) ->{ok, rcl_state:t()} | relcool:error().
do(State) ->
- ConfigFiles = rcl_state:config_files(State),
- lists:foldl(fun load_config/2, {ok, State}, ConfigFiles).
+ case rcl_state:config_files(State) of
+ [] ->
+ search_for_dominating_config(State);
+ ConfigFiles ->
+ lists:foldl(fun load_config/2, {ok, State}, ConfigFiles)
+ end.
-spec format_error(Reason::term()) -> iolist().
format_error({consult, ConfigFile, Reason}) ->
@@ -42,6 +46,48 @@ format_error({invalid_term, Term}) ->
%%%===================================================================
%%% Internal Functions
%%%===================================================================
+search_for_dominating_config({ok, Cwd}) ->
+ ConfigFile = filename:join(Cwd, "relcool.config"),
+ case ec_file:exists(ConfigFile) of
+ true ->
+ {ok, ConfigFile};
+ false ->
+ search_for_dominating_config(parent_dir(Cwd))
+ end;
+search_for_dominating_config({error, _}) ->
+ no_config;
+search_for_dominating_config(State0) ->
+ {ok, Cwd} = file:get_cwd(),
+ case search_for_dominating_config({ok, Cwd}) of
+ {ok, Config} ->
+ %% we need to set the root dir on state as well
+ {ok, RootDir} = parent_dir(Config),
+ State1 = rcl_state:root_dir(State0, RootDir),
+ load_config(Config, {ok, rcl_state:config_files(State1, [Config])});
+ no_config ->
+ {ok, State0}
+ end.
+
+%% @doc Given a directory returns the name of the parent directory.
+-spec parent_dir(Filename::string()) ->
+ {ok, DirName::string()} | {error, no_parent_dir}.
+parent_dir(Filename) ->
+ parent_dir(filename:split(Filename), []).
+
+%% @doc Given list of directories, splits the list and returns all dirs but the
+%% last as a path.
+-spec parent_dir([string()], [string()]) ->
+ {ok, DirName::string()} | {error, no_parent_dir}.
+parent_dir([_H], []) ->
+ {error, no_parent_dir};
+parent_dir([], []) ->
+ {error, no_parent_dir};
+parent_dir([_H], Acc) ->
+ {ok, filename:join(lists:reverse(Acc))};
+parent_dir([H | T], Acc) ->
+ parent_dir(T, [H | Acc]).
+
+
-spec load_config(file:filename(), {ok, rcl_state:t()} | relcool:error()) ->
{ok, rcl_state:t()} | relcool:error().
load_config(_, Err = {error, _}) ->
diff --git a/src/rcl_state.erl b/src/rcl_state.erl
index d324bf9..bd26a47 100644
--- a/src/rcl_state.erl
+++ b/src/rcl_state.erl
@@ -31,6 +31,7 @@
overrides/2,
goals/1,
config_files/1,
+ config_files/2,
providers/1,
providers/2,
sys_config/1,
@@ -140,6 +141,10 @@ goals(#state_t{goals=TS}) ->
config_files(#state_t{config_files=ConfigFiles}) ->
ConfigFiles.
+-spec config_files(t(), [file:filename()]) -> t().
+config_files(State, ConfigFiles) ->
+ State#state_t{config_files=ConfigFiles}.
+
-spec providers(t()) -> [rcl_provider:t()].
providers(#state_t{providers=Providers}) ->
Providers.
diff --git a/test/rclt_command_SUITE.erl b/test/rclt_command_SUITE.erl
index 46449e9..1c6accf 100644
--- a/test/rclt_command_SUITE.erl
+++ b/test/rclt_command_SUITE.erl
@@ -25,7 +25,6 @@
all/0,
normal_passing_case/1,
lib_fail_case/1,
- output_fail_case/1,
spec_parse_fail_case/1,
config_fail_case/1]).
@@ -42,7 +41,7 @@ end_per_suite(_Config) ->
ok.
all() ->
- [normal_passing_case, lib_fail_case, output_fail_case, config_fail_case].
+ [normal_passing_case, lib_fail_case, config_fail_case].
normal_passing_case(Config) ->
DataDir = proplists:get_value(data_dir, Config),
@@ -82,18 +81,6 @@ lib_fail_case(Config) ->
?assertMatch({error, {_, {not_directory, Lib2}}},
rcl_cmd_args:args2state(getopt:parse(relcool:opt_spec_list(), CmdLine))).
-
-output_fail_case(Config) ->
- DataDir = proplists:get_value(data_dir, Config),
- UnwritableDir = filename:join([DataDir, "unwritable"]),
- ok = rcl_util:mkdir_p(UnwritableDir),
- ok = file:change_mode(UnwritableDir, 8#555),
- CanNotCreate = filename:join([UnwritableDir, "out-dir-should-not-create"]),
-
- CmdLine = ["-o", CanNotCreate],
- ?assertMatch({error, {_, {unable_to_create_output_dir, CanNotCreate}}},
- rcl_cmd_args:args2state(getopt:parse(relcool:opt_spec_list(), CmdLine))).
-
spec_parse_fail_case(_Config) ->
Spec = "aaeu:3333:33.22a44",
CmdLine = ["-g", Spec],
diff --git a/test/rclt_release_SUITE.erl b/test/rclt_release_SUITE.erl
index c13672a..4ac44d9 100644
--- a/test/rclt_release_SUITE.erl
+++ b/test/rclt_release_SUITE.erl
@@ -25,7 +25,8 @@
init_per_testcase/2,
all/0,
make_release/1,
- make_overridden_release/1]).
+ make_overridden_release/1,
+ make_implicit_config_release/1]).
-include_lib("common_test/include/ct.hrl").
-include_lib("eunit/include/eunit.hrl").
@@ -49,7 +50,7 @@ init_per_testcase(_, Config) ->
{state, State} | Config].
all() ->
- [make_release, make_overridden_release].
+ [make_release, make_overridden_release, make_implicit_config_release].
make_release(Config) ->
LibDir1 = proplists:get_value(lib1, Config),
@@ -136,6 +137,46 @@ make_overridden_release(Config) ->
OverrideApp ++ "-" ++ OverrideVsn])),
?assertMatch(OverrideAppDir, Real).
+make_implicit_config_release(Config) ->
+ LibDir1 = proplists:get_value(lib1, Config),
+ FooRoot = filename:join([LibDir1, "foodir1", "foodir2"]),
+ filelib:ensure_dir(filename:join([FooRoot, "tmp"])),
+ [(fun({Name, Vsn}) ->
+ create_app(LibDir1, Name, Vsn, [kernel, stdlib], [])
+ end)(App)
+ ||
+ App <-
+ [{create_random_name("lib_app1_"), create_random_vsn()}
+ || _ <- lists:seq(1, 100)]],
+
+ create_app(LibDir1, "goal_app_1", "0.0.1", [stdlib,kernel,non_goal_1], []),
+ create_app(LibDir1, "lib_dep_1", "0.0.1", [stdlib,kernel], []),
+ create_app(LibDir1, "goal_app_2", "0.0.1", [stdlib,kernel,goal_app_1,non_goal_2], []),
+ create_app(LibDir1, "non_goal_1", "0.0.1", [stdlib,kernel], [lib_dep_1]),
+ create_app(LibDir1, "non_goal_2", "0.0.1", [stdlib,kernel], []),
+
+ ConfigFile = filename:join([LibDir1, "relcool.config"]),
+ write_config(ConfigFile,
+ [{release, {foo, "0.0.1"},
+ [goal_app_1,
+ goal_app_2]}]),
+ OutputDir = filename:join([proplists:get_value(data_dir, Config),
+ create_random_name("relcool-output")]),
+ ok = file:set_cwd(FooRoot),
+ {ok, FooRoot} = file:get_cwd(),
+ {ok, State} = relcool:do(undefined, undefined, [], [LibDir1], 2,
+ OutputDir, []),
+ [{{foo, "0.0.1"}, Release}] = ec_dictionary:to_list(rcl_state:releases(State)),
+ ?assert(ec_file:exists(OutputDir)),
+
+ AppSpecs = rcl_release:applications(Release),
+ ?assert(lists:keymember(stdlib, 1, AppSpecs)),
+ ?assert(lists:keymember(kernel, 1, AppSpecs)),
+ ?assert(lists:member({non_goal_1, "0.0.1"}, AppSpecs)),
+ ?assert(lists:member({non_goal_2, "0.0.1"}, AppSpecs)),
+ ?assert(lists:member({goal_app_1, "0.0.1"}, AppSpecs)),
+ ?assert(lists:member({goal_app_2, "0.0.1"}, AppSpecs)),
+ ?assert(lists:member({lib_dep_1, "0.0.1", load}, AppSpecs)).
%%%===================================================================