smbdotconf: mark "dfree command" with substitution="1"
[Samba.git] / script / compare_cc_results.py
blobcc16751cf6e95f9dd24c2d0edab62df448f3b0b2
1 #!/usr/bin/env python3
2 """Compare the results of native and cross-compiled configure tests
4 The compared files are called "default.cache.py" and are generated in
5 bin/c4che/.
7 USAGE: compare_cc_results.py CONFIG_1 CONFIG_2 [CONFIG_3 [CONFIG_4 ...]]
8 """
9 from __future__ import print_function
10 import sys
11 import difflib
13 exceptions = [
14 'BUILD_DIRECTORY', 'SELFTEST_PREFIX', 'defines',
15 'CROSS_COMPILE', 'CROSS_ANSWERS', 'CROSS_EXECUTE',
16 'LIBSOCKET_WRAPPER_SO_PATH',
17 'LIBNSS_WRAPPER_SO_PATH',
18 'LIBPAM_WRAPPER_SO_PATH',
19 'PAM_SET_ITEMS_SO_PATH',
20 'LIBUID_WRAPPER_SO_PATH',
21 'LIBRESOLV_WRAPPER_SO_PATH',
24 if len(sys.argv) < 3:
25 print(__doc__)
26 sys.exit(1)
28 base_lines = list()
29 base_fname = ''
31 found_diff = False
33 for fname in sys.argv[1:]:
34 lines = list()
35 f = open(fname, 'r')
36 for line in f:
37 if line.startswith("cfg_files ="):
38 # waf writes configuration files as absolute paths
39 continue
40 if len(line.split('=', 1)) == 2:
41 key = line.split('=', 1)[0].strip()
42 value = line.split('=', 1)[1].strip()
43 if key in exceptions:
44 continue
45 # using waf with python 3.4 seems to randomly sort dict keys
46 # we can't modify the waf code but we can fake a dict value
47 # string representation as if it were sorted. python 3.6.5
48 # doesn't seem to suffer from this behaviour
49 if value.startswith('{'):
50 import ast
51 amap = ast.literal_eval(value)
52 fakeline = ""
53 for k in sorted(amap.keys()):
54 if not len(fakeline) == 0:
55 fakeline = fakeline + ", "
56 fakeline = fakeline + '\'' + k + '\': \'' + amap[k] + '\''
57 line = key + ' = {' + fakeline + '}'
58 lines.append(line)
59 f.close()
60 if base_fname:
61 diff = list(difflib.unified_diff(base_lines, lines, base_fname, fname))
62 if diff:
63 print('configuration files %s and %s do not match' % (base_fname, fname))
64 for l in diff:
65 sys.stdout.write(l)
66 found_diff = True
67 else:
68 base_fname = fname
69 base_lines = lines
71 if found_diff:
72 sys.exit(1)