Swift package support

Description

It looks to me that codecov.io/bash script lacks support for uploading code coverage for Swift packages. I had not found any information regarding that on this forum, thus I decided to ask.

  1. Did anyone try to upload code coverage for Swift packages?
  2. Are there any plans to support them?

Repository

I run my experiments on the following repository, branch feature/swift_package_conversion.
https://github.com/wnagrodzki/SwiftLogger/tree/feature/swift_package_conversion

Versions

Safari Version 13.0.3 (15608.3.10.1.4). macOS Catalina 10.15.1 (19B88).

Additional Information

I tried passing .build/debug/codecov as directory to search for coverage reports, but the script did not find any.

$ curl --silent https://codecov.io/bash | bash -s -- -s .build/debug/codecov/

  _____          _
 / ____|        | |
| |     ___   __| | ___  ___ _____   __
| |    / _ \ / _` |/ _ \/ __/ _ \ \ / /
| |___| (_) | (_| |  __/ (_| (_) \ V /
 \_____\___/ \__,_|\___|\___\___/ \_/
                              Bash-8a28df4


==> Travis CI detected.
    project root: .
    Yaml not found, that's ok! Learn more at http://docs.codecov.io/docs/codecov-yaml
==> Running gcov in . (disable via -X gcov)
==> Python coveragepy not found
==> Searching for coverage reports in:
    + .build/debug/codecov/
--> No coverage report found.
    Please visit http://docs.codecov.io/docs/supported-languages

Testing package and printing code coverage

I confirmed it is possible to test Swift package and gather code coverage data.

  1. Clone the repository and checkout feature/swift_package_conversion branch
  2. Run unit tests and generate code coverage files $ swift test --enable-code-coverage
  3. Print code coverage $ xcrun llvm-cov report .build/debug/SwiftLoggerPackageTests.xctest/Contents/MacOS/SwiftLoggerPackageTests -instr-profile .build/debug/codecov/default.profdata
Filename                                                         Regions    Missed Regions     Cover   Functions  Missed Functions  Executed       Lines      Missed Lines     Cover
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Sources/SwiftLogger/LogStringConvertible.swift                         2                 0   100.00%           2                 0   100.00%           6                 0   100.00%
Sources/SwiftLogger/Logger.swift                                      14                 0   100.00%           5                 0   100.00%          24                 0   100.00%
Sources/SwiftLogger/Loggers/AgregateLogger.swift                       5                 0   100.00%           3                 0   100.00%           9                 0   100.00%
Sources/SwiftLogger/Loggers/ConsoleLogger.swift                        2                 2     0.00%           2                 2     0.00%           8                 8     0.00%
Sources/SwiftLogger/Loggers/DiskLogger/DiskLogger.swift               22                 4    81.82%          11                 4    63.64%          91                12    86.81%
Sources/SwiftLogger/Loggers/DiskLogger/Logrotate.swift                11                 0   100.00%           5                 0   100.00%          26                 0   100.00%
Sources/SwiftLogger/Loggers/DiskLogger/OSFileHandle.swift             20                20     0.00%           4                 4     0.00%          30                30     0.00%
Sources/SwiftLogger/Loggers/DiskLogger/OSFileManager.swift             2                 2     0.00%           2                 2     0.00%           6                 6     0.00%
Sources/SwiftLogger/Loggers/DiskLogger/SizeLimitedFile.swift           5                 0   100.00%           3                 0   100.00%          17                 0   100.00%
Sources/SwiftLogger/Loggers/NullLogger.swift                           3                 3     0.00%           3                 3     0.00%           8                 8     0.00%
Tests/SwiftLoggerTests/AgregateLoggerTests.swift                      13                 0   100.00%          13                 0   100.00%          31                 0   100.00%
Tests/SwiftLoggerTests/DiskLoggerTests.swift                          51                 3    94.12%          39                 3    92.31%         176                 9    94.89%
Tests/SwiftLoggerTests/LogStringConvertibleTests.swift                10                 0   100.00%          10                 0   100.00%          21                 0   100.00%
Tests/SwiftLoggerTests/LoggetTests.swift                              22                 1    95.45%          22                 1    95.45%          37                 1    97.30%
Tests/SwiftLoggerTests/LogrotateTests.swift                           41                 4    90.24%          41                 4    90.24%         142                11    92.25%
Tests/SwiftLoggerTests/SizeLimitedFileTests.swift                     24                 2    91.67%          24                 2    91.67%          67                 2    97.01%
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
TOTAL                                                                247                41    83.40%         189                25    86.77%         699                87    87.55%

Hi @wnagrodzki

You need to convert the files a bit, does to changes in XCode’s coverage file format, but we do support Swift.

Please give this repo a look: GitHub - codecov/swift-standard: Codecov coverage standard for Swift

Thank you @drazisil. I boiled down to generating file in lcov format.

xcrun llvm-cov export -format="lcov" .build/debug/SwiftLoggerPackageTests.xctest/Contents/MacOS/SwiftLoggerPackageTests -instr-profile .build/debug/codecov/default.profdata > info.lcov
bash <(curl https://codecov.io/bash)

@drazisil Thanks for pointing this out. Do you also have a solution on a platform where Xcode is not present. As you know swift can also be compiled on Linux. Since I use swift for the server this is something I’m really interested in. Currently I have a mac test running just to generate codecoverage. Would love to get rid of this.
Thanks so much in advance.

@fabianfett Install Swift on your linux distribution, this will provide swift and llvm-cov commands. Build and test your package, convert code coverage info to lcov format, then run the script provided by codecov.io.

swift build
swift test --enable-code-coverage
llvm-cov export -format="lcov" .build/debug/SwiftLoggerPackageTests.xctest -instr-profile .build/debug/codecov/default.profdata > info.lcov
bash <(curl https://codecov.io/bash)
3 Likes