Handle compiler return code, and emit good code for erl_prettypr decompilation. #43

Closed
wants to merge 1 commit into
from

Projects

None yet

2 participants

@saleyn
saleyn commented Oct 18, 2012

Bug fixes:

  1. When compiler_option includes 'return', properly handle Error and Warnings
    returned by the compiler, so that the user still gets 'ok' instead of
    {ok, Module, Bin, {Errors, Warnings}}, which rebar doesn't property handle.
  2. When compiling templates with custom tags with a given custom_tags_modules
    option, the arguments were saved as atoms in the AST as opposed to strings.
    This caused a failure when decompiling the beam and printing its source
    by erl_prettypr.
  3. Local unused function render_tags/3 emitted in templates was compiling with
    a warning. Made it exported to suppress the warnings.

In order to illustrate the issue compile the template test.dtl containing:

{% tr xxx="ABC" %}

with options:

[
    , {doc_root, "src"}
    , {out_dir,   "ebin"}
    , {compiler_options, [verbose, debug_info, report, return]}
    , {custom_tags_modules, [custom_tags]}
    , {force_recompile, true}
].

where custom_tags module is:

-module(custom_tags).

-export([tr/2]).

tr(Vars, Context) ->
    io:format("Vars: ~p\n  Context: ~p\n", [Vars, Context]),
    [].

Observe the return code of erlydtl_compiler:compile/3, and also try to
decompile the emitted beam with:
[http://erlang.org/pipermail/erlang-questions/2006-January/018813.html]

@saleyn saleyn Property handle compiler return code, and emit good code for erl_pret…
…typr decompilation.

Bug fixes:
1. When compiler_option includes 'return', properly handle Error and Warnings
   returned by the compiler, so that the user still gets 'ok' instead of
   {ok, Module, Bin, {Errors, Warnings}}, which rebar doesn't property handle.

2. When compiling templates with custom tags with a given custom_tags_modules
   option, the arguments were saved as atoms in the AST as opposed to strings.
   This caused a failure when decompiling the beam and printing its source
   by erl_prettypr.

3. Local unused function render_tags/3 emitted in templates was compiling with
   a warning.  Made it exported to suppress the warnings.

In order to illustrate the issue compile the template test.dtl containing:

    {% tr xxx="ABC" %}

with options:

    [
        , {doc_root, "src"}
        , {out_dir,   "ebin"}
        , {compiler_options, [verbose, debug_info, report, return]}
        , {custom_tags_modules, [custom_tags]}
        , {force_recompile, true}
    ].

where custom_tags module is:

    -module(custom_tags).

    -export([tr/2]).

    tr(Vars, Context) ->
        io:format("Vars: ~p\n  Context: ~p\n", [Vars, Context]),
        [].

Observe the return code of erlydtl_compiler:compile/3, and also try to
decompile the emitted beam with:
[http://erlang.org/pipermail/erlang-questions/2006-January/018813.html]
6c0927c
@evanmiller
Collaborator

Please break this into a separate pull request for each issue so that I can wrap my head around it. Thanks!

@saleyn saleyn closed this Oct 19, 2012
@saleyn
saleyn commented Oct 19, 2012

I broke it off in three separate commits and resubmitted the pull request. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment