Show More
@@ -1,121 +1,133 b'' | |||
|
1 | 1 | #!/usr/bin/env python |
|
2 | 2 | # |
|
3 | 3 | # This is the mercurial setup script. |
|
4 | 4 | # |
|
5 | 5 | # 'python setup.py install', or |
|
6 | 6 | # 'python setup.py --help' for more options |
|
7 | 7 | |
|
8 | 8 | import sys |
|
9 | 9 | if not hasattr(sys, 'version_info') or sys.version_info < (2, 3, 0, 'final'): |
|
10 | 10 | raise SystemExit, "Mercurial requires python 2.3 or later." |
|
11 | 11 | |
|
12 | 12 | import os |
|
13 | 13 | import shutil |
|
14 | 14 | import tempfile |
|
15 | 15 | from distutils.core import setup, Extension |
|
16 | 16 | from distutils.command.install_data import install_data |
|
17 | 17 | from distutils.ccompiler import new_compiler |
|
18 | 18 | |
|
19 | 19 | import mercurial.version |
|
20 | 20 | |
|
21 | 21 | extra = {} |
|
22 | 22 | |
|
23 | 23 | # simplified version of distutils.ccompiler.CCompiler.has_function |
|
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 |
|
44 | 56 | try: |
|
45 | 57 | import py2exe |
|
46 | 58 | |
|
47 | 59 | # Help py2exe to find win32com.shell |
|
48 | 60 | try: |
|
49 | 61 | import modulefinder |
|
50 | 62 | import win32com |
|
51 | 63 | for p in win32com.__path__[1:]: # Take the path to win32comext |
|
52 | 64 | modulefinder.AddPackagePath("win32com", p) |
|
53 | 65 | pn = "win32com.shell" |
|
54 | 66 | __import__(pn) |
|
55 | 67 | m = sys.modules[pn] |
|
56 | 68 | for p in m.__path__[1:]: |
|
57 | 69 | modulefinder.AddPackagePath(pn, p) |
|
58 | 70 | except ImportError: |
|
59 | 71 | pass |
|
60 | 72 | |
|
61 | 73 | extra['console'] = ['hg'] |
|
62 | 74 | |
|
63 | 75 | except ImportError: |
|
64 | 76 | pass |
|
65 | 77 | |
|
66 | 78 | # specify version string, otherwise 'hg identify' will be used: |
|
67 | 79 | version = '' |
|
68 | 80 | |
|
69 | 81 | class install_package_data(install_data): |
|
70 | 82 | def finalize_options(self): |
|
71 | 83 | self.set_undefined_options('install', |
|
72 | 84 | ('install_lib', 'install_dir')) |
|
73 | 85 | install_data.finalize_options(self) |
|
74 | 86 | |
|
75 | 87 | mercurial.version.remember_version(version) |
|
76 | 88 | cmdclass = {'install_data': install_package_data} |
|
77 | 89 | |
|
78 | 90 | ext_modules=[ |
|
79 | 91 | Extension('mercurial.mpatch', ['mercurial/mpatch.c']), |
|
80 | 92 | Extension('mercurial.bdiff', ['mercurial/bdiff.c']), |
|
81 | 93 | Extension('mercurial.base85', ['mercurial/base85.c']), |
|
82 | 94 | Extension('mercurial.diffhelpers', ['mercurial/diffhelpers.c']) |
|
83 | 95 | ] |
|
84 | 96 | |
|
85 | 97 | packages = ['mercurial', 'mercurial.hgweb', 'hgext', 'hgext.convert'] |
|
86 | 98 | |
|
87 | 99 | try: |
|
88 | 100 | import posix |
|
89 | 101 | ext_modules.append(Extension('mercurial.osutil', ['mercurial/osutil.c'])) |
|
90 | 102 | |
|
91 | 103 | if sys.platform == 'linux2' and os.uname()[2] > '2.6': |
|
92 | 104 | # The inotify extension is only usable with Linux 2.6 kernels. |
|
93 | 105 | # You also need a reasonably recent C library. |
|
94 | 106 | cc = new_compiler() |
|
95 | 107 | if has_function(cc, 'inotify_add_watch'): |
|
96 | 108 | ext_modules.append(Extension('hgext.inotify.linux._inotify', |
|
97 | 109 | ['hgext/inotify/linux/_inotify.c'])) |
|
98 | 110 | packages.extend(['hgext.inotify', 'hgext.inotify.linux']) |
|
99 | 111 | except ImportError: |
|
100 | 112 | pass |
|
101 | 113 | |
|
102 | 114 | setup(name='mercurial', |
|
103 | 115 | version=mercurial.version.get_version(), |
|
104 | 116 | author='Matt Mackall', |
|
105 | 117 | author_email='mpm@selenic.com', |
|
106 | 118 | url='http://selenic.com/mercurial', |
|
107 | 119 | description='Scalable distributed SCM', |
|
108 | 120 | license='GNU GPL', |
|
109 | 121 | scripts=['hg'], |
|
110 | 122 | packages=packages, |
|
111 | 123 | ext_modules=ext_modules, |
|
112 | 124 | data_files=[(os.path.join('mercurial', root), |
|
113 | 125 | [os.path.join(root, file_) for file_ in files]) |
|
114 | 126 | for root, dirs, files in os.walk('templates')], |
|
115 | 127 | cmdclass=cmdclass, |
|
116 | 128 | options=dict(py2exe=dict(packages=['hgext']), |
|
117 | 129 | bdist_mpkg=dict(zipdist=True, |
|
118 | 130 | license='COPYING', |
|
119 | 131 | readme='contrib/macosx/Readme.html', |
|
120 | 132 | welcome='contrib/macosx/Welcome.html')), |
|
121 | 133 | **extra) |
General Comments 0
You need to be logged in to leave comments.
Login now