Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/slather/command/coverage_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ def project
xcodeproj_path_to_open = xcodeproj_path || Slather::Project.yml["xcodeproj"]
if xcodeproj_path_to_open
project = Slather::Project.open(xcodeproj_path_to_open)
elsif File.exist?("Package.swift")
project = Slather::Project.open(".")
else
raise StandardError, "Must provide an xcodeproj either via the 'slather [SUBCOMMAND] [PROJECT].xcodeproj' command or through .slather.yml"
end
Expand Down
28 changes: 25 additions & 3 deletions lib/slather/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ class Project < Xcodeproj::Project
alias_method :setup_for_coverage, :slather_setup_for_coverage

def self.open(xcodeproj)
proj = super
if File.directory?(xcodeproj) && File.exist?(File.join(xcodeproj, "Package.swift"))
proj = self.new(xcodeproj)
else
proj = super
end
proj.xcodeproj = xcodeproj
proj
end
Expand Down Expand Up @@ -86,7 +90,11 @@ def derived_data_path
end

if derived_data_path == nil
derived_data_path = File.expand_path('~') + "/Library/Developer/Xcode/DerivedData/"
if File.exist?(File.join(self.xcodeproj, "Package.swift"))
derived_data_path = File.join(self.xcodeproj, ".build")
else
derived_data_path = File.expand_path('~') + "/Library/Developer/Xcode/DerivedData/"
end
end

derived_data_path
Expand Down Expand Up @@ -205,10 +213,13 @@ def create_profdata(binary_path, pathnames)
private :create_profdata

def remove_extension(path)
return "" if self.products.nil? || self.products.empty?
path.split(".")[0..-2].join(".")
end

def first_product_name
# If products is nil it means we are likely using a Swift Package and not an xcodeproj
return "" if self.products.nil? || self.products.empty?
first_product = self.products.first
# If name is not available it computes it using
# the path by dropping the 'extension' of the path.
Expand All @@ -220,11 +231,19 @@ def profdata_coverage_dir
raise StandardError, "The specified build directory (#{self.build_directory}) does not exist" unless File.exist?(self.build_directory)
dir = nil
if self.scheme
dir = Dir[File.join(build_directory,"/**/CodeCoverage/#{self.scheme}")].first
product_name = first_product_name
if !product_name.empty?
dir = Dir[File.join(build_directory,"/**/#{product_name}")].first
end.first
else
dir = Dir[File.join(build_directory,"/**/#{first_product_name}")].first
end

if dir == nil
# Swift Package Manager
dir = Dir[File.join(build_directory,"/**/codecov")].first
end

if dir == nil
# Xcode 7.3 moved the location of Coverage.profdata
dir = Dir[File.join(build_directory,"/**/CodeCoverage")].first
Expand Down Expand Up @@ -383,6 +402,9 @@ def configure_source_directory
end

def configure_output_directory
if self.source_directory.nil? && File.exist?(File.join(self.xcodeproj, "Package.swift"))
self.source_directory = self.xcodeproj
end
self.output_directory ||= self.class.yml["output_directory"] if self.class.yml["output_directory"]
end

Expand Down