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