kip

kip

ex_cldr Core Team

I have a dep that might need recompiling when the host app configuration changes. That requires a forced compile since by design deps aren’t automatically recompiled (which is the right strategy).

At the command line I can force recompile fine. But from IEx calling Mix.Task.run/2 I cannot. From the command line:

$ mix deps.compile ex_cldr --force
==> ex_cldr
Compiling 2 files (.erl)
Compiling 31 files (.ex)
Generating Cldr for 6 locales named ["en-001", "it", "pl", "root", "ru", ...] with a default locale named "en-001"
Generated ex_cldr app

From IEx shell:

$ iex -S mix
Erlang/OTP 20 [erts-9.2] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]

iex(1)> Mix.Task.run "deps.compile", [:ex_cldr, "--force"]
:ok

…but no compilation takes place.

Any advice on how I specify the args to Mix.Task.run/2 so that it force compiles would be most appreciated.

Showing Posts 1 to 10

ericmj

ericmj

Elixir Core Team

This seems to be an Elixir bug. When the --force flag is given the compile task for the dependency should be reenabled, by default a task is called only once per project/dependency and in this case it seems to have been called earlier at some point.

You have the same bug in your example, you should call Mix.Task.rerun since the task may have already run when mix was started.

kip

kip OP

ex_cldr Core Team

@ericmj, thanks for your reply. I’ve tried a few combinations without success so far, including reenabling, running and rerunning. All seems to return :ok without actually compiling. Anything else you might suggest>

Interactive Elixir (1.5.3) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> Mix.Task.rerun "deps.compile", ["ex_cldr", "--force"]
:ok
iex(2)> Mix.Task.reenable "deps.compile"                     
:ok
iex(3)> Mix.Task.rerun "deps.compile", ["ex_cldr", "--force"]
:ok
iex(4)> Mix.Task.reenable "deps.compile"                     
:ok
iex(5)> Mix.Task.run "deps.compile", ["ex_cldr", "--force"]  
:ok
ericmj

ericmj

Elixir Core Team

After looking at this more closely we decided this is a wont fix in Elixir. Mix is not intended to be called from iex or inside of your application. The primary interface is the CLI and because of this tasks are allowed to only run once.

You have to compile the dependency from the command line and restart the application. An application shouldn’t be recompiled after it has started, since it can have new modules, changed environment, or even changed supervision tree. If you don’t want to restart your application it is safest to use the OTP application upgrade mechanisms.

kip

kip OP

ex_cldr Core Team

Thanks @ericmj. My IEx demo was an example only. My use case is actually in a Mix compiler.

I think that calling a Mix task from a Mix compiler would be a reasonable expectation? I can work around it if tasks aren’t intended to be called at compile time but it does seem a little strange to me.

ericmj

ericmj

Elixir Core Team

If it’s in a Mix compiler then it’s a different question :). But since you are doing something uncommon by compiling dependencies after the parent project some more details about your problem would be helpful. It is possible we can solve it another way than compiling deps after the parent, for example would it be possible for you to alias the deps.compile or deps.precompile tasks to run your task before deps compilation? Can you elaborate on why the host app config changes in a compiler task?

mayel

mayel

If anyone passing by needs to do something similar, I managed to get a mix task to recompile deps: https://github.com/bonfire-networks/bonfire-app/tree/main/lib/mix/tasks/localise (feedback welcome)

zachdaniel

zachdaniel

Creator of Ash

I do in fact need to do this, but that link is broken for me @mayel

EDIT: I think I found its new location https://github.com/bonfire-networks/bonfire_common/blob/main/lib/mix_tasks/localise/localise_extract.ex

mayel

mayel

I haven’t looked at this in a while (or tried it with the last Elixir version) but hopefully it can help! There’s also this task: bonfire_common/lib/mix_tasks/extension/deps_compile.ex at main · bonfire-networks/bonfire_common · GitHub

zachdaniel

zachdaniel

Creator of Ash

Trying to isolate what about this task is different from the standard mix task is proving a bit of a challenge :sob: I feel like surely there must just be some kind of cache I can clear or some piece of state I can modify to make this work. Like before running mix deps.compile ...

mayel

mayel

Yeah I remember feeling the same but ended up with that less than ideal code by trial and error. Thinking about it fresh, I’m not sure why chaining mix deps.clean --build dep1 dep2 wouldn’t do the job? But maybe I’m not remembering some details.

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews