How to delay the compilation of a specific module

Hi,

Is there a way to delay the compilation of a specific module to get information about other modules?

The reason is that I have to wait for the macro execution of other modules to generate some functions in the main module.

Thanks!

No, but you can write custom compiler that will recompile given module after everything got compiled earlier.

Do you know some project that uses this kind of thing?

Your question reminded me that @grych was working on custom compiler for his templates in drab project, but looking at code repository looks like he removed related mentioned compiler. Maybe he could give you some ideas …


Possibly related:

2 Likes

Hmm probably, if I remember something. What do you wanted to do with it?

1 Like

Well … you were working on something similar (file compilation in custom mix compiler), so when @rodrigozc asked:

I thought that it would be useful in terms of this topic to ask some basic questions like:

  1. What were the advantages and disadvantages of such solution
  2. Why you decided to remove it
  3. What was your new solution
  4. Why it was better than previous one.

Even if your use case was a bit different it’s still a quite similar topic, so even if that would not be an answer you may give him an inspiration. Many times when looking at other repositories gives me ideas I would never think about or at least not enough soon.

1 Like

A possibility is to read static .ex files to generate the code that I want instead of delay the compilation of some modules to access the info of each one in a “main” module.

Your experience with custom compilation could help me to think of a better solution, maybe I don’t need to write a custom compilation for that.

@rodrigozc In case there is no other solution and you need this then I would go with files saved in other directory than lib and use a custom mix compiler to get path of them (which would be relative to app’s path) and compile them. For sure I have never tried that even in my pet projects. I know that in theory it’s possible, but I can’t say how (if any) it could cause trouble when for example compiling your app in prod server. If that would work and if that’s important for you I would recheck if hot code reloading is working with your custom mix compiler.

@Eiji, thanks for the support.
Now I have some insights to work.

If you don’t trust elixirs compile ordering resolver, you can put Code.ensure_compiled(<dependency>) in front of your defmodule statement.

1 Like