@@ -332,6 +332,25 @@ def generate_kconfig(idf_path, component_path):
332
332
return [remote_kconfig ]
333
333
334
334
335
+ def compare_files (base_dir , component_path , files_to_check ):
336
+ failures = []
337
+ for file_path in files_to_check :
338
+ relative_path = os .path .relpath (file_path , component_path )
339
+ base_file = os .path .join (base_dir , relative_path )
340
+
341
+ if not os .path .exists (base_file ):
342
+ failures .append ((relative_path , 'File does not exist in base directory' ))
343
+ continue
344
+
345
+ diff_cmd = ['diff' , '-I' , 'Copyright' , file_path , base_file ]
346
+ result = subprocess .run (diff_cmd , stdout = subprocess .PIPE , stderr = subprocess .PIPE )
347
+
348
+ if result .returncode != 0 : # diff returns 0 if files are identical
349
+ failures .append ((relative_path , result .stdout .decode ('utf-8' )))
350
+
351
+ return failures
352
+
353
+
335
354
if __name__ == '__main__' :
336
355
parser = argparse .ArgumentParser (
337
356
description = 'Build all projects' ,
@@ -346,6 +365,7 @@ def generate_kconfig(idf_path, component_path):
346
365
making changes you might need to modify 'copyright_header.h' in the script directory.
347
366
''' )
348
367
parser .add_argument ('-s' , '--skip-check' , help = 'Skip checking the versioned files against the re-generated' , action = 'store_true' )
368
+ parser .add_argument ('--base-dir' , help = 'Base directory to compare generated files against' , required = True )
349
369
args = parser .parse_args ()
350
370
351
371
component_path = os .path .normpath (os .path .join (os .path .realpath (__file__ ),'..' , '..' ))
@@ -371,21 +391,17 @@ def generate_kconfig(idf_path, component_path):
371
391
372
392
files_to_check += generate_kconfig (idf_path , component_path )
373
393
374
- fail_test = False
375
- failures = []
376
- for f in files_to_check :
377
- print (f'checking { f } ' )
378
- rc , out , err , cmd = exec_cmd (['git' , 'difftool' , '-y' , '-x' , 'diff -I Copyright' , '--' , f ])
379
- if out == '' or out .isspace ():
380
- print (' - ok' )
381
- else :
382
- print (' - FAILED!' )
383
- failures .append ((f , out ))
384
- fail_test = True
385
-
386
- if fail_test :
394
+ if args .skip_check :
395
+ exit (0 )
396
+
397
+ failures = compare_files (args .base_dir , component_path , files_to_check )
398
+
399
+ if failures :
387
400
print (parser .epilog )
388
- print ('\n DIfferent files:\n ' )
389
- for i in failures :
390
- print (f'{ i [ 0 ] } \n Changes:\n { i [ 1 ] } ' )
401
+ print ('\n Different files:\n ' )
402
+ for file , diff in failures :
403
+ print (f'{ file } \n Changes:\n { diff } ' )
391
404
exit (1 )
405
+ else :
406
+ print ('All files are identical to the base directory.' )
407
+ exit (0 )
0 commit comments