Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slather not working for projects with single source file #376

Closed
darrarski opened this issue Mar 31, 2018 · 2 comments
Closed

Slather not working for projects with single source file #376

darrarski opened this issue Mar 31, 2018 · 2 comments

Comments

@darrarski
Copy link

darrarski commented Mar 31, 2018

I have a problem with Slather in one of my iOS app projects. It fails with error when generating report:

Processing coverage file: /Users/darrarski/Library/Developer/Xcode/DerivedData/MyProject-efhmagkskbeguggstcnkdsjuvfzu/Build/ProfileData/BBE3075A-51D0-48FA-B620-41EDD8D0A149/Coverage.profdata
Against binary files:
	/Users/darrarski/Library/Developer/Xcode/DerivedData/MyProject-efhmagkskbeguggstcnkdsjuvfzu/Build/Products/Debug-iphonesimulator/MyProject.app/MyProject

/Users/darrarski/.rvm/gems/ruby-2.4.1/gems/slather-2.4.5/lib/slather/coverage_info.rb:74:in `realpath': No such file or directory @ realpath_rec - /Users/darrarski/Dev/MyProject/    1|       |import UIKit (Errno::ENOENT)
	from /Users/darrarski/.rvm/gems/ruby-2.4.1/gems/slather-2.4.5/lib/slather/coverage_info.rb:74:in `realpath'
	from /Users/darrarski/.rvm/gems/ruby-2.4.1/gems/slather-2.4.5/lib/slather/coverage_info.rb:74:in `source_file_pathname_relative_to_repo_root'
	from /Users/darrarski/.rvm/gems/ruby-2.4.1/gems/slather-2.4.5/lib/slather/coverage_service/html_output.rb:104:in `block (4 levels) in create_index_html'
	from /Users/darrarski/.rvm/gems/ruby-2.4.1/gems/slather-2.4.5/lib/slather/coverage_service/html_output.rb:103:in `each'
	from /Users/darrarski/.rvm/gems/ruby-2.4.1/gems/slather-2.4.5/lib/slather/coverage_service/html_output.rb:103:in `block (3 levels) in create_index_html'
	from /Users/darrarski/.rvm/gems/ruby-2.4.1/gems/nokogiri-1.8.2/lib/nokogiri/xml/builder.rb:391:in `insert'
	from /Users/darrarski/.rvm/gems/ruby-2.4.1/gems/nokogiri-1.8.2/lib/nokogiri/xml/builder.rb:375:in `method_missing'
	from /Users/darrarski/.rvm/gems/ruby-2.4.1/gems/slather-2.4.5/lib/slather/coverage_service/html_output.rb:102:in `block (2 levels) in create_index_html'
	from /Users/darrarski/.rvm/gems/ruby-2.4.1/gems/nokogiri-1.8.2/lib/nokogiri/xml/builder.rb:391:in `insert'
	from /Users/darrarski/.rvm/gems/ruby-2.4.1/gems/nokogiri-1.8.2/lib/nokogiri/xml/builder.rb:375:in `method_missing'
	from /Users/darrarski/.rvm/gems/ruby-2.4.1/gems/slather-2.4.5/lib/slather/coverage_service/html_output.rb:89:in `block in create_index_html'
	from /Users/darrarski/.rvm/gems/ruby-2.4.1/gems/nokogiri-1.8.2/lib/nokogiri/xml/builder.rb:293:in `initialize'
	from /Users/darrarski/.rvm/gems/ruby-2.4.1/gems/nokogiri-1.8.2/lib/nokogiri/xml/builder.rb:254:in `new'
	from /Users/darrarski/.rvm/gems/ruby-2.4.1/gems/nokogiri-1.8.2/lib/nokogiri/xml/builder.rb:254:in `with'
	from /Users/darrarski/.rvm/gems/ruby-2.4.1/gems/slather-2.4.5/lib/slather/coverage_service/html_output.rb:78:in `create_index_html'
	from /Users/darrarski/.rvm/gems/ruby-2.4.1/gems/slather-2.4.5/lib/slather/coverage_service/html_output.rb:48:in `create_html_reports'
	from /Users/darrarski/.rvm/gems/ruby-2.4.1/gems/slather-2.4.5/lib/slather/coverage_service/html_output.rb:26:in `post'
	from /Users/darrarski/.rvm/gems/ruby-2.4.1/gems/slather-2.4.5/lib/slather/command/coverage_command.rb:97:in `post'
	from /Users/darrarski/.rvm/gems/ruby-2.4.1/gems/slather-2.4.5/lib/slather/command/coverage_command.rb:59:in `execute'
	from /Users/darrarski/.rvm/gems/ruby-2.4.1/gems/clamp-0.6.5/lib/clamp/command.rb:67:in `run'
	from /Users/darrarski/.rvm/gems/ruby-2.4.1/gems/clamp-0.6.5/lib/clamp/subcommand/execution.rb:11:in `execute'
	from /Users/darrarski/.rvm/gems/ruby-2.4.1/gems/clamp-0.6.5/lib/clamp/command.rb:67:in `run'
	from /Users/darrarski/.rvm/gems/ruby-2.4.1/gems/clamp-0.6.5/lib/clamp/command.rb:132:in `run'
	from /Users/darrarski/.rvm/gems/ruby-2.4.1/gems/slather-2.4.5/bin/slather:17:in `<top (required)>'
	from /Users/darrarski/.rvm/gems/ruby-2.4.1/bin/slather:23:in `load'
	from /Users/darrarski/.rvm/gems/ruby-2.4.1/bin/slather:23:in `<main>'
	from /Users/darrarski/.rvm/gems/ruby-2.4.1/bin/ruby_executable_hooks:15:in `eval'
	from /Users/darrarski/.rvm/gems/ruby-2.4.1/bin/ruby_executable_hooks:15:in `<main>'

I tried to investigate the issue myself, but I am not familiar with Ruby enough to solve it :-(

However, I found that this function from /lib/slather/profdata_coverage_file.rb:

module Slather
  class ProfdataCoverageFile
  ...
  def source_file_pathname
      @source_file_pathname ||= begin
        if path_on_first_line?
          path = self.source.split("\n")[0].sub ":", ""  # <<<===
          path &&= Pathname(path)
        else
        ...
  end
  ...
end

returns 1| |import UIKit which looks like first line of some Swift source code file, instead of path to that file.

I would be really thankful for any hints of steps I can take to solve this issue.

Here is my setup:
Xcode 9.3 / Swift 4.1
Ruby 2.4.1 (from RVM)
Slather 2.4.5
Fastlane 2.88.0 (I am running Slather from it)

Xcode is generating code coverage correctly. I am using correctly configured build scheme. I didn't notice any other issues with Fastlane (building, deploying etc) - everything else works like a charm.

@darrarski
Copy link
Author

darrarski commented Mar 31, 2018

I manage to solve the issue, which apparently is connected to the comment in /lib/slather/profdata_coverage_file.rb file:

    def source_file_pathname
      @source_file_pathname ||= begin
        if path_on_first_line?
          path = self.source.split("\n")[0].sub ":", ""
          path &&= Pathname(path)
        else
          # llvm-cov was run with just one matching source file
          # It doesn't print the source path in this case, so we have to find it ourselves
          # This is slow because we read every source file and compare it, but this should only happen if there aren't many source files
          digest = Digest::MD5.digest(self.raw_source)
          path = nil

          project.find_source_files.each do |file|
            file_digest = Digest::MD5.digest(File.read(file).strip)

            if digest == file_digest
              path = file
            end
          end
          
          path
        end
      end
    end

My project contained only one Swift file. After adding another one, everything is working like expected, the problem disappeared.

I think the issue is still valid for projects with one source file. The else block that contains comment mentioned above is not executed in such case (I assume that it should be).

@darrarski darrarski changed the title Invalid source_file_pathname Slather not working for projects with single source file Mar 31, 2018
blackm00n added a commit to blackm00n/slather that referenced this issue Apr 3, 2018
blackm00n added a commit to blackm00n/slather that referenced this issue Apr 3, 2018
blackm00n added a commit to blackm00n/slather that referenced this issue Apr 3, 2018
@ksuther
Copy link
Contributor

ksuther commented Apr 8, 2018

Should be fixed by #377

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants