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