diff --git a/lib/xcov-core/bin/xcov-core b/lib/xcov-core/bin/xcov-core index b5d4f10..1a0362c 100755 Binary files a/lib/xcov-core/bin/xcov-core and b/lib/xcov-core/bin/xcov-core differ diff --git a/lib/xcov-core/version.rb b/lib/xcov-core/version.rb index cfc8754..609508f 100644 --- a/lib/xcov-core/version.rb +++ b/lib/xcov-core/version.rb @@ -1,5 +1,5 @@ module Xcov module Core - VERSION = "0.7" + VERSION = "0.8" end end diff --git a/lib/xcov/manager.rb b/lib/xcov/manager.rb index 7435574..7e89193 100755 --- a/lib/xcov/manager.rb +++ b/lib/xcov/manager.rb @@ -40,6 +40,11 @@ def run end def parse_xccoverage + xccoverage_files = [] + + # xcresults to parse and export after collecting + xcresults_to_parse_and_export = [] + # Find .xccoverage file # If no xccov direct path, use the old derived data path method if xccov_file_direct_paths.nil? @@ -50,17 +55,36 @@ def parse_xccoverage 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) + xcresults_to_parse_and_export << xcresult_path end end - unless test_logs_path.directory? && !xccoverage_files.empty? + unless test_logs_path.directory? ErrorHandler.handle_error("XccoverageFileNotFound") end else - xccoverage_files = xccov_file_direct_paths + # Iterate over direct paths and find .xcresult files + # that need to be processed before getting coverage + xccov_file_direct_paths.each do |path| + if File.extname(path) == '.xcresult' + xcresults_to_parse_and_export << path + else + xccoverage_files << path + end + end + end + + # Iterates over xcresults + # Exports .xccovarchives + # Exports .xccovreports and collects the paths + unless xcresults_to_parse_and_export.empty? + xccoverage_files = process_xcresults!(xcresults_to_parse_and_export) end + # Errors if no coverage files were found + if xccoverage_files.empty? + ErrorHandler.handle_error("XccoverageFileNotFound") + end # Convert .xccoverage file to json ide_foundation_path = Xcov.config[:legacy_support] ? nil : Xcov.config[:ideFoundationPath] @@ -174,21 +198,36 @@ def xccov_file_direct_paths end 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 + def process_xcresults!(xcresult_paths) + output_path = Xcov.config[:output_directory] + FileUtils.mkdir_p(output_path) + + return xcresult_paths.flat_map do |xcresult_path| + begin + parser = XCResult::Parser.new(path: xcresult_path) + + # Exporting to same directory as xcresult + archive_paths = parser.export_xccovarchives(destination: output_path) + report_paths = parser.export_xccovreports(destination: output_path) + + # Informating user of export paths + archive_paths.each do |path| + UI.important("Copying .xccovarchive to #{path}") + end + report_paths.each do |path| + UI.important("Copying .xccovreport to #{path}") + end + report_paths + rescue + UI.error("Error occured while exporting xccovreport from xcresult '#{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 + end end end diff --git a/lib/xcov/model/target.rb b/lib/xcov/model/target.rb index 59d1175..fd6369a 100644 --- a/lib/xcov/model/target.rb +++ b/lib/xcov/model/target.rb @@ -7,10 +7,10 @@ class Target < Xcov::Base attr_accessor :files attr_accessor :file_templates - def initialize(name, coverage, files) + def initialize(name, files) @name = CGI::escapeHTML(name) @files = files - @coverage = coverage + @coverage = files.count == 0 ? 0.0 : files.reduce(0) { |acc, file| acc + file.coverage.to_f } / files.count @displayable_coverage = self.create_displayable_coverage @coverage_color = self.create_coverage_color @id = Target.create_id(name) @@ -53,12 +53,11 @@ def json_value def self.map(dictionary) name = dictionary["name"] - coverage = dictionary["coverage"] files = dictionary["files"].map { |file| Source.map(file)} files = files.sort &by_coverage_with_ignored_at_the_end non_ignored_files = Target.select_non_ignored_files(files) - Target.new(name, coverage, non_ignored_files) + Target.new(name, non_ignored_files) end def self.by_coverage_with_ignored_at_the_end diff --git a/lib/xcov/options.rb b/lib/xcov/options.rb index a7a19f8..9f0887b 100755 --- a/lib/xcov/options.rb +++ b/lib/xcov/options.rb @@ -93,6 +93,14 @@ def self.available_options default_value: File.join(containing, "xcov_report"), default_value_dynamic: true ), + FastlaneCore::ConfigItem.new( + key: :cloned_source_packages_path, + short_option: "-C", + env_name: "XCOV_CLONED_SOURCE_PACKAGES_PATH", + description: "Sets a custom path for Swift Package Manager dependencies", + type: String, + optional: true + ), # Report options FastlaneCore::ConfigItem.new( diff --git a/lib/xcov/version.rb b/lib/xcov/version.rb index e204d78..74f16fe 100755 --- a/lib/xcov/version.rb +++ b/lib/xcov/version.rb @@ -1,7 +1,6 @@ module Xcov - VERSION = "1.6.1" - + VERSION = "1.7.3" DESCRIPTION = "xcov is a friendly visualizer for Xcode's code coverage files" end diff --git a/xcov.gemspec b/xcov.gemspec index 60c1a36..188823e 100755 --- a/xcov.gemspec +++ b/xcov.gemspec @@ -21,12 +21,12 @@ Gem::Specification.new do |spec| spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) spec.require_paths = ["lib"] - spec.add_dependency 'fastlane', '>= 2.82.0', '< 3.0.0' + spec.add_dependency 'fastlane', '>= 2.141.0', '< 3.0.0' spec.add_dependency 'slack-notifier' spec.add_dependency 'xcodeproj' spec.add_dependency 'terminal-table' spec.add_dependency 'multipart-post' - spec.add_dependency 'xcresult', '~> 0.1.1' + spec.add_dependency 'xcresult', '~> 0.2.0' # Development only spec.add_development_dependency "bundler"