[erlang-questions] compile transforms which change the module name

Ulf Wiger ulf.wiger@REDACTED
Fri Jul 10 12:00:54 CEST 2009


Peter Andersson wrote:
> The  'no_error_module_mismatch' option should do the trick:
> 
> -module(foo).
> -compile({parse_transform,rename}).
> ...
> 
> 1> compile:file(foo, [no_error_module_mismatch]).
> {ok,xyz}

...except it still produces a file called foo.beam,
so c(foo, [no_error_module_mismatch]) still won't work.

It seems as if a wrapper is needed:

compile(F, Opts) ->
   case compile:file(F, [{parse_transform,rename},binary,
                         no_error_module_mismatch|Opts]) of
     {ok, Mod, Bin} ->
       Dir = filename:dirname(F),
       OutF = filename:join(Dir, atom_to_list(Mod) ++ ".beam"),
       ok = file:write_file(OutF, Bin),
       {ok, Mod};
     Error ->
       Error
   end.

(Above code not compiled - let alone tested.)

BR,
Ulf W


>   /Peppe
> 
> 
> Joe Armstrong wrote:
>> If I change the module name in a compile transform I get an error.
>>
>> If there a work-around for this?
>>
>> I really want to change the module name so that when I compile foo.erl it
>> produces a new name xyz.beam containing code for the module xyz.
>>
>> /Joe
>>
>> ________________________________________________________________
>> erlang-questions mailing list. See http://www.erlang.org/faq.html
>> erlang-questions (at) erlang.org
>>
>>   
> 
> 
> ________________________________________________________________
> erlang-questions mailing list. See http://www.erlang.org/faq.html
> erlang-questions (at) erlang.org
> 


-- 
Ulf Wiger
CTO, Erlang Training & Consulting Ltd
http://www.erlang-consulting.com


More information about the erlang-questions mailing list