Pārlūkot izejas kodu

compile source from the symlinked directories under `_build` to

get correct compile paths included in module info
pull/249/head
alisdair sullivan pirms 10 gadiem
vecāks
revīzija
ab84fc89cc
5 mainītis faili ar 43 papildinājumiem un 12 dzēšanām
  1. +7
    -3
      src/rebar_erlc_compiler.erl
  2. +1
    -2
      src/rebar_prv_common_test.erl
  3. +7
    -5
      src/rebar_prv_compile.erl
  4. +1
    -2
      src/rebar_prv_eunit.erl
  5. +27
    -0
      test/rebar_compile_SUITE.erl

+ 7
- 3
src/rebar_erlc_compiler.erl Parādīt failu

@ -26,7 +26,8 @@
%% -------------------------------------------------------------------
-module(rebar_erlc_compiler).
-export([compile/3,
-export([compile/2,
compile/3,
clean/2]).
-include("rebar.hrl").
@ -79,6 +80,10 @@
%% 'old_inets'}]}.
%%
-spec compile(rebar_state:t(), file:name()) -> 'ok'.
compile(Config, Dir) ->
compile(Config, Dir, filename:join([Dir, "ebin"])).
-spec compile(rebar_state:t(), file:name(), file:name()) -> 'ok'.
compile(Config, Dir, OutDir) ->
rebar_base_compiler:run(Config,
@ -133,8 +138,7 @@ doterl_compile(State, Dir, ODir) ->
ErlOpts = rebar_utils:erl_opts(State),
doterl_compile(State, Dir, ODir, [], ErlOpts).
doterl_compile(Config, Dir, ODir, MoreSources, ErlOpts) ->
OutDir = filename:join(ODir, "ebin"),
doterl_compile(Config, Dir, OutDir, MoreSources, ErlOpts) ->
ErlFirstFilesConf = rebar_state:get(Config, erl_first_files, []),
?DEBUG("erl_opts ~p", [ErlOpts]),
%% Support the src_dirs option allowing multiple directories to

+ 1
- 2
src/rebar_prv_common_test.erl Parādīt failu

@ -370,7 +370,6 @@ compile_tests(State, TestApps, InDirs) ->
AppState
end,
ok = rebar_erlc_compiler:compile(replace_src_dirs(S, InDirs),
ec_cnv:to_list(rebar_app_info:dir(AppInfo)),
ec_cnv:to_list(rebar_app_info:out_dir(AppInfo)))
end,
lists:foreach(F, TestApps),
@ -382,7 +381,7 @@ compile_bare_tests(State, TestApps, InDirs) ->
%% compile just the `test` directory of the base dir
[] -> rebar_erlc_compiler:compile(replace_src_dirs(State, InDirs),
rebar_dir:get_cwd(),
rebar_dir:base_dir(State));
filename:join([rebar_dir:base_dir(State), "ebin"]));
%% already compiled `./test` so do nothing
_ -> ok
end.

+ 7
- 5
src/rebar_prv_compile.erl Parādīt failu

