@@ -32,7 +32,7 @@ defmodule Mix.Tasks.Xref do
32
32
33
33
Therefore, if your goal is to reduce recompilations, the first step is to run:
34
34
35
- mix xref graph --format stats --label compile-connected
35
+ $ mix xref graph --format stats --label compile-connected
36
36
37
37
This command will show general information about the project, but
38
38
focus on compile-connected dependencies. In the stats, you will see
@@ -50,11 +50,11 @@ defmodule Mix.Tasks.Xref do
50
50
that "lib/livebook_web.ex" itself has its own dependencies. We can find
51
51
which files depend on "lib/livebook_web.ex" at compile time like this:
52
52
53
- mix xref graph --sink lib/livebook_web.ex --label compile --only-nodes
53
+ $ mix xref graph --sink lib/livebook_web.ex --label compile --only-nodes
54
54
55
55
And you can find the files lib/livebook_web.ex depends on like this:
56
56
57
- mix xref graph --source lib/livebook_web.ex --only-nodes
57
+ $ mix xref graph --source lib/livebook_web.ex --only-nodes
58
58
59
59
The trouble here is precisely that, if any of the files in the latter
60
60
command changes, all of the files in the first command will be recompiled,
@@ -65,7 +65,7 @@ defmodule Mix.Tasks.Xref do
65
65
dependencies within the same project. You can understand all of the
66
66
dependencies of a given file by running:
67
67
68
- mix xref trace lib/livebook_web.ex
68
+ $ mix xref trace lib/livebook_web.ex
69
69
70
70
The command above will output three types of dependencies, which we
71
71
detail next.
@@ -331,6 +331,36 @@ defmodule Mix.Tasks.Xref do
331
331
command will list all files from all umbrella children, without
332
332
any namespacing.
333
333
334
+ ### Understanding the printed cycle
335
+
336
+ If you run `mix xref graph --format cycle`, Elixir will print cycles
337
+ of shape:
338
+
339
+ Cycle of length 3:
340
+
341
+ lib/c.ex
342
+ lib/b.ex
343
+ lib/a.ex
344
+
345
+ The cycles are given in order: `c.ex` depends on `b.ex` which depends
346
+ on `a.ex` which depends on `c.ex`. In particular, you want to avoid
347
+ cycles with compile dependencies in there. You can find those cycles
348
+ with:
349
+
350
+ $ mix xref graph --format cycles --label compile-connected
351
+
352
+ Which may look like this:
353
+
354
+ Cycle of length 3:
355
+
356
+ lib/c.ex
357
+ lib/b.ex (compile)
358
+ lib/a.ex
359
+
360
+ This means `c.ex` depends on `b.ex` at compile time. Any compile dependency
361
+ in a cycle is by definition a compile-connected dependency, which must be
362
+ generally avoided, as explained earlier in the module documentation.
363
+
334
364
## Shared options
335
365
336
366
Those options are shared across all modes:
0 commit comments