Skip to content
Snippets Groups Projects
Commit c6427cd4 authored by Matt Mackall's avatar Matt Mackall
Browse files

setup: use try/except/finally

This will raise a syntax error for people who attempt to use Py2.4,
but that's already going to fail and we have no way to keep other
2.6isms from creeping in since we've removed the check-code rules and
the buildbot.
parent 754df8e9
No related branches found
No related tags found
No related merge requests found
...@@ -106,22 +106,19 @@ ...@@ -106,22 +106,19 @@
tmpdir = tempfile.mkdtemp(prefix='hg-install-') tmpdir = tempfile.mkdtemp(prefix='hg-install-')
devnull = oldstderr = None devnull = oldstderr = None
try: try:
try: fname = os.path.join(tmpdir, 'funcname.c')
fname = os.path.join(tmpdir, 'funcname.c') f = open(fname, 'w')
f = open(fname, 'w') f.write('int main(void) {\n')
f.write('int main(void) {\n') f.write(' %s();\n' % funcname)
f.write(' %s();\n' % funcname) f.write('}\n')
f.write('}\n') f.close()
f.close() # Redirect stderr to /dev/null to hide any error messages
# Redirect stderr to /dev/null to hide any error messages # from the compiler.
# from the compiler. # This will have to be changed if we ever have to check
# This will have to be changed if we ever have to check # for a function on Windows.
# for a function on Windows. devnull = open('/dev/null', 'w')
devnull = open('/dev/null', 'w') oldstderr = os.dup(sys.stderr.fileno())
oldstderr = os.dup(sys.stderr.fileno()) os.dup2(devnull.fileno(), sys.stderr.fileno())
os.dup2(devnull.fileno(), sys.stderr.fileno()) objects = cc.compile([fname], output_dir=tmpdir)
objects = cc.compile([fname], output_dir=tmpdir) cc.link_executable(objects, os.path.join(tmpdir, "a.out"))
cc.link_executable(objects, os.path.join(tmpdir, "a.out"))
except Exception:
return False
return True return True
...@@ -127,4 +124,6 @@ ...@@ -127,4 +124,6 @@
return True return True
except Exception:
return False
finally: finally:
if oldstderr is not None: if oldstderr is not None:
os.dup2(oldstderr, sys.stderr.fileno()) os.dup2(oldstderr, sys.stderr.fileno())
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment