3
3
# Copyright (C) 2021-2024 SUSE
4
4
# Author: Marcos Paulo de Souza <[email protected] >
5
5
6
- import concurrent .futures
6
+ from concurrent .futures import ThreadPoolExecutor
7
7
import difflib as dl
8
8
import json
9
9
import logging
@@ -158,8 +158,7 @@ def get_make_cmd(out_dir, cs, filename, odir, sdir):
158
158
elif shutil .which ("gcc-7" ):
159
159
cc = "gcc-7"
160
160
else :
161
- logging .error ("Only gcc12 or higher are available, and it's problematic with kernel sources" )
162
- raise
161
+ raise RuntimeError ("Only gcc12 or higher are available, and it's problematic with kernel sources" )
163
162
164
163
make_args = [
165
164
"make" ,
@@ -187,9 +186,8 @@ def get_make_cmd(out_dir, cs, filename, odir, sdir):
187
186
f .write (str (completed ))
188
187
f .write ("\n " )
189
188
f .flush ()
190
- except subprocess .CalledProcessError as exc :
191
- logging .error (f"Failed to run make for { cs .name ()} ({ cs .kernel } ). Check file { str (log_path )} for more details." )
192
- raise exc
189
+ except Exception :
190
+ raise RuntimeError (f"Failed to run make for { cs .name ()} ({ cs .kernel } ). Check file { str (log_path )} for more details." )
193
191
194
192
# 15.4 onwards changes the regex a little: -MD -> -MMD
195
193
# 15.6 onwards we don't have -isystem.
@@ -210,9 +208,7 @@ def get_make_cmd(out_dir, cs, filename, odir, sdir):
210
208
f .flush ()
211
209
212
210
if not result :
213
- logging .error (f"Failed to get the kernel cmdline for file { str (ofname )} in { cs .name ()} . "
214
- f"Check file { str (log_path )} for more details." )
215
- return None
211
+ raise RuntimeError (f"Failed to get the kernel cmdline for file { str (ofname )} in { cs .name ()} . Check file { str (log_path )} for more details." )
216
212
217
213
ret = Extractor .process_make_output (result .group (1 ))
218
214
@@ -230,11 +226,8 @@ def get_make_cmd(out_dir, cs, filename, odir, sdir):
230
226
231
227
return ret
232
228
233
- return None
234
-
235
-
236
- # Generate the list of exported symbols
237
229
def get_symbol_list (self , out_dir ):
230
+ # Generate the list of exported symbols
238
231
exts = []
239
232
240
233
for ext_file in ["fun_exts" , "obj_exts" ]:
@@ -341,24 +334,25 @@ def apply_all_patches(self, cs, fil):
341
334
if not patched :
342
335
raise RuntimeError (f"{ cs .name ()} ({ cs .kernel } ): Failed to apply patches. Aborting" )
343
336
344
-
345
-
346
337
def get_cmd_from_json (self , cs , fname ):
347
- cc_file = Path (cs .get_obj_dir (), "compile_commands.json" )
348
- # FIXME: compile_commands.json that is packaged with SLE/openSUSE
349
- # doesn't quite work yet, so don't use it yet.
350
- return None
338
+ cc_file = cs .get_obj_dir ()/ "compile_commands.json"
339
+
340
+ # Older codestreams doens't support compile_commands.json, so use make for them
341
+ if not cc_file .exists ():
342
+ return None
351
343
352
344
with open (cc_file ) as f :
353
345
buf = f .read ()
354
346
data = json .loads (buf )
355
347
for d in data :
356
348
if fname in d ["file" ]:
357
349
output = d ["command" ]
358
- return Extractor .process_make_output (output )
350
+ # The arguments found on the file point to .., since they are generated
351
+ # when the kernel is compiled. Replace the .. by the codestream kernel source
352
+ # directory since klp-ccp needs to reach the files
353
+ return Extractor .process_make_output (output ).replace (".." , str (cs .get_src_dir ()))
359
354
360
- logging .error (f"Couldn't find cmdline for { fname } . Aborting" )
361
- return None
355
+ raise RuntimeError (f"Couldn't find cmdline for { fname } on { str (cc_file )} . Aborting" )
362
356
363
357
def cmd_args (self , cs , fname , out_dir , fdata , cmd ):
364
358
lp_out = Path (out_dir , cs .lp_out_file (self .lp_name , fname ))
@@ -439,13 +433,10 @@ def process(self, args):
439
433
# Make can regenerate fixdep for each file being processed per
440
434
# codestream, so avoid the TXTBUSY error by serializing the 'make -sn'
441
435
# calls. Make is pretty fast, so there isn't a real slow down here.
442
- with self .make_lock :
443
- cmd = self .get_cmd_from_json (cs , fname )
444
- if not cmd :
445
- cmd = Extractor .get_make_cmd (out_dir , cs , fname , odir , sdir )
446
-
436
+ cmd = self .get_cmd_from_json (cs , fname )
447
437
if not cmd :
448
- raise
438
+ with self .make_lock :
439
+ cmd = Extractor .get_make_cmd (out_dir , cs , fname , odir , sdir )
449
440
450
441
args , lenv = self .cmd_args (cs , fname , out_dir , fdata , cmd )
451
442
@@ -462,9 +453,8 @@ def process(self, args):
462
453
f .flush ()
463
454
try :
464
455
subprocess .run (args , cwd = odir , stdout = f , stderr = f , env = lenv , check = True )
465
- except :
466
- logging .error (f"Error when processing { cs .name ()} :{ fname } . Check file { out_log } for details." )
467
- raise
456
+ except Exception as exc :
457
+ raise RuntimeError (f"Error when processing { cs .name ()} :{ fname } . Check file { out_log } for details." ) from exc
468
458
469
459
cs .files [fname ]["ext_symbols" ] = self .get_symbol_list (out_dir )
470
460
@@ -511,15 +501,14 @@ def run(self):
511
501
logging .info (f"\n Generating livepatches for { len (args )} file(s) using { self .workers } workers..." )
512
502
logging .info ("\t \t Codestream\t File" )
513
503
514
- with concurrent .futures .ThreadPoolExecutor (max_workers = self .workers ) as executor :
515
- results = executor .map (self .process , args )
504
+ with ThreadPoolExecutor (max_workers = self .workers ) as executor :
516
505
try :
517
- for result in results :
518
- if result :
519
- logging . error ( f" { cs } : { result } " )
520
- except :
521
- executor . shutdown ()
522
- sys . exit ( 1 )
506
+ futures = executor . map ( self . process , args )
507
+ for future in futures :
508
+ if future :
509
+ logging . error ( future )
510
+ except Exception as exc :
511
+ raise RuntimeError ( str ( exc )) from exc
523
512
524
513
# Save the ext_symbols set by execute
525
514
store_codestreams (self .lp_name , working_cs )
0 commit comments