Show More
@@ -24,20 +24,32 extra = {} | |||
|
24 | 24 | # that actually removes its temporary files. |
|
25 | 25 | def has_function(cc, funcname): |
|
26 | 26 | tmpdir = tempfile.mkdtemp(prefix='hg-install-') |
|
27 | devnull = oldstderr = None | |
|
27 | 28 | try: |
|
28 | fname = os.path.join(tmpdir, 'funcname.c') | |
|
29 | f = open(fname, 'w') | |
|
30 | f.write('int main(void) {\n') | |
|
31 | f.write(' %s();\n' % funcname) | |
|
32 | f.write('}\n') | |
|
33 | f.close() | |
|
34 | 29 | try: |
|
30 | fname = os.path.join(tmpdir, 'funcname.c') | |
|
31 | f = open(fname, 'w') | |
|
32 | f.write('int main(void) {\n') | |
|
33 | f.write(' %s();\n' % funcname) | |
|
34 | f.write('}\n') | |
|
35 | f.close() | |
|
36 | # Redirect stderr to /dev/null to hide any error messages | |
|
37 | # from the compiler. | |
|
38 | # This will have to be changed if we ever have to check | |
|
39 | # for a function on Windows. | |
|
40 | devnull = open('/dev/null', 'w') | |
|
41 | oldstderr = os.dup(sys.stderr.fileno()) | |
|
42 | os.dup2(devnull.fileno(), sys.stderr.fileno()) | |
|
35 | 43 | objects = cc.compile([fname]) |
|
36 | 44 | cc.link_executable(objects, os.path.join(tmpdir, "a.out")) |
|
37 | 45 | except: |
|
38 | 46 | return False |
|
39 | 47 | return True |
|
40 | 48 | finally: |
|
49 | if oldstderr is not None: | |
|
50 | os.dup2(oldstderr, sys.stderr.fileno()) | |
|
51 | if devnull is not None: | |
|
52 | devnull.close() | |
|
41 | 53 | shutil.rmtree(tmpdir) |
|
42 | 54 | |
|
43 | 55 | # py2exe needs to be installed to work |
General Comments 0
You need to be logged in to leave comments.
Login now