aboutsummaryrefslogtreecommitdiffstats
path: root/build/scripts
diff options
context:
space:
mode:
authorasatarin <asatarin@yandex-team.ru>2022-02-10 16:47:30 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:47:30 +0300
commitca04a556317a80ac802f38457a2292185282878b (patch)
treec0748b5dcbade83af788c0abfa89c0383d6b779c /build/scripts
parent4ca29390ac54b7877174de542de47532c67453b5 (diff)
downloadydb-ca04a556317a80ac802f38457a2292185282878b.tar.gz
Restoring authorship annotation for <asatarin@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'build/scripts')
-rw-r--r--build/scripts/coverage-info.py158
1 files changed, 79 insertions, 79 deletions
diff --git a/build/scripts/coverage-info.py b/build/scripts/coverage-info.py
index c43e7aeff8..94491d9256 100644
--- a/build/scripts/coverage-info.py
+++ b/build/scripts/coverage-info.py
@@ -12,18 +12,18 @@ GCNO_EXT = '.gcno'
def suffixes(path):
- """
- >>> list(suffixes('/a/b/c'))
- ['c', 'b/c', '/a/b/c']
- >>> list(suffixes('/a/b/c/'))
- ['c', 'b/c', '/a/b/c']
- >>> list(suffixes('/a'))
- ['/a']
- >>> list(suffixes('/a/'))
- ['/a']
- >>> list(suffixes('/'))
- []
- """
+ """
+ >>> list(suffixes('/a/b/c'))
+ ['c', 'b/c', '/a/b/c']
+ >>> list(suffixes('/a/b/c/'))
+ ['c', 'b/c', '/a/b/c']
+ >>> list(suffixes('/a'))
+ ['/a']
+ >>> list(suffixes('/a/'))
+ ['/a']
+ >>> list(suffixes('/'))
+ []
+ """
path = os.path.normpath(path)
def up_dirs(cur_path):
@@ -85,21 +85,21 @@ def print_stat(da, fnda, teamcity_stat_output):
tc_file.write("##teamcity[blockClosed name='Code Coverage Summary']\n")
-def chunks(l, n):
- """
- >>> list(chunks(range(10), 3))
- [[0, 1, 2], [3, 4, 5], [6, 7, 8], [9]]
- >>> list(chunks(range(10), 5))
- [[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]]
- """
- for i in xrange(0, len(l), n):
- yield l[i:i + n]
-
-
+def chunks(l, n):
+ """
+ >>> list(chunks(range(10), 3))
+ [[0, 1, 2], [3, 4, 5], [6, 7, 8], [9]]
+ >>> list(chunks(range(10), 5))
+ [[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]]
+ """
+ for i in xrange(0, len(l), n):
+ yield l[i:i + n]
+
+
def combine_info_files(lcov, files, out_file):
chunk_size = 50
files = list(set(files))
-
+
for chunk in chunks(files, chunk_size):
combine_cmd = [lcov]
if os.path.exists(out_file):
@@ -116,39 +116,39 @@ def combine_info_files(lcov, files, out_file):
os.rename(out_file_tmp, out_file)
-def probe_path_global(path, source_root, prefix_filter, exclude_files):
- if path.endswith('_ut.cpp'):
+def probe_path_global(path, source_root, prefix_filter, exclude_files):
+ if path.endswith('_ut.cpp'):
return None
- for suff in reversed(list(suffixes(path))):
- if (not prefix_filter or suff.startswith(prefix_filter)) and (not exclude_files or not exclude_files.match(suff)):
- full_path = source_root + os.sep + suff
- if os.path.isfile(full_path):
- return full_path
-
- return None
-
-
-def update_stat_global(src_file, line, fnda, da):
- if line.startswith("FNDA:"):
- visits, func_name = line[len("FNDA:"):].split(',')
- fnda[src_file + func_name] += int(visits)
-
- if line.startswith("DA"):
- line_number, visits = line[len("DA:"):].split(',')
- if visits == '=====':
- visits = 0
-
- da[src_file + line_number] += int(visits)
-
-
-def gen_info_global(cmd, cov_info, probe_path, update_stat, lcov_args):
- print >>sys.stderr, '## geninfo', ' '.join(cmd)
- subprocess.check_call(cmd)
- if recast(cov_info + '.tmp', cov_info, probe_path, update_stat):
- lcov_args.append(cov_info)
-
-
+ for suff in reversed(list(suffixes(path))):
+ if (not prefix_filter or suff.startswith(prefix_filter)) and (not exclude_files or not exclude_files.match(suff)):
+ full_path = source_root + os.sep + suff
+ if os.path.isfile(full_path):
+ return full_path
+
+ return None
+
+
+def update_stat_global(src_file, line, fnda, da):
+ if line.startswith("FNDA:"):
+ visits, func_name = line[len("FNDA:"):].split(',')
+ fnda[src_file + func_name] += int(visits)
+
+ if line.startswith("DA"):
+ line_number, visits = line[len("DA:"):].split(',')
+ if visits == '=====':
+ visits = 0
+
+ da[src_file + line_number] += int(visits)
+
+
+def gen_info_global(cmd, cov_info, probe_path, update_stat, lcov_args):
+ print >>sys.stderr, '## geninfo', ' '.join(cmd)
+ subprocess.check_call(cmd)
+ if recast(cov_info + '.tmp', cov_info, probe_path, update_stat):
+ lcov_args.append(cov_info)
+
+
def init_all_coverage_files(gcno_archive, fname2gcno, fname2info, geninfo_executable, gcov_tool, gen_info, prefix_filter, exclude_files):
with tarfile.open(gcno_archive) as gcno_tf:
for gcno_item in gcno_tf:
@@ -177,8 +177,8 @@ def init_all_coverage_files(gcno_archive, fname2gcno, fname2info, geninfo_execut
]
gen_info(geninfo_cmd, coverage_info)
-
-def process_all_coverage_files(gcda_archive, fname2gcno, fname2info, geninfo_executable, gcov_tool, gen_info):
+
+def process_all_coverage_files(gcda_archive, fname2gcno, fname2info, geninfo_executable, gcov_tool, gen_info):
with tarfile.open(gcda_archive) as gcda_tf:
for gcda_item in gcda_tf:
if gcda_item.isfile() and gcda_item.name.endswith(GCDA_EXT):
@@ -200,7 +200,7 @@ def process_all_coverage_files(gcda_archive, fname2gcno, fname2info, geninfo_exe
]
gen_info(geninfo_cmd, coverage_info)
-
+
def gen_cobertura(tool, output, combined_info):
cmd = [
tool,
@@ -215,28 +215,28 @@ def gen_cobertura(tool, output, combined_info):
def main(source_root, output, gcno_archive, gcda_archive, gcov_tool, prefix_filter, exclude_regexp, teamcity_stat_output, coverage_report_path, gcov_report, lcov_cobertura):
- exclude_files = re.compile(exclude_regexp) if exclude_regexp else None
-
- fname2gcno = {}
- fname2info = collections.defaultdict(list)
- lcov_args = []
- geninfo_executable = os.path.join(source_root, 'devtools', 'lcov', 'geninfo')
-
- def probe_path(path):
- return probe_path_global(path, source_root, prefix_filter, exclude_files)
-
- fnda = collections.defaultdict(int)
- da = collections.defaultdict(int)
-
- def update_stat(src_file, line):
- update_stat_global(src_file, line, da, fnda)
-
- def gen_info(cmd, cov_info):
- gen_info_global(cmd, cov_info, probe_path, update_stat, lcov_args)
-
+ exclude_files = re.compile(exclude_regexp) if exclude_regexp else None
+
+ fname2gcno = {}
+ fname2info = collections.defaultdict(list)
+ lcov_args = []
+ geninfo_executable = os.path.join(source_root, 'devtools', 'lcov', 'geninfo')
+
+ def probe_path(path):
+ return probe_path_global(path, source_root, prefix_filter, exclude_files)
+
+ fnda = collections.defaultdict(int)
+ da = collections.defaultdict(int)
+
+ def update_stat(src_file, line):
+ update_stat_global(src_file, line, da, fnda)
+
+ def gen_info(cmd, cov_info):
+ gen_info_global(cmd, cov_info, probe_path, update_stat, lcov_args)
+
init_all_coverage_files(gcno_archive, fname2gcno, fname2info, geninfo_executable, gcov_tool, gen_info, prefix_filter, exclude_files)
- process_all_coverage_files(gcda_archive, fname2gcno, fname2info, geninfo_executable, gcov_tool, gen_info)
-
+ process_all_coverage_files(gcda_archive, fname2gcno, fname2info, geninfo_executable, gcov_tool, gen_info)
+
if coverage_report_path:
output_dir = coverage_report_path
else: