setup.py revision 3026
3177N/A#!/usr/bin/python2.6
290N/A#
290N/A# CDDL HEADER START
290N/A#
290N/A# The contents of this file are subject to the terms of the
290N/A# Common Development and Distribution License (the "License").
290N/A# You may not use this file except in compliance with the License.
290N/A#
290N/A# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
290N/A# or http://www.opensolaris.org/os/licensing.
290N/A# See the License for the specific language governing permissions
290N/A# and limitations under the License.
290N/A#
290N/A# When distributing Covered Code, include this CDDL HEADER in each
290N/A# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
290N/A# If applicable, add the following below this CDDL HEADER, with the
290N/A# fields enclosed by brackets "[]" replaced with your own identifying
290N/A# information: Portions Copyright [yyyy] [name of copyright owner]
290N/A#
290N/A# CDDL HEADER END
290N/A#
3313N/A# Copyright (c) 2008, 2014, Oracle and/or its affiliates. All rights reserved.
395N/A#
290N/A
3143N/Aimport errno
883N/Aimport fnmatch
454N/Aimport os
290N/Aimport platform
448N/Aimport stat
3234N/Aimport sys
290N/Aimport shutil
290N/Aimport re
290N/Aimport subprocess
383N/Aimport tarfile
290N/Aimport tempfile
395N/Aimport urllib
290N/Aimport py_compile
849N/Aimport hashlib
1516N/Aimport time
2508N/Aimport StringIO
290N/A
2535N/Afrom distutils.errors import DistutilsError, DistutilsFileError
2698N/Afrom distutils.core import setup
290N/Afrom distutils.cmd import Command
290N/Afrom distutils.command.install import install as _install
2535N/Afrom distutils.command.install_data import install_data as _install_data
2561N/Afrom distutils.command.install_lib import install_lib as _install_lib
290N/Afrom distutils.command.build import build as _build
2508N/Afrom distutils.command.build_ext import build_ext as _build_ext
383N/Afrom distutils.command.build_py import build_py as _build_py
290N/Afrom distutils.command.bdist import bdist as _bdist
290N/Afrom distutils.command.clean import clean as _clean
2339N/Afrom distutils.dist import Distribution
2535N/Afrom distutils import log
290N/A
290N/Afrom distutils.sysconfig import get_python_inc
2535N/Aimport distutils.dep_util as dep_util
2535N/Aimport distutils.dir_util as dir_util
290N/Aimport distutils.file_util as file_util
290N/Aimport distutils.util as util
2508N/Aimport distutils.ccompiler
2508N/Afrom distutils.unixccompiler import UnixCCompiler
290N/A
1660N/Aosname = platform.uname()[0].lower()
1660N/Aostype = arch = 'unknown'
1660N/Aif osname == 'sunos':
1660N/A arch = platform.processor()
1660N/A ostype = "posix"
1660N/Aelif osname == 'linux':
1660N/A arch = "linux_" + platform.machine()
1660N/A ostype = "posix"
1660N/Aelif osname == 'windows':
1660N/A arch = osname
1660N/A ostype = "windows"
1660N/Aelif osname == 'darwin':
1660N/A arch = osname
1660N/A ostype = "posix"
1660N/Aelif osname == 'aix':
1660N/A arch = "aix"
1660N/A ostype = "posix"
1660N/A
448N/Apwd = os.path.normpath(sys.path[0])
448N/A
2828N/A# the version of pylint that we must have in order to run the pylint checks.
3253N/Areq_pylint_version = "0.25.2"
2828N/A
534N/A#
534N/A# Unbuffer stdout and stderr. This helps to ensure that subprocess output
534N/A# is properly interleaved with output from this program.
534N/A#
3339N/Asys.stdout = os.fdopen(sys.stdout.fileno(), "w", 0)
3339N/Asys.stderr = os.fdopen(sys.stderr.fileno(), "w", 0)
3339N/A
3339N/Adist_dir = os.path.normpath(os.path.join(pwd, os.pardir, "proto", "dist_" + arch))
534N/Abuild_dir = os.path.normpath(os.path.join(pwd, os.pardir, "proto", "build_" + arch))
290N/Aif "ROOT" in os.environ and os.environ["ROOT"] != "":
290N/A root_dir = os.environ["ROOT"]
954N/Aelse:
954N/A root_dir = os.path.normpath(os.path.join(pwd, os.pardir, "proto", "root_" + arch))
954N/Apkgs_dir = os.path.normpath(os.path.join(pwd, os.pardir, "packages", arch))
954N/Aextern_dir = os.path.normpath(os.path.join(pwd, "extern"))
534N/A
1099N/Apy_install_dir = 'usr/lib/python2.6/vendor-packages'
3261N/A
290N/Ascripts_dir = 'usr/bin'
3117N/Alib_dir = 'usr/lib'
3117N/Asvc_method_dir = 'lib/svc/method'
3203N/Asvc_share_dir = 'lib/svc/share'
3117N/A
290N/Aman1_dir = 'usr/share/man/man1'
3246N/Aman1m_dir = 'usr/share/man/man1m'
3246N/Aman5_dir = 'usr/share/man/man5'
3246N/Aman1_ja_JP_dir = 'usr/share/man/ja_JP.UTF-8/man1'
3374N/Aman1m_ja_JP_dir = 'usr/share/man/ja_JP.UTF-8/man1m'
3246N/Aman5_ja_JP_dir = 'usr/share/man/ja_JP.UTF-8/man5'
290N/Aman1_zh_CN_dir = 'usr/share/man/zh_CN.UTF-8/man1'
290N/Aman1m_zh_CN_dir = 'usr/share/man/zh_CN.UTF-8/man1m'
661N/Aman5_zh_CN_dir = 'usr/share/man/zh_CN.UTF-8/man5'
2867N/A
290N/Aresource_dir = 'usr/share/lib/pkg'
2494N/Atransform_dir = 'usr/share/pkg/transforms'
3356N/Asmf_app_dir = 'lib/svc/manifest/application/pkg'
3356N/Aexecattrd_dir = 'etc/security/exec_attr.d'
2516N/Aauthattrd_dir = 'etc/security/auth_attr.d'
3356N/Auserattrd_dir = 'etc/user_attr.d'
3356N/Asysrepo_dir = 'etc/pkg/sysrepo'
2516N/Asysrepo_logs_dir = 'var/log/pkg/sysrepo'
3356N/Asysrepo_cache_dir = 'var/cache/pkg/sysrepo'
3356N/Adepot_dir = 'etc/pkg/depot'
2516N/Adepot_conf_dir = 'etc/pkg/depot/conf.d'
290N/Adepot_logs_dir = 'var/log/pkg/depot'
3185N/Adepot_cache_dir = 'var/cache/pkg/depot'
2523N/Alocale_dir = 'usr/share/locale'
3138N/Amirror_logs_dir = 'var/log/pkg/mirror'
2390N/Amirror_cache_dir = 'var/cache/pkg/mirror'
1498N/A
1498N/A
2867N/A# A list of source, destination tuples of modules which should be hardlinked
2310N/A# together if the os supports it and otherwise copied.
3237N/Ahardlink_modules = []
2310N/A
2310N/Ascripts_sunos = {
2852N/A scripts_dir: [
3237N/A ['client.py', 'pkg'],
2852N/A ['pkgdep.py', 'pkgdepend'],
2852N/A ['pkgrepo.py', 'pkgrepo'],
2852N/A ['util/publish/pkgdiff.py', 'pkgdiff'],
2535N/A ['util/publish/pkgfmt.py', 'pkgfmt'],
2867N/A ['util/publish/pkglint.py', 'pkglint'],
2867N/A ['util/publish/pkgmerge.py', 'pkgmerge'],
2310N/A ['util/publish/pkgmogrify.py', 'pkgmogrify'],
290N/A ['util/publish/pkgsurf.py', 'pkgsurf'],
1674N/A ['publish.py', 'pkgsend'],
1674N/A ['pull.py', 'pkgrecv'],
2262N/A ['sign.py', 'pkgsign'],
1674N/A ],
395N/A lib_dir: [
430N/A ['depot.py', 'pkg.depotd'],
395N/A ['sysrepo.py', 'pkg.sysrepo'],
1544N/A ['depot-config.py', "pkg.depot-config"]
1968N/A ],
1557N/A svc_method_dir: [
1903N/A ['svc/svc-pkg-depot', 'svc-pkg-depot'],
2046N/A ['svc/svc-pkg-mdns', 'svc-pkg-mdns'],
2240N/A ['svc/svc-pkg-mirror', 'svc-pkg-mirror'],
1506N/A ['svc/svc-pkg-repositories-setup',
2928N/A 'svc-pkg-repositories-setup'],
395N/A ['svc/svc-pkg-server', 'svc-pkg-server'],
395N/A ['svc/svc-pkg-sysrepo', 'svc-pkg-sysrepo'],
2026N/A ],
395N/A svc_share_dir: [
395N/A ['svc/pkg5_include.sh', 'pkg5_include.sh'],
395N/A ],
2310N/A }
2852N/A
395N/Ascripts_windows = {
661N/A scripts_dir: [
2867N/A ['client.py', 'client.py'],
2867N/A ['pkgrepo.py', 'pkgrepo.py'],
2867N/A ['publish.py', 'publish.py'],
2867N/A ['pull.py', 'pull.py'],
2867N/A ['scripts/pkg.bat', 'pkg.bat'],
2852N/A ['scripts/pkgsend.bat', 'pkgsend.bat'],
2310N/A ['scripts/pkgrecv.bat', 'pkgrecv.bat'],
3216N/A ],
3216N/A lib_dir: [
2867N/A ['depot.py', 'depot.py'],
2867N/A ['scripts/pkg.depotd.bat', 'pkg.depotd.bat'],
2867N/A ],
661N/A }
3185N/A
3185N/Ascripts_other_unix = {
3185N/A scripts_dir: [
395N/A ['client.py', 'client.py'],
849N/A ['pkgdep.py', 'pkgdep'],
290N/A ['util/publish/pkgdiff.py', 'pkgdiff'],
395N/A ['util/publish/pkgfmt.py', 'pkgfmt'],
395N/A ['util/publish/pkgmogrify.py', 'pkgmogrify'],
1968N/A ['pull.py', 'pull.py'],
395N/A ['publish.py', 'publish.py'],
395N/A ['scripts/pkg.sh', 'pkg'],
395N/A ['scripts/pkgsend.sh', 'pkgsend'],
395N/A ['scripts/pkgrecv.sh', 'pkgrecv'],
395N/A ],
395N/A lib_dir: [
395N/A ['depot.py', 'depot.py'],
395N/A ['scripts/pkg.depotd.sh', 'pkg.depotd'],
395N/A ],
395N/A }
395N/A
290N/A# indexed by 'osname'
290N/Ascripts = {
395N/A "sunos": scripts_sunos,
395N/A "linux": scripts_other_unix,
1231N/A "windows": scripts_windows,
1557N/A "darwin": scripts_other_unix,
1903N/A "aix" : scripts_other_unix,
1557N/A "unknown": scripts_sunos,
395N/A }
395N/A
395N/Aman1_files = [
395N/A 'man/pkg.1',
395N/A 'man/pkgdepend.1',
395N/A 'man/pkgdiff.1',
395N/A 'man/pkgfmt.1',
395N/A 'man/pkglint.1',
395N/A 'man/pkgmerge.1',
395N/A 'man/pkgmogrify.1',
3185N/A 'man/pkgsend.1',
3185N/A 'man/pkgsign.1',
3185N/A 'man/pkgsurf.1',
395N/A 'man/pkgrecv.1',
290N/A 'man/pkgrepo.1',
290N/A ]
430N/Aman1m_files = [
395N/A 'man/pkg.depotd.1m',
395N/A 'man/pkg.depot-config.1m',
395N/A 'man/pkg.sysrepo.1m'
395N/A ]
1302N/Aman5_files = [
395N/A 'man/pkg.5'
395N/A ]
290N/A
3313N/Aman1_ja_files = [
3313N/A 'man/ja_JP/pkg.1',
3139N/A 'man/ja_JP/pkgdepend.1',
395N/A 'man/ja_JP/pkgdiff.1',
3139N/A 'man/ja_JP/pkgfmt.1',
3139N/A 'man/ja_JP/pkglint.1',
3139N/A 'man/ja_JP/pkgmerge.1',
3139N/A 'man/ja_JP/pkgmogrify.1',
3139N/A 'man/ja_JP/pkgsend.1',
3139N/A 'man/ja_JP/pkgsign.1',
3139N/A 'man/ja_JP/pkgrecv.1',
3139N/A 'man/ja_JP/pkgrepo.1',
3139N/A ]
3139N/Aman1m_ja_files = [
3139N/A 'man/ja_JP/pkg.depotd.1m',
3139N/A 'man/ja_JP/pkg.sysrepo.1m'
3139N/A ]
3139N/Aman5_ja_files = [
3139N/A 'man/ja_JP/pkg.5'
3139N/A ]
3356N/A
3356N/Aman1_zh_CN_files = [
3139N/A 'man/zh_CN/pkg.1',
3356N/A 'man/zh_CN/pkgdepend.1',
3139N/A 'man/zh_CN/pkgdiff.1',
3139N/A 'man/zh_CN/pkgfmt.1',
3356N/A 'man/zh_CN/pkglint.1',
3356N/A 'man/zh_CN/pkgmerge.1',
3139N/A 'man/zh_CN/pkgmogrify.1',
3356N/A 'man/zh_CN/pkgsend.1',
3356N/A 'man/zh_CN/pkgsign.1',
3356N/A 'man/zh_CN/pkgrecv.1',
3139N/A 'man/zh_CN/pkgrepo.1',
3139N/A ]
2516N/Aman1m_zh_CN_files = [
2516N/A 'man/zh_CN/pkg.depotd.1m',
3139N/A 'man/zh_CN/pkg.sysrepo.1m'
3139N/A ]
3139N/Aman5_zh_CN_files = [
3139N/A 'man/zh_CN/pkg.5'
3139N/A ]
3139N/A
3139N/Apackages = [
3139N/A 'pkg',
3139N/A 'pkg.actions',
3139N/A 'pkg.bundle',
3139N/A 'pkg.client',
3139N/A 'pkg.client.linkedimage',
3139N/A 'pkg.client.transport',
3387N/A 'pkg.file_layout',
3139N/A 'pkg.flavor',
3139N/A 'pkg.lint',
3356N/A 'pkg.portable',
3356N/A 'pkg.publish',
3139N/A 'pkg.server'
3356N/A ]
3139N/A
3139N/Apylint_targets = [
3356N/A 'pkg.altroot',
3356N/A 'pkg.client.__init__',
3139N/A 'pkg.client.api',
3356N/A 'pkg.client.linkedimage',
3387N/A 'pkg.client.pkgdefs',
3356N/A 'pkg.client.pkgremote',
3139N/A 'pkg.client.plandesc',
3139N/A 'pkg.client.printengine',
2516N/A 'pkg.client.progress',
2516N/A 'pkg.misc',
3139N/A 'pkg.pipeutils',
3139N/A ]
3139N/A
3139N/Aweb_files = []
3139N/Afor entry in os.walk("web"):
3139N/A web_dir, dirs, files = entry
3139N/A if not files:
3139N/A continue
3139N/A web_files.append((os.path.join(resource_dir, web_dir), [
3139N/A os.path.join(web_dir, f) for f in files
3139N/A if f != "Makefile"
3139N/A ]))
3139N/A # install same set of files in "en/" in "__LOCALE__/ as well"
3387N/A # for localizable file package (regarding themes, install
3139N/A # theme "oracle.com" only)
3139N/A if os.path.basename(web_dir) == "en" and \
3356N/A os.path.dirname(web_dir) in ("web", "web/_themes/oracle.com"):
3356N/A web_files.append((os.path.join(resource_dir,
3139N/A os.path.dirname(web_dir), "__LOCALE__"), [
3356N/A os.path.join(web_dir, f) for f in files
3139N/A if f != "Makefile"
3139N/A ]))
3356N/A
3356N/Asmf_app_files = [
3139N/A 'svc/pkg-depot.xml',
3356N/A 'svc/pkg-mdns.xml',
3387N/A 'svc/pkg-mirror.xml',
3356N/A 'svc/pkg-repositories-setup.xml',
3139N/A 'svc/pkg-server.xml',
3139N/A 'svc/pkg-system-repository.xml',
2516N/A 'svc/zoneproxy-client.xml',
395N/A 'svc/zoneproxyd.xml'
395N/A ]
395N/Aresource_files = [
395N/A 'util/opensolaris.org.sections',
395N/A 'util/pkglintrc',
2339N/A ]
1191N/Atransform_files = [
1452N/A 'util/publish/transforms/developer',
1231N/A 'util/publish/transforms/documentation',
2046N/A 'util/publish/transforms/locale',
395N/A 'util/publish/transforms/smf-manifests'
395N/A ]
424N/Asysrepo_files = [
395N/A 'util/apache2/sysrepo/sysrepo_p5p.py',
742N/A 'util/apache2/sysrepo/sysrepo_httpd.conf.mako',
2339N/A 'util/apache2/sysrepo/sysrepo_publisher_response.mako',
2339N/A ]
2693N/Asysrepo_log_stubs = [
2690N/A 'util/apache2/sysrepo/logs/access_log',
2339N/A 'util/apache2/sysrepo/logs/error_log',
3094N/A 'util/apache2/sysrepo/logs/rewrite.log',
2339N/A ]
2690N/Adepot_files = [
2690N/A 'util/apache2/depot/depot.conf.mako',
2693N/A 'util/apache2/depot/depot_httpd.conf.mako',
2693N/A 'util/apache2/depot/depot_index.py',
2690N/A ]
2690N/Adepot_log_stubs = [
2339N/A 'util/apache2/depot/logs/access_log',
2339N/A 'util/apache2/depot/logs/error_log',
742N/A 'util/apache2/depot/logs/rewrite.log',
742N/A ]
742N/A# The apache-based depot includes an shtml file we add to the resource dir
742N/Aweb_files.append((os.path.join(resource_dir, "web"),
742N/A ["util/apache2/depot/repos.shtml"]))
742N/Aexecattrd_files = [
742N/A 'util/misc/exec_attr.d/package:pkg',
742N/A]
742N/Aauthattrd_files = ['util/misc/auth_attr.d/package:pkg']
3136N/Auserattrd_files = ['util/misc/user_attr.d/package:pkg']
2688N/Apkg_locales = \
2688N/A 'ar ca cs de es fr he hu id it ja ko nl pl pt_BR ru sk sv zh_CN zh_HK zh_TW'.split()
2688N/A
2688N/Asysattr_srcs = [
2688N/A 'modules/sysattr.c'
2688N/A ]
2688N/Asyscallat_srcs = [
2688N/A 'modules/syscallat.c'
2688N/A ]
742N/Apspawn_srcs = [
2310N/A 'modules/pspawn.c'
2852N/A ]
1902N/Aelf_srcs = [
2867N/A 'modules/elf.c',
2867N/A 'modules/elfextract.c',
1099N/A 'modules/liblist.c',
2867N/A ]
3216N/Aarch_srcs = [
2338N/A 'modules/arch.c'
2338N/A ]
2310N/A_actions_srcs = [
2046N/A 'modules/actions/_actions.c'
2223N/A ]
2046N/A_actcomm_srcs = [
2046N/A 'modules/actions/_common.c'
2523N/A ]
2523N/A_varcet_srcs = [
2523N/A 'modules/_varcet.c'
2523N/A ]
2523N/Asolver_srcs = [
2523N/A 'modules/solver/solver.c',
2310N/A 'modules/solver/py_solver.c'
2677N/A ]
2310N/Asolver_link_args = ["-lm", "-lc"]
2310N/Aif osname == 'sunos':
2310N/A solver_link_args = ["-ztext"] + solver_link_args
3237N/A
3237N/A# Runs lint on the extension module source code
3237N/Aclass pylint_func(Command):
3237N/A description = "Runs pylint tools over IPS python source code"
2310N/A user_options = []
2310N/A
2310N/A def initialize_options(self):
2858N/A pass
2310N/A
2852N/A def finalize_options(self):
2852N/A pass
2852N/A
2852N/A # Make string shell-friendly
3136N/A @staticmethod
2852N/A def escape(astring):
3237N/A return astring.replace(' ', '\\ ')
3237N/A
3237N/A def run(self, quiet=False):
3237N/A
3237N/A def supported_pylint_ver(version):
2852N/A """Compare the installed version against the version
2852N/A we require to build with, returning False if the version
2852N/A is too old. It's tempting to use pkg.version.Version
2858N/A here, but since that's a build artifact, we'll do it
2852N/A the long way."""
3138N/A inst_pylint_ver = version.split(".")
3138N/A req_pylint_ver = req_pylint_version.split(".")
2852N/A
2852N/A # if the lists are of different lengths, we just
2852N/A # compare with the precision we have.
2508N/A vers_comp = zip(inst_pylint_ver, req_pylint_ver)
2508N/A for inst, req in vers_comp:
2508N/A try:
2508N/A if int(inst) < int(req):
2867N/A return False
2535N/A except ValueError:
2535N/A # if we somehow get non-numeric version
2535N/A # components, we ignore them.
3053N/A continue
3261N/A return True
3053N/A
3026N/A # it's fine to default to the required version - the build will
3261N/A # break if the installed version is incompatible and $PYLINT_VER
3026N/A # didn't get set, somehow.
2339N/A pylint_ver_str = os.environ.get("PYLINT_VER",
3261N/A req_pylint_version)
2339N/A if pylint_ver_str == "":
691N/A pylint_ver_str = req_pylint_version
3261N/A
691N/A if os.environ.get("PKG_SKIP_PYLINT"):
395N/A log.warn("WARNING: skipping pylint checks: "
395N/A "$PKG_SKIP_PYLINT was set")
395N/A return
395N/A elif not pylint_ver_str or \
395N/A not supported_pylint_ver(pylint_ver_str):
290N/A log.warn("WARNING: skipping pylint checks: the "
3261N/A "installed version %s is older than version %s" %
395N/A (pylint_ver_str, req_pylint_version))
591N/A return
591N/A
591N/A proto = os.path.join(root_dir, py_install_dir)
2639N/A sys.path.insert(0, proto)
2639N/A
2639N/A # Insert tests directory onto sys.path so any custom checkers
2639N/A # can be found.
2639N/A sys.path.insert(0, os.path.join(pwd, 'tests'))
2639N/A # assumes pylint is accessible on the sys.path
1505N/A from pylint import lint
2516N/A
1505N/A #
1505N/A # For some reason, the load-plugins option, when used in the
1632N/A # rcfile, does not work, so we put it here instead, to load
1632N/A # our custom checkers.
1632N/A #
1632N/A # Unfortunately, pylint seems pretty fragile and will crash if
2339N/A # we try to run it over all the current pkg source. Hence for
2339N/A # now we only run it over a subset of the source. As source
2339N/A # files are made pylint clean they should be added to the
2339N/A # pylint_targets list.
2339N/A #
2339N/A args = ['--load-plugins=multiplatform']
2339N/A if quiet:
2339N/A args += ['--reports=no']
2339N/A args += ['--rcfile', os.path.join(pwd, 'tests', 'pylintrc')]
2339N/A args += pylint_targets
2339N/A lint.Run(args)
2339N/A
2339N/A
2339N/Aclass pylint_func_quiet(pylint_func):
2339N/A
2339N/A def run(self, quiet=False):
3253N/A pylint_func.run(self, quiet=True)
2828N/A
2828N/A
2828N/Ainclude_dirs = [ 'modules' ]
2828N/Alint_flags = [ '-u', '-axms', '-erroff=E_NAME_DEF_NOT_USED2' ]
2828N/A
2828N/A# Runs lint on the extension module source code
2828N/Aclass clint_func(Command):
2828N/A description = "Runs lint tools over IPS C extension source code"
2828N/A user_options = []
2828N/A
2828N/A def initialize_options(self):
2828N/A pass
2828N/A
2828N/A def finalize_options(self):
2828N/A pass
2828N/A
2828N/A # Make string shell-friendly
3253N/A @staticmethod
3253N/A def escape(astring):
2828N/A return astring.replace(' ', '\\ ')
2828N/A
2828N/A def run(self):
2828N/A if "LINT" in os.environ and os.environ["LINT"] != "":
2828N/A lint = [os.environ["LINT"]]
2828N/A else:
2828N/A lint = ['lint']
2828N/A if osname == 'sunos' or osname == "linux":
2828N/A archcmd = lint + lint_flags + \
2828N/A ['-D_FILE_OFFSET_BITS=64'] + \
2828N/A ["%s%s" % ("-I", k) for k in include_dirs] + \
2892N/A ['-I' + self.escape(get_python_inc())] + \
2892N/A arch_srcs
2828N/A elfcmd = lint + lint_flags + \
2828N/A ["%s%s" % ("-I", k) for k in include_dirs] + \
2828N/A ['-I' + self.escape(get_python_inc())] + \
2828N/A ["%s%s" % ("-l", k) for k in elf_libraries] + \
2828N/A elf_srcs
2828N/A _actionscmd = lint + lint_flags + \
2828N/A ["%s%s" % ("-I", k) for k in include_dirs] + \
2828N/A ['-I' + self.escape(get_python_inc())] + \
3158N/A _actions_srcs
3158N/A _actcommcmd = lint + lint_flags + \
2828N/A ["%s%s" % ("-I", k) for k in include_dirs] + \
2828N/A ['-I' + self.escape(get_python_inc())] + \
2339N/A _actcomm_srcs
2339N/A _varcetcmd = lint + lint_flags + \
2339N/A ["%s%s" % ("-I", k) for k in include_dirs] + \
3253N/A ['-I' + self.escape(get_python_inc())] + \
2339N/A _varcet_srcs
2339N/A pspawncmd = lint + lint_flags + \
2339N/A ['-D_FILE_OFFSET_BITS=64'] + \
2339N/A ["%s%s" % ("-I", k) for k in include_dirs] + \
2339N/A ['-I' + self.escape(get_python_inc())] + \
2339N/A pspawn_srcs
2339N/A syscallatcmd = lint + lint_flags + \
2339N/A ['-D_FILE_OFFSET_BITS=64'] + \
2339N/A ["%s%s" % ("-I", k) for k in include_dirs] + \
2339N/A ['-I' + self.escape(get_python_inc())] + \
2339N/A syscallat_srcs
2339N/A sysattrcmd = lint + lint_flags + \
2339N/A ['-D_FILE_OFFSET_BITS=64'] + \
3253N/A ["%s%s" % ("-I", k) for k in include_dirs] + \
3253N/A ['-I' + self.escape(get_python_inc())] + \
3253N/A ["%s%s" % ("-l", k) for k in sysattr_libraries] + \
3253N/A sysattr_srcs
3253N/A
3253N/A print(" ".join(archcmd))
3253N/A os.system(" ".join(archcmd))
3253N/A print(" ".join(elfcmd))
3253N/A os.system(" ".join(elfcmd))
3253N/A print(" ".join(_actionscmd))
3253N/A os.system(" ".join(_actionscmd))
3253N/A print(" ".join(_actcommcmd))
3253N/A os.system(" ".join(_actcommcmd))
3253N/A print(" ".join(_varcetcmd))
3253N/A os.system(" ".join(_varcetcmd))
3253N/A print(" ".join(pspawncmd))
3253N/A os.system(" ".join(pspawncmd))
3253N/A print(" ".join(syscallatcmd))
3253N/A os.system(" ".join(syscallatcmd))
3253N/A print(" ".join(sysattrcmd))
3253N/A os.system(" ".join(sysattrcmd))
3253N/A
3253N/A
3253N/A# Runs both C and Python lint
3253N/Aclass lint_func(Command):
3253N/A description = "Runs C and Python lint checkers"
2364N/A user_options = []
2364N/A
2364N/A def initialize_options(self):
2364N/A pass
2364N/A
2364N/A def finalize_options(self):
2364N/A pass
3253N/A
3253N/A # Make string shell-friendly
3253N/A @staticmethod
2339N/A def escape(astring):
395N/A return astring.replace(' ', '\\ ')
395N/A
290N/A def run(self):
290N/A clint_func(Distribution()).run()
2339N/A pylint_func(Distribution()).run()
2339N/A
290N/Aclass install_func(_install):
290N/A def initialize_options(self):
290N/A _install.initialize_options(self)
290N/A
290N/A # PRIVATE_BUILD set in the environment tells us to put the build
290N/A # directory into the .pyc files, rather than the final
290N/A # installation directory.
290N/A private_build = os.getenv("PRIVATE_BUILD", None)
290N/A
290N/A if private_build is None:
395N/A self.install_lib = py_install_dir
395N/A self.install_data = os.path.sep
290N/A self.root = root_dir
290N/A else:
2674N/A self.install_lib = os.path.join(root_dir, py_install_dir)
2674N/A self.install_data = root_dir
2674N/A
2674N/A # This is used when installing scripts, below, but it isn't a
290N/A # standard distutils variable.
2674N/A self.root_dir = root_dir
2674N/A
3158N/A def run(self):
395N/A """At the end of the install function, we need to rename some
395N/A files because distutils provides no way to rename files as they
2674N/A are placed in their install locations.
3158N/A """
395N/A
3158N/A _install.run(self)
395N/A
2674N/A for o_src, o_dest in hardlink_modules:
3158N/A for e in [".py", ".pyc"]:
591N/A src = util.change_root(self.root_dir, o_src + e)
591N/A dest = util.change_root(
2674N/A self.root_dir, o_dest + e)
3158N/A if ostype == "posix":
2639N/A if os.path.exists(dest) and \
2639N/A os.stat(src)[stat.ST_INO] != \
2674N/A os.stat(dest)[stat.ST_INO]:
3158N/A os.remove(dest)
2639N/A file_util.copy_file(src, dest,
2639N/A link="hard", update=1)
2674N/A else:
2674N/A file_util.copy_file(src, dest, update=1)
3158N/A
691N/A for d, files in scripts[osname].iteritems():
691N/A for (srcname, dstname) in files:
2674N/A dst_dir = util.change_root(self.root_dir, d)
2674N/A dst_path = util.change_root(self.root_dir,
3158N/A os.path.join(d, dstname))
2339N/A dir_util.mkpath(dst_dir, verbose=True)
2339N/A file_util.copy_file(srcname, dst_path, update=True)
3026N/A # make scripts executable
3026N/A os.chmod(dst_path,
3158N/A os.stat(dst_path).st_mode
3026N/A | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)
3158N/A
3026N/Aclass install_lib_func(_install_lib):
3053N/A """Remove the target files prior to the standard install_lib procedure
3053N/A if the build_py module has determined that they've actually changed.
3158N/A This may be needed when a module's timestamp goes backwards in time, if
3053N/A a working-directory change is reverted, or an older changeset is checked
3158N/A out.
3053N/A """
290N/A
290N/A def install(self):
290N/A build_py = self.get_finalized_command("build_py")
290N/A prefix_len = len(self.build_dir) + 1
290N/A for p in build_py.copied:
591N/A id_p = os.path.join(self.install_dir, p[prefix_len:])
591N/A rm_f(id_p)
2639N/A if self.compile:
2639N/A rm_f(id_p + "c")
2639N/A if self.optimize > 0:
2639N/A rm_f(id_p + "o")
691N/A return _install_lib.install(self)
691N/A
2339N/Aclass install_data_func(_install_data):
2339N/A """Enhance the standard install_data subcommand to take not only a list
3026N/A of filenames, but a list of source and destination filename tuples, for
3026N/A the cases where a filename needs to be renamed between the two
3053N/A locations."""
3053N/A
290N/A def run(self):
290N/A self.mkpath(self.install_dir)
2339N/A for f in self.data_files:
2339N/A dir, files = f
2339N/A dir = util.convert_path(dir)
2339N/A if not os.path.isabs(dir):
2339N/A dir = os.path.join(self.install_dir, dir)
2339N/A elif self.root:
2339N/A dir = change_root(self.root, dir)
290N/A self.mkpath(dir)
2339N/A
2339N/A if not files:
290N/A self.outfiles.append(dir)
2339N/A else:
2339N/A for file in files:
2339N/A if isinstance(file, basestring):
2339N/A infile = file
2339N/A outfile = os.path.join(dir,
2339N/A os.path.basename(file))
2339N/A else:
2339N/A infile, outfile = file
290N/A infile = util.convert_path(infile)
395N/A outfile = util.convert_path(outfile)
290N/A if os.path.sep not in outfile:
395N/A outfile = os.path.join(dir,
506N/A outfile)
506N/A self.copy_file(infile, outfile)
506N/A self.outfiles.append(outfile)
506N/A
506N/Adef run_cmd(args, swdir, updenv=None, ignerr=False, savestderr=None):
506N/A if updenv:
506N/A # use temp environment modified with the given dict
506N/A env = os.environ.copy()
834N/A env.update(updenv)
506N/A else:
506N/A # just use environment of this (parent) process as is
506N/A env = os.environ
513N/A if ignerr:
506N/A # send stderr to devnull
506N/A stderr = open(os.devnull)
506N/A elif savestderr:
506N/A stderr = savestderr
290N/A else:
290N/A # just use stderr of this (parent) process
2535N/A stderr = None
2535N/A ret = subprocess.Popen(args, cwd=swdir, env=env,
2535N/A stderr=stderr).wait()
395N/A if ret != 0:
413N/A if stderr:
395N/A stderr.close()
1674N/A print >> sys.stderr, \
1674N/A "install failed and returned %d." % ret
1674N/A print >> sys.stderr, \
1674N/A "Command was: %s" % " ".join(args)
1674N/A sys.exit(1)
1674N/A if stderr:
1674N/A stderr.close()
1674N/A
1674N/Adef _copy_file_contents(src, dst, buffer_size=16*1024):
1674N/A """A clone of distutils.file_util._copy_file_contents() that strips the
1674N/A CDDL text. For Python files, we replace the CDDL text with an equal
1674N/A number of empty comment lines so that line numbers match between the
1674N/A source and destination files."""
1674N/A
1674N/A # Match the lines between and including the CDDL header signposts, as
3203N/A # well as empty comment lines before and after, if they exist.
3203N/A cddl_re = re.compile("\n(#\s*\n)?^[^\n]*CDDL HEADER START.+"
3203N/A "CDDL HEADER END[^\n]*$(\n#\s*$)?", re.MULTILINE|re.DOTALL)
3339N/A
3339N/A with file(src, "r") as sfp:
3234N/A try:
395N/A os.unlink(dst)
506N/A except EnvironmentError, e:
506N/A if e.errno != errno.ENOENT:
395N/A raise DistutilsFileError("could not delete "
2535N/A "'%s': %s" % (dst, e))
3246N/A
3246N/A with file(dst, "w") as dfp:
395N/A while True:
430N/A buf = sfp.read(buffer_size)
849N/A if not buf:
834N/A break
290N/A if src.endswith(".py"):
2561N/A match = cddl_re.search(buf)
2561N/A if match:
2561N/A # replace the CDDL expression
2561N/A # with the same number of empty
2561N/A # comment lines as the cddl_re
2561N/A # matched.
2561N/A substr = buf[
2561N/A match.start():match.end()]
2561N/A count = len(
2561N/A substr.split("\n")) - 2
2561N/A blanks = "#\n" * count
2561N/A buf = cddl_re.sub("\n" + blanks,
2561N/A buf)
2561N/A else:
2561N/A buf = cddl_re.sub("", buf)
2561N/A dfp.write(buf)
2561N/A
2561N/A# Make file_util use our version of _copy_file_contents
2561N/Afile_util._copy_file_contents = _copy_file_contents
2561N/A
2535N/Adef intltool_update_maintain():
2535N/A """Check if scope of localization looks up-to-date or possibly not,
2535N/A by comparing file set described in po/POTFILES.{in,skip} and
2535N/A actual source files (e.g. .py) detected.
2535N/A """
1099N/A rm_f("po/missing")
2535N/A rm_f("po/notexist")
2535N/A
2535N/A args = [
2535N/A "/usr/bin/intltool-update", "--maintain"
2535N/A ]
2535N/A print " ".join(args)
2535N/A podir = os.path.join(os.getcwd(), "po")
2535N/A run_cmd(args, podir, updenv={"LC_ALL": "C"}, ignerr=True)
2535N/A
2535N/A if os.path.exists("po/missing"):
1099N/A print >> sys.stderr, \
2535N/A "New file(s) with translatable strings detected:"
2535N/A missing = open("po/missing", "r")
2535N/A print >> sys.stderr, "--------"
2535N/A for fn in missing:
3234N/A print >> sys.stderr, "%s" % fn.strip()
2535N/A print >> sys.stderr, "--------"
2535N/A missing.close()
2535N/A print >> sys.stderr, \
2535N/A"""Please evaluate whether any of the above file(s) needs localization.
2535N/AIf so, please add its name to po/POTFILES.in. If not (e.g., it's not
2535N/Adelivered), please add its name to po/POTFILES.skip.
2535N/APlease be sure to maintain alphabetical ordering in both files."""
2535N/A sys.exit(1)
2535N/A
2535N/A if os.path.exists("po/notexist"):
2535N/A print >> sys.stderr, \
2535N/A"""The following files are listed in po/POTFILES.in, but no longer exist
1099N/Ain the workspace:"""
2826N/A notexist = open("po/notexist", "r")
2688N/A print >> sys.stderr, "--------"
2688N/A for fn in notexist:
2688N/A print >> sys.stderr, "%s" % fn.strip()
2688N/A print >> sys.stderr, "--------"
2688N/A notexist.close()
2688N/A print >> sys.stderr, \
1660N/A "Please remove the file names from po/POTFILES.in"
2688N/A sys.exit(1)
2688N/A
2688N/Adef intltool_update_pot():
2826N/A """Generate pkg.pot by extracting localizable strings from source
2826N/A files (e.g. .py)
2688N/A """
2688N/A rm_f("po/pkg.pot")
2688N/A
2688N/A args = [
2688N/A "/usr/bin/intltool-update", "--pot"
849N/A ]
2688N/A print " ".join(args)
2688N/A podir = os.path.join(os.getcwd(), "po")
3158N/A run_cmd(args, podir,
3143N/A updenv={"LC_ALL": "C", "XGETTEXT": "/usr/gnu/bin/xgettext"})
3177N/A
3143N/A if not os.path.exists("po/pkg.pot"):
3158N/A print >> sys.stderr, \
849N/A "Failed in generating pkg.pot."
2688N/A sys.exit(1)
2688N/A
290N/Adef intltool_merge(src, dst):
2535N/A if not dep_util.newer(src, dst):
2535N/A return
2597N/A
2597N/A args = [
2597N/A "/usr/bin/intltool-merge", "-d", "-u",
2535N/A "-c", "po/.intltool-merge-cache", "po", src, dst
2535N/A ]
2535N/A print " ".join(args)
3339N/A run_cmd(args, os.getcwd(), updenv={"LC_ALL": "C"})
3339N/A
2535N/Adef i18n_check():
3246N/A """Checks for common i18n messaging bugs in the source."""
3246N/A
3246N/A src_files = []
3246N/A # A list of the i18n errors we check for in the code
3339N/A common_i18n_errors = [
2535N/A # This checks that messages with multiple parameters are always
2535N/A # written using "%(name)s" format, rather than just "%s"
3171N/A "format string with unnamed arguments cannot be properly localized"
2535N/A ]
2535N/A
3158N/A for line in open("po/POTFILES.in", "r").readlines():
2535N/A if line.startswith("["):
3339N/A continue
2535N/A if line.startswith("#"):
2535N/A continue
2535N/A src_files.append(line.rstrip())
2535N/A
3374N/A args = [
2597N/A "/usr/gnu/bin/xgettext", "--from-code=UTF-8", "-o", "/dev/null"]
2597N/A args += src_files
2597N/A
2597N/A xgettext_output_path = tempfile.mkstemp()[1]
2597N/A xgettext_output = open(xgettext_output_path, "w")
2597N/A run_cmd(args, os.getcwd(), updenv={"LC_ALL": "C"},
2597N/A savestderr=xgettext_output)
2597N/A
2597N/A found_errs = False
3339N/A i18n_errs = open("po/i18n_errs.txt", "w")
3339N/A for line in open(xgettext_output_path, "r").readlines():
3339N/A for err in common_i18n_errors:
2597N/A if err in line:
3246N/A i18n_errs.write(line)
3246N/A found_errs = True
3246N/A i18n_errs.close()
3246N/A if found_errs:
3246N/A print >> sys.stderr, \
3246N/A"The following i18n errors were detected and should be corrected:\n" \
3246N/A"(this list is saved in po/i18n_errs.txt)\n"
3246N/A for line in open("po/i18n_errs.txt", "r"):
3246N/A print >> sys.stderr, line.rstrip()
3246N/A sys.exit(1)
3246N/A os.remove(xgettext_output_path)
2597N/A
3339N/Adef msgfmt(src, dst):
2535N/A if not dep_util.newer(src, dst):
3246N/A return
2535N/A
2535N/A args = ["/usr/bin/msgfmt", "-o", dst, src]
2535N/A print " ".join(args)
2535N/A run_cmd(args, os.getcwd())
2688N/A
2688N/Adef localizablexml(src, dst):
2688N/A """create XML help for localization, where French part of legalnotice
2688N/A is stripped off
2688N/A """
2688N/A if not dep_util.newer(src, dst):
2688N/A return
2688N/A
2688N/A fsrc = open(src, "r")
2688N/A fdst = open(dst, "w")
2688N/A
3143N/A # indicates currently in French part of legalnotice
2688N/A in_fr = False
2688N/A
2688N/A for l in fsrc:
2688N/A if in_fr: # in French part
3143N/A if l.startswith('</legalnotice>'):
3143N/A # reached end of legalnotice
2688N/A print >> fdst, l,
3143N/A in_fr = False
2688N/A elif l.startswith('<para lang="fr"/>') or \
3158N/A l.startswith('<para lang="fr"></para>'):
3177N/A in_fr = True
2688N/A else:
3143N/A # not in French part
3143N/A print >> fdst, l,
3136N/A
3136N/A fsrc.close()
3143N/A fdst.close()
2688N/A
2688N/Adef xml2po_gen(src, dst):
2688N/A """Input is English XML file. Output is pkg_help.pot, message
3143N/A source for next translation update.
3143N/A """
3143N/A if not dep_util.newer(src, dst):
2688N/A return
3143N/A
2688N/A args = ["/usr/bin/xml2po", "-o", dst, src]
3158N/A print " ".join(args)
3158N/A run_cmd(args, os.getcwd())
3158N/A
2688N/Adef xml2po_merge(src, dst, mofile):
3143N/A """Input is English XML file and <lang>.po file (which contains
3143N/A translations). Output is translated XML file.
2688N/A """
2688N/A msgfmt(mofile[:-3] + ".po", mofile)
2688N/A
2688N/A monewer = dep_util.newer(mofile, dst)
2688N/A srcnewer = dep_util.newer(src, dst)
2688N/A
2688N/A if not srcnewer and not monewer:
2688N/A return
2688N/A
2688N/A args = ["/usr/bin/xml2po", "-t", mofile, "-o", dst, src]
2688N/A print " ".join(args)
3143N/A run_cmd(args, os.getcwd())
2688N/A
2688N/Aclass installfile(Command):
2688N/A user_options = [
2688N/A ("file=", "f", "source file to copy"),
2688N/A ("dest=", "d", "destination directory"),
3143N/A ("mode=", "m", "file mode"),
2688N/A ]
2688N/A
2535N/A description = "De-CDDLing file copy"
2535N/A
2535N/A def initialize_options(self):
2535N/A self.file = None
2535N/A self.dest = None
2535N/A self.mode = None
2535N/A
2535N/A def finalize_options(self):
3143N/A if self.mode is None:
2688N/A self.mode = 0644
2535N/A elif isinstance(self.mode, basestring):
2826N/A try:
2826N/A self.mode = int(self.mode, 8)
2826N/A except ValueError:
2826N/A self.mode = 0644
2826N/A
2826N/A def run(self):
2826N/A dest_file = os.path.join(self.dest, os.path.basename(self.file))
3158N/A ret = self.copy_file(self.file, dest_file)
2826N/A
2826N/A os.chmod(dest_file, self.mode)
2826N/A os.utime(dest_file, None)
2826N/A
2826N/A return ret
2826N/A
2826N/Aclass build_func(_build):
2826N/A sub_commands = _build.sub_commands + [('build_data', None)]
2826N/A
2826N/A def initialize_options(self):
2826N/A _build.initialize_options(self)
2826N/A self.build_base = build_dir
2826N/A
2826N/Adef get_hg_version():
2826N/A try:
2826N/A p = subprocess.Popen(['hg', 'id', '-i'], stdout = subprocess.PIPE)
2826N/A return p.communicate()[0].strip()
2826N/A except OSError:
2826N/A print >> sys.stderr, "ERROR: unable to obtain mercurial version"
2826N/A return "unknown"
2826N/A
2826N/Adef syntax_check(filename):
2826N/A """ Run python's compiler over the file, and discard the results.
2826N/A Arrange to generate an exception if the file does not compile.
2826N/A This is needed because distutil's own use of pycompile (in the
2826N/A distutils.utils module) is broken, and doesn't stop on error. """
2826N/A try:
2826N/A py_compile.compile(filename, os.devnull, doraise=True)
3143N/A except py_compile.PyCompileError, e:
3143N/A res = ""
3143N/A for err in e.exc_value:
3143N/A if isinstance(err, basestring):
2826N/A res += err + "\n"
3143N/A continue
2826N/A
2826N/A # Assume it's a tuple of (filename, lineno, col, code)
2826N/A fname, line, col, code = err
2535N/A res += "line %d, column %s, in %s:\n%s" % (line,
2535N/A col or "unknown", fname, code)
2535N/A
2535N/A raise DistutilsError(res)
2535N/A
3143N/A# On Solaris, ld inserts the full argument to the -o option into the symbol
2535N/A# table. This means that the resulting object will be different depending on
2535N/A# the path at which the workspace lives, and not just on the interesting content
2688N/A# of the object.
2688N/A#
2688N/A# In order to work around that bug (7076871), we create a new compiler class
2688N/A# that looks at the argument indicating the output file, chdirs to its
2688N/A# directory, and runs the real link with the output file set to just the base
2688N/A# name of the file.
2688N/A#
2688N/A# Unfortunately, distutils isn't too customizable in this regard, so we have to
2688N/A# twiddle with a couple of the names in the distutils.ccompiler namespace: we
2688N/A# have to add a new entry to the compiler_class dict, and we have to override
2688N/A# the new_compiler() function to point to our own. Luckily, our copy of
2688N/A# new_compiler() gets to be very simple, since we always know what we want to
2688N/A# return.
2688N/Aclass MyUnixCCompiler(UnixCCompiler):
2688N/A
2688N/A def link(self, *args, **kwargs):
2688N/A
3143N/A output_filename = args[2]
2688N/A output_dir = kwargs.get('output_dir')
2688N/A cwd = os.getcwd()
2688N/A
2688N/A assert(not output_dir)
2688N/A output_dir = os.path.join(cwd, os.path.dirname(output_filename))
2688N/A output_filename = os.path.basename(output_filename)
3143N/A nargs = args[:2] + (output_filename,) + args[3:]
3136N/A if not os.path.exists(output_dir):
2688N/A os.mkdir(output_dir, 0755)
2688N/A os.chdir(output_dir)
2688N/A
2688N/A UnixCCompiler.link(self, *nargs, **kwargs)
2688N/A
2688N/A os.chdir(cwd)
2688N/A
2688N/Adistutils.ccompiler.compiler_class['myunix'] = (
2688N/A 'unixccompiler', 'MyUnixCCompiler',
2688N/A 'standard Unix-style compiler with a link stage modified for Solaris'
2688N/A)
3143N/A
2688N/Adef my_new_compiler(plat=None, compiler=None, verbose=0, dry_run=0, force=0):
2688N/A return MyUnixCCompiler(None, dry_run, force)
2688N/A
2688N/Aif osname == 'sunos':
2688N/A distutils.ccompiler.new_compiler = my_new_compiler
2688N/A
2535N/Aclass build_ext_func(_build_ext):
2535N/A
2535N/A def initialize_options(self):
2535N/A _build_ext.initialize_options(self)
2535N/A self.build64 = False
2535N/A
2535N/A if osname == 'sunos':
2535N/A self.compiler = 'myunix'
2535N/A
3143N/A def build_extension(self, ext):
2535N/A # Build 32-bit
2535N/A _build_ext.build_extension(self, ext)
2535N/A if not ext.build_64:
2535N/A return
2535N/A
2535N/A # Set up for 64-bit
2535N/A old_build_temp = self.build_temp
2535N/A d, f = os.path.split(self.build_temp)
2535N/A
2535N/A # store our 64-bit extensions elsewhere
2535N/A self.build_temp = d + "/temp64.%s" % \
2535N/A os.path.basename(self.build_temp).replace("temp.", "")
2535N/A ext.extra_compile_args += ["-m64"]
2535N/A ext.extra_link_args += ["-m64"]
2535N/A self.build64 = True
2535N/A
2535N/A # Build 64-bit
2535N/A _build_ext.build_extension(self, ext)
3194N/A
3234N/A # Reset to 32-bit
2535N/A self.build_temp = old_build_temp
2535N/A ext.extra_compile_args.remove("-m64")
2535N/A ext.extra_link_args.remove("-m64")
3194N/A self.build64 = False
2535N/A
2535N/A def get_ext_fullpath(self, ext_name):
2535N/A path = _build_ext.get_ext_fullpath(self, ext_name)
2535N/A if not self.build64:
2535N/A return path
2535N/A
2535N/A dpath, fpath = os.path.split(path)
2535N/A return os.path.join(dpath, "64", fpath)
2535N/A
849N/A
290N/Aclass build_py_func(_build_py):
2535N/A
2535N/A def __init__(self, dist):
430N/A ret = _build_py.__init__(self, dist)
395N/A
395N/A self.copied = []
290N/A
383N/A # Gather the timestamps of the .py files in the gate, so we can
383N/A # force the mtimes of the built and delivered copies to be
395N/A # consistent across builds, causing their corresponding .pyc
383N/A # files to be unchanged unless the .py file content changed.
383N/A
3143N/A self.timestamps = {}
3143N/A
383N/A p = subprocess.Popen(
849N/A [sys.executable, os.path.join(pwd, "pydates")],
849N/A stdout=subprocess.PIPE)
849N/A
849N/A for line in p.stdout:
849N/A stamp, path = line.split()
849N/A stamp = float(stamp)
849N/A self.timestamps[path] = stamp
3339N/A
3339N/A if p.wait() != 0:
3171N/A print >> sys.stderr, "ERROR: unable to gather .py " \
2242N/A "timestamps"
2242N/A sys.exit(1)
3234N/A
2242N/A return ret
2242N/A
2242N/A # override the build_module method to do VERSION substitution on
2242N/A # pkg/__init__.py
2242N/A def build_module (self, module, module_file, package):
3158N/A
3158N/A if module == "__init__" and package == "pkg":
2242N/A versionre = '(?m)^VERSION[^"]*"([^"]*)"'
2242N/A # Grab the previously-built version out of the build
3412N/A # tree.
3412N/A try:
849N/A ocontent = \
2508N/A file(self.get_module_outfile(self.build_lib,
2508N/A [package], module)).read()
2508N/A ov = re.search(versionre, ocontent).group(1)
2508N/A except IOError:
2508N/A ov = None
2508N/A v = get_hg_version()
2508N/A vstr = 'VERSION = "%s"' % v
2508N/A # If the versions haven't changed, there's no need to
2508N/A # recompile.
2508N/A if v == ov:
2508N/A return
2508N/A
2508N/A mcontent = file(module_file).read()
2508N/A mcontent = re.sub(versionre, vstr, mcontent)
2508N/A tmpfd, tmp_file = tempfile.mkstemp()
2508N/A os.write(tmpfd, mcontent)
2508N/A os.close(tmpfd)
2508N/A print "doing version substitution: ", v
2508N/A rv = _build_py.build_module(self, module, tmp_file, package)
2508N/A os.unlink(tmp_file)
2508N/A return rv
2508N/A
2508N/A # Will raise a DistutilsError on failure.
2508N/A syntax_check(module_file)
2508N/A
2508N/A return _build_py.build_module(self, module, module_file, package)
2508N/A
2508N/A def copy_file(self, infile, outfile, preserve_mode=1, preserve_times=1,
2677N/A link=None, level=1):
3194N/A
2508N/A # If the timestamp on the source file (coming from mercurial if
2508N/A # unchanged, or from the filesystem if changed) doesn't match
2508N/A # the filesystem timestamp on the destination, then force the
2508N/A # copy to make sure the right data is in place.
2508N/A
2508N/A try:
2508N/A dst_mtime = os.stat(outfile).st_mtime
2508N/A except OSError, e:
2508N/A if e.errno != errno.ENOENT:
2508N/A raise
2508N/A dst_mtime = time.time()
2508N/A
2508N/A # The timestamp for __init__.py is the timestamp for the
2508N/A # workspace itself.
2508N/A if outfile.endswith("/pkg/__init__.py"):
2508N/A src_mtime = self.timestamps["."]
2508N/A else:
2508N/A src_mtime = self.timestamps.get(
2508N/A os.path.join("src", infile), self.timestamps["."])
2508N/A
2508N/A # Force a copy of the file if the source timestamp is different
2677N/A # from that of the destination, not just if it's newer. This
2677N/A # allows timestamps in the working directory to regress (for
2508N/A # instance, following the reversion of a change).
2508N/A if dst_mtime != src_mtime:
849N/A f = self.force
2677N/A self.force = True
2677N/A dst, copied = _build_py.copy_file(self, infile, outfile,
3339N/A preserve_mode, preserve_times, link, level)
2677N/A self.force = f
2698N/A else:
2698N/A dst, copied = outfile, 0
2677N/A
2677N/A # If we copied the file, then we need to go and readjust the
2677N/A # timestamp on the file to match what we have in our database.
2677N/A # Save the filename aside for our version of install_lib.
2677N/A if copied and dst.endswith(".py"):
2677N/A os.utime(dst, (src_mtime, src_mtime))
3339N/A self.copied.append(dst)
3339N/A
2677N/A return dst, copied
2677N/A
2677N/Aclass build_data_func(Command):
2677N/A description = "build data files whose source isn't in deliverable form"
2677N/A user_options = []
2677N/A
2677N/A # As a subclass of distutils.cmd.Command, these methods are required to
2677N/A # be implemented.
3339N/A def initialize_options(self):
2677N/A pass
2677N/A
2677N/A def finalize_options(self):
2677N/A pass
2677N/A
2677N/A def run(self):
2677N/A # Anything that gets created here should get deleted in
2677N/A # clean_func.run() below.
2677N/A i18n_check()
2677N/A
3339N/A for l in pkg_locales:
3339N/A msgfmt("po/%s.po" % l, "po/%s.mo" % l)
3339N/A
2677N/A # generate pkg.pot for next translation
2677N/A intltool_update_maintain()
383N/A intltool_update_pot()
2508N/A
2508N/Adef rm_f(filepath):
2508N/A """Remove a file without caring whether it exists."""
2508N/A
2561N/A try:
2561N/A os.unlink(filepath)
2508N/A except OSError, e:
2508N/A if e.errno != errno.ENOENT:
2508N/A raise
2508N/A
2508N/Aclass clean_func(_clean):
2508N/A def initialize_options(self):
2508N/A _clean.initialize_options(self)
2508N/A self.build_base = build_dir
3339N/A
2508N/A def run(self):
2508N/A _clean.run(self)
2508N/A
2508N/A rm_f("po/.intltool-merge-cache")
2508N/A
2508N/A for l in pkg_locales:
2508N/A rm_f("po/%s.mo" % l)
2508N/A
3143N/A rm_f("po/pkg.pot")
3143N/A
2508N/A rm_f("po/i18n_errs.txt")
2508N/A
3261N/Aclass clobber_func(Command):
3261N/A user_options = []
3261N/A description = "Deletes any and all files created by setup"
3261N/A
3261N/A def initialize_options(self):
3261N/A pass
3261N/A def finalize_options(self):
3261N/A pass
3261N/A def run(self):
3261N/A # nuke everything
3261N/A print("deleting " + dist_dir)
3261N/A shutil.rmtree(dist_dir, True)
3261N/A print("deleting " + build_dir)
3261N/A shutil.rmtree(build_dir, True)
3261N/A print("deleting " + root_dir)
3261N/A shutil.rmtree(root_dir, True)
2508N/A print("deleting " + pkgs_dir)
2508N/A shutil.rmtree(pkgs_dir, True)
2535N/A print("deleting " + extern_dir)
2535N/A shutil.rmtree(extern_dir, True)
383N/A
849N/Aclass test_func(Command):
383N/A # NOTE: these options need to be in sync with tests/run.py and the
422N/A # list of options stored in initialize_options below. The first entry
422N/A # in each tuple must be the exact name of a member variable.
422N/A user_options = [
422N/A ("archivedir=", 'a', "archive failed tests <dir>"),
422N/A ("baselinefile=", 'b', "baseline file <file>"),
3234N/A ("coverage", "c", "collect code coverage data"),
422N/A ("genbaseline", 'g', "generate test baseline"),
422N/A ("only=", "o", "only <regex>"),
3339N/A ("parseable", 'p', "parseable output"),
422N/A ("port=", "z", "lowest port to start a depot on"),
422N/A ("timing", "t", "timing file <file>"),
3158N/A ("verbosemode", 'v', "run tests in verbose mode"),
422N/A ("stoponerr", 'x', "stop when a baseline mismatch occurs"),
422N/A ("debugoutput", 'd', "emit debugging output"),
422N/A ("showonexpectedfail", 'f',
422N/A "show all failure info, even for expected fails"),
422N/A ("startattest=", 's', "start at indicated test"),
3339N/A ("jobs=", 'j', "number of parallel processes to use"),
3339N/A ("quiet", "q", "use the dots as the output format"),
3339N/A ]
3339N/A description = "Runs unit and functional tests"
3339N/A
3339N/A def initialize_options(self):
3143N/A self.only = ""
3339N/A self.baselinefile = ""
383N/A self.verbosemode = 0
383N/A self.parseable = 0
422N/A self.genbaseline = 0
849N/A self.timing = 0
849N/A self.coverage = 0
849N/A self.stoponerr = 0
3339N/A self.debugoutput = 0
383N/A self.showonexpectedfail = 0
2508N/A self.startattest = ""
2508N/A self.archivedir = ""
2508N/A self.port = 12001
2508N/A self.jobs = 1
2508N/A self.quiet = False
2508N/A
2508N/A def finalize_options(self):
2508N/A pass
2508N/A
2508N/A def run(self):
3171N/A
2508N/A os.putenv('PYEXE', sys.executable)
2508N/A os.chdir(os.path.join(pwd, "tests"))
2508N/A
2508N/A # Reconstruct the cmdline and send that to run.py
2508N/A cmd = [sys.executable, "run.py"]
2508N/A args = ""
2508N/A if "test" in sys.argv:
3339N/A args = sys.argv[sys.argv.index("test")+1:]
2508N/A cmd.extend(args)
2535N/A subprocess.call(cmd)
3339N/A
2508N/Aclass dist_func(_bdist):
2561N/A def initialize_options(self):
2561N/A _bdist.initialize_options(self)
2561N/A self.dist_dir = dist_dir
2561N/A
2508N/Aclass Extension(distutils.core.Extension):
2508N/A # This class wraps the distutils Extension class, allowing us to set
2508N/A # build_64 in the object constructor instead of being forced to add it
2508N/A # after the object has been created.
2508N/A def __init__(self, name, sources, build_64=False, **kwargs):
2508N/A distutils.core.Extension.__init__(self, name, sources, **kwargs)
2508N/A self.build_64 = build_64
2508N/A
2508N/A# These are set to real values based on the platform, down below
2508N/Acompile_args = None
2508N/Aif osname in ("sunos", "linux", "darwin"):
2561N/A compile_args = [ "-O3" ]
2508N/Aif osname == "sunos":
2508N/A link_args = [ "-zstrip-class=nonalloc" ]
2561N/Aelse:
2508N/A link_args = []
2508N/A# We don't support 64-bit yet, but 64-bit _actions.so, _common.so, and
2508N/A# _varcet.so are needed for a system repository mod_wsgi application,
3139N/A# sysrepo_p5p.py.
3139N/Aext_modules = [
3139N/A Extension(
3139N/A 'actions._actions',
3139N/A _actions_srcs,
3139N/A include_dirs = include_dirs,
3139N/A extra_compile_args = compile_args,
3139N/A extra_link_args = link_args,
3139N/A build_64 = True
3139N/A ),
3139N/A Extension(
3139N/A 'actions._common',
3139N/A _actcomm_srcs,
3139N/A include_dirs = include_dirs,
3139N/A extra_compile_args = compile_args,
3139N/A extra_link_args = link_args,
3139N/A build_64 = True
3139N/A ),
3139N/A Extension(
3139N/A '_varcet',
3139N/A _varcet_srcs,
3139N/A include_dirs = include_dirs,
3139N/A extra_compile_args = compile_args,
3139N/A extra_link_args = link_args,
3139N/A build_64 = True
3139N/A ),
3139N/A Extension(
3139N/A 'solver',
3139N/A solver_srcs,
3139N/A include_dirs = include_dirs + ["."],
3139N/A extra_compile_args = compile_args,
3139N/A extra_link_args = link_args + solver_link_args,
3139N/A define_macros = [('_FILE_OFFSET_BITS', '64')]
3139N/A ),
3139N/A ]
3139N/Aelf_libraries = None
3143N/Asysattr_libraries = None
3139N/Adata_files = web_files
3139N/Acmdclasses = {
2535N/A 'install': install_func,
2535N/A 'install_data': install_data_func,
2535N/A 'install_lib': install_lib_func,
2535N/A 'build': build_func,
2535N/A 'build_data': build_data_func,
2535N/A 'build_ext': build_ext_func,
2535N/A 'build_py': build_py_func,
2535N/A 'bdist': dist_func,
2535N/A 'lint': lint_func,
2535N/A 'clint': clint_func,
2535N/A 'pylint': pylint_func,
2535N/A 'pylint_quiet': pylint_func_quiet,
2535N/A 'clean': clean_func,
2535N/A 'clobber': clobber_func,
2535N/A 'test': test_func,
2826N/A 'installfile': installfile,
2688N/A }
2535N/A
3158N/A# all builds of IPS should have manpages
2535N/Adata_files += [
2688N/A (man1_dir, man1_files),
2688N/A (man1m_dir, man1m_files),
2688N/A (man5_dir, man5_files),
2688N/A (man1_ja_JP_dir, man1_ja_files),
3356N/A (man1m_ja_JP_dir, man1m_ja_files),
3356N/A (man5_ja_JP_dir, man5_ja_files),
3356N/A (man1_zh_CN_dir, man1_zh_CN_files),
3139N/A (man1m_zh_CN_dir, man1m_zh_CN_files),
2535N/A (man5_zh_CN_dir, man5_zh_CN_files),
2535N/A (resource_dir, resource_files),
2535N/A ]
2535N/A# add transforms
2535N/Adata_files += [
3171N/A (transform_dir, transform_files)
2535N/A ]
2535N/Aif osname == 'sunos':
2535N/A # Solaris-specific extensions are added here
290N/A data_files += [
430N/A (smf_app_dir, smf_app_files),
395N/A (execattrd_dir, execattrd_files),
395N/A (authattrd_dir, authattrd_files),
290N/A (userattrd_dir, userattrd_files),
2535N/A (sysrepo_dir, sysrepo_files),
2535N/A (sysrepo_logs_dir, sysrepo_log_stubs),
2535N/A (sysrepo_cache_dir, {}),
2535N/A (depot_dir, depot_files),
2535N/A (depot_conf_dir, {}),
2535N/A (depot_logs_dir, depot_log_stubs),
3158N/A (depot_cache_dir, {}),
2535N/A (mirror_cache_dir, {}),
2688N/A (mirror_logs_dir, {}),
2688N/A ]
2826N/A # install localizable .xml and its .pot file to put into localizable file package
2688N/A data_files += [
3139N/A (os.path.join(locale_dir, locale, 'LC_MESSAGES'),
3139N/A [('po/%s.mo' % locale, 'pkg.mo')])
290N/A for locale in pkg_locales
290N/A ]
290N/A # install English .pot file to put into localizable file package
290N/A data_files += [
290N/A (os.path.join(locale_dir, '__LOCALE__', 'LC_MESSAGES'),
290N/A [('po/pkg.pot', 'pkg.pot')])
290N/A ]
290N/A
290N/Aif osname == 'sunos' or osname == "linux":
290N/A # Unix platforms which the elf extension has been ported to
395N/A # are specified here, so they are built automatically
290N/A elf_libraries = ['elf']
395N/A ext_modules += [
290N/A Extension(
395N/A 'elf',
290N/A elf_srcs,
534N/A include_dirs = include_dirs,
534N/A libraries = elf_libraries,
1099N/A extra_compile_args = compile_args,
1099N/A extra_link_args = link_args,
3261N/A ),
3261N/A ]
3261N/A
3261N/A # Solaris has built-in md library and Solaris-specific arch extension
3261N/A # All others use OpenSSL and cross-platform arch module
3261N/A if osname == 'sunos':
3261N/A elf_libraries += [ 'md' ]
3261N/A sysattr_libraries = [ 'nvpair' ]
290N/A ext_modules += [
290N/A Extension(
1101N/A 'arch',
1101N/A arch_srcs,
1101N/A include_dirs = include_dirs,
1513N/A extra_compile_args = compile_args,
1715N/A extra_link_args = link_args,
1513N/A define_macros = [('_FILE_OFFSET_BITS', '64')]
1513N/A ),
448N/A Extension(
1513N/A 'pspawn',
448N/A pspawn_srcs,
2272N/A include_dirs = include_dirs,
1101N/A extra_compile_args = compile_args,
1513N/A extra_link_args = link_args,
1715N/A define_macros = [('_FILE_OFFSET_BITS', '64')]
1715N/A ),
1716N/A Extension(
1715N/A 'syscallat',
1715N/A syscallat_srcs,
2499N/A include_dirs = include_dirs,
2499N/A extra_compile_args = compile_args,
3049N/A extra_link_args = link_args,
1513N/A define_macros = [('_FILE_OFFSET_BITS', '64')]
290N/A ),
290N/A Extension(
290N/A 'sysattr',
448N/A sysattr_srcs,
448N/A include_dirs = include_dirs,
430N/A libraries = sysattr_libraries,
448N/A extra_compile_args = compile_args,
430N/A extra_link_args = link_args,
1101N/A define_macros = [('_FILE_OFFSET_BITS', '64')],
1513N/A build_64 = True
1715N/A ),
1715N/A ]
1716N/A else:
1715N/A elf_libraries += [ 'ssl' ]
1715N/A
2272N/Asetup(cmdclass = cmdclasses,
2499N/A name = 'pkg',
2499N/A version = '0.1',
3049N/A package_dir = {'pkg':'modules'},
1101N/A packages = packages,
290N/A data_files = data_files,
290N/A ext_package = 'pkg',
1101N/A ext_modules = ext_modules,
290N/A )
1101N/A