@@ -107,9 +107,22 @@ def arg_parser():
107
107
)
108
108
parser .add_argument ("-i" , "--input" , help = "Input dump data" )
109
109
parser .add_argument ("-t" , dest = "gcov_tool" , help = "Path to gcov tool" )
110
- parser .add_argument ("-b" , dest = "base_dir" , help = "Compile base directory" )
111
- parser .add_argument ("-s" , dest = "gcno_dir" , help = "Directory containing gcno files" )
112
- parser .add_argument ("-a" , dest = "gcda_dir" , help = "Directory containing gcda files" )
110
+ parser .add_argument (
111
+ "-b" , dest = "base_dir" , default = os .getcwd (), help = "Compile base directory"
112
+ )
113
+ parser .add_argument (
114
+ "-s" ,
115
+ dest = "gcno_dir" ,
116
+ default = os .getcwd (),
117
+ help = "Directory containing gcno files" ,
118
+ )
119
+ parser .add_argument (
120
+ "-a" ,
121
+ dest = "gcda_dir" ,
122
+ default = os .getcwd (),
123
+ nargs = "+" ,
124
+ help = "Directory containing gcda files" ,
125
+ )
113
126
parser .add_argument ("--debug" , action = "store_true" , help = "Enable debug mode" )
114
127
parser .add_argument (
115
128
"-x" ,
@@ -118,7 +131,8 @@ def arg_parser():
118
131
help = "Only copy *.gcno and *.gcda files" ,
119
132
)
120
133
parser .add_argument (
121
- "gcov_dir" ,
134
+ "-o" ,
135
+ dest = "gcov_dir" ,
122
136
nargs = "?" ,
123
137
default = os .getcwd (),
124
138
help = "Directory to store gcov data and report" ,
@@ -132,12 +146,19 @@ def main():
132
146
133
147
root_dir = os .getcwd ()
134
148
gcov_dir = os .path .abspath (args .gcov_dir )
135
- gcno_dir = os .path .abspath (args .gcno_dir ) if args .gcno_dir else root_dir
136
- gcda_dir = os .path .abspath (args .gcda_dir ) if args .gcda_dir else root_dir
149
+ gcno_dir = os .path .abspath (args .gcno_dir )
150
+
151
+ if os .path .exists (gcov_dir ):
152
+ shutil .rmtree (gcov_dir )
153
+
154
+ os .makedirs (gcov_dir )
155
+
156
+ gcda_dir = []
157
+ for i in args .gcda_dir :
158
+ gcda_dir .append (os .path .abspath (i ))
137
159
138
160
coverage_file = os .path .join (gcov_dir , "coverage.info" )
139
161
result_dir = os .path .join (gcov_dir , "result" )
140
- gcov_data_dir = os .path .join (gcov_dir , "data" )
141
162
142
163
if args .debug :
143
164
debug_file = os .path .join (gcov_dir , "debug.log" )
@@ -146,11 +167,17 @@ def main():
146
167
if args .input :
147
168
parse_gcda_data (os .path .join (root_dir , args .input ))
148
169
149
- os . makedirs ( os . path . join ( gcov_dir , "data" ), exist_ok = True )
170
+ gcov_data_dir = []
150
171
151
172
# Collect gcno, gcda files
152
- copy_file_endswith (".gcno" , gcno_dir , gcov_data_dir )
153
- copy_file_endswith (".gcda" , gcda_dir , gcov_data_dir )
173
+ for i in gcda_dir :
174
+
175
+ dir = os .path .join (gcov_dir + "/data" , os .path .basename (i ))
176
+ gcov_data_dir .append (dir )
177
+ os .makedirs (dir )
178
+
179
+ copy_file_endswith (".gcno" , gcno_dir , dir )
180
+ copy_file_endswith (".gcda" , i , dir )
154
181
155
182
# Only copy files
156
183
if args .only_copy :
@@ -166,21 +193,26 @@ def main():
166
193
try :
167
194
168
195
# lcov collect coverage data to coverage_file
196
+ command = [
197
+ "lcov" ,
198
+ "-c" ,
199
+ "-o" ,
200
+ coverage_file ,
201
+ "--rc" ,
202
+ "lcov_branch_coverage=1" ,
203
+ "--gcov-tool" ,
204
+ args .gcov_tool ,
205
+ "--ignore-errors" ,
206
+ "gcov" ,
207
+ ]
208
+ for i in gcov_data_dir :
209
+ command .append ("-d" )
210
+ command .append (i )
211
+
212
+ print (command )
213
+
169
214
subprocess .run (
170
- [
171
- "lcov" ,
172
- "-c" ,
173
- "-d" ,
174
- gcov_data_dir ,
175
- "-o" ,
176
- coverage_file ,
177
- "--rc" ,
178
- "lcov_branch_coverage=1" ,
179
- "--gcov-tool" ,
180
- args .gcov_tool ,
181
- "--ignore-errors" ,
182
- "gcov" ,
183
- ],
215
+ command ,
184
216
check = True ,
185
217
stdout = sys .stdout ,
186
218
stderr = sys .stdout ,
@@ -214,7 +246,9 @@ def main():
214
246
print ("Failed to generate coverage file." )
215
247
sys .exit (1 )
216
248
217
- shutil .rmtree (gcov_data_dir )
249
+ for i in gcov_data_dir :
250
+ shutil .rmtree (i )
251
+
218
252
os .remove (coverage_file )
219
253
220
254
0 commit comments