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