elixir-cldr / cldr

Elixir implementation of CLDR/ICU
Other
440 stars 33 forks source link

Recompiling every time? #200

Closed bortzmeyer closed 1 year ago

bortzmeyer commented 1 year ago

Apparently, each time, I mix run, everything is recompiled (with the time it takes) eve,n if I changed nothing in the source code.

mix.exs:

  defp deps do
    [
      {:jason, "~> 1.0"},
      {:ex_cldr_numbers, "~> 2.30"}
    ]
  end

lib/test_cldr.ex:

defmodule MyApp.Cldr do
  use Cldr,
    locales: ["en", "fr"],
    default_locale: "fr",
    providers: [Cldr.Number]
end

defmodule TestCldr do
  def hello do

  end
end

mix run lib/test_cldr.ex always recompile (with a lot of warnings, see #199):

...
Generating MyApp.Cldr for 3 locales named [:en, :fr, :und] with a default locale named :fr
...
% elixir --version           
Erlang/OTP 24 [erts-12.2.1] [source] [64-bit] [smp:12:12] [ds:12:12:10] [async-threads:1] [jit]

Elixir 1.12.2 (compiled with Erlang/OTP 24)
kipcole9 commented 1 year ago

That's very surprising behaviour. Thanks for the report. I've added a question in Elixir Forum in the hope someone can given me some suggestions as to what is triggering recompilation in mix run that is not triggered with mix compile or iex -S mix.

kipcole9 commented 1 year ago

The response from ericmj is a clear explanation:

mix run is the same as iex -S mix and they call mix compile so the compilation of your project code they do will be the same.

But when you pass a file to mix run it will evaluate that file, essentially compiling it without storing any compilation artifacts. You shouldn’t pass files from lib/ to mix run since that will compile the file twice, which is why you get the “redefining module” warnings.

You should only pass script files (.exs) to mix run.

bortzmeyer commented 1 year ago

OK, it now works with a script (.exs), not under lib/, and calling the various modules. Thanks, I understand better how mix works.

kipcole9 commented 1 year ago

Glad that's cleared up the issue. Not sure what your use case is, doing mix run lib/.....exs isn't that common. If there's anything you need clarification on feel free to start a GitHub discussion and I'm happy to help.