Browse files

More reliable and efficient Erlson rebar plugin

  • Loading branch information...
1 parent 262a022 commit c45f38457edc2bd205c4cf305922386b3f99dbfe @alavrik committed Jul 9, 2011
Showing with 17 additions and 7 deletions.
  1. +17 −7 src/erlson_rebar_plugin.erl
View
24 src/erlson_rebar_plugin.erl
@@ -27,11 +27,21 @@ pre_xref(Config, X) ->
common(_Config, _X) ->
- code:purge(erl_parse),
- code:delete(erl_parse),
- code:load_file(erl_parse),
- rebar_log:log(debug,
- "erlson_rebar_plugin: repointed erl_parse to: ~s~n",
- [code:which(erl_parse)]),
- ok.
+ ErlParsePath = code:which(erl_parse),
+ case {string:str(ErlParsePath, "erlson"), string:str(ErlParsePath, "stdlib")} of
+ {N, 0} when N =/= 0 ->
+ % Erlson version of the Erlang parser is already loaded
+ ok;
+ {0, N} when N =/= 0 ->
+ % for loading the custom "erl_parse" module, we rely on the fact
+ % that it is located next to this rebar plugin
+ code:purge(erl_parse),
+ code:delete(erl_parse),
+ code:load_file(erl_parse),
+ rebar_log:log(debug,
+ "erlson_rebar_plugin: repointed erl_parse to: ~s~n",
+ [code:which(erl_parse)]),
+ true = (string:str(code:which(erl_parse), "erlson") =/= 0),
+ ok
+ end.

0 comments on commit c45f384

Please sign in to comment.