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