summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/rebar.erl16
-rw-r--r--src/rebar_appups.erl66
-rw-r--r--src/rebar_dialyzer.erl16
-rw-r--r--src/rebar_erlc_compiler.erl33
-rw-r--r--src/rebar_lfe_compiler.erl16
-rw-r--r--src/rebar_port_compiler.erl127
-rw-r--r--src/rebar_post_script.erl65
-rw-r--r--src/rebar_pre_script.erl64
-rw-r--r--src/rebar_rel_utils.erl15
-rw-r--r--src/rebar_reltool.erl2
-rw-r--r--src/rebar_upgrade.erl5
-rw-r--r--src/rebar_utils.erl12
-rw-r--r--src/rebar_xref.erl47
13 files changed, 186 insertions, 298 deletions
diff --git a/src/rebar.erl b/src/rebar.erl
index 36114cf..1d53622 100644
--- a/src/rebar.erl
+++ b/src/rebar.erl
@@ -324,17 +324,15 @@ is_command_name_sub_word_candidate(Command, Candidate) ->
%% Allow for parts of commands to be abbreviated, i.e. create-app
%% can be shortened to "create-a", "c-a" or "c-app" (but not
%% "create-" since that would be ambiguous).
- CommandSubWords = re:split(Command, "-", [{return, list}]),
- CandidateSubWords = re:split(Candidate, "-", [{return, list}]),
+ ReOpts = [{return, list}],
+ CommandSubWords = re:split(Command, "-", ReOpts),
+ CandidateSubWords = re:split(Candidate, "-", ReOpts),
is_command_name_sub_word_candidate_aux(CommandSubWords, CandidateSubWords).
-is_command_name_sub_word_candidate_aux([CmdSW | CmdSWs], [CandSW | CandSWs]) ->
- case lists:prefix(CmdSW, CandSW) of
- true ->
- is_command_name_sub_word_candidate_aux(CmdSWs, CandSWs);
- false ->
- false
- end;
+is_command_name_sub_word_candidate_aux([CmdSW | CmdSWs],
+ [CandSW | CandSWs]) ->
+ lists:prefix(CmdSW, CandSW) andalso
+ is_command_name_sub_word_candidate_aux(CmdSWs, CandSWs);
is_command_name_sub_word_candidate_aux([], []) ->
true;
is_command_name_sub_word_candidate_aux(_CmdSWs, _CandSWs) ->
diff --git a/src/rebar_appups.erl b/src/rebar_appups.erl
index 079d596..871c426 100644
--- a/src/rebar_appups.erl
+++ b/src/rebar_appups.erl
@@ -56,22 +56,20 @@
"Reltool and .rel release names do not match~n", []),
%% Find all the apps that have been upgraded
- UpgradedApps = get_upgraded_apps(Name, OldVerPath, NewVerPath),
+ {_Added, _Removed, Upgraded} = get_apps(Name, OldVerPath, NewVerPath),
%% Get a list of any appup files that exist in the new release
NewAppUpFiles = rebar_utils:find_files(
filename:join([NewName, "lib"]), "^.*.appup$"),
%% Convert the list of appup files into app names
- AppUpApps = lists:map(fun(File) ->
- file_to_name(File)
- end, NewAppUpFiles),
+ AppUpApps = [file_to_name(File) || File <- NewAppUpFiles],
%% Create a list of apps that don't already have appups
- Apps = genappup_which_apps(UpgradedApps, AppUpApps),
+ UpgradeApps = genappup_which_apps(Upgraded, AppUpApps),
- %% Generate appup files
- generate_appup_files(Name, OldVerPath, Apps),
+ %% Generate appup files for upgraded apps
+ generate_appup_files(Name, OldVerPath, UpgradeApps),
ok.
@@ -79,24 +77,43 @@
%% Internal functions
%% ===================================================================
-get_upgraded_apps(Name, OldVerPath, NewVerPath) ->
+get_apps(Name, OldVerPath, NewVerPath) ->
OldApps = rebar_rel_utils:get_rel_apps(Name, OldVerPath),
+ ?DEBUG("Old Version Apps: ~p~n", [OldApps]),
+
NewApps = rebar_rel_utils:get_rel_apps(Name, NewVerPath),
+ ?DEBUG("New Version Apps: ~p~n", [NewApps]),
+
+ Added = app_list_diff(NewApps, OldApps),
+ ?DEBUG("Added: ~p~n", [Added]),
+
+ Removed = app_list_diff(OldApps, NewApps),
+ ?DEBUG("Removed: ~p~n", [Removed]),
+
+ PossiblyUpgraded = proplists:get_keys(NewApps),
- Sorted = lists:umerge(lists:sort(NewApps), lists:sort(OldApps)),
- AddedorChanged = lists:subtract(Sorted, OldApps),
- DeletedorChanged = lists:subtract(Sorted, NewApps),
- ?DEBUG("Added or Changed: ~p~n", [AddedorChanged]),
- ?DEBUG("Deleted or Changed: ~p~n", [DeletedorChanged]),
+ UpgradedApps = [upgraded_app(AppName,
+ proplists:get_value(AppName, OldApps),
+ proplists:get_value(AppName, NewApps))
+ || AppName <- PossiblyUpgraded],
- AddedDeletedChanged = lists:ukeysort(1, lists:append(DeletedorChanged,
- AddedorChanged)),
- UpgradedApps = lists:subtract(AddedorChanged, AddedDeletedChanged),
- ?DEBUG("Upgraded Apps:~p~n", [UpgradedApps]),
+ Upgraded = lists:dropwhile(fun(Elem) ->
+ Elem == false
+ end, lists:sort(UpgradedApps)),
- [{AppName, {proplists:get_value(AppName, OldApps), NewVer}}
- || {AppName, NewVer} <- UpgradedApps].
+ ?DEBUG("Upgraded: ~p~n", [Upgraded]),
+ {Added, Removed, Upgraded}.
+
+upgraded_app(AppName, OldAppVer, NewAppVer) when OldAppVer /= NewAppVer ->
+ {AppName, {OldAppVer, NewAppVer}};
+upgraded_app(_, _, _) ->
+ false.
+
+app_list_diff(List1, List2) ->
+ List3 = lists:umerge(lists:sort(proplists:get_keys(List1)),
+ lists:sort(proplists:get_keys(List2))),
+ List3 -- proplists:get_keys(List2).
file_to_name(File) ->
filename:rootname(filename:basename(File)).
@@ -161,13 +178,10 @@ generate_instruction_advanced(Name, _, _) ->
get_behavior(List) ->
Attributes = proplists:get_value(attributes, List),
- Behavior = case proplists:get_value(behavior, Attributes) of
- undefined ->
- proplists:get_value(behaviour, Attributes);
- Else ->
- Else
- end,
- Behavior.
+ case proplists:get_value(behavior, Attributes) of
+ undefined -> proplists:get_value(behaviour, Attributes);
+ Else -> Else
+ end.
is_code_change(List) ->
Exports = proplists:get_value(exports, List),
diff --git a/src/rebar_dialyzer.erl b/src/rebar_dialyzer.erl
index 58fbf23..b624a44 100644
--- a/src/rebar_dialyzer.erl
+++ b/src/rebar_dialyzer.erl
@@ -55,7 +55,7 @@
-include("rebar.hrl").
--type(warning() :: {atom(), {string(), integer()}, any()}).
+-type warning() :: {atom(), {string(), integer()}, any()}.
%% ===================================================================
%% Public API
@@ -84,7 +84,10 @@ dialyze(Config, File) ->
end,
?DEBUG("DialyzerOpts: ~p~n", [DialyzerOpts]),
try dialyzer:run(DialyzerOpts) of
- Warnings -> output_warnings(Warnings)
+ [] ->
+ ok;
+ Warnings ->
+ print_warnings(Warnings)
catch
throw:{dialyzer_error, Reason} ->
?ABORT("~s~n", [Reason])
@@ -116,7 +119,7 @@ dialyze(Config, File) ->
[] ->
?INFO("The built PLT can be found in ~s~n", [Plt]);
_ ->
- output_warnings(Warnings)
+ print_warnings(Warnings)
end,
ok.
@@ -147,11 +150,12 @@ app_dirs(Apps) ->
|| Path <- [code:lib_dir(App) || App <- Apps], erlang:is_list(Path)].
%% @doc Render the warnings on the console.
--spec output_warnings(Warnings::[warning()]) -> 'ok'.
-output_warnings(Warnings) ->
+-spec print_warnings(Warnings::[warning(), ...]) -> no_return().
+print_warnings(Warnings) ->
lists:foreach(fun(Warning) ->
?CONSOLE("~s", [dialyzer:format_warning(Warning)])
- end, Warnings).
+ end, Warnings),
+ ?FAIL.
%% @doc If the plt option is present in rebar.config return its value,
%% otherwise return $HOME/.dialyzer_plt or $REBAR_PLT_DIR/.dialyzer_plt.
diff --git a/src/rebar_erlc_compiler.erl b/src/rebar_erlc_compiler.erl
index 38dd198..fe06cbf 100644
--- a/src/rebar_erlc_compiler.erl
+++ b/src/rebar_erlc_compiler.erl
@@ -52,7 +52,8 @@
%%
%% OtpRelease = erlang:system_info(otp_release).
%% SysArch = erlang:system_info(system_architecture).
-%% Words = integer_to_list(8 * erlang:system_info(wordsize)).
+%% Words = integer_to_list(8 *
+%% erlang:system_info({wordsize, external})).
%%
%% E.g. to define HAVE_SENDFILE only on systems with
%% sendfile(), to define BACKLOG on Linux/FreeBSD as 128,
@@ -69,9 +70,13 @@
-spec compile(Config::rebar_config:config(), AppFile::file:filename()) -> 'ok'.
compile(Config, _AppFile) ->
- ?DEPRECATED(fail_on_warning, warnings_as_errors,
- rebar_config:get_list(Config, erl_opts, []),
- "once OTP R14B03 is released"),
+ %% TODO: enable as soon as OTP patch has been accepted
+ %% ?DEPRECATED(fail_on_warning, warnings_as_errors,
+ %% rebar_config:get_list(Config, xrl_opts, []),
+ %% "once R15 is released"),
+ %% ?DEPRECATED(fail_on_warning, warnings_as_errors,
+ %% rebar_config:get_list(Config, yrl_opts, []),
+ %% "once R15 is released"),
rebar_base_compiler:run(Config,
check_files(rebar_config:get_local(
@@ -247,21 +252,10 @@ internal_erl_compile(Source, Config, Outdir, ErlOpts) ->
case needs_compile(Source, Target, Hrls) of
true ->
Opts = [{outdir, filename:dirname(Target)}] ++
- ErlOpts ++ [{i, "include"}, report, return],
+ ErlOpts ++ [{i, "include"}, report],
case compile:file(Source, Opts) of
- {ok, _, []} ->
+ {ok, _} ->
ok;
- {ok, _, _Warnings} ->
- %% We got at least one warning -- if fail_on_warning
- %% is in options, fail
- case lists:member(fail_on_warning, Opts) of
- true ->
- %% remove target to prevent overlooking this failure
- ok = file:delete(Target),
- ?FAIL;
- false ->
- ok
- end;
_ ->
?FAIL
end;
@@ -286,14 +280,14 @@ compile_mib(Source, Target, Config) ->
Config::rebar_config:config()) -> 'ok'.
compile_xrl(Source, Target, Config) ->
Opts = [{scannerfile, Target}, {return, true}
- |rebar_config:get(Config, xrl_opts, [])],
+ | rebar_config:get(Config, xrl_opts, [])],
compile_xrl_yrl(Source, Target, Opts, leex).
-spec compile_yrl(Source::file:filename(), Target::file:filename(),
Config::rebar_config:config()) -> 'ok'.
compile_yrl(Source, Target, Config) ->
Opts = [{parserfile, Target}, {return, true}
- |rebar_config:get(Config, yrl_opts, [])],
+ | rebar_config:get(Config, yrl_opts, [])],
compile_xrl_yrl(Source, Target, Opts, yecc).
-spec compile_xrl_yrl(Source::file:filename(), Target::file:filename(),
@@ -305,6 +299,7 @@ compile_xrl_yrl(Source, Target, Opts, Mod) ->
{ok, _, []} ->
ok;
{ok, _, _Warnings} ->
+ %% TODO: remove once R15 is released
case lists:member(fail_on_warning, Opts) of
true ->
?FAIL;
diff --git a/src/rebar_lfe_compiler.erl b/src/rebar_lfe_compiler.erl
index 50b7c29..3775735 100644
--- a/src/rebar_lfe_compiler.erl
+++ b/src/rebar_lfe_compiler.erl
@@ -45,7 +45,7 @@ compile(Config, _AppFile) ->
%% Internal functions
%% ===================================================================
-compile_lfe(Source, Target, Config) ->
+compile_lfe(Source, _Target, Config) ->
case code:which(lfe_comp) of
non_existing ->
?CONSOLE(<<
@@ -61,19 +61,11 @@ compile_lfe(Source, Target, Config) ->
>>, []),
?FAIL;
_ ->
- Opts = [{i, "include"}, {outdir, "ebin"}, report, return] ++
- rebar_config:get_list(Config, erl_opts, []),
+ Opts = [{i, "include"}, {outdir, "ebin"}, report]
+ ++ rebar_config:get_list(Config, erl_opts, []),
case lfe_comp:file(Source, Opts) of
- {ok, _, []} ->
+ {ok, _} ->
ok;
- {ok, _, _Warnings} ->
- case lists:member(fail_on_warning, Opts) of
- true ->
- ok = file:delete(Target),
- ?FAIL;
- false ->
- ok
- end;
_ ->
?FAIL
end
diff --git a/src/rebar_port_compiler.erl b/src/rebar_port_compiler.erl
index 19c6f79..b9c2ea4 100644
--- a/src/rebar_port_compiler.erl
+++ b/src/rebar_port_compiler.erl
@@ -38,11 +38,11 @@
%% Supported configuration variables:
%%
-%% * port_sources - Erlang list of files and/or wildcard strings to be
-%% compiled. Platform specific sources can be specified
-%% by enclosing a string in a tuple of the form
-%% {Regex, String} wherein Regex is a regular expression
-%% that is checked against the system architecture.
+%% * port_sources - Erlang list of filenames or wildcards to be compiled. May
+%% also contain a tuple consisting of a regular expression to
+%% be applied against the system architecture and a list of
+%% filenames or wildcards to include should the expression
+%% pass.
%%
%% * so_specs - Erlang list of tuples of the form
%% {"priv/so_name.so", ["c_src/object_file_name.o"]}
@@ -62,6 +62,14 @@
%% ERL_LDFLAGS - default -L and -lerl_interface -lei
%% DRV_CFLAGS - flags that will be used for compiling the driver
%% DRV_LDFLAGS - flags that will be used for linking the driver
+%% ERL_EI_LIBDIR - ei library directory
+%% CXX_TEMPLATE - C++ command template
+%% CC_TEMPLATE - C command template
+%% LINK_TEMPLATE - Linker command template
+%% PORT_IN_FILES - contains a space separated list of input
+%% file(s), (used in command template)
+%% PORT_OUT_FILE - contains the output filename (used in
+%% command template)
%%
%% Note that if you wish to extend (vs. replace) these variables,
%% you MUST include a shell-style reference in your definition.
@@ -97,10 +105,6 @@ compile(Config, AppFile) ->
_ ->
Env = setup_env(Config),
- %% One or more files are available for building.
- %% Run the pre-compile hook, if necessary.
- ok = run_precompile_hook(Config, Env),
-
%% Compile each of the sources
{NewBins, ExistingBins} = compile_each(Sources, Config, Env,
[], []),
@@ -116,14 +120,15 @@ compile(Config, AppFile) ->
%% and list of new binaries
lists:foreach(
fun({SoName,Bins}) ->
- AllBins = [sets:from_list(Bins), sets:from_list(NewBins)],
+ AllBins = [sets:from_list(Bins),
+ sets:from_list(NewBins)],
Intersection = sets:intersection(AllBins),
case needs_link(SoName, sets:to_list(Intersection)) of
true ->
- rebar_utils:sh(
- ?FMT("$CC ~s $LDFLAGS $DRV_LDFLAGS -o ~s",
- [string:join(Bins, " "), SoName]),
- [{env, Env}]);
+ Cmd = expand_command("LINK_TEMPLATE", Env,
+ string:join(Bins, " "),
+ SoName),
+ rebar_utils:sh(Cmd, [{env, Env}]);
false ->
?INFO("Skipping relink of ~s\n", [SoName]),
ok
@@ -141,10 +146,7 @@ clean(Config, AppFile) ->
ExtractSoName = fun({SoName, _}) -> SoName end,
rebar_file_utils:delete_each([ExtractSoName(S)
|| S <- so_specs(Config, AppFile,
- expand_objects(Sources))]),
-
- %% Run the cleanup script, if it exists
- run_cleanup_hook(Config).
+ expand_objects(Sources))]).
setup_env(Config) ->
%% Extract environment values from the config (if specified) and
@@ -165,7 +167,7 @@ expand_sources([], Acc) ->
expand_sources([{ArchRegex, Spec} | Rest], Acc) ->
case rebar_utils:is_arch(ArchRegex) of
true ->
- Acc2 = filelib:wildcard(Spec) ++ Acc,
+ Acc2 = expand_sources(Spec, Acc),
expand_sources(Rest, Acc2);
false ->
expand_sources(Rest, Acc)
@@ -178,39 +180,6 @@ expand_objects(Sources) ->
[filename:join([filename:dirname(F), filename:basename(F) ++ ".o"])
|| F <- Sources].
-run_precompile_hook(Config, Env) ->
- case rebar_config:get(Config, port_pre_script, undefined) of
- undefined ->
- ok;
- {Script, BypassFileName} ->
- ?DEPRECATED(port_pre_script,
- {pre_hooks, [{compile, "script"}]},
- "in a future build of rebar"),
- case filelib:is_regular(BypassFileName) of
- false ->
- ?CONSOLE("Running ~s\n", [Script]),
- {ok, _} = rebar_utils:sh(Script, [{env, Env}]),
- ok;
- true ->
- ?INFO("~s exists; not running ~s\n",
- [BypassFileName, Script])
- end
- end.
-
-run_cleanup_hook(Config) ->
- case rebar_config:get(Config, port_cleanup_script, undefined) of
- undefined ->
- ok;
- Script ->
- ?DEPRECATED(port_cleanup_script,
- {post_hooks, [{clean, "script"}]},
- "in a future build of rebar"),
- ?CONSOLE("Running ~s\n", [Script]),
- {ok, _} = rebar_utils:sh(Script, []),
- ok
- end.
-
-
compile_each([], _Config, _Env, NewBins, ExistingBins) ->
{lists:reverse(NewBins), lists:reverse(ExistingBins)};
compile_each([Source | Rest], Config, Env, NewBins, ExistingBins) ->
@@ -221,12 +190,13 @@ compile_each([Source | Rest], Config, Env, NewBins, ExistingBins) ->
?CONSOLE("Compiling ~s\n", [Source]),
case compiler(Ext) of
"$CC" ->
- rebar_utils:sh(?FMT("$CC -c $CFLAGS $DRV_CFLAGS ~s -o ~s",
- [Source, Bin]), [{env, Env}]);
+ rebar_utils:sh(expand_command("CC_TEMPLATE", Env,
+ Source, Bin),
+ [{env, Env}]);
"$CXX" ->
- rebar_utils:sh(
- ?FMT("$CXX -c $CXXFLAGS $DRV_CFLAGS ~s -o ~s",
- [Source, Bin]), [{env, Env}])
+ rebar_utils:sh(expand_command("CXX_TEMPLATE", Env,
+ Source, Bin),
+ [{env, Env}])
end,
compile_each(Rest, Config, Env, [Bin | NewBins], ExistingBins);
@@ -274,16 +244,17 @@ compiler(_) -> "$CC".
%%
apply_defaults(Vars, Defaults) ->
dict:to_list(
- dict:merge(fun(Key, VarValue, DefaultValue) ->
- case is_expandable(DefaultValue) of
+ dict:merge(fun(Key, VarValue, DefaultValue) ->
+ case is_expandable(DefaultValue) of
true ->
expand_env_variable(DefaultValue,
Key, VarValue);
false -> VarValue
- end
- end,
- dict:from_list(Vars),
- dict:from_list(Defaults))).
+ end
+ end,
+ dict:from_list(Vars),
+ dict:from_list(Defaults))).
+
%%
%% Given a list of {Key, Value} environment variables, where Key may be defined
%% multiple times, walk the list and expand each self-reference so that we
@@ -340,6 +311,11 @@ expand_vars(Key, Value, Vars) ->
end,
[], Vars).
+expand_command(TmplName, Env, InFiles, OutFile) ->
+ Cmd0 = proplists:get_value(TmplName, Env),
+ Cmd1 = expand_env_variable(Cmd0, "PORT_IN_FILES", InFiles),
+ Cmd2 = expand_env_variable(Cmd1, "PORT_OUT_FILE", OutFile),
+ re:replace(Cmd2, "\\\$\\w+|\\\${\\w+}", "", [global, {return, list}]).
%%
%% Given a string, determine if it is expandable
@@ -350,15 +326,17 @@ is_expandable(InStr) ->
nomatch -> false
end.
-
%%
%% Given env. variable FOO we want to expand all references to
%% it in InStr. References can have two forms: $FOO and ${FOO}
+%% The end of form $FOO is delimited with whitespace or eol
%%
expand_env_variable(InStr, VarName, VarValue) ->
- R1 = re:replace(InStr, "\\\$" ++ VarName, VarValue),
- re:replace(R1, "\\\${" ++ VarName ++ "}", VarValue, [{return, list}]).
-
+ R1 = re:replace(InStr, "\\\$" ++ VarName ++ "\\s", VarValue ++ " ",
+ [global]),
+ R2 = re:replace(R1, "\\\$" ++ VarName ++ "\$", VarValue),
+ re:replace(R2, "\\\${" ++ VarName ++ "}", VarValue,
+ [global, {return, list}]).
%%
%% Filter a list of env vars such that only those which match the provided
@@ -383,22 +361,29 @@ erts_dir() ->
os_env() ->
Os = [list_to_tuple(re:split(S, "=", [{return, list}, {parts, 2}])) ||
S <- os:getenv()],
- lists:keydelete([],1,Os). %% Remove Windows current disk and path
+ %% Drop variables without a name (win32)
+ [T1 || {K, _V} = T1 <- Os, K =/= []].
default_env() ->
[
+ {"CXX_TEMPLATE",
+ "$CXX -c $CXXFLAGS $DRV_CFLAGS $PORT_IN_FILES -o $PORT_OUT_FILE"},
+ {"CC_TEMPLATE",
+ "$CC -c $CFLAGS $DRV_CFLAGS $PORT_IN_FILES -o $PORT_OUT_FILE"},
+ {"LINK_TEMPLATE",
+ "$CC $PORT_IN_FILES $LDFLAGS $DRV_LDFLAGS -o $PORT_OUT_FILE"},
{"CC", "cc"},
{"CXX", "c++"},
{"ERL_CFLAGS", lists:concat([" -I", code:lib_dir(erl_interface, include),
" -I", filename:join(erts_dir(), "include"),
" "])},
- {"ERL_LDFLAGS", lists:concat([" -L", code:lib_dir(erl_interface, lib),
- " -lerl_interface -lei"])},
+ {"ERL_LDFLAGS", " -L$ERL_EI_LIBDIR -lerl_interface -lei"},
{"DRV_CFLAGS", "-g -Wall -fPIC $ERL_CFLAGS"},
{"DRV_LDFLAGS", "-shared $ERL_LDFLAGS"},
+ {"ERL_EI_LIBDIR", code:lib_dir(erl_interface, lib)},
{"darwin", "DRV_LDFLAGS",
"-bundle -flat_namespace -undefined suppress $ERL_LDFLAGS"},
- {"ERLANG_ARCH", integer_to_list(8 * erlang:system_info(wordsize))},
+ {"ERLANG_ARCH", rebar_utils:wordsize()},
{"ERLANG_TARGET", rebar_utils:get_arch()},
%% Solaris specific flags
diff --git a/src/rebar_post_script.erl b/src/rebar_post_script.erl
deleted file mode 100644
index c254fb8..0000000
--- a/src/rebar_post_script.erl
+++ /dev/null
@@ -1,65 +0,0 @@
-%% -*- erlang-indent-level: 4;indent-tabs-mode: nil -*-
-%% ex: ts=4 sw=4 et
-%% -------------------------------------------------------------------
-%%
-%% rebar: Erlang Build Tools
-%%
-%% Copyright (c) 2009, 2010 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_post_script).
-
--export([compile/2,
- clean/2]).
-
--include("rebar.hrl").
-
-%% ===================================================================
-%% Public API
-%% ===================================================================
-
-compile(Config, _) ->
- execute_post_script(Config, compile_post_script).
-
-clean(Config, _) ->
- execute_post_script(Config, clean_post_script).
-
-
-%% ===================================================================
-%% Internal functions
-%% ===================================================================
-
-execute_post_script(Config, Key) ->
- case rebar_config:get_local(Config, Key, undefined) of
- undefined ->
- ok;
- Script ->
- deprecated(Key),
- {ok, _} = rebar_utils:sh(Script, []),
- ok
- end.
-
-
-deprecated(Key=compile_post_script) ->
- ?DEPRECATED(Key, {post_hooks, [{compile, "script"}]},
- "in a future build of rebar");
-deprecated(Key=clean_post_script) ->
- ?DEPRECATED(Key, {post_hooks, [{clean, "script"}]},
- "in a future build of rebar").
diff --git a/src/rebar_pre_script.erl b/src/rebar_pre_script.erl
deleted file mode 100644
index d79d662..0000000
--- a/src/rebar_pre_script.erl
+++ /dev/null
@@ -1,64 +0,0 @@
-%% -*- erlang-indent-level: 4;indent-tabs-mode: nil -*-
-%% ex: ts=4 sw=4 et
-%% -------------------------------------------------------------------
-%%
-%% rebar: Erlang Build Tools
-%%
-%% Copyright (c) 2009, 2010 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_pre_script).
-
--export([compile/2,
- clean/2]).
-
--include("rebar.hrl").
-
-%% ===================================================================
-%% Public API
-%% ===================================================================
-
-compile(Config, _) ->
- execute_pre_script(Config, compile_pre_script).
-
-clean(Config, _) ->
- execute_pre_script(Config, clean_pre_script).
-
-
-%% ===================================================================
-%% Internal functions
-%% ===================================================================
-
-execute_pre_script(Config, Key) ->
- case rebar_config:get_local(Config, Key, undefined) of
- undefined ->
- ok;
- Script ->
- deprecated(Key),
- {ok, _} = rebar_utils:sh(Script, []),
- ok
- end.
-
-deprecated(Key=compile_pre_script) ->
- ?DEPRECATED(Key, {pre_hooks, [{compile, "script"}]},
- "in a future build of rebar");
-deprecated(Key=clean_pre_script) ->
- ?DEPRECATED(Key, {pre_hooks, [{clean, "script"}]},
- "in a future build of rebar").
diff --git a/src/rebar_rel_utils.erl b/src/rebar_rel_utils.erl
index d3baf4d..0b14a28 100644
--- a/src/rebar_rel_utils.erl
+++ b/src/rebar_rel_utils.erl
@@ -80,7 +80,7 @@ get_rel_release_info(Name, Path) ->
get_rel_apps(RelFile) ->
case file:consult(RelFile) of
{ok, [{release, _, _, Apps}]} ->
- Apps;
+ make_proplist(Apps, []);
_ ->
?ABORT("Failed to parse ~s~n", [RelFile])
end.
@@ -106,3 +106,16 @@ get_previous_release_path() ->
OldVerPath ->
OldVerPath
end.
+
+%% ===================================================================
+%% Internal functions
+%% ===================================================================
+
+make_proplist([{_,_}=H|T], Acc) ->
+ make_proplist(T, [H|Acc]);
+make_proplist([H|T], Acc) ->
+ App = erlang:element(1, H),
+ Ver = erlang:element(2, H),
+ make_proplist(T, [{App,Ver}|Acc]);
+make_proplist([], Acc) ->
+ Acc.
diff --git a/src/rebar_reltool.erl b/src/rebar_reltool.erl
index 5e71814..72bfe49 100644
--- a/src/rebar_reltool.erl
+++ b/src/rebar_reltool.erl
@@ -302,7 +302,7 @@ execute_overlay([{template_wildcard, Wildcard, OutDir} | Rest], Vars, BaseDir, T
[{template, F, filename:join(OutDir, filename:basename(F))} | Acc0]
end,
NewInstrs = lists:foldl(Ifun, Rest, filelib:wildcard(Wildcard, BaseDir)),
- case length(NewInstrs) == length(Rest) of
+ case length(NewInstrs) =:= length(Rest) of
true ->
?WARN("template_wildcard: ~s did not match any files!\n", [Wildcard]);
false ->
diff --git a/src/rebar_upgrade.erl b/src/rebar_upgrade.erl
index 39b2c61..0bf0338 100644
--- a/src/rebar_upgrade.erl
+++ b/src/rebar_upgrade.erl
@@ -81,7 +81,8 @@ run_checks(OldVerPath, ReltoolFile) ->
true = rebar_utils:prop_check(filelib:is_dir(NamePath),
"Release directory doesn't exist (~p)~n", [NamePath]),
- {NewName, NewVer} = rebar_rel_utils:get_rel_release_info(Name, NamePath),
+ {NewName, NewVer} = NewNameAndVer =
+ rebar_rel_utils:get_rel_release_info(Name, NamePath),
{OldName, OldVer} = rebar_rel_utils:get_rel_release_info(Name, OldVerPath),
true = rebar_utils:prop_check(NewName == OldName,
@@ -93,7 +94,7 @@ run_checks(OldVerPath, ReltoolFile) ->
true = rebar_utils:prop_check(Ver == NewVer,
"Reltool and .rel versions do not match~n", []),
- {NewName, NewVer}.
+ NewNameAndVer.
setup(OldVerPath, NewName, NewVer, NameVer) ->
NewRelPath = filename:join([".", NewName]),
diff --git a/src/rebar_utils.erl b/src/rebar_utils.erl
index 792c54f..ebf6656 100644
--- a/src/rebar_utils.erl
+++ b/src/rebar_utils.erl
@@ -29,6 +29,7 @@
-export([get_cwd/0,
is_arch/1,
get_arch/0,
+ wordsize/0,
sh/2,
find_files/2,
now_str/0,
@@ -62,10 +63,19 @@ is_arch(ArchRegex) ->
end.
get_arch() ->
- Words = integer_to_list(8 * erlang:system_info(wordsize)),
+ Words = wordsize(),
erlang:system_info(otp_release) ++ "-"
++ erlang:system_info(system_architecture) ++ "-" ++ Words.
+wordsize() ->
+ try erlang:system_info({wordsize, external}) of
+ Val ->
+ integer_to_list(8 * Val)
+ catch
+ error:badarg ->
+ integer_to_list(8 * erlang:system_info(wordsize))
+ end.
+
%%
%% Options = [Option] -- defaults to [use_stdout, abort_on_error]
%% Option = ErrorOption | OutputOption | {cd, string()} | {env, Env}
diff --git a/src/rebar_xref.erl b/src/rebar_xref.erl
index e0f4547..c210486 100644
--- a/src/rebar_xref.erl
+++ b/src/rebar_xref.erl
@@ -61,54 +61,59 @@ xref(Config, _) ->
undefined_function_calls]),
%% Look for exports that are unused by anything
- case lists:member(exports_not_used, XrefChecks) of
- true ->
- check_exports_not_used(Config);
- false ->
- ok
- end,
+ ExportsNoWarn =
+ case lists:member(exports_not_used, XrefChecks) of
+ true ->
+ check_exports_not_used();
+ false ->
+ true
+ end,
%% Look for calls to undefined functions
- case lists:member(undefined_function_calls, XrefChecks) of
- true ->
- check_undefined_function_calls(Config);
- false ->
- ok
- end,
-
+ UndefNoWarn =
+ case lists:member(undefined_function_calls, XrefChecks) of
+ true ->
+ check_undefined_function_calls();
+ false ->
+ true
+ end,
%% Restore the original code path
true = code:set_path(OrigPath),
%% Stop xref
stopped = xref:stop(xref),
- ok.
+ case lists:all(fun(NoWarn) -> NoWarn end, [ExportsNoWarn, UndefNoWarn]) of
+ true ->
+ ok;
+ false ->
+ ?FAIL
+ end.
%% ===================================================================
%% Internal functions
%% ===================================================================
-check_exports_not_used(_Config) ->
+check_exports_not_used() ->
{ok, UnusedExports0} = xref:analyze(xref, exports_not_used),
UnusedExports = filter_away_ignored(UnusedExports0),
%% Report all the unused functions
display_mfas(UnusedExports, "is unused export (Xref)"),
- ok.
+ UnusedExports =:= [].
-check_undefined_function_calls(_Config) ->
+check_undefined_function_calls() ->
{ok, UndefinedCalls0} = xref:analyze(xref, undefined_function_calls),
UndefinedCalls =
- [{find_mfa_source(Caller), format_fa(Caller), format_mfa(Target)} ||
- {Caller, Target} <- UndefinedCalls0],
+ [{find_mfa_source(Caller), format_fa(Caller), format_mfa(Target)}
+ || {Caller, Target} <- UndefinedCalls0],
lists:foreach(
fun({{Source, Line}, FunStr, Target}) ->
?CONSOLE("~s:~w: Warning ~s calls undefined function ~s\n",
[Source, Line, FunStr, Target])
end, UndefinedCalls),
- ok.
-
+ UndefinedCalls =:= [].
code_path() ->
[P || P <- code:get_path(),