Show More
@@ -64,36 +64,4 b" if __name__ == '__main__':" | |||||
64 | if options.test_features: |
|
64 | if options.test_features: | |
65 | sys.exit(test_features()) |
|
65 | sys.exit(test_features()) | |
66 |
|
66 | |||
67 |
|
|
67 | hghave.require(args, options.quiet) | |
68 |
|
||||
69 | failures = 0 |
|
|||
70 |
|
||||
71 | def error(msg): |
|
|||
72 | global failures |
|
|||
73 | if not quiet: |
|
|||
74 | sys.stderr.write(msg + '\n') |
|
|||
75 | failures += 1 |
|
|||
76 |
|
||||
77 | for feature in args: |
|
|||
78 | negate = feature.startswith('no-') |
|
|||
79 | if negate: |
|
|||
80 | feature = feature[3:] |
|
|||
81 |
|
||||
82 | if feature not in checks: |
|
|||
83 | error('skipped: unknown feature: ' + feature) |
|
|||
84 | sys.exit(2) |
|
|||
85 |
|
||||
86 | check, desc = checks[feature] |
|
|||
87 | try: |
|
|||
88 | available = check() |
|
|||
89 | except Exception, e: |
|
|||
90 | error('hghave check failed: ' + feature) |
|
|||
91 | continue |
|
|||
92 |
|
||||
93 | if not negate and not available: |
|
|||
94 | error('skipped: missing feature: ' + desc) |
|
|||
95 | elif negate and available: |
|
|||
96 | error('skipped: system supports %s' % desc) |
|
|||
97 |
|
||||
98 | if failures != 0: |
|
|||
99 | sys.exit(1) |
|
@@ -17,6 +17,54 b' def check(name, desc):' | |||||
17 | return func |
|
17 | return func | |
18 | return decorator |
|
18 | return decorator | |
19 |
|
19 | |||
|
20 | def checkfeatures(features): | |||
|
21 | result = { | |||
|
22 | 'error': [], | |||
|
23 | 'missing': [], | |||
|
24 | 'skipped': [], | |||
|
25 | } | |||
|
26 | ||||
|
27 | for feature in features: | |||
|
28 | negate = feature.startswith('no-') | |||
|
29 | if negate: | |||
|
30 | feature = feature[3:] | |||
|
31 | ||||
|
32 | if feature not in checks: | |||
|
33 | result['missing'].append(feature) | |||
|
34 | continue | |||
|
35 | ||||
|
36 | check, desc = checks[feature] | |||
|
37 | try: | |||
|
38 | available = check() | |||
|
39 | except Exception: | |||
|
40 | result['error'].append('hghave check failed: %s' % feature) | |||
|
41 | continue | |||
|
42 | ||||
|
43 | if not negate and not available: | |||
|
44 | result['skipped'].append('missing feature: %s' % desc) | |||
|
45 | elif negate and available: | |||
|
46 | result['skipped'].append('system supports %s' % desc) | |||
|
47 | ||||
|
48 | return result | |||
|
49 | ||||
|
50 | def require(features, quiet=False): | |||
|
51 | """Require that features are available, exiting if not.""" | |||
|
52 | result = checkfeatures(features) | |||
|
53 | ||||
|
54 | if not quiet: | |||
|
55 | for missing in result['missing']: | |||
|
56 | sys.stderr.write('skipped: unknown feature: %s\n' % missing) | |||
|
57 | for msg in result['skipped']: | |||
|
58 | sys.stderr.write('skipped: %s\n' % msg) | |||
|
59 | for msg in result['error']: | |||
|
60 | sys.stderr.write('%s\n' % msg) | |||
|
61 | ||||
|
62 | if result['missing']: | |||
|
63 | sys.exit(2) | |||
|
64 | ||||
|
65 | if result['skipped'] or result['error']: | |||
|
66 | sys.exit(1) | |||
|
67 | ||||
20 | def matchoutput(cmd, regexp, ignorestatus=False): |
|
68 | def matchoutput(cmd, regexp, ignorestatus=False): | |
21 | """Return True if cmd executes successfully and its output |
|
69 | """Return True if cmd executes successfully and its output | |
22 | is matched by the supplied regular expression. |
|
70 | is matched by the supplied regular expression. |
General Comments 0
You need to be logged in to leave comments.
Login now