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