##// END OF EJS Templates
setup: do not use -c with msgfmt on Solaris (issue1489)
Martin Geisler -
r7720:b6c2cb40 default
parent child Browse files
Show More
@@ -1,208 +1,211 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 # 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.command.build import build
35 35 from distutils.spawn import spawn, find_executable
36 36 from distutils.ccompiler import new_compiler
37 37
38 38 extra = {}
39 39 scripts = ['hg']
40 40 if os.name == 'nt':
41 41 scripts.append('contrib/win32/hg.bat')
42 42
43 43 # simplified version of distutils.ccompiler.CCompiler.has_function
44 44 # that actually removes its temporary files.
45 45 def has_function(cc, funcname):
46 46 tmpdir = tempfile.mkdtemp(prefix='hg-install-')
47 47 devnull = oldstderr = None
48 48 try:
49 49 try:
50 50 fname = os.path.join(tmpdir, 'funcname.c')
51 51 f = open(fname, 'w')
52 52 f.write('int main(void) {\n')
53 53 f.write(' %s();\n' % funcname)
54 54 f.write('}\n')
55 55 f.close()
56 56 # Redirect stderr to /dev/null to hide any error messages
57 57 # from the compiler.
58 58 # This will have to be changed if we ever have to check
59 59 # for a function on Windows.
60 60 devnull = open('/dev/null', 'w')
61 61 oldstderr = os.dup(sys.stderr.fileno())
62 62 os.dup2(devnull.fileno(), sys.stderr.fileno())
63 63 objects = cc.compile([fname])
64 64 cc.link_executable(objects, os.path.join(tmpdir, "a.out"))
65 65 except:
66 66 return False
67 67 return True
68 68 finally:
69 69 if oldstderr is not None:
70 70 os.dup2(oldstderr, sys.stderr.fileno())
71 71 if devnull is not None:
72 72 devnull.close()
73 73 shutil.rmtree(tmpdir)
74 74
75 75 # py2exe needs to be installed to work
76 76 try:
77 77 import py2exe
78 78
79 79 # Help py2exe to find win32com.shell
80 80 try:
81 81 import modulefinder
82 82 import win32com
83 83 for p in win32com.__path__[1:]: # Take the path to win32comext
84 84 modulefinder.AddPackagePath("win32com", p)
85 85 pn = "win32com.shell"
86 86 __import__(pn)
87 87 m = sys.modules[pn]
88 88 for p in m.__path__[1:]:
89 89 modulefinder.AddPackagePath(pn, p)
90 90 except ImportError:
91 91 pass
92 92
93 93 extra['console'] = ['hg']
94 94
95 95 except ImportError:
96 96 pass
97 97
98 98 try:
99 99 l = os.popen('hg id -it').read().split()
100 100 while len(l) > 1 and l[-1][0].isalpha(): # remove non-numbered tags
101 101 l.pop()
102 102 version = l and l[-1] or 'unknown' # latest tag or revision number
103 103 if version.endswith('+'):
104 104 version += time.strftime('%Y%m%d')
105 105
106 106 except OSError:
107 107 version = "unknown"
108 108
109 109 f = file("mercurial/__version__.py", "w")
110 110 f.write('# this file is autogenerated by setup.py\n')
111 111 f.write('version = "%s"\n' % version)
112 112 f.close()
113 113
114 114 class install_package_data(install_data):
115 115 def finalize_options(self):
116 116 self.set_undefined_options('install',
117 117 ('install_lib', 'install_dir'))
118 118 install_data.finalize_options(self)
119 119
120 120 class build_mo(build):
121 121
122 122 description = "build translations (.mo files)"
123 123
124 124 def run(self):
125 125 if not find_executable('msgfmt'):
126 126 self.warn("could not find msgfmt executable, no translations "
127 127 "will be built")
128 128 return
129 129
130 130 podir = 'i18n'
131 131 if not os.path.isdir(podir):
132 132 self.warn("could not find %s/ directory" % podir)
133 133 return
134 134
135 135 join = os.path.join
136 136 for po in os.listdir(podir):
137 137 if not po.endswith('.po'):
138 138 continue
139 139 pofile = join(podir, po)
140 140 modir = join('locale', po[:-3], 'LC_MESSAGES')
141 141 mofile = join(modir, 'hg.mo')
142 cmd = ['msgfmt', '-v', '-o', mofile, pofile]
143 if sys.platform != 'sunos5':
144 # msgfmt on Solaris does not know about -c
145 cmd.append('-c')
142 146 self.mkpath(modir)
143 self.make_file([pofile], mofile, spawn,
144 (['msgfmt', '-v', '-c', '-o', mofile, pofile],))
147 self.make_file([pofile], mofile, spawn, (cmd,))
145 148 self.distribution.data_files.append((join('mercurial', modir),
146 149 [mofile]))
147 150
148 151 build.sub_commands.append(('build_mo', None))
149 152
150 153 cmdclass = {'install_data': install_package_data,
151 154 'build_mo': build_mo}
152 155
153 156 ext_modules=[
154 157 Extension('mercurial.base85', ['mercurial/base85.c']),
155 158 Extension('mercurial.bdiff', ['mercurial/bdiff.c']),
156 159 Extension('mercurial.diffhelpers', ['mercurial/diffhelpers.c']),
157 160 Extension('mercurial.mpatch', ['mercurial/mpatch.c']),
158 161 Extension('mercurial.parsers', ['mercurial/parsers.c']),
159 162 ]
160 163
161 164 packages = ['mercurial', 'mercurial.hgweb', 'hgext', 'hgext.convert',
162 165 'hgext.highlight', 'hgext.zeroconf', ]
163 166
164 167 try:
165 168 import msvcrt
166 169 ext_modules.append(Extension('mercurial.osutil', ['mercurial/osutil.c']))
167 170 except ImportError:
168 171 pass
169 172
170 173 try:
171 174 import posix
172 175 ext_modules.append(Extension('mercurial.osutil', ['mercurial/osutil.c']))
173 176
174 177 if sys.platform == 'linux2' and os.uname()[2] > '2.6':
175 178 # The inotify extension is only usable with Linux 2.6 kernels.
176 179 # You also need a reasonably recent C library.
177 180 cc = new_compiler()
178 181 if has_function(cc, 'inotify_add_watch'):
179 182 ext_modules.append(Extension('hgext.inotify.linux._inotify',
180 183 ['hgext/inotify/linux/_inotify.c']))
181 184 packages.extend(['hgext.inotify', 'hgext.inotify.linux'])
182 185 except ImportError:
183 186 pass
184 187
185 188 datafiles = []
186 189 for root in ('templates', 'i18n'):
187 190 for dir, dirs, files in os.walk(root):
188 191 datafiles.append((os.path.join('mercurial', dir),
189 192 [os.path.join(dir, file_) for file_ in files]))
190 193
191 194 setup(name='mercurial',
192 195 version=version,
193 196 author='Matt Mackall',
194 197 author_email='mpm@selenic.com',
195 198 url='http://selenic.com/mercurial',
196 199 description='Scalable distributed SCM',
197 200 license='GNU GPL',
198 201 scripts=scripts,
199 202 packages=packages,
200 203 ext_modules=ext_modules,
201 204 data_files=datafiles,
202 205 cmdclass=cmdclass,
203 206 options=dict(py2exe=dict(packages=['hgext', 'email']),
204 207 bdist_mpkg=dict(zipdist=True,
205 208 license='COPYING',
206 209 readme='contrib/macosx/Readme.html',
207 210 welcome='contrib/macosx/Welcome.html')),
208 211 **extra)
General Comments 0
You need to be logged in to leave comments. Login now