Skip to content

Commit

Permalink
add include and exclude config for coverage report (#213)
Browse files Browse the repository at this point in the history
* add include and exclude config for coverage report

* correct the typo
  • Loading branch information
TingDaoK authored Dec 13, 2022
1 parent 77e57b1 commit bd2cec4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ Usage: ```builder.pyz [build|inspect|<action-name>] [spec] [OPTIONS]```
* ```--build-dir DIR``` - Make a new directory to do all the build work in, instead of using the current directory
* ```--dump-config``` - Dumps the resultant config after merging all available options. Useful for debugging your project configuration.
* ```--cmake-extra``` - Extra cmake config arg applied to all projects. e.g ```--cmake-extra=-DBUILD_SHARED_LIBS=ON```. May be specified multiple times.
* ```--coverage``` - Generate the test coverage report and upload it to codecov. Only supported when using cmake and gcc as compiler, error out on other cases.
* ```--coverage``` - Generate the test coverage report and upload it to codecov. Only supported when using cmake and gcc as compiler, error out on other cases. Use `--coverage-include` and `--coverage-exclude` to report the needed coverage file. The default code coverage report will include everything in the `source/` directory
* ```--coverage-include``` - The relative (based on the project directory) path of files and folders to include in the test coverage report. May be specified multiple times.
* ```--coverage-exclude``` - The relative (based on the project directory) path of files and folders to exclude in the test coverage report. May be specified multiple times. Note: the include can override the exlucde path.

### Supported Targets:
* linux: x86|i686, x64|x86_64, armv6, armv7, arm64|armv8|aarch64|arm64v8
Expand Down
25 changes: 23 additions & 2 deletions builder/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from builder.core.scripts import Scripts
from builder.core.toolchain import Toolchain
from builder.core.host import current_os, current_host, current_arch, current_platform, normalize_target
from builder.core.util import UniqueList
import builder.core.data as data

import builder.core.api # force API to load and expose the virtual module
Expand Down Expand Up @@ -145,7 +146,14 @@ def parse_args():
parser.add_argument('--variant', type=str, help="Build variant to use instead of default")
parser.add_argument('--cmake-extra', action='append', default=[])
parser.add_argument('--coverage', action='store_true',
help="Enable test coverage report and upload it the codecov. Only supported when using cmake with gcc as compiler, error out on other cases.")
help="Enable test coverage report and upload it the codecov. Only supported when using cmake with gcc as compiler, error out on other cases.\n"
+ "Use --coverage-include and --coverage-exclude to report the needed coverage file. The default code coverage report will include everything in the `source/` directory")
parser.add_argument('--coverage-include', action='append', default=[],
help="The relative (based on the project directory) path of files and folders to include in the test coverage report.\n"
+ "The default code coverage report will include everything in the `source/` directory")
parser.add_argument('--coverage-exclude', action='append', default=[],
help="The relative (based on the project directory) path of files and folders (ends with `/`) to exlude from the test coverage report.\n"
+ "The default code coverage report will include everything in the `source/` directory")

# hand parse command and spec from within the args given
command = None
Expand Down Expand Up @@ -234,8 +242,21 @@ def upload_test_coverage(env):
# only works for linux for now
env.shell.exec('curl', '-Os', 'https://uploader.codecov.io/latest/linux/codecov', check=True)
env.shell.exec('chmod', '+x', 'codecov', check=True)
include_args = UniqueList(['source/'])
include_args += env.args.coverage_include
exclude_args = UniqueList(env.args.coverage_exclude)
uploader_args = []
for include in include_args:
include += '*'
uploader_args.append('-f')
uploader_args.append(include.replace("/", "#"))
for exclude in exclude_args:
exclude += '*'
exclude = "!" + exclude
uploader_args.append('-f')
uploader_args.append(exclude.replace("/", "#"))
# based on the way generated report, we only upload the report started with `source/`
env.shell.exec('./codecov', '-t', token, '-f', 'source#*', check=True)
env.shell.exec('./codecov', '-t', token, uploader_args, check=True)


def main():
Expand Down

0 comments on commit bd2cec4

Please sign in to comment.