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