Permalink
Browse files

Fix release generation (conflict with stdlib's erl_parse.beam)

Erlang release generation wouldn't work because the conflict between
erlson/ebin/erl_parse.beam and stdlib/ebin/erl_parse.beam
  • Loading branch information...
1 parent a2f34fe commit c4fb53e1e16b516870e663a90a7e5034c19f29c9 @alavrik committed Nov 19, 2011
File renamed without changes.
@@ -0,0 +1,6 @@
+{application, erlson_erlc,
+ [{description, "Erlang Simple Object Notation (version for Erlang compiler)"},
+ {vsn, git},
+ {modules, []},
+ {applications, [kernel, stdlib]},
+ {env, []}]}.
File renamed without changes.
View
@@ -6,10 +6,11 @@
{rebar_plugins, [erlson_rebar_plugin]}. % older rebar
% version of the extended Erlang parser that generates Erlson at parse time
-{sub_dirs, ["shell"]}.
+{sub_dirs, ["erlson_erlc", "erlson_shell"]}.
{post_hooks, [
- {compile, "cp shell/ebin/erl_parse.beam ebin/erl_parse_shell.beam"}
+ {compile, "cp erlson_erlc/ebin/erl_parse.beam ebin/erl_parse_erlc.beam"},
+ {compile, "cp erlson_shell/ebin/erl_parse.beam ebin/erl_parse_shell.beam"}
]}.
View
@@ -13,7 +13,7 @@ ERL_TEST_OBJECTS = $(ERL_TESTS:%.erl=$(EBIN_DIR)/%.beam)
.PHONY: all test
-all: $(ERL_SOURCES) erl_parse_shell.yrl $(ERL_OBJECTS) expand test
+all: $(ERL_SOURCES) erl_parse_shell.yrl erl_parse.yrl $(ERL_OBJECTS) expand test
erlson_tests.erl: $(ERL_SOURCES)
@@ -25,7 +25,11 @@ erlson_tests.erl: $(ERL_SOURCES)
erl_parse_shell.yrl:
- test -s $@ || ln -s ../shell/src/erl_parse.yrl $@
+ test -s $@ || ln -s ../erlson_shell/src/erl_parse.yrl $@
+
+
+erl_parse.yrl:
+ test -s $@ || ln -s ../erlson_erlc/src/erl_parse.yrl $@
$(ERL_OBJECTS) $(ERL_TEST_OBJECTS): %.beam: %.erl
@@ -48,7 +52,7 @@ expand: erlson_tests.erl erlson_tests.P
clean:
rm -f $(ERL_OBJECTS) erl_crash.dump \
- erl_parse.erl \
+ erl_parse.erl erl_parse.yrl \
erl_parse_shell.* \
erlson_tests.*
View
@@ -24,7 +24,7 @@
%
-module(erlson).
--export([init/0]).
+-export([init/0, init_erlc/0]).
% public API
-export([from_proplist/1, from_nested_proplist/1, from_nested_proplist/2]).
@@ -311,17 +311,32 @@ decode_json_field_name(N) ->
% @doc Enable Erlson syntax in Erlang shell
init() ->
- case code:get_object_code(erl_parse_shell) of
+ init(erl_parse_shell).
+
+
+% @doc Enable Erlson syntax when compiling Erlang modules using erlc. The
+% resulting Erlang AST will be proccessed by Erlson pase transform module
+% (erlson_pt.erl).
+init_erlc() ->
+ init(erl_parse_erlc).
+
+
+init(Mod) ->
+ % unload stdlib's erl_parse
+ code:purge(erl_parse),
+ code:delete(erl_parse),
+
+ case code:get_object_code(Mod) of
{_, Code, File} ->
code:unstick_dir(filename:dirname(File)),
case code:load_binary(erl_parse, File, Code) of
{module, _Name} -> ok;
{error, Reason} ->
exit({erlson_error,
- {"failed to load erl_parse_shell.beam", Reason}})
+ {"failed to load module " ++ atom_to_list(Mod), Reason}})
end;
error ->
exit({erlson_error,
- "failed to load code from erl_parse_shell.beam"})
+ "failed to load code from module " ++ atom_to_list(Mod)})
end.
@@ -27,21 +27,9 @@ pre_xref(Config, X) ->
common(_Config, _X) ->
- 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.
+ erlson:init_erlc(),
+ rebar_log:log(debug,
+ "erlson_rebar_plugin: loaded erl_parse as ~s~n",
+ [code:which(erl_parse)]),
+ ok.

0 comments on commit c4fb53e

Please sign in to comment.