[erlang-questions] compile transforms which change the module name
Chad DePue
chad@REDACTED
Fri Jul 10 15:20:27 CEST 2009
this is cool. is MD5 good enough or would it be better to use SHA1?
On Jul 10, 2009, at 7:36 AM, Joe Armstrong wrote:
> Works a charm - thanks
>
> I am making a very nice transform.
>
> Hint: take all files in an application call these {x1.erl, x2.erl ...}
>
> 1) Make a name map
>
> map() -> [{"x1", m27313afsadfddsf, "joe", 213517657153675}
> ...
>
> This means that the md5 checksum of x1.erl is m273 .... and 2135... is
> the MD5 sum signed
> with joe's public key
>
> 2) transform all code in x1.erl x2.erl replacing the module names x1,
> x2 ... etc.
> with the MD5 sums so x1:abc(...) becomes m273...:abc( ...)
>
> 3) replace apply(M,F,A) with newapply(map(),M, F, A)
>
> result - a) no name space collisions
> b) exact version control
> c) safety (if you can't guess the MD5 sum :-)
>
> It's kind of like adding a big "where" clause round a module
>
> -module(foo).
>
> a() -> lists:reverse(...)
>
> WHERE
> foo = m1283abcd ...
> lists = m34aefg ...
>
> ie all modules names are converted to the MD5 sums of the original
> sources.
>
> I think this might solve a lot of problems with safety, versioning,
> testing, namespaces etc.
>
> (safe erlang can be made by replacing calls to dangerous mods like
> file etc.
> with safe_file ... etc.)
>
> /Joe
>
>
>
> On Fri, Jul 10, 2009 at 12:00 PM, Ulf
> Wiger<ulf.wiger@REDACTED> wrote:
>> 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
>>
>
> ________________________________________________________________
> erlang-questions mailing list. See http://www.erlang.org/faq.html
> erlang-questions (at) erlang.org
>
More information about the erlang-questions
mailing list