##// END OF EJS Templates
recover when no version information is available
Benoit Boissinot -
r7647:f7256cd9 default
parent child Browse files
Show More
@@ -1,171 +1,171
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 # Solaris Python packaging brain damage
13 13 try:
14 14 import hashlib
15 15 sha = hashlib.sha1()
16 16 except:
17 17 try:
18 18 import sha
19 19 except:
20 20 raise SystemExit(
21 21 "Couldn't import standard hashlib (incomplete Python install).")
22 22
23 23 try:
24 24 import zlib
25 25 except:
26 26 raise SystemExit(
27 27 "Couldn't import standard zlib (incomplete Python install).")
28 28
29 29 import os, time
30 30 import shutil
31 31 import tempfile
32 32 from distutils.core import setup, Extension
33 33 from distutils.command.install_data import install_data
34 34 from distutils.ccompiler import new_compiler
35 35
36 36 extra = {}
37 37 scripts = ['hg']
38 38 if os.name == 'nt':
39 39 scripts.append('contrib/win32/hg.bat')
40 40
41 41 # simplified version of distutils.ccompiler.CCompiler.has_function
42 42 # that actually removes its temporary files.
43 43 def has_function(cc, funcname):
44 44 tmpdir = tempfile.mkdtemp(prefix='hg-install-')
45 45 devnull = oldstderr = None
46 46 try:
47 47 try:
48 48 fname = os.path.join(tmpdir, 'funcname.c')
49 49 f = open(fname, 'w')
50 50 f.write('int main(void) {\n')
51 51 f.write(' %s();\n' % funcname)
52 52 f.write('}\n')
53 53 f.close()
54 54 # Redirect stderr to /dev/null to hide any error messages
55 55 # from the compiler.
56 56 # This will have to be changed if we ever have to check
57 57 # for a function on Windows.
58 58 devnull = open('/dev/null', 'w')
59 59 oldstderr = os.dup(sys.stderr.fileno())
60 60 os.dup2(devnull.fileno(), sys.stderr.fileno())
61 61 objects = cc.compile([fname])
62 62 cc.link_executable(objects, os.path.join(tmpdir, "a.out"))
63 63 except:
64 64 return False
65 65 return True
66 66 finally:
67 67 if oldstderr is not None:
68 68 os.dup2(oldstderr, sys.stderr.fileno())
69 69 if devnull is not None:
70 70 devnull.close()
71 71 shutil.rmtree(tmpdir)
72 72
73 73 # py2exe needs to be installed to work
74 74 try:
75 75 import py2exe
76 76
77 77 # Help py2exe to find win32com.shell
78 78 try:
79 79 import modulefinder
80 80 import win32com
81 81 for p in win32com.__path__[1:]: # Take the path to win32comext
82 82 modulefinder.AddPackagePath("win32com", p)
83 83 pn = "win32com.shell"
84 84 __import__(pn)
85 85 m = sys.modules[pn]
86 86 for p in m.__path__[1:]:
87 87 modulefinder.AddPackagePath(pn, p)
88 88 except ImportError:
89 89 pass
90 90
91 91 extra['console'] = ['hg']
92 92
93 93 except ImportError:
94 94 pass
95 95
96 96 try:
97 97 l = os.popen('hg id -it').read().split()
98 98 while len(l) > 1 and l[-1][0].isalpha(): # remove non-numbered tags
99 99 l.pop()
100 version = l[-1] or 'unknown' # latest tag or revision number
100 version = l and l[-1] or 'unknown' # latest tag or revision number
101 101 if version.endswith('+'):
102 102 version += time.strftime('%Y%m%d')
103 103
104 104 except OSError:
105 105 version = "unknown"
106 106
107 107 f = file("mercurial/__version__.py", "w")
108 108 f.write('# this file is autogenerated by setup.py\n')
109 109 f.write('version = "%s"\n' % version)
110 110 f.close()
111 111
112 112 class install_package_data(install_data):
113 113 def finalize_options(self):
114 114 self.set_undefined_options('install',
115 115 ('install_lib', 'install_dir'))
116 116 install_data.finalize_options(self)
117 117
118 118 cmdclass = {'install_data': install_package_data}
119 119
120 120 ext_modules=[
121 121 Extension('mercurial.base85', ['mercurial/base85.c']),
122 122 Extension('mercurial.bdiff', ['mercurial/bdiff.c']),
123 123 Extension('mercurial.diffhelpers', ['mercurial/diffhelpers.c']),
124 124 Extension('mercurial.mpatch', ['mercurial/mpatch.c']),
125 125 Extension('mercurial.parsers', ['mercurial/parsers.c']),
126 126 ]
127 127
128 128 packages = ['mercurial', 'mercurial.hgweb', 'hgext', 'hgext.convert',
129 129 'hgext.highlight', 'hgext.zeroconf', ]
130 130
131 131 try:
132 132 import msvcrt
133 133 ext_modules.append(Extension('mercurial.osutil', ['mercurial/osutil.c']))
134 134 except ImportError:
135 135 pass
136 136
137 137 try:
138 138 import posix
139 139 ext_modules.append(Extension('mercurial.osutil', ['mercurial/osutil.c']))
140 140
141 141 if sys.platform == 'linux2' and os.uname()[2] > '2.6':
142 142 # The inotify extension is only usable with Linux 2.6 kernels.
143 143 # You also need a reasonably recent C library.
144 144 cc = new_compiler()
145 145 if has_function(cc, 'inotify_add_watch'):
146 146 ext_modules.append(Extension('hgext.inotify.linux._inotify',
147 147 ['hgext/inotify/linux/_inotify.c']))
148 148 packages.extend(['hgext.inotify', 'hgext.inotify.linux'])
149 149 except ImportError:
150 150 pass
151 151
152 152 setup(name='mercurial',
153 153 version=version,
154 154 author='Matt Mackall',
155 155 author_email='mpm@selenic.com',
156 156 url='http://selenic.com/mercurial',
157 157 description='Scalable distributed SCM',
158 158 license='GNU GPL',
159 159 scripts=scripts,
160 160 packages=packages,
161 161 ext_modules=ext_modules,
162 162 data_files=[(os.path.join('mercurial', root),
163 163 [os.path.join(root, file_) for file_ in files])
164 164 for root, dirs, files in os.walk('templates')],
165 165 cmdclass=cmdclass,
166 166 options=dict(py2exe=dict(packages=['hgext', 'email']),
167 167 bdist_mpkg=dict(zipdist=True,
168 168 license='COPYING',
169 169 readme='contrib/macosx/Readme.html',
170 170 welcome='contrib/macosx/Welcome.html')),
171 171 **extra)
General Comments 0
You need to be logged in to leave comments. Login now