Hi folks,
After delivering the library generating code from type specs, I realised 
that I'm missing the explicit indication of whether the function/macro is 
executed within the mix compile task, the mix test task, or interactively 
(iex / live book) during the compile-time.

Here is the code to illustrate the use case:
defmacro __using__(opts) do
  ...
   cond do
      in_mix_compile? -> 
        # plan the code generation when mix compile finishes to resolve 
type dependencies between BEAM files.
      in_mix_test? ->
        # raise an error and suggest compiling the module as an .ex file 
for the test environment.
      true ->
        # we're in iex / live book, generate code immediately because type 
dependencies are resolved during the sequential definition of the modules. 
   end
end

Currently, I use the following hacks to get to know the execution mode:
def in_mix_compile?(module_env) do         
  tracers = Map.get(module_env || %{}, :tracers, [])         
  Enum.member?(tracers, Mix.Compilers.ApplicationTracer)
end
  
def in_mix_test?(_module_env) do
  not is_nil(GenServer.whereis(ExUnit.Server))           
end

Is it an absurd idea to add the explicit field indicating execution mode 
like the following?: 
%Module.Env{
   execution_mode: :compile | :test | :interactive
}

that can be returned by __CALLER__ in a macro or by __EVN__ in a function.

Warm regards,
Ivan.

-- 
You received this message because you are subscribed to the Google Groups 
"elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elixir-lang-core+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elixir-lang-core/cb990143-1498-4ccc-b982-73515656f91an%40googlegroups.com.

Reply via email to