kip

kip

ex_cldr Core Team

Mix.Task.run "deps.compile", ["dep_name", "--force"] not compiling

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.

Most Liked

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.

zachdaniel

zachdaniel

Creator of Ash

Was just about to post back here with my current solution which is probably a very very ugly hack, but it does work:

      case Mix.shell().cmd("mix deps.get") do
        0 ->
          Mix.Task.reenable("compile")
          Mix.Task.run("compile")

          Mix.Project.clear_deps_cache()
          Mix.Project.pop()

          "mix.exs"
          |> File.read!()
          |> Code.eval_string([], file: Path.expand("mix.exs"))

          Mix.Task.run("deps.compile", Enum.map(install_list, &to_string/1))

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

        exit_code ->
          Mix.shell().info("""
          mix deps.get returned exited with code: `#{exit_code}`
          """)
      end
zachdaniel

zachdaniel

Creator of Ash

Not sure I fully understand the question, sorry.

A brief explanation of what I need to do is: I add a dependency to the mix.exs file, and I need to fetch it and look for a mix task defined by it. So I need to add a dep, get it with mix deps.get and then compile it with mix deps.compile. My use case is quite limited, as I know that the app will shut down after running my mix task, so it’s not really a problem if it ends up in a weird state. But this is happening at runtime, not at compile time (since its in a mix task.

Does that answer your question?

zachdaniel

zachdaniel

Creator of Ash

I’m sorry, I’m having trouble understanding your question :frowning:

Another way my lib can, he/she changes the mix file and your code can re-compile in runtime without any downtime? yes?

I believe the answer to this question is yes. You can run this to install any deps added to the mix.exs file without downtime. But if the app is currently running I’m not sure if there will be weird behavior from the Mix.Project.pop/1 call. Hard to say.

shahryarjb

shahryarjb

Thank you. Aha, this is the answer I need.

So I should re-check it. I do not care about state if lost! because hot coding is very hard for full project, hot coding just useful for one or 2 modules manually and it is very harder in release mode!

Thank you and sorry for my english I am not native, it wasted your time :face_holding_back_tears::pray:t2:

Anyway, Ash means bear in my mother tongue lang :joy:

Where Next?

Popular in Questions Top

Tee
can someone please explain to me how Enum.reduce works with maps
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
mathew4509
I have a list say x = ["23gh", "56kh", "97mh"] I would like to pass each element to Val in each iteration. Say, in iteration 1 -------...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
idi527
I’ve been re-reading swift book again and noticed that multiline strings there don’t have a trailing line break, unlike in elixir iex(2)...
New

Other popular topics Top

yurko
Here are few pieces of (common) Linux knowledge that we use for reasonably small one server apps. We use Ubuntu but this should work for ...
New
Tee
can someone please explain to me how Enum.reduce works with maps
New
chrismccord
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
New
vac
Hi, I'm quite new in Elixir and I'm trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and ...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
chensan
I have a User schema with a :from_id field set to type :string: defmodule TweetBot.Repo.Migrations.CreateUsers do use Ecto.Migration ...
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 42633 214
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New

We're in Beta

About us Mission Statement