lib/jazzy/symbol_graph.rb in jazzy-0.14.1 vs lib/jazzy/symbol_graph.rb in jazzy-0.14.2
- old
+ new
@@ -12,31 +12,28 @@
# figuring out arguments, running the tool, and loading the
# results.
module Jazzy
module SymbolGraph
- # Run `swift symbolgraph-extract` with configured args,
- # parse the results, and return as JSON in SourceKit[ten]
+ # Find swift symbol graph files, either having been passed
+ # in directly, or generated by running`swift symbolgraph-extract`
+ # with configured args.
+ # Then parse the results, and return as JSON in SourceKit[ten]
# format.
def self.build(config)
- Dir.mktmpdir do |tmp_dir|
- args = arguments(config, tmp_dir)
+ if config.symbolgraph_directory.nil?
+ Dir.mktmpdir do |tmp_dir|
+ args = arguments(config, tmp_dir)
- Executable.execute_command('swift',
- args.unshift('symbolgraph-extract'),
- true) # raise on error
+ Executable.execute_command('swift',
+ args.unshift('symbolgraph-extract'),
+ true) # raise on error
- Dir[tmp_dir + '/*.symbols.json'].map do |filename|
- # The @ part is for extensions in our module (before the @)
- # of types in another module (after the @).
- filename =~ /(.*?)(@(.*?))?\.symbols/
- module_name = Regexp.last_match[3] || Regexp.last_match[1]
- {
- filename =>
- Graph.new(File.read(filename), module_name).to_sourcekit,
- }
- end.to_json
+ parse_symbols(tmp_dir)
+ end
+ else
+ parse_symbols(config.symbolgraph_directory.to_s)
end
end
# Figure out the args to pass to symbolgraph-extract
def self.arguments(config, output_path)
@@ -65,9 +62,23 @@
args += ['-target', target] unless user_args =~ /-target/
args += ['-F', config.source_directory.to_s] unless user_args =~ /-F(?!s)/
args += ['-I', config.source_directory.to_s] unless user_args =~ /-I/
args + config.build_tool_arguments
+ end
+
+ # Parse the symbol files in the given directory
+ def self.parse_symbols(directory)
+ Dir[directory + '/*.symbols.json'].map do |filename|
+ # The @ part is for extensions in our module (before the @)
+ # of types in another module (after the @).
+ File.basename(filename) =~ /(.*?)(@(.*?))?\.symbols/
+ module_name = Regexp.last_match[3] || Regexp.last_match[1]
+ {
+ filename =>
+ Graph.new(File.read(filename), module_name).to_sourcekit,
+ }
+ end.to_json
end
# Get the SDK path. On !darwin this just isn't needed.
def self.sdk(config)
`xcrun --show-sdk-path --sdk #{config.sdk}`.chomp