diff options
-rw-r--r-- | src/rebar_erlc_compiler.erl | 5 | ||||
-rw-r--r-- | src/rebar_prv_common_test.erl | 25 | ||||
-rw-r--r-- | test/rebar_compile_SUITE.erl | 66 | ||||
-rw-r--r-- | test/rebar_ct_SUITE.erl | 11 |
4 files changed, 89 insertions, 18 deletions
diff --git a/src/rebar_erlc_compiler.erl b/src/rebar_erlc_compiler.erl index 162ed07..3480cf6 100644 --- a/src/rebar_erlc_compiler.erl +++ b/src/rebar_erlc_compiler.erl @@ -304,7 +304,8 @@ needed_files(G, ErlOpts, Dir, OutDir, SourceFiles) -> TargetBase = target_base(OutDir, Source), Target = TargetBase ++ ".beam", AllOpts = [{outdir, filename:dirname(Target)} - ,{i, filename:join(Dir, "include")}] ++ ErlOpts, + ,{i, filename:join(Dir, "include")} + ,{i, Dir}] ++ ErlOpts, digraph:vertex(G, Source) > {Source, filelib:last_modified(Target)} orelse opts_changed(AllOpts, TargetBase) end, SourceFiles). @@ -503,7 +504,7 @@ internal_erl_compile(_Opts, Dir, Module, OutDir, ErlOpts) -> Target = target_base(OutDir, Module) ++ ".beam", ok = filelib:ensure_dir(Target), AllOpts = [{outdir, filename:dirname(Target)}] ++ ErlOpts ++ - [{i, filename:join(Dir, "include")}, return], + [{i, filename:join(Dir, "include")}, {i, Dir}, return], case compile:file(Module, AllOpts) of {ok, _Mod} -> ok; diff --git a/src/rebar_prv_common_test.erl b/src/rebar_prv_common_test.erl index 1136e08..4be50d8 100644 --- a/src/rebar_prv_common_test.erl +++ b/src/rebar_prv_common_test.erl @@ -281,7 +281,8 @@ inject_ct_state(State, [App|Rest], Acc) -> inject_ct_state(State, [], Acc) -> case inject(rebar_state:opts(State), State) of {error, _} = Error -> Error; - NewOpts -> {ok, {rebar_state:opts(State, NewOpts), lists:reverse(Acc)}} + NewOpts -> + {ok, {rebar_state:opts(State, NewOpts), lists:reverse(Acc)}} end. opts(Opts, Key, Default) -> @@ -380,12 +381,10 @@ maybe_inject_test_dir(State, AppAcc, [App|Rest], Dir) -> %% suite exists in but if the suite is in the app root directory %% the current compiler tries to compile all subdirs including priv %% instead copy only files ending in `.erl' and directories - %% ending in `_SUITE_data' into the `_build/PROFILE/extras' dir - {ok, RelAppDir} = rebar_file_utils:path_from_ancestor(rebar_app_info:dir(App), rebar_state:dir(State)), - ExtrasDir = filename:join([rebar_dir:base_dir(State), "extras", RelAppDir]), - ok = copy_bare_suites(Dir, ExtrasDir), - Opts = inject_test_dir(rebar_state:opts(State), ExtrasDir), - {rebar_state:opts(State, Opts), AppAcc}; + %% ending in `_SUITE_data' into the `_build/PROFILE/lib/APP' dir + ok = copy_bare_suites(Dir, rebar_app_info:out_dir(App)), + Opts = inject_test_dir(rebar_state:opts(State), rebar_app_info:out_dir(App)), + {rebar_state:opts(State, Opts), AppAcc ++ [App]}; {ok, Path} -> Opts = inject_test_dir(rebar_app_info:opts(App), Path), {State, AppAcc ++ [rebar_app_info:opts(App, Opts)] ++ Rest}; @@ -449,15 +448,23 @@ translate_suites(_State, [], Acc) -> lists:reverse(Acc); translate_suites(State, [{suite, Suite}|Rest], Acc) when is_integer(hd(Suite)) -> %% single suite Apps = rebar_state:project_apps(State), - translate_suites(State, Rest, [{suite, translate(State, Apps, Suite)}|Acc]); + translate_suites(State, Rest, [{suite, translate_suite(State, Apps, Suite)}|Acc]); translate_suites(State, [{suite, Suites}|Rest], Acc) -> %% multiple suites Apps = rebar_state:project_apps(State), - NewSuites = {suite, lists:map(fun(Suite) -> translate(State, Apps, Suite) end, Suites)}, + NewSuites = {suite, lists:map(fun(Suite) -> translate_suite(State, Apps, Suite) end, Suites)}, translate_suites(State, Rest, [NewSuites|Acc]); translate_suites(State, [Test|Rest], Acc) -> translate_suites(State, Rest, [Test|Acc]). +translate_suite(State, Apps, Suite) -> + Dirname = filename:dirname(Suite), + Basename = filename:basename(Suite), + case Dirname of + "." -> Suite; + _ -> filename:join([translate(State, Apps, Dirname), Basename]) + end. + translate(State, [App|Rest], Path) -> case rebar_file_utils:path_from_ancestor(Path, rebar_app_info:dir(App)) of {ok, P} -> filename:join([rebar_app_info:out_dir(App), P]); diff --git a/test/rebar_compile_SUITE.erl b/test/rebar_compile_SUITE.erl index cbf59ef..76a3de5 100644 --- a/test/rebar_compile_SUITE.erl +++ b/test/rebar_compile_SUITE.erl @@ -38,7 +38,9 @@ clean_all/1, override_deps/1, profile_override_deps/1, - deps_build_in_prod/1]). + deps_build_in_prod/1, + include_file_relative_to_working_directory/1, + include_file_in_src/1]). -include_lib("common_test/include/ct.hrl"). -include_lib("eunit/include/eunit.hrl"). @@ -59,7 +61,8 @@ all() -> deps_in_path, checkout_priority, highest_version_of_pkg_dep, parse_transform_test, erl_first_files_test, mib_test, umbrella_mib_first_test, only_default_transitive_deps, - clean_all, override_deps, profile_override_deps, deps_build_in_prod]. + clean_all, override_deps, profile_override_deps, deps_build_in_prod, + include_file_relative_to_working_directory, include_file_in_src]. groups() -> [{basic_app, [], [build_basic_app, paths_basic_app, clean_basic_app]}, @@ -1203,3 +1206,62 @@ deps_build_in_prod(Config) -> {ok, [{app, Name}, {dep, "asdf", <<"1.0.0">>}, {dep, PkgName}, {file, filename:join([AppDir, "_build", "default", "lib", "asdf", "randomfile"])}]} ). + +%% verify that the proper include path is defined +%% according the erlang doc which states: +%% If the filename File is absolute (possibly after variable substitution), +%% the include file with that name is included. Otherwise, the specified file +%% is searched for in the following directories, and in this order: +%% * The current working directory +%% * The directory where the module is being compiled +%% * The directories given by the include option +include_file_relative_to_working_directory(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]), + + Src = <<"-module(test).\n" +"\n" +"-include(\"include/test.hrl\").\n" +"\n" +"test() -> ?TEST_MACRO.\n" +"\n">>, + Include = <<"-define(TEST_MACRO, test).\n">>, + + ok = filelib:ensure_dir(filename:join([AppDir, "src", "dummy"])), + ok = file:write_file(filename:join([AppDir, "src", "test.erl"]), Src), + + ok = filelib:ensure_dir(filename:join([AppDir, "include", "dummy"])), + ok = file:write_file(filename:join([AppDir, "include", "test.hrl"]), Include), + + RebarConfig = [], + rebar_test_utils:run_and_check(Config, RebarConfig, + ["compile"], + {ok, [{app, Name}]}). + +include_file_in_src(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]), + + Src = <<"-module(test).\n" +"\n" +"-include(\"test.hrl\").\n" +"\n" +"test() -> ?TEST_MACRO.\n" +"\n">>, + Include = <<"-define(TEST_MACRO, test).\n">>, + + ok = filelib:ensure_dir(filename:join([AppDir, "src", "dummy"])), + ok = file:write_file(filename:join([AppDir, "src", "test.erl"]), Src), + + ok = file:write_file(filename:join([AppDir, "src", "test.hrl"]), Include), + + RebarConfig = [], + rebar_test_utils:run_and_check(Config, RebarConfig, + ["compile"], + {ok, [{app, Name}]}). diff --git a/test/rebar_ct_SUITE.erl b/test/rebar_ct_SUITE.erl index 183a1d0..94ab690 100644 --- a/test/rebar_ct_SUITE.erl +++ b/test/rebar_ct_SUITE.erl @@ -681,25 +681,26 @@ suite_at_app_root(Config) -> Opts = rebar_prv_common_test:translate_paths(NewState, T), Suite = proplists:get_value(suite, Opts), - Expected = filename:join([AppDir, "_build", "test", "extras", "apps", Name2, "app_root_SUITE"]), + Expected = filename:join([AppDir, "_build", "test", "lib", Name2, "app_root_SUITE"]), [Expected] = Suite, - TestHrl = filename:join([AppDir, "_build", "test", "extras", "apps", Name2, "app_root_SUITE.hrl"]), + TestHrl = filename:join([AppDir, "_build", "test", "lib", Name2, "app_root_SUITE.hrl"]), true = filelib:is_file(TestHrl), - TestBeam = filename:join([AppDir, "_build", "test", "extras", "apps", Name2, "app_root_SUITE.beam"]), + TestBeam = filename:join([AppDir, "_build", "test", "lib", Name2, "app_root_SUITE.beam"]), true = filelib:is_file(TestBeam), - DataDir = filename:join([AppDir, "_build", "test", "extras", "apps", Name2, "app_root_SUITE_data"]), + DataDir = filename:join([AppDir, "_build", "test", "lib", Name2, "app_root_SUITE_data"]), true = filelib:is_dir(DataDir), - DataFile = filename:join([AppDir, "_build", "test", "extras", "root_SUITE_data", "some_data.txt"]), + DataFile = filename:join([AppDir, "_build", "test", "lib", Name2, "app_root_SUITE_data", "some_data.txt"]), true = filelib:is_file(DataFile). %% this test probably only fails when this suite is run via rebar3 with the --cover flag data_dir_correct(Config) -> DataDir = ?config(data_dir, Config), Parts = filename:split(DataDir), + ct:pal(Parts), ["rebar_ct_SUITE_data","test","rebar","lib","test","_build"|_] = lists:reverse(Parts). cmd_label(Config) -> |