@@ -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.
@@ -330,6 +330,36 @@ defmodule Mix.Tasks.Xref do
330
330
command will list all files from all umbrella children, without
331
331
any namespacing.
332
332
333
+ ### Understanding the printed cycle
334
+
335
+ If you run `mix xref graph --format cycle`, Elixir will print cycles
336
+ of shape:
337
+
338
+ Cycle of length 3:
339
+
340
+ lib/c.ex
341
+ lib/b.ex
342
+ lib/a.ex
343
+
344
+ The cycles are given in order: `c.ex` depends on `b.ex` which depends
345
+ on `a.ex` which depends on `c.ex`. In particular, you want to avoid
346
+ cycles with compile dependencies in there. You can find those cycles
347
+ with:
348
+
349
+ $ mix xref graph --format cycles --label compile-connected
350
+
351
+ Which may look like this:
352
+
353
+ Cycle of length 3:
354
+
355
+ lib/c.ex
356
+ lib/b.ex (compile)
357
+ lib/a.ex
358
+
359
+ This means `c.ex` depends on `b.ex` at compile time. Any compile dependency
360
+ in a cycle is by definition a compile-connected dependency, which must be
361
+ generally avoided, as explained earlier in the module documentation.
362
+
333
363
## Shared options
334
364
335
365
Those options are shared across all modes:
0 commit comments