##// END OF EJS Templates
hghave: fix typo of sslutil.supportedprotocols
Yuya Nishihara -
r29611:33463238 stable
parent child Browse files
Show More
@@ -1,561 +1,561 b''
1 from __future__ import absolute_import
1 from __future__ import absolute_import
2
2
3 import errno
3 import errno
4 import os
4 import os
5 import re
5 import re
6 import socket
6 import socket
7 import stat
7 import stat
8 import subprocess
8 import subprocess
9 import sys
9 import sys
10 import tempfile
10 import tempfile
11
11
12 tempprefix = 'hg-hghave-'
12 tempprefix = 'hg-hghave-'
13
13
14 checks = {
14 checks = {
15 "true": (lambda: True, "yak shaving"),
15 "true": (lambda: True, "yak shaving"),
16 "false": (lambda: False, "nail clipper"),
16 "false": (lambda: False, "nail clipper"),
17 }
17 }
18
18
19 def check(name, desc):
19 def check(name, desc):
20 """Registers a check function for a feature."""
20 """Registers a check function for a feature."""
21 def decorator(func):
21 def decorator(func):
22 checks[name] = (func, desc)
22 checks[name] = (func, desc)
23 return func
23 return func
24 return decorator
24 return decorator
25
25
26 def checkvers(name, desc, vers):
26 def checkvers(name, desc, vers):
27 """Registers a check function for each of a series of versions.
27 """Registers a check function for each of a series of versions.
28
28
29 vers can be a list or an iterator"""
29 vers can be a list or an iterator"""
30 def decorator(func):
30 def decorator(func):
31 def funcv(v):
31 def funcv(v):
32 def f():
32 def f():
33 return func(v)
33 return func(v)
34 return f
34 return f
35 for v in vers:
35 for v in vers:
36 v = str(v)
36 v = str(v)
37 f = funcv(v)
37 f = funcv(v)
38 checks['%s%s' % (name, v.replace('.', ''))] = (f, desc % v)
38 checks['%s%s' % (name, v.replace('.', ''))] = (f, desc % v)
39 return func
39 return func
40 return decorator
40 return decorator
41
41
42 def checkfeatures(features):
42 def checkfeatures(features):
43 result = {
43 result = {
44 'error': [],
44 'error': [],
45 'missing': [],
45 'missing': [],
46 'skipped': [],
46 'skipped': [],
47 }
47 }
48
48
49 for feature in features:
49 for feature in features:
50 negate = feature.startswith('no-')
50 negate = feature.startswith('no-')
51 if negate:
51 if negate:
52 feature = feature[3:]
52 feature = feature[3:]
53
53
54 if feature not in checks:
54 if feature not in checks:
55 result['missing'].append(feature)
55 result['missing'].append(feature)
56 continue
56 continue
57
57
58 check, desc = checks[feature]
58 check, desc = checks[feature]
59 try:
59 try:
60 available = check()
60 available = check()
61 except Exception:
61 except Exception:
62 result['error'].append('hghave check failed: %s' % feature)
62 result['error'].append('hghave check failed: %s' % feature)
63 continue
63 continue
64
64
65 if not negate and not available:
65 if not negate and not available:
66 result['skipped'].append('missing feature: %s' % desc)
66 result['skipped'].append('missing feature: %s' % desc)
67 elif negate and available:
67 elif negate and available:
68 result['skipped'].append('system supports %s' % desc)
68 result['skipped'].append('system supports %s' % desc)
69
69
70 return result
70 return result
71
71
72 def require(features):
72 def require(features):
73 """Require that features are available, exiting if not."""
73 """Require that features are available, exiting if not."""
74 result = checkfeatures(features)
74 result = checkfeatures(features)
75
75
76 for missing in result['missing']:
76 for missing in result['missing']:
77 sys.stderr.write('skipped: unknown feature: %s\n' % missing)
77 sys.stderr.write('skipped: unknown feature: %s\n' % missing)
78 for msg in result['skipped']:
78 for msg in result['skipped']:
79 sys.stderr.write('skipped: %s\n' % msg)
79 sys.stderr.write('skipped: %s\n' % msg)
80 for msg in result['error']:
80 for msg in result['error']:
81 sys.stderr.write('%s\n' % msg)
81 sys.stderr.write('%s\n' % msg)
82
82
83 if result['missing']:
83 if result['missing']:
84 sys.exit(2)
84 sys.exit(2)
85
85
86 if result['skipped'] or result['error']:
86 if result['skipped'] or result['error']:
87 sys.exit(1)
87 sys.exit(1)
88
88
89 def matchoutput(cmd, regexp, ignorestatus=False):
89 def matchoutput(cmd, regexp, ignorestatus=False):
90 """Return the match object if cmd executes successfully and its output
90 """Return the match object if cmd executes successfully and its output
91 is matched by the supplied regular expression.
91 is matched by the supplied regular expression.
92 """
92 """
93 r = re.compile(regexp)
93 r = re.compile(regexp)
94 try:
94 try:
95 p = subprocess.Popen(
95 p = subprocess.Popen(
96 cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
96 cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
97 except OSError as e:
97 except OSError as e:
98 if e.errno != errno.ENOENT:
98 if e.errno != errno.ENOENT:
99 raise
99 raise
100 ret = -1
100 ret = -1
101 ret = p.wait()
101 ret = p.wait()
102 s = p.stdout.read()
102 s = p.stdout.read()
103 return (ignorestatus or not ret) and r.search(s)
103 return (ignorestatus or not ret) and r.search(s)
104
104
105 @check("baz", "GNU Arch baz client")
105 @check("baz", "GNU Arch baz client")
106 def has_baz():
106 def has_baz():
107 return matchoutput('baz --version 2>&1', br'baz Bazaar version')
107 return matchoutput('baz --version 2>&1', br'baz Bazaar version')
108
108
109 @check("bzr", "Canonical's Bazaar client")
109 @check("bzr", "Canonical's Bazaar client")
110 def has_bzr():
110 def has_bzr():
111 try:
111 try:
112 import bzrlib
112 import bzrlib
113 return bzrlib.__doc__ is not None
113 return bzrlib.__doc__ is not None
114 except ImportError:
114 except ImportError:
115 return False
115 return False
116
116
117 @checkvers("bzr", "Canonical's Bazaar client >= %s", (1.14,))
117 @checkvers("bzr", "Canonical's Bazaar client >= %s", (1.14,))
118 def has_bzr_range(v):
118 def has_bzr_range(v):
119 major, minor = v.split('.')[0:2]
119 major, minor = v.split('.')[0:2]
120 try:
120 try:
121 import bzrlib
121 import bzrlib
122 return (bzrlib.__doc__ is not None
122 return (bzrlib.__doc__ is not None
123 and bzrlib.version_info[:2] >= (int(major), int(minor)))
123 and bzrlib.version_info[:2] >= (int(major), int(minor)))
124 except ImportError:
124 except ImportError:
125 return False
125 return False
126
126
127 @check("chg", "running with chg")
127 @check("chg", "running with chg")
128 def has_chg():
128 def has_chg():
129 return 'CHGHG' in os.environ
129 return 'CHGHG' in os.environ
130
130
131 @check("cvs", "cvs client/server")
131 @check("cvs", "cvs client/server")
132 def has_cvs():
132 def has_cvs():
133 re = br'Concurrent Versions System.*?server'
133 re = br'Concurrent Versions System.*?server'
134 return matchoutput('cvs --version 2>&1', re) and not has_msys()
134 return matchoutput('cvs --version 2>&1', re) and not has_msys()
135
135
136 @check("cvs112", "cvs client/server 1.12.* (not cvsnt)")
136 @check("cvs112", "cvs client/server 1.12.* (not cvsnt)")
137 def has_cvs112():
137 def has_cvs112():
138 re = br'Concurrent Versions System \(CVS\) 1.12.*?server'
138 re = br'Concurrent Versions System \(CVS\) 1.12.*?server'
139 return matchoutput('cvs --version 2>&1', re) and not has_msys()
139 return matchoutput('cvs --version 2>&1', re) and not has_msys()
140
140
141 @check("cvsnt", "cvsnt client/server")
141 @check("cvsnt", "cvsnt client/server")
142 def has_cvsnt():
142 def has_cvsnt():
143 re = br'Concurrent Versions System \(CVSNT\) (\d+).(\d+).*\(client/server\)'
143 re = br'Concurrent Versions System \(CVSNT\) (\d+).(\d+).*\(client/server\)'
144 return matchoutput('cvsnt --version 2>&1', re)
144 return matchoutput('cvsnt --version 2>&1', re)
145
145
146 @check("darcs", "darcs client")
146 @check("darcs", "darcs client")
147 def has_darcs():
147 def has_darcs():
148 return matchoutput('darcs --version', br'2\.[2-9]', True)
148 return matchoutput('darcs --version', br'2\.[2-9]', True)
149
149
150 @check("mtn", "monotone client (>= 1.0)")
150 @check("mtn", "monotone client (>= 1.0)")
151 def has_mtn():
151 def has_mtn():
152 return matchoutput('mtn --version', br'monotone', True) and not matchoutput(
152 return matchoutput('mtn --version', br'monotone', True) and not matchoutput(
153 'mtn --version', br'monotone 0\.', True)
153 'mtn --version', br'monotone 0\.', True)
154
154
155 @check("eol-in-paths", "end-of-lines in paths")
155 @check("eol-in-paths", "end-of-lines in paths")
156 def has_eol_in_paths():
156 def has_eol_in_paths():
157 try:
157 try:
158 fd, path = tempfile.mkstemp(dir='.', prefix=tempprefix, suffix='\n\r')
158 fd, path = tempfile.mkstemp(dir='.', prefix=tempprefix, suffix='\n\r')
159 os.close(fd)
159 os.close(fd)
160 os.remove(path)
160 os.remove(path)
161 return True
161 return True
162 except (IOError, OSError):
162 except (IOError, OSError):
163 return False
163 return False
164
164
165 @check("execbit", "executable bit")
165 @check("execbit", "executable bit")
166 def has_executablebit():
166 def has_executablebit():
167 try:
167 try:
168 EXECFLAGS = stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH
168 EXECFLAGS = stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH
169 fh, fn = tempfile.mkstemp(dir='.', prefix=tempprefix)
169 fh, fn = tempfile.mkstemp(dir='.', prefix=tempprefix)
170 try:
170 try:
171 os.close(fh)
171 os.close(fh)
172 m = os.stat(fn).st_mode & 0o777
172 m = os.stat(fn).st_mode & 0o777
173 new_file_has_exec = m & EXECFLAGS
173 new_file_has_exec = m & EXECFLAGS
174 os.chmod(fn, m ^ EXECFLAGS)
174 os.chmod(fn, m ^ EXECFLAGS)
175 exec_flags_cannot_flip = ((os.stat(fn).st_mode & 0o777) == m)
175 exec_flags_cannot_flip = ((os.stat(fn).st_mode & 0o777) == m)
176 finally:
176 finally:
177 os.unlink(fn)
177 os.unlink(fn)
178 except (IOError, OSError):
178 except (IOError, OSError):
179 # we don't care, the user probably won't be able to commit anyway
179 # we don't care, the user probably won't be able to commit anyway
180 return False
180 return False
181 return not (new_file_has_exec or exec_flags_cannot_flip)
181 return not (new_file_has_exec or exec_flags_cannot_flip)
182
182
183 @check("icasefs", "case insensitive file system")
183 @check("icasefs", "case insensitive file system")
184 def has_icasefs():
184 def has_icasefs():
185 # Stolen from mercurial.util
185 # Stolen from mercurial.util
186 fd, path = tempfile.mkstemp(dir='.', prefix=tempprefix)
186 fd, path = tempfile.mkstemp(dir='.', prefix=tempprefix)
187 os.close(fd)
187 os.close(fd)
188 try:
188 try:
189 s1 = os.stat(path)
189 s1 = os.stat(path)
190 d, b = os.path.split(path)
190 d, b = os.path.split(path)
191 p2 = os.path.join(d, b.upper())
191 p2 = os.path.join(d, b.upper())
192 if path == p2:
192 if path == p2:
193 p2 = os.path.join(d, b.lower())
193 p2 = os.path.join(d, b.lower())
194 try:
194 try:
195 s2 = os.stat(p2)
195 s2 = os.stat(p2)
196 return s2 == s1
196 return s2 == s1
197 except OSError:
197 except OSError:
198 return False
198 return False
199 finally:
199 finally:
200 os.remove(path)
200 os.remove(path)
201
201
202 @check("fifo", "named pipes")
202 @check("fifo", "named pipes")
203 def has_fifo():
203 def has_fifo():
204 if getattr(os, "mkfifo", None) is None:
204 if getattr(os, "mkfifo", None) is None:
205 return False
205 return False
206 name = tempfile.mktemp(dir='.', prefix=tempprefix)
206 name = tempfile.mktemp(dir='.', prefix=tempprefix)
207 try:
207 try:
208 os.mkfifo(name)
208 os.mkfifo(name)
209 os.unlink(name)
209 os.unlink(name)
210 return True
210 return True
211 except OSError:
211 except OSError:
212 return False
212 return False
213
213
214 @check("killdaemons", 'killdaemons.py support')
214 @check("killdaemons", 'killdaemons.py support')
215 def has_killdaemons():
215 def has_killdaemons():
216 return True
216 return True
217
217
218 @check("cacheable", "cacheable filesystem")
218 @check("cacheable", "cacheable filesystem")
219 def has_cacheable_fs():
219 def has_cacheable_fs():
220 from mercurial import util
220 from mercurial import util
221
221
222 fd, path = tempfile.mkstemp(dir='.', prefix=tempprefix)
222 fd, path = tempfile.mkstemp(dir='.', prefix=tempprefix)
223 os.close(fd)
223 os.close(fd)
224 try:
224 try:
225 return util.cachestat(path).cacheable()
225 return util.cachestat(path).cacheable()
226 finally:
226 finally:
227 os.remove(path)
227 os.remove(path)
228
228
229 @check("lsprof", "python lsprof module")
229 @check("lsprof", "python lsprof module")
230 def has_lsprof():
230 def has_lsprof():
231 try:
231 try:
232 import _lsprof
232 import _lsprof
233 _lsprof.Profiler # silence unused import warning
233 _lsprof.Profiler # silence unused import warning
234 return True
234 return True
235 except ImportError:
235 except ImportError:
236 return False
236 return False
237
237
238 def gethgversion():
238 def gethgversion():
239 m = matchoutput('hg --version --quiet 2>&1', br'(\d+)\.(\d+)')
239 m = matchoutput('hg --version --quiet 2>&1', br'(\d+)\.(\d+)')
240 if not m:
240 if not m:
241 return (0, 0)
241 return (0, 0)
242 return (int(m.group(1)), int(m.group(2)))
242 return (int(m.group(1)), int(m.group(2)))
243
243
244 @checkvers("hg", "Mercurial >= %s",
244 @checkvers("hg", "Mercurial >= %s",
245 list([(1.0 * x) / 10 for x in range(9, 40)]))
245 list([(1.0 * x) / 10 for x in range(9, 40)]))
246 def has_hg_range(v):
246 def has_hg_range(v):
247 major, minor = v.split('.')[0:2]
247 major, minor = v.split('.')[0:2]
248 return gethgversion() >= (int(major), int(minor))
248 return gethgversion() >= (int(major), int(minor))
249
249
250 @check("hg08", "Mercurial >= 0.8")
250 @check("hg08", "Mercurial >= 0.8")
251 def has_hg08():
251 def has_hg08():
252 if checks["hg09"][0]():
252 if checks["hg09"][0]():
253 return True
253 return True
254 return matchoutput('hg help annotate 2>&1', '--date')
254 return matchoutput('hg help annotate 2>&1', '--date')
255
255
256 @check("hg07", "Mercurial >= 0.7")
256 @check("hg07", "Mercurial >= 0.7")
257 def has_hg07():
257 def has_hg07():
258 if checks["hg08"][0]():
258 if checks["hg08"][0]():
259 return True
259 return True
260 return matchoutput('hg --version --quiet 2>&1', 'Mercurial Distributed SCM')
260 return matchoutput('hg --version --quiet 2>&1', 'Mercurial Distributed SCM')
261
261
262 @check("hg06", "Mercurial >= 0.6")
262 @check("hg06", "Mercurial >= 0.6")
263 def has_hg06():
263 def has_hg06():
264 if checks["hg07"][0]():
264 if checks["hg07"][0]():
265 return True
265 return True
266 return matchoutput('hg --version --quiet 2>&1', 'Mercurial version')
266 return matchoutput('hg --version --quiet 2>&1', 'Mercurial version')
267
267
268 @check("gettext", "GNU Gettext (msgfmt)")
268 @check("gettext", "GNU Gettext (msgfmt)")
269 def has_gettext():
269 def has_gettext():
270 return matchoutput('msgfmt --version', br'GNU gettext-tools')
270 return matchoutput('msgfmt --version', br'GNU gettext-tools')
271
271
272 @check("git", "git command line client")
272 @check("git", "git command line client")
273 def has_git():
273 def has_git():
274 return matchoutput('git --version 2>&1', br'^git version')
274 return matchoutput('git --version 2>&1', br'^git version')
275
275
276 @check("docutils", "Docutils text processing library")
276 @check("docutils", "Docutils text processing library")
277 def has_docutils():
277 def has_docutils():
278 try:
278 try:
279 import docutils.core
279 import docutils.core
280 docutils.core.publish_cmdline # silence unused import
280 docutils.core.publish_cmdline # silence unused import
281 return True
281 return True
282 except ImportError:
282 except ImportError:
283 return False
283 return False
284
284
285 def getsvnversion():
285 def getsvnversion():
286 m = matchoutput('svn --version --quiet 2>&1', br'^(\d+)\.(\d+)')
286 m = matchoutput('svn --version --quiet 2>&1', br'^(\d+)\.(\d+)')
287 if not m:
287 if not m:
288 return (0, 0)
288 return (0, 0)
289 return (int(m.group(1)), int(m.group(2)))
289 return (int(m.group(1)), int(m.group(2)))
290
290
291 @checkvers("svn", "subversion client and admin tools >= %s", (1.3, 1.5))
291 @checkvers("svn", "subversion client and admin tools >= %s", (1.3, 1.5))
292 def has_svn_range(v):
292 def has_svn_range(v):
293 major, minor = v.split('.')[0:2]
293 major, minor = v.split('.')[0:2]
294 return getsvnversion() >= (int(major), int(minor))
294 return getsvnversion() >= (int(major), int(minor))
295
295
296 @check("svn", "subversion client and admin tools")
296 @check("svn", "subversion client and admin tools")
297 def has_svn():
297 def has_svn():
298 return matchoutput('svn --version 2>&1', br'^svn, version') and \
298 return matchoutput('svn --version 2>&1', br'^svn, version') and \
299 matchoutput('svnadmin --version 2>&1', br'^svnadmin, version')
299 matchoutput('svnadmin --version 2>&1', br'^svnadmin, version')
300
300
301 @check("svn-bindings", "subversion python bindings")
301 @check("svn-bindings", "subversion python bindings")
302 def has_svn_bindings():
302 def has_svn_bindings():
303 try:
303 try:
304 import svn.core
304 import svn.core
305 version = svn.core.SVN_VER_MAJOR, svn.core.SVN_VER_MINOR
305 version = svn.core.SVN_VER_MAJOR, svn.core.SVN_VER_MINOR
306 if version < (1, 4):
306 if version < (1, 4):
307 return False
307 return False
308 return True
308 return True
309 except ImportError:
309 except ImportError:
310 return False
310 return False
311
311
312 @check("p4", "Perforce server and client")
312 @check("p4", "Perforce server and client")
313 def has_p4():
313 def has_p4():
314 return (matchoutput('p4 -V', br'Rev\. P4/') and
314 return (matchoutput('p4 -V', br'Rev\. P4/') and
315 matchoutput('p4d -V', br'Rev\. P4D/'))
315 matchoutput('p4d -V', br'Rev\. P4D/'))
316
316
317 @check("symlink", "symbolic links")
317 @check("symlink", "symbolic links")
318 def has_symlink():
318 def has_symlink():
319 if getattr(os, "symlink", None) is None:
319 if getattr(os, "symlink", None) is None:
320 return False
320 return False
321 name = tempfile.mktemp(dir='.', prefix=tempprefix)
321 name = tempfile.mktemp(dir='.', prefix=tempprefix)
322 try:
322 try:
323 os.symlink(".", name)
323 os.symlink(".", name)
324 os.unlink(name)
324 os.unlink(name)
325 return True
325 return True
326 except (OSError, AttributeError):
326 except (OSError, AttributeError):
327 return False
327 return False
328
328
329 @check("hardlink", "hardlinks")
329 @check("hardlink", "hardlinks")
330 def has_hardlink():
330 def has_hardlink():
331 from mercurial import util
331 from mercurial import util
332 fh, fn = tempfile.mkstemp(dir='.', prefix=tempprefix)
332 fh, fn = tempfile.mkstemp(dir='.', prefix=tempprefix)
333 os.close(fh)
333 os.close(fh)
334 name = tempfile.mktemp(dir='.', prefix=tempprefix)
334 name = tempfile.mktemp(dir='.', prefix=tempprefix)
335 try:
335 try:
336 util.oslink(fn, name)
336 util.oslink(fn, name)
337 os.unlink(name)
337 os.unlink(name)
338 return True
338 return True
339 except OSError:
339 except OSError:
340 return False
340 return False
341 finally:
341 finally:
342 os.unlink(fn)
342 os.unlink(fn)
343
343
344 @check("tla", "GNU Arch tla client")
344 @check("tla", "GNU Arch tla client")
345 def has_tla():
345 def has_tla():
346 return matchoutput('tla --version 2>&1', br'The GNU Arch Revision')
346 return matchoutput('tla --version 2>&1', br'The GNU Arch Revision')
347
347
348 @check("gpg", "gpg client")
348 @check("gpg", "gpg client")
349 def has_gpg():
349 def has_gpg():
350 return matchoutput('gpg --version 2>&1', br'GnuPG')
350 return matchoutput('gpg --version 2>&1', br'GnuPG')
351
351
352 @check("unix-permissions", "unix-style permissions")
352 @check("unix-permissions", "unix-style permissions")
353 def has_unix_permissions():
353 def has_unix_permissions():
354 d = tempfile.mkdtemp(dir='.', prefix=tempprefix)
354 d = tempfile.mkdtemp(dir='.', prefix=tempprefix)
355 try:
355 try:
356 fname = os.path.join(d, 'foo')
356 fname = os.path.join(d, 'foo')
357 for umask in (0o77, 0o07, 0o22):
357 for umask in (0o77, 0o07, 0o22):
358 os.umask(umask)
358 os.umask(umask)
359 f = open(fname, 'w')
359 f = open(fname, 'w')
360 f.close()
360 f.close()
361 mode = os.stat(fname).st_mode
361 mode = os.stat(fname).st_mode
362 os.unlink(fname)
362 os.unlink(fname)
363 if mode & 0o777 != ~umask & 0o666:
363 if mode & 0o777 != ~umask & 0o666:
364 return False
364 return False
365 return True
365 return True
366 finally:
366 finally:
367 os.rmdir(d)
367 os.rmdir(d)
368
368
369 @check("unix-socket", "AF_UNIX socket family")
369 @check("unix-socket", "AF_UNIX socket family")
370 def has_unix_socket():
370 def has_unix_socket():
371 return getattr(socket, 'AF_UNIX', None) is not None
371 return getattr(socket, 'AF_UNIX', None) is not None
372
372
373 @check("root", "root permissions")
373 @check("root", "root permissions")
374 def has_root():
374 def has_root():
375 return getattr(os, 'geteuid', None) and os.geteuid() == 0
375 return getattr(os, 'geteuid', None) and os.geteuid() == 0
376
376
377 @check("pyflakes", "Pyflakes python linter")
377 @check("pyflakes", "Pyflakes python linter")
378 def has_pyflakes():
378 def has_pyflakes():
379 return matchoutput("sh -c \"echo 'import re' 2>&1 | pyflakes\"",
379 return matchoutput("sh -c \"echo 'import re' 2>&1 | pyflakes\"",
380 br"<stdin>:1: 're' imported but unused",
380 br"<stdin>:1: 're' imported but unused",
381 True)
381 True)
382
382
383 @check("pygments", "Pygments source highlighting library")
383 @check("pygments", "Pygments source highlighting library")
384 def has_pygments():
384 def has_pygments():
385 try:
385 try:
386 import pygments
386 import pygments
387 pygments.highlight # silence unused import warning
387 pygments.highlight # silence unused import warning
388 return True
388 return True
389 except ImportError:
389 except ImportError:
390 return False
390 return False
391
391
392 @check("outer-repo", "outer repo")
392 @check("outer-repo", "outer repo")
393 def has_outer_repo():
393 def has_outer_repo():
394 # failing for other reasons than 'no repo' imply that there is a repo
394 # failing for other reasons than 'no repo' imply that there is a repo
395 return not matchoutput('hg root 2>&1',
395 return not matchoutput('hg root 2>&1',
396 br'abort: no repository found', True)
396 br'abort: no repository found', True)
397
397
398 @check("ssl", "ssl module available")
398 @check("ssl", "ssl module available")
399 def has_ssl():
399 def has_ssl():
400 try:
400 try:
401 import ssl
401 import ssl
402 ssl.CERT_NONE
402 ssl.CERT_NONE
403 return True
403 return True
404 except ImportError:
404 except ImportError:
405 return False
405 return False
406
406
407 @check("sslcontext", "python >= 2.7.9 ssl")
407 @check("sslcontext", "python >= 2.7.9 ssl")
408 def has_sslcontext():
408 def has_sslcontext():
409 try:
409 try:
410 import ssl
410 import ssl
411 ssl.SSLContext
411 ssl.SSLContext
412 return True
412 return True
413 except (ImportError, AttributeError):
413 except (ImportError, AttributeError):
414 return False
414 return False
415
415
416 @check("defaultcacerts", "can verify SSL certs by system's CA certs store")
416 @check("defaultcacerts", "can verify SSL certs by system's CA certs store")
417 def has_defaultcacerts():
417 def has_defaultcacerts():
418 from mercurial import sslutil, ui as uimod
418 from mercurial import sslutil, ui as uimod
419 ui = uimod.ui()
419 ui = uimod.ui()
420 return sslutil._defaultcacerts(ui) or sslutil._canloaddefaultcerts
420 return sslutil._defaultcacerts(ui) or sslutil._canloaddefaultcerts
421
421
422 @check("defaultcacertsloaded", "detected presence of loaded system CA certs")
422 @check("defaultcacertsloaded", "detected presence of loaded system CA certs")
423 def has_defaultcacertsloaded():
423 def has_defaultcacertsloaded():
424 import ssl
424 import ssl
425 from mercurial import sslutil, ui as uimod
425 from mercurial import sslutil, ui as uimod
426
426
427 if not has_defaultcacerts():
427 if not has_defaultcacerts():
428 return False
428 return False
429 if not has_sslcontext():
429 if not has_sslcontext():
430 return False
430 return False
431
431
432 ui = uimod.ui()
432 ui = uimod.ui()
433 cafile = sslutil._defaultcacerts(ui)
433 cafile = sslutil._defaultcacerts(ui)
434 ctx = ssl.create_default_context()
434 ctx = ssl.create_default_context()
435 if cafile:
435 if cafile:
436 ctx.load_verify_locations(cafile=cafile)
436 ctx.load_verify_locations(cafile=cafile)
437 else:
437 else:
438 ctx.load_default_certs()
438 ctx.load_default_certs()
439
439
440 return len(ctx.get_ca_certs()) > 0
440 return len(ctx.get_ca_certs()) > 0
441
441
442 @check("tls1.2", "TLS 1.2 protocol support")
442 @check("tls1.2", "TLS 1.2 protocol support")
443 def has_tls1_2():
443 def has_tls1_2():
444 from mercurial import sslutil
444 from mercurial import sslutil
445 return 'tls1.2' in sslutil.supportprotocols
445 return 'tls1.2' in sslutil.supportedprotocols
446
446
447 @check("windows", "Windows")
447 @check("windows", "Windows")
448 def has_windows():
448 def has_windows():
449 return os.name == 'nt'
449 return os.name == 'nt'
450
450
451 @check("system-sh", "system() uses sh")
451 @check("system-sh", "system() uses sh")
452 def has_system_sh():
452 def has_system_sh():
453 return os.name != 'nt'
453 return os.name != 'nt'
454
454
455 @check("serve", "platform and python can manage 'hg serve -d'")
455 @check("serve", "platform and python can manage 'hg serve -d'")
456 def has_serve():
456 def has_serve():
457 return os.name != 'nt' # gross approximation
457 return os.name != 'nt' # gross approximation
458
458
459 @check("test-repo", "running tests from repository")
459 @check("test-repo", "running tests from repository")
460 def has_test_repo():
460 def has_test_repo():
461 t = os.environ["TESTDIR"]
461 t = os.environ["TESTDIR"]
462 return os.path.isdir(os.path.join(t, "..", ".hg"))
462 return os.path.isdir(os.path.join(t, "..", ".hg"))
463
463
464 @check("tic", "terminfo compiler and curses module")
464 @check("tic", "terminfo compiler and curses module")
465 def has_tic():
465 def has_tic():
466 try:
466 try:
467 import curses
467 import curses
468 curses.COLOR_BLUE
468 curses.COLOR_BLUE
469 return matchoutput('test -x "`which tic`"', br'')
469 return matchoutput('test -x "`which tic`"', br'')
470 except ImportError:
470 except ImportError:
471 return False
471 return False
472
472
473 @check("msys", "Windows with MSYS")
473 @check("msys", "Windows with MSYS")
474 def has_msys():
474 def has_msys():
475 return os.getenv('MSYSTEM')
475 return os.getenv('MSYSTEM')
476
476
477 @check("aix", "AIX")
477 @check("aix", "AIX")
478 def has_aix():
478 def has_aix():
479 return sys.platform.startswith("aix")
479 return sys.platform.startswith("aix")
480
480
481 @check("osx", "OS X")
481 @check("osx", "OS X")
482 def has_osx():
482 def has_osx():
483 return sys.platform == 'darwin'
483 return sys.platform == 'darwin'
484
484
485 @check("osxpackaging", "OS X packaging tools")
485 @check("osxpackaging", "OS X packaging tools")
486 def has_osxpackaging():
486 def has_osxpackaging():
487 try:
487 try:
488 return (matchoutput('pkgbuild', br'Usage: pkgbuild ', ignorestatus=1)
488 return (matchoutput('pkgbuild', br'Usage: pkgbuild ', ignorestatus=1)
489 and matchoutput(
489 and matchoutput(
490 'productbuild', br'Usage: productbuild ',
490 'productbuild', br'Usage: productbuild ',
491 ignorestatus=1)
491 ignorestatus=1)
492 and matchoutput('lsbom', br'Usage: lsbom', ignorestatus=1)
492 and matchoutput('lsbom', br'Usage: lsbom', ignorestatus=1)
493 and matchoutput(
493 and matchoutput(
494 'xar --help', br'Usage: xar', ignorestatus=1))
494 'xar --help', br'Usage: xar', ignorestatus=1))
495 except ImportError:
495 except ImportError:
496 return False
496 return False
497
497
498 @check("docker", "docker support")
498 @check("docker", "docker support")
499 def has_docker():
499 def has_docker():
500 pat = br'A self-sufficient runtime for'
500 pat = br'A self-sufficient runtime for'
501 if matchoutput('docker --help', pat):
501 if matchoutput('docker --help', pat):
502 if 'linux' not in sys.platform:
502 if 'linux' not in sys.platform:
503 # TODO: in theory we should be able to test docker-based
503 # TODO: in theory we should be able to test docker-based
504 # package creation on non-linux using boot2docker, but in
504 # package creation on non-linux using boot2docker, but in
505 # practice that requires extra coordination to make sure
505 # practice that requires extra coordination to make sure
506 # $TESTTEMP is going to be visible at the same path to the
506 # $TESTTEMP is going to be visible at the same path to the
507 # boot2docker VM. If we figure out how to verify that, we
507 # boot2docker VM. If we figure out how to verify that, we
508 # can use the following instead of just saying False:
508 # can use the following instead of just saying False:
509 # return 'DOCKER_HOST' in os.environ
509 # return 'DOCKER_HOST' in os.environ
510 return False
510 return False
511
511
512 return True
512 return True
513 return False
513 return False
514
514
515 @check("debhelper", "debian packaging tools")
515 @check("debhelper", "debian packaging tools")
516 def has_debhelper():
516 def has_debhelper():
517 dpkg = matchoutput('dpkg --version',
517 dpkg = matchoutput('dpkg --version',
518 br"Debian `dpkg' package management program")
518 br"Debian `dpkg' package management program")
519 dh = matchoutput('dh --help',
519 dh = matchoutput('dh --help',
520 br'dh is a part of debhelper.', ignorestatus=True)
520 br'dh is a part of debhelper.', ignorestatus=True)
521 dh_py2 = matchoutput('dh_python2 --help',
521 dh_py2 = matchoutput('dh_python2 --help',
522 br'other supported Python versions')
522 br'other supported Python versions')
523 return dpkg and dh and dh_py2
523 return dpkg and dh and dh_py2
524
524
525 @check("absimport", "absolute_import in __future__")
525 @check("absimport", "absolute_import in __future__")
526 def has_absimport():
526 def has_absimport():
527 import __future__
527 import __future__
528 from mercurial import util
528 from mercurial import util
529 return util.safehasattr(__future__, "absolute_import")
529 return util.safehasattr(__future__, "absolute_import")
530
530
531 @check("py27+", "running with Python 2.7+")
531 @check("py27+", "running with Python 2.7+")
532 def has_python27ornewer():
532 def has_python27ornewer():
533 return sys.version_info[0:2] >= (2, 7)
533 return sys.version_info[0:2] >= (2, 7)
534
534
535 @check("py3k", "running with Python 3.x")
535 @check("py3k", "running with Python 3.x")
536 def has_py3k():
536 def has_py3k():
537 return 3 == sys.version_info[0]
537 return 3 == sys.version_info[0]
538
538
539 @check("py3exe", "a Python 3.x interpreter is available")
539 @check("py3exe", "a Python 3.x interpreter is available")
540 def has_python3exe():
540 def has_python3exe():
541 return 'PYTHON3' in os.environ
541 return 'PYTHON3' in os.environ
542
542
543 @check("pure", "running with pure Python code")
543 @check("pure", "running with pure Python code")
544 def has_pure():
544 def has_pure():
545 return any([
545 return any([
546 os.environ.get("HGMODULEPOLICY") == "py",
546 os.environ.get("HGMODULEPOLICY") == "py",
547 os.environ.get("HGTEST_RUN_TESTS_PURE") == "--pure",
547 os.environ.get("HGTEST_RUN_TESTS_PURE") == "--pure",
548 ])
548 ])
549
549
550 @check("slow", "allow slow tests")
550 @check("slow", "allow slow tests")
551 def has_slow():
551 def has_slow():
552 return os.environ.get('HGTEST_SLOW') == 'slow'
552 return os.environ.get('HGTEST_SLOW') == 'slow'
553
553
554 @check("hypothesis", "Hypothesis automated test generation")
554 @check("hypothesis", "Hypothesis automated test generation")
555 def has_hypothesis():
555 def has_hypothesis():
556 try:
556 try:
557 import hypothesis
557 import hypothesis
558 hypothesis.given
558 hypothesis.given
559 return True
559 return True
560 except ImportError:
560 except ImportError:
561 return False
561 return False
General Comments 0
You need to be logged in to leave comments. Login now