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