diff --git a/README.md b/README.md index dd1c3ad5b..d01c2f769 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,9 @@ Usage: ```builder.pyz [build|inspect|] [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 diff --git a/builder/main.py b/builder/main.py index 750598d43..300dec7a0 100755 --- a/builder/main.py +++ b/builder/main.py @@ -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 @@ -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 @@ -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():