comparison setup.py @ 22640:e88a634e0195

setup: set mode 644 or 755 on installed files
author Kyle Lippincott <spectral@google.com>
date Tue, 30 Sep 2014 17:13:54 -0700
parents d7f7f1860f00
children c4ce077588d0
comparison
equal deleted inserted replaced
22639:79c4178b2169 22640:e88a634e0195
61 bz2.BZ2Compressor # silence unused import warning 61 bz2.BZ2Compressor # silence unused import warning
62 except ImportError: 62 except ImportError:
63 raise SystemExit( 63 raise SystemExit(
64 "Couldn't import standard bz2 (incomplete Python install).") 64 "Couldn't import standard bz2 (incomplete Python install).")
65 65
66 import os, subprocess, time 66 import os, stat, subprocess, time
67 import re 67 import re
68 import shutil 68 import shutil
69 import tempfile 69 import tempfile
70 from distutils import log 70 from distutils import log
71 from distutils.core import setup, Command, Extension 71 from distutils.core import setup, Command, Extension
72 from distutils.dist import Distribution 72 from distutils.dist import Distribution
73 from distutils.command.build import build 73 from distutils.command.build import build
74 from distutils.command.build_ext import build_ext 74 from distutils.command.build_ext import build_ext
75 from distutils.command.build_py import build_py 75 from distutils.command.build_py import build_py
76 from distutils.command.install_lib import install_lib
76 from distutils.command.install_scripts import install_scripts 77 from distutils.command.install_scripts import install_scripts
77 from distutils.spawn import spawn, find_executable 78 from distutils.spawn import spawn, find_executable
78 from distutils import cygwinccompiler 79 from distutils import cygwinccompiler, file_util
79 from distutils.errors import CCompilerError, DistutilsExecError 80 from distutils.errors import CCompilerError, DistutilsExecError
80 from distutils.sysconfig import get_python_inc, get_config_var 81 from distutils.sysconfig import get_python_inc, get_config_var
81 from distutils.version import StrictVersion 82 from distutils.version import StrictVersion
82 83
83 convert2to3 = '--c2to3' in sys.argv 84 convert2to3 = '--c2to3' in sys.argv
373 target = os.path.join(dir, 'hg') 374 target = os.path.join(dir, 'hg')
374 self.compiler.link_executable(objects, target, 375 self.compiler.link_executable(objects, target,
375 libraries=[], 376 libraries=[],
376 output_dir=self.build_temp) 377 output_dir=self.build_temp)
377 378
379 class hginstalllib(install_lib):
380 '''
381 This is a specialization of install_lib that replaces the copy_file used
382 there so that it supports setting the mode of files after copying them,
383 instead of just preserving the mode that the files originally had. If your
384 system has a umask of something like 027, preserving the permissions when
385 copying will lead to a broken install.
386
387 Note that just passing keep_permissions=False to copy_file would be
388 insufficient, as it might still be applying a umask.
389 '''
390
391 def run(self):
392 realcopyfile = file_util.copy_file
393 def copyfileandsetmode(*args, **kwargs):
394 src, dst = args[0], args[1]
395 dst, copied = realcopyfile(*args, **kwargs)
396 if copied:
397 st = os.stat(src)
398 # Persist executable bit (apply it to group and other if user
399 # has it)
400 if st[stat.ST_MODE] & stat.S_IXUSR:
401 setmode = 0755
402 else:
403 setmode = 0644
404 os.chmod(dst, (stat.S_IMODE(st[stat.ST_MODE]) & ~0777) |
405 setmode)
406 file_util.copy_file = copyfileandsetmode
407 try:
408 install_lib.run(self)
409 finally:
410 file_util.copy_file = realcopyfile
411
378 class hginstallscripts(install_scripts): 412 class hginstallscripts(install_scripts):
379 ''' 413 '''
380 This is a specialization of install_scripts that replaces the @LIBDIR@ with 414 This is a specialization of install_scripts that replaces the @LIBDIR@ with
381 the configured directory for modules. If possible, the path is made relative 415 the configured directory for modules. If possible, the path is made relative
382 to the directory for scripts. 416 to the directory for scripts.
424 cmdclass = {'build': hgbuild, 458 cmdclass = {'build': hgbuild,
425 'build_mo': hgbuildmo, 459 'build_mo': hgbuildmo,
426 'build_ext': hgbuildext, 460 'build_ext': hgbuildext,
427 'build_py': hgbuildpy, 461 'build_py': hgbuildpy,
428 'build_hgextindex': buildhgextindex, 462 'build_hgextindex': buildhgextindex,
463 'install_lib': hginstalllib,
429 'install_scripts': hginstallscripts, 464 'install_scripts': hginstallscripts,
430 'build_hgexe': buildhgexe, 465 'build_hgexe': buildhgexe,
431 } 466 }
432 467
433 packages = ['mercurial', 'mercurial.hgweb', 'mercurial.httpclient', 468 packages = ['mercurial', 'mercurial.hgweb', 'mercurial.httpclient',