aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJordan Wilberding <[email protected]>2013-09-28 15:57:33 -0700
committerJordan Wilberding <[email protected]>2013-09-28 15:57:33 -0700
commitc2bbc32be1cefafca6fd12867293070a9790fd76 (patch)
tree673344960289c731045dd97b70028c51ed71fd96 /src
parent8a60327694646893729cde1708be4f507beceae0 (diff)
parentfaf83051cc5046659ce6beeff4427206dcca4e5d (diff)
downloadrelx-c2bbc32be1cefafca6fd12867293070a9790fd76.tar.gz
relx-c2bbc32be1cefafca6fd12867293070a9790fd76.tar.bz2
relx-c2bbc32be1cefafca6fd12867293070a9790fd76.zip
Merge pull request #56 from tsloughter/masterv0.4.00.4.0
warn on bad app during discovery and erts in tar fix
Diffstat (limited to 'src')
-rw-r--r--src/relx.erl4
-rw-r--r--src/rlx_app_discovery.erl19
-rw-r--r--src/rlx_cmd_args.erl4
-rw-r--r--src/rlx_dscv_util.erl2
-rw-r--r--src/rlx_log.erl33
-rw-r--r--src/rlx_prv_assembler.erl44
-rw-r--r--src/rlx_rel_discovery.erl2
7 files changed, 73 insertions, 35 deletions
diff --git a/src/relx.erl b/src/relx.erl
index f6575a1..f6e156d 100644
--- a/src/relx.erl
+++ b/src/relx.erl
@@ -195,8 +195,8 @@ opt_spec_list() ->
{default_libs, undefined, "default-libs",
{boolean, true},
"Whether to use the default system added lib dirs (means you must add them all manually). Default is true"},
- {log_level, $V, "verbose", {integer, 1},
- "Verbosity level, maybe between 0 and 2"},
+ {log_level, $V, "verbose", {integer, 2},
+ "Verbosity level, maybe between 0 and 3"},
{override_app, $a, "override_app", string,
"Provide an app name and a directory to override in the form <appname>:<app directory>"},
{config, $c, "config", {string, ""}, "The path to a config file"},
diff --git a/src/rlx_app_discovery.erl b/src/rlx_app_discovery.erl
index 39f3921..cf0d1c6 100644
--- a/src/rlx_app_discovery.erl
+++ b/src/rlx_app_discovery.erl
@@ -39,8 +39,8 @@
do(State, LibDirs) ->
rlx_log:info(rlx_state:log(State),
fun() ->
- ["Resolving OTP Applications from directories:\n",
- [[rlx_util:indent(2), LibDir, "\n"] || LibDir <- LibDirs]]
+ ["Resolving OTP Applications from directories:\n",
+ string:join([[rlx_util:indent(2), LibDir] || LibDir <- LibDirs], "\n")]
end),
resolve_app_metadata(State, LibDirs).
@@ -62,6 +62,9 @@ resolve_app_metadata(State, LibDirs) ->
case Err of
{error, _} ->
true;
+ {warning, W} ->
+ rlx_log:warn(rlx_state:log(State), format_detail(W)),
+ false;
_ ->
false
end] of
@@ -79,6 +82,8 @@ resolve_app_metadata(State, LibDirs) ->
?RLX_ERROR(Errors)
end.
+app_name({warning, _}) ->
+ undefined;
app_name({error, _}) ->
undefined;
app_name({ok, AppMeta}) ->
@@ -103,7 +108,7 @@ resolve_override(AppName, FileName0) ->
end.
-spec format_detail(ErrorDetail::term()) -> iolist().
-format_detail({error, {missing_beam_file, Module, BeamFile}}) ->
+format_detail({missing_beam_file, Module, BeamFile}) ->
io_lib:format("Missing beam file ~p ~p", [Module, BeamFile]);
format_detail({error, {invalid_override, AppName, FileName}}) ->
io_lib:format("Override {~p, ~p} is not a valid OTP App. Perhaps you forgot to build it?",
@@ -161,9 +166,9 @@ gather_application_info(EbinDir, File) ->
{ok, [{application, AppName, AppDetail}]} ->
validate_application_info(EbinDir, File, AppName, AppDetail);
{error, Reason} ->
- {error, {unable_to_load_app, AppDir, Reason}};
+ {warning, {unable_to_load_app, AppDir, Reason}};
_ ->
- {error, {invalid_app_file, File}}
+ {warning, {invalid_app_file, File}}
end.
-spec validate_application_info(file:name(),
@@ -189,7 +194,7 @@ validate_application_info(EbinDir, AppFile, AppName, AppDetail) ->
get_modules_list(AppFile, AppDetail) ->
case proplists:get_value(modules, AppDetail) of
undefined ->
- {error, {invalid_app_file, AppFile}};
+ {warning, {invalid_app_file, AppFile}};
ModulesList ->
{ok, ModulesList}
end.
@@ -203,7 +208,7 @@ has_all_beams(EbinDir, [Module | ModuleList]) ->
true ->
has_all_beams(EbinDir, ModuleList);
false ->
- {error, {missing_beam_file, Module, BeamFile}}
+ {warning, {missing_beam_file, Module, BeamFile}}
end;
has_all_beams(_, []) ->
ok.
diff --git a/src/rlx_cmd_args.erl b/src/rlx_cmd_args.erl
index 621b626..57c9a57 100644
--- a/src/rlx_cmd_args.erl
+++ b/src/rlx_cmd_args.erl
@@ -80,7 +80,7 @@ format_error({not_directory, Dir}) ->
io_lib:format("Library directory does not exist: ~s", [Dir]);
format_error({invalid_log_level, LogLevel}) ->
io_lib:format("Invalid log level specified -V ~p, log level must be in the"
- " range 0..2", [LogLevel]);
+ " range 0..3", [LogLevel]);
format_error({invalid_target, Target}) ->
io_lib:format("Invalid action specified: ~s", [Target]).
@@ -136,7 +136,7 @@ validate_config(Config) ->
create_log(Opts, Acc) ->
LogLevel = proplists:get_value(log_level, Opts, 0),
if
- LogLevel >= 0, LogLevel =< 2 ->
+ LogLevel >= 0, LogLevel =< 3 ->
create_goals(Opts, [{log, rlx_log:new(LogLevel, command_line)} | Acc]);
true ->
?RLX_ERROR({invalid_log_level, LogLevel})
diff --git a/src/rlx_dscv_util.erl b/src/rlx_dscv_util.erl
index 779534c..52bbd07 100644
--- a/src/rlx_dscv_util.erl
+++ b/src/rlx_dscv_util.erl
@@ -97,6 +97,8 @@ discover_dir(ProcessDir, File, file) ->
[{ok, Result}];
{noresult, _} ->
[];
+ Warn = {warning, _} ->
+ [Warn];
Err = {error, _} ->
[Err]
end;
diff --git a/src/rlx_log.erl b/src/rlx_log.erl
index 608c0af..64997a2 100644
--- a/src/rlx_log.erl
+++ b/src/rlx_log.erl
@@ -32,6 +32,8 @@
info/3,
error/2,
error/3,
+ warn/2,
+ warn/3,
log_level/1,
atom_log_level/1,
format/1]).
@@ -63,11 +65,9 @@
-type log_level() :: int_log_level() | atom_log_level().
--type int_log_level() :: 0..2.
+-type int_log_level() :: 0..3.
-%% Why no warn? because for our purposes there is no difference between error
-%% and warn
--type atom_log_level() :: error | info | debug.
+-type atom_log_level() :: error | warn | info | debug.
-type log_fun() :: fun(() -> iolist()).
@@ -83,16 +83,18 @@
new(LogLevel) ->
new(LogLevel, api).
-new(LogLevel, Caller) when LogLevel >= 0, LogLevel =< 2 ->
+new(LogLevel, Caller) when LogLevel >= 0, LogLevel =< 3 ->
#state_t{mod=?MODULE, log_level=LogLevel, caller=Caller};
new(AtomLogLevel, Caller)
when AtomLogLevel =:= error;
+ AtomLogLevel =:= warn;
AtomLogLevel =:= info;
AtomLogLevel =:= debug ->
LogLevel = case AtomLogLevel of
error -> 0;
- info -> 1;
- debug -> 2
+ warn -> 1;
+ info -> 2;
+ debug -> 3
end,
new(LogLevel, Caller).
@@ -142,6 +144,21 @@ error(LogState, String) ->
error(LogState, FormatString, Args) ->
log(LogState, ?RLX_ERROR, colorize(LogState, ?GREEN, false, FormatString), Args).
+%% @doc log at the warn level given the current log state with a string or
+%% format string that returns a function
+-spec warn(t(), string() | log_fun()) -> ok.
+warn(LogState, Fun)
+ when erlang:is_function(Fun) ->
+ log(LogState, ?RLX_WARN, fun() -> colorize(LogState, ?MAGENTA, false, Fun()) end);
+warn(LogState, String) ->
+ warn(LogState, "~s~n", [String]).
+
+%% @doc log at the warn level given the current log state with a format string
+%% and argements @see io:format/2
+-spec warn(t(), string(), [any()]) -> ok.
+warn(LogState, FormatString, Args) ->
+ log(LogState, ?RLX_WARN, colorize(LogState, ?MAGENTA, false, FormatString), Args).
+
%% @doc Execute the fun passed in if log level is as expected.
-spec log(t(), int_log_level(), log_fun()) -> ok.
log(#state_t{mod=?MODULE, log_level=DetailLogLevel}, LogLevel, Fun)
@@ -178,6 +195,8 @@ log_level(#state_t{mod=?MODULE, log_level=DetailLogLevel}) ->
-spec atom_log_level(t()) -> atom_log_level().
atom_log_level(#state_t{mod=?MODULE, log_level=?RLX_ERROR}) ->
error;
+atom_log_level(#state_t{mod=?MODULE, log_level=?RLX_WARN}) ->
+ warn;
atom_log_level(#state_t{mod=?MODULE, log_level=?RLX_INFO}) ->
info;
atom_log_level(#state_t{mod=?MODULE, log_level=?RLX_DEBUG}) ->
diff --git a/src/rlx_prv_assembler.erl b/src/rlx_prv_assembler.erl
index 27dd3c1..9369f5d 100644
--- a/src/rlx_prv_assembler.erl
+++ b/src/rlx_prv_assembler.erl
@@ -431,10 +431,16 @@ make_tar(State, Release, OutputDir) ->
Prefix = code:root_dir(),
ErtsVersion = rlx_release:erts(Release),
ErtsDir = filename:join([Prefix]),
+ Opts = [{path, [filename:join([OutputDir, "lib", "*", "ebin"])]},
+ {outdir, OutputDir} |
+ case rlx_state:get(State, include_erts, true) of
+ true ->
+ [{erts, ErtsDir}];
+ false ->
+ []
+ end],
case systools:make_tar(filename:join([OutputDir, "releases", Vsn, Name]),
- [{path, [filename:join([OutputDir, "lib", "*", "ebin"])]},
- {erts, ErtsDir},
- {outdir, OutputDir}]) of
+ Opts) of
ok ->
TempDir = ec_file:insecure_mkdtemp(),
try
@@ -456,19 +462,25 @@ update_tar(State, TempDir, OutputDir, Name, Vsn, ErtsVersion) ->
TarFile = filename:join(OutputDir, Name++"-"++Vsn++".tar.gz"),
file:rename(filename:join(OutputDir, Name++".tar.gz"), TarFile),
erl_tar:extract(TarFile, [{cwd, TempDir}, compressed]),
- ok = erl_tar:create(TarFile,
- [{"erts-"++ErtsVersion, filename:join(TempDir, "erts-"++ErtsVersion)},
- {filename:join(["erts-"++ErtsVersion, "bin", "nodetool"]),
- hd(nodetool_contents())},
- {filename:join(["erts-"++ErtsVersion, "bin", "install_upgrade.escript"]),
- hd(install_upgrade_escript_contents())},
- {"lib", filename:join(TempDir, "lib")},
- {"releases", filename:join(TempDir, "releases")},
- {filename:join(["releases", "RELEASES"]),
- filename:join([OutputDir, "releases", "RELEASES"])},
- {filename:join(["releases", Vsn, "vm.args"]),
- filename:join([OutputDir, "releases", Vsn, "vm.args"])},
- {"bin", filename:join([OutputDir, "bin"])}], [compressed]),
+ ok =
+ erl_tar:create(TarFile,
+ [{"lib", filename:join(TempDir, "lib")},
+ {"releases", filename:join(TempDir, "releases")},
+ {filename:join(["releases", "RELEASES"]),
+ filename:join([OutputDir, "releases", "RELEASES"])},
+ {filename:join(["releases", Vsn, "vm.args"]),
+ filename:join([OutputDir, "releases", Vsn, "vm.args"])},
+ {"bin", filename:join([OutputDir, "bin"])} |
+ case rlx_state:get(State, include_erts, true) of
+ true ->
+ [{"erts-"++ErtsVersion, filename:join(TempDir, "erts-"++ErtsVersion)},
+ {filename:join(["erts-"++ErtsVersion, "bin", "nodetool"]),
+ hd(nodetool_contents())},
+ {filename:join(["erts-"++ErtsVersion, "bin", "install_upgrade.escript"]),
+ hd(install_upgrade_escript_contents())}];
+ false ->
+ []
+ end], [compressed]),
rlx_log:info(rlx_state:log(State),
"tarball ~s successfully created!~n", [TarFile]),
ec_file:remove(TempDir, [recursive]),
diff --git a/src/rlx_rel_discovery.erl b/src/rlx_rel_discovery.erl
index 1616f52..ee9d941 100644
--- a/src/rlx_rel_discovery.erl
+++ b/src/rlx_rel_discovery.erl
@@ -41,7 +41,7 @@ do(State, LibDirs, AppMeta) ->
rlx_log:info(rlx_state:log(State),
fun() ->
["Resolving available OTP Releases from directories:\n",
- [[rlx_util:indent(2), LibDir, "\n"] || LibDir <- LibDirs]]
+ string:join([[rlx_util:indent(2), LibDir] || LibDir <- LibDirs], "\n")]
end),
resolve_rel_metadata(State, LibDirs, AppMeta).