tsloughter / rebar3_erlydtl_plugin

Rebar3 Erlydtl Plugin
Other
11 stars 33 forks source link

does not load custom tags and filters modules because code path does not contain path to the current app #21

Open brigadier opened 9 months ago

brigadier commented 9 months ago

Plugin does not work with filter and tag libraries at least with erlang 26 assuming in the rebar.config in erlydtl options we have

{libraries, [{my_dtl_filters, my_dtl_filters_lib}]},
    {default_libraries, [my_dtl_filters]},

When we start rebar with something like rebar3 shell eventually the following lites are executed in the erlydtl_compiler_utils.erl:

lib_module(Name, #dtl_context{ libraries=Libs }) ->
    Mod = proplists:get_value(Name, Libs, Name),
    case code:ensure_loaded(Mod) of
        {module, Mod} ->

and code:ensure_loaded() always fails because path to the ebin of the current app is not in the code:get_path() yet. I checked the difference between code path in this function and in the running app and as expected the difference was

["/home/evgeny/projects/myapp/myapp/_build/default/lib/myapp/ebin",
 "/home/evgeny/projects/myapp/myapp/apps/myapp"]
brigadier commented 9 months ago

https://github.com/tsloughter/rebar3_erlydtl_plugin/compare/master...brigadier:rebar3_erlydtl_plugin:patch-1

This fixes teh problem, not bsure if it is teh correct way or not though

tsloughter commented 9 months ago

Oh, hm, that is probably right, can you send a PR?

brigadier commented 9 months ago

Unfortunatelly this does not solve the problem as erlydtl modules are compiled befor app modules. So while this fix works it works only after second compilation when the module with filters is already compiled.

tsloughter commented 9 months ago

Ah, so sounds like a need to erl_first_first lost to say what to compile first.

On Wed, Dec 20, 2023, at 04:55, Evgeny M. wrote:

Unfortunatelly this does not solve the problem as erlydtl modules are compiled befor app modules. So while this fix works it works only after second compilation when the module with filters is already compiled.

— Reply to this email directly, view it on GitHub https://github.com/tsloughter/rebar3_erlydtl_plugin/issues/21#issuecomment-1864348320, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAI3A6QJ75N4UAPYCURKADYKLG3DAVCNFSM6AAAAAA724JOVGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQNRUGM2DQMZSGA. You are receiving this because you commented.Message ID: @.***>