App recompilation at runtime within a Mix task

53 views
Skip to first unread message

Brian Cardarella

unread,
Jul 29, 2024, 12:19:54 PM7/29/24
to elixir-lang-core
For LiveView Native's setup task I am doing some codegen with Sourceror to inject or modify existing config settings within config/config.exs and config/dev.exs"

After that step I want to run generators but the generators themselves would rely upon config settings.

There appears to be no way to do this in a single step within a Task at the moment.

My naive approach was:

Mix.Task.reenable("compile")
Mix.Task.run("compile")

but the Application.env was not changed after this within the runtime

What would be nice is if within a Mix task a full application recompilation would be done. So without leaving the runtime a complete recompilation could be triggered.

If there is a way to do this today any pointers would be greatly appreciated.

FWIW, Zach Daniels is also in need of this for Igniter.

Zach Daniel

unread,
Jul 29, 2024, 12:23:57 PM7/29/24
to elixir-lang-core
We've also had a fair amount of difficulty here, in a similar vein (but slightly different).

Specifically, we need to modify the `mix.exs` file to include a new dependency and do a recompile. I can understand that `Mix.Task.run("compile")` should remain as it is, but it would be great if there was some kind of magic `Mix.recompile` that would recompile the project including any file system changes or `mix.exs` changes, etc.

The goal would be that it was functionally equivalent to the user typing `mix compile` into their shell.

We've hacked around this by vendoring the `mix deps.compile` task and doing some goofy stuff to reload the mix project, but a proper core api for this would be wonderful.

Wojtek Mach

unread,
Jul 29, 2024, 12:26:51 PM7/29/24
to elixir-l...@googlegroups.com
If your task depends on configs I think you should do:

    @requirements [“app.config”]

--
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-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/d36e0659-ff98-4899-9455-8ae06036008fn%40googlegroups.com.

Brian Cardarella

unread,
Jul 29, 2024, 12:28:38 PM7/29/24
to elixir-lang-core
To be clear, the task itself doesn't rely on config but it is using modules that do

Wojtek Mach

unread,
Jul 29, 2024, 2:33:40 PM7/29/24
to elixir-l...@googlegroups.com
Sure. It should just work there. Otherwise it sounds like a bug.
Reply all
Reply to author
Forward
0 new messages