1#!/usr/bin/env python
2
3# This code runs compatibly under Python 2 and 3.x for x >= 2.
4# Preserve this property!
5from __future__ import absolute_import, print_function, division
6
7import os
8
9always_on = [
10    'minimal',
11]
12
13always_off = [
14    'leapfetch',
15]
16
17other = [
18    'debug',
19    'chrpath',
20    'ipv6',
21    'manbuild',
22    'nostrip',
23    'slow',
24    'profiling',
25    'libQgpsmm',
26]
27
28knobs = [
29    'aivdm',
30    'ashtech',
31    'bluez',
32    'clientdebug',
33    'control_socket',
34    'controlsend',
35    'coveraging',
36    'dbus_export',
37    'earthmate',
38    'evermore',
39    'force_global',
40    'fury',
41    'fv18',
42    'garmin',
43    'garmintxt',
44    'geostar',
45    'gpsclock',
46    'gpsd',
47    'gpsdclients',
48    'itrax',
49    'libgpsmm',
50    'mtk3301',
51    'navcom',
52    'ncurses',
53    'netfeed',
54    'nmea0183',
55    'nmea2000',
56    'nofloats',
57    'ntp',
58    'ntpshm',
59    'ntrip',
60    'oceanserver',
61    'oncore',
62    'passthrough',
63    'pps',
64    'python',
65    'qt',
66    'reconfigure',
67    'rtcm104v2',
68    'rtcm104v3',
69    'shared',
70    'shm_export',
71    'sirf',
72    'socket_export',
73    'squelch',
74    'superstar2',
75    'systemd',
76    'timing',
77    'tnt',
78    'tripmate',
79    'tsip',
80    'ublox',
81    'usb',
82    'xgps',
83]
84
85
86def main(starting_number_of_options=0):
87    import itertools
88    import multiprocessing
89    import shutil
90    import subprocess
91
92    num_cpus = multiprocessing.cpu_count()
93    job_arg = '-j%d' % num_cpus
94
95    failed_configurations = []
96    dev_null = open('/dev/null', 'w')
97
98    def _run(command, phase):
99        if subprocess.call(command, stdout=dev_null) == 0:
100            return True
101        failed_configurations.append(command)
102        print(command)
103        with open('failed_%s_configs.txt' % phase, 'a') as failed_configs:
104            failed_configs.write(' '.join(command) + '\n')
105        return False
106
107    static_params = [key + '=on' for key in always_on]
108    static_params += [key + '=off' for key in always_off]
109
110    for i in range(starting_number_of_options, len(knobs)):
111        print('Testing at length {}'.format(i))
112
113        for row in itertools.combinations(knobs, i):
114            print(row)
115            params = static_params + [key + '=on' for key in row]
116
117            # print {'on_params': row, 'scons_params': params}
118
119            # Clean before clearing cached options, in case options
120            # affect what's cleaned.
121            subprocess.call(['scons', '-c'], stdout=dev_null)
122            # Now remove all the scons temporaries
123            try:
124                shutil.rmtree('.sconf_temp')
125            except OSError:
126                pass
127            for f in ['.sconsign.dblite', '.scons-option-cache']:
128                try:
129                    os.remove(f)
130                except OSError:
131                    pass
132
133            if _run(['scons', job_arg, 'build-all'] + params, 'build'):
134                _run(['scons', job_arg, 'check'] + params, 'check')
135
136    return failed_configurations
137
138
139if __name__ == '__main__':
140    failed = main(0)
141    for row in failed:
142        print(' '.join(row))
143