From 0b18b208e221adc8c5095a670313395615bae766 Mon Sep 17 00:00:00 2001 From: Tuncer Ayaz Date: Sun, 5 Aug 2012 19:56:27 +0200 Subject: Only print absolute filename if not in base_dir --- src/rebar_base_compiler.erl | 33 +++++++++++-------- src/rebar_core.erl | 5 +-- src/rebar_erlc_compiler.erl | 78 ++++++++++++++++++++++----------------------- src/rebar_lfe_compiler.erl | 5 +-- src/rebar_port_compiler.erl | 25 +++++++++------ src/rebar_utils.erl | 10 +++++- 6 files changed, 85 insertions(+), 71 deletions(-) (limited to 'src') diff --git a/src/rebar_base_compiler.erl b/src/rebar_base_compiler.erl index c2ebf51..e83a7aa 100644 --- a/src/rebar_base_compiler.erl +++ b/src/rebar_base_compiler.erl @@ -29,8 +29,7 @@ -include("rebar.hrl"). -export([run/4, run/7, run/8, - ok_tuple/2, error_tuple/4]). - + ok_tuple/3, error_tuple/5]). %% =================================================================== %% Public API @@ -80,11 +79,12 @@ run(Config, FirstFiles, SourceDir, SourceExt, TargetDir, TargetExt, simple_compile_wrapper(S, Target, Compile3Fn, C, CheckLastMod) end). -ok_tuple(Source, Ws) -> - {ok, format_warnings(Source, Ws)}. +ok_tuple(Config, Source, Ws) -> + {ok, format_warnings(Config, Source, Ws)}. -error_tuple(Source, Es, Ws, Opts) -> - {error, format_errors(Source, Es), format_warnings(Source, Ws, Opts)}. +error_tuple(Config, Source, Es, Ws, Opts) -> + {error, format_errors(Config, Source, Es), + format_warnings(Config, Source, Ws, Opts)}. %% =================================================================== %% Internal functions @@ -211,18 +211,18 @@ compile_worker(QueuePid, Config, CompileFn) -> ok end. -format_errors(Source, Errors) -> - format_errors(Source, "", Errors). +format_errors(Config, Source, Errors) -> + format_errors(Config, Source, "", Errors). -format_warnings(Source, Warnings) -> - format_warnings(Source, Warnings, []). +format_warnings(Config, Source, Warnings) -> + format_warnings(Config, Source, Warnings, []). -format_warnings(Source, Warnings, Opts) -> +format_warnings(Config, Source, Warnings, Opts) -> Prefix = case lists:member(warnings_as_errors, Opts) of true -> ""; false -> "Warning: " end, - format_errors(Source, Prefix, Warnings). + format_errors(Config, Source, Prefix, Warnings). maybe_report([{error, {error, _Es, _Ws}=ErrorsAndWarnings}, {source, _}]) -> maybe_report(ErrorsAndWarnings); @@ -235,8 +235,13 @@ maybe_report(_) -> report(Messages) -> lists:foreach(fun(Msg) -> io:format("~s", [Msg]) end, Messages). -format_errors(Source, Extra, Errors) -> - AbsSource = filename:absname(Source), +format_errors(Config, Source, Extra, Errors) -> + AbsSource = case rebar_utils:processing_base_dir(Config) of + true -> + Source; + false -> + filename:absname(Source) + end, [[format_error(AbsSource, Extra, Desc) || Desc <- Descs] || {_, Descs} <- Errors]. diff --git a/src/rebar_core.erl b/src/rebar_core.erl index dd4a9be..a150ef2 100644 --- a/src/rebar_core.erl +++ b/src/rebar_core.erl @@ -242,16 +242,13 @@ remember_cwd_subdir(Cwd, Subdirs) -> maybe_load_local_config(Dir, ParentConfig) -> %% We need to ensure we don't overwrite custom %% config when we are dealing with base_dir. - case processing_base_dir(ParentConfig, Dir) of + case rebar_utils:processing_base_dir(ParentConfig, Dir) of true -> ParentConfig; false -> rebar_config:new(ParentConfig) end. -processing_base_dir(Config, Dir) -> - Dir == rebar_config:get_xconf(Config, base_dir). - %% %% Given a list of directories and a set of previously processed directories, %% process each one we haven't seen yet diff --git a/src/rebar_erlc_compiler.erl b/src/rebar_erlc_compiler.erl index f3dd5b6..2435884 100644 --- a/src/rebar_erlc_compiler.erl +++ b/src/rebar_erlc_compiler.erl @@ -87,7 +87,7 @@ compile(Config, _AppFile) -> fun compile_mib/3), doterl_compile(Config, "ebin"). --spec clean(Config::rebar_config:config(), AppFile::file:filename()) -> 'ok'. +-spec clean(rebar_config:config(), file:filename()) -> 'ok'. clean(_Config, _AppFile) -> MibFiles = rebar_utils:find_files("mibs", "^.*\\.mib\$"), MIBs = [filename:rootname(filename:basename(MIB)) || MIB <- MibFiles], @@ -217,8 +217,7 @@ is_lib_avail(Config, DictKey, Mod, Hrl, Name) -> {Config, IsAvail} end. --spec doterl_compile(Config::rebar_config:config(), - OutDir::file:filename()) -> 'ok'. +-spec doterl_compile(rebar_config:config(), file:filename()) -> 'ok'. doterl_compile(Config, OutDir) -> doterl_compile(Config, OutDir, []). @@ -258,7 +257,7 @@ doterl_compile(Config, OutDir, MoreSources) -> true = code:add_path(filename:absname("ebin")), rebar_base_compiler:run(Config, NewFirstErls, OtherErls, fun(S, C) -> - internal_erl_compile(S, C, OutDir, ErlOpts) + internal_erl_compile(C, S, OutDir, ErlOpts) end), true = code:set_path(CurrPath), ok. @@ -268,15 +267,15 @@ doterl_compile(Config, OutDir, MoreSources) -> %% Internal functions %% =================================================================== --spec include_path(Source::file:filename(), - Config::rebar_config:config()) -> [file:filename(), ...]. +-spec include_path(file:filename(), + rebar_config:config()) -> [file:filename(), ...]. include_path(Source, Config) -> ErlOpts = rebar_config:get(Config, erl_opts, []), ["include", filename:dirname(Source)] ++ proplists:get_all_values(i, ErlOpts). --spec inspect(Source::file:filename(), - IncludePath::[file:filename(), ...]) -> {string(), [string()]}. +-spec inspect(file:filename(), + [file:filename(), ...]) -> {string(), [string()]}. inspect(Source, IncludePath) -> ModuleDefault = filename:basename(Source, ".erl"), case epp:open(Source, IncludePath) of @@ -287,8 +286,8 @@ inspect(Source, IncludePath) -> {ModuleDefault, []} end. --spec inspect_epp(Epp::pid(), Source::file:filename(), Module::file:filename(), - Includes::[string()]) -> {string(), [string()]}. +-spec inspect_epp(pid(), file:filename(), file:filename(), + [string()]) -> {string(), [string()]}. inspect_epp(Epp, Source, Module, Includes) -> case epp:parse_erl_form(Epp) of {ok, {attribute, _, module, ModInfo}} -> @@ -323,18 +322,16 @@ inspect_epp(Epp, Source, Module, Includes) -> inspect_epp(Epp, Source, Module, Includes) end. --spec needs_compile(Source::file:filename(), Target::file:filename(), - Hrls::[string()]) -> boolean(). +-spec needs_compile(file:filename(), file:filename(), + [string()]) -> boolean(). needs_compile(Source, Target, Hrls) -> TargetLastMod = filelib:last_modified(Target), lists:any(fun(I) -> TargetLastMod < filelib:last_modified(I) end, [Source] ++ Hrls). --spec internal_erl_compile(Source::file:filename(), - Config::rebar_config:config(), - Outdir::file:filename(), - ErlOpts::list()) -> 'ok' | 'skipped'. -internal_erl_compile(Source, Config, Outdir, ErlOpts) -> +-spec internal_erl_compile(rebar_config:config(), file:filename(), + file:filename(), list()) -> 'ok' | 'skipped'. +internal_erl_compile(Config, Source, Outdir, ErlOpts) -> %% Determine the target name and includes list by inspecting the source file {Module, Hrls} = inspect(Source, include_path(Source, Config)), @@ -352,17 +349,18 @@ internal_erl_compile(Source, Config, Outdir, ErlOpts) -> {ok, _Mod} -> ok; {ok, _Mod, Ws} -> - rebar_base_compiler:ok_tuple(Source, Ws); + rebar_base_compiler:ok_tuple(Config, Source, Ws); {error, Es, Ws} -> - rebar_base_compiler:error_tuple(Source, Es, Ws, Opts) + rebar_base_compiler:error_tuple(Config, Source, + Es, Ws, Opts) end; false -> skipped end. --spec compile_mib(Source::file:filename(), Target::file:filename(), - Config::rebar_config:config()) -> 'ok'. -compile_mib(Source, Target, Config) -> +-spec compile_mib(rebar_config:config(), file:filename(), + file:filename()) -> 'ok'. +compile_mib(Config, Source, Target) -> ok = rebar_utils:ensure_dir(Target), ok = rebar_utils:ensure_dir(filename:join("include", "dummy.hrl")), Opts = [{outdir, "priv/mibs"}, {i, ["priv/mibs"]}] ++ @@ -378,30 +376,31 @@ compile_mib(Source, Target, Config) -> ?FAIL end. --spec compile_xrl(Source::file:filename(), Target::file:filename(), - Config::rebar_config:config()) -> 'ok'. +-spec compile_xrl(file:filename(), file:filename(), + rebar_config:config()) -> 'ok'. compile_xrl(Source, Target, Config) -> Opts = [{scannerfile, Target} | rebar_config:get(Config, xrl_opts, [])], - compile_xrl_yrl(Source, Target, Opts, leex). + compile_xrl_yrl(Config, Source, Target, Opts, leex). --spec compile_yrl(Source::file:filename(), Target::file:filename(), - Config::rebar_config:config()) -> 'ok'. +-spec compile_yrl(file:filename(), file:filename(), + rebar_config:config()) -> 'ok'. compile_yrl(Source, Target, Config) -> Opts = [{parserfile, Target} | rebar_config:get(Config, yrl_opts, [])], - compile_xrl_yrl(Source, Target, Opts, yecc). + compile_xrl_yrl(Config, Source, Target, Opts, yecc). --spec compile_xrl_yrl(Source::file:filename(), Target::file:filename(), - Opts::list(), Mod::atom()) -> 'ok'. -compile_xrl_yrl(Source, Target, Opts, Mod) -> +-spec compile_xrl_yrl(rebar_config:config(), file:filename(), + file:filename(), list(), module()) -> 'ok'. +compile_xrl_yrl(Config, Source, Target, Opts, Mod) -> case needs_compile(Source, Target, []) of true -> case Mod:file(Source, Opts ++ [{return, true}]) of {ok, _} -> ok; {ok, _Mod, Ws} -> - rebar_base_compiler:ok_tuple(Source, Ws); + rebar_base_compiler:ok_tuple(Config, Source, Ws); {error, Es, Ws} -> - rebar_base_compiler:error_tuple(Source, Es, Ws, Opts) + rebar_base_compiler:error_tuple(Config, Source, + Es, Ws, Opts) end; false -> skipped @@ -413,21 +412,20 @@ gather_src([Dir|Rest], Srcs) -> gather_src(Rest, Srcs ++ rebar_utils:find_files(Dir, ".*\\.erl\$")). --spec dirs(Dir::file:filename()) -> [file:filename()]. +-spec dirs(file:filename()) -> [file:filename()]. dirs(Dir) -> [F || F <- filelib:wildcard(filename:join([Dir, "*"])), filelib:is_dir(F)]. --spec delete_dir(Dir::file:filename(), - Subdirs::[string()]) -> 'ok' | {'error', atom()}. +-spec delete_dir(file:filename(), [string()]) -> 'ok' | {'error', atom()}. delete_dir(Dir, []) -> file:del_dir(Dir); delete_dir(Dir, Subdirs) -> lists:foreach(fun(D) -> delete_dir(D, dirs(D)) end, Subdirs), file:del_dir(Dir). --spec compile_priority(File::file:filename()) -> 'normal' | 'behaviour' | - 'callback' | - 'parse_transform'. +-spec compile_priority(file:filename()) -> 'normal' | 'behaviour' | + 'callback' | + 'parse_transform'. compile_priority(File) -> case epp_dodger:parse_file(File) of {error, _} -> @@ -462,7 +460,7 @@ compile_priority(File) -> %% %% Ensure all files in a list are present and abort if one is missing %% --spec check_files(FileList::[file:filename()]) -> [file:filename()]. +-spec check_files([file:filename()]) -> [file:filename()]. check_files(FileList) -> [check_file(F) || F <- FileList]. diff --git a/src/rebar_lfe_compiler.erl b/src/rebar_lfe_compiler.erl index 4011798..d288ca5 100644 --- a/src/rebar_lfe_compiler.erl +++ b/src/rebar_lfe_compiler.erl @@ -63,9 +63,10 @@ compile_lfe(Source, _Target, Config) -> ++ rebar_config:get_list(Config, erl_opts, []), case lfe_comp:file(Source, Opts) of {ok, _Mod, Ws} -> - rebar_base_compiler:ok_tuple(Source, Ws); + rebar_base_compiler:ok_tuple(Config, Source, Ws); {error, Es, Ws} -> - rebar_base_compiler:error_tuple(Source, Es, Ws, Opts); + rebar_base_compiler:error_tuple(Config, Source, + Es, Ws, Opts); _ -> ?FAIL end diff --git a/src/rebar_port_compiler.erl b/src/rebar_port_compiler.erl index 38d77e4..644d8c2 100644 --- a/src/rebar_port_compiler.erl +++ b/src/rebar_port_compiler.erl @@ -100,7 +100,7 @@ compile(Config, _AppFile) -> SharedEnv = rebar_config:get_env(Config, ?MODULE), %% Compile each of the sources - NewBins = compile_sources(Specs, SharedEnv), + NewBins = compile_sources(Config, Specs, SharedEnv), %% Make sure that the target directories exist ?INFO("Using specs ~p\n", [Specs]), @@ -177,16 +177,16 @@ replace_extension(File, OldExt, NewExt) -> %% == compile and link == %% -compile_sources(Specs, SharedEnv) -> +compile_sources(Config, Specs, SharedEnv) -> lists:foldl( fun(#spec{sources=Sources, type=Type, opts=Opts}, NewBins) -> Env = proplists:get_value(env, Opts, SharedEnv), - compile_each(Sources, Type, Env, NewBins) + compile_each(Config, Sources, Type, Env, NewBins) end, [], Specs). -compile_each([], _Type, _Env, NewBins) -> +compile_each(_Config, [], _Type, _Env, NewBins) -> lists:reverse(NewBins); -compile_each([Source | Rest], Type, Env, NewBins) -> +compile_each(Config, [Source | Rest], Type, Env, NewBins) -> Ext = filename:extension(Source), Bin = replace_extension(Source, Ext, ".o"), case needs_compile(Source, Bin) of @@ -194,17 +194,22 @@ compile_each([Source | Rest], Type, Env, NewBins) -> Template = select_compile_template(Type, compiler(Ext)), Cmd = expand_command(Template, Env, Source, Bin), ShOpts = [{env, Env}, return_on_error, {use_stdout, false}], - exec_compiler(Source, Cmd, ShOpts), - compile_each(Rest, Type, Env, [Bin | NewBins]); + exec_compiler(Config, Source, Cmd, ShOpts), + compile_each(Config, Rest, Type, Env, [Bin | NewBins]); false -> ?INFO("Skipping ~s\n", [Source]), - compile_each(Rest, Type, Env, NewBins) + compile_each(Config, Rest, Type, Env, NewBins) end. -exec_compiler(Source, Cmd, ShOpts) -> +exec_compiler(Config, Source, Cmd, ShOpts) -> case rebar_utils:sh(Cmd, ShOpts) of {error, {_RC, RawError}} -> - AbsSource = filename:absname(Source), + AbsSource = case rebar_utils:processing_base_dir(Config) of + true -> + Source; + false -> + filename:absname(Source) + end, ?CONSOLE("Compiling ~s\n", [AbsSource]), Error = re:replace(RawError, Source, AbsSource, [{return, list}, global]), diff --git a/src/rebar_utils.erl b/src/rebar_utils.erl index 5da53dd..4d52dff 100644 --- a/src/rebar_utils.erl +++ b/src/rebar_utils.erl @@ -51,7 +51,8 @@ erl_opts/1, src_dirs/1, test_dir/0, - ebin_dir/0]). + ebin_dir/0, + processing_base_dir/1, processing_base_dir/2]). -include("rebar.hrl"). @@ -313,6 +314,13 @@ test_dir() -> ebin_dir() -> filename:join(rebar_utils:get_cwd(), "ebin"). +processing_base_dir(Config) -> + Cwd = rebar_utils:get_cwd(), + processing_base_dir(Config, Cwd). + +processing_base_dir(Config, Dir) -> + Dir =:= rebar_config:get_xconf(Config, base_dir). + %% ==================================================================== %% Internal functions %% ==================================================================== -- cgit v1.1