Skip to content

Commit

Permalink
Merge pull request #155 from fastlane-community/joshdholtz-xcresult-s…
Browse files Browse the repository at this point in the history
…upport

Add Xcode11 xcresult support
  • Loading branch information
Josh Holtz committed Sep 17, 2019
2 parents c567739 + 573aee2 commit ac248a1
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
33 changes: 29 additions & 4 deletions lib/xcov/manager.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
require 'fastlane_core'
require 'pty'
require 'open3'
require 'tmpdir'
require 'fileutils'
require 'terminal-table'
require 'xcov-core'
require 'pathname'
require 'json'
require 'xcresult'

module Xcov
class Manager
Expand Down Expand Up @@ -38,18 +40,26 @@ def run
def parse_xccoverage
# Find .xccoverage file
# If no xccov direct path, use the old derived data path method
if xccov_file_direct_path.nil?
if xccov_file_direct_paths.nil?
extension = Xcov.config[:legacy_support] ? "xccoverage" : "xccovreport"
test_logs_path = derived_data_path + "Logs/Test/"
xccoverage_files = Dir["#{test_logs_path}*.#{extension}", "#{test_logs_path}*.xcresult/*/action.#{extension}"].sort_by { |filename| File.mtime(filename) }.reverse

if xccoverage_files.empty?
xcresult_paths = Dir["#{test_logs_path}*.xcresult"].sort_by { |filename| File.mtime(filename) }.reverse
xcresult_paths.each do |xcresult_path|
xccoverage_files += export_paths_from_xcresult!(xcresult_path)
end
end

unless test_logs_path.directory? && !xccoverage_files.empty?
ErrorHandler.handle_error("XccoverageFileNotFound")
end
else
xccoverage_files = ["#{xccov_file_direct_path}"]
xccoverage_files = xccov_file_direct_paths
end


# Convert .xccoverage file to json
ide_foundation_path = Xcov.config[:legacy_support] ? nil : Xcov.config[:ideFoundationPath]
json_report = Xcov::Core::Parser.parse(xccoverage_files.first, Xcov.config[:output_directory], ide_foundation_path)
Expand Down Expand Up @@ -155,12 +165,27 @@ def derived_data_path
return product_builds_path.parent.parent
end

def xccov_file_direct_path
def xccov_file_direct_paths
# If xccov_file_direct_path was supplied, return
if Xcov.config[:xccov_file_direct_path].nil?
return nil
end
return Pathname.new(Xcov.config[:xccov_file_direct_path])

path = Xcov.config[:xccov_file_direct_path]
if File.extname(path) == '.xcresult'
return export_paths_from_xcresult!(path)
end

return [Pathname.new(path).to_s]
end

def export_paths_from_xcresult!(path)
parser = XCResult::Parser.new(path: path)
return parser.export_xccovreports(destination: Dir.mktmpdir)
rescue
UI.error("Error occured while exporting xccovreport from xcresult '#{path}'")
UI.error("Make sure you have both Xcode 11 selected and pointing to the correct xcresult file")
UI.crash!("Failed to export xccovreport from xcresult'")
end

end
Expand Down
6 changes: 3 additions & 3 deletions lib/xcov/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@ def self.available_options
key: :xccov_file_direct_path,
short_option: "-f",
env_name: "XCOV_FILE_DIRECT_PATH",
description: "The path to the xccoverage/xccovreport file to parse to generate code coverage",
description: "The path to the xccoverage/xccovreport/xcresult file to parse to generate code coverage",
optional: true,
verify_block: proc do |value|
v = File.expand_path(value.to_s)
raise "xccoverage/xccovreport file does not exist".red unless File.exist?(v)
raise "Invalid xccov file type (must be xccoverage or xccovreport)".red unless value.end_with? "xccoverage" or value.end_with? "xccovreport"
raise "xccoverage/xccovreport/xcresult file does not exist".red unless File.exist?(v)
raise "Invalid xccov file type (must be xccoverage, xccovreport, xcresult)".red unless value.end_with? "xccoverage" or value.end_with? "xccovreport" or value.end_with? "xcresult"
end
),
FastlaneCore::ConfigItem.new(
Expand Down
1 change: 1 addition & 0 deletions xcov.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Gem::Specification.new do |spec|
spec.add_dependency 'xcodeproj'
spec.add_dependency 'terminal-table'
spec.add_dependency 'multipart-post'
spec.add_dependency 'xcresult', '~> 0.1.1'

# Development only
spec.add_development_dependency "bundler"
Expand Down

0 comments on commit ac248a1

Please sign in to comment.