8000 Fixed find command not working on Windows. #167 · codecov/codecov-python@65d596e · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on May 21, 2025. It is now read-only.

Commit 65d596e

Browse files
committed
Fixed find command not working on Windows. #167
1 parent 94ae0a2 commit 65d596e

File tree

1 file changed

+33
-23
lines changed

1 file changed

+33
-23
lines changed

codecov/__init__.py

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import glob
77
import requests
88
import argparse
9+
import fnmatch
910
from time import sleep
1011
from json import loads
1112

@@ -228,6 +229,26 @@ def _add_env_if_not_empty(lst, value):
228229
lst.add(value)
229230

230231

232+
def find_files(directory, patterns, recursive=True, exclude_dirs=[]):
233+
if recursive:
234+
items = os.walk(directory, followlinks=False)
235+
else:
236+
items = [next(os.walk(directory, followLinks=False))]
237+
if not isinstance(patterns, list):
238+
patterns = [patterns]
239+
for root, dirs, files in items:
240+
dirs[:] = [d for d in dirs if d not in exclude_dirs]
241+
for basename in files:
242+
match = False
243+
for pattern in patterns:
244+
if fnmatch.fnmatch(basename, pattern):
245+
match = True
246+
break
247+
if match:
248+
filename = os.path.join(root, basename)
249+
yield filename
250+
251+
231252
def generate_toc(root):
232253
res = (
233254
try_to_run(["git", "ls-files"], cwd=root)
@@ -869,30 +890,19 @@ def main(*argv, **kwargs):
869890
write("XX> Skip processing gcov")
870891

871892
else:
872-
dont_search_here = (
873-
"-not -path './bower_components/**' "
874-
"-not -path './node_modules/**' "
875-
"-not -path './vendor/**'"
876-
)
877-
write("==> Processing gcov (disable by -X gcov)")
878-
cmd = [
879-
"find",
880-
(sanitize_arg("", codecov.gcov_root or root)),
881-
dont_search_here,
882-
"-type",
883-
"f",
884-
"-name",
885-
"*.gcno",
886-
" ".join(map(lambda a: "-not -path '%s'" % a, codecov.gcov_glob)),
887-
"-exec",
888-
(sanitize_arg("", codecov.gcov_exec or "")),
889-
"-pb",
890-
(sanitize_arg("", codecov.gcov_args or "")),
891-
"{}",
892-
"+",
893+
dont_search_here = [
894+
"bower_components"
895+
"node_modules"
896+
"vendor"
893897
]
894-
write(" Executing gcov (%s)" % cmd)
895-
try_to_run(cmd)
898+
if codecov.gcov_glob:
899+
dont_search_here.append(codecov.gcov_glob)
900+
901+
write("==> Processing gcov (disable by -X gcov)")
902+
for path in find_files(sanitize_arg("", codecov.gcov_root or root), "*.gcno", True, dont_search_here):
903+
cmd = sanitize_arg("", codecov.gcov_exec or "") + " -pb " + sanitize_arg("", codecov.gcov_args or "") + " " + path
904+
write(" Executing gcov (%s)" % cmd)
905+
write(try_to_run(cmd))
896906

897907
# Collect Reports
898908
# ---------------

0 commit comments

Comments
 (0)
0