setup.py revision 1337
1516N/A#!/usr/bin/python2.4
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#
2223N/A# Copyright 2009 Sun Microsystems, Inc. All rights reserved.
395N/A# Use is subject to license terms.
290N/A#
883N/A
454N/Aimport errno
290N/Aimport fnmatch
448N/Aimport os
290N/Aimport platform
290N/Aimport stat
290N/Aimport sys
383N/Aimport shutil
290N/Aimport re
395N/Aimport subprocess
290N/Aimport tarfile
395N/Aimport tempfile
849N/Aimport urllib
1516N/Aimport py_compile
290N/Aimport sha
849N/A
290N/Afrom distutils.errors import DistutilsError
290N/Afrom distutils.core import setup, Extension
290N/Afrom distutils.cmd import Command
290N/Afrom distutils.command.install import install as _install
383N/Afrom distutils.command.build import build as _build
290N/Afrom distutils.command.build_py import build_py as _build_py
290N/Afrom distutils.command.bdist import bdist as _bdist
290N/Afrom distutils.command.clean import clean as _clean
290N/A
290N/Afrom distutils.sysconfig import get_python_inc
290N/Aimport distutils.file_util as file_util
290N/Aimport distutils.dir_util as dir_util
290N/Aimport distutils.util as util
1660N/A
1660N/A# 3rd party software required for the build
1660N/ACP = 'CherryPy'
1660N/ACPIDIR = 'cherrypy'
1660N/ACPVER = '3.1.1'
1660N/ACPARC = '%s-%s.tar.gz' % (CP, CPVER)
1660N/ACPDIR = '%s-%s' % (CP, CPVER)
1660N/ACPURL = 'http://download.cherrypy.org/cherrypy/%s/%s' % (CPVER, CPARC)
1660N/ACPHASH = '0a8aace00ea28adc05edd41e20dd910042e6d265'
1660N/A
1660N/APO = 'pyOpenSSL'
1660N/APOIDIR = 'OpenSSL'
1660N/APOVER = '0.7'
1660N/APOARC = '%s-%s.tar.gz' % (PO, POVER)
1660N/APODIR = '%s-%s' % (PO, POVER)
1660N/APOURL = 'http://downloads.sourceforge.net/pyopenssl/%s' % (POARC)
1660N/APOHASH = 'bd072fef8eb36241852d25a9161282a051f0a63e'
1660N/A
465N/AFL = 'figleaf'
465N/AFLIDIR = 'figleaf'
465N/AFLVER = 'latest'
1516N/AFLARC = '%s-%s.tar.gz' % (FL, FLVER)
465N/AFLDIR = '%s-%s' % (FL, FLVER)
465N/AFLURL = 'http://darcs.idyll.org/~t/projects/%s' % FLARC
465N/A# No hash, since we always fetch the latest
1516N/AFLHASH = None
465N/A
465N/AMAKO = 'Mako'
465N/AMAKOIDIR = 'mako'
465N/AMAKOVER = '0.2.2'
465N/AMAKOARC = '%s-%s.tar.gz' % (MAKO, MAKOVER)
465N/AMAKODIR = '%s-%s' % (MAKO, MAKOVER)
465N/AMAKOURL = 'http://www.makotemplates.org/downloads/%s' % (MAKOARC)
1099N/AMAKOHASH = '85c04ab3a6a26a1cab47067449712d15a8b29790'
465N/A
1513N/APLY = 'ply'
1513N/APLYIDIR = 'ply'
2075N/APLYVER = '3.1'
2180N/APLYARC = '%s-%s.tar.gz' % (PLY, PLYVER)
2075N/APLYDIR = '%s-%s' % (PLY, PLYVER)
2075N/APLYURL = 'http://www.dabeaz.com/ply/%s' % (PLYARC)
2075N/APLYHASH = '38efe9e03bc39d40ee73fa566eb9c1975f1a8003'
2075N/A
708N/APC = 'pycurl'
1391N/APCIDIR = 'pycurl'
1391N/APCVER = '7.19.0'
1391N/APCARC = '%s-%s.tar.gz' % (PC, PCVER)
1391N/APCDIR = '%s-%s' % (PC, PCVER)
1391N/APCURL = 'http://pycurl.sourceforge.net/download/%s' % PCARC
1391N/APCHASH = '3fb59eca1461331bb9e9e8d6fe3b23eda961a416'
1391N/A
1391N/Aosname = platform.uname()[0].lower()
1391N/Aostype = arch = 'unknown'
1391N/Aif osname == 'sunos':
1391N/A arch = platform.processor()
742N/A ostype = "posix"
742N/Aelif osname == 'linux':
742N/A arch = "linux_" + platform.machine()
742N/A ostype = "posix"
742N/Aelif osname == 'windows':
742N/A arch = osname
1099N/A ostype = "windows"
742N/Aelif osname == 'darwin':
941N/A arch = osname
941N/A ostype = "posix"
941N/Aelif osname == 'aix':
941N/A arch = "aix"
941N/A ostype = "posix"
941N/A
1099N/Apwd = os.path.normpath(sys.path[0])
941N/A
2023N/A#
2023N/A# Unbuffer stdout and stderr. This helps to ensure that subprocess output
2023N/A# is properly interleaved with output from this program.
2023N/A#
2023N/Asys.stdout = os.fdopen(sys.stdout.fileno(), "w", 0)
2023N/Asys.stderr = os.fdopen(sys.stderr.fileno(), "w", 0)
2023N/A
2023N/Adist_dir = os.path.normpath(os.path.join(pwd, os.pardir, "proto", "dist_" + arch))
1191N/Abuild_dir = os.path.normpath(os.path.join(pwd, os.pardir, "proto", "build_" + arch))
1513N/Aif "ROOT" in os.environ and os.environ["ROOT"] != "":
1191N/A root_dir = os.environ["ROOT"]
2180N/Aelse:
1191N/A root_dir = os.path.normpath(os.path.join(pwd, os.pardir, "proto", "root_" + arch))
1191N/Apkgs_dir = os.path.normpath(os.path.join(pwd, os.pardir, "packages", arch))
1191N/Aextern_dir = os.path.normpath(os.path.join(pwd, "extern"))
1191N/A
1660N/Acacert_dir = os.path.normpath(os.path.join(pwd, "cacert"))
1660N/Acacert_install_dir = 'usr/share/pkg/cacert'
1660N/A
290N/Apy_install_dir = 'usr/lib/python2.4/vendor-packages'
2026N/A
2026N/Ascripts_dir = 'usr/bin'
2263N/Alib_dir = 'usr/lib'
2026N/Asvc_method_dir = 'lib/svc/method'
2026N/A
2026N/Aman1_dir = 'usr/share/man/cat1'
2263N/Aman1m_dir = 'usr/share/man/cat1m'
2026N/Aman5_dir = 'usr/share/man/cat5'
448N/Aresource_dir = 'usr/share/lib/pkg'
448N/Asmf_dir = 'var/svc/manifest/application'
534N/Azones_dir = 'etc/zones'
534N/Abrand_dir = 'usr/lib/brand/ipkg'
534N/A
534N/Ascripts_sunos = {
534N/A scripts_dir: [
534N/A ['client.py', 'pkg'],
534N/A ['pkgdep.py', 'pkgdep'],
290N/A ['publish.py', 'pkgsend'],
290N/A ['pull.py', 'pkgrecv'],
954N/A ['packagemanager.py', 'packagemanager'],
954N/A ['updatemanager.py', 'pm-updatemanager'],
954N/A ],
954N/A lib_dir: [
534N/A ['depot.py', 'pkg.depotd'],
1099N/A ['updatemanagernotifier.py', 'updatemanagernotifier'],
290N/A ['checkforupdates.py', 'pm-checkforupdates'],
1516N/A ['launch.py', 'pm-launch'],
290N/A ],
290N/A svc_method_dir: [
290N/A ['svc/svc-pkg-depot', 'svc-pkg-depot'],
661N/A ],
290N/A }
290N/A
290N/Ascripts_windows = {
395N/A scripts_dir: [
290N/A ['client.py', 'client.py'],
2125N/A ['publish.py', 'publish.py'],
290N/A ['pull.py', 'pull.py'],
1483N/A ['scripts/pkg.bat', 'pkg.bat'],
290N/A ['scripts/pkgsend.bat', 'pkgsend.bat'],
1498N/A ['scripts/pkgrecv.bat', 'pkgrecv.bat'],
1498N/A ],
290N/A lib_dir: [
1674N/A ['depot.py', 'depot.py'],
1674N/A ['scripts/pkg.depotd.bat', 'pkg.depotd.bat'],
2262N/A ],
1674N/A }
395N/A
430N/Ascripts_other_unix = {
395N/A scripts_dir: [
1544N/A ['client.py', 'client.py'],
1968N/A ['pkgdep.py', 'pkgdep'],
1557N/A ['pull.py', 'pull.py'],
1903N/A ['publish.py', 'publish.py'],
2046N/A ['scripts/pkg.sh', 'pkg'],
2240N/A ['scripts/pkgsend.sh', 'pkgsend'],
1506N/A ['scripts/pkgrecv.sh', 'pkgrecv'],
395N/A ],
395N/A lib_dir: [
2026N/A ['depot.py', 'depot.py'],
424N/A ['scripts/pkg.depotd.sh', 'pkg.depotd'],
1024N/A ],
395N/A }
395N/A
395N/A# indexed by 'osname'
2078N/Ascripts = {
578N/A "sunos": scripts_sunos,
1172N/A "linux": scripts_other_unix,
395N/A "windows": scripts_windows,
661N/A "darwin": scripts_other_unix,
1099N/A "aix" : scripts_other_unix,
1902N/A "unknown": scripts_sunos,
661N/A }
395N/A
849N/Aman1_files = [
290N/A 'man/packagemanager.1',
395N/A 'man/pkg.1',
395N/A 'man/pkgdep.1',
1968N/A 'man/pkgsend.1',
395N/A 'man/pkgrecv.1',
395N/A 'man/pm-updatemanager.1',
395N/A ]
395N/Aman1m_files = [
395N/A 'man/pkg.depotd.1m'
395N/A ]
395N/Aman5_files = [
395N/A 'man/pkg.5'
395N/A ]
395N/Apackages = [
395N/A 'pkg',
290N/A 'pkg.actions',
290N/A 'pkg.bundle',
395N/A 'pkg.client',
395N/A 'pkg.client.transport',
1231N/A 'pkg.flavor',
1557N/A 'pkg.portable',
1903N/A 'pkg.publish',
1557N/A 'pkg.server'
395N/A ]
395N/A
395N/Aweb_files = []
395N/Afor entry in os.walk("web"):
395N/A web_dir, dirs, files = entry
395N/A if not files:
395N/A continue
395N/A web_files.append((os.path.join(resource_dir, web_dir), [
395N/A os.path.join(web_dir, f) for f in files
395N/A if f != "Makefile"
395N/A ]))
290N/A
290N/Azones_files = [
430N/A 'brand/SUNWipkg.xml',
395N/A ]
395N/Abrand_files = [
395N/A 'brand/config.xml',
395N/A 'brand/platform.xml',
1302N/A 'brand/pkgcreatezone',
395N/A 'brand/attach',
395N/A 'brand/clone',
290N/A 'brand/detach',
395N/A 'brand/prestate',
1024N/A 'brand/poststate',
413N/A 'brand/query',
1544N/A 'brand/uninstall',
1557N/A 'brand/common.ksh',
1903N/A ]
2046N/Asmf_files = [
2240N/A 'svc/pkg-server.xml',
1506N/A 'svc/pkg-update.xml',
413N/A ]
2026N/Apspawn_srcs = [
413N/A 'modules/pspawn.c'
1978N/A ]
1024N/Aelf_srcs = [
395N/A 'modules/elf.c',
395N/A 'modules/elfextract.c',
413N/A 'modules/liblist.c',
395N/A ]
395N/Aarch_srcs = [
413N/A 'modules/arch.c'
395N/A ]
395N/A_actions_srcs = [
395N/A 'modules/actions/_actions.c'
395N/A ]
395N/Ainclude_dirs = [ 'modules' ]
395N/Alint_flags = [ '-u', '-axms', '-erroff=E_NAME_DEF_NOT_USED2' ]
1191N/A
1452N/A# Runs the test suite with the code coverage suite (figleaf) turned on, and
1231N/A# outputs a coverage report.
2046N/A# TODO: Make the cov report format an option (html, ast, cov, etc)
395N/Aclass cov_func(Command):
395N/A description = "Runs figleaf code coverage suite"
424N/A user_options = []
395N/A def initialize_options(self):
742N/A pass
742N/A def finalize_options(self):
742N/A pass
742N/A def run(self):
742N/A if not os.path.isdir(FLDIR):
742N/A install_sw(FL, FLVER, FLARC, FLDIR, FLURL, FLIDIR,
742N/A FLHASH)
742N/A # Run the test suite with coverage enabled
742N/A os.putenv('PYEXE', sys.executable)
742N/A os.chdir(os.path.join(pwd, "tests"))
742N/A # Reconstruct the cmdline and send that to run.py
395N/A os.environ["PKGCOVERAGE"] = "1"
395N/A cmd = [sys.executable, "run.py"]
395N/A subprocess.call(cmd)
395N/A print "Generating coverage report in directory: '%s/cov_report'" % \
395N/A pwd
954N/A os.system("figleaf2html -d cov_report .figleaf")
954N/A
954N/A# Runs lint on the extension module source code
954N/Aclass lint_func(Command):
954N/A description = "Runs various lint tools over IPS extension source code"
954N/A user_options = []
954N/A
395N/A def initialize_options(self):
1483N/A pass
1483N/A
1483N/A def finalize_options(self):
1483N/A pass
395N/A
1902N/A # Make string shell-friendly
1099N/A @staticmethod
1099N/A def escape(astring):
395N/A return astring.replace(' ', '\\ ')
2046N/A
2223N/A def run(self):
2046N/A # assumes lint is on the $PATH
2046N/A if osname == 'sunos' or osname == "linux":
1498N/A archcmd = ['lint'] + lint_flags + ['-D_FILE_OFFSET_BITS=64'] + \
1498N/A ["%s%s" % ("-I", k) for k in include_dirs] + \
691N/A ['-I' + self.escape(get_python_inc())] + \
691N/A arch_srcs
691N/A elfcmd = ['lint'] + lint_flags + \
395N/A ["%s%s" % ("-I", k) for k in include_dirs] + \
395N/A ['-I' + self.escape(get_python_inc())] + \
395N/A ["%s%s" % ("-l", k) for k in elf_libraries] + \
395N/A elf_srcs
395N/A _actionscmd = ['lint'] + lint_flags + \
290N/A ["%s%s" % ("-I", k) for k in include_dirs] + \
395N/A ['-I' + self.escape(get_python_inc())] + \
395N/A _actions_srcs
591N/A pspawncmd = ['lint'] + lint_flags + ['-D_FILE_OFFSET_BITS=64'] + \
591N/A ["%s%s" % ("-I", k) for k in include_dirs] + \
591N/A ['-I' + self.escape(get_python_inc())] + \
1505N/A pspawn_srcs
1505N/A
1505N/A print(" ".join(archcmd))
1505N/A os.system(" ".join(archcmd))
1632N/A print(" ".join(elfcmd))
1632N/A os.system(" ".join(elfcmd))
1632N/A print(" ".join(_actionscmd))
1632N/A os.system(" ".join(_actionscmd))
395N/A print(" ".join(pspawncmd))
395N/A os.system(" ".join(pspawncmd))
290N/A
290N/A proto = os.path.join(root_dir, py_install_dir)
290N/A sys.path.insert(0, proto)
290N/A
290N/A # Insert tests directory onto sys.path so any custom checkers
290N/A # can be found.
290N/A sys.path.insert(0, os.path.join(pwd, 'tests'))
290N/A print(sys.path)
290N/A
290N/A # assumes pylint is accessible on the sys.path
290N/A from pylint import lint
290N/A scriptlist = [ 'setup.py' ]
290N/A for d, m in scripts_sunos.items():
290N/A for a in m:
395N/A # specify the filenames of the scripts, in addition
395N/A # to the package names themselves
290N/A scriptlist.append(os.path.join(root_dir, d, a[1]))
290N/A
290N/A # For some reason, the load-plugins option, when used in the
290N/A # rcfile, does not work, so we put it here instead, to load
290N/A # our custom checkers.
395N/A lint.Run(['--load-plugins=multiplatform', '--rcfile',
395N/A os.path.join(pwd, 'tests', 'pylintrc')] +
395N/A scriptlist + packages)
290N/A
395N/Aclass install_func(_install):
395N/A def initialize_options(self):
395N/A _install.initialize_options(self)
395N/A
591N/A # PRIVATE_BUILD set in the environment tells us to put the build
591N/A # directory into the .pyc files, rather than the final
591N/A # installation directory.
591N/A private_build = os.getenv("PRIVATE_BUILD", None)
691N/A
691N/A if private_build is None:
691N/A self.install_lib = py_install_dir
691N/A self.install_data = os.path.sep
290N/A self.root = root_dir
290N/A else:
290N/A self.install_lib = os.path.join(root_dir, py_install_dir)
290N/A self.install_data = root_dir
290N/A
591N/A # This is used when installing scripts, below, but it isn't a
591N/A # standard distutils variable.
691N/A self.root_dir = root_dir
691N/A
290N/A def run(self):
395N/A """
395N/A At the end of the install function, we need to rename some files
290N/A because distutils provides no way to rename files as they are
395N/A placed in their install locations.
395N/A Also, make sure that cherrypy and other external dependencies
395N/A are installed.
395N/A """
290N/A for f in man1_files + man1m_files + man5_files:
290N/A file_util.copy_file(f + ".txt", f, update=1)
290N/A
395N/A _install.run(self)
395N/A
395N/A for d, files in scripts[osname].iteritems():
395N/A for (srcname, dstname) in files:
395N/A dst_dir = util.change_root(self.root_dir, d)
395N/A dst_path = util.change_root(self.root_dir,
290N/A os.path.join(d, dstname))
290N/A dir_util.mkpath(dst_dir, verbose = True)
290N/A file_util.copy_file(srcname, dst_path, update = True)
290N/A # make scripts executable
290N/A os.chmod(dst_path,
430N/A os.stat(dst_path).st_mode
290N/A | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)
290N/A
395N/A # Take cacerts in cacert_dir and install them in
290N/A # proto-area-relative cacert_install_dir
395N/A install_cacerts()
506N/A
506N/A install_sw(CP, CPVER, CPARC, CPDIR, CPURL, CPIDIR, CPHASH)
506N/A if "BUILD_PYOPENSSL" in os.environ and \
506N/A os.environ["BUILD_PYOPENSSL"] != "":
506N/A #
506N/A # Include /usr/sfw/lib in the build environment
506N/A # to ensure that this builds and runs on older
506N/A # nevada builds, before openssl moved out of /usr/sfw.
834N/A #
506N/A saveenv = os.environ.copy()
506N/A if osname == "sunos":
506N/A os.environ["CFLAGS"] = "-I/usr/sfw/include " + \
513N/A os.environ.get("CFLAGS", "")
506N/A os.environ["LDFLAGS"] = \
506N/A "-L/usr/sfw/lib -R/usr/sfw/lib " + \
506N/A os.environ.get("LDFLAGS", "")
506N/A install_sw(PO, POVER, POARC, PODIR, POURL, POIDIR,
290N/A POHASH)
290N/A os.environ = saveenv
395N/A install_sw(MAKO, MAKOVER, MAKOARC, MAKODIR, MAKOURL, MAKOIDIR,
395N/A MAKOHASH)
849N/A install_sw(PLY, PLYVER, PLYARC, PLYDIR, PLYURL, PLYIDIR,
849N/A PLYHASH)
883N/A install_sw(PC, PCVER, PCARC, PCDIR, PCURL, PCIDIR, PCHASH)
883N/A
395N/A # Remove some bits that we're not going to package, but be sure
413N/A # not to complain if we try to remove them twice.
413N/A def onerror(func, path, exc_info):
413N/A if exc_info[1].errno != errno.ENOENT:
395N/A raise
290N/A
1674N/A for dir in ("cherrypy/scaffold", "cherrypy/test",
1674N/A "cherrypy/tutorial"):
1674N/A shutil.rmtree(os.path.join(root_dir, py_install_dir, dir),
1674N/A onerror=onerror)
1674N/A try:
1674N/A os.remove(os.path.join(root_dir, "usr/bin/mako-render"))
1674N/A except EnvironmentError, e:
1674N/A if e.errno != errno.ENOENT:
1674N/A raise
1674N/A
1674N/Adef hash_sw(swname, swarc, swhash):
1674N/A if swhash == None:
1674N/A return True
1674N/A
1674N/A print "checksumming %s" % swname
395N/A hash = sha.new()
395N/A f = open(swarc, "rb")
506N/A while True:
506N/A data = f.read(65536)
395N/A if data == "":
395N/A break
395N/A hash.update(data)
395N/A f.close()
430N/A
849N/A if hash.hexdigest() == swhash:
834N/A return True
290N/A else:
1391N/A print >> sys.stderr, "bad checksum! %s != %s" % \
1391N/A (swhash, hash.hexdigest())
1401N/A return False
1391N/A
1391N/Adef install_cacerts():
1391N/A
1391N/A findir = os.path.join(root_dir, cacert_install_dir)
1391N/A dir_util.mkpath(findir, verbose = True)
1391N/A for f in os.listdir(cacert_dir):
1391N/A
1391N/A # Copy certificate
836N/A srcname = os.path.normpath(os.path.join(cacert_dir, f))
836N/A dn, copied = file_util.copy_file(srcname, findir, update = True)
849N/A
849N/A if not copied:
849N/A continue
849N/A
849N/A # Call openssl to create hash symlink
849N/A cmd = ["openssl", "x509", "-noout", "-hash", "-in",
849N/A srcname]
849N/A
849N/A p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
849N/A hashval = p.stdout.read()
849N/A p.wait()
849N/A
1513N/A hashval = hashval.strip()
1391N/A hashval += ".0"
849N/A
2026N/A hashpath = os.path.join(findir, hashval)
2026N/A if os.path.exists(hashpath):
1513N/A os.unlink(hashpath)
1391N/A if hasattr(os, "symlink"):
1513N/A os.symlink(f, hashpath)
1391N/A else:
1391N/A file_util.copy_file(srcname, hashpath)
1660N/A
1513N/Adef install_sw(swname, swver, swarc, swdir, swurl, swidir, swhash):
1513N/A swarc = os.path.join(extern_dir, swarc)
2023N/A swdir = os.path.join(extern_dir, swdir)
2023N/A if not os.path.exists(extern_dir):
290N/A os.mkdir(extern_dir)
883N/A
883N/A if not os.path.exists(swarc):
883N/A print "downloading %s" % swname
883N/A try:
883N/A fname, hdr = urllib.urlretrieve(swurl, swarc)
883N/A except IOError:
883N/A pass
883N/A if not os.path.exists(swarc) or \
883N/A (hdr.gettype() != "application/x-gzip" and
883N/A hdr.gettype() != "application/x-tar"):
883N/A print >> sys.stderr, "Unable to retrieve %s.\n" \
883N/A "Please retrieve the file " \
883N/A "and place it at: %s\n" % (swurl, swarc)
883N/A # remove a partial download or error message from proxy
883N/A remove_sw(swname)
883N/A sys.exit(1)
1099N/A if not os.path.exists(swdir):
1099N/A if not hash_sw(swname, swarc, swhash):
1099N/A sys.exit(1)
1099N/A
1099N/A print "unpacking %s" % swname
1516N/A tar = tarfile.open(swarc)
1265N/A # extractall doesn't exist until python 2.5
1099N/A for m in tar.getmembers():
1099N/A tar.extract(m, extern_dir)
1099N/A tar.close()
1099N/A
1099N/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):
1099N/A patches = os.listdir(patchdir)
1099N/A for p in patches:
1208N/A patchpath = os.path.join(os.path.pardir,
1208N/A os.path.pardir, patchdir, p)
1099N/A print "Applying %s to %s" % (p, swname)
1099N/A args = ["patch", "-d", swdir, "-i", patchpath, "-p0"]
1391N/A if osname == "windows":
1099N/A args.append("--binary")
1099N/A ret = subprocess.Popen(args).wait()
1099N/A if ret != 0:
1099N/A print >> sys.stderr, \
1099N/A "patch failed and returned %d." % ret
465N/A print >> sys.stderr, \
465N/A "Command was: %s" % " ".join(args)
395N/A sys.exit(1)
465N/A file(already_patched, "w").close()
395N/A
395N/A swinst_dir = os.path.join(root_dir, py_install_dir, swidir)
2176N/A if not os.path.exists(swinst_dir):
1208N/A print "installing %s" % swname
1208N/A args = ['python', 'setup.py', 'install',
465N/A '--root=%s' % root_dir,
395N/A '--install-lib=%s' % py_install_dir,
465N/A '--install-data=%s' % py_install_dir]
395N/A ret = subprocess.Popen(args, cwd = swdir).wait()
465N/A if ret != 0:
1099N/A print >> sys.stderr, \
1099N/A "install failed and returned %d." % ret
1099N/A print >> sys.stderr, \
465N/A "Command was: %s" % " ".join(args)
465N/A sys.exit(1)
395N/A
395N/A
1099N/Adef remove_sw(swname):
395N/A print("deleting %s" % swname)
1191N/A for file in os.listdir(extern_dir):
1191N/A if fnmatch.fnmatch(file, "%s*" % swname):
1191N/A fpath = os.path.join(extern_dir, file)
1191N/A if os.path.isfile(fpath):
1191N/A os.unlink(fpath)
1191N/A else:
1191N/A shutil.rmtree(fpath, True)
1191N/A
1191N/Aclass build_func(_build):
1191N/A def initialize_options(self):
1265N/A _build.initialize_options(self)
1265N/A self.build_base = build_dir
1265N/A
1208N/Adef get_hg_version():
1208N/A try:
1208N/A p = subprocess.Popen(['hg', 'id', '-i'], stdout = subprocess.PIPE)
1208N/A return p.communicate()[0].strip()
1208N/A except OSError:
1208N/A print >> sys.stderr, "ERROR: unable to obtain mercurial version"
1208N/A return "unknown"
1191N/A
1191N/Adef syntax_check(filename):
1391N/A """ Run python's compiler over the file, and discard the results.
1391N/A Arrange to generate an exception if the file does not compile.
1391N/A This is needed because distutil's own use of pycompile (in the
1391N/A distutils.utils module) is broken, and doesn't stop on error. """
1391N/A try:
1391N/A py_compile.compile(filename, os.devnull, doraise=True)
1391N/A except py_compile.PyCompileError, e:
1394N/A raise DistutilsError("%s: failed syntax check: %s" %
1394N/A (filename, e))
1391N/A
1391N/A
1391N/Aclass build_py_func(_build_py):
1391N/A # override the build_module method to do VERSION substitution on pkg/__init__.py
1391N/A def build_module (self, module, module_file, package):
1391N/A
1391N/A if module == "__init__" and package == "pkg":
1660N/A versionre = '(?m)^VERSION[^"]*"([^"]*)"'
1391N/A # Grab the previously-built version out of the build
465N/A # tree.
1660N/A try:
1660N/A ocontent = \
1660N/A file(self.get_module_outfile(self.build_lib,
1660N/A [package], module)).read()
465N/A ov = re.search(versionre, ocontent).group(1)
465N/A except IOError:
1516N/A ov = None
498N/A v = get_hg_version()
498N/A vstr = 'VERSION = "%s"' % v
849N/A # If the versions haven't changed, there's no need to
1660N/A # recompile.
1391N/A if v == ov:
1660N/A return
1660N/A
1660N/A mcontent = file(module_file).read()
1660N/A mcontent = re.sub(versionre, vstr, mcontent)
849N/A tmpfd, tmp_file = tempfile.mkstemp()
1208N/A os.write(tmpfd, mcontent)
1208N/A os.close(tmpfd)
1208N/A print "doing version substitution: ", v
1208N/A rv = _build_py.build_module(self, module, tmp_file, package)
849N/A os.unlink(tmp_file)
290N/A return rv
465N/A
465N/A # Will raise a DistutilsError on failure.
1099N/A syntax_check(module_file)
465N/A
1099N/A return _build_py.build_module(self, module, module_file, package)
1099N/A
1099N/Aclass clean_func(_clean):
454N/A def initialize_options(self):
1099N/A _clean.initialize_options(self)
849N/A self.build_base = build_dir
290N/A
430N/Aclass clobber_func(Command):
395N/A user_options = []
395N/A description = "Deletes any and all files created by setup"
290N/A
383N/A def initialize_options(self):
383N/A pass
395N/A def finalize_options(self):
383N/A pass
383N/A def run(self):
384N/A # nuke everything
383N/A print("deleting " + dist_dir)
849N/A shutil.rmtree(dist_dir, True)
849N/A print("deleting " + build_dir)
849N/A shutil.rmtree(build_dir, True)
849N/A print("deleting " + root_dir)
849N/A shutil.rmtree(root_dir, True)
849N/A print("deleting " + pkgs_dir)
849N/A shutil.rmtree(pkgs_dir, True)
849N/A print("deleting " + extern_dir)
849N/A shutil.rmtree(extern_dir, True)
2242N/A
2242N/Aclass test_func(Command):
2242N/A # NOTE: these options need to be in sync with tests/run.py and the
2242N/A # list of options stored in initialize_options below. The first entry
2242N/A # in each tuple must be the exact name of a member variable.
2242N/A user_options = [("verbosemode", 'v', "run tests in verbose mode"),
2242N/A ("genbaseline", 'g', "generate test baseline"),
2242N/A ("parseable", 'p', "parseable output"),
2242N/A ("timing", "t", "timing file <file>"),
2242N/A ("baselinefile=", 'b', "baseline file <file>"),
2242N/A ("only=", "o", "only <regex>")]
2242N/A description = "Runs unit and functional tests"
849N/A
849N/A def initialize_options(self):
383N/A self.only = ""
383N/A self.baselinefile = ""
383N/A self.verbosemode = 0
849N/A self.parseable = 0
383N/A self.genbaseline = 0
422N/A self.timing = 0
422N/A
422N/A def finalize_options(self):
422N/A pass
422N/A
422N/A def run(self):
422N/A
422N/A os.putenv('PYEXE', sys.executable)
422N/A os.chdir(os.path.join(pwd, "tests"))
422N/A
422N/A # Reconstruct the cmdline and send that to run.py
422N/A cmd = [sys.executable, "run.py"]
422N/A args = ""
422N/A if "test" in sys.argv:
422N/A args = sys.argv[sys.argv.index("test")+1:]
422N/A cmd.extend(args)
422N/A subprocess.call(cmd)
383N/A
422N/Aclass dist_func(_bdist):
383N/A def initialize_options(self):
383N/A _bdist.initialize_options(self)
383N/A self.dist_dir = dist_dir
383N/A
383N/A
383N/A# These are set to real values based on the platform, down below
383N/Acompile_args = None
422N/Alink_args = None
849N/Aext_modules = [
849N/A Extension(
849N/A 'actions._actions',
383N/A _actions_srcs,
383N/A include_dirs = include_dirs,
290N/A extra_compile_args = compile_args,
430N/A extra_link_args = link_args
395N/A ),
395N/A ]
290N/Aelf_libraries = None
290N/Adata_files = web_files
290N/Acmdclasses = {
290N/A 'install': install_func,
290N/A 'build': build_func,
290N/A 'build_py': build_py_func,
290N/A 'bdist': dist_func,
290N/A 'lint': lint_func,
290N/A 'clean': clean_func,
290N/A 'clobber': clobber_func,
290N/A 'coverage': cov_func,
395N/A 'test': test_func,
290N/A }
395N/A
290N/A# all builds of IPS should have manpages
395N/Adata_files += [
290N/A (man1_dir, man1_files),
534N/A (man1m_dir, man1m_files),
534N/A (man5_dir, man5_files),
1099N/A ]
1099N/A
290N/Aif osname == 'sunos':
290N/A # Solaris-specific extensions are added here
1101N/A data_files += [
1101N/A (zones_dir, zones_files),
1101N/A (brand_dir, brand_files),
1513N/A (smf_dir, smf_files),
1715N/A ]
1513N/A
1513N/Aif osname == 'sunos' or osname == "linux":
448N/A # Unix platforms which the elf extension has been ported to
1513N/A # are specified here, so they are built automatically
448N/A elf_libraries = ['elf']
1101N/A ext_modules += [
1513N/A Extension(
1715N/A 'elf',
1715N/A elf_srcs,
1716N/A include_dirs = include_dirs,
1715N/A libraries = elf_libraries,
1715N/A extra_compile_args = compile_args,
1513N/A extra_link_args = link_args
290N/A ),
290N/A ]
290N/A
448N/A # Solaris has built-in md library and Solaris-specific arch extension
448N/A # All others use OpenSSL and cross-platform arch module
430N/A if osname == 'sunos':
448N/A elf_libraries += [ 'md' ]
430N/A ext_modules += [
1101N/A Extension(
1513N/A 'arch',
1715N/A arch_srcs,
1715N/A include_dirs = include_dirs,
1716N/A extra_compile_args = compile_args,
1715N/A extra_link_args = link_args,
1715N/A define_macros = [('_FILE_OFFSET_BITS', '64')]
1101N/A ),
290N/A Extension(
290N/A 'pspawn',
1101N/A pspawn_srcs,
290N/A include_dirs = include_dirs,
1101N/A extra_compile_args = compile_args,
290N/A extra_link_args = link_args,
290N/A define_macros = [('_FILE_OFFSET_BITS', '64')]
290N/A ),
448N/A ]
448N/A else:
448N/A elf_libraries += [ 'ssl' ]
448N/A
448N/Asetup(cmdclass = cmdclasses,
430N/A name = 'ips',
448N/A version = '1.0',
290N/A package_dir = {'pkg':'modules'},
290N/A packages = packages,
290N/A data_files = data_files,
430N/A ext_package = 'pkg',
395N/A ext_modules = ext_modules,
290N/A )
2180N/A