-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy pathcreate-cov-rpt.py
More file actions
220 lines (178 loc) · 5.84 KB
/
create-cov-rpt.py
File metadata and controls
220 lines (178 loc) · 5.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
#!/usr/bin/env python
#
# Copyright 2019-2019 by Martin Moene
##!/usr/bin/env python
#
# Copyright 2019-2019 by Martin Moene
#
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#
# script/create-cov-rpt.py, Python 3.4 and later
#
import argparse
import os
import re
import sys
import subprocess
# Configuration:
cfg_github_project = 'optional-lite'
cfg_github_user = 'martinmoene'
cfg_prj_folder_level = 3
tpl_coverage_cmd = 'opencppcoverage --no_aggregate_by_file --sources {src} -- {exe}'
# End configuration.
def project_folder( f, args ):
"""Project root"""
if args.prj_folder:
return args.prj_folder
return os.path.normpath( os.path.join( os.path.dirname( os.path.abspath(f) ), '../' * args.prj_folder_level ) )
def executable_folder( f ):
"""Folder where the xecutable is"""
return os.path.dirname( os.path.abspath(f) )
def executable_name( f ):
"""Folder where the executable is"""
return os.path.basename( f )
def createCoverageReport( f, args ):
print( "Creating coverage report for project '{usr}/{prj}', '{file}':".
format( usr=args.user, prj=args.project, file=f ) )
cmd = tpl_coverage_cmd.format( folder=executable_folder(f), src=project_folder(f, args), exe=executable_name(f) )
if args.verbose:
print( "> {}".format(cmd) )
if not args.dry_run:
os.chdir( executable_folder(f) )
subprocess.call( cmd, shell=False )
os.chdir( project_folder(f, args) )
def createCoverageReports( args ):
for f in args.executable:
createCoverageReport( f, args )
def createCoverageReportFromCommandLine():
"""Collect arguments from the commandline and create coverage report."""
parser = argparse.ArgumentParser(
description='Create coverage report.',
epilog="""""",
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument(
'executable',
metavar='executable',
type=str,
nargs=1,
help='executable to report on')
parser.add_argument(
'-n', '--dry-run',
action='store_true',
help='do not execute conan commands')
parser.add_argument(
'-v', '--verbose',
action='count',
default=0,
help='level of progress reporting')
parser.add_argument(
'--user',
metavar='u',
type=str,
default=cfg_github_user,
help='github user name')
parser.add_argument(
'--project',
metavar='p',
type=str,
default=cfg_github_project,
help='github project name')
parser.add_argument(
'--prj-folder',
metavar='f',
type=str,
default=None,
help='project root folder')
parser.add_argument(
'--prj-folder-level',
metavar='n',
type=int,
default=cfg_prj_folder_level,
help='project root folder level from executable')
createCoverageReports( parser.parse_args() )
if __name__ == '__main__':
createCoverageReportFromCommandLine()
# end of file
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#
# script/create-cov-rpt.py, Python 3.4 and later
#
import argparse
import os
import re
import sys
import subprocess
# Configuration:
cfg_github_project = 'expected-lite'
cfg_github_user = 'martinmoene'
tpl_coverage_cmd = 'opencppcoverage --no_aggregate_by_file --sources {src} -- {exe}'
# End configuration.
def project_folder( f, args ):
"""Project root"""
if args.prj_folder:
return args.prj_folder
return os.path.normpath( os.path.join( os.path.dirname( os.path.abspath(f) ), '../../..') )
def executable_folder( f ):
"""Folder where the xecutable is"""
return os.path.dirname( os.path.abspath(f) )
def executable_name( f ):
"""Folder where the executable is"""
return os.path.basename( f )
def createCoverageReport( f, args ):
print( "Creating coverage report for project '{usr}/{prj}', '{file}':".
format( usr=args.user, prj=args.project, file=f ) )
cmd = tpl_coverage_cmd.format( folder=executable_folder(f), src=project_folder(f, args), exe=executable_name(f) )
if args.verbose:
print( "> {}".format(cmd) )
if not args.dry_run:
os.chdir( executable_folder(f) )
subprocess.call( cmd, shell=False )
os.chdir( project_folder(f, args) )
def createCoverageReports( args ):
for f in args.executable:
createCoverageReport( f, args )
def createCoverageReportFromCommandLine():
"""Collect arguments from the commandline and create coverage report."""
parser = argparse.ArgumentParser(
description='Create coverage report.',
epilog="""""",
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument(
'executable',
metavar='executable',
type=str,
nargs=1,
help='executable to report on')
parser.add_argument(
'-n', '--dry-run',
action='store_true',
help='do not execute conan commands')
parser.add_argument(
'-v', '--verbose',
action='count',
default=0,
help='level of progress reporting')
parser.add_argument(
'--user',
metavar='u',
type=str,
default=cfg_github_user,
help='github user name')
parser.add_argument(
'--project',
metavar='p',
type=str,
default=cfg_github_project,
help='github project name')
parser.add_argument(
'--prj-folder',
metavar='f',
type=str,
default=None,
help='project root folder')
createCoverageReports( parser.parse_args() )
if __name__ == '__main__':
createCoverageReportFromCommandLine()
# end of file