-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Description
After a conversation with @sasa1977, it seems now possible to track application boundaries in Mix by using compilation tracers. The idea is: if a user calls a module that does not belong to any of the applications listed in the mix.exs
, a warning should be emitted. The process is roughly this:
-
Move the application computation code in here to Mix.Project and cache it. It should return a map like this:
%{app => :runtime | :compile}
. Only runtime deps should go to the .app file. -
When compiling Elixir code, get all of the applications above, load them, and store their modules in a ETS table with runtime | compile as value. Note
:mix
and:ex_unit
need to be special cased to always be introduced. -
Define a tracer that runs module invocations against the ETS table. The tracer should always be added here. If a call violates the application boundary, it is stored somewhere.
-
Once all code is compiled, we go through all violations, rule out any violation to modules for the current application itself, and define warnings for the remaining ones. This needs to be done inside "lib/mix/compilers/elixir.ex".
We don't need to cache lookups because a change in the applications/dependencies will recompile the whole project. Furthermore, if warnings are emitted during compilation, they are automatically cached for replayability. The only concern about this task is time spent on building the ETS table but this can likely be cached.