summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/rebar_deps.erl24
-rw-r--r--src/rebar_erlc_compiler.erl55
2 files changed, 66 insertions, 13 deletions
diff --git a/src/rebar_deps.erl b/src/rebar_deps.erl
index 11c78d0..5ba0af3 100644
--- a/src/rebar_deps.erl
+++ b/src/rebar_deps.erl
@@ -203,15 +203,25 @@ download_source(AppDir, {hg, Url, Rev}) ->
download_source(AppDir, {git, Url, Rev}) ->
ok = filelib:ensure_dir(AppDir),
rebar_utils:sh(?FMT("git clone -n ~s", [Url]), [], filename:dirname(AppDir)),
- rebar_utils:sh(?FMT("git checkout ~s", [Rev]), [], AppDir).
-
+ rebar_utils:sh(?FMT("git checkout ~s", [Rev]), [], AppDir);
+download_source(AppDir, {bzr, Url, Rev}) ->
+ ok = filelib:ensure_dir(AppDir),
+ rebar_utils:sh(?FMT("bzr branch -r ~s ~s ~s",
+ [Rev, Url, filename:basename(AppDir)]), [],
+ filename:dirname(AppDir));
+download_source(AppDir, {svn, Url, Rev}) ->
+ ok = filelib:ensure_dir(AppDir),
+ rebar_utils:sh(?FMT("svn checkout -r ~s ~s ~s",
+ [Rev, Url, filename:basename(AppDir)]), [],
+ filename:dirname(AppDir)).
%% ===================================================================
%% Source helper functions
%% ===================================================================
-source_engine_avail({Name, _, _}) when Name == hg; Name == git ->
+source_engine_avail({Name, _, _})
+ when Name == hg; Name == git; Name == svn; Name == bzr ->
case scm_client_vsn(Name) >= required_scm_client_vsn(Name) of
true ->
true;
@@ -232,11 +242,17 @@ scm_client_vsn(Path, VsnArg, VsnRegex) ->
end.
required_scm_client_vsn(hg) -> {1, 4};
-required_scm_client_vsn(git) -> {1, 6}.
+required_scm_client_vsn(git) -> {1, 6};
+required_scm_client_vsn(bzr) -> {2, 0};
+required_scm_client_vsn(svn) -> {1, 6}.
scm_client_vsn(hg) ->
scm_client_vsn(os:find_executable(hg), " --version", "version (\\d+).(\\d+)");
scm_client_vsn(git) ->
scm_client_vsn(os:find_executable(git), " --version", "git version (\\d+).(\\d+)");
+scm_client_vsn(bzr) ->
+ scm_client_vsn(os:find_executable(bzr), " --version", "Bazaar \\(bzr\\) (\\d+).(\\d+)");
+scm_client_vsn(svn) ->
+ scm_client_vsn(os:find_executable(svn), " --version", "svn, version (\\d+).(\\d+)");
scm_client_vsn(_) ->
undefined.
diff --git a/src/rebar_erlc_compiler.erl b/src/rebar_erlc_compiler.erl
index 2065a60..473fa20 100644
--- a/src/rebar_erlc_compiler.erl
+++ b/src/rebar_erlc_compiler.erl
@@ -80,10 +80,16 @@ doterl_compile(Config, OutDir, MoreSources) ->
RestErls = [Source || Source <- gather_src(SrcDirs, []) ++ MoreSources,
lists:member(Source, FirstErls) == false],
+ % Sort RestErls so that parse_transforms and behaviours are first
+ % This should probably be somewhat combined with inspect_epp
+ SortedRestErls = [K || {K, _V} <- lists:keysort(2,
+ [{F, compile_priority(F)} || F <- RestErls ])],
+
+
%% Make sure that ebin/ is on the path
CurrPath = code:get_path(),
code:add_path("ebin"),
- rebar_base_compiler:run(Config, FirstErls, RestErls,
+ rebar_base_compiler:run(Config, FirstErls, SortedRestErls,
fun(S, C) -> internal_erl_compile(S, C, OutDir) end),
code:set_path(CurrPath),
ok.
@@ -96,21 +102,21 @@ doterl_compile(Config, OutDir, MoreSources) ->
-spec include_path(Source::string(), Config::#config{}) -> [string()].
include_path(Source, Config) ->
ErlOpts = rebar_config:get(Config, erl_opts, []),
- [filename:dirname(Source)] ++ proplists:get_all_values(i, ErlOpts).
+ ["include", filename:dirname(Source)] ++ proplists:get_all_values(i, ErlOpts).
-spec inspect(Source::string(), IncludePath::[string()]) -> {string(), [string()]}.
inspect(Source, IncludePath) ->
ModuleDefault = filename:basename(Source, ".erl"),
case epp:open(Source, IncludePath) of
{ok, Epp} ->
- inspect_epp(Epp, ModuleDefault, []);
+ inspect_epp(Epp, Source, ModuleDefault, []);
{error, Reason} ->
?DEBUG("Failed to inspect ~s: ~p\n", [Source, Reason]),
{ModuleDefault, []}
end.
--spec inspect_epp(Epp::pid(), Module::string(), Includes::[string()]) -> {string(), [string()]}.
-inspect_epp(Epp, Module, Includes) ->
+-spec inspect_epp(Epp::pid(), Source::string(), Module::string(), Includes::[string()]) -> {string(), [string()]}.
+inspect_epp(Epp, Source, Module, Includes) ->
case epp:parse_erl_form(Epp) of
{ok, {attribute, _, module, ModInfo}} ->
case ModInfo of
@@ -127,16 +133,18 @@ inspect_epp(Epp, Module, Includes) ->
{ActualModule, _} when is_list(ActualModule) ->
ActualModuleStr = string:join([atom_to_list(P) || P <- ActualModule], ".")
end,
- inspect_epp(Epp, ActualModuleStr, Includes);
+ inspect_epp(Epp, Source, ActualModuleStr, Includes);
{ok, {attribute, 1, file, {Module, 1}}} ->
- inspect_epp(Epp, Module, Includes);
+ inspect_epp(Epp, Source, Module, Includes);
+ {ok, {attribute, 1, file, {Source, 1}}} ->
+ inspect_epp(Epp, Source, Module, Includes);
{ok, {attribute, 1, file, {IncFile, 1}}} ->
- inspect_epp(Epp, Module, [IncFile | Includes]);
+ inspect_epp(Epp, Source, Module, [IncFile | Includes]);
{eof, _} ->
epp:close(Epp),
{Module, Includes};
_ ->
- inspect_epp(Epp, Module, Includes)
+ inspect_epp(Epp, Source, Module, Includes)
end.
-spec needs_compile(Source::string(), Target::string(), Hrls::[string()]) -> boolean().
@@ -211,3 +219,32 @@ delete_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::string()) -> pos_integer().
+compile_priority(File) ->
+ case epp_dodger:parse_file(File) of
+ {error, _} ->
+ 10; % couldn't parse the file, default priority
+ {ok, Trees} ->
+ ?DEBUG("Computing priority of ~p\n", [File]),
+ F2 = fun({tree,arity_qualifier,_,
+ {arity_qualifier,{tree,atom,_,behaviour_info},
+ {tree,integer,_,1}}}, _) ->
+ 2;
+ ({tree,arity_qualifier,_,
+ {arity_qualifier,{tree,atom,_,parse_transform},
+ {tree,integer,_,2}}}, _) ->
+ 1;
+ (_, Acc) ->
+ Acc
+ end,
+
+ F = fun({tree, attribute, _, {attribute, {tree, atom, _, export},
+ [{tree, list, _, {list, List, none}}]}}, Acc) ->
+ lists:foldl(F2, Acc, List);
+ (_, Acc) ->
+ Acc
+ end,
+
+ lists:foldl(F, 10, Trees)
+ end.