sashaafm
End of compilation hook
Hello, I was wondering if there’s a way to do something at the end of application’s compilation? For example, there are the @before_compile and @after_compile hooks, which are scoped to the calling module. However, since Elixir’s compiler is concurrent, there doesn’t seem to be a deterministic way to know what will be the last compiled module in case you want to do something at the end of all compilations.
I reckon there must be some way to know the compilation has finished (e.g., Elixir emits a Generated <app_name> app at the end of each app’s compilation process which by looking at the source code seems to be emitted once the target app file is written)? Probably the API for this won’t be public for the general user.
Marked As Solved
michalmuskala
Elixir has the concept of multiple compilers. Currently the built-in ones are:
- yecc - responsible for generating yecc parser files
- leex - responsible for generating leex lexer files
- erlang - responsible for compiling erlang files
- elixir - responsible for compiling elixir files
- xref - responsible for collecting compilation information so that missing module information can be displayed
- app - responsible for generating the
.appfile.
You can define your own compiles and include them at a particular point. For example: phoenix includes the phoenix compiler to support code reloading.
Maybe that could solve your issue?
Also Liked
hazardfn
Not sure if this is entirely what you meant but I think you can extend the compile mix task by adding your own “compiler” to the project and (to run it after everything else is compiled) just set it to last in the :compilers list. The docs has some info on this:
http://elixir-lang.org/docs/stable/mix/Mix.Tasks.Compile.html#content
I have never tried it but adding a module in the same namespace (Mix.Tasks.Compile.x) should work if I understand correctly…







