@@ -4,7 +4,9 @@ Released under Apache 2.0 license as described in the file LICENSE.
44Authors: Scott Morrison
55-/
66import Mathlib.Util.Imports
7+ import Mathlib.Lean.Data.NameMap
78import Mathlib.Lean.IO.Process
9+ import Mathlib.Lean.Name
810import Cli
911
1012/-!
@@ -47,20 +49,24 @@ instance : ParseableType Name where
4749 else
4850 String.toName s
4951
50- open IO.FS IO.Process in
52+ open IO.FS IO.Process Name in
5153/-- Implementation of the import graph command line program. -/
5254def importGraphCLI (args : Cli.Parsed) : IO UInt32 := do
5355 let to := match args.flag? "to" with
5456 | some to => to.as! Name
5557 | none => `Mathlib -- autodetect the main module from the `lakefile.lean`?
5658 let from ? := match args.flag? "from" with
57- | some to => some <| to .as! Name
59+ | some fr => some <| fr .as! Name
5860 | none => none
5961 searchPathRef.set compileTimeSearchPath
6062 let dotFile ← unsafe withImportModules [{module := to}] {} (trustLevel := 1024 ) fun env => do
6163 let mut graph := env.importGraph
6264 if let .some f := from ? then
6365 graph := graph.dependenciesOf (NameSet.empty.insert f)
66+ if ¬(args.hasFlag "include-deps" ) then
67+ let p := getModule to
68+ graph := graph.filterMap (fun n i =>
69+ if p.isPrefixOf n then (i.filter (isPrefixOf p)) else none)
6470 if args.hasFlag "reduce" then
6571 graph := graph.transitiveReduction
6672 return asDotGraph graph
@@ -83,6 +89,7 @@ def graph : Cmd := `[Cli|
8389 reduce; "Remove transitively redundant edges."
8490 to : Name; "Only show the upstream imports of the specified module."
8591 "from" : Name; "Only show the downstream dependencies of the specified module."
92+ "include-deps" ; "Include used files from other projects (e.g. lake packages)"
8693
8794 ARGS:
8895 ...outputs : String; "Filename(s) for the output. " ++
0 commit comments