summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/rebar_erlc_compiler.erl29
-rw-r--r--src/rebar_otp_app.erl22
-rw-r--r--src/rebar_prv_dialyzer.erl6
-rw-r--r--src/rebar_templater.erl31
-rw-r--r--test/rebar_compile_SUITE.erl14
-rw-r--r--test/rebar_eunit_SUITE.erl6
-rw-r--r--test/rebar_new_SUITE.erl28
-rw-r--r--test/rebar_resource_SUITE.erl3
-rw-r--r--test/rebar_xref_SUITE.erl19
9 files changed, 89 insertions, 69 deletions
diff --git a/src/rebar_erlc_compiler.erl b/src/rebar_erlc_compiler.erl
index c757511..a113fc4 100644
--- a/src/rebar_erlc_compiler.erl
+++ b/src/rebar_erlc_compiler.erl
@@ -256,24 +256,21 @@ needs_compile(Source, Target, Opts, Parents) ->
source_changed(TargetLastMod, I) -> TargetLastMod < filelib:last_modified(I).
-opts_changed(Opts, Target) ->
- Basename = filename:basename(Target, ".beam"),
- Dirname = filename:dirname(Target),
- ObjectFile = filename:join([Dirname, Basename]),
- _ = purge(list_to_atom(Basename)),
- case code:load_abs(ObjectFile) of
- {module, Mod} ->
- Compile = Mod:module_info(compile),
- lists:sort(Opts) =/= lists:sort(proplists:get_value(options,
- Compile));
- {error, nofile} -> false
+opts_changed(NewOpts, Target) ->
+ case compile_info(Target) of
+ {ok, Opts} -> lists:sort(Opts) =/= lists:sort(NewOpts);
+ _ -> true
end.
-purge(Mod) ->
- %% remove old code if necessary
- _ = code:purge(Mod),
- %% move current code to old
- _ = code:delete(Mod).
+compile_info(Target) ->
+ case beam_lib:chunks(Target, [compile_info]) of
+ {ok, {_mod, Chunks}} ->
+ CompileInfo = proplists:get_value(compile_info, Chunks, []),
+ {ok, proplists:get_value(options, CompileInfo, [])};
+ {error, beam_lib, Reason} ->
+ ?WARN("Couldn't read debug info from ~p for reason: ~p", [Target, Reason]),
+ {error, Reason}
+ end.
check_erlcinfo(_Config, #erlcinfo{vsn=?ERLCINFO_VSN}) ->
ok;
diff --git a/src/rebar_otp_app.erl b/src/rebar_otp_app.erl
index e850e58..2b5f682 100644
--- a/src/rebar_otp_app.erl
+++ b/src/rebar_otp_app.erl
@@ -166,23 +166,15 @@ ebin_modules(App, Dir) ->
[rebar_utils:beam_to_mod(N) || N <- Filtered].
beam_src(Beam) ->
- try
- Mod = list_to_atom(filename:basename(Beam, ".beam")),
- _ = purge(Mod),
- {module, Mod} = code:load_abs(filename:rootname(Beam, ".beam")),
- Compile = Mod:module_info(compile),
- proplists:get_value(source, Compile, [])
- catch
- error:undef -> [];
- error:nofile -> []
+ case beam_lib:chunks(Beam, [compile_info]) of
+ {ok, {_mod, Chunks}} ->
+ CompileInfo = proplists:get_value(compile_info, Chunks, []),
+ proplists:get_value(source, CompileInfo, []);
+ {error, beam_lib, Reason} ->
+ ?WARN("Couldn't read debug info from ~p for reason: ~p", [Beam, Reason]),
+ []
end.
-purge(Mod) ->
- %% remove old code if necessary
- _ = code:purge(Mod),
- %% move current code to old
- _ = code:delete(Mod).
-
ensure_registered(AppData) ->
case lists:keyfind(registered, 1, AppData) of
false ->
diff --git a/src/rebar_prv_dialyzer.erl b/src/rebar_prv_dialyzer.erl
index 4b6812f..e7275c7 100644
--- a/src/rebar_prv_dialyzer.erl
+++ b/src/rebar_prv_dialyzer.erl
@@ -143,6 +143,8 @@ get_plt_files([AppName | DepApps], Apps, PltApps, Files) ->
get_plt_files(DepApps, Apps, PltApps, Files);
false ->
{DepApps2, Files2} = app_name_to_info(AppName),
+ ?DEBUG("~s dependencies: ~p", [AppName, DepApps2]),
+ ?DEBUG("~s files: ~p", [AppName, Files2]),
DepApps3 = DepApps2 ++ DepApps,
Files3 = Files2 ++ Files,
get_plt_files(DepApps3, Apps, [AppName | PltApps], Files3)
@@ -191,6 +193,7 @@ search_ebin(AppName) ->
ebin_to_info(EbinDir, AppName) ->
AppFile = filename:join(EbinDir, atom_to_list(AppName) ++ ".app"),
+ ?DEBUG("Consulting app file ~p", [AppFile]),
case file:consult(AppFile) of
{ok, [{application, AppName, AppDetails}]} ->
DepApps = proplists:get_value(applications, AppDetails, []),
@@ -247,7 +250,6 @@ check_plt(State, Plt, OldList, FilesList) ->
{CheckWarnings, State2} = check_plt(State1, Plt, sets:to_list(Check)),
Add = sets:subtract(Files, Old),
{AddWarnings, State3} = add_plt(State2, Plt, sets:to_list(Add)),
- ?DEBUG("~p", [[RemWarnings, CheckWarnings, AddWarnings]]),
{RemWarnings + CheckWarnings + AddWarnings, State3}.
remove_plt(State, _Plt, []) ->
@@ -366,6 +368,7 @@ run_dialyzer(State, Opts) ->
Opts2 = [{warnings, WarningsList},
{check_plt, false} |
Opts],
+ ?DEBUG("Running dialyzer with options: ~p~n", [Opts2]),
{Unknowns, Warnings} = format_warnings(dialyzer:run(Opts2)),
_ = [?CONSOLE("~s", [Unknown]) || Unknown <- Unknowns],
_ = [?CONSOLE("~s", [Warning]) || Warning <- Warnings],
@@ -374,6 +377,7 @@ run_dialyzer(State, Opts) ->
Opts2 = [{warnings, no_warnings()},
{check_plt, false} |
Opts],
+ ?DEBUG("Running dialyzer with options: ~p~n", [Opts2]),
_ = dialyzer:run(Opts2),
{0, State}
end.
diff --git a/src/rebar_templater.erl b/src/rebar_templater.erl
index edfe3bd..588f5b2 100644
--- a/src/rebar_templater.erl
+++ b/src/rebar_templater.erl
@@ -132,14 +132,41 @@ override_vars([{Var, Default, Doc} | Rest], General) ->
%% Default variables, generated dynamically.
default_variables() ->
+ {DefaultAuthor, DefaultEmail} = default_author_and_email(),
{{Y,M,D},{H,Min,S}} = calendar:universal_time(),
[{date, lists:flatten(io_lib:format("~4..0w-~2..0w-~2..0w",[Y,M,D]))},
{datetime, lists:flatten(io_lib:format("~4..0w-~2..0w-~2..0wT~2..0w:~2..0w:~2..0w+00:00",[Y,M,D,H,Min,S]))},
- {author_name, "Anonymous"},
- {author_email, "anonymous@example.org"},
+ {author_name, DefaultAuthor},
+ {author_email, DefaultEmail},
{copyright_year, integer_to_list(Y)},
{apps_dir, "apps", "Directory where applications will be created if needed"}].
+default_author_and_email() ->
+ %% See if we can get a git user and email to use as defaults
+ case rebar_utils:sh("git config --global user.name", []) of
+ {ok, Name} ->
+ case rebar_utils:sh("git config --global user.email", []) of
+ {ok, Email} ->
+ {string:strip(Name, both, $\n), string:strip(Email, both, $\n)};
+ {error, _} ->
+ %% Use neither if one doesn't exist
+ {"Anonymous", "anonymous@example.org"}
+ end;
+ {error, _} ->
+ %% Ok, try mecurial
+ case rebar_utils:sh("hg showconfig ui.username", []) of
+ {ok, NameEmail} ->
+ case re:run(NameEmail, [{capture, [1,2], list}]) of
+ {match, [Name, Email]} ->
+ {Name, Email};
+ _ ->
+ {"Anonymous", "anonymous@example.org"}
+ end;
+ {error, _} ->
+ {"Anonymous", "anonymous@example.org"}
+ end
+ end.
+
%% Load variable definitions from the 'Globals' file in the home template
%% directory
global_variables(State) ->
diff --git a/test/rebar_compile_SUITE.erl b/test/rebar_compile_SUITE.erl
index 368ba98..b42b6b7 100644
--- a/test/rebar_compile_SUITE.erl
+++ b/test/rebar_compile_SUITE.erl
@@ -11,8 +11,7 @@
build_checkout_deps/1,
recompile_when_opts_change/1,
dont_recompile_when_opts_dont_change/1,
- dont_recompile_yrl_or_xrl/1,
- purge_before_load/1]).
+ dont_recompile_yrl_or_xrl/1]).
-include_lib("common_test/include/ct.hrl").
-include_lib("eunit/include/eunit.hrl").
@@ -34,7 +33,7 @@ all() ->
[build_basic_app, build_release_apps,
build_checkout_apps, build_checkout_deps,
recompile_when_opts_change, dont_recompile_when_opts_dont_change,
- dont_recompile_yrl_or_xrl, purge_before_load].
+ dont_recompile_yrl_or_xrl].
build_basic_app(Config) ->
AppDir = ?config(apps, Config),
@@ -185,12 +184,3 @@ dont_recompile_yrl_or_xrl(Config) ->
?assert(ModTime == NewModTime).
-purge_before_load(Config) ->
- AppDir = ?config(apps, Config),
-
- Name = rebar_test_utils:create_random_name("app1_"),
- Vsn = rebar_test_utils:create_random_vsn(),
- rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
-
- Tasks = ["do", "compile,compile,compile"],
- rebar_test_utils:run_and_check(Config, [], Tasks, {ok, [{app, Name}]}).
diff --git a/test/rebar_eunit_SUITE.erl b/test/rebar_eunit_SUITE.erl
index 190fbfa..d2d8608 100644
--- a/test/rebar_eunit_SUITE.erl
+++ b/test/rebar_eunit_SUITE.erl
@@ -21,7 +21,7 @@ end_per_suite(_Config) ->
ok.
init_per_testcase(_, Config) ->
- rebar_test_utils:init_rebar_state(Config).
+ rebar_test_utils:init_rebar_state(Config, "eunit_").
all() ->
[test_basic_app].
@@ -29,9 +29,9 @@ all() ->
test_basic_app(Config) ->
AppDir = ?config(apps, Config),
- Name = rebar_test_utils:create_random_name("eunit_"),
+ Name = rebar_test_utils:create_random_name("basic_"),
Vsn = rebar_test_utils:create_random_vsn(),
rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
-
+
RebarConfig = [{erl_opts, [{d, some_define}]}],
rebar_test_utils:run_and_check(Config, RebarConfig, ["eunit"], {ok, [{app, Name}]}).
diff --git a/test/rebar_new_SUITE.erl b/test/rebar_new_SUITE.erl
index 6b57b74..e382ae4 100644
--- a/test/rebar_new_SUITE.erl
+++ b/test/rebar_new_SUITE.erl
@@ -6,7 +6,7 @@
-include_lib("common_test/include/ct.hrl").
-include_lib("eunit/include/eunit.hrl").
-all() -> [app].
+all() -> [app, app_with_fallbacks].
init_per_testcase(Case, Config0) ->
@@ -32,6 +32,10 @@ mock_empty_escript_templates() ->
meck:expect(rebar_utils, escript_foldl, fun(_,_,_) -> {ok, []} end).
app(Config) ->
+ meck:expect(rebar_utils, sh, fun("git config --global user.name", _) -> {ok, "gitname"};
+ ("git config --global user.email", _) -> {ok, "git@email.com"}
+ end),
+
Name = ?config(name, Config),
rebar_test_utils:run_and_check(
Config, [],
@@ -40,7 +44,7 @@ app(Config) ->
),
validate_files(
Config, Name,
- [{"LICENSE", ["some_name", "anonymous@example.org"]},
+ [{"LICENSE", ["some_name", "git@email.com"]},
{"README.md", [Name]},
{".gitignore", []},
{"rebar.config", []},
@@ -49,6 +53,26 @@ app(Config) ->
{filename:join(["src", Name++"_app.erl"]), [Name]}
]).
+app_with_fallbacks(Config) ->
+ meck:expect(rebar_utils, sh, fun(_, _) -> {error, fallback} end),
+
+ Name = ?config(name, Config),
+ rebar_test_utils:run_and_check(
+ Config, [],
+ ["new", "test_app", Name],
+ {ok, []}
+ ),
+ validate_files(
+ Config, Name,
+ [{"LICENSE", ["Anonymous", "anonymous@example.org"]},
+ {"README.md", [Name]},
+ {".gitignore", []},
+ {"rebar.config", []},
+ {filename:join(["src", Name++".app.src"]), [Name]},
+ {filename:join(["src", Name++"_sup.erl"]), [Name]},
+ {filename:join(["src", Name++"_app.erl"]), [Name]}
+ ]).
+
validate_files(_Config, Name, Checks) ->
[begin
Path = filename:join([Name, File]),
diff --git a/test/rebar_resource_SUITE.erl b/test/rebar_resource_SUITE.erl
index 088ab67..95263c7 100644
--- a/test/rebar_resource_SUITE.erl
+++ b/test/rebar_resource_SUITE.erl
@@ -17,6 +17,9 @@ init_per_group(Name, Config) ->
[{type, Name},
{resource, {Name, "https://example.org/user/app", "vsn"}} | Config].
+end_per_group(_, _Config) ->
+ ok.
+
%% Changing the resource type is seen as an upgrade
init_per_testcase(change_type_upgrade, Config) ->
Type = ?config(type, Config),
diff --git a/test/rebar_xref_SUITE.erl b/test/rebar_xref_SUITE.erl
index 1b1d6d7..b2438cf 100644
--- a/test/rebar_xref_SUITE.erl
+++ b/test/rebar_xref_SUITE.erl
@@ -31,7 +31,6 @@ end_per_suite(_Config) ->
init_per_testcase(Case, Config) ->
UpdConfig = rebar_test_utils:init_rebar_state(Config),
AppDir = ?config(apps, UpdConfig),
- {ok, OrigDir} = file:get_cwd(),
file:set_cwd(AppDir),
Name = rebar_test_utils:create_random_name("xrefapp_"),
Vsn = rebar_test_utils:create_random_vsn(),
@@ -43,25 +42,9 @@ init_per_testcase(Case, Config) ->
undefined_function_calls,undefined_functions,
exports_not_used,locals_not_used]}],
[{app_name, Name},
- {rebar_config, RebarConfig},
- {orig_dir, OrigDir} | UpdConfig].
+ {rebar_config, RebarConfig} | UpdConfig].
end_per_testcase(_, Config) ->
- ?debugMsg("End test case cleanup"),
- AppDir = ?config(apps, Config),
- OrigDir = ?config(orig_dir, Config),
- %% Code path cleanup because we set the CWD to the `AppDir' prior
- %% to launching rebar and these paths make it into the code path
- %% before the xref module executes so they don't get cleaned up
- %% automatically after the xref run. Only have to do this because
- %% we are about to remove the directory and there may be
- %% subsequent test cases that error out when the code path tries
- %% to include one of these soon-to-be nonexistent directories.
- Name = ?config(app_name, Config),
- EbinDir = filename:join([AppDir, "_build", "default" "lib", Name, "ebin"]),
- true = code:del_path(EbinDir),
- file:set_cwd(OrigDir),
- ec_file:remove(AppDir, [recursive]),
ok.
all() ->