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