##// END OF EJS Templates
setup: remove set and dict comprehensions...
Gregory Szorc -
r42365:bd92dd3e stable
parent child Browse files
Show More
@@ -1,1463 +1,1466 b''
1 1 #
2 2 # This is the mercurial setup script.
3 3 #
4 4 # 'python setup.py install', or
5 5 # 'python setup.py --help' for more options
6 6
7 7 import os
8 8
9 9 supportedpy = '~= 2.7'
10 10 if os.environ.get('HGALLOWPYTHON3', ''):
11 11 # Mercurial will never work on Python 3 before 3.5 due to a lack
12 12 # of % formatting on bytestrings, and can't work on 3.6.0 or 3.6.1
13 13 # due to a bug in % formatting in bytestrings.
14 14 # We cannot support Python 3.5.0, 3.5.1, 3.5.2 because of bug in
15 15 # codecs.escape_encode() where it raises SystemError on empty bytestring
16 16 # bug link: https://bugs.python.org/issue25270
17 17 #
18 18 # TODO: when we actually work on Python 3, use this string as the
19 19 # actual supportedpy string.
20 20 supportedpy = ','.join([
21 21 '>=2.7',
22 22 '!=3.0.*',
23 23 '!=3.1.*',
24 24 '!=3.2.*',
25 25 '!=3.3.*',
26 26 '!=3.4.*',
27 27 '!=3.5.0',
28 28 '!=3.5.1',
29 29 '!=3.5.2',
30 30 '!=3.6.0',
31 31 '!=3.6.1',
32 32 ])
33 33
34 34 import sys, platform
35 35 if sys.version_info[0] >= 3:
36 36 printf = eval('print')
37 37 libdir_escape = 'unicode_escape'
38 38 def sysstr(s):
39 39 return s.decode('latin-1')
40 40 else:
41 41 libdir_escape = 'string_escape'
42 42 def printf(*args, **kwargs):
43 43 f = kwargs.get('file', sys.stdout)
44 44 end = kwargs.get('end', '\n')
45 45 f.write(b' '.join(args) + end)
46 46 def sysstr(s):
47 47 return s
48 48
49 49 # Attempt to guide users to a modern pip - this means that 2.6 users
50 50 # should have a chance of getting a 4.2 release, and when we ratchet
51 51 # the version requirement forward again hopefully everyone will get
52 52 # something that works for them.
53 53 if sys.version_info < (2, 7, 0, 'final'):
54 54 pip_message = ('This may be due to an out of date pip. '
55 55 'Make sure you have pip >= 9.0.1.')
56 56 try:
57 57 import pip
58 58 pip_version = tuple([int(x) for x in pip.__version__.split('.')[:3]])
59 59 if pip_version < (9, 0, 1) :
60 60 pip_message = (
61 61 'Your pip version is out of date, please install '
62 62 'pip >= 9.0.1. pip {} detected.'.format(pip.__version__))
63 63 else:
64 64 # pip is new enough - it must be something else
65 65 pip_message = ''
66 66 except Exception:
67 67 pass
68 68 error = """
69 69 Mercurial does not support Python older than 2.7.
70 70 Python {py} detected.
71 71 {pip}
72 72 """.format(py=sys.version_info, pip=pip_message)
73 73 printf(error, file=sys.stderr)
74 74 sys.exit(1)
75 75
76 76 # We don't yet officially support Python 3. But we want to allow developers to
77 77 # hack on. Detect and disallow running on Python 3 by default. But provide a
78 78 # backdoor to enable working on Python 3.
79 79 if sys.version_info[0] != 2:
80 80 badpython = True
81 81
82 82 # Allow Python 3 from source checkouts.
83 83 if os.path.isdir('.hg') or 'HGPYTHON3' in os.environ:
84 84 badpython = False
85 85
86 86 if badpython:
87 87 error = """
88 88 Mercurial only supports Python 2.7.
89 89 Python {py} detected.
90 90 Please re-run with Python 2.7.
91 91 """.format(py=sys.version_info)
92 92
93 93 printf(error, file=sys.stderr)
94 94 sys.exit(1)
95 95
96 96 # Solaris Python packaging brain damage
97 97 try:
98 98 import hashlib
99 99 sha = hashlib.sha1()
100 100 except ImportError:
101 101 try:
102 102 import sha
103 103 sha.sha # silence unused import warning
104 104 except ImportError:
105 105 raise SystemExit(
106 106 "Couldn't import standard hashlib (incomplete Python install).")
107 107
108 108 try:
109 109 import zlib
110 110 zlib.compressobj # silence unused import warning
111 111 except ImportError:
112 112 raise SystemExit(
113 113 "Couldn't import standard zlib (incomplete Python install).")
114 114
115 115 # The base IronPython distribution (as of 2.7.1) doesn't support bz2
116 116 isironpython = False
117 117 try:
118 118 isironpython = (platform.python_implementation()
119 119 .lower().find("ironpython") != -1)
120 120 except AttributeError:
121 121 pass
122 122
123 123 if isironpython:
124 124 sys.stderr.write("warning: IronPython detected (no bz2 support)\n")
125 125 else:
126 126 try:
127 127 import bz2
128 128 bz2.BZ2Compressor # silence unused import warning
129 129 except ImportError:
130 130 raise SystemExit(
131 131 "Couldn't import standard bz2 (incomplete Python install).")
132 132
133 133 ispypy = "PyPy" in sys.version
134 134
135 135 hgrustext = os.environ.get('HGWITHRUSTEXT')
136 136 # TODO record it for proper rebuild upon changes
137 137 # (see mercurial/__modulepolicy__.py)
138 138 if hgrustext != 'cpython' and hgrustext is not None:
139 139 hgrustext = 'direct-ffi'
140 140
141 141 import ctypes
142 142 import errno
143 143 import stat, subprocess, time
144 144 import re
145 145 import shutil
146 146 import tempfile
147 147 from distutils import log
148 148 # We have issues with setuptools on some platforms and builders. Until
149 149 # those are resolved, setuptools is opt-in except for platforms where
150 150 # we don't have issues.
151 151 issetuptools = (os.name == 'nt' or 'FORCE_SETUPTOOLS' in os.environ)
152 152 if issetuptools:
153 153 from setuptools import setup
154 154 else:
155 155 from distutils.core import setup
156 156 from distutils.ccompiler import new_compiler
157 157 from distutils.core import Command, Extension
158 158 from distutils.dist import Distribution
159 159 from distutils.command.build import build
160 160 from distutils.command.build_ext import build_ext
161 161 from distutils.command.build_py import build_py
162 162 from distutils.command.build_scripts import build_scripts
163 163 from distutils.command.install import install
164 164 from distutils.command.install_lib import install_lib
165 165 from distutils.command.install_scripts import install_scripts
166 166 from distutils.spawn import spawn, find_executable
167 167 from distutils import file_util
168 168 from distutils.errors import (
169 169 CCompilerError,
170 170 DistutilsError,
171 171 DistutilsExecError,
172 172 )
173 173 from distutils.sysconfig import get_python_inc, get_config_var
174 174 from distutils.version import StrictVersion
175 175
176 176 # Explain to distutils.StrictVersion how our release candidates are versionned
177 177 StrictVersion.version_re = re.compile(r'^(\d+)\.(\d+)(\.(\d+))?-?(rc(\d+))?$')
178 178
179 179 def write_if_changed(path, content):
180 180 """Write content to a file iff the content hasn't changed."""
181 181 if os.path.exists(path):
182 182 with open(path, 'rb') as fh:
183 183 current = fh.read()
184 184 else:
185 185 current = b''
186 186
187 187 if current != content:
188 188 with open(path, 'wb') as fh:
189 189 fh.write(content)
190 190
191 191 scripts = ['hg']
192 192 if os.name == 'nt':
193 193 # We remove hg.bat if we are able to build hg.exe.
194 194 scripts.append('contrib/win32/hg.bat')
195 195
196 196 def cancompile(cc, code):
197 197 tmpdir = tempfile.mkdtemp(prefix='hg-install-')
198 198 devnull = oldstderr = None
199 199 try:
200 200 fname = os.path.join(tmpdir, 'testcomp.c')
201 201 f = open(fname, 'w')
202 202 f.write(code)
203 203 f.close()
204 204 # Redirect stderr to /dev/null to hide any error messages
205 205 # from the compiler.
206 206 # This will have to be changed if we ever have to check
207 207 # for a function on Windows.
208 208 devnull = open('/dev/null', 'w')
209 209 oldstderr = os.dup(sys.stderr.fileno())
210 210 os.dup2(devnull.fileno(), sys.stderr.fileno())
211 211 objects = cc.compile([fname], output_dir=tmpdir)
212 212 cc.link_executable(objects, os.path.join(tmpdir, "a.out"))
213 213 return True
214 214 except Exception:
215 215 return False
216 216 finally:
217 217 if oldstderr is not None:
218 218 os.dup2(oldstderr, sys.stderr.fileno())
219 219 if devnull is not None:
220 220 devnull.close()
221 221 shutil.rmtree(tmpdir)
222 222
223 223 # simplified version of distutils.ccompiler.CCompiler.has_function
224 224 # that actually removes its temporary files.
225 225 def hasfunction(cc, funcname):
226 226 code = 'int main(void) { %s(); }\n' % funcname
227 227 return cancompile(cc, code)
228 228
229 229 def hasheader(cc, headername):
230 230 code = '#include <%s>\nint main(void) { return 0; }\n' % headername
231 231 return cancompile(cc, code)
232 232
233 233 # py2exe needs to be installed to work
234 234 try:
235 235 import py2exe
236 236 py2exe.Distribution # silence unused import warning
237 237 py2exeloaded = True
238 238 # import py2exe's patched Distribution class
239 239 from distutils.core import Distribution
240 240 except ImportError:
241 241 py2exeloaded = False
242 242
243 243 def runcmd(cmd, env, cwd=None):
244 244 p = subprocess.Popen(cmd, stdout=subprocess.PIPE,
245 245 stderr=subprocess.PIPE, env=env, cwd=cwd)
246 246 out, err = p.communicate()
247 247 return p.returncode, out, err
248 248
249 249 class hgcommand(object):
250 250 def __init__(self, cmd, env):
251 251 self.cmd = cmd
252 252 self.env = env
253 253
254 254 def run(self, args):
255 255 cmd = self.cmd + args
256 256 returncode, out, err = runcmd(cmd, self.env)
257 257 err = filterhgerr(err)
258 258 if err or returncode != 0:
259 259 printf("stderr from '%s':" % (' '.join(cmd)), file=sys.stderr)
260 260 printf(err, file=sys.stderr)
261 261 return ''
262 262 return out
263 263
264 264 def filterhgerr(err):
265 265 # If root is executing setup.py, but the repository is owned by
266 266 # another user (as in "sudo python setup.py install") we will get
267 267 # trust warnings since the .hg/hgrc file is untrusted. That is
268 268 # fine, we don't want to load it anyway. Python may warn about
269 269 # a missing __init__.py in mercurial/locale, we also ignore that.
270 270 err = [e for e in err.splitlines()
271 271 if (not e.startswith(b'not trusting file')
272 272 and not e.startswith(b'warning: Not importing')
273 273 and not e.startswith(b'obsolete feature not enabled')
274 274 and not e.startswith(b'*** failed to import extension')
275 275 and not e.startswith(b'devel-warn:')
276 276 and not (e.startswith(b'(third party extension')
277 277 and e.endswith(b'or newer of Mercurial; disabling)')))]
278 278 return b'\n'.join(b' ' + e for e in err)
279 279
280 280 def findhg():
281 281 """Try to figure out how we should invoke hg for examining the local
282 282 repository contents.
283 283
284 284 Returns an hgcommand object."""
285 285 # By default, prefer the "hg" command in the user's path. This was
286 286 # presumably the hg command that the user used to create this repository.
287 287 #
288 288 # This repository may require extensions or other settings that would not
289 289 # be enabled by running the hg script directly from this local repository.
290 290 hgenv = os.environ.copy()
291 291 # Use HGPLAIN to disable hgrc settings that would change output formatting,
292 292 # and disable localization for the same reasons.
293 293 hgenv['HGPLAIN'] = '1'
294 294 hgenv['LANGUAGE'] = 'C'
295 295 hgcmd = ['hg']
296 296 # Run a simple "hg log" command just to see if using hg from the user's
297 297 # path works and can successfully interact with this repository. Windows
298 298 # gives precedence to hg.exe in the current directory, so fall back to the
299 299 # python invocation of local hg, where pythonXY.dll can always be found.
300 300 check_cmd = ['log', '-r.', '-Ttest']
301 301 if os.name != 'nt':
302 302 try:
303 303 retcode, out, err = runcmd(hgcmd + check_cmd, hgenv)
304 304 except EnvironmentError:
305 305 retcode = -1
306 306 if retcode == 0 and not filterhgerr(err):
307 307 return hgcommand(hgcmd, hgenv)
308 308
309 309 # Fall back to trying the local hg installation.
310 310 hgenv = localhgenv()
311 311 hgcmd = [sys.executable, 'hg']
312 312 try:
313 313 retcode, out, err = runcmd(hgcmd + check_cmd, hgenv)
314 314 except EnvironmentError:
315 315 retcode = -1
316 316 if retcode == 0 and not filterhgerr(err):
317 317 return hgcommand(hgcmd, hgenv)
318 318
319 319 raise SystemExit('Unable to find a working hg binary to extract the '
320 320 'version from the repository tags')
321 321
322 322 def localhgenv():
323 323 """Get an environment dictionary to use for invoking or importing
324 324 mercurial from the local repository."""
325 325 # Execute hg out of this directory with a custom environment which takes
326 326 # care to not use any hgrc files and do no localization.
327 327 env = {'HGMODULEPOLICY': 'py',
328 328 'HGRCPATH': '',
329 329 'LANGUAGE': 'C',
330 330 'PATH': ''} # make pypi modules that use os.environ['PATH'] happy
331 331 if 'LD_LIBRARY_PATH' in os.environ:
332 332 env['LD_LIBRARY_PATH'] = os.environ['LD_LIBRARY_PATH']
333 333 if 'SystemRoot' in os.environ:
334 334 # SystemRoot is required by Windows to load various DLLs. See:
335 335 # https://bugs.python.org/issue13524#msg148850
336 336 env['SystemRoot'] = os.environ['SystemRoot']
337 337 return env
338 338
339 339 version = ''
340 340
341 341 if os.path.isdir('.hg'):
342 342 hg = findhg()
343 343 cmd = ['log', '-r', '.', '--template', '{tags}\n']
344 344 numerictags = [t for t in sysstr(hg.run(cmd)).split() if t[0:1].isdigit()]
345 345 hgid = sysstr(hg.run(['id', '-i'])).strip()
346 346 if not hgid:
347 347 # Bail out if hg is having problems interacting with this repository,
348 348 # rather than falling through and producing a bogus version number.
349 349 # Continuing with an invalid version number will break extensions
350 350 # that define minimumhgversion.
351 351 raise SystemExit('Unable to determine hg version from local repository')
352 352 if numerictags: # tag(s) found
353 353 version = numerictags[-1]
354 354 if hgid.endswith('+'): # propagate the dirty status to the tag
355 355 version += '+'
356 356 else: # no tag found
357 357 ltagcmd = ['parents', '--template', '{latesttag}']
358 358 ltag = sysstr(hg.run(ltagcmd))
359 359 changessincecmd = ['log', '-T', 'x\n', '-r', "only(.,'%s')" % ltag]
360 360 changessince = len(hg.run(changessincecmd).splitlines())
361 361 version = '%s+%s-%s' % (ltag, changessince, hgid)
362 362 if version.endswith('+'):
363 363 version += time.strftime('%Y%m%d')
364 364 elif os.path.exists('.hg_archival.txt'):
365 365 kw = dict([[t.strip() for t in l.split(':', 1)]
366 366 for l in open('.hg_archival.txt')])
367 367 if 'tag' in kw:
368 368 version = kw['tag']
369 369 elif 'latesttag' in kw:
370 370 if 'changessincelatesttag' in kw:
371 371 version = '%(latesttag)s+%(changessincelatesttag)s-%(node).12s' % kw
372 372 else:
373 373 version = '%(latesttag)s+%(latesttagdistance)s-%(node).12s' % kw
374 374 else:
375 375 version = kw.get('node', '')[:12]
376 376
377 377 if version:
378 378 versionb = version
379 379 if not isinstance(versionb, bytes):
380 380 versionb = versionb.encode('ascii')
381 381
382 382 write_if_changed('mercurial/__version__.py', b''.join([
383 383 b'# this file is autogenerated by setup.py\n'
384 384 b'version = b"%s"\n' % versionb,
385 385 ]))
386 386
387 387 try:
388 388 oldpolicy = os.environ.get('HGMODULEPOLICY', None)
389 389 os.environ['HGMODULEPOLICY'] = 'py'
390 390 from mercurial import __version__
391 391 version = __version__.version
392 392 except ImportError:
393 393 version = b'unknown'
394 394 finally:
395 395 if oldpolicy is None:
396 396 del os.environ['HGMODULEPOLICY']
397 397 else:
398 398 os.environ['HGMODULEPOLICY'] = oldpolicy
399 399
400 400 class hgbuild(build):
401 401 # Insert hgbuildmo first so that files in mercurial/locale/ are found
402 402 # when build_py is run next.
403 403 sub_commands = [('build_mo', None)] + build.sub_commands
404 404
405 405 class hgbuildmo(build):
406 406
407 407 description = "build translations (.mo files)"
408 408
409 409 def run(self):
410 410 if not find_executable('msgfmt'):
411 411 self.warn("could not find msgfmt executable, no translations "
412 412 "will be built")
413 413 return
414 414
415 415 podir = 'i18n'
416 416 if not os.path.isdir(podir):
417 417 self.warn("could not find %s/ directory" % podir)
418 418 return
419 419
420 420 join = os.path.join
421 421 for po in os.listdir(podir):
422 422 if not po.endswith('.po'):
423 423 continue
424 424 pofile = join(podir, po)
425 425 modir = join('locale', po[:-3], 'LC_MESSAGES')
426 426 mofile = join(modir, 'hg.mo')
427 427 mobuildfile = join('mercurial', mofile)
428 428 cmd = ['msgfmt', '-v', '-o', mobuildfile, pofile]
429 429 if sys.platform != 'sunos5':
430 430 # msgfmt on Solaris does not know about -c
431 431 cmd.append('-c')
432 432 self.mkpath(join('mercurial', modir))
433 433 self.make_file([pofile], mobuildfile, spawn, (cmd,))
434 434
435 435
436 436 class hgdist(Distribution):
437 437 pure = False
438 438 cffi = ispypy
439 439
440 440 global_options = Distribution.global_options + [
441 441 ('pure', None, "use pure (slow) Python code instead of C extensions"),
442 442 ]
443 443
444 444 def has_ext_modules(self):
445 445 # self.ext_modules is emptied in hgbuildpy.finalize_options which is
446 446 # too late for some cases
447 447 return not self.pure and Distribution.has_ext_modules(self)
448 448
449 449 # This is ugly as a one-liner. So use a variable.
450 450 buildextnegops = dict(getattr(build_ext, 'negative_options', {}))
451 451 buildextnegops['no-zstd'] = 'zstd'
452 452
453 453 class hgbuildext(build_ext):
454 454 user_options = build_ext.user_options + [
455 455 ('zstd', None, 'compile zstd bindings [default]'),
456 456 ('no-zstd', None, 'do not compile zstd bindings'),
457 457 ]
458 458
459 459 boolean_options = build_ext.boolean_options + ['zstd']
460 460 negative_opt = buildextnegops
461 461
462 462 def initialize_options(self):
463 463 self.zstd = True
464 464 return build_ext.initialize_options(self)
465 465
466 466 def build_extensions(self):
467 467 ruststandalones = [e for e in self.extensions
468 468 if isinstance(e, RustStandaloneExtension)]
469 469 self.extensions = [e for e in self.extensions
470 470 if e not in ruststandalones]
471 471 # Filter out zstd if disabled via argument.
472 472 if not self.zstd:
473 473 self.extensions = [e for e in self.extensions
474 474 if e.name != 'mercurial.zstd']
475 475
476 476 for rustext in ruststandalones:
477 477 rustext.build('' if self.inplace else self.build_lib)
478 478
479 479 return build_ext.build_extensions(self)
480 480
481 481 def build_extension(self, ext):
482 482 if isinstance(ext, RustExtension):
483 483 ext.rustbuild()
484 484 try:
485 485 build_ext.build_extension(self, ext)
486 486 except CCompilerError:
487 487 if not getattr(ext, 'optional', False):
488 488 raise
489 489 log.warn("Failed to build optional extension '%s' (skipping)",
490 490 ext.name)
491 491
492 492 class hgbuildscripts(build_scripts):
493 493 def run(self):
494 494 if os.name != 'nt' or self.distribution.pure:
495 495 return build_scripts.run(self)
496 496
497 497 exebuilt = False
498 498 try:
499 499 self.run_command('build_hgexe')
500 500 exebuilt = True
501 501 except (DistutilsError, CCompilerError):
502 502 log.warn('failed to build optional hg.exe')
503 503
504 504 if exebuilt:
505 505 # Copying hg.exe to the scripts build directory ensures it is
506 506 # installed by the install_scripts command.
507 507 hgexecommand = self.get_finalized_command('build_hgexe')
508 508 dest = os.path.join(self.build_dir, 'hg.exe')
509 509 self.mkpath(self.build_dir)
510 510 self.copy_file(hgexecommand.hgexepath, dest)
511 511
512 512 # Remove hg.bat because it is redundant with hg.exe.
513 513 self.scripts.remove('contrib/win32/hg.bat')
514 514
515 515 return build_scripts.run(self)
516 516
517 517 class hgbuildpy(build_py):
518 518 def finalize_options(self):
519 519 build_py.finalize_options(self)
520 520
521 521 if self.distribution.pure:
522 522 self.distribution.ext_modules = []
523 523 elif self.distribution.cffi:
524 524 from mercurial.cffi import (
525 525 bdiffbuild,
526 526 mpatchbuild,
527 527 )
528 528 exts = [mpatchbuild.ffi.distutils_extension(),
529 529 bdiffbuild.ffi.distutils_extension()]
530 530 # cffi modules go here
531 531 if sys.platform == 'darwin':
532 532 from mercurial.cffi import osutilbuild
533 533 exts.append(osutilbuild.ffi.distutils_extension())
534 534 self.distribution.ext_modules = exts
535 535 else:
536 536 h = os.path.join(get_python_inc(), 'Python.h')
537 537 if not os.path.exists(h):
538 538 raise SystemExit('Python headers are required to build '
539 539 'Mercurial but weren\'t found in %s' % h)
540 540
541 541 def run(self):
542 542 basepath = os.path.join(self.build_lib, 'mercurial')
543 543 self.mkpath(basepath)
544 544
545 545 if self.distribution.pure:
546 546 modulepolicy = 'py'
547 547 elif self.build_lib == '.':
548 548 # in-place build should run without rebuilding C extensions
549 549 modulepolicy = 'allow'
550 550 else:
551 551 modulepolicy = 'c'
552 552
553 553 content = b''.join([
554 554 b'# this file is autogenerated by setup.py\n',
555 555 b'modulepolicy = b"%s"\n' % modulepolicy.encode('ascii'),
556 556 ])
557 557 write_if_changed(os.path.join(basepath, '__modulepolicy__.py'),
558 558 content)
559 559
560 560 build_py.run(self)
561 561
562 562 class buildhgextindex(Command):
563 563 description = 'generate prebuilt index of hgext (for frozen package)'
564 564 user_options = []
565 565 _indexfilename = 'hgext/__index__.py'
566 566
567 567 def initialize_options(self):
568 568 pass
569 569
570 570 def finalize_options(self):
571 571 pass
572 572
573 573 def run(self):
574 574 if os.path.exists(self._indexfilename):
575 575 with open(self._indexfilename, 'w') as f:
576 576 f.write('# empty\n')
577 577
578 578 # here no extension enabled, disabled() lists up everything
579 579 code = ('import pprint; from mercurial import extensions; '
580 580 'pprint.pprint(extensions.disabled())')
581 581 returncode, out, err = runcmd([sys.executable, '-c', code],
582 582 localhgenv())
583 583 if err or returncode != 0:
584 584 raise DistutilsExecError(err)
585 585
586 586 with open(self._indexfilename, 'wb') as f:
587 587 f.write(b'# this file is autogenerated by setup.py\n')
588 588 f.write(b'docs = ')
589 589 f.write(out)
590 590
591 591 class buildhgexe(build_ext):
592 592 description = 'compile hg.exe from mercurial/exewrapper.c'
593 593 user_options = build_ext.user_options + [
594 594 ('long-paths-support', None, 'enable support for long paths on '
595 595 'Windows (off by default and '
596 596 'experimental)'),
597 597 ]
598 598
599 599 LONG_PATHS_MANIFEST = """
600 600 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
601 601 <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
602 602 <application>
603 603 <windowsSettings
604 604 xmlns:ws2="http://schemas.microsoft.com/SMI/2016/WindowsSettings">
605 605 <ws2:longPathAware>true</ws2:longPathAware>
606 606 </windowsSettings>
607 607 </application>
608 608 </assembly>"""
609 609
610 610 def initialize_options(self):
611 611 build_ext.initialize_options(self)
612 612 self.long_paths_support = False
613 613
614 614 def build_extensions(self):
615 615 if os.name != 'nt':
616 616 return
617 617 if isinstance(self.compiler, HackedMingw32CCompiler):
618 618 self.compiler.compiler_so = self.compiler.compiler # no -mdll
619 619 self.compiler.dll_libraries = [] # no -lmsrvc90
620 620
621 621 # Different Python installs can have different Python library
622 622 # names. e.g. the official CPython distribution uses pythonXY.dll
623 623 # and MinGW uses libpythonX.Y.dll.
624 624 _kernel32 = ctypes.windll.kernel32
625 625 _kernel32.GetModuleFileNameA.argtypes = [ctypes.c_void_p,
626 626 ctypes.c_void_p,
627 627 ctypes.c_ulong]
628 628 _kernel32.GetModuleFileNameA.restype = ctypes.c_ulong
629 629 size = 1000
630 630 buf = ctypes.create_string_buffer(size + 1)
631 631 filelen = _kernel32.GetModuleFileNameA(sys.dllhandle, ctypes.byref(buf),
632 632 size)
633 633
634 634 if filelen > 0 and filelen != size:
635 635 dllbasename = os.path.basename(buf.value)
636 636 if not dllbasename.lower().endswith(b'.dll'):
637 637 raise SystemExit('Python DLL does not end with .dll: %s' %
638 638 dllbasename)
639 639 pythonlib = dllbasename[:-4]
640 640 else:
641 641 log.warn('could not determine Python DLL filename; '
642 642 'assuming pythonXY')
643 643
644 644 hv = sys.hexversion
645 645 pythonlib = 'python%d%d' % (hv >> 24, (hv >> 16) & 0xff)
646 646
647 647 log.info('using %s as Python library name' % pythonlib)
648 648 with open('mercurial/hgpythonlib.h', 'wb') as f:
649 649 f.write(b'/* this file is autogenerated by setup.py */\n')
650 650 f.write(b'#define HGPYTHONLIB "%s"\n' % pythonlib)
651 651
652 652 macros = None
653 653 if sys.version_info[0] >= 3:
654 654 macros = [('_UNICODE', None), ('UNICODE', None)]
655 655
656 656 objects = self.compiler.compile(['mercurial/exewrapper.c'],
657 657 output_dir=self.build_temp,
658 658 macros=macros)
659 659 dir = os.path.dirname(self.get_ext_fullpath('dummy'))
660 660 self.hgtarget = os.path.join(dir, 'hg')
661 661 self.compiler.link_executable(objects, self.hgtarget,
662 662 libraries=[],
663 663 output_dir=self.build_temp)
664 664 if self.long_paths_support:
665 665 self.addlongpathsmanifest()
666 666
667 667 def addlongpathsmanifest(self):
668 668 r"""Add manifest pieces so that hg.exe understands long paths
669 669
670 670 This is an EXPERIMENTAL feature, use with care.
671 671 To enable long paths support, one needs to do two things:
672 672 - build Mercurial with --long-paths-support option
673 673 - change HKLM\SYSTEM\CurrentControlSet\Control\FileSystem\
674 674 LongPathsEnabled to have value 1.
675 675
676 676 Please ignore 'warning 81010002: Unrecognized Element "longPathAware"';
677 677 it happens because Mercurial uses mt.exe circa 2008, which is not
678 678 yet aware of long paths support in the manifest (I think so at least).
679 679 This does not stop mt.exe from embedding/merging the XML properly.
680 680
681 681 Why resource #1 should be used for .exe manifests? I don't know and
682 682 wasn't able to find an explanation for mortals. But it seems to work.
683 683 """
684 684 exefname = self.compiler.executable_filename(self.hgtarget)
685 685 fdauto, manfname = tempfile.mkstemp(suffix='.hg.exe.manifest')
686 686 os.close(fdauto)
687 687 with open(manfname, 'w') as f:
688 688 f.write(self.LONG_PATHS_MANIFEST)
689 689 log.info("long paths manifest is written to '%s'" % manfname)
690 690 inputresource = '-inputresource:%s;#1' % exefname
691 691 outputresource = '-outputresource:%s;#1' % exefname
692 692 log.info("running mt.exe to update hg.exe's manifest in-place")
693 693 # supplying both -manifest and -inputresource to mt.exe makes
694 694 # it merge the embedded and supplied manifests in the -outputresource
695 695 self.spawn(['mt.exe', '-nologo', '-manifest', manfname,
696 696 inputresource, outputresource])
697 697 log.info("done updating hg.exe's manifest")
698 698 os.remove(manfname)
699 699
700 700 @property
701 701 def hgexepath(self):
702 702 dir = os.path.dirname(self.get_ext_fullpath('dummy'))
703 703 return os.path.join(self.build_temp, dir, 'hg.exe')
704 704
705 705 class hgbuilddoc(Command):
706 706 description = 'build documentation'
707 707 user_options = [
708 708 ('man', None, 'generate man pages'),
709 709 ('html', None, 'generate html pages'),
710 710 ]
711 711
712 712 def initialize_options(self):
713 713 self.man = None
714 714 self.html = None
715 715
716 716 def finalize_options(self):
717 717 # If --man or --html are set, only generate what we're told to.
718 718 # Otherwise generate everything.
719 719 have_subset = self.man is not None or self.html is not None
720 720
721 721 if have_subset:
722 722 self.man = True if self.man else False
723 723 self.html = True if self.html else False
724 724 else:
725 725 self.man = True
726 726 self.html = True
727 727
728 728 def run(self):
729 729 def normalizecrlf(p):
730 730 with open(p, 'rb') as fh:
731 731 orig = fh.read()
732 732
733 733 if b'\r\n' not in orig:
734 734 return
735 735
736 736 log.info('normalizing %s to LF line endings' % p)
737 737 with open(p, 'wb') as fh:
738 738 fh.write(orig.replace(b'\r\n', b'\n'))
739 739
740 740 def gentxt(root):
741 741 txt = 'doc/%s.txt' % root
742 742 log.info('generating %s' % txt)
743 743 res, out, err = runcmd(
744 744 [sys.executable, 'gendoc.py', root],
745 745 os.environ,
746 746 cwd='doc')
747 747 if res:
748 748 raise SystemExit('error running gendoc.py: %s' %
749 749 '\n'.join([out, err]))
750 750
751 751 with open(txt, 'wb') as fh:
752 752 fh.write(out)
753 753
754 754 def gengendoc(root):
755 755 gendoc = 'doc/%s.gendoc.txt' % root
756 756
757 757 log.info('generating %s' % gendoc)
758 758 res, out, err = runcmd(
759 759 [sys.executable, 'gendoc.py', '%s.gendoc' % root],
760 760 os.environ,
761 761 cwd='doc')
762 762 if res:
763 763 raise SystemExit('error running gendoc: %s' %
764 764 '\n'.join([out, err]))
765 765
766 766 with open(gendoc, 'wb') as fh:
767 767 fh.write(out)
768 768
769 769 def genman(root):
770 770 log.info('generating doc/%s' % root)
771 771 res, out, err = runcmd(
772 772 [sys.executable, 'runrst', 'hgmanpage', '--halt', 'warning',
773 773 '--strip-elements-with-class', 'htmlonly',
774 774 '%s.txt' % root, root],
775 775 os.environ,
776 776 cwd='doc')
777 777 if res:
778 778 raise SystemExit('error running runrst: %s' %
779 779 '\n'.join([out, err]))
780 780
781 781 normalizecrlf('doc/%s' % root)
782 782
783 783 def genhtml(root):
784 784 log.info('generating doc/%s.html' % root)
785 785 res, out, err = runcmd(
786 786 [sys.executable, 'runrst', 'html', '--halt', 'warning',
787 787 '--link-stylesheet', '--stylesheet-path', 'style.css',
788 788 '%s.txt' % root, '%s.html' % root],
789 789 os.environ,
790 790 cwd='doc')
791 791 if res:
792 792 raise SystemExit('error running runrst: %s' %
793 793 '\n'.join([out, err]))
794 794
795 795 normalizecrlf('doc/%s.html' % root)
796 796
797 797 # This logic is duplicated in doc/Makefile.
798 sources = {f for f in os.listdir('mercurial/help')
799 if re.search(r'[0-9]\.txt$', f)}
798 sources = set(f for f in os.listdir('mercurial/help')
799 if re.search(r'[0-9]\.txt$', f))
800 800
801 801 # common.txt is a one-off.
802 802 gentxt('common')
803 803
804 804 for source in sorted(sources):
805 805 assert source[-4:] == '.txt'
806 806 root = source[:-4]
807 807
808 808 gentxt(root)
809 809 gengendoc(root)
810 810
811 811 if self.man:
812 812 genman(root)
813 813 if self.html:
814 814 genhtml(root)
815 815
816 816 class hginstall(install):
817 817
818 818 user_options = install.user_options + [
819 819 ('old-and-unmanageable', None,
820 820 'noop, present for eggless setuptools compat'),
821 821 ('single-version-externally-managed', None,
822 822 'noop, present for eggless setuptools compat'),
823 823 ]
824 824
825 825 # Also helps setuptools not be sad while we refuse to create eggs.
826 826 single_version_externally_managed = True
827 827
828 828 def get_sub_commands(self):
829 829 # Screen out egg related commands to prevent egg generation. But allow
830 830 # mercurial.egg-info generation, since that is part of modern
831 831 # packaging.
832 832 excl = set(['bdist_egg'])
833 833 return filter(lambda x: x not in excl, install.get_sub_commands(self))
834 834
835 835 class hginstalllib(install_lib):
836 836 '''
837 837 This is a specialization of install_lib that replaces the copy_file used
838 838 there so that it supports setting the mode of files after copying them,
839 839 instead of just preserving the mode that the files originally had. If your
840 840 system has a umask of something like 027, preserving the permissions when
841 841 copying will lead to a broken install.
842 842
843 843 Note that just passing keep_permissions=False to copy_file would be
844 844 insufficient, as it might still be applying a umask.
845 845 '''
846 846
847 847 def run(self):
848 848 realcopyfile = file_util.copy_file
849 849 def copyfileandsetmode(*args, **kwargs):
850 850 src, dst = args[0], args[1]
851 851 dst, copied = realcopyfile(*args, **kwargs)
852 852 if copied:
853 853 st = os.stat(src)
854 854 # Persist executable bit (apply it to group and other if user
855 855 # has it)
856 856 if st[stat.ST_MODE] & stat.S_IXUSR:
857 857 setmode = int('0755', 8)
858 858 else:
859 859 setmode = int('0644', 8)
860 860 m = stat.S_IMODE(st[stat.ST_MODE])
861 861 m = (m & ~int('0777', 8)) | setmode
862 862 os.chmod(dst, m)
863 863 file_util.copy_file = copyfileandsetmode
864 864 try:
865 865 install_lib.run(self)
866 866 finally:
867 867 file_util.copy_file = realcopyfile
868 868
869 869 class hginstallscripts(install_scripts):
870 870 '''
871 871 This is a specialization of install_scripts that replaces the @LIBDIR@ with
872 872 the configured directory for modules. If possible, the path is made relative
873 873 to the directory for scripts.
874 874 '''
875 875
876 876 def initialize_options(self):
877 877 install_scripts.initialize_options(self)
878 878
879 879 self.install_lib = None
880 880
881 881 def finalize_options(self):
882 882 install_scripts.finalize_options(self)
883 883 self.set_undefined_options('install',
884 884 ('install_lib', 'install_lib'))
885 885
886 886 def run(self):
887 887 install_scripts.run(self)
888 888
889 889 # It only makes sense to replace @LIBDIR@ with the install path if
890 890 # the install path is known. For wheels, the logic below calculates
891 891 # the libdir to be "../..". This is because the internal layout of a
892 892 # wheel archive looks like:
893 893 #
894 894 # mercurial-3.6.1.data/scripts/hg
895 895 # mercurial/__init__.py
896 896 #
897 897 # When installing wheels, the subdirectories of the "<pkg>.data"
898 898 # directory are translated to system local paths and files therein
899 899 # are copied in place. The mercurial/* files are installed into the
900 900 # site-packages directory. However, the site-packages directory
901 901 # isn't known until wheel install time. This means we have no clue
902 902 # at wheel generation time what the installed site-packages directory
903 903 # will be. And, wheels don't appear to provide the ability to register
904 904 # custom code to run during wheel installation. This all means that
905 905 # we can't reliably set the libdir in wheels: the default behavior
906 906 # of looking in sys.path must do.
907 907
908 908 if (os.path.splitdrive(self.install_dir)[0] !=
909 909 os.path.splitdrive(self.install_lib)[0]):
910 910 # can't make relative paths from one drive to another, so use an
911 911 # absolute path instead
912 912 libdir = self.install_lib
913 913 else:
914 914 common = os.path.commonprefix((self.install_dir, self.install_lib))
915 915 rest = self.install_dir[len(common):]
916 916 uplevel = len([n for n in os.path.split(rest) if n])
917 917
918 918 libdir = uplevel * ('..' + os.sep) + self.install_lib[len(common):]
919 919
920 920 for outfile in self.outfiles:
921 921 with open(outfile, 'rb') as fp:
922 922 data = fp.read()
923 923
924 924 # skip binary files
925 925 if b'\0' in data:
926 926 continue
927 927
928 928 # During local installs, the shebang will be rewritten to the final
929 929 # install path. During wheel packaging, the shebang has a special
930 930 # value.
931 931 if data.startswith(b'#!python'):
932 932 log.info('not rewriting @LIBDIR@ in %s because install path '
933 933 'not known' % outfile)
934 934 continue
935 935
936 936 data = data.replace(b'@LIBDIR@', libdir.encode(libdir_escape))
937 937 with open(outfile, 'wb') as fp:
938 938 fp.write(data)
939 939
940 940 # virtualenv installs custom distutils/__init__.py and
941 941 # distutils/distutils.cfg files which essentially proxy back to the
942 942 # "real" distutils in the main Python install. The presence of this
943 943 # directory causes py2exe to pick up the "hacked" distutils package
944 944 # from the virtualenv and "import distutils" will fail from the py2exe
945 945 # build because the "real" distutils files can't be located.
946 946 #
947 947 # We work around this by monkeypatching the py2exe code finding Python
948 948 # modules to replace the found virtualenv distutils modules with the
949 949 # original versions via filesystem scanning. This is a bit hacky. But
950 950 # it allows us to use virtualenvs for py2exe packaging, which is more
951 951 # deterministic and reproducible.
952 952 #
953 953 # It's worth noting that the common StackOverflow suggestions for this
954 954 # problem involve copying the original distutils files into the
955 955 # virtualenv or into the staging directory after setup() is invoked.
956 956 # The former is very brittle and can easily break setup(). Our hacking
957 957 # of the found modules routine has a similar result as copying the files
958 958 # manually. But it makes fewer assumptions about how py2exe works and
959 959 # is less brittle.
960 960
961 961 # This only catches virtualenvs made with virtualenv (as opposed to
962 962 # venv, which is likely what Python 3 uses).
963 963 py2exehacked = py2exeloaded and getattr(sys, 'real_prefix', None) is not None
964 964
965 965 if py2exehacked:
966 966 from distutils.command.py2exe import py2exe as buildpy2exe
967 967 from py2exe.mf import Module as py2exemodule
968 968
969 969 class hgbuildpy2exe(buildpy2exe):
970 970 def find_needed_modules(self, mf, files, modules):
971 971 res = buildpy2exe.find_needed_modules(self, mf, files, modules)
972 972
973 973 # Replace virtualenv's distutils modules with the real ones.
974 res.modules = {
975 k: v for k, v in res.modules.items()
976 if k != 'distutils' and not k.startswith('distutils.')}
974 modules = {}
975 for k, v in res.modules.items():
976 if k != 'distutils' and not k.startswith('distutils.'):
977 modules[k] = v
978
979 res.modules = modules
977 980
978 981 import opcode
979 982 distutilsreal = os.path.join(os.path.dirname(opcode.__file__),
980 983 'distutils')
981 984
982 985 for root, dirs, files in os.walk(distutilsreal):
983 986 for f in sorted(files):
984 987 if not f.endswith('.py'):
985 988 continue
986 989
987 990 full = os.path.join(root, f)
988 991
989 992 parents = ['distutils']
990 993
991 994 if root != distutilsreal:
992 995 rel = os.path.relpath(root, distutilsreal)
993 996 parents.extend(p for p in rel.split(os.sep))
994 997
995 998 modname = '%s.%s' % ('.'.join(parents), f[:-3])
996 999
997 1000 if modname.startswith('distutils.tests.'):
998 1001 continue
999 1002
1000 1003 if modname.endswith('.__init__'):
1001 1004 modname = modname[:-len('.__init__')]
1002 1005 path = os.path.dirname(full)
1003 1006 else:
1004 1007 path = None
1005 1008
1006 1009 res.modules[modname] = py2exemodule(modname, full,
1007 1010 path=path)
1008 1011
1009 1012 if 'distutils' not in res.modules:
1010 1013 raise SystemExit('could not find distutils modules')
1011 1014
1012 1015 return res
1013 1016
1014 1017 cmdclass = {'build': hgbuild,
1015 1018 'build_doc': hgbuilddoc,
1016 1019 'build_mo': hgbuildmo,
1017 1020 'build_ext': hgbuildext,
1018 1021 'build_py': hgbuildpy,
1019 1022 'build_scripts': hgbuildscripts,
1020 1023 'build_hgextindex': buildhgextindex,
1021 1024 'install': hginstall,
1022 1025 'install_lib': hginstalllib,
1023 1026 'install_scripts': hginstallscripts,
1024 1027 'build_hgexe': buildhgexe,
1025 1028 }
1026 1029
1027 1030 if py2exehacked:
1028 1031 cmdclass['py2exe'] = hgbuildpy2exe
1029 1032
1030 1033 packages = ['mercurial',
1031 1034 'mercurial.cext',
1032 1035 'mercurial.cffi',
1033 1036 'mercurial.hgweb',
1034 1037 'mercurial.pure',
1035 1038 'mercurial.thirdparty',
1036 1039 'mercurial.thirdparty.attr',
1037 1040 'mercurial.thirdparty.zope',
1038 1041 'mercurial.thirdparty.zope.interface',
1039 1042 'mercurial.utils',
1040 1043 'mercurial.revlogutils',
1041 1044 'mercurial.testing',
1042 1045 'hgext', 'hgext.convert', 'hgext.fsmonitor',
1043 1046 'hgext.fastannotate',
1044 1047 'hgext.fsmonitor.pywatchman',
1045 1048 'hgext.infinitepush',
1046 1049 'hgext.highlight',
1047 1050 'hgext.largefiles', 'hgext.lfs', 'hgext.narrow',
1048 1051 'hgext.remotefilelog',
1049 1052 'hgext.zeroconf', 'hgext3rd',
1050 1053 'hgdemandimport']
1051 1054 if sys.version_info[0] == 2:
1052 1055 packages.extend(['mercurial.thirdparty.concurrent',
1053 1056 'mercurial.thirdparty.concurrent.futures'])
1054 1057
1055 1058 if 'HG_PY2EXE_EXTRA_INSTALL_PACKAGES' in os.environ:
1056 1059 # py2exe can't cope with namespace packages very well, so we have to
1057 1060 # install any hgext3rd.* extensions that we want in the final py2exe
1058 1061 # image here. This is gross, but you gotta do what you gotta do.
1059 1062 packages.extend(os.environ['HG_PY2EXE_EXTRA_INSTALL_PACKAGES'].split(' '))
1060 1063
1061 1064 common_depends = ['mercurial/bitmanipulation.h',
1062 1065 'mercurial/compat.h',
1063 1066 'mercurial/cext/util.h']
1064 1067 common_include_dirs = ['mercurial']
1065 1068
1066 1069 osutil_cflags = []
1067 1070 osutil_ldflags = []
1068 1071
1069 1072 # platform specific macros
1070 1073 for plat, func in [('bsd', 'setproctitle')]:
1071 1074 if re.search(plat, sys.platform) and hasfunction(new_compiler(), func):
1072 1075 osutil_cflags.append('-DHAVE_%s' % func.upper())
1073 1076
1074 1077 for plat, macro, code in [
1075 1078 ('bsd|darwin', 'BSD_STATFS', '''
1076 1079 #include <sys/param.h>
1077 1080 #include <sys/mount.h>
1078 1081 int main() { struct statfs s; return sizeof(s.f_fstypename); }
1079 1082 '''),
1080 1083 ('linux', 'LINUX_STATFS', '''
1081 1084 #include <linux/magic.h>
1082 1085 #include <sys/vfs.h>
1083 1086 int main() { struct statfs s; return sizeof(s.f_type); }
1084 1087 '''),
1085 1088 ]:
1086 1089 if re.search(plat, sys.platform) and cancompile(new_compiler(), code):
1087 1090 osutil_cflags.append('-DHAVE_%s' % macro)
1088 1091
1089 1092 if sys.platform == 'darwin':
1090 1093 osutil_ldflags += ['-framework', 'ApplicationServices']
1091 1094
1092 1095 xdiff_srcs = [
1093 1096 'mercurial/thirdparty/xdiff/xdiffi.c',
1094 1097 'mercurial/thirdparty/xdiff/xprepare.c',
1095 1098 'mercurial/thirdparty/xdiff/xutils.c',
1096 1099 ]
1097 1100
1098 1101 xdiff_headers = [
1099 1102 'mercurial/thirdparty/xdiff/xdiff.h',
1100 1103 'mercurial/thirdparty/xdiff/xdiffi.h',
1101 1104 'mercurial/thirdparty/xdiff/xinclude.h',
1102 1105 'mercurial/thirdparty/xdiff/xmacros.h',
1103 1106 'mercurial/thirdparty/xdiff/xprepare.h',
1104 1107 'mercurial/thirdparty/xdiff/xtypes.h',
1105 1108 'mercurial/thirdparty/xdiff/xutils.h',
1106 1109 ]
1107 1110
1108 1111 class RustCompilationError(CCompilerError):
1109 1112 """Exception class for Rust compilation errors."""
1110 1113
1111 1114 class RustExtension(Extension):
1112 1115 """Base classes for concrete Rust Extension classes.
1113 1116 """
1114 1117
1115 1118 rusttargetdir = os.path.join('rust', 'target', 'release')
1116 1119
1117 1120 def __init__(self, mpath, sources, rustlibname, subcrate,
1118 1121 py3_features=None, **kw):
1119 1122 Extension.__init__(self, mpath, sources, **kw)
1120 1123 if hgrustext is None:
1121 1124 return
1122 1125 srcdir = self.rustsrcdir = os.path.join('rust', subcrate)
1123 1126 self.py3_features = py3_features
1124 1127
1125 1128 # adding Rust source and control files to depends so that the extension
1126 1129 # gets rebuilt if they've changed
1127 1130 self.depends.append(os.path.join(srcdir, 'Cargo.toml'))
1128 1131 cargo_lock = os.path.join(srcdir, 'Cargo.lock')
1129 1132 if os.path.exists(cargo_lock):
1130 1133 self.depends.append(cargo_lock)
1131 1134 for dirpath, subdir, fnames in os.walk(os.path.join(srcdir, 'src')):
1132 1135 self.depends.extend(os.path.join(dirpath, fname)
1133 1136 for fname in fnames
1134 1137 if os.path.splitext(fname)[1] == '.rs')
1135 1138
1136 1139 def rustbuild(self):
1137 1140 if hgrustext is None:
1138 1141 return
1139 1142 env = os.environ.copy()
1140 1143 if 'HGTEST_RESTOREENV' in env:
1141 1144 # Mercurial tests change HOME to a temporary directory,
1142 1145 # but, if installed with rustup, the Rust toolchain needs
1143 1146 # HOME to be correct (otherwise the 'no default toolchain'
1144 1147 # error message is issued and the build fails).
1145 1148 # This happens currently with test-hghave.t, which does
1146 1149 # invoke this build.
1147 1150
1148 1151 # Unix only fix (os.path.expanduser not really reliable if
1149 1152 # HOME is shadowed like this)
1150 1153 import pwd
1151 1154 env['HOME'] = pwd.getpwuid(os.getuid()).pw_dir
1152 1155
1153 1156 cargocmd = ['cargo', 'build', '-vv', '--release']
1154 1157 if sys.version_info[0] == 3 and self.py3_features is not None:
1155 1158 cargocmd.extend(('--features', self.py3_features,
1156 1159 '--no-default-features'))
1157 1160 try:
1158 1161 subprocess.check_call(cargocmd, env=env, cwd=self.rustsrcdir)
1159 1162 except OSError as exc:
1160 1163 if exc.errno == errno.ENOENT:
1161 1164 raise RustCompilationError("Cargo not found")
1162 1165 elif exc.errno == errno.EACCES:
1163 1166 raise RustCompilationError(
1164 1167 "Cargo found, but permisssion to execute it is denied")
1165 1168 else:
1166 1169 raise
1167 1170 except subprocess.CalledProcessError:
1168 1171 raise RustCompilationError(
1169 1172 "Cargo failed. Working directory: %r, "
1170 1173 "command: %r, environment: %r"
1171 1174 % (self.rustsrcdir, cargocmd, env))
1172 1175
1173 1176 class RustEnhancedExtension(RustExtension):
1174 1177 """A C Extension, conditionally enhanced with Rust code.
1175 1178
1176 1179 If the HGRUSTEXT environment variable is set to something else
1177 1180 than 'cpython', the Rust sources get compiled and linked within the
1178 1181 C target shared library object.
1179 1182 """
1180 1183
1181 1184 def __init__(self, mpath, sources, rustlibname, subcrate, **kw):
1182 1185 RustExtension.__init__(self, mpath, sources, rustlibname, subcrate,
1183 1186 **kw)
1184 1187 if hgrustext != 'direct-ffi':
1185 1188 return
1186 1189 self.extra_compile_args.append('-DWITH_RUST')
1187 1190 self.libraries.append(rustlibname)
1188 1191 self.library_dirs.append(self.rusttargetdir)
1189 1192
1190 1193 class RustStandaloneExtension(RustExtension):
1191 1194
1192 1195 def __init__(self, pydottedname, rustcrate, dylibname, **kw):
1193 1196 RustExtension.__init__(self, pydottedname, [], dylibname, rustcrate,
1194 1197 **kw)
1195 1198 self.dylibname = dylibname
1196 1199
1197 1200 def build(self, target_dir):
1198 1201 self.rustbuild()
1199 1202 target = [target_dir]
1200 1203 target.extend(self.name.split('.'))
1201 1204 ext = '.so' # TODO Unix only
1202 1205 target[-1] += ext
1203 1206 shutil.copy2(os.path.join(self.rusttargetdir, self.dylibname + ext),
1204 1207 os.path.join(*target))
1205 1208
1206 1209
1207 1210 extmodules = [
1208 1211 Extension('mercurial.cext.base85', ['mercurial/cext/base85.c'],
1209 1212 include_dirs=common_include_dirs,
1210 1213 depends=common_depends),
1211 1214 Extension('mercurial.cext.bdiff', ['mercurial/bdiff.c',
1212 1215 'mercurial/cext/bdiff.c'] + xdiff_srcs,
1213 1216 include_dirs=common_include_dirs,
1214 1217 depends=common_depends + ['mercurial/bdiff.h'] + xdiff_headers),
1215 1218 Extension('mercurial.cext.mpatch', ['mercurial/mpatch.c',
1216 1219 'mercurial/cext/mpatch.c'],
1217 1220 include_dirs=common_include_dirs,
1218 1221 depends=common_depends),
1219 1222 RustEnhancedExtension(
1220 1223 'mercurial.cext.parsers', ['mercurial/cext/charencode.c',
1221 1224 'mercurial/cext/dirs.c',
1222 1225 'mercurial/cext/manifest.c',
1223 1226 'mercurial/cext/parsers.c',
1224 1227 'mercurial/cext/pathencode.c',
1225 1228 'mercurial/cext/revlog.c'],
1226 1229 'hgdirectffi',
1227 1230 'hg-direct-ffi',
1228 1231 include_dirs=common_include_dirs,
1229 1232 depends=common_depends + ['mercurial/cext/charencode.h',
1230 1233 'mercurial/cext/revlog.h',
1231 1234 'rust/hg-core/src/ancestors.rs',
1232 1235 'rust/hg-core/src/lib.rs']),
1233 1236 Extension('mercurial.cext.osutil', ['mercurial/cext/osutil.c'],
1234 1237 include_dirs=common_include_dirs,
1235 1238 extra_compile_args=osutil_cflags,
1236 1239 extra_link_args=osutil_ldflags,
1237 1240 depends=common_depends),
1238 1241 Extension(
1239 1242 'mercurial.thirdparty.zope.interface._zope_interface_coptimizations', [
1240 1243 'mercurial/thirdparty/zope/interface/_zope_interface_coptimizations.c',
1241 1244 ]),
1242 1245 Extension('hgext.fsmonitor.pywatchman.bser',
1243 1246 ['hgext/fsmonitor/pywatchman/bser.c']),
1244 1247 ]
1245 1248
1246 1249 if hgrustext == 'cpython':
1247 1250 extmodules.append(
1248 1251 RustStandaloneExtension('mercurial.rustext', 'hg-cpython', 'librusthg',
1249 1252 py3_features='python3')
1250 1253 )
1251 1254
1252 1255
1253 1256 sys.path.insert(0, 'contrib/python-zstandard')
1254 1257 import setup_zstd
1255 1258 extmodules.append(setup_zstd.get_c_extension(
1256 1259 name='mercurial.zstd',
1257 1260 root=os.path.abspath(os.path.dirname(__file__))))
1258 1261
1259 1262 try:
1260 1263 from distutils import cygwinccompiler
1261 1264
1262 1265 # the -mno-cygwin option has been deprecated for years
1263 1266 mingw32compilerclass = cygwinccompiler.Mingw32CCompiler
1264 1267
1265 1268 class HackedMingw32CCompiler(cygwinccompiler.Mingw32CCompiler):
1266 1269 def __init__(self, *args, **kwargs):
1267 1270 mingw32compilerclass.__init__(self, *args, **kwargs)
1268 1271 for i in 'compiler compiler_so linker_exe linker_so'.split():
1269 1272 try:
1270 1273 getattr(self, i).remove('-mno-cygwin')
1271 1274 except ValueError:
1272 1275 pass
1273 1276
1274 1277 cygwinccompiler.Mingw32CCompiler = HackedMingw32CCompiler
1275 1278 except ImportError:
1276 1279 # the cygwinccompiler package is not available on some Python
1277 1280 # distributions like the ones from the optware project for Synology
1278 1281 # DiskStation boxes
1279 1282 class HackedMingw32CCompiler(object):
1280 1283 pass
1281 1284
1282 1285 if os.name == 'nt':
1283 1286 # Allow compiler/linker flags to be added to Visual Studio builds. Passing
1284 1287 # extra_link_args to distutils.extensions.Extension() doesn't have any
1285 1288 # effect.
1286 1289 from distutils import msvccompiler
1287 1290
1288 1291 msvccompilerclass = msvccompiler.MSVCCompiler
1289 1292
1290 1293 class HackedMSVCCompiler(msvccompiler.MSVCCompiler):
1291 1294 def initialize(self):
1292 1295 msvccompilerclass.initialize(self)
1293 1296 # "warning LNK4197: export 'func' specified multiple times"
1294 1297 self.ldflags_shared.append('/ignore:4197')
1295 1298 self.ldflags_shared_debug.append('/ignore:4197')
1296 1299
1297 1300 msvccompiler.MSVCCompiler = HackedMSVCCompiler
1298 1301
1299 1302 packagedata = {'mercurial': ['locale/*/LC_MESSAGES/hg.mo',
1300 1303 'help/*.txt',
1301 1304 'help/internals/*.txt',
1302 1305 'default.d/*.rc',
1303 1306 'dummycert.pem']}
1304 1307
1305 1308 def ordinarypath(p):
1306 1309 return p and p[0] != '.' and p[-1] != '~'
1307 1310
1308 1311 for root in ('templates',):
1309 1312 for curdir, dirs, files in os.walk(os.path.join('mercurial', root)):
1310 1313 curdir = curdir.split(os.sep, 1)[1]
1311 1314 dirs[:] = filter(ordinarypath, dirs)
1312 1315 for f in filter(ordinarypath, files):
1313 1316 f = os.path.join(curdir, f)
1314 1317 packagedata['mercurial'].append(f)
1315 1318
1316 1319 datafiles = []
1317 1320
1318 1321 # distutils expects version to be str/unicode. Converting it to
1319 1322 # unicode on Python 2 still works because it won't contain any
1320 1323 # non-ascii bytes and will be implicitly converted back to bytes
1321 1324 # when operated on.
1322 1325 assert isinstance(version, bytes)
1323 1326 setupversion = version.decode('ascii')
1324 1327
1325 1328 extra = {}
1326 1329
1327 1330 py2exepackages = [
1328 1331 'hgdemandimport',
1329 1332 'hgext3rd',
1330 1333 'hgext',
1331 1334 'email',
1332 1335 # implicitly imported per module policy
1333 1336 # (cffi wouldn't be used as a frozen exe)
1334 1337 'mercurial.cext',
1335 1338 #'mercurial.cffi',
1336 1339 'mercurial.pure',
1337 1340 ]
1338 1341
1339 1342 py2exeexcludes = []
1340 1343 py2exedllexcludes = ['crypt32.dll']
1341 1344
1342 1345 if issetuptools:
1343 1346 extra['python_requires'] = supportedpy
1344 1347
1345 1348 if py2exeloaded:
1346 1349 extra['console'] = [
1347 1350 {'script':'hg',
1348 1351 'copyright':'Copyright (C) 2005-2019 Matt Mackall and others',
1349 1352 'product_version':version}]
1350 1353 # Sub command of 'build' because 'py2exe' does not handle sub_commands.
1351 1354 # Need to override hgbuild because it has a private copy of
1352 1355 # build.sub_commands.
1353 1356 hgbuild.sub_commands.insert(0, ('build_hgextindex', None))
1354 1357 # put dlls in sub directory so that they won't pollute PATH
1355 1358 extra['zipfile'] = 'lib/library.zip'
1356 1359
1357 1360 # We allow some configuration to be supplemented via environment
1358 1361 # variables. This is better than setup.cfg files because it allows
1359 1362 # supplementing configs instead of replacing them.
1360 1363 extrapackages = os.environ.get('HG_PY2EXE_EXTRA_PACKAGES')
1361 1364 if extrapackages:
1362 1365 py2exepackages.extend(extrapackages.split(' '))
1363 1366
1364 1367 excludes = os.environ.get('HG_PY2EXE_EXTRA_EXCLUDES')
1365 1368 if excludes:
1366 1369 py2exeexcludes.extend(excludes.split(' '))
1367 1370
1368 1371 dllexcludes = os.environ.get('HG_PY2EXE_EXTRA_DLL_EXCLUDES')
1369 1372 if dllexcludes:
1370 1373 py2exedllexcludes.extend(dllexcludes.split(' '))
1371 1374
1372 1375 if os.name == 'nt':
1373 1376 # Windows binary file versions for exe/dll files must have the
1374 1377 # form W.X.Y.Z, where W,X,Y,Z are numbers in the range 0..65535
1375 1378 setupversion = setupversion.split(r'+', 1)[0]
1376 1379
1377 1380 if sys.platform == 'darwin' and os.path.exists('/usr/bin/xcodebuild'):
1378 1381 version = runcmd(['/usr/bin/xcodebuild', '-version'], {})[1].splitlines()
1379 1382 if version:
1380 1383 version = version[0]
1381 1384 if sys.version_info[0] == 3:
1382 1385 version = version.decode('utf-8')
1383 1386 xcode4 = (version.startswith('Xcode') and
1384 1387 StrictVersion(version.split()[1]) >= StrictVersion('4.0'))
1385 1388 xcode51 = re.match(r'^Xcode\s+5\.1', version) is not None
1386 1389 else:
1387 1390 # xcodebuild returns empty on OS X Lion with XCode 4.3 not
1388 1391 # installed, but instead with only command-line tools. Assume
1389 1392 # that only happens on >= Lion, thus no PPC support.
1390 1393 xcode4 = True
1391 1394 xcode51 = False
1392 1395
1393 1396 # XCode 4.0 dropped support for ppc architecture, which is hardcoded in
1394 1397 # distutils.sysconfig
1395 1398 if xcode4:
1396 1399 os.environ['ARCHFLAGS'] = ''
1397 1400
1398 1401 # XCode 5.1 changes clang such that it now fails to compile if the
1399 1402 # -mno-fused-madd flag is passed, but the version of Python shipped with
1400 1403 # OS X 10.9 Mavericks includes this flag. This causes problems in all
1401 1404 # C extension modules, and a bug has been filed upstream at
1402 1405 # http://bugs.python.org/issue21244. We also need to patch this here
1403 1406 # so Mercurial can continue to compile in the meantime.
1404 1407 if xcode51:
1405 1408 cflags = get_config_var('CFLAGS')
1406 1409 if cflags and re.search(r'-mno-fused-madd\b', cflags) is not None:
1407 1410 os.environ['CFLAGS'] = (
1408 1411 os.environ.get('CFLAGS', '') + ' -Qunused-arguments')
1409 1412
1410 1413 setup(name='mercurial',
1411 1414 version=setupversion,
1412 1415 author='Matt Mackall and many others',
1413 1416 author_email='mercurial@mercurial-scm.org',
1414 1417 url='https://mercurial-scm.org/',
1415 1418 download_url='https://mercurial-scm.org/release/',
1416 1419 description=('Fast scalable distributed SCM (revision control, version '
1417 1420 'control) system'),
1418 1421 long_description=('Mercurial is a distributed SCM tool written in Python.'
1419 1422 ' It is used by a number of large projects that require'
1420 1423 ' fast, reliable distributed revision control, such as '
1421 1424 'Mozilla.'),
1422 1425 license='GNU GPLv2 or any later version',
1423 1426 classifiers=[
1424 1427 'Development Status :: 6 - Mature',
1425 1428 'Environment :: Console',
1426 1429 'Intended Audience :: Developers',
1427 1430 'Intended Audience :: System Administrators',
1428 1431 'License :: OSI Approved :: GNU General Public License (GPL)',
1429 1432 'Natural Language :: Danish',
1430 1433 'Natural Language :: English',
1431 1434 'Natural Language :: German',
1432 1435 'Natural Language :: Italian',
1433 1436 'Natural Language :: Japanese',
1434 1437 'Natural Language :: Portuguese (Brazilian)',
1435 1438 'Operating System :: Microsoft :: Windows',
1436 1439 'Operating System :: OS Independent',
1437 1440 'Operating System :: POSIX',
1438 1441 'Programming Language :: C',
1439 1442 'Programming Language :: Python',
1440 1443 'Topic :: Software Development :: Version Control',
1441 1444 ],
1442 1445 scripts=scripts,
1443 1446 packages=packages,
1444 1447 ext_modules=extmodules,
1445 1448 data_files=datafiles,
1446 1449 package_data=packagedata,
1447 1450 cmdclass=cmdclass,
1448 1451 distclass=hgdist,
1449 1452 options={
1450 1453 'py2exe': {
1451 1454 'bundle_files': 3,
1452 1455 'dll_excludes': py2exedllexcludes,
1453 1456 'excludes': py2exeexcludes,
1454 1457 'packages': py2exepackages,
1455 1458 },
1456 1459 'bdist_mpkg': {
1457 1460 'zipdist': False,
1458 1461 'license': 'COPYING',
1459 1462 'readme': 'contrib/packaging/macosx/Readme.html',
1460 1463 'welcome': 'contrib/packaging/macosx/Welcome.html',
1461 1464 },
1462 1465 },
1463 1466 **extra)
General Comments 0
You need to be logged in to leave comments. Login now