# Swift package support

**URL:** https://community.codecov.com/t/swift-package-support/675
**Category:** Support
**Tags:** swift
**Created:** [November 6, 2019, 6:30pm UTC](https://community.codecov.com/t/swift-package-support/675 "2019-11-06T18:30:25Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![wnagrodzki](https://avatars.discourse-cdn.com/v4/letter/w/3da27b/32.png) [@wnagrodzki](https://community.codecov.com/u/wnagrodzki)
#### Post date: [November 6, 2019, 6:30pm UTC](https://community.codecov.com/t/swift-package-support/675/1 "2019-11-06T18:30:26Z")

</div>

### Description

It looks to me that [codecov.io/bash](http://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](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.

```auto
$ 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`

```auto
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%

```

---

<div class="post-metadata">

### Author: ![drazisil](https://yyz1.discourse-cdn.com/flex029/user_avatar/community.codecov.com/drazisil/32/496_2.png) [@drazisil](https://community.codecov.com/u/drazisil)
#### Post date: [November 6, 2019, 6:34pm UTC](https://community.codecov.com/t/swift-package-support/675/2 "2019-11-06T18:34:41Z")

</div>

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](https://github.com/codecov/swift-standard)

---

<div class="post-metadata">

### Author: ![wnagrodzki](https://avatars.discourse-cdn.com/v4/letter/w/3da27b/32.png) [@wnagrodzki](https://community.codecov.com/u/wnagrodzki)
#### Post date: [November 10, 2019, 9:41am UTC](https://community.codecov.com/t/swift-package-support/675/3 "2019-11-10T09:41:50Z")

</div>

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)
```

---

<div class="post-metadata">

### Author: ![fabianfett](https://yyz1.discourse-cdn.com/flex029/user_avatar/community.codecov.com/fabianfett/32/387_2.png) [@fabianfett](https://community.codecov.com/u/fabianfett)
#### Post date: [November 14, 2019, 3:15pm UTC](https://community.codecov.com/t/swift-package-support/675/4 "2019-11-14T15:15:34Z")

</div>

@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.

---

<div class="post-metadata">

### Author: ![wnagrodzki](https://avatars.discourse-cdn.com/v4/letter/w/3da27b/32.png) [@wnagrodzki](https://community.codecov.com/u/wnagrodzki)
#### Post date: [November 17, 2019, 7:31am UTC](https://community.codecov.com/t/swift-package-support/675/5 "2019-11-17T07:31:19Z")

</div>

@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](http://codecov.io).

```auto
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)

```
