Is there a way put env in compile time and use it in runtime?

Hello. Based on a reporting bug (which was not bug :lady_beetle:), @josevalim said I can not use Application.put_env inside compile time macro like this:

This makes it so Mix believes the build of your dependency stale because a compile env flag is changing.

quote do
      [:validate_derive, :sanitize_derive]
      |> Enum.each(fn item ->
        if is_nil(Application.compile_env(:guarded_struct, item)) do
          Application.put_env(:guarded_struct, item, Keyword.get(unquote(opts), item))
        end
      end)

But I have question. is there a way to put env in compile time and access it inside run-time?

Thank you in advance.

Refs:

I donā€™t think so, but even if there would Iā€™d argue this is abusing the system. Config is an input to code compilation and running its result. Itā€™s not an output of compiling code.

2 Likes

Stop torturing poor elixir and make your own language already :joy: .

1 Like

A healthy body, including hands, waist, and neck, needs proper nutrition in a normal country. Unfortunately, I donā€™t have any :joy: :joy: :face_with_spiral_eyes:

I havenā€™t entirely traced how that env is being used, but this one looks like you need a different approach for getting metadata to ValidationDerive:

At an absolute minimum, youā€™d need to be able to distinguish ā€œthis module that said guardedstruct wants validationā€ from ā€œthis OTHER module that said guardedstruct doesnā€™t want validationā€ - a single boolean in the application env isnā€™t sufficient for that.

1 Like

Yes, I am trying to change my whole passing data to my derive function. It needs lot of works :face_with_spiral_eyes:

Update:

I left this option of my macro. it is not necessary, for now