##// END OF EJS Templates
setup: use try/except/finally...
Matt Mackall -
r25089:c6427cd4 default
parent child Browse files
Show More
@@ -106,25 +106,24 b' def hasfunction(cc, funcname):'
106 tmpdir = tempfile.mkdtemp(prefix='hg-install-')
106 tmpdir = tempfile.mkdtemp(prefix='hg-install-')
107 devnull = oldstderr = None
107 devnull = oldstderr = None
108 try:
108 try:
109 try:
109 fname = os.path.join(tmpdir, 'funcname.c')
110 fname = os.path.join(tmpdir, 'funcname.c')
110 f = open(fname, 'w')
111 f = open(fname, 'w')
111 f.write('int main(void) {\n')
112 f.write('int main(void) {\n')
112 f.write(' %s();\n' % funcname)
113 f.write(' %s();\n' % funcname)
113 f.write('}\n')
114 f.write('}\n')
114 f.close()
115 f.close()
115 # Redirect stderr to /dev/null to hide any error messages
116 # Redirect stderr to /dev/null to hide any error messages
116 # from the compiler.
117 # from the compiler.
117 # This will have to be changed if we ever have to check
118 # This will have to be changed if we ever have to check
118 # for a function on Windows.
119 # for a function on Windows.
119 devnull = open('/dev/null', 'w')
120 devnull = open('/dev/null', 'w')
120 oldstderr = os.dup(sys.stderr.fileno())
121 oldstderr = os.dup(sys.stderr.fileno())
121 os.dup2(devnull.fileno(), sys.stderr.fileno())
122 os.dup2(devnull.fileno(), sys.stderr.fileno())
122 objects = cc.compile([fname], output_dir=tmpdir)
123 objects = cc.compile([fname], output_dir=tmpdir)
123 cc.link_executable(objects, os.path.join(tmpdir, "a.out"))
124 cc.link_executable(objects, os.path.join(tmpdir, "a.out"))
125 except Exception:
126 return False
127 return True
124 return True
125 except Exception:
126 return False
128 finally:
127 finally:
129 if oldstderr is not None:
128 if oldstderr is not None:
130 os.dup2(oldstderr, sys.stderr.fileno())
129 os.dup2(oldstderr, sys.stderr.fileno())
General Comments 0
You need to be logged in to leave comments. Login now