summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuis Rascão <luis.rascao@gmail.com>2016-08-26 23:50:45 +0100
committerGitHub <noreply@github.com>2016-08-26 23:50:45 +0100
commitdc3b1eb4ebe99beb49b1a12bbb131d67a0d82060 (patch)
tree88e0f3fd2f71672ea684874af6d422cfc22b938f
parent1387a83e24eba0a794e9890c3351871a0fb7262e (diff)
parent4914a2f29ff6d5ced53d5dc7c97b9e82ff7033f8 (diff)
downloadrebar-dc3b1eb4ebe99beb49b1a12bbb131d67a0d82060.tar.gz
Merge pull request #616 from tuncer/clang-compilation-db
port_compiler: clean up compile_each()
-rw-r--r--src/rebar_port_compiler.erl46
1 files changed, 25 insertions, 21 deletions
diff --git a/src/rebar_port_compiler.erl b/src/rebar_port_compiler.erl
index 10f8f69..48c276c 100644
--- a/src/rebar_port_compiler.erl
+++ b/src/rebar_port_compiler.erl
@@ -238,6 +238,20 @@ compile_each(Config, [Source | Rest], Type, Env, {NewBins, CDB}) ->
Bin = replace_extension(Source, Ext, ".o"),
Template = select_compile_template(Type, compiler(Ext)),
Cmd = expand_command(Template, Env, Source, Bin),
+ CDBEnt = cdb_entry(Source, Cmd, Rest),
+ case needs_compile(Source, Bin) of
+ true ->
+ ShOpts = [{env, Env}, return_on_error, {use_stdout, false}],
+ exec_compiler(Config, Source, Cmd, ShOpts),
+ compile_each(Config, Rest, Type, Env,
+ {[Bin | NewBins], [CDBEnt | CDB]});
+ false ->
+ ?INFO("Skipping ~s\n", [Source]),
+ compile_each(Config, Rest, Type, Env, {NewBins, [CDBEnt, CDB]})
+ end.
+
+%% Generate a clang compilation db entry for Src and Cmd
+cdb_entry(Src, Cmd, SrcRest) ->
%% Omit all variables from cmd, and use that as cmd in
%% CDB, because otherwise clang-* will complain about it.
CDBCmd = string:join(
@@ -246,31 +260,21 @@ compile_each(Config, [Source | Rest], Type, Env, {NewBins, CDB}) ->
(_) -> true
end,
string:tokens(Cmd, " ")),
- " "),
+ " "),
+
Cwd = rebar_utils:get_cwd(),
%% If there are more source files, make sure we end the CDB entry
%% with a comma.
- CDBEntSep = case Rest of
- [] -> "~n";
- _ -> ",~n"
- end,
+ Sep = case SrcRest of
+ [] -> "~n";
+ _ -> ",~n"
+ end,
%% CDB entry
- CDBEnt = ?FMT("{ \"file\" : ~p~n"
- ", \"directory\" : ~p~n"
- ", \"command\" : ~p~n}"
- "~s",
- [Source, Cwd, CDBCmd, CDBEntSep]
- ),
- case needs_compile(Source, Bin) of
- true ->
- ShOpts = [{env, Env}, return_on_error, {use_stdout, false}],
- exec_compiler(Config, Source, Cmd, ShOpts),
- compile_each(Config, Rest, Type, Env,
- {[Bin | NewBins], [CDBEnt | CDB]});
- false ->
- ?INFO("Skipping ~s\n", [Source]),
- compile_each(Config, Rest, Type, Env, {NewBins, [CDBEnt, CDB]})
- end.
+ ?FMT("{ \"file\" : ~p~n"
+ ", \"directory\" : ~p~n"
+ ", \"command\" : ~p~n"
+ "}~s",
+ [Src, Cwd, CDBCmd, Sep]).
exec_compiler(Config, Source, Cmd, ShOpts) ->
case rebar_utils:sh(Cmd, ShOpts) of