@ -71,7 +71,7 @@ build_app(State, AppInfo) ->
AppDir = rebar_app_info:dir(AppInfo),
OutDir = rebar_app_info:out_dir(AppInfo),
copy_app_dirs(AppDir, OutDir),
copy_app_dirs(State, AppDir, OutDir),
S = case rebar_app_info:state(AppInfo) of
undefined ->
@ -91,7 +91,7 @@ build_app(State, AppInfo) ->
compile(State, AppInfo) ->
?INFO("Compiling ~s", [rebar_app_info:name(AppInfo)]),
rebar_erlc_compiler:compile(State, ec_cnv:to_list(rebar_app_info:dir(AppInfo)), ec_cnv:to_list(rebar_app_info:out_dir(AppInfo))),
rebar_erlc_compiler:compile(State, ec_cnv:to_list(rebar_app_info:out_dir(AppInfo))),
case rebar_otp_app:compile(State, AppInfo) of
{ok, AppInfo1} ->
AppInfo1;
@ -108,7 +108,7 @@ handle_args(State) ->
Jobs = proplists:get_value(jobs, Args, ?DEFAULT_JOBS),
{ok, rebar_state:set(State, jobs, Jobs)}.
copy_app_dirs(OldAppDir, AppDir) ->
copy_app_dirs(State, OldAppDir, AppDir) ->
case ec_cnv:to_binary(filename:absname(OldAppDir)) =/=
ec_cnv:to_binary(filename:absname(AppDir)) of
true ->
@ -123,8 +123,10 @@ copy_app_dirs(OldAppDir, AppDir) ->
ok
end,
filelib:ensure_dir(filename:join(AppDir, "dummy")),
%% link to src to be adjacent to ebin is needed for R15 use of cover/xref
[symlink_or_copy(OldAppDir, AppDir, Dir) || Dir <- ["priv", "include", "src", "test"]];
%% link to src_dirs to be adjacent to ebin is needed for R15 use of cover/xref
ErlOpts = rebar_utils:erl_opts(State),
SrcDirs = proplists:get_value(src_dirs, ErlOpts, ["src"]),
[symlink_or_copy(OldAppDir, AppDir, Dir) || Dir <- ["priv", "include", "test"] ++ SrcDirs];
false ->
ok
end.

+ 1
- 2
src/rebar_prv_eunit.erl Parādīt failu

@ -137,7 +137,6 @@ compile_tests(State, TestApps) ->
AppState
end,
ok = rebar_erlc_compiler:compile(replace_src_dirs(S),
ec_cnv:to_list(rebar_app_info:dir(AppInfo)),
ec_cnv:to_list(rebar_app_info:out_dir(AppInfo)))
end,
lists:foreach(F, TestApps),
@ -149,7 +148,7 @@ compile_bare_tests(State, TestApps) ->
%% compile just the `test` directory of the base dir
[] -> rebar_erlc_compiler:compile(replace_src_dirs(State),
rebar_dir:get_cwd(),
rebar_dir:base_dir(State));
filename:join([rebar_dir:base_dir(State), "ebin"]));
%% already compiled `./test` so do nothing
_ -> ok
end.

+ 27
- 0
test/rebar_compile_SUITE.erl Parādīt failu

@ -9,6 +9,7 @@
build_release_apps/1,
build_checkout_apps/1,
build_checkout_deps/1,
build_all_srcdirs/1,
recompile_when_opts_change/1,
dont_recompile_when_opts_dont_change/1,
dont_recompile_yrl_or_xrl/1]).
@ -32,6 +33,7 @@ init_per_testcase(_, Config) ->
all() ->
[build_basic_app, build_release_apps,
build_checkout_apps, build_checkout_deps,
build_all_srcdirs,
recompile_when_opts_change, dont_recompile_when_opts_dont_change,
dont_recompile_yrl_or_xrl].
@ -94,6 +96,31 @@ build_checkout_deps(Config) ->
Loaded = application:loaded_applications(),
{_, _, Vsn2} = lists:keyfind(list_to_atom(Name2), 1, Loaded).
build_all_srcdirs(Config) ->
AppDir = ?config(apps, Config),
RebarConfig = [{erl_opts, [{src_dirs, ["src", "extra"]}]}],
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]),
ExtraSrc = <<"-module(extra_src).\n"
"-export([ok/0]).\n"
"ok() -> ok.\n">>,
ok = filelib:ensure_dir(filename:join([AppDir, "extra", "dummy"])),
ok = file:write_file(filename:join([AppDir, "extra", "extra_src.erl"]), ExtraSrc),
rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], {ok, [{app, Name}]}),
%% check a beam corresponding to the src in the extra src_dir exists in ebin
EbinDir = filename:join([AppDir, "_build", "default", "lib", Name, "ebin"]),
true = filelib:is_file(filename:join([EbinDir, "extra_src.beam"])),
%% check the extra src_dir was linked into the _build dir
true = filelib:is_dir(filename:join([AppDir, "_build", "default", "lib", Name, "extra"])).
recompile_when_opts_change(Config) ->
AppDir = ?config(apps, Config),

Notiek ielāde…
Atcelt
Saglabāt