aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTristan Sloughter <[email protected]>2013-11-18 06:38:27 -0800
committerTristan Sloughter <[email protected]>2013-11-18 06:38:27 -0800
commite27e17ea3b0d9e9a83ca5084145edc99fd526444 (patch)
tree06371825a8876bc8d19e10755241510b341bbb02
parent10620765c5028c24d57caba20b8e86b98351e3a5 (diff)
parent73b24fd1a0604e413fece30181cc632c1081aa29 (diff)
downloadrelx-e27e17ea3b0d9e9a83ca5084145edc99fd526444.tar.gz
relx-e27e17ea3b0d9e9a83ca5084145edc99fd526444.tar.bz2
relx-e27e17ea3b0d9e9a83ca5084145edc99fd526444.zip
Merge pull request #94 from josevalim/jv-expand-lib-dirs
Support wildcards in lib dirs
-rw-r--r--src/rlx_cmd_args.erl5
-rw-r--r--src/rlx_prv_config.erl2
-rw-r--r--src/rlx_util.erl20
-rw-r--r--test/rlx_command_SUITE.erl15
-rw-r--r--test/rlx_release_SUITE.erl3
5 files changed, 39 insertions, 6 deletions
diff --git a/src/rlx_cmd_args.erl b/src/rlx_cmd_args.erl
index f592474..d2402ce 100644
--- a/src/rlx_cmd_args.erl
+++ b/src/rlx_cmd_args.erl
@@ -223,11 +223,12 @@ create_output_dir(Opts, Acc) ->
create_lib_dirs(Opts, Acc) ->
Dirs = proplists:get_all_values(lib_dir, Opts) ++
proplists:get_value(lib_dirs, Opts, []),
- case check_lib_dirs(Dirs) of
+ ExpDirs = rlx_util:wildcard_paths(Dirs),
+ case check_lib_dirs(ExpDirs) of
Error = {error, _} ->
Error;
ok ->
- create_root_dir(Opts, [{lib_dirs, [filename:absname(Dir) || Dir <- Dirs]} | Acc])
+ create_root_dir(Opts, [{lib_dirs, ExpDirs} | Acc])
end.
-spec create_root_dir([getopt:option()], rlx_state:cmd_args()) ->
diff --git a/src/rlx_prv_config.erl b/src/rlx_prv_config.erl
index 19aa576..aa2e79c 100644
--- a/src/rlx_prv_config.erl
+++ b/src/rlx_prv_config.erl
@@ -129,7 +129,7 @@ load_terms({paths, Paths}, {ok, State}) ->
load_terms({lib_dirs, Dirs}, {ok, State}) ->
State2 =
rlx_state:add_lib_dirs(State,
- [list_to_binary(filename:absname(Dir)) || Dir <- Dirs]),
+ [list_to_binary(Dir) || Dir <- rlx_util:wildcard_paths(Dirs)]),
{ok, State2};
load_terms({providers, Providers0}, {ok, State0}) ->
Providers1 = gen_providers(Providers0, State0),
diff --git a/src/rlx_util.erl b/src/rlx_util.erl
index 53e9122..48e2ee1 100644
--- a/src/rlx_util.erl
+++ b/src/rlx_util.erl
@@ -28,7 +28,8 @@
is_error/1,
error_reason/1,
indent/1,
- optional_to_string/1]).
+ optional_to_string/1,
+ wildcard_paths/1]).
-define(ONE_LEVEL_INDENT, " ").
%%============================================================================
@@ -96,6 +97,23 @@ optional_to_string(undefined) ->
optional_to_string(Value) when is_list(Value) ->
Value.
+%% @doc expand wildcards and names in the given paths
+-spec wildcard_paths([file:filename_all()]) -> [string()].
+wildcard_paths(Paths) ->
+ [filename:absname(Expanded) || Path <- Paths, Expanded <- wildcard(Path)].
+
+%% In case the given directory does not expand,
+%% we return it back in a list so we trigger the
+%% proper error reportings.
+-spec wildcard(file:filename_all()) -> [string()].
+wildcard(Path) when is_binary(Path) ->
+ wildcard(binary_to_list(Path));
+wildcard(Path) when is_list(Path) ->
+ case filelib:wildcard(Path) of
+ [] -> [Path];
+ Paths -> Paths
+ end.
+
%%%===================================================================
%%% Test Functions
%%%===================================================================
diff --git a/test/rlx_command_SUITE.erl b/test/rlx_command_SUITE.erl
index 6f726b4..5ea4769 100644
--- a/test/rlx_command_SUITE.erl
+++ b/test/rlx_command_SUITE.erl
@@ -24,6 +24,7 @@
end_per_suite/1,
all/0,
normal_passing_case/1,
+ lib_expansion_case/1,
lib_fail_case/1,
spec_parse_fail_case/1,
config_fail_case/1]).
@@ -41,7 +42,7 @@ end_per_suite(_Config) ->
ok.
all() ->
- [normal_passing_case, lib_fail_case, config_fail_case].
+ [normal_passing_case, lib_expansion_case, lib_fail_case, config_fail_case].
normal_passing_case(Config) ->
DataDir = proplists:get_value(data_dir, Config),
@@ -70,6 +71,18 @@ normal_passing_case(Config) ->
{{45,22},{[],[<<"build">>,21]}}, between}],
rlx_state:goals(State)).
+lib_expansion_case(Config) ->
+ DataDir = proplists:get_value(data_dir, Config),
+ Lib1 = filename:join(DataDir, <<"lib1">>),
+ Lib2 = filename:join(DataDir, <<"lib2">>),
+ ok = rlx_util:mkdir_p(Lib1),
+ ok = rlx_util:mkdir_p(Lib2),
+
+ CmdLine = ["-l", filename:join(DataDir, "*")],
+ {ok, {Opts, Targets}} = getopt:parse(relx:opt_spec_list(), CmdLine),
+ {ok, State} = rlx_cmd_args:args2state(Opts, Targets),
+ ?assertMatch([Lib1, Lib2],
+ rlx_state:lib_dirs(State)).
lib_fail_case(Config) ->
DataDir = proplists:get_value(data_dir, Config),
diff --git a/test/rlx_release_SUITE.erl b/test/rlx_release_SUITE.erl
index d16dce9..3087e63 100644
--- a/test/rlx_release_SUITE.erl
+++ b/test/rlx_release_SUITE.erl
@@ -130,7 +130,8 @@ make_extend_release(Config) ->
[goal_app_1,
goal_app_2]},
{release, {foo_test, "0.0.1", {extend, foo}},
- [goal_app_2]}]),
+ [goal_app_2]},
+ {lib_dirs, [filename:join(LibDir1, "*")]}]),
OutputDir = filename:join([proplists:get_value(data_dir, Config),
create_random_name("relx-output")]),
{ok, State} = relx:do(foo_test, undefined, [], [LibDir1], 3,