setup.py revision 2023
1516N/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#
1902N/A# Copyright (c) 2008, 2010 Oracle and/or its affiliates. All rights reserved.
395N/A#
290N/A
883N/Aimport errno
454N/Aimport fnmatch
290N/Aimport os
448N/Aimport platform
290N/Aimport stat
290N/Aimport sys
290N/Aimport shutil
383N/Aimport re
290N/Aimport subprocess
395N/Aimport tarfile
290N/Aimport tempfile
395N/Aimport urllib
849N/Aimport py_compile
1516N/Aimport hashlib
290N/A
849N/Afrom distutils.errors import DistutilsError
290N/Afrom distutils.core import setup, Extension
290N/Afrom distutils.cmd import Command
290N/Afrom distutils.command.install import install as _install
290N/Afrom distutils.command.build import build as _build
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
290N/A
290N/Afrom distutils.sysconfig import get_python_inc
290N/Aimport distutils.file_util as file_util
290N/Aimport distutils.dir_util as dir_util
290N/Aimport distutils.util as util
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
465N/A# 3rd party software required for the build
465N/ACP = 'CherryPy'
465N/ACPIDIR = 'cherrypy'
1516N/ACPVER = '3.1.2'
465N/ACPARC = '%s-%s.tar.gz' % (CP, CPVER)
465N/ACPDIR = '%s-%s' % (CP, CPVER)
465N/ACPURL = 'http://download.cherrypy.org/cherrypy/%s/%s' % (CPVER, CPARC)
1516N/ACPHASH = 'a94aedfd0e675858dbcc32dd250c23d285ee9b88'
465N/A
465N/APO = 'pyOpenSSL'
465N/APOIDIR = 'OpenSSL'
465N/APOVER = '0.7'
465N/APOARC = '%s-%s.tar.gz' % (PO, POVER)
465N/APODIR = '%s-%s' % (PO, POVER)
465N/APOURL = 'http://downloads.sourceforge.net/pyopenssl/%s' % (POARC)
1099N/APOHASH = 'bd072fef8eb36241852d25a9161282a051f0a63e'
465N/A
1513N/ACOV = 'coveragepy'
1513N/ACOVIDIR = 'coverage'
1514N/ACOVVER = 'coverage-3.2b2'
1513N/ACOVARC = '%s-%s.tar.bz2' % (COV, COVVER)
1513N/ACOVDIR = '%s' % COV
1513N/ACOVURL = 'http://bitbucket.org/ned/%s/get/%s.tar.bz2' % (COV, COVVER)
1099N/A# No hash, since we always fetch the latest
1513N/ACOVHASH = None
708N/A
1391N/ALDTP = 'ldtp'
1391N/ALDTPIDIR = 'ldtp'
1391N/ALDTPVER = '1.7.1'
1391N/ALDTPMINORVER = '1.7.x'
1391N/ALDTPMAJORVER = '1.x'
1391N/ALDTPARC = '%s-%s.tar.gz' % (LDTP, LDTPVER)
1391N/ALDTPDIR = '%s-%s' % (LDTP, LDTPVER)
1391N/ALDTPURL = 'http://download.freedesktop.org/ldtp/%s/%s/%s' % \
1391N/A (LDTPMAJORVER, LDTPMINORVER, LDTPARC)
1391N/ALDTPHASH = 'd31213d2b1449a0dadcace723b9ff7041169f7ce'
1391N/A
742N/AMAKO = 'Mako'
742N/AMAKOIDIR = 'mako'
742N/AMAKOVER = '0.2.2'
742N/AMAKOARC = '%s-%s.tar.gz' % (MAKO, MAKOVER)
742N/AMAKODIR = '%s-%s' % (MAKO, MAKOVER)
742N/AMAKOURL = 'http://www.makotemplates.org/downloads/%s' % (MAKOARC)
1099N/AMAKOHASH = '85c04ab3a6a26a1cab47067449712d15a8b29790'
742N/A
941N/APLY = 'ply'
941N/APLYIDIR = 'ply'
941N/APLYVER = '3.1'
941N/APLYARC = '%s-%s.tar.gz' % (PLY, PLYVER)
941N/APLYDIR = '%s-%s' % (PLY, PLYVER)
941N/APLYURL = 'http://www.dabeaz.com/ply/%s' % (PLYARC)
1099N/APLYHASH = '38efe9e03bc39d40ee73fa566eb9c1975f1a8003'
941N/A
2023N/APBJ = 'pybonjour'
2023N/APBJIDIR = 'pybonjour'
2023N/APBJVER = '1.1.1'
2023N/APBJARC = '%s-%s.tar.gz' % (PBJ, PBJVER)
2023N/APBJDIR = '%s-%s' % (PBJ, PBJVER)
2023N/APBJURL = 'http://pybonjour.googlecode.com/files/%s' % (PBJARC)
2023N/APBJHASH = '92cabd14e04c5f62ce067c47c2057ee3d424d29b'
2023N/A
1191N/APC = 'pycurl'
1513N/APCIDIR = 'curl'
1191N/APCVER = '7.19.0'
1191N/APCARC = '%s-%s.tar.gz' % (PC, PCVER)
1191N/APCDIR = '%s-%s' % (PC, PCVER)
1191N/APCURL = 'http://pycurl.sourceforge.net/download/%s' % PCARC
1191N/APCHASH = '3fb59eca1461331bb9e9e8d6fe3b23eda961a416'
1660N/APCENVIRON = {}
1660N/Aif osname in ("sunos", "linux", "darwin"):
1660N/A PCENVIRON = {'CFLAGS': '-O3'}
290N/A
448N/Apwd = os.path.normpath(sys.path[0])
448N/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#
534N/Asys.stdout = os.fdopen(sys.stdout.fileno(), "w", 0)
534N/Asys.stderr = os.fdopen(sys.stderr.fileno(), "w", 0)
534N/A
290N/Adist_dir = os.path.normpath(os.path.join(pwd, os.pardir, "proto", "dist_" + arch))
290N/Abuild_dir = os.path.normpath(os.path.join(pwd, os.pardir, "proto", "build_" + arch))
954N/Aif "ROOT" in os.environ and os.environ["ROOT"] != "":
954N/A root_dir = os.environ["ROOT"]
954N/Aelse:
954N/A root_dir = os.path.normpath(os.path.join(pwd, os.pardir, "proto", "root_" + arch))
534N/Apkgs_dir = os.path.normpath(os.path.join(pwd, os.pardir, "packages", arch))
1099N/Aextern_dir = os.path.normpath(os.path.join(pwd, "extern"))
290N/A
1516N/Apy_install_dir = 'usr/lib/python2.6/vendor-packages'
290N/A
290N/Ascripts_dir = 'usr/bin'
290N/Alib_dir = 'usr/lib'
661N/Asvc_method_dir = 'lib/svc/method'
290N/A
290N/Aman1_dir = 'usr/share/man/cat1'
290N/Aman1m_dir = 'usr/share/man/cat1m'
395N/Aman5_dir = 'usr/share/man/cat5'
290N/Aresource_dir = 'usr/share/lib/pkg'
290N/Asmf_dir = 'var/svc/manifest/application'
290N/Azones_dir = 'etc/zones'
1483N/Aetcbrand_dir = 'etc/brand/ipkg'
290N/Abrand_dir = 'usr/lib/brand/ipkg'
1498N/Aexecattrd_dir = 'etc/security/exec_attr.d'
1498N/Aauthattrd_dir = 'etc/security/auth_attr.d'
290N/A
1674N/A# A list of source, destination tuples of modules which should be hardlinked
1674N/A# together if the os supports it and otherwise copied.
1674N/Ahardlink_modules = [
1674N/A ("%s/pkg/flavor/depthlimitedmf24" % py_install_dir,
1674N/A "%s/pkg/flavor/depthlimitedmf25" % py_install_dir)
1674N/A]
1674N/A
395N/Ascripts_sunos = {
430N/A scripts_dir: [
395N/A ['client.py', 'pkg'],
1544N/A ['pkgdep.py', 'pkgdepend'],
1968N/A ['pkgrepo.py', 'pkgrepo'],
1557N/A ['util/publish/pkgdiff.py', 'pkgdiff'],
1903N/A ['util/publish/pkgfmt.py', 'pkgfmt'],
1506N/A ['util/publish/pkgmogrify.py', 'pkgmogrify'],
395N/A ['publish.py', 'pkgsend'],
395N/A ['pull.py', 'pkgrecv'],
424N/A ['packagemanager.py', 'packagemanager'],
1024N/A ['updatemanager.py', 'pm-updatemanager'],
395N/A ],
395N/A lib_dir: [
395N/A ['depot.py', 'pkg.depotd'],
578N/A ['updatemanagernotifier.py', 'updatemanagernotifier'],
1228N/A ['checkforupdates.py', 'pm-checkforupdates'],
1172N/A ['launch.py', 'pm-launch'],
395N/A ],
661N/A svc_method_dir: [
1099N/A ['svc/svc-pkg-depot', 'svc-pkg-depot'],
1902N/A ['svc/svc-pkg-mdns', 'svc-pkg-mdns'],
661N/A ],
395N/A }
849N/A
290N/Ascripts_windows = {
395N/A scripts_dir: [
395N/A ['client.py', 'client.py'],
1968N/A ['pkgrepo.py', 'pkgrepo.py'],
395N/A ['publish.py', 'publish.py'],
395N/A ['pull.py', 'pull.py'],
395N/A ['scripts/pkg.bat', 'pkg.bat'],
395N/A ['scripts/pkgsend.bat', 'pkgsend.bat'],
395N/A ['scripts/pkgrecv.bat', 'pkgrecv.bat'],
395N/A ],
395N/A lib_dir: [
395N/A ['depot.py', 'depot.py'],
395N/A ['scripts/pkg.depotd.bat', 'pkg.depotd.bat'],
395N/A ],
395N/A }
290N/A
290N/Ascripts_other_unix = {
395N/A scripts_dir: [
395N/A ['client.py', 'client.py'],
1231N/A ['pkgdep.py', 'pkgdep'],
1557N/A ['util/publish/pkgdiff.py', 'pkgdiff'],
1903N/A ['util/publish/pkgfmt.py', 'pkgfmt'],
1557N/A ['util/publish/pkgmogrify.py', 'pkgmogrify'],
395N/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 }
290N/A
290N/A# indexed by 'osname'
430N/Ascripts = {
395N/A "sunos": scripts_sunos,
395N/A "linux": scripts_other_unix,
395N/A "windows": scripts_windows,
395N/A "darwin": scripts_other_unix,
1302N/A "aix" : scripts_other_unix,
395N/A "unknown": scripts_sunos,
395N/A }
290N/A
395N/Aman1_files = [
1024N/A 'man/packagemanager.1',
413N/A 'man/pkg.1',
1544N/A 'man/pkgdepend.1',
1557N/A 'man/pkgdiff.1',
1903N/A 'man/pkgfmt.1',
1506N/A 'man/pkgmogrify.1',
413N/A 'man/pkgsend.1',
413N/A 'man/pkgrecv.1',
1978N/A 'man/pkgrepo.1',
1024N/A 'man/pm-updatemanager.1',
395N/A ]
395N/Aman1m_files = [
413N/A 'man/pkg.depotd.1m'
395N/A ]
395N/Aman5_files = [
413N/A 'man/pkg.5'
395N/A ]
395N/Apackages = [
395N/A 'pkg',
395N/A 'pkg.actions',
395N/A 'pkg.bundle',
395N/A 'pkg.client',
1191N/A 'pkg.client.transport',
1452N/A 'pkg.file_layout',
1231N/A 'pkg.flavor',
395N/A 'pkg.portable',
395N/A 'pkg.publish',
424N/A 'pkg.server'
395N/A ]
742N/A
742N/Aweb_files = []
742N/Afor entry in os.walk("web"):
742N/A web_dir, dirs, files = entry
742N/A if not files:
742N/A continue
742N/A web_files.append((os.path.join(resource_dir, web_dir), [
742N/A os.path.join(web_dir, f) for f in files
742N/A if f != "Makefile"
742N/A ]))
742N/A
395N/Azones_files = [
395N/A 'brand/SUNWipkg.xml',
395N/A ]
395N/Abrand_files = [
395N/A 'brand/pkgcreatezone',
954N/A 'brand/attach',
954N/A 'brand/clone',
954N/A 'brand/detach',
954N/A 'brand/prestate',
954N/A 'brand/poststate',
954N/A 'brand/uninstall',
954N/A 'brand/common.ksh',
395N/A ]
1483N/Aetcbrand_files = [
1483N/A 'brand/pkgrm.conf',
1483N/A 'brand/smf_disable.conf',
1483N/A ]
395N/Asmf_files = [
1902N/A 'svc/pkg-mdns.xml',
1099N/A 'svc/pkg-server.xml',
1099N/A 'svc/pkg-update.xml',
395N/A ]
1498N/Aexecattrd_files = ['util/misc/exec_attr.d/SUNWipkg']
1498N/Aauthattrd_files = ['util/misc/auth_attr.d/SUNWipkg']
691N/Apspawn_srcs = [
691N/A 'modules/pspawn.c'
691N/A ]
395N/Aelf_srcs = [
395N/A 'modules/elf.c',
395N/A 'modules/elfextract.c',
395N/A 'modules/liblist.c',
395N/A ]
290N/Aarch_srcs = [
395N/A 'modules/arch.c'
395N/A ]
591N/A_actions_srcs = [
591N/A 'modules/actions/_actions.c'
591N/A ]
1505N/Asolver_srcs = [
1505N/A 'modules/solver/solver.c',
1505N/A 'modules/solver/py_solver.c'
1505N/A ]
1632N/Asolver_link_args = ["-lm", "-lc"]
1632N/Aif osname == 'sunos':
1632N/A solver_link_args = ["-ztext"] + solver_link_args
1632N/A
395N/Ainclude_dirs = [ 'modules' ]
395N/Alint_flags = [ '-u', '-axms', '-erroff=E_NAME_DEF_NOT_USED2' ]
290N/A
290N/A# Runs lint on the extension module source code
290N/Aclass lint_func(Command):
290N/A description = "Runs various lint tools over IPS extension source code"
290N/A user_options = []
290N/A
290N/A def initialize_options(self):
290N/A pass
290N/A
290N/A def finalize_options(self):
290N/A pass
290N/A
290N/A # Make string shell-friendly
290N/A @staticmethod
395N/A def escape(astring):
395N/A return astring.replace(' ', '\\ ')
290N/A
290N/A def run(self):
290N/A # assumes lint is on the $PATH
290N/A if osname == 'sunos' or osname == "linux":
290N/A archcmd = ['lint'] + lint_flags + ['-D_FILE_OFFSET_BITS=64'] + \
395N/A ["%s%s" % ("-I", k) for k in include_dirs] + \
395N/A ['-I' + self.escape(get_python_inc())] + \
395N/A arch_srcs
290N/A elfcmd = ['lint'] + lint_flags + \
395N/A ["%s%s" % ("-I", k) for k in include_dirs] + \
395N/A ['-I' + self.escape(get_python_inc())] + \
395N/A ["%s%s" % ("-l", k) for k in elf_libraries] + \
395N/A elf_srcs
591N/A _actionscmd = ['lint'] + lint_flags + \
591N/A ["%s%s" % ("-I", k) for k in include_dirs] + \
591N/A ['-I' + self.escape(get_python_inc())] + \
591N/A _actions_srcs
691N/A pspawncmd = ['lint'] + lint_flags + ['-D_FILE_OFFSET_BITS=64'] + \
691N/A ["%s%s" % ("-I", k) for k in include_dirs] + \
691N/A ['-I' + self.escape(get_python_inc())] + \
691N/A pspawn_srcs
290N/A
290N/A print(" ".join(archcmd))
290N/A os.system(" ".join(archcmd))
290N/A print(" ".join(elfcmd))
290N/A os.system(" ".join(elfcmd))
591N/A print(" ".join(_actionscmd))
591N/A os.system(" ".join(_actionscmd))
691N/A print(" ".join(pspawncmd))
691N/A os.system(" ".join(pspawncmd))
290N/A
395N/A proto = os.path.join(root_dir, py_install_dir)
395N/A sys.path.insert(0, proto)
290N/A
395N/A # Insert tests directory onto sys.path so any custom checkers
395N/A # can be found.
395N/A sys.path.insert(0, os.path.join(pwd, 'tests'))
395N/A print(sys.path)
290N/A
290N/A # assumes pylint is accessible on the sys.path
290N/A from pylint import lint
395N/A scriptlist = [ 'setup.py' ]
395N/A for d, m in scripts_sunos.items():
395N/A for a in m:
395N/A # specify the filenames of the scripts, in addition
395N/A # to the package names themselves
395N/A scriptlist.append(os.path.join(root_dir, d, a[1]))
290N/A
290N/A # For some reason, the load-plugins option, when used in the
290N/A # rcfile, does not work, so we put it here instead, to load
290N/A # our custom checkers.
290N/A lint.Run(['--load-plugins=multiplatform', '--rcfile',
430N/A os.path.join(pwd, 'tests', 'pylintrc')] +
290N/A scriptlist + packages)
290N/A
395N/Aclass install_func(_install):
290N/A def initialize_options(self):
395N/A _install.initialize_options(self)
506N/A
506N/A # PRIVATE_BUILD set in the environment tells us to put the build
506N/A # directory into the .pyc files, rather than the final
506N/A # installation directory.
506N/A private_build = os.getenv("PRIVATE_BUILD", None)
506N/A
506N/A if private_build is None:
506N/A self.install_lib = py_install_dir
834N/A self.install_data = os.path.sep
506N/A self.root = root_dir
506N/A else:
506N/A self.install_lib = os.path.join(root_dir, py_install_dir)
513N/A self.install_data = root_dir
506N/A
506N/A # This is used when installing scripts, below, but it isn't a
506N/A # standard distutils variable.
506N/A self.root_dir = root_dir
290N/A
290N/A def run(self):
395N/A """
395N/A At the end of the install function, we need to rename some files
849N/A because distutils provides no way to rename files as they are
849N/A placed in their install locations.
883N/A Also, make sure that cherrypy and other external dependencies
883N/A are installed.
395N/A """
413N/A for f in man1_files + man1m_files + man5_files:
413N/A file_util.copy_file(f + ".txt", f, update=1)
413N/A
395N/A _install.run(self)
290N/A
1674N/A for o_src, o_dest in hardlink_modules:
1674N/A for e in [".py", ".pyc"]:
1674N/A src = util.change_root(self.root_dir, o_src + e)
1674N/A dest = util.change_root(
1674N/A self.root_dir, o_dest + e)
1674N/A if ostype == "posix":
1674N/A if os.path.exists(dest) and \
1674N/A os.stat(src)[stat.ST_INO] != \
1674N/A os.stat(dest)[stat.ST_INO]:
1674N/A os.remove(dest)
1674N/A file_util.copy_file(src, dest,
1674N/A link="hard", update=1)
1674N/A else:
1674N/A file_util.copy_file(src, dest, update=1)
1674N/A
395N/A for d, files in scripts[osname].iteritems():
395N/A for (srcname, dstname) in files:
506N/A dst_dir = util.change_root(self.root_dir, d)
506N/A dst_path = util.change_root(self.root_dir,
395N/A os.path.join(d, dstname))
395N/A dir_util.mkpath(dst_dir, verbose = True)
395N/A file_util.copy_file(srcname, dst_path, update = True)
395N/A # make scripts executable
430N/A os.chmod(dst_path,
849N/A os.stat(dst_path).st_mode
834N/A | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)
290N/A
1391N/A prep_sw(CP, CPARC, CPDIR, CPURL, CPHASH)
1391N/A install_sw(CP, CPDIR, CPIDIR)
1401N/A if osname == "sunos" and platform.uname()[2] == "5.11":
1391N/A prep_sw(LDTP, LDTPARC, LDTPDIR, LDTPURL,
1391N/A LDTPHASH)
1391N/A saveenv = os.environ.copy()
1391N/A os.environ["LDFLAGS"] = os.environ.get("LDFLAGS", "") + \
1391N/A " -lsocket -lnsl"
1391N/A install_ldtp(LDTP, LDTPDIR, LDTPIDIR)
1391N/A os.environ = saveenv
1391N/A
836N/A if "BUILD_PYOPENSSL" in os.environ and \
836N/A os.environ["BUILD_PYOPENSSL"] != "":
849N/A #
849N/A # Include /usr/sfw/lib in the build environment
849N/A # to ensure that this builds and runs on older
849N/A # nevada builds, before openssl moved out of /usr/sfw.
849N/A #
849N/A saveenv = os.environ.copy()
849N/A if osname == "sunos":
849N/A os.environ["CFLAGS"] = "-I/usr/sfw/include " + \
849N/A os.environ.get("CFLAGS", "")
849N/A os.environ["LDFLAGS"] = \
849N/A "-L/usr/sfw/lib -R/usr/sfw/lib " + \
849N/A os.environ.get("LDFLAGS", "")
1513N/A prep_sw(PO, POARC, PODIR, POURL, POHASH)
1391N/A install_sw(PO, PODIR, POIDIR)
849N/A os.environ = saveenv
1513N/A prep_sw(MAKO, MAKOARC, MAKODIR, MAKOURL, MAKOHASH)
1391N/A install_sw(MAKO, MAKODIR, MAKOIDIR)
1513N/A prep_sw(PLY, PLYARC, PLYDIR, PLYURL, PLYHASH)
1391N/A install_sw(PLY, PLYDIR, PLYIDIR)
1391N/A prep_sw(PC, PCARC, PCDIR, PCURL, PCHASH)
1660N/A install_sw(PC, PCDIR, PCIDIR, extra_env=PCENVIRON)
1513N/A prep_sw(COV, COVARC, COVDIR, COVURL, COVHASH)
1513N/A install_sw(COV, COVDIR, COVIDIR)
2023N/A prep_sw(PBJ, PBJARC, PBJDIR, PBJURL, PBJHASH)
2023N/A install_sw(PBJ, PBJDIR, PBJIDIR)
290N/A
883N/A # Remove some bits that we're not going to package, but be sure
883N/A # not to complain if we try to remove them twice.
883N/A def onerror(func, path, exc_info):
883N/A if exc_info[1].errno != errno.ENOENT:
883N/A raise
883N/A
883N/A for dir in ("cherrypy/scaffold", "cherrypy/test",
883N/A "cherrypy/tutorial"):
883N/A shutil.rmtree(os.path.join(root_dir, py_install_dir, dir),
883N/A onerror=onerror)
883N/A try:
883N/A os.remove(os.path.join(root_dir, "usr/bin/mako-render"))
883N/A except EnvironmentError, e:
883N/A if e.errno != errno.ENOENT:
883N/A raise
883N/A
1099N/Adef hash_sw(swname, swarc, swhash):
1099N/A if swhash == None:
1099N/A return True
1099N/A
1099N/A print "checksumming %s" % swname
1516N/A hash = hashlib.sha1()
1265N/A f = open(swarc, "rb")
1099N/A while True:
1099N/A data = f.read(65536)
1099N/A if data == "":
1099N/A break
1099N/A hash.update(data)
1099N/A f.close()
1099N/A
1099N/A if hash.hexdigest() == swhash:
1099N/A return True
1099N/A else:
1208N/A print >> sys.stderr, "bad checksum! %s != %s" % \
1208N/A (swhash, hash.hexdigest())
1099N/A return False
1099N/A
1391N/Adef prep_sw(swname, swarc, swdir, swurl, swhash):
1099N/A swarc = os.path.join(extern_dir, swarc)
1099N/A swdir = os.path.join(extern_dir, swdir)
1099N/A if not os.path.exists(extern_dir):
1099N/A os.mkdir(extern_dir)
1099N/A
465N/A if not os.path.exists(swarc):
465N/A print "downloading %s" % swname
395N/A try:
465N/A fname, hdr = urllib.urlretrieve(swurl, swarc)
395N/A except IOError:
395N/A pass
465N/A if not os.path.exists(swarc) or \
465N/A (hdr.gettype() != "application/x-gzip" and
465N/A hdr.gettype() != "application/x-tar"):
1208N/A print >> sys.stderr, "Unable to retrieve %s.\n" \
1208N/A "Please retrieve the file " \
465N/A "and place it at: %s\n" % (swurl, swarc)
395N/A # remove a partial download or error message from proxy
465N/A remove_sw(swname)
395N/A sys.exit(1)
465N/A if not os.path.exists(swdir):
1099N/A if not hash_sw(swname, swarc, swhash):
1099N/A sys.exit(1)
1099N/A
465N/A print "unpacking %s" % swname
465N/A tar = tarfile.open(swarc)
395N/A # extractall doesn't exist until python 2.5
395N/A for m in tar.getmembers():
1099N/A tar.extract(m, extern_dir)
395N/A tar.close()
1191N/A
1191N/A # If there are patches, apply them now.
1191N/A patchdir = os.path.join("patch", swname)
1191N/A already_patched = os.path.join(swdir, ".patched")
1191N/A if os.path.exists(patchdir) and not os.path.exists(already_patched):
1191N/A patches = os.listdir(patchdir)
1191N/A for p in patches:
1191N/A patchpath = os.path.join(os.path.pardir,
1191N/A os.path.pardir, patchdir, p)
1191N/A print "Applying %s to %s" % (p, swname)
1265N/A args = ["patch", "-d", swdir, "-i", patchpath, "-p0"]
1265N/A if osname == "windows":
1265N/A args.append("--binary")
1208N/A ret = subprocess.Popen(args).wait()
1208N/A if ret != 0:
1208N/A print >> sys.stderr, \
1208N/A "patch failed and returned %d." % ret
1208N/A print >> sys.stderr, \
1208N/A "Command was: %s" % " ".join(args)
1208N/A sys.exit(1)
1191N/A file(already_patched, "w").close()
1191N/A
1391N/Adef install_ldtp(swname, swdir, swidir):
1391N/A swdir = os.path.join(extern_dir, swdir)
1391N/A swinst_file = os.path.join(root_dir, py_install_dir, swidir + ".py")
1391N/A if not os.path.exists(swinst_file):
1391N/A print "installing %s" % swname
1391N/A args_config = ['./configure',
1391N/A '--prefix=/usr',
1394N/A '--bindir=/usr/bin',
1394N/A 'PYTHONPATH=""',
1391N/A ]
1391N/A args_make_install = ['make', 'install',
1391N/A 'DESTDIR=%s' % root_dir
1391N/A ]
1391N/A run_cmd(args_config, swdir)
1391N/A run_cmd(args_make_install, swdir)
1391N/A
1660N/Adef install_sw(swname, swdir, swidir, extra_env=None):
1391N/A swdir = os.path.join(extern_dir, swdir)
465N/A swinst_dir = os.path.join(root_dir, py_install_dir, swidir)
1660N/A inst_env = os.environ.copy()
1660N/A if extra_env:
1660N/A inst_env.update(extra_env)
1660N/A
465N/A if not os.path.exists(swinst_dir):
465N/A print "installing %s" % swname
1516N/A args = ['python2.6', 'setup.py', 'install',
498N/A '--root=%s' % root_dir,
498N/A '--install-lib=%s' % py_install_dir,
849N/A '--install-data=%s' % py_install_dir]
1660N/A run_cmd(args, swdir, env=inst_env)
1391N/A
1660N/Adef run_cmd(args, swdir, env=None):
1660N/A if env is None:
1660N/A env = os.environ
1660N/A ret = subprocess.Popen(args, cwd=swdir, env=env).wait()
849N/A if ret != 0:
1208N/A print >> sys.stderr, \
1208N/A "install failed and returned %d." % ret
1208N/A print >> sys.stderr, \
1208N/A "Command was: %s" % " ".join(args)
849N/A sys.exit(1)
290N/A
465N/Adef remove_sw(swname):
465N/A print("deleting %s" % swname)
1099N/A for file in os.listdir(extern_dir):
465N/A if fnmatch.fnmatch(file, "%s*" % swname):
1099N/A fpath = os.path.join(extern_dir, file)
1099N/A if os.path.isfile(fpath):
1099N/A os.unlink(fpath)
454N/A else:
1099N/A shutil.rmtree(fpath, True)
849N/A
290N/Aclass build_func(_build):
430N/A def initialize_options(self):
395N/A _build.initialize_options(self)
395N/A self.build_base = build_dir
290N/A
383N/Adef get_hg_version():
383N/A try:
395N/A p = subprocess.Popen(['hg', 'id', '-i'], stdout = subprocess.PIPE)
383N/A return p.communicate()[0].strip()
383N/A except OSError:
384N/A print >> sys.stderr, "ERROR: unable to obtain mercurial version"
383N/A return "unknown"
849N/A
849N/Adef syntax_check(filename):
849N/A """ Run python's compiler over the file, and discard the results.
849N/A Arrange to generate an exception if the file does not compile.
849N/A This is needed because distutil's own use of pycompile (in the
849N/A distutils.utils module) is broken, and doesn't stop on error. """
849N/A try:
849N/A py_compile.compile(filename, os.devnull, doraise=True)
849N/A except py_compile.PyCompileError, e:
849N/A raise DistutilsError("%s: failed syntax check: %s" %
849N/A (filename, e))
849N/A
849N/A
383N/Aclass build_py_func(_build_py):
383N/A # override the build_module method to do VERSION substitution on pkg/__init__.py
383N/A def build_module (self, module, module_file, package):
849N/A
383N/A if module == "__init__" and package == "pkg":
422N/A versionre = '(?m)^VERSION[^"]*"([^"]*)"'
422N/A # Grab the previously-built version out of the build
422N/A # tree.
422N/A try:
422N/A ocontent = \
422N/A file(self.get_module_outfile(self.build_lib,
422N/A [package], module)).read()
422N/A ov = re.search(versionre, ocontent).group(1)
422N/A except IOError:
422N/A ov = None
422N/A v = get_hg_version()
422N/A vstr = 'VERSION = "%s"' % v
422N/A # If the versions haven't changed, there's no need to
422N/A # recompile.
422N/A if v == ov:
422N/A return
422N/A
383N/A mcontent = file(module_file).read()
422N/A mcontent = re.sub(versionre, vstr, mcontent)
383N/A tmpfd, tmp_file = tempfile.mkstemp()
383N/A os.write(tmpfd, mcontent)
383N/A os.close(tmpfd)
383N/A print "doing version substitution: ", v
383N/A rv = _build_py.build_module(self, module, tmp_file, package)
383N/A os.unlink(tmp_file)
383N/A return rv
422N/A
849N/A # Will raise a DistutilsError on failure.
849N/A syntax_check(module_file)
849N/A
383N/A return _build_py.build_module(self, module, module_file, package)
383N/A
290N/Aclass clean_func(_clean):
430N/A def initialize_options(self):
395N/A _clean.initialize_options(self)
395N/A self.build_base = build_dir
290N/A
290N/Aclass clobber_func(Command):
290N/A user_options = []
290N/A description = "Deletes any and all files created by setup"
290N/A
290N/A def initialize_options(self):
290N/A pass
290N/A def finalize_options(self):
290N/A pass
290N/A def run(self):
290N/A # nuke everything
395N/A print("deleting " + dist_dir)
290N/A shutil.rmtree(dist_dir, True)
395N/A print("deleting " + build_dir)
290N/A shutil.rmtree(build_dir, True)
395N/A print("deleting " + root_dir)
290N/A shutil.rmtree(root_dir, True)
534N/A print("deleting " + pkgs_dir)
534N/A shutil.rmtree(pkgs_dir, True)
1099N/A print("deleting " + extern_dir)
1099N/A shutil.rmtree(extern_dir, True)
290N/A
290N/Aclass test_func(Command):
1101N/A # NOTE: these options need to be in sync with tests/run.py and the
1101N/A # list of options stored in initialize_options below. The first entry
1101N/A # in each tuple must be the exact name of a member variable.
1513N/A user_options = [
1715N/A ("archivedir=", 'a', "archive failed tests <dir>"),
1513N/A ("baselinefile=", 'b', "baseline file <file>"),
1513N/A ("coverage", "c", "collect code coverage data"),
448N/A ("genbaseline", 'g', "generate test baseline"),
1513N/A ("only=", "o", "only <regex>"),
448N/A ("parseable", 'p', "parseable output"),
1101N/A ("timing", "t", "timing file <file>"),
1513N/A ("verbosemode", 'v', "run tests in verbose mode"),
1715N/A ("stoponerr", 'x', "stop when a baseline mismatch occurs"),
1715N/A ("debugoutput", 'd', "emit debugging output"),
1716N/A ("showonexpectedfail", 'f',
1715N/A "show all failure info, even for expected fails"),
1715N/A ("startattest=", 's', "start at indicated test"),
1513N/A ]
290N/A description = "Runs unit and functional tests"
290N/A
290N/A def initialize_options(self):
448N/A self.only = ""
448N/A self.baselinefile = ""
430N/A self.verbosemode = 0
448N/A self.parseable = 0
430N/A self.genbaseline = 0
1101N/A self.timing = 0
1513N/A self.coverage = 0
1715N/A self.stoponerr = 0
1715N/A self.debugoutput = 0
1716N/A self.showonexpectedfail = 0
1715N/A self.startattest = ""
1715N/A self.archivedir = ""
1101N/A
290N/A def finalize_options(self):
290N/A pass
1101N/A
290N/A def run(self):
1101N/A
290N/A os.putenv('PYEXE', sys.executable)
290N/A os.chdir(os.path.join(pwd, "tests"))
290N/A
448N/A # Reconstruct the cmdline and send that to run.py
448N/A cmd = [sys.executable, "run.py"]
448N/A args = ""
448N/A if "test" in sys.argv:
448N/A args = sys.argv[sys.argv.index("test")+1:]
430N/A cmd.extend(args)
448N/A subprocess.call(cmd)
290N/A
290N/Aclass dist_func(_bdist):
290N/A def initialize_options(self):
430N/A _bdist.initialize_options(self)
395N/A self.dist_dir = dist_dir
290N/A
290N/A
290N/A# These are set to real values based on the platform, down below
290N/Acompile_args = None
1637N/Aif osname in ("sunos", "linux", "darwin"):
1637N/A compile_args = [ "-O3" ]
290N/Alink_args = None
613N/Aext_modules = [
613N/A Extension(
613N/A 'actions._actions',
613N/A _actions_srcs,
613N/A include_dirs = include_dirs,
613N/A extra_compile_args = compile_args,
613N/A extra_link_args = link_args
613N/A ),
1632N/A Extension(
1632N/A 'solver',
1632N/A solver_srcs,
1632N/A include_dirs = include_dirs + ["."],
1632N/A extra_compile_args = compile_args,
1632N/A extra_link_args = solver_link_args,
1632N/A define_macros = [('_FILE_OFFSET_BITS', '64')]
1632N/A ),
613N/A ]
290N/Aelf_libraries = None
742N/Adata_files = web_files
395N/Acmdclasses = {
395N/A 'install': install_func,
395N/A 'build': build_func,
395N/A 'build_py': build_py_func,
395N/A 'bdist': dist_func,
395N/A 'lint': lint_func,
395N/A 'clean': clean_func,
395N/A 'clobber': clobber_func,
395N/A 'test': test_func,
395N/A }
290N/A
383N/A# all builds of IPS should have manpages
395N/Adata_files += [
395N/A (man1_dir, man1_files),
395N/A (man1m_dir, man1m_files),
395N/A (man5_dir, man5_files),
395N/A ]
290N/A
290N/Aif osname == 'sunos':
395N/A # Solaris-specific extensions are added here
395N/A data_files += [
395N/A (zones_dir, zones_files),
395N/A (brand_dir, brand_files),
1483N/A (etcbrand_dir, etcbrand_files),
395N/A (smf_dir, smf_files),
1498N/A (execattrd_dir, execattrd_files),
1498N/A (authattrd_dir, authattrd_files),
395N/A ]
290N/A
290N/Aif osname == 'sunos' or osname == "linux":
395N/A # Unix platforms which the elf extension has been ported to
395N/A # are specified here, so they are built automatically
395N/A elf_libraries = ['elf']
613N/A ext_modules += [
290N/A Extension(
395N/A 'elf',
395N/A elf_srcs,
395N/A include_dirs = include_dirs,
395N/A libraries = elf_libraries,
395N/A extra_compile_args = compile_args,
395N/A extra_link_args = link_args
395N/A ),
395N/A ]
290N/A
395N/A # Solaris has built-in md library and Solaris-specific arch extension
395N/A # All others use OpenSSL and cross-platform arch module
395N/A if osname == 'sunos':
395N/A elf_libraries += [ 'md' ]
395N/A ext_modules += [
395N/A Extension(
430N/A 'arch',
395N/A arch_srcs,
395N/A include_dirs = include_dirs,
395N/A extra_compile_args = compile_args,
395N/A extra_link_args = link_args,
395N/A define_macros = [('_FILE_OFFSET_BITS', '64')]
395N/A ),
691N/A Extension(
691N/A 'pspawn',
691N/A pspawn_srcs,
691N/A include_dirs = include_dirs,
691N/A extra_compile_args = compile_args,
691N/A extra_link_args = link_args,
691N/A define_macros = [('_FILE_OFFSET_BITS', '64')]
691N/A ),
395N/A ]
395N/A else:
395N/A elf_libraries += [ 'ssl' ]
395N/A
395N/Asetup(cmdclass = cmdclasses,
1516N/A name = 'pkg',
1516N/A version = '0.1',
395N/A package_dir = {'pkg':'modules'},
395N/A packages = packages,
395N/A data_files = data_files,
395N/A ext_package = 'pkg',
395N/A ext_modules = ext_modules,
395N/A )