2018-12-12 03:18:40 +03:00
#!/usr/bin/env python3
2019-06-27 07:57:20 +03:00
""" Compare the results of native and cross-compiled configure tests
2015-05-19 11:50:41 +03:00
2019-06-27 07:57:20 +03:00
The compared files are called " default.cache.py " and are generated in
bin / c4che / .
2015-05-19 11:50:41 +03:00
2019-06-27 07:57:20 +03:00
USAGE : compare_cc_results . py CONFIG_1 CONFIG_2 [ CONFIG_3 [ CONFIG_4 . . . ] ]
"""
2015-05-19 11:50:41 +03:00
import sys
import difflib
2017-04-07 10:26:53 +03:00
exceptions = [
' BUILD_DIRECTORY ' , ' SELFTEST_PREFIX ' , ' defines ' ,
' CROSS_COMPILE ' , ' CROSS_ANSWERS ' , ' CROSS_EXECUTE ' ,
' LIBSOCKET_WRAPPER_SO_PATH ' ,
' LIBNSS_WRAPPER_SO_PATH ' ,
2017-03-29 16:55:53 +03:00
' LIBPAM_WRAPPER_SO_PATH ' ,
2018-05-19 15:57:01 +03:00
' PAM_SET_ITEMS_SO_PATH ' ,
2017-04-07 10:26:53 +03:00
' LIBUID_WRAPPER_SO_PATH ' ,
' LIBRESOLV_WRAPPER_SO_PATH ' ,
]
2015-05-19 11:50:41 +03:00
2019-06-27 07:57:20 +03:00
if len ( sys . argv ) < 3 :
print ( __doc__ )
sys . exit ( 1 )
2015-05-19 11:50:41 +03:00
base_lines = list ( )
base_fname = ' '
found_diff = False
for fname in sys . argv [ 1 : ] :
lines = list ( )
f = open ( fname , ' r ' )
for line in f :
2017-04-15 19:56:11 +03:00
if line . startswith ( " cfg_files = " ) :
# waf writes configuration files as absolute paths
continue
2015-05-19 11:50:41 +03:00
if len ( line . split ( ' = ' , 1 ) ) == 2 :
key = line . split ( ' = ' , 1 ) [ 0 ] . strip ( )
2018-12-05 19:37:17 +03:00
value = line . split ( ' = ' , 1 ) [ 1 ] . strip ( )
2015-05-19 11:50:41 +03:00
if key in exceptions :
continue
2018-12-05 19:37:17 +03:00
# using waf with python 3.4 seems to randomly sort dict keys
# we can't modify the waf code but we can fake a dict value
# string representation as if it were sorted. python 3.6.5
# doesn't seem to suffer from this behaviour
if value . startswith ( ' { ' ) :
import ast
amap = ast . literal_eval ( value )
fakeline = " "
for k in sorted ( amap . keys ( ) ) :
if not len ( fakeline ) == 0 :
fakeline = fakeline + " , "
fakeline = fakeline + ' \' ' + k + ' \' : \' ' + amap [ k ] + ' \' '
line = key + ' = { ' + fakeline + ' } '
2015-05-19 11:50:41 +03:00
lines . append ( line )
f . close ( )
if base_fname :
2018-07-30 09:19:05 +03:00
diff = list ( difflib . unified_diff ( base_lines , lines , base_fname , fname ) )
2015-05-19 11:50:41 +03:00
if diff :
2018-03-09 17:06:21 +03:00
print ( ' configuration files %s and %s do not match ' % ( base_fname , fname ) )
2015-05-19 11:50:41 +03:00
for l in diff :
sys . stdout . write ( l )
found_diff = True
else :
base_fname = fname
base_lines = lines
if found_diff :
sys . exit ( 1 )