##// END OF EJS Templates
hghave: fix 'rmcwd' to ensure temporary directory is removed...
Yuya Nishihara -
r30242:389cbfe6 stable
parent child Browse files
Show More
@@ -1,607 +1,612 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 import bzrlib.bzrdir
113 import bzrlib.bzrdir
114 import bzrlib.errors
114 import bzrlib.errors
115 import bzrlib.revision
115 import bzrlib.revision
116 import bzrlib.revisionspec
116 import bzrlib.revisionspec
117 bzrlib.revisionspec.RevisionSpec
117 bzrlib.revisionspec.RevisionSpec
118 return bzrlib.__doc__ is not None
118 return bzrlib.__doc__ is not None
119 except (AttributeError, ImportError):
119 except (AttributeError, ImportError):
120 return False
120 return False
121
121
122 @checkvers("bzr", "Canonical's Bazaar client >= %s", (1.14,))
122 @checkvers("bzr", "Canonical's Bazaar client >= %s", (1.14,))
123 def has_bzr_range(v):
123 def has_bzr_range(v):
124 major, minor = v.split('.')[0:2]
124 major, minor = v.split('.')[0:2]
125 try:
125 try:
126 import bzrlib
126 import bzrlib
127 return (bzrlib.__doc__ is not None
127 return (bzrlib.__doc__ is not None
128 and bzrlib.version_info[:2] >= (int(major), int(minor)))
128 and bzrlib.version_info[:2] >= (int(major), int(minor)))
129 except ImportError:
129 except ImportError:
130 return False
130 return False
131
131
132 @check("chg", "running with chg")
132 @check("chg", "running with chg")
133 def has_chg():
133 def has_chg():
134 return 'CHGHG' in os.environ
134 return 'CHGHG' in os.environ
135
135
136 @check("cvs", "cvs client/server")
136 @check("cvs", "cvs client/server")
137 def has_cvs():
137 def has_cvs():
138 re = br'Concurrent Versions System.*?server'
138 re = br'Concurrent Versions System.*?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("cvs112", "cvs client/server 1.12.* (not cvsnt)")
141 @check("cvs112", "cvs client/server 1.12.* (not cvsnt)")
142 def has_cvs112():
142 def has_cvs112():
143 re = br'Concurrent Versions System \(CVS\) 1.12.*?server'
143 re = br'Concurrent Versions System \(CVS\) 1.12.*?server'
144 return matchoutput('cvs --version 2>&1', re) and not has_msys()
144 return matchoutput('cvs --version 2>&1', re) and not has_msys()
145
145
146 @check("cvsnt", "cvsnt client/server")
146 @check("cvsnt", "cvsnt client/server")
147 def has_cvsnt():
147 def has_cvsnt():
148 re = br'Concurrent Versions System \(CVSNT\) (\d+).(\d+).*\(client/server\)'
148 re = br'Concurrent Versions System \(CVSNT\) (\d+).(\d+).*\(client/server\)'
149 return matchoutput('cvsnt --version 2>&1', re)
149 return matchoutput('cvsnt --version 2>&1', re)
150
150
151 @check("darcs", "darcs client")
151 @check("darcs", "darcs client")
152 def has_darcs():
152 def has_darcs():
153 return matchoutput('darcs --version', br'2\.[2-9]', True)
153 return matchoutput('darcs --version', br'2\.[2-9]', True)
154
154
155 @check("mtn", "monotone client (>= 1.0)")
155 @check("mtn", "monotone client (>= 1.0)")
156 def has_mtn():
156 def has_mtn():
157 return matchoutput('mtn --version', br'monotone', True) and not matchoutput(
157 return matchoutput('mtn --version', br'monotone', True) and not matchoutput(
158 'mtn --version', br'monotone 0\.', True)
158 'mtn --version', br'monotone 0\.', True)
159
159
160 @check("eol-in-paths", "end-of-lines in paths")
160 @check("eol-in-paths", "end-of-lines in paths")
161 def has_eol_in_paths():
161 def has_eol_in_paths():
162 try:
162 try:
163 fd, path = tempfile.mkstemp(dir='.', prefix=tempprefix, suffix='\n\r')
163 fd, path = tempfile.mkstemp(dir='.', prefix=tempprefix, suffix='\n\r')
164 os.close(fd)
164 os.close(fd)
165 os.remove(path)
165 os.remove(path)
166 return True
166 return True
167 except (IOError, OSError):
167 except (IOError, OSError):
168 return False
168 return False
169
169
170 @check("execbit", "executable bit")
170 @check("execbit", "executable bit")
171 def has_executablebit():
171 def has_executablebit():
172 try:
172 try:
173 EXECFLAGS = stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH
173 EXECFLAGS = stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH
174 fh, fn = tempfile.mkstemp(dir='.', prefix=tempprefix)
174 fh, fn = tempfile.mkstemp(dir='.', prefix=tempprefix)
175 try:
175 try:
176 os.close(fh)
176 os.close(fh)
177 m = os.stat(fn).st_mode & 0o777
177 m = os.stat(fn).st_mode & 0o777
178 new_file_has_exec = m & EXECFLAGS
178 new_file_has_exec = m & EXECFLAGS
179 os.chmod(fn, m ^ EXECFLAGS)
179 os.chmod(fn, m ^ EXECFLAGS)
180 exec_flags_cannot_flip = ((os.stat(fn).st_mode & 0o777) == m)
180 exec_flags_cannot_flip = ((os.stat(fn).st_mode & 0o777) == m)
181 finally:
181 finally:
182 os.unlink(fn)
182 os.unlink(fn)
183 except (IOError, OSError):
183 except (IOError, OSError):
184 # we don't care, the user probably won't be able to commit anyway
184 # we don't care, the user probably won't be able to commit anyway
185 return False
185 return False
186 return not (new_file_has_exec or exec_flags_cannot_flip)
186 return not (new_file_has_exec or exec_flags_cannot_flip)
187
187
188 @check("icasefs", "case insensitive file system")
188 @check("icasefs", "case insensitive file system")
189 def has_icasefs():
189 def has_icasefs():
190 # Stolen from mercurial.util
190 # Stolen from mercurial.util
191 fd, path = tempfile.mkstemp(dir='.', prefix=tempprefix)
191 fd, path = tempfile.mkstemp(dir='.', prefix=tempprefix)
192 os.close(fd)
192 os.close(fd)
193 try:
193 try:
194 s1 = os.stat(path)
194 s1 = os.stat(path)
195 d, b = os.path.split(path)
195 d, b = os.path.split(path)
196 p2 = os.path.join(d, b.upper())
196 p2 = os.path.join(d, b.upper())
197 if path == p2:
197 if path == p2:
198 p2 = os.path.join(d, b.lower())
198 p2 = os.path.join(d, b.lower())
199 try:
199 try:
200 s2 = os.stat(p2)
200 s2 = os.stat(p2)
201 return s2 == s1
201 return s2 == s1
202 except OSError:
202 except OSError:
203 return False
203 return False
204 finally:
204 finally:
205 os.remove(path)
205 os.remove(path)
206
206
207 @check("fifo", "named pipes")
207 @check("fifo", "named pipes")
208 def has_fifo():
208 def has_fifo():
209 if getattr(os, "mkfifo", None) is None:
209 if getattr(os, "mkfifo", None) is None:
210 return False
210 return False
211 name = tempfile.mktemp(dir='.', prefix=tempprefix)
211 name = tempfile.mktemp(dir='.', prefix=tempprefix)
212 try:
212 try:
213 os.mkfifo(name)
213 os.mkfifo(name)
214 os.unlink(name)
214 os.unlink(name)
215 return True
215 return True
216 except OSError:
216 except OSError:
217 return False
217 return False
218
218
219 @check("killdaemons", 'killdaemons.py support')
219 @check("killdaemons", 'killdaemons.py support')
220 def has_killdaemons():
220 def has_killdaemons():
221 return True
221 return True
222
222
223 @check("cacheable", "cacheable filesystem")
223 @check("cacheable", "cacheable filesystem")
224 def has_cacheable_fs():
224 def has_cacheable_fs():
225 from mercurial import util
225 from mercurial import util
226
226
227 fd, path = tempfile.mkstemp(dir='.', prefix=tempprefix)
227 fd, path = tempfile.mkstemp(dir='.', prefix=tempprefix)
228 os.close(fd)
228 os.close(fd)
229 try:
229 try:
230 return util.cachestat(path).cacheable()
230 return util.cachestat(path).cacheable()
231 finally:
231 finally:
232 os.remove(path)
232 os.remove(path)
233
233
234 @check("lsprof", "python lsprof module")
234 @check("lsprof", "python lsprof module")
235 def has_lsprof():
235 def has_lsprof():
236 try:
236 try:
237 import _lsprof
237 import _lsprof
238 _lsprof.Profiler # silence unused import warning
238 _lsprof.Profiler # silence unused import warning
239 return True
239 return True
240 except ImportError:
240 except ImportError:
241 return False
241 return False
242
242
243 def gethgversion():
243 def gethgversion():
244 m = matchoutput('hg --version --quiet 2>&1', br'(\d+)\.(\d+)')
244 m = matchoutput('hg --version --quiet 2>&1', br'(\d+)\.(\d+)')
245 if not m:
245 if not m:
246 return (0, 0)
246 return (0, 0)
247 return (int(m.group(1)), int(m.group(2)))
247 return (int(m.group(1)), int(m.group(2)))
248
248
249 @checkvers("hg", "Mercurial >= %s",
249 @checkvers("hg", "Mercurial >= %s",
250 list([(1.0 * x) / 10 for x in range(9, 40)]))
250 list([(1.0 * x) / 10 for x in range(9, 40)]))
251 def has_hg_range(v):
251 def has_hg_range(v):
252 major, minor = v.split('.')[0:2]
252 major, minor = v.split('.')[0:2]
253 return gethgversion() >= (int(major), int(minor))
253 return gethgversion() >= (int(major), int(minor))
254
254
255 @check("hg08", "Mercurial >= 0.8")
255 @check("hg08", "Mercurial >= 0.8")
256 def has_hg08():
256 def has_hg08():
257 if checks["hg09"][0]():
257 if checks["hg09"][0]():
258 return True
258 return True
259 return matchoutput('hg help annotate 2>&1', '--date')
259 return matchoutput('hg help annotate 2>&1', '--date')
260
260
261 @check("hg07", "Mercurial >= 0.7")
261 @check("hg07", "Mercurial >= 0.7")
262 def has_hg07():
262 def has_hg07():
263 if checks["hg08"][0]():
263 if checks["hg08"][0]():
264 return True
264 return True
265 return matchoutput('hg --version --quiet 2>&1', 'Mercurial Distributed SCM')
265 return matchoutput('hg --version --quiet 2>&1', 'Mercurial Distributed SCM')
266
266
267 @check("hg06", "Mercurial >= 0.6")
267 @check("hg06", "Mercurial >= 0.6")
268 def has_hg06():
268 def has_hg06():
269 if checks["hg07"][0]():
269 if checks["hg07"][0]():
270 return True
270 return True
271 return matchoutput('hg --version --quiet 2>&1', 'Mercurial version')
271 return matchoutput('hg --version --quiet 2>&1', 'Mercurial version')
272
272
273 @check("gettext", "GNU Gettext (msgfmt)")
273 @check("gettext", "GNU Gettext (msgfmt)")
274 def has_gettext():
274 def has_gettext():
275 return matchoutput('msgfmt --version', br'GNU gettext-tools')
275 return matchoutput('msgfmt --version', br'GNU gettext-tools')
276
276
277 @check("git", "git command line client")
277 @check("git", "git command line client")
278 def has_git():
278 def has_git():
279 return matchoutput('git --version 2>&1', br'^git version')
279 return matchoutput('git --version 2>&1', br'^git version')
280
280
281 @check("docutils", "Docutils text processing library")
281 @check("docutils", "Docutils text processing library")
282 def has_docutils():
282 def has_docutils():
283 try:
283 try:
284 import docutils.core
284 import docutils.core
285 docutils.core.publish_cmdline # silence unused import
285 docutils.core.publish_cmdline # silence unused import
286 return True
286 return True
287 except ImportError:
287 except ImportError:
288 return False
288 return False
289
289
290 def getsvnversion():
290 def getsvnversion():
291 m = matchoutput('svn --version --quiet 2>&1', br'^(\d+)\.(\d+)')
291 m = matchoutput('svn --version --quiet 2>&1', br'^(\d+)\.(\d+)')
292 if not m:
292 if not m:
293 return (0, 0)
293 return (0, 0)
294 return (int(m.group(1)), int(m.group(2)))
294 return (int(m.group(1)), int(m.group(2)))
295
295
296 @checkvers("svn", "subversion client and admin tools >= %s", (1.3, 1.5))
296 @checkvers("svn", "subversion client and admin tools >= %s", (1.3, 1.5))
297 def has_svn_range(v):
297 def has_svn_range(v):
298 major, minor = v.split('.')[0:2]
298 major, minor = v.split('.')[0:2]
299 return getsvnversion() >= (int(major), int(minor))
299 return getsvnversion() >= (int(major), int(minor))
300
300
301 @check("svn", "subversion client and admin tools")
301 @check("svn", "subversion client and admin tools")
302 def has_svn():
302 def has_svn():
303 return matchoutput('svn --version 2>&1', br'^svn, version') and \
303 return matchoutput('svn --version 2>&1', br'^svn, version') and \
304 matchoutput('svnadmin --version 2>&1', br'^svnadmin, version')
304 matchoutput('svnadmin --version 2>&1', br'^svnadmin, version')
305
305
306 @check("svn-bindings", "subversion python bindings")
306 @check("svn-bindings", "subversion python bindings")
307 def has_svn_bindings():
307 def has_svn_bindings():
308 try:
308 try:
309 import svn.core
309 import svn.core
310 version = svn.core.SVN_VER_MAJOR, svn.core.SVN_VER_MINOR
310 version = svn.core.SVN_VER_MAJOR, svn.core.SVN_VER_MINOR
311 if version < (1, 4):
311 if version < (1, 4):
312 return False
312 return False
313 return True
313 return True
314 except ImportError:
314 except ImportError:
315 return False
315 return False
316
316
317 @check("p4", "Perforce server and client")
317 @check("p4", "Perforce server and client")
318 def has_p4():
318 def has_p4():
319 return (matchoutput('p4 -V', br'Rev\. P4/') and
319 return (matchoutput('p4 -V', br'Rev\. P4/') and
320 matchoutput('p4d -V', br'Rev\. P4D/'))
320 matchoutput('p4d -V', br'Rev\. P4D/'))
321
321
322 @check("symlink", "symbolic links")
322 @check("symlink", "symbolic links")
323 def has_symlink():
323 def has_symlink():
324 if getattr(os, "symlink", None) is None:
324 if getattr(os, "symlink", None) is None:
325 return False
325 return False
326 name = tempfile.mktemp(dir='.', prefix=tempprefix)
326 name = tempfile.mktemp(dir='.', prefix=tempprefix)
327 try:
327 try:
328 os.symlink(".", name)
328 os.symlink(".", name)
329 os.unlink(name)
329 os.unlink(name)
330 return True
330 return True
331 except (OSError, AttributeError):
331 except (OSError, AttributeError):
332 return False
332 return False
333
333
334 @check("hardlink", "hardlinks")
334 @check("hardlink", "hardlinks")
335 def has_hardlink():
335 def has_hardlink():
336 from mercurial import util
336 from mercurial import util
337 fh, fn = tempfile.mkstemp(dir='.', prefix=tempprefix)
337 fh, fn = tempfile.mkstemp(dir='.', prefix=tempprefix)
338 os.close(fh)
338 os.close(fh)
339 name = tempfile.mktemp(dir='.', prefix=tempprefix)
339 name = tempfile.mktemp(dir='.', prefix=tempprefix)
340 try:
340 try:
341 util.oslink(fn, name)
341 util.oslink(fn, name)
342 os.unlink(name)
342 os.unlink(name)
343 return True
343 return True
344 except OSError:
344 except OSError:
345 return False
345 return False
346 finally:
346 finally:
347 os.unlink(fn)
347 os.unlink(fn)
348
348
349 @check("rmcwd", "can remove current working directory")
349 @check("rmcwd", "can remove current working directory")
350 def has_rmcwd():
350 def has_rmcwd():
351 ocwd = os.getcwd()
351 ocwd = os.getcwd()
352 temp = tempfile.mkdtemp(dir='.', prefix=tempprefix)
352 temp = tempfile.mkdtemp(dir='.', prefix=tempprefix)
353 try:
353 try:
354 os.chdir(temp)
354 os.chdir(temp)
355 # On Linux, 'rmdir .' isn't allowed, but the other names are okay.
355 # On Linux, 'rmdir .' isn't allowed, but the other names are okay.
356 # On Solaris and Windows, the cwd can't be removed by any names.
356 # On Solaris and Windows, the cwd can't be removed by any names.
357 os.rmdir(os.getcwd())
357 os.rmdir(os.getcwd())
358 return True
358 return True
359 except OSError:
359 except OSError:
360 return False
360 return False
361 finally:
361 finally:
362 os.chdir(ocwd)
362 os.chdir(ocwd)
363 # clean up temp dir on platforms where cwd can't be removed
364 try:
365 os.rmdir(temp)
366 except OSError:
367 pass
363
368
364 @check("tla", "GNU Arch tla client")
369 @check("tla", "GNU Arch tla client")
365 def has_tla():
370 def has_tla():
366 return matchoutput('tla --version 2>&1', br'The GNU Arch Revision')
371 return matchoutput('tla --version 2>&1', br'The GNU Arch Revision')
367
372
368 @check("gpg", "gpg client")
373 @check("gpg", "gpg client")
369 def has_gpg():
374 def has_gpg():
370 return matchoutput('gpg --version 2>&1', br'GnuPG')
375 return matchoutput('gpg --version 2>&1', br'GnuPG')
371
376
372 @check("gpg2", "gpg client v2")
377 @check("gpg2", "gpg client v2")
373 def has_gpg2():
378 def has_gpg2():
374 return matchoutput('gpg --version 2>&1', br'GnuPG[^0-9]+2\.')
379 return matchoutput('gpg --version 2>&1', br'GnuPG[^0-9]+2\.')
375
380
376 @check("gpg21", "gpg client v2.1+")
381 @check("gpg21", "gpg client v2.1+")
377 def has_gpg21():
382 def has_gpg21():
378 return matchoutput('gpg --version 2>&1', br'GnuPG[^0-9]+2\.(?!0)')
383 return matchoutput('gpg --version 2>&1', br'GnuPG[^0-9]+2\.(?!0)')
379
384
380 @check("unix-permissions", "unix-style permissions")
385 @check("unix-permissions", "unix-style permissions")
381 def has_unix_permissions():
386 def has_unix_permissions():
382 d = tempfile.mkdtemp(dir='.', prefix=tempprefix)
387 d = tempfile.mkdtemp(dir='.', prefix=tempprefix)
383 try:
388 try:
384 fname = os.path.join(d, 'foo')
389 fname = os.path.join(d, 'foo')
385 for umask in (0o77, 0o07, 0o22):
390 for umask in (0o77, 0o07, 0o22):
386 os.umask(umask)
391 os.umask(umask)
387 f = open(fname, 'w')
392 f = open(fname, 'w')
388 f.close()
393 f.close()
389 mode = os.stat(fname).st_mode
394 mode = os.stat(fname).st_mode
390 os.unlink(fname)
395 os.unlink(fname)
391 if mode & 0o777 != ~umask & 0o666:
396 if mode & 0o777 != ~umask & 0o666:
392 return False
397 return False
393 return True
398 return True
394 finally:
399 finally:
395 os.rmdir(d)
400 os.rmdir(d)
396
401
397 @check("unix-socket", "AF_UNIX socket family")
402 @check("unix-socket", "AF_UNIX socket family")
398 def has_unix_socket():
403 def has_unix_socket():
399 return getattr(socket, 'AF_UNIX', None) is not None
404 return getattr(socket, 'AF_UNIX', None) is not None
400
405
401 @check("root", "root permissions")
406 @check("root", "root permissions")
402 def has_root():
407 def has_root():
403 return getattr(os, 'geteuid', None) and os.geteuid() == 0
408 return getattr(os, 'geteuid', None) and os.geteuid() == 0
404
409
405 @check("pyflakes", "Pyflakes python linter")
410 @check("pyflakes", "Pyflakes python linter")
406 def has_pyflakes():
411 def has_pyflakes():
407 return matchoutput("sh -c \"echo 'import re' 2>&1 | pyflakes\"",
412 return matchoutput("sh -c \"echo 'import re' 2>&1 | pyflakes\"",
408 br"<stdin>:1: 're' imported but unused",
413 br"<stdin>:1: 're' imported but unused",
409 True)
414 True)
410
415
411 @check("pygments", "Pygments source highlighting library")
416 @check("pygments", "Pygments source highlighting library")
412 def has_pygments():
417 def has_pygments():
413 try:
418 try:
414 import pygments
419 import pygments
415 pygments.highlight # silence unused import warning
420 pygments.highlight # silence unused import warning
416 return True
421 return True
417 except ImportError:
422 except ImportError:
418 return False
423 return False
419
424
420 @check("outer-repo", "outer repo")
425 @check("outer-repo", "outer repo")
421 def has_outer_repo():
426 def has_outer_repo():
422 # failing for other reasons than 'no repo' imply that there is a repo
427 # failing for other reasons than 'no repo' imply that there is a repo
423 return not matchoutput('hg root 2>&1',
428 return not matchoutput('hg root 2>&1',
424 br'abort: no repository found', True)
429 br'abort: no repository found', True)
425
430
426 @check("ssl", "ssl module available")
431 @check("ssl", "ssl module available")
427 def has_ssl():
432 def has_ssl():
428 try:
433 try:
429 import ssl
434 import ssl
430 ssl.CERT_NONE
435 ssl.CERT_NONE
431 return True
436 return True
432 except ImportError:
437 except ImportError:
433 return False
438 return False
434
439
435 @check("sslcontext", "python >= 2.7.9 ssl")
440 @check("sslcontext", "python >= 2.7.9 ssl")
436 def has_sslcontext():
441 def has_sslcontext():
437 try:
442 try:
438 import ssl
443 import ssl
439 ssl.SSLContext
444 ssl.SSLContext
440 return True
445 return True
441 except (ImportError, AttributeError):
446 except (ImportError, AttributeError):
442 return False
447 return False
443
448
444 @check("defaultcacerts", "can verify SSL certs by system's CA certs store")
449 @check("defaultcacerts", "can verify SSL certs by system's CA certs store")
445 def has_defaultcacerts():
450 def has_defaultcacerts():
446 from mercurial import sslutil, ui as uimod
451 from mercurial import sslutil, ui as uimod
447 ui = uimod.ui()
452 ui = uimod.ui()
448 return sslutil._defaultcacerts(ui) or sslutil._canloaddefaultcerts
453 return sslutil._defaultcacerts(ui) or sslutil._canloaddefaultcerts
449
454
450 @check("defaultcacertsloaded", "detected presence of loaded system CA certs")
455 @check("defaultcacertsloaded", "detected presence of loaded system CA certs")
451 def has_defaultcacertsloaded():
456 def has_defaultcacertsloaded():
452 import ssl
457 import ssl
453 from mercurial import sslutil, ui as uimod
458 from mercurial import sslutil, ui as uimod
454
459
455 if not has_defaultcacerts():
460 if not has_defaultcacerts():
456 return False
461 return False
457 if not has_sslcontext():
462 if not has_sslcontext():
458 return False
463 return False
459
464
460 ui = uimod.ui()
465 ui = uimod.ui()
461 cafile = sslutil._defaultcacerts(ui)
466 cafile = sslutil._defaultcacerts(ui)
462 ctx = ssl.create_default_context()
467 ctx = ssl.create_default_context()
463 if cafile:
468 if cafile:
464 ctx.load_verify_locations(cafile=cafile)
469 ctx.load_verify_locations(cafile=cafile)
465 else:
470 else:
466 ctx.load_default_certs()
471 ctx.load_default_certs()
467
472
468 return len(ctx.get_ca_certs()) > 0
473 return len(ctx.get_ca_certs()) > 0
469
474
470 @check("tls1.2", "TLS 1.2 protocol support")
475 @check("tls1.2", "TLS 1.2 protocol support")
471 def has_tls1_2():
476 def has_tls1_2():
472 from mercurial import sslutil
477 from mercurial import sslutil
473 return 'tls1.2' in sslutil.supportedprotocols
478 return 'tls1.2' in sslutil.supportedprotocols
474
479
475 @check("windows", "Windows")
480 @check("windows", "Windows")
476 def has_windows():
481 def has_windows():
477 return os.name == 'nt'
482 return os.name == 'nt'
478
483
479 @check("system-sh", "system() uses sh")
484 @check("system-sh", "system() uses sh")
480 def has_system_sh():
485 def has_system_sh():
481 return os.name != 'nt'
486 return os.name != 'nt'
482
487
483 @check("serve", "platform and python can manage 'hg serve -d'")
488 @check("serve", "platform and python can manage 'hg serve -d'")
484 def has_serve():
489 def has_serve():
485 return os.name != 'nt' # gross approximation
490 return os.name != 'nt' # gross approximation
486
491
487 @check("test-repo", "running tests from repository")
492 @check("test-repo", "running tests from repository")
488 def has_test_repo():
493 def has_test_repo():
489 t = os.environ["TESTDIR"]
494 t = os.environ["TESTDIR"]
490 return os.path.isdir(os.path.join(t, "..", ".hg"))
495 return os.path.isdir(os.path.join(t, "..", ".hg"))
491
496
492 @check("tic", "terminfo compiler and curses module")
497 @check("tic", "terminfo compiler and curses module")
493 def has_tic():
498 def has_tic():
494 try:
499 try:
495 import curses
500 import curses
496 curses.COLOR_BLUE
501 curses.COLOR_BLUE
497 return matchoutput('test -x "`which tic`"', br'')
502 return matchoutput('test -x "`which tic`"', br'')
498 except ImportError:
503 except ImportError:
499 return False
504 return False
500
505
501 @check("msys", "Windows with MSYS")
506 @check("msys", "Windows with MSYS")
502 def has_msys():
507 def has_msys():
503 return os.getenv('MSYSTEM')
508 return os.getenv('MSYSTEM')
504
509
505 @check("aix", "AIX")
510 @check("aix", "AIX")
506 def has_aix():
511 def has_aix():
507 return sys.platform.startswith("aix")
512 return sys.platform.startswith("aix")
508
513
509 @check("osx", "OS X")
514 @check("osx", "OS X")
510 def has_osx():
515 def has_osx():
511 return sys.platform == 'darwin'
516 return sys.platform == 'darwin'
512
517
513 @check("osxpackaging", "OS X packaging tools")
518 @check("osxpackaging", "OS X packaging tools")
514 def has_osxpackaging():
519 def has_osxpackaging():
515 try:
520 try:
516 return (matchoutput('pkgbuild', br'Usage: pkgbuild ', ignorestatus=1)
521 return (matchoutput('pkgbuild', br'Usage: pkgbuild ', ignorestatus=1)
517 and matchoutput(
522 and matchoutput(
518 'productbuild', br'Usage: productbuild ',
523 'productbuild', br'Usage: productbuild ',
519 ignorestatus=1)
524 ignorestatus=1)
520 and matchoutput('lsbom', br'Usage: lsbom', ignorestatus=1)
525 and matchoutput('lsbom', br'Usage: lsbom', ignorestatus=1)
521 and matchoutput(
526 and matchoutput(
522 'xar --help', br'Usage: xar', ignorestatus=1))
527 'xar --help', br'Usage: xar', ignorestatus=1))
523 except ImportError:
528 except ImportError:
524 return False
529 return False
525
530
526 @check("docker", "docker support")
531 @check("docker", "docker support")
527 def has_docker():
532 def has_docker():
528 pat = br'A self-sufficient runtime for'
533 pat = br'A self-sufficient runtime for'
529 if matchoutput('docker --help', pat):
534 if matchoutput('docker --help', pat):
530 if 'linux' not in sys.platform:
535 if 'linux' not in sys.platform:
531 # TODO: in theory we should be able to test docker-based
536 # TODO: in theory we should be able to test docker-based
532 # package creation on non-linux using boot2docker, but in
537 # package creation on non-linux using boot2docker, but in
533 # practice that requires extra coordination to make sure
538 # practice that requires extra coordination to make sure
534 # $TESTTEMP is going to be visible at the same path to the
539 # $TESTTEMP is going to be visible at the same path to the
535 # boot2docker VM. If we figure out how to verify that, we
540 # boot2docker VM. If we figure out how to verify that, we
536 # can use the following instead of just saying False:
541 # can use the following instead of just saying False:
537 # return 'DOCKER_HOST' in os.environ
542 # return 'DOCKER_HOST' in os.environ
538 return False
543 return False
539
544
540 return True
545 return True
541 return False
546 return False
542
547
543 @check("debhelper", "debian packaging tools")
548 @check("debhelper", "debian packaging tools")
544 def has_debhelper():
549 def has_debhelper():
545 dpkg = matchoutput('dpkg --version',
550 dpkg = matchoutput('dpkg --version',
546 br"Debian `dpkg' package management program")
551 br"Debian `dpkg' package management program")
547 dh = matchoutput('dh --help',
552 dh = matchoutput('dh --help',
548 br'dh is a part of debhelper.', ignorestatus=True)
553 br'dh is a part of debhelper.', ignorestatus=True)
549 dh_py2 = matchoutput('dh_python2 --help',
554 dh_py2 = matchoutput('dh_python2 --help',
550 br'other supported Python versions')
555 br'other supported Python versions')
551 return dpkg and dh and dh_py2
556 return dpkg and dh and dh_py2
552
557
553 @check("demandimport", "demandimport enabled")
558 @check("demandimport", "demandimport enabled")
554 def has_demandimport():
559 def has_demandimport():
555 return os.environ.get('HGDEMANDIMPORT') != 'disable'
560 return os.environ.get('HGDEMANDIMPORT') != 'disable'
556
561
557 @check("absimport", "absolute_import in __future__")
562 @check("absimport", "absolute_import in __future__")
558 def has_absimport():
563 def has_absimport():
559 import __future__
564 import __future__
560 from mercurial import util
565 from mercurial import util
561 return util.safehasattr(__future__, "absolute_import")
566 return util.safehasattr(__future__, "absolute_import")
562
567
563 @check("py27+", "running with Python 2.7+")
568 @check("py27+", "running with Python 2.7+")
564 def has_python27ornewer():
569 def has_python27ornewer():
565 return sys.version_info[0:2] >= (2, 7)
570 return sys.version_info[0:2] >= (2, 7)
566
571
567 @check("py3k", "running with Python 3.x")
572 @check("py3k", "running with Python 3.x")
568 def has_py3k():
573 def has_py3k():
569 return 3 == sys.version_info[0]
574 return 3 == sys.version_info[0]
570
575
571 @check("py3exe", "a Python 3.x interpreter is available")
576 @check("py3exe", "a Python 3.x interpreter is available")
572 def has_python3exe():
577 def has_python3exe():
573 return 'PYTHON3' in os.environ
578 return 'PYTHON3' in os.environ
574
579
575 @check("py3pygments", "Pygments available on Python 3.x")
580 @check("py3pygments", "Pygments available on Python 3.x")
576 def has_py3pygments():
581 def has_py3pygments():
577 if has_py3k():
582 if has_py3k():
578 return has_pygments()
583 return has_pygments()
579 elif has_python3exe():
584 elif has_python3exe():
580 # just check exit status (ignoring output)
585 # just check exit status (ignoring output)
581 py3 = os.environ['PYTHON3']
586 py3 = os.environ['PYTHON3']
582 return matchoutput('%s -c "import pygments"' % py3, br'')
587 return matchoutput('%s -c "import pygments"' % py3, br'')
583 return False
588 return False
584
589
585 @check("pure", "running with pure Python code")
590 @check("pure", "running with pure Python code")
586 def has_pure():
591 def has_pure():
587 return any([
592 return any([
588 os.environ.get("HGMODULEPOLICY") == "py",
593 os.environ.get("HGMODULEPOLICY") == "py",
589 os.environ.get("HGTEST_RUN_TESTS_PURE") == "--pure",
594 os.environ.get("HGTEST_RUN_TESTS_PURE") == "--pure",
590 ])
595 ])
591
596
592 @check("slow", "allow slow tests")
597 @check("slow", "allow slow tests")
593 def has_slow():
598 def has_slow():
594 return os.environ.get('HGTEST_SLOW') == 'slow'
599 return os.environ.get('HGTEST_SLOW') == 'slow'
595
600
596 @check("hypothesis", "Hypothesis automated test generation")
601 @check("hypothesis", "Hypothesis automated test generation")
597 def has_hypothesis():
602 def has_hypothesis():
598 try:
603 try:
599 import hypothesis
604 import hypothesis
600 hypothesis.given
605 hypothesis.given
601 return True
606 return True
602 except ImportError:
607 except ImportError:
603 return False
608 return False
604
609
605 @check("unziplinks", "unzip(1) understands and extracts symlinks")
610 @check("unziplinks", "unzip(1) understands and extracts symlinks")
606 def unzip_understands_symlinks():
611 def unzip_understands_symlinks():
607 return matchoutput('unzip --help', br'Info-ZIP')
612 return matchoutput('unzip --help', br'Info-ZIP')
General Comments 0
You need to be logged in to leave comments. Login now