mirror of
https://github.com/correl/rebar.git
synced 2024-12-18 11:06:20 +00:00
include source path in compiler errors, process commands separately (to make get-deps compile work), ensure ebin dir, process iteratively to support transitive deps
This commit is contained in:
parent
fc58d12820
commit
9dd9585d5b
3 changed files with 80 additions and 38 deletions
|
@ -179,7 +179,8 @@ compile_worker(QueuePid, Config, CompileFn) ->
|
||||||
QueuePid ! {skipped, Source},
|
QueuePid ! {skipped, Source},
|
||||||
compile_worker(QueuePid, Config, CompileFn);
|
compile_worker(QueuePid, Config, CompileFn);
|
||||||
Error ->
|
Error ->
|
||||||
QueuePid ! {fail, Error},
|
QueuePid ! {fail, [{error, Error},
|
||||||
|
{source, Source}]},
|
||||||
ok
|
ok
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
|
@ -72,7 +72,9 @@ run(RawArgs) ->
|
||||||
?DEBUG("Rebar location: ~p\n", [rebar_config:get_global(escript, undefined)]),
|
?DEBUG("Rebar location: ~p\n", [rebar_config:get_global(escript, undefined)]),
|
||||||
|
|
||||||
%% Load rebar.config, if it exists
|
%% Load rebar.config, if it exists
|
||||||
process_dir(rebar_utils:get_cwd(), rebar_config:new(), CommandAtoms).
|
[process_dir(rebar_utils:get_cwd(), rebar_config:new(), [Command])
|
||||||
|
|| Command <- CommandAtoms],
|
||||||
|
ok.
|
||||||
|
|
||||||
|
|
||||||
%% ===================================================================
|
%% ===================================================================
|
||||||
|
@ -277,6 +279,23 @@ process_dir(Dir, ParentConfig, Commands) ->
|
||||||
|
|
||||||
Modules = AnyDirModules ++ DirModules,
|
Modules = AnyDirModules ++ DirModules,
|
||||||
|
|
||||||
|
ok = process_subdirs(Dir, Modules, Config, ModuleSetFile, Commands),
|
||||||
|
|
||||||
|
%% Once we're all done processing, reset the code path to whatever
|
||||||
|
%% the parent initialized it to
|
||||||
|
restore_code_path(CurrentCodePath),
|
||||||
|
ok
|
||||||
|
end.
|
||||||
|
|
||||||
|
|
||||||
|
%%
|
||||||
|
%% Run the preprocessors and execute commands on all newly
|
||||||
|
%% found Dirs until no new Dirs are found by the preprocessors.
|
||||||
|
%%
|
||||||
|
process_subdirs(Dir, Modules, Config, ModuleSetFile, Commands) ->
|
||||||
|
process_subdirs(Dir, Modules, Config, ModuleSetFile, Commands, sets:new()).
|
||||||
|
|
||||||
|
process_subdirs(Dir, Modules, Config, ModuleSetFile, Commands, ProcessedDirs) ->
|
||||||
%% Give the modules a chance to tweak config and indicate if there
|
%% Give the modules a chance to tweak config and indicate if there
|
||||||
%% are any other dirs that might need processing first.
|
%% are any other dirs that might need processing first.
|
||||||
{UpdatedConfig, Dirs} = acc_modules(select_modules(Modules, preprocess, []),
|
{UpdatedConfig, Dirs} = acc_modules(select_modules(Modules, preprocess, []),
|
||||||
|
@ -286,35 +305,56 @@ process_dir(Dir, ParentConfig, Commands) ->
|
||||||
%% Add ebin to path if this app has any plugins configured locally.
|
%% Add ebin to path if this app has any plugins configured locally.
|
||||||
prep_plugin_modules(UpdatedConfig),
|
prep_plugin_modules(UpdatedConfig),
|
||||||
|
|
||||||
[process_dir(D, UpdatedConfig, Commands) || D <- Dirs],
|
%% Process subdirs that haven't already been processed.
|
||||||
|
F = fun (D, S) ->
|
||||||
|
case filelib:is_dir(D) andalso (not sets:is_element(D, S)) of
|
||||||
|
true ->
|
||||||
|
process_dir(D, UpdatedConfig, Commands),
|
||||||
|
sets:add_element(D, S);
|
||||||
|
false ->
|
||||||
|
S
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
NewProcessedDirs = lists:foldl(F, sets:add_element(parent, ProcessedDirs), Dirs),
|
||||||
|
|
||||||
|
%% http://bitbucket.org/basho/rebar/issue/5
|
||||||
|
%% If the compiler ran, run the preprocess again because a new ebin dir
|
||||||
|
%% may have been produced.
|
||||||
|
{UpdatedConfig1, _} = case (Dirs =/= [] andalso
|
||||||
|
lists:member(compile, Commands)) of
|
||||||
|
true ->
|
||||||
|
acc_modules(
|
||||||
|
select_modules(Modules, preprocess, []),
|
||||||
|
preprocess, UpdatedConfig, ModuleSetFile, []);
|
||||||
|
false ->
|
||||||
|
{UpdatedConfig, Dirs}
|
||||||
|
end,
|
||||||
|
|
||||||
%% Make sure the CWD is reset properly; processing subdirs may have caused it
|
%% Make sure the CWD is reset properly; processing subdirs may have caused it
|
||||||
%% to change
|
%% to change
|
||||||
ok = file:set_cwd(Dir),
|
ok = file:set_cwd(Dir),
|
||||||
|
|
||||||
%% http://bitbucket.org/basho/rebar/issue/5
|
%% Run the parent commands exactly once as well
|
||||||
%% If the compiler ran, run the preprocess again because a new ebin dir
|
case sets:is_element(parent, ProcessedDirs) of
|
||||||
%% may have been produced.
|
|
||||||
case Dirs =/= [] andalso lists:member(compile, Commands) of
|
|
||||||
true ->
|
true ->
|
||||||
acc_modules(select_modules(Modules, preprocess, []),
|
ok;
|
||||||
preprocess, Config, ModuleSetFile, []);
|
|
||||||
false ->
|
false ->
|
||||||
ok
|
|
||||||
end,
|
|
||||||
|
|
||||||
%% Get the list of plug-in modules from rebar.config. These modules are
|
%% Get the list of plug-in modules from rebar.config. These modules are
|
||||||
%% processed LAST and do not participate in preprocess.
|
%% processed LAST and do not participate in preprocess.
|
||||||
{ok, PluginModules} = plugin_modules(UpdatedConfig),
|
{ok, PluginModules} = plugin_modules(UpdatedConfig1),
|
||||||
|
|
||||||
%% Finally, process the current working directory
|
%% Finally, process the current working directory
|
||||||
?DEBUG("Commands: ~p Modules: ~p Plugins: ~p\n", [Commands, Modules, PluginModules]),
|
?DEBUG("Commands: ~p Modules: ~p Plugins: ~p\n", [Commands, Modules, PluginModules]),
|
||||||
apply_commands(Commands, Modules ++ PluginModules, UpdatedConfig, ModuleSetFile),
|
apply_commands(Commands, Modules ++ PluginModules, UpdatedConfig1, ModuleSetFile)
|
||||||
|
end,
|
||||||
|
|
||||||
%% Once we're all done processing, reset the code path to whatever
|
%% Repeat the process if there are new SeenDirs
|
||||||
%% the parent initialized it to
|
case NewProcessedDirs =:= ProcessedDirs of
|
||||||
restore_code_path(CurrentCodePath),
|
true ->
|
||||||
ok
|
ok;
|
||||||
|
false ->
|
||||||
|
process_subdirs(Dir, Modules, UpdatedConfig1, ModuleSetFile, Commands,
|
||||||
|
NewProcessedDirs)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
%%
|
%%
|
||||||
|
@ -347,7 +387,7 @@ prep_plugin_modules(Config) ->
|
||||||
%%
|
%%
|
||||||
plugin_modules(Config) ->
|
plugin_modules(Config) ->
|
||||||
Modules = lists:flatten(rebar_config:get_all(Config, rebar_plugins)),
|
Modules = lists:flatten(rebar_config:get_all(Config, rebar_plugins)),
|
||||||
plugin_modules(Config, Modules).
|
plugin_modules(Config, ulist(Modules)).
|
||||||
|
|
||||||
ulist(L) ->
|
ulist(L) ->
|
||||||
ulist(L, sets:new(), []).
|
ulist(L, sets:new(), []).
|
||||||
|
@ -373,7 +413,7 @@ plugin_modules(_Config, Modules) ->
|
||||||
?DEBUG("Missing plugins: ~p\n", [Modules -- FoundModules]),
|
?DEBUG("Missing plugins: ~p\n", [Modules -- FoundModules]),
|
||||||
ok
|
ok
|
||||||
end,
|
end,
|
||||||
{ok, ulist(FoundModules)}.
|
{ok, FoundModules}.
|
||||||
|
|
||||||
%%
|
%%
|
||||||
%% Return .app file if the current directory is an OTP app
|
%% Return .app file if the current directory is an OTP app
|
||||||
|
|
|
@ -116,7 +116,8 @@ doterl_compile(Config, OutDir, MoreSources) ->
|
||||||
[{F, compile_priority(F)} || F <- RestErls ])],
|
[{F, compile_priority(F)} || F <- RestErls ])],
|
||||||
|
|
||||||
|
|
||||||
%% Make sure that ebin/ is on the path
|
%% Make sure that ebin/ exists and is on the path
|
||||||
|
ok = filelib:ensure_dir(filename:join("ebin", "dummy.beam")),
|
||||||
CurrPath = code:get_path(),
|
CurrPath = code:get_path(),
|
||||||
code:add_path("ebin"),
|
code:add_path("ebin"),
|
||||||
rebar_base_compiler:run(Config, FirstErls, SortedRestErls,
|
rebar_base_compiler:run(Config, FirstErls, SortedRestErls,
|
||||||
|
|
Loading…
Reference in a new issue