setup.py revision 1660
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#
2951N/A# Copyright 2010 Sun Microsystems, Inc. All rights reserved.
20N/A# Use is subject to license terms.
20N/A#
22N/A
0N/Aimport errno
50N/Aimport fnmatch
50N/Aimport os
50N/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
589N/Afrom distutils.errors import DistutilsError
589N/Afrom distutils.core import setup, Extension
965N/Afrom distutils.cmd import Command
965N/Afrom distutils.command.install import install as _install
965N/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
2951N/Afrom distutils.command.clean import clean as _clean
1836N/A
1836N/Afrom distutils.sysconfig import get_python_inc
382N/Aimport distutils.file_util as file_util
812N/Aimport distutils.dir_util as dir_util
382N/Aimport distutils.util as util
382N/A
382N/Aosname = platform.uname()[0].lower()
1963N/Aostype = arch = 'unknown'
382N/Aif osname == 'sunos':
1963N/A arch = platform.processor()
382N/A ostype = "posix"
382N/Aelif osname == 'linux':
382N/A arch = "linux_" + platform.machine()
382N/A ostype = "posix"
382N/Aelif osname == 'windows':
26N/A arch = osname
689N/A ostype = "windows"
689N/Aelif osname == 'darwin':
466N/A arch = osname
0N/A ostype = "posix"
468N/Aelif osname == 'aix':
812N/A arch = "aix"
812N/A ostype = "posix"
52N/A
812N/A# 3rd party software required for the build
451N/ACP = 'CherryPy'
0N/ACPIDIR = 'cherrypy'
382N/ACPVER = '3.1.2'
382N/ACPARC = '%s-%s.tar.gz' % (CP, CPVER)
382N/ACPDIR = '%s-%s' % (CP, CPVER)
452N/ACPURL = 'http://download.cherrypy.org/cherrypy/%s/%s' % (CPVER, CPARC)
382N/ACPHASH = 'a94aedfd0e675858dbcc32dd250c23d285ee9b88'
452N/A
382N/APO = 'pyOpenSSL'
382N/APOIDIR = 'OpenSSL'
751N/APOVER = '0.7'
751N/APOARC = '%s-%s.tar.gz' % (PO, POVER)
382N/APODIR = '%s-%s' % (PO, POVER)
22N/APOURL = 'http://downloads.sourceforge.net/pyopenssl/%s' % (POARC)
1836N/APOHASH = 'bd072fef8eb36241852d25a9161282a051f0a63e'
2507N/A
1836N/ACOV = 'coveragepy'
1836N/ACOVIDIR = 'coverage'
1431N/ACOVVER = 'coverage-3.2b2'
1968N/ACOVARC = '%s-%s.tar.bz2' % (COV, COVVER)
873N/ACOVDIR = '%s' % COV
812N/ACOVURL = 'http://bitbucket.org/ned/%s/get/%s.tar.bz2' % (COV, COVVER)
1431N/A# No hash, since we always fetch the latest
873N/ACOVHASH = None
1431N/A
466N/ALDTP = 'ldtp'
1431N/ALDTPIDIR = 'ldtp'
466N/ALDTPVER = '1.7.1'
466N/ALDTPMINORVER = '1.7.x'
466N/ALDTPMAJORVER = '1.x'
23N/ALDTPARC = '%s-%s.tar.gz' % (LDTP, LDTPVER)
466N/ALDTPDIR = '%s-%s' % (LDTP, LDTPVER)
466N/ALDTPURL = 'http://download.freedesktop.org/ldtp/%s/%s/%s' % \
466N/A (LDTPMAJORVER, LDTPMINORVER, LDTPARC)
466N/ALDTPHASH = 'd31213d2b1449a0dadcace723b9ff7041169f7ce'
466N/A
466N/AMAKO = 'Mako'
466N/AMAKOIDIR = 'mako'
466N/AMAKOVER = '0.2.2'
1431N/AMAKOARC = '%s-%s.tar.gz' % (MAKO, MAKOVER)
1633N/AMAKODIR = '%s-%s' % (MAKO, MAKOVER)
1633N/AMAKOURL = 'http://www.makotemplates.org/downloads/%s' % (MAKOARC)
1633N/AMAKOHASH = '85c04ab3a6a26a1cab47067449712d15a8b29790'
1633N/A
466N/APLY = 'ply'
466N/APLYIDIR = 'ply'
466N/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)
1633N/APLYHASH = '38efe9e03bc39d40ee73fa566eb9c1975f1a8003'
1633N/A
1633N/APC = 'pycurl'
26N/APCIDIR = 'curl'
2230N/APCVER = '7.19.0'
1968N/APCARC = '%s-%s.tar.gz' % (PC, PCVER)
1633N/APCDIR = '%s-%s' % (PC, PCVER)
2515N/APCURL = 'http://pycurl.sourceforge.net/download/%s' % PCARC
2816N/APCHASH = '3fb59eca1461331bb9e9e8d6fe3b23eda961a416'
2816N/APCENVIRON = {}
1937N/Aif osname in ("sunos", "linux", "darwin"):
382N/A PCENVIRON = {'CFLAGS': '-O3'}
2230N/A
2230N/Apwd = os.path.normpath(sys.path[0])
2230N/A
2230N/A#
2028N/A# Unbuffer stdout and stderr. This helps to ensure that subprocess output
1968N/A# is properly interleaved with output from this program.
1968N/A#
2028N/Asys.stdout = os.fdopen(sys.stdout.fileno(), "w", 0)
1968N/Asys.stderr = os.fdopen(sys.stderr.fileno(), "w", 0)
1968N/A
1968N/Adist_dir = os.path.normpath(os.path.join(pwd, os.pardir, "proto", "dist_" + arch))
2028N/Abuild_dir = os.path.normpath(os.path.join(pwd, os.pardir, "proto", "build_" + arch))
2028N/Aif "ROOT" in os.environ and os.environ["ROOT"] != "":
2028N/A root_dir = os.environ["ROOT"]
1968N/Aelse:
1968N/A root_dir = os.path.normpath(os.path.join(pwd, os.pardir, "proto", "root_" + arch))
1968N/Apkgs_dir = os.path.normpath(os.path.join(pwd, os.pardir, "packages", arch))
1968N/Aextern_dir = os.path.normpath(os.path.join(pwd, "extern"))
1968N/A
1968N/Acacert_dir = os.path.normpath(os.path.join(pwd, "cacert"))
589N/Acacert_install_dir = 'usr/share/pkg/cacert'
589N/A
589N/Apy_install_dir = 'usr/lib/python2.6/vendor-packages'
589N/A
1431N/Ascripts_dir = 'usr/bin'
1431N/Alib_dir = 'usr/lib'
1431N/Asvc_method_dir = 'lib/svc/method'
1431N/A
1431N/Aman1_dir = 'usr/share/man/cat1'
858N/Aman1m_dir = 'usr/share/man/cat1m'
1633N/Aman5_dir = 'usr/share/man/cat5'
1633N/Aresource_dir = 'usr/share/lib/pkg'
2515N/Asmf_dir = 'var/svc/manifest/application'
2515N/Azones_dir = 'etc/zones'
466N/Aetcbrand_dir = 'etc/brand/ipkg'
466N/Abrand_dir = 'usr/lib/brand/ipkg'
466N/Aexecattrd_dir = 'etc/security/exec_attr.d'
466N/Aauthattrd_dir = 'etc/security/auth_attr.d'
466N/A
466N/Ascripts_sunos = {
466N/A scripts_dir: [
466N/A ['client.py', 'pkg'],
466N/A ['pkgdep.py', 'pkgdepend'],
589N/A ['util/publish/pkgdiff.py', 'pkgdiff'],
589N/A ['util/publish/pkgmogrify.py', 'pkgmogrify'],
589N/A ['publish.py', 'pkgsend'],
1191N/A ['pull.py', 'pkgrecv'],
1191N/A ['packagemanager.py', 'packagemanager'],
1191N/A ['updatemanager.py', 'pm-updatemanager'],
1191N/A ],
1191N/A lib_dir: [
2816N/A ['depot.py', 'pkg.depotd'],
2816N/A ['updatemanagernotifier.py', 'updatemanagernotifier'],
589N/A ['checkforupdates.py', 'pm-checkforupdates'],
589N/A ['launch.py', 'pm-launch'],
589N/A ],
589N/A svc_method_dir: [
812N/A ['svc/svc-pkg-depot', 'svc-pkg-depot'],
812N/A ],
812N/A }
812N/A
812N/Ascripts_windows = {
812N/A scripts_dir: [
812N/A ['client.py', 'client.py'],
1968N/A ['publish.py', 'publish.py'],
1968N/A ['pull.py', 'pull.py'],
1968N/A ['scripts/pkg.bat', 'pkg.bat'],
812N/A ['scripts/pkgsend.bat', 'pkgsend.bat'],
812N/A ['scripts/pkgrecv.bat', 'pkgrecv.bat'],
812N/A ],
812N/A lib_dir: [
1475N/A ['depot.py', 'depot.py'],
1475N/A ['scripts/pkg.depotd.bat', 'pkg.depotd.bat'],
1475N/A ],
1475N/A }
975N/A
975N/Ascripts_other_unix = {
975N/A scripts_dir: [
975N/A ['client.py', 'client.py'],
1633N/A ['pkgdep.py', 'pkgdep'],
1633N/A ['util/publish/pkgdiff.py', 'pkgdiff'],
1633N/A ['util/publish/pkgmogrify.py', 'pkgmogrify'],
1633N/A ['pull.py', 'pull.py'],
2028N/A ['publish.py', 'publish.py'],
1633N/A ['scripts/pkg.sh', 'pkg'],
1633N/A ['scripts/pkgsend.sh', 'pkgsend'],
1633N/A ['scripts/pkgrecv.sh', 'pkgrecv'],
14N/A ],
382N/A lib_dir: [
429N/A ['depot.py', 'depot.py'],
14N/A ['scripts/pkg.depotd.sh', 'pkg.depotd'],
404N/A ],
404N/A }
30N/A
382N/A# indexed by 'osname'
30N/Ascripts = {
791N/A "sunos": scripts_sunos,
2728N/A "linux": scripts_other_unix,
2728N/A "windows": scripts_windows,
689N/A "darwin": scripts_other_unix,
1968N/A "aix" : scripts_other_unix,
1968N/A "unknown": scripts_sunos,
1968N/A }
1968N/A
1191N/Aman1_files = [
258N/A 'man/packagemanager.1',
1968N/A 'man/pkg.1',
2816N/A 'man/pkgdepend.1',
382N/A 'man/pkgdiff.1',
1968N/A 'man/pkgmogrify.1',
30N/A 'man/pkgsend.1',
589N/A 'man/pkgrecv.1',
589N/A 'man/pm-updatemanager.1',
1968N/A ]
589N/Aman1m_files = [
589N/A 'man/pkg.depotd.1m'
589N/A ]
589N/Aman5_files = [
1968N/A 'man/pkg.5'
589N/A ]
1968N/Apackages = [
466N/A 'pkg',
466N/A 'pkg.actions',
2230N/A 'pkg.bundle',
1968N/A 'pkg.client',
1968N/A 'pkg.client.transport',
1431N/A 'pkg.file_layout',
1968N/A 'pkg.flavor',
1968N/A 'pkg.portable',
54N/A 'pkg.publish',
1968N/A 'pkg.server'
1968N/A ]
2515N/A
2816N/Aweb_files = []
2816N/Afor entry in os.walk("web"):
2816N/A web_dir, dirs, files = entry
2816N/A if not files:
1475N/A continue
2230N/A web_files.append((os.path.join(resource_dir, web_dir), [
466N/A os.path.join(web_dir, f) for f in files
1633N/A if f != "Makefile"
1633N/A ]))
135N/A
2230N/Azones_files = [
2230N/A 'brand/SUNWipkg.xml',
2230N/A ]
135N/Abrand_files = [
135N/A 'brand/pkgcreatezone',
1968N/A 'brand/attach',
135N/A 'brand/clone',
1968N/A 'brand/detach',
382N/A 'brand/prestate',
382N/A 'brand/poststate',
382N/A 'brand/uninstall',
382N/A 'brand/common.ksh',
382N/A ]
382N/Aetcbrand_files = [
382N/A 'brand/pkgrm.conf',
382N/A 'brand/smf_disable.conf',
1968N/A ]
382N/Asmf_files = [
1968N/A 'svc/pkg-server.xml',
1542N/A 'svc/pkg-update.xml',
1542N/A ]
1968N/Aexecattrd_files = ['util/misc/exec_attr.d/SUNWipkg']
1968N/Aauthattrd_files = ['util/misc/auth_attr.d/SUNWipkg']
812N/Apspawn_srcs = [
1968N/A 'modules/pspawn.c'
589N/A ]
1968N/Aelf_srcs = [
858N/A 'modules/elf.c',
858N/A 'modules/elfextract.c',
1968N/A 'modules/liblist.c',
858N/A ]
858N/Aarch_srcs = [
858N/A 'modules/arch.c'
858N/A ]
858N/A_actions_srcs = [
858N/A 'modules/actions/_actions.c'
858N/A ]
1968N/Asolver_srcs = [
1431N/A 'modules/solver/solver.c',
1431N/A 'modules/solver/py_solver.c'
1431N/A ]
1431N/Asolver_link_args = ["-lm", "-lc"]
1431N/Aif osname == 'sunos':
1431N/A solver_link_args = ["-ztext"] + solver_link_args
1431N/A
1431N/Ainclude_dirs = [ 'modules' ]
1431N/Alint_flags = [ '-u', '-axms', '-erroff=E_NAME_DEF_NOT_USED2' ]
1431N/A
1431N/A# Runs lint on the extension module source code
1431N/Aclass lint_func(Command):
1431N/A description = "Runs various lint tools over IPS extension source code"
1431N/A user_options = []
1431N/A
1431N/A def initialize_options(self):
1431N/A pass
1431N/A
1968N/A def finalize_options(self):
1542N/A pass
1542N/A
2515N/A # Make string shell-friendly
2515N/A @staticmethod
1968N/A def escape(astring):
1968N/A return astring.replace(' ', '\\ ')
1968N/A
1633N/A def run(self):
1633N/A # assumes lint is on the $PATH
589N/A if osname == 'sunos' or osname == "linux":
1968N/A archcmd = ['lint'] + lint_flags + ['-D_FILE_OFFSET_BITS=64'] + \
1902N/A ["%s%s" % ("-I", k) for k in include_dirs] + \
1968N/A ['-I' + self.escape(get_python_inc())] + \
1968N/A arch_srcs
1968N/A elfcmd = ['lint'] + lint_flags + \
1191N/A ["%s%s" % ("-I", k) for k in include_dirs] + \
2816N/A ['-I' + self.escape(get_python_inc())] + \
2816N/A ["%s%s" % ("-l", k) for k in elf_libraries] + \
2816N/A elf_srcs
1191N/A _actionscmd = ['lint'] + lint_flags + \
1191N/A ["%s%s" % ("-I", k) for k in include_dirs] + \
1191N/A ['-I' + self.escape(get_python_inc())] + \
1191N/A _actions_srcs
2816N/A pspawncmd = ['lint'] + lint_flags + ['-D_FILE_OFFSET_BITS=64'] + \
2816N/A ["%s%s" % ("-I", k) for k in include_dirs] + \
2816N/A ['-I' + self.escape(get_python_inc())] + \
2816N/A pspawn_srcs
2816N/A
589N/A print(" ".join(archcmd))
589N/A os.system(" ".join(archcmd))
589N/A print(" ".join(elfcmd))
589N/A os.system(" ".join(elfcmd))
589N/A print(" ".join(_actionscmd))
589N/A os.system(" ".join(_actionscmd))
589N/A print(" ".join(pspawncmd))
765N/A os.system(" ".join(pspawncmd))
765N/A
765N/A proto = os.path.join(root_dir, py_install_dir)
765N/A sys.path.insert(0, proto)
765N/A
765N/A # Insert tests directory onto sys.path so any custom checkers
765N/A # can be found.
589N/A sys.path.insert(0, os.path.join(pwd, 'tests'))
765N/A print(sys.path)
765N/A
765N/A # assumes pylint is accessible on the sys.path
765N/A from pylint import lint
765N/A scriptlist = [ 'setup.py' ]
765N/A for d, m in scripts_sunos.items():
765N/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]))
135N/A
1968N/A # For some reason, the load-plugins option, when used in the
157N/A # rcfile, does not work, so we put it here instead, to load
382N/A # our custom checkers.
429N/A lint.Run(['--load-plugins=multiplatform', '--rcfile',
429N/A os.path.join(pwd, 'tests', 'pylintrc')] +
2028N/A scriptlist + packages)
2028N/A
429N/Aclass install_func(_install):
429N/A def initialize_options(self):
429N/A _install.initialize_options(self)
429N/A
429N/A # PRIVATE_BUILD set in the environment tells us to put the build
429N/A # directory into the .pyc files, rather than the final
429N/A # installation directory.
2028N/A private_build = os.getenv("PRIVATE_BUILD", None)
1968N/A
1968N/A if private_build is None:
1968N/A self.install_lib = py_install_dir
1968N/A self.install_data = os.path.sep
1968N/A self.root = root_dir
1968N/A else:
1968N/A self.install_lib = os.path.join(root_dir, py_install_dir)
1968N/A self.install_data = root_dir
1968N/A
1968N/A # This is used when installing scripts, below, but it isn't a
812N/A # standard distutils variable.
1968N/A self.root_dir = root_dir
1968N/A
1968N/A def run(self):
1968N/A """
1968N/A At the end of the install function, we need to rename some files
812N/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
812N/A _install.run(self)
1968N/A
812N/A for d, files in scripts[osname].iteritems():
1968N/A for (srcname, dstname) in files:
1968N/A dst_dir = util.change_root(self.root_dir, d)
1968N/A dst_path = util.change_root(self.root_dir,
1968N/A os.path.join(d, dstname))
1968N/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
812N/A | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)
812N/A
1968N/A # Take cacerts in cacert_dir and install them in
812N/A # proto-area-relative cacert_install_dir
812N/A install_cacerts()
1968N/A
812N/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":
812N/A prep_sw(LDTP, LDTPARC, LDTPDIR, LDTPURL,
1968N/A LDTPHASH)
812N/A saveenv = os.environ.copy()
812N/A os.environ["LDFLAGS"] = os.environ.get("LDFLAGS", "") + \
1968N/A " -lsocket -lnsl"
1968N/A install_ldtp(LDTP, LDTPDIR, LDTPIDIR)
812N/A os.environ = saveenv
1968N/A
812N/A if "BUILD_PYOPENSSL" in os.environ and \
812N/A os.environ["BUILD_PYOPENSSL"] != "":
873N/A #
873N/A # Include /usr/sfw/lib in the build environment
873N/A # to ensure that this builds and runs on older
873N/A # nevada builds, before openssl moved out of /usr/sfw.
873N/A #
873N/A saveenv = os.environ.copy()
873N/A if osname == "sunos":
812N/A os.environ["CFLAGS"] = "-I/usr/sfw/include " + \
1968N/A os.environ.get("CFLAGS", "")
812N/A os.environ["LDFLAGS"] = \
812N/A "-L/usr/sfw/lib -R/usr/sfw/lib " + \
812N/A os.environ.get("LDFLAGS", "")
812N/A prep_sw(PO, POARC, PODIR, POURL, POHASH)
812N/A install_sw(PO, PODIR, POIDIR)
1968N/A os.environ = saveenv
1475N/A prep_sw(MAKO, MAKOARC, MAKODIR, MAKOURL, MAKOHASH)
1968N/A install_sw(MAKO, MAKODIR, MAKOIDIR)
975N/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
1968N/A # Remove some bits that we're not going to package, but be sure
2230N/A # not to complain if we try to remove them twice.
2230N/A def onerror(func, path, exc_info):
1968N/A if exc_info[1].errno != errno.ENOENT:
1968N/A raise
1968N/A
873N/A for dir in ("cherrypy/scaffold", "cherrypy/test",
873N/A "cherrypy/tutorial"):
1968N/A shutil.rmtree(os.path.join(root_dir, py_install_dir, dir),
1968N/A onerror=onerror)
873N/A try:
873N/A os.remove(os.path.join(root_dir, "usr/bin/mako-render"))
382N/A except EnvironmentError, e:
466N/A if e.errno != errno.ENOENT:
466N/A raise
451N/A
1633N/Adef hash_sw(swname, swarc, swhash):
1633N/A if swhash == None:
1633N/A return True
1968N/A
1968N/A print "checksumming %s" % swname
1968N/A hash = hashlib.sha1()
1968N/A f = open(swarc, "rb")
1968N/A while True:
1968N/A data = f.read(65536)
1968N/A if data == "":
1968N/A break
1968N/A hash.update(data)
1968N/A f.close()
1968N/A
1968N/A if hash.hexdigest() == swhash:
2515N/A return True
2515N/A else:
1968N/A print >> sys.stderr, "bad checksum! %s != %s" % \
2230N/A (swhash, hash.hexdigest())
1968N/A return False
1968N/A
1542N/Adef install_cacerts():
1542N/A
445N/A findir = os.path.join(root_dir, cacert_install_dir)
466N/A dir_util.mkpath(findir, verbose = True)
1542N/A for f in os.listdir(cacert_dir):
1633N/A
1633N/A # Copy certificate
1020N/A srcname = os.path.normpath(os.path.join(cacert_dir, f))
1020N/A dn, copied = file_util.copy_file(srcname, findir, update = True)
1020N/A
1020N/A if not copied:
1020N/A continue
2515N/A
2515N/A # Call openssl to create hash symlink
2515N/A cmd = ["openssl", "x509", "-noout", "-hash", "-in",
2515N/A srcname]
2515N/A
2515N/A p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
2515N/A hashval = p.stdout.read()
2515N/A p.wait()
2515N/A
2515N/A hashval = hashval.strip()
2515N/A hashval += ".0"
451N/A
1968N/A hashpath = os.path.join(findir, hashval)
2230N/A if os.path.exists(hashpath):
2230N/A os.unlink(hashpath)
2230N/A if hasattr(os, "symlink"):
2230N/A os.symlink(f, hashpath)
2230N/A else:
2230N/A file_util.copy_file(srcname, hashpath)
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)
2515N/A if not os.path.exists(extern_dir):
2515N/A os.mkdir(extern_dir)
1902N/A
1968N/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) or \
1968N/A (hdr.gettype() != "application/x-gzip" and
812N/A hdr.gettype() != "application/x-tar"):
812N/A print >> sys.stderr, "Unable to retrieve %s.\n" \
812N/A "Please retrieve the file " \
812N/A "and place it at: %s\n" % (swurl, swarc)
1968N/A # remove a partial download or error message from proxy
1968N/A remove_sw(swname)
1968N/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")
812N/A if os.path.exists(patchdir) and not os.path.exists(already_patched):
429N/A patches = os.listdir(patchdir)
429N/A for p in patches:
2028N/A patchpath = os.path.join(os.path.pardir,
1836N/A os.path.pardir, patchdir, p)
2230N/A print "Applying %s to %s" % (p, swname)
1836N/A args = ["patch", "-d", swdir, "-i", patchpath, "-p0"]
1836N/A if osname == "windows":
1836N/A args.append("--binary")
429N/A ret = subprocess.Popen(args).wait()
612N/A if ret != 0:
1542N/A print >> sys.stderr, \
1968N/A "patch failed and returned %d." % ret
1968N/A print >> sys.stderr, \
1968N/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,
812N/A '--install-lib=%s' % py_install_dir,
1968N/A '--install-data=%s' % py_install_dir]
2028N/A run_cmd(args, swdir, env=inst_env)
812N/A
812N/Adef run_cmd(args, swdir, env=None):
812N/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, \
873N/A "Command was: %s" % " ".join(args)
1836N/A sys.exit(1)
1836N/A
1836N/Adef remove_sw(swname):
1836N/A print("deleting %s" % swname)
812N/A for file in os.listdir(extern_dir):
812N/A if fnmatch.fnmatch(file, "%s*" % swname):
812N/A fpath = os.path.join(extern_dir, file)
812N/A if os.path.isfile(fpath):
1968N/A os.unlink(fpath)
1968N/A else:
1968N/A shutil.rmtree(fpath, True)
1968N/A
1968N/Aclass build_func(_build):
1968N/A def initialize_options(self):
1968N/A _build.initialize_options(self)
1968N/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)
812N/A return p.communicate()[0].strip()
1968N/A except OSError:
812N/A print >> sys.stderr, "ERROR: unable to obtain mercurial version"
812N/A return "unknown"
812N/A
812N/Adef syntax_check(filename):
812N/A """ Run python's compiler over the file, and discard the results.
1968N/A Arrange to generate an exception if the file does not compile.
1968N/A This is needed because distutil's own use of pycompile (in the
1968N/A distutils.utils module) is broken, and doesn't stop on error. """
1968N/A try:
812N/A py_compile.compile(filename, os.devnull, doraise=True)
812N/A except py_compile.PyCompileError, e:
812N/A raise DistutilsError("%s: failed syntax check: %s" %
812N/A (filename, e))
812N/A
873N/A
1836N/Aclass build_py_func(_build_py):
1836N/A # override the build_module method to do VERSION substitution on pkg/__init__.py
812N/A def build_module (self, module, module_file, package):
873N/A
1836N/A if module == "__init__" and package == "pkg":
1836N/A versionre = '(?m)^VERSION[^"]*"([^"]*)"'
1836N/A # Grab the previously-built version out of the build
812N/A # tree.
812N/A try:
812N/A ocontent = \
812N/A file(self.get_module_outfile(self.build_lib,
812N/A [package], module)).read()
452N/A ov = re.search(versionre, ocontent).group(1)
466N/A except IOError:
858N/A ov = None
382N/A v = get_hg_version()
466N/A vstr = 'VERSION = "%s"' % v
965N/A # If the versions haven't changed, there's no need to
858N/A # recompile.
2230N/A if v == ov:
382N/A return
858N/A
858N/A mcontent = file(module_file).read()
858N/A mcontent = re.sub(versionre, vstr, mcontent)
382N/A tmpfd, tmp_file = tempfile.mkstemp()
742N/A os.write(tmpfd, mcontent)
858N/A os.close(tmpfd)
466N/A print "doing version substitution: ", v
466N/A rv = _build_py.build_module(self, module, tmp_file, package)
1968N/A os.unlink(tmp_file)
858N/A return rv
858N/A
858N/A # Will raise a DistutilsError on failure.
858N/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
466N/A
466N/Aclass clobber_func(Command):
466N/A user_options = []
466N/A description = "Deletes any and all files created by setup"
466N/A
466N/A def initialize_options(self):
466N/A pass
466N/A def finalize_options(self):
466N/A pass
466N/A def run(self):
466N/A # nuke everything
466N/A print("deleting " + dist_dir)
1968N/A shutil.rmtree(dist_dir, True)
466N/A print("deleting " + build_dir)
466N/A shutil.rmtree(build_dir, True)
466N/A print("deleting " + root_dir)
466N/A shutil.rmtree(root_dir, True)
466N/A print("deleting " + pkgs_dir)
466N/A shutil.rmtree(pkgs_dir, True)
466N/A print("deleting " + extern_dir)
466N/A shutil.rmtree(extern_dir, True)
466N/A
466N/Aclass test_func(Command):
466N/A # NOTE: these options need to be in sync with tests/run.py and the
466N/A # list of options stored in initialize_options below. The first entry
466N/A # in each tuple must be the exact name of a member variable.
466N/A user_options = [
466N/A ("baselinefile=", 'b', "baseline file <file>"),
1968N/A ("coverage", "c", "collect code coverage data"),
1968N/A ("genbaseline", 'g', "generate test baseline"),
1968N/A ("only=", "o", "only <regex>"),
466N/A ("parseable", 'p', "parseable output"),
382N/A ("timing", "t", "timing file <file>"),
612N/A ("verbosemode", 'v', "run tests in verbose mode"),
612N/A ]
612N/A description = "Runs unit and functional tests"
612N/A
1431N/A def initialize_options(self):
1431N/A self.only = ""
2028N/A self.baselinefile = ""
2028N/A self.verbosemode = 0
2028N/A self.parseable = 0
2028N/A self.genbaseline = 0
2028N/A self.timing = 0
2028N/A self.coverage = 0
2028N/A
2028N/A def finalize_options(self):
2028N/A pass
2028N/A
2028N/A def run(self):
1431N/A
1968N/A os.putenv('PYEXE', sys.executable)
1968N/A os.chdir(os.path.join(pwd, "tests"))
1968N/A
2028N/A # Reconstruct the cmdline and send that to run.py
2515N/A cmd = [sys.executable, "run.py"]
2515N/A args = ""
2515N/A if "test" in sys.argv:
1431N/A args = sys.argv[sys.argv.index("test")+1:]
1895N/A cmd.extend(args)
1431N/A subprocess.call(cmd)
1431N/A
1672N/Aclass dist_func(_bdist):
1672N/A def initialize_options(self):
1672N/A _bdist.initialize_options(self)
1968N/A self.dist_dir = dist_dir
1672N/A
1431N/A
1431N/A# These are set to real values based on the platform, down below
2028N/Acompile_args = None
2028N/Aif osname in ("sunos", "linux", "darwin"):
2028N/A compile_args = [ "-O3" ]
2028N/Alink_args = None
2028N/Aext_modules = [
2028N/A Extension(
612N/A 'actions._actions',
617N/A _actions_srcs,
2065N/A include_dirs = include_dirs,
2065N/A extra_compile_args = compile_args,
2065N/A extra_link_args = link_args
2065N/A ),
2028N/A Extension(
2028N/A 'solver',
2028N/A solver_srcs,
2028N/A include_dirs = include_dirs + ["."],
2028N/A extra_compile_args = compile_args,
2028N/A extra_link_args = solver_link_args,
2028N/A define_macros = [('_FILE_OFFSET_BITS', '64')]
2028N/A ),
1431N/A ]
1431N/Aelf_libraries = None
1431N/Adata_files = web_files
975N/Acmdclasses = {
1779N/A 'install': install_func,
1431N/A 'build': build_func,
1431N/A 'build_py': build_py_func,
617N/A 'bdist': dist_func,
1542N/A 'lint': lint_func,
1542N/A 'clean': clean_func,
1542N/A 'clobber': clobber_func,
2028N/A 'test': test_func,
1542N/A }
1542N/A
1542N/A# all builds of IPS should have manpages
1542N/Adata_files += [
1779N/A (man1_dir, man1_files),
1542N/A (man1m_dir, man1m_files),
1542N/A (man5_dir, man5_files),
1542N/A ]
1542N/A
2028N/Aif osname == 'sunos':
1542N/A # Solaris-specific extensions are added here
1542N/A data_files += [
1542N/A (zones_dir, zones_files),
1431N/A (brand_dir, brand_files),
1431N/A (etcbrand_dir, etcbrand_files),
1968N/A (smf_dir, smf_files),
1431N/A (execattrd_dir, execattrd_files),
1968N/A (authattrd_dir, authattrd_files),
612N/A ]
451N/A
382N/Aif osname == 'sunos' or osname == "linux":
452N/A # Unix platforms which the elf extension has been ported to
452N/A # are specified here, so they are built automatically
452N/A elf_libraries = ['elf']
452N/A ext_modules += [
873N/A Extension(
452N/A 'elf',
382N/A elf_srcs,
382N/A include_dirs = include_dirs,
1431N/A libraries = elf_libraries,
382N/A extra_compile_args = compile_args,
382N/A extra_link_args = link_args
382N/A ),
145N/A ]
1968N/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,
451N/A define_macros = [('_FILE_OFFSET_BITS', '64')]
451N/A ),
451N/A Extension(
451N/A 'pspawn',
451N/A pspawn_srcs,
451N/A include_dirs = include_dirs,
451N/A extra_compile_args = compile_args,
1902N/A extra_link_args = link_args,
2230N/A define_macros = [('_FILE_OFFSET_BITS', '64')]
1902N/A ),
2065N/A ]
2065N/A else:
2065N/A elf_libraries += [ 'ssl' ]
2065N/A
2065N/Asetup(cmdclass = cmdclasses,
2065N/A name = 'pkg',
2065N/A version = '0.1',
2507N/A package_dir = {'pkg':'modules'},
2507N/A packages = packages,
2507N/A data_files = data_files,
2507N/A ext_package = 'pkg',
2507N/A ext_modules = ext_modules,
2507N/A )
814N/A