setup.py revision 1716
1516N/A#!/usr/bin/python2.6
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 2010 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 hashlib
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/Aosname = platform.uname()[0].lower()
290N/Aostype = arch = 'unknown'
290N/Aif osname == 'sunos':
2535N/A arch = platform.processor()
2535N/A ostype = "posix"
290N/Aelif osname == 'linux':
290N/A arch = "linux_" + platform.machine()
2508N/A ostype = "posix"
2508N/Aelif osname == 'windows':
290N/A arch = osname
1660N/A ostype = "windows"
1660N/Aelif osname == 'darwin':
1660N/A arch = osname
1660N/A ostype = "posix"
1660N/Aelif osname == 'aix':
1660N/A arch = "aix"
1660N/A ostype = "posix"
1660N/A
1660N/A# 3rd party software required for the build
1660N/ACP = 'CherryPy'
1660N/ACPIDIR = 'cherrypy'
1660N/ACPVER = '3.1.2'
1660N/ACPARC = '%s-%s.tar.gz' % (CP, CPVER)
1660N/ACPDIR = '%s-%s' % (CP, CPVER)
1660N/ACPURL = 'http://download.cherrypy.org/cherrypy/%s/%s' % (CPVER, CPARC)
1660N/ACPHASH = 'a94aedfd0e675858dbcc32dd250c23d285ee9b88'
1660N/A
1660N/APO = 'pyOpenSSL'
448N/APOIDIR = 'OpenSSL'
448N/APOVER = '0.7'
2828N/APOARC = '%s-%s.tar.gz' % (PO, POVER)
2828N/APODIR = '%s-%s' % (PO, POVER)
2828N/APOURL = 'http://downloads.sourceforge.net/pyopenssl/%s' % (POARC)
534N/APOHASH = 'bd072fef8eb36241852d25a9161282a051f0a63e'
534N/A
534N/ACOV = 'coveragepy'
534N/ACOVIDIR = 'coverage'
534N/ACOVVER = 'coverage-3.2b2'
534N/ACOVARC = '%s-%s.tar.bz2' % (COV, COVVER)
534N/ACOVDIR = '%s' % COV
290N/ACOVURL = 'http://bitbucket.org/ned/%s/get/%s.tar.bz2' % (COV, COVVER)
290N/A# No hash, since we always fetch the latest
954N/ACOVHASH = None
954N/A
954N/ALDTP = 'ldtp'
954N/ALDTPIDIR = 'ldtp'
534N/ALDTPVER = '1.7.1'
1099N/ALDTPMINORVER = '1.7.x'
290N/ALDTPMAJORVER = '1.x'
3117N/ALDTPARC = '%s-%s.tar.gz' % (LDTP, LDTPVER)
3117N/ALDTPDIR = '%s-%s' % (LDTP, LDTPVER)
3117N/ALDTPURL = 'http://download.freedesktop.org/ldtp/%s/%s/%s' % \
3117N/A (LDTPMAJORVER, LDTPMINORVER, LDTPARC)
290N/ALDTPHASH = 'd31213d2b1449a0dadcace723b9ff7041169f7ce'
290N/A
290N/AMAKO = 'Mako'
661N/AMAKOIDIR = 'mako'
2867N/AMAKOVER = '0.2.2'
290N/AMAKOARC = '%s-%s.tar.gz' % (MAKO, MAKOVER)
2494N/AMAKODIR = '%s-%s' % (MAKO, MAKOVER)
2494N/AMAKOURL = 'http://www.makotemplates.org/downloads/%s' % (MAKOARC)
2494N/AMAKOHASH = '85c04ab3a6a26a1cab47067449712d15a8b29790'
2516N/A
2516N/APLY = 'ply'
2516N/APLYIDIR = 'ply'
2516N/APLYVER = '3.1'
2516N/APLYARC = '%s-%s.tar.gz' % (PLY, PLYVER)
2516N/APLYDIR = '%s-%s' % (PLY, PLYVER)
2516N/APLYURL = 'http://www.dabeaz.com/ply/%s' % (PLYARC)
290N/APLYHASH = '38efe9e03bc39d40ee73fa566eb9c1975f1a8003'
2523N/A
3138N/APC = 'pycurl'
2390N/APCIDIR = 'curl'
1498N/APCVER = '7.19.0'
1498N/APCARC = '%s-%s.tar.gz' % (PC, PCVER)
2867N/APCDIR = '%s-%s' % (PC, PCVER)
2310N/APCURL = 'http://pycurl.sourceforge.net/download/%s' % PCARC
2310N/APCHASH = '3fb59eca1461331bb9e9e8d6fe3b23eda961a416'
2310N/APCENVIRON = {}
2852N/Aif osname in ("sunos", "linux", "darwin"):
2852N/A PCENVIRON = {'CFLAGS': '-O3'}
2852N/A
2852N/Apwd = os.path.normpath(sys.path[0])
2535N/A
2867N/A#
2867N/A# Unbuffer stdout and stderr. This helps to ensure that subprocess output
2310N/A# is properly interleaved with output from this program.
290N/A#
1674N/Asys.stdout = os.fdopen(sys.stdout.fileno(), "w", 0)
1674N/Asys.stderr = os.fdopen(sys.stderr.fileno(), "w", 0)
2262N/A
1674N/Adist_dir = os.path.normpath(os.path.join(pwd, os.pardir, "proto", "dist_" + arch))
395N/Abuild_dir = os.path.normpath(os.path.join(pwd, os.pardir, "proto", "build_" + arch))
430N/Aif "ROOT" in os.environ and os.environ["ROOT"] != "":
395N/A root_dir = os.environ["ROOT"]
1544N/Aelse:
1968N/A root_dir = os.path.normpath(os.path.join(pwd, os.pardir, "proto", "root_" + arch))
1557N/Apkgs_dir = os.path.normpath(os.path.join(pwd, os.pardir, "packages", arch))
1903N/Aextern_dir = os.path.normpath(os.path.join(pwd, "extern"))
2046N/A
2240N/Acacert_dir = os.path.normpath(os.path.join(pwd, "cacert"))
1506N/Acacert_install_dir = 'usr/share/pkg/cacert'
2928N/A
395N/Apy_install_dir = 'usr/lib/python2.6/vendor-packages'
395N/A
2026N/Ascripts_dir = 'usr/bin'
395N/Alib_dir = 'usr/lib'
395N/Asvc_method_dir = 'lib/svc/method'
395N/A
2310N/Aman1_dir = 'usr/share/man/cat1'
2852N/Aman1m_dir = 'usr/share/man/cat1m'
395N/Aman5_dir = 'usr/share/man/cat5'
661N/Aresource_dir = 'usr/share/lib/pkg'
2867N/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'
2852N/Aauthattrd_dir = 'etc/security/auth_attr.d'
2310N/A
2867N/A# A list of source, destination tuples of modules which should be hardlinked
2867N/A# together if the os supports it and otherwise copied.
2867N/Ahardlink_modules = [
661N/A ("%s/pkg/flavor/depthlimitedmf24" % py_install_dir,
395N/A "%s/pkg/flavor/depthlimitedmf25" % py_install_dir)
849N/A]
290N/A
395N/Ascripts_sunos = {
395N/A scripts_dir: [
1968N/A ['client.py', 'pkg'],
395N/A ['pkgdep.py', 'pkgdepend'],
395N/A ['util/publish/pkgdiff.py', 'pkgdiff'],
395N/A ['util/publish/pkgmogrify.py', 'pkgmogrify'],
395N/A ['publish.py', 'pkgsend'],
395N/A ['pull.py', 'pkgrecv'],
395N/A ['packagemanager.py', 'packagemanager'],
395N/A ['updatemanager.py', 'pm-updatemanager'],
395N/A ],
395N/A lib_dir: [
395N/A ['depot.py', 'pkg.depotd'],
395N/A ['updatemanagernotifier.py', 'updatemanagernotifier'],
290N/A ['checkforupdates.py', 'pm-checkforupdates'],
290N/A ['launch.py', 'pm-launch'],
395N/A ],
395N/A svc_method_dir: [
1231N/A ['svc/svc-pkg-depot', 'svc-pkg-depot'],
1557N/A ],
1903N/A }
1557N/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'],
395N/A ['scripts/pkgrecv.bat', 'pkgrecv.bat'],
395N/A ],
395N/A lib_dir: [
395N/A ['depot.py', 'depot.py'],
290N/A ['scripts/pkg.depotd.bat', 'pkg.depotd.bat'],
290N/A ],
430N/A }
395N/A
395N/Ascripts_other_unix = {
395N/A scripts_dir: [
395N/A ['client.py', 'client.py'],
1302N/A ['pkgdep.py', 'pkgdep'],
395N/A ['util/publish/pkgdiff.py', 'pkgdiff'],
395N/A ['util/publish/pkgmogrify.py', 'pkgmogrify'],
290N/A ['pull.py', 'pull.py'],
3139N/A ['publish.py', 'publish.py'],
3139N/A ['scripts/pkg.sh', 'pkg'],
395N/A ['scripts/pkgsend.sh', 'pkgsend'],
3139N/A ['scripts/pkgrecv.sh', 'pkgrecv'],
3139N/A ],
3139N/A lib_dir: [
3139N/A ['depot.py', 'depot.py'],
3139N/A ['scripts/pkg.depotd.sh', 'pkg.depotd'],
3139N/A ],
3139N/A }
3139N/A
3139N/A# indexed by 'osname'
3139N/Ascripts = {
3139N/A "sunos": scripts_sunos,
3139N/A "linux": scripts_other_unix,
3139N/A "windows": scripts_windows,
3139N/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/pkgdepend.1',
3139N/A 'man/pkgdiff.1',
3139N/A 'man/pkgmogrify.1',
395N/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'
2516N/A ]
2516N/Aman5_files = [
3139N/A 'man/pkg.5'
3139N/A ]
3139N/Apackages = [
3139N/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',
3139N/A 'pkg.publish',
3139N/A 'pkg.server'
3139N/A ]
3139N/A
2516N/Aweb_files = []
3139N/Afor entry in os.walk("web"):
3139N/A web_dir, dirs, files = entry
3139N/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
2516N/A if f != "Makefile"
3139N/A ]))
3139N/A
3139N/Azones_files = [
3139N/A 'brand/SUNWipkg.xml',
3139N/A ]
2516N/Abrand_files = [
2516N/A 'brand/pkgcreatezone',
3139N/A 'brand/attach',
3139N/A 'brand/clone',
3139N/A 'brand/detach',
3139N/A 'brand/prestate',
3139N/A 'brand/poststate',
3139N/A 'brand/uninstall',
3139N/A 'brand/common.ksh',
3139N/A ]
3139N/Aetcbrand_files = [
3139N/A 'brand/pkgrm.conf',
3139N/A 'brand/smf_disable.conf',
3139N/A ]
3139N/Asmf_files = [
3139N/A 'svc/pkg-server.xml',
3139N/A 'svc/pkg-update.xml',
2516N/A ]
3139N/Aexecattrd_files = ['util/misc/exec_attr.d/SUNWipkg']
3139N/Aauthattrd_files = ['util/misc/auth_attr.d/SUNWipkg']
3139N/Apspawn_srcs = [
3139N/A 'modules/pspawn.c'
3139N/A ]
3139N/Aelf_srcs = [
2516N/A 'modules/elf.c',
3139N/A 'modules/elfextract.c',
3139N/A 'modules/liblist.c',
3139N/A ]
3139N/Aarch_srcs = [
3139N/A 'modules/arch.c'
2516N/A ]
395N/A_actions_srcs = [
395N/A 'modules/actions/_actions.c'
395N/A ]
395N/Asolver_srcs = [
395N/A 'modules/solver/solver.c',
2339N/A 'modules/solver/py_solver.c'
1191N/A ]
1452N/Asolver_link_args = ["-lm", "-lc"]
1231N/Aif osname == 'sunos':
2046N/A solver_link_args = ["-ztext"] + solver_link_args
395N/A
395N/Ainclude_dirs = [ 'modules' ]
424N/Alint_flags = [ '-u', '-axms', '-erroff=E_NAME_DEF_NOT_USED2' ]
395N/A
742N/A# Runs lint on the extension module source code
2339N/Aclass lint_func(Command):
2339N/A description = "Runs various lint tools over IPS extension source code"
2693N/A user_options = []
2690N/A
2339N/A def initialize_options(self):
3094N/A pass
2339N/A
2690N/A def finalize_options(self):
2690N/A pass
2693N/A
2693N/A # Make string shell-friendly
2690N/A @staticmethod
2690N/A def escape(astring):
2339N/A return astring.replace(' ', '\\ ')
2339N/A
742N/A def run(self):
742N/A # assumes lint is on the $PATH
742N/A if osname == 'sunos' or osname == "linux":
742N/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] + \
3136N/A ['-I' + self.escape(get_python_inc())] + \
2688N/A ["%s%s" % ("-l", k) for k in elf_libraries] + \
2688N/A elf_srcs
2688N/A _actionscmd = ['lint'] + lint_flags + \
2688N/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())] + \
742N/A pspawn_srcs
2310N/A
2852N/A print(" ".join(archcmd))
1902N/A os.system(" ".join(archcmd))
2867N/A print(" ".join(elfcmd))
2867N/A os.system(" ".join(elfcmd))
1099N/A print(" ".join(_actionscmd))
2867N/A os.system(" ".join(_actionscmd))
2338N/A print(" ".join(pspawncmd))
2338N/A os.system(" ".join(pspawncmd))
2310N/A
2046N/A proto = os.path.join(root_dir, py_install_dir)
2223N/A sys.path.insert(0, proto)
2046N/A
2046N/A # Insert tests directory onto sys.path so any custom checkers
2523N/A # can be found.
2523N/A sys.path.insert(0, os.path.join(pwd, 'tests'))
2523N/A print(sys.path)
2523N/A
2523N/A # assumes pylint is accessible on the sys.path
2523N/A from pylint import lint
2310N/A scriptlist = [ 'setup.py' ]
2677N/A for d, m in scripts_sunos.items():
2310N/A for a in m:
2310N/A # specify the filenames of the scripts, in addition
2310N/A # to the package names themselves
2310N/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
2858N/A # rcfile, does not work, so we put it here instead, to load
2310N/A # our custom checkers.
2852N/A lint.Run(['--load-plugins=multiplatform', '--rcfile',
2852N/A os.path.join(pwd, 'tests', 'pylintrc')] +
2852N/A scriptlist + packages)
2852N/A
3136N/Aclass install_func(_install):
2852N/A def initialize_options(self):
2852N/A _install.initialize_options(self)
2852N/A
2852N/A # PRIVATE_BUILD set in the environment tells us to put the build
2858N/A # directory into the .pyc files, rather than the final
2852N/A # installation directory.
3138N/A private_build = os.getenv("PRIVATE_BUILD", None)
3138N/A
2852N/A if private_build is None:
2852N/A self.install_lib = py_install_dir
2852N/A self.install_data = os.path.sep
2508N/A self.root = root_dir
2508N/A else:
2508N/A self.install_lib = os.path.join(root_dir, py_install_dir)
2508N/A self.install_data = root_dir
2867N/A
2535N/A # This is used when installing scripts, below, but it isn't a
2535N/A # standard distutils variable.
2535N/A self.root_dir = root_dir
3053N/A
3053N/A def run(self):
3053N/A """
3026N/A At the end of the install function, we need to rename some files
3026N/A because distutils provides no way to rename files as they are
3026N/A placed in their install locations.
2339N/A Also, make sure that cherrypy and other external dependencies
2339N/A are installed.
2339N/A """
691N/A for f in man1_files + man1m_files + man5_files:
691N/A file_util.copy_file(f + ".txt", f, update=1)
691N/A
395N/A _install.run(self)
395N/A
395N/A for o_src, o_dest in hardlink_modules:
395N/A for e in [".py", ".pyc"]:
395N/A src = util.change_root(self.root_dir, o_src + e)
290N/A dest = util.change_root(
395N/A self.root_dir, o_dest + e)
395N/A if ostype == "posix":
591N/A if os.path.exists(dest) and \
591N/A os.stat(src)[stat.ST_INO] != \
591N/A os.stat(dest)[stat.ST_INO]:
2639N/A os.remove(dest)
2639N/A file_util.copy_file(src, dest,
2639N/A link="hard", update=1)
2639N/A else:
2639N/A file_util.copy_file(src, dest, update=1)
2639N/A
1505N/A for d, files in scripts[osname].iteritems():
2516N/A for (srcname, dstname) in files:
1505N/A dst_dir = util.change_root(self.root_dir, d)
1505N/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)
1632N/A file_util.copy_file(srcname, dst_path, update = True)
1632N/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()
2339N/A os.environ["LDFLAGS"] = os.environ.get("LDFLAGS", "") + \
2339N/A " -lsocket -lnsl"
2364N/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, extra_env=PCENVIRON)
2828N/A prep_sw(COV, COVARC, COVDIR, COVURL, COVHASH)
2828N/A install_sw(COV, COVDIR, COVIDIR)
2828N/A
2892N/A # Remove some bits that we're not going to package, but be sure
2892N/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)
3158N/A try:
3158N/A os.remove(os.path.join(root_dir, "usr/bin/mako-render"))
2828N/A except EnvironmentError, e:
2828N/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 = hashlib.sha1()
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
2339N/A else:
2339N/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))
2364N/A dn, copied = file_util.copy_file(srcname, findir, update = True)
2364N/A
2339N/A if not copied:
395N/A continue
395N/A
290N/A # Call openssl to create hash symlink
290N/A cmd = ["openssl", "x509", "-noout", "-hash", "-in",
2339N/A srcname]
2339N/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)
290N/A if os.path.exists(hashpath):
290N/A os.unlink(hashpath)
395N/A if hasattr(os, "symlink"):
395N/A os.symlink(f, hashpath)
290N/A else:
290N/A file_util.copy_file(srcname, hashpath)
2674N/A
2674N/Adef prep_sw(swname, swarc, swdir, swurl, swhash):
2674N/A swarc = os.path.join(extern_dir, swarc)
2674N/A swdir = os.path.join(extern_dir, swdir)
290N/A if not os.path.exists(extern_dir):
2674N/A os.mkdir(extern_dir)
2674N/A
3158N/A if not os.path.exists(swarc):
395N/A print "downloading %s" % swname
395N/A try:
2674N/A fname, hdr = urllib.urlretrieve(swurl, swarc)
3158N/A except IOError:
395N/A pass
3158N/A if not os.path.exists(swarc) or \
395N/A (hdr.gettype() != "application/x-gzip" and
2674N/A hdr.gettype() != "application/x-tar"):
3158N/A print >> sys.stderr, "Unable to retrieve %s.\n" \
591N/A "Please retrieve the file " \
591N/A "and place it at: %s\n" % (swurl, swarc)
2674N/A # remove a partial download or error message from proxy
3158N/A remove_sw(swname)
2639N/A sys.exit(1)
2639N/A if not os.path.exists(swdir):
2674N/A if not hash_sw(swname, swarc, swhash):
3158N/A sys.exit(1)
2639N/A
2639N/A print "unpacking %s" % swname
2674N/A tar = tarfile.open(swarc)
2674N/A # extractall doesn't exist until python 2.5
3158N/A for m in tar.getmembers():
691N/A tar.extract(m, extern_dir)
691N/A tar.close()
2674N/A
2674N/A # If there are patches, apply them now.
3158N/A patchdir = os.path.join("patch", swname)
2339N/A already_patched = os.path.join(swdir, ".patched")
2339N/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:
3158N/A patchpath = os.path.join(os.path.pardir,
3026N/A os.path.pardir, patchdir, p)
3158N/A print "Applying %s to %s" % (p, swname)
3026N/A args = ["patch", "-d", swdir, "-i", patchpath, "-p0"]
3053N/A if osname == "windows":
3053N/A args.append("--binary")
3158N/A ret = subprocess.Popen(args).wait()
3053N/A if ret != 0:
3158N/A print >> sys.stderr, \
3053N/A "patch failed and returned %d." % ret
290N/A print >> sys.stderr, \
290N/A "Command was: %s" % " ".join(args)
290N/A sys.exit(1)
290N/A file(already_patched, "w").close()
290N/A
591N/Adef install_ldtp(swname, swdir, swidir):
591N/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):
2639N/A print "installing %s" % swname
2639N/A args_config = ['./configure',
691N/A '--prefix=/usr',
691N/A '--bindir=/usr/bin',
2339N/A 'PYTHONPATH=""',
2339N/A ]
3026N/A args_make_install = ['make', 'install',
3026N/A 'DESTDIR=%s' % root_dir
3053N/A ]
3053N/A run_cmd(args_config, swdir)
290N/A run_cmd(args_make_install, swdir)
290N/A
2339N/Adef install_sw(swname, swdir, swidir, extra_env=None):
2339N/A swdir = os.path.join(extern_dir, swdir)
2339N/A swinst_dir = os.path.join(root_dir, py_install_dir, swidir)
2339N/A inst_env = os.environ.copy()
2339N/A if extra_env:
2339N/A inst_env.update(extra_env)
2339N/A
290N/A if not os.path.exists(swinst_dir):
2339N/A print "installing %s" % swname
2339N/A args = ['python2.6', 'setup.py', 'install',
290N/A '--root=%s' % root_dir,
2339N/A '--install-lib=%s' % py_install_dir,
2339N/A '--install-data=%s' % py_install_dir]
2339N/A run_cmd(args, swdir, env=inst_env)
2339N/A
2339N/Adef run_cmd(args, swdir, env=None):
2339N/A if env is None:
2339N/A env = os.environ
2339N/A ret = subprocess.Popen(args, cwd=swdir, env=env).wait()
290N/A if ret != 0:
395N/A print >> sys.stderr, \
290N/A "install failed and returned %d." % ret
395N/A print >> sys.stderr, \
506N/A "Command was: %s" % " ".join(args)
506N/A sys.exit(1)
506N/A
506N/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)
834N/A if os.path.isfile(fpath):
506N/A os.unlink(fpath)
506N/A else:
506N/A shutil.rmtree(fpath, True)
513N/A
506N/Aclass build_func(_build):
506N/A def initialize_options(self):
506N/A _build.initialize_options(self)
506N/A self.build_base = build_dir
290N/A
290N/Adef get_hg_version():
2535N/A try:
2535N/A p = subprocess.Popen(['hg', 'id', '-i'], stdout = subprocess.PIPE)
2535N/A return p.communicate()[0].strip()
395N/A except OSError:
413N/A print >> sys.stderr, "ERROR: unable to obtain mercurial version"
395N/A return "unknown"
290N/A
1674N/Adef syntax_check(filename):
1674N/A """ Run python's compiler over the file, and discard the results.
1674N/A Arrange to generate an exception if the file does not compile.
1674N/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):
3117N/A
3117N/A if module == "__init__" and package == "pkg":
3117N/A versionre = '(?m)^VERSION[^"]*"([^"]*)"'
395N/A # Grab the previously-built version out of the build
395N/A # tree.
506N/A try:
506N/A ocontent = \
395N/A file(self.get_module_outfile(self.build_lib,
2535N/A [package], module)).read()
2535N/A ov = re.search(versionre, ocontent).group(1)
395N/A except IOError:
430N/A ov = None
849N/A v = get_hg_version()
834N/A vstr = 'VERSION = "%s"' % v
290N/A # If the versions haven't changed, there's no need to
2561N/A # recompile.
2561N/A if v == ov:
2561N/A return
2561N/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):
2535N/A def initialize_options(self):
2535N/A _clean.initialize_options(self)
2535N/A self.build_base = build_dir
2535N/A
2535N/Aclass clobber_func(Command):
1099N/A user_options = []
2535N/A description = "Deletes any and all files created by setup"
2535N/A
2535N/A def initialize_options(self):
2535N/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)
1099N/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)
2535N/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 ("archivedir=", 'a', "archive failed tests <dir>"),
2535N/A ("baselinefile=", 'b', "baseline file <file>"),
2535N/A ("coverage", "c", "collect code coverage data"),
2535N/A ("genbaseline", 'g', "generate test baseline"),
1099N/A ("only=", "o", "only <regex>"),
2826N/A ("parseable", 'p', "parseable output"),
2688N/A ("timing", "t", "timing file <file>"),
2688N/A ("verbosemode", 'v', "run tests in verbose mode"),
2688N/A ("stoponerr", 'x', "stop when a baseline mismatch occurs"),
2688N/A ("debugoutput", 'd', "emit debugging output"),
2688N/A ("showonexpectedfail", 'f',
2688N/A "show all failure info, even for expected fails"),
1660N/A ("startattest=", 's', "start at indicated test"),
2688N/A ]
2688N/A description = "Runs unit and functional tests"
2688N/A
2826N/A def initialize_options(self):
2826N/A self.only = ""
2688N/A self.baselinefile = ""
2688N/A self.verbosemode = 0
2688N/A self.parseable = 0
2688N/A self.genbaseline = 0
2688N/A self.timing = 0
849N/A self.coverage = 0
2688N/A self.stoponerr = 0
2688N/A self.debugoutput = 0
3158N/A self.showonexpectedfail = 0
3143N/A self.startattest = ""
3158N/A self.archivedir = ""
3143N/A
3158N/A def finalize_options(self):
849N/A pass
2688N/A
2688N/A def run(self):
290N/A
2535N/A os.putenv('PYEXE', sys.executable)
2535N/A os.chdir(os.path.join(pwd, "tests"))
2597N/A
2597N/A # Reconstruct the cmdline and send that to run.py
2597N/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:]
2535N/A cmd.extend(args)
2535N/A subprocess.call(cmd)
2535N/A
2535N/Aclass dist_func(_bdist):
2535N/A def initialize_options(self):
2535N/A _bdist.initialize_options(self)
2535N/A self.dist_dir = dist_dir
2535N/A
2535N/A
3158N/A# These are set to real values based on the platform, down below
2535N/Acompile_args = None
2535N/Aif osname in ("sunos", "linux", "darwin"):
2535N/A compile_args = [ "-O3" ]
2535N/Alink_args = None
2535N/Aext_modules = [
2535N/A Extension(
2597N/A 'actions._actions',
2597N/A _actions_srcs,
2597N/A include_dirs = include_dirs,
2597N/A extra_compile_args = compile_args,
2597N/A extra_link_args = link_args
2597N/A ),
2597N/A Extension(
2597N/A 'solver',
2597N/A solver_srcs,
2597N/A include_dirs = include_dirs + ["."],
2597N/A extra_compile_args = compile_args,
2597N/A extra_link_args = solver_link_args,
2597N/A define_macros = [('_FILE_OFFSET_BITS', '64')]
2597N/A ),
2597N/A ]
2597N/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,
2688N/A 'bdist': dist_func,
2688N/A 'lint': lint_func,
2688N/A 'clean': clean_func,
2688N/A 'clobber': clobber_func,
2688N/A 'test': test_func,
2688N/A }
2688N/A
2688N/A# all builds of IPS should have manpages
2688N/Adata_files += [
2688N/A (man1_dir, man1_files),
2688N/A (man1m_dir, man1m_files),
3143N/A (man5_dir, man5_files),
2688N/A ]
2688N/A
2688N/Aif osname == 'sunos':
2688N/A # Solaris-specific extensions are added here
3143N/A data_files += [
3143N/A (zones_dir, zones_files),
2688N/A (brand_dir, brand_files),
3143N/A (etcbrand_dir, etcbrand_files),
2688N/A (smf_dir, smf_files),
3158N/A (execattrd_dir, execattrd_files),
3143N/A (authattrd_dir, authattrd_files),
2688N/A ]
3143N/A
3143N/Aif osname == 'sunos' or osname == "linux":
3136N/A # Unix platforms which the elf extension has been ported to
3136N/A # are specified here, so they are built automatically
3143N/A elf_libraries = ['elf']
2688N/A ext_modules += [
2688N/A Extension(
2688N/A 'elf',
3143N/A elf_srcs,
3143N/A include_dirs = include_dirs,
3143N/A libraries = elf_libraries,
2688N/A extra_compile_args = compile_args,
3143N/A extra_link_args = link_args
2688N/A ),
3158N/A ]
3158N/A
3158N/A # Solaris has built-in md library and Solaris-specific arch extension
2688N/A # All others use OpenSSL and cross-platform arch module
3143N/A if osname == 'sunos':
3143N/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',
3143N/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 ),
3143N/A ]
2688N/A else:
2688N/A elf_libraries += [ 'ssl' ]
2535N/A
2535N/Asetup(cmdclass = cmdclasses,
2535N/A name = 'pkg',
2535N/A version = '0.1',
2535N/A package_dir = {'pkg':'modules'},
2535N/A packages = packages,
2535N/A data_files = data_files,
2535N/A ext_package = 'pkg',
3143N/A ext_modules = ext_modules,
2688N/A )
2535N/A