2007-07-14 20:34:06 +04:00
|
|
|
"""Test the running system for features availability. Exit with zero
|
2007-08-09 01:07:39 +04:00
|
|
|
if all features are there, non-zero otherwise. If a feature name is
|
|
|
|
prefixed with "no-", the absence of feature is tested.
|
2007-07-14 20:34:06 +04:00
|
|
|
"""
|
2016-02-28 08:19:53 +03:00
|
|
|
|
2016-05-13 01:01:07 +03:00
|
|
|
from __future__ import absolute_import, print_function
|
2016-02-28 08:19:53 +03:00
|
|
|
|
2012-06-14 14:54:54 +04:00
|
|
|
import hghave
|
2016-05-13 01:01:07 +03:00
|
|
|
import optparse
|
|
|
|
import os
|
|
|
|
import sys
|
2007-07-14 20:34:06 +04:00
|
|
|
|
2012-06-14 14:54:54 +04:00
|
|
|
checks = hghave.checks
|
2007-07-14 20:34:06 +04:00
|
|
|
|
|
|
|
def list_features():
|
2016-05-05 12:12:26 +03:00
|
|
|
for name, feature in sorted(checks.items()):
|
2007-07-14 20:34:06 +04:00
|
|
|
desc = feature[1]
|
2016-02-28 08:19:53 +03:00
|
|
|
print(name + ':', desc)
|
2007-07-14 20:34:06 +04:00
|
|
|
|
2009-04-07 21:34:00 +04:00
|
|
|
def test_features():
|
|
|
|
failed = 0
|
2016-05-05 12:12:26 +03:00
|
|
|
for name, feature in checks.items():
|
2009-04-07 21:34:00 +04:00
|
|
|
check, _ = feature
|
|
|
|
try:
|
|
|
|
check()
|
2016-02-10 16:44:29 +03:00
|
|
|
except Exception as e:
|
2016-02-28 08:19:53 +03:00
|
|
|
print("feature %s failed: %s" % (name, e))
|
2009-04-07 21:34:00 +04:00
|
|
|
failed += 1
|
|
|
|
return failed
|
|
|
|
|
2007-07-14 20:34:06 +04:00
|
|
|
parser = optparse.OptionParser("%prog [options] [features]")
|
2009-04-07 21:34:00 +04:00
|
|
|
parser.add_option("--test-features", action="store_true",
|
|
|
|
help="test available features")
|
2007-07-14 20:34:06 +04:00
|
|
|
parser.add_option("--list-features", action="store_true",
|
|
|
|
help="list available features")
|
|
|
|
|
2015-08-22 20:37:38 +03:00
|
|
|
def _loadaddon():
|
2015-07-03 00:56:03 +03:00
|
|
|
if 'TESTDIR' in os.environ:
|
|
|
|
# loading from '.' isn't needed, because `hghave` should be
|
|
|
|
# running at TESTTMP in this case
|
|
|
|
path = os.environ['TESTDIR']
|
|
|
|
else:
|
|
|
|
path = '.'
|
|
|
|
|
|
|
|
if not os.path.exists(os.path.join(path, 'hghaveaddon.py')):
|
|
|
|
return
|
|
|
|
|
|
|
|
sys.path.insert(0, path)
|
|
|
|
try:
|
|
|
|
import hghaveaddon
|
2016-05-15 04:40:26 +03:00
|
|
|
assert hghaveaddon # silence pyflakes
|
2016-02-10 16:44:29 +03:00
|
|
|
except BaseException as inst:
|
2015-08-22 20:37:38 +03:00
|
|
|
sys.stderr.write('failed to import hghaveaddon.py from %r: %s\n'
|
|
|
|
% (path, inst))
|
2015-07-03 00:56:03 +03:00
|
|
|
sys.exit(2)
|
|
|
|
sys.path.pop(0)
|
|
|
|
|
2007-07-14 20:34:06 +04:00
|
|
|
if __name__ == '__main__':
|
|
|
|
options, args = parser.parse_args()
|
2015-08-22 20:37:38 +03:00
|
|
|
_loadaddon()
|
2007-07-14 20:34:06 +04:00
|
|
|
if options.list_features:
|
|
|
|
list_features()
|
|
|
|
sys.exit(0)
|
2007-08-07 12:24:33 +04:00
|
|
|
|
2009-04-07 21:34:00 +04:00
|
|
|
if options.test_features:
|
|
|
|
sys.exit(test_features())
|
|
|
|
|
2020-03-04 06:15:56 +03:00
|
|
|
# Exit code:
|
|
|
|
# - 2: internal error
|
|
|
|
# - 80: skipped (missing features)
|
2015-08-22 20:37:38 +03:00
|
|
|
hghave.require(args)
|