From 65d596e454d7a24fd0114418d1f13e6e5f66f0ee Mon Sep 17 00:00:00 2001 From: Nathan Moinvaziri Date: Wed, 6 Nov 2019 16:38:53 -0800 Subject: [PATCH] Fixed find command not working on Windows. #167 --- codecov/__init__.py | 56 ++++++++++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 23 deletions(-) diff --git a/codecov/__init__.py b/codecov/__init__.py index 2a2a3f69..37afd5a8 100644 --- a/codecov/__init__.py +++ b/codecov/__init__.py @@ -6,6 +6,7 @@ import glob import requests import argparse +import fnmatch from time import sleep from json import loads @@ -228,6 +229,26 @@ def _add_env_if_not_empty(lst, value): lst.add(value) +def find_files(directory, patterns, recursive=True, exclude_dirs=[]): + if recursive: + items = os.walk(directory, followlinks=False) + else: + items = [next(os.walk(directory, followLinks=False))] + if not isinstance(patterns, list): + patterns = [patterns] + for root, dirs, files in items: + dirs[:] = [d for d in dirs if d not in exclude_dirs] + for basename in files: + match = False + for pattern in patterns: + if fnmatch.fnmatch(basename, pattern): + match = True + break + if match: + filename = os.path.join(root, basename) + yield filename + + def generate_toc(root): res = ( try_to_run(["git", "ls-files"], cwd=root) @@ -869,30 +890,19 @@ def main(*argv, **kwargs): write("XX> Skip processing gcov") else: - dont_search_here = ( - "-not -path './bower_components/**' " - "-not -path './node_modules/**' " - "-not -path './vendor/**'" - ) - write("==> Processing gcov (disable by -X gcov)") - cmd = [ - "find", - (sanitize_arg("", codecov.gcov_root or root)), - dont_search_here, - "-type", - "f", - "-name", - "*.gcno", - " ".join(map(lambda a: "-not -path '%s'" % a, codecov.gcov_glob)), - "-exec", - (sanitize_arg("", codecov.gcov_exec or "")), - "-pb", - (sanitize_arg("", codecov.gcov_args or "")), - "{}", - "+", + dont_search_here = [ + "bower_components" + "node_modules" + "vendor" ] - write(" Executing gcov (%s)" % cmd) - try_to_run(cmd) + if codecov.gcov_glob: + dont_search_here.append(codecov.gcov_glob) + + write("==> Processing gcov (disable by -X gcov)") + for path in find_files(sanitize_arg("", codecov.gcov_root or root), "*.gcno", True, dont_search_here): + cmd = sanitize_arg("", codecov.gcov_exec or "") + " -pb " + sanitize_arg("", codecov.gcov_args or "") + " " + path + write(" Executing gcov (%s)" % cmd) + write(try_to_run(cmd)) # Collect Reports # ---------------