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