-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
crystal tool dependencies
(#13613)
Co-authored-by: Quinton Miller <[email protected]>
- Loading branch information
1 parent
03301a5
commit 8ddf285
Showing
5 changed files
with
109 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
require "set" | ||
require "colorize" | ||
require "../syntax/ast" | ||
|
||
class Crystal::Command | ||
private def dependencies | ||
config = create_compiler "tool dependencies", no_codegen: true, dependencies: true | ||
|
||
config.compiler.dependency_printer = DependencyPrinter.new(STDOUT, flat: config.output_format == "flat") | ||
config.compiler.top_level_semantic config.sources | ||
end | ||
end | ||
|
||
module Crystal | ||
class DependencyPrinter | ||
@depth = 0 | ||
|
||
def initialize(@io : IO, @flat : Bool = false) | ||
end | ||
|
||
def enter_file(filename : String, unseen : Bool) | ||
print_indent | ||
print_file(filename) | ||
unless unseen | ||
@io.print " (duplicate skipped)" | ||
end | ||
@io.puts | ||
|
||
@depth += 1 | ||
end | ||
|
||
def leave_file | ||
@depth -= 1 | ||
end | ||
|
||
private def print_indent | ||
return if @flat | ||
@io.print " " * @depth if @depth > 0 | ||
end | ||
|
||
private def print_file(filename) | ||
@io.print ::Path[filename].relative_to?(Dir.current) || filename | ||
end | ||
end | ||
end |