Quantcast

Question about per file compile options

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Question about per file compile options

Michael Kokich

Hi everyone

I'm hitting up against against how Erlang passes compile options to parse_transform and was wanting some guidance.

I'm making changes to lager's parse_tranform and I'm making eunit tests to check these changes. The changes involve setting compile options to add extra metadata to logging calls, such as the example below.

{erl_opts, [
  {parse_transform, lager_transform},
  {lager_function_transforms, [
    {metadata_value, {module_name, function_name}}
  ]}
]}.

One of these tests involves calls to a undefined Module:Function and I need to apply the transform only to the specific test file since this will break all the other tests.

If I set lager_function_transforms in lager's rebar.config eunit_compile_opts it applies the transforms to all  the tests with -compile([{parse_transform, lager_transform}]). If I supply these options to the -compile, they don't appear in the options provided to the parse_transform.

-compile([
  {parse_transform, lager_transform}, % If you don't supply this to the test file it won't transformed
  {lager_function_transforms, [ % But these options seem to be ignored
    {metadata_value, {module_name, function_name}}
  ]}
]).

Is there a way a to compile these new tests with my specific settings without applying them globally, or having to compile them separately?

Thank you
Michael


_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Question about per file compile options

Michael Kokich

Hi all


I've worked out how to do it and learnt some things along the way which I'll document for future travelers. The -compile module attribute is the correct place for per file compile options, however not for any custom values you want to supply. Unlike other module attributes, any values that are passed via -compile don't end up in the AST which was a surprise to me.


E.g. my example

-compile([
  {parse_transform, lager_transform},
  {lager_parse_transform_functions, [
    {metadata_value, {module_name, function_name}}
  ]}
]).


Got turned into:

{attribute,3,compile,[]),

If you use :module_info() on a module in which you've included the -compile options it also doesn't include the values. I'll assume that the options passed to parse_transform/2 come from the same source as the compile values in :module_info().


To apply these transforms per file I've set my own module attribute and as we're walking the AST merge the values into any globally supplied values as long as I set it before I start transforming the logging lines themselves.

E.g
-lager_parse_transform_functions([
  {metadata_value, {module_name, function_name}}
]).

Now everything works as expected and the tests pass!

Michael


From: [hidden email] <[hidden email]> on behalf of Michael Kokich <[hidden email]>
Sent: Thursday, 23 February 2017 9:05 a.m.
To: [hidden email]
Subject: [erlang-questions] Question about per file compile options
 

Hi everyone

I'm hitting up against against how Erlang passes compile options to parse_transform and was wanting some guidance.

I'm making changes to lager's parse_tranform and I'm making eunit tests to check these changes. The changes involve setting compile options to add extra metadata to logging calls, such as the example below.

{erl_opts, [
  {parse_transform, lager_transform},
  {lager_function_transforms, [
    {metadata_value, {module_name, function_name}}
  ]}
]}.

One of these tests involves calls to a undefined Module:Function and I need to apply the transform only to the specific test file since this will break all the other tests.

If I set lager_function_transforms in lager's rebar.config eunit_compile_opts it applies the transforms to all  the tests with -compile([{parse_transform, lager_transform}]). If I supply these options to the -compile, they don't appear in the options provided to the parse_transform.

-compile([
  {parse_transform, lager_transform}, % If you don't supply this to the test file it won't transformed
  {lager_function_transforms, [ % But these options seem to be ignored
    {metadata_value, {module_name, function_name}}
  ]}
]).

Is there a way a to compile these new tests with my specific settings without applying them globally, or having to compile them separately?

Thank you
Michael


_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Loading...