setup.py revision 1099
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/AMAKO = 'Mako'
3339N/AMAKOIDIR = 'mako'
3339N/AMAKOVER = '0.2.2'
3234N/AMAKOARC = '%s-%s.tar.gz' % (MAKO, MAKOVER)
3194N/AMAKODIR = '%s-%s' % (MAKO, MAKOVER)
382N/AMAKOURL = 'http://www.makotemplates.org/downloads/%s' % (MAKOARC)
382N/AMAKOHASH = '85c04ab3a6a26a1cab47067449712d15a8b29790'
382N/A
3234N/APLY = 'ply'
3234N/APLYIDIR = 'ply'
382N/APLYVER = '3.1'
382N/APLYARC = '%s-%s.tar.gz' % (PLY, PLYVER)
3274N/APLYDIR = '%s-%s' % (PLY, PLYVER)
3274N/APLYURL = 'http://www.dabeaz.com/ply/%s' % (PLYARC)
382N/APLYHASH = '38efe9e03bc39d40ee73fa566eb9c1975f1a8003'
22N/A
1836N/Aosname = platform.uname()[0].lower()
2507N/Aostype = arch = 'unknown'
3274N/Aif osname == 'sunos':
1836N/A arch = platform.processor()
1836N/A ostype = "posix"
2962N/Aelif osname == 'linux':
2962N/A arch = "linux_" + platform.machine()
2962N/A ostype = "posix"
1431N/Aelif osname == 'windows':
1968N/A arch = osname
873N/A ostype = "windows"
812N/Aelif osname == 'darwin':
1431N/A arch = osname
1431N/A ostype = "posix"
466N/A
1431N/Apwd = os.path.normpath(sys.path[0])
3274N/A
3274N/A#
3274N/A# Unbuffer stdout and stderr. This helps to ensure that subprocess output
3274N/A# is properly interleaved with output from this program.
3274N/A#
3274N/Asys.stdout = os.fdopen(sys.stdout.fileno(), "w", 0)
3274N/Asys.stderr = os.fdopen(sys.stderr.fileno(), "w", 0)
3274N/A
3274N/Adist_dir = os.path.normpath(os.path.join(pwd, os.pardir, "proto", "dist_" + arch))
3274N/Abuild_dir = os.path.normpath(os.path.join(pwd, os.pardir, "proto", "build_" + arch))
3274N/Aif "ROOT" in os.environ and os.environ["ROOT"] != "":
3274N/A root_dir = os.environ["ROOT"]
3274N/Aelse:
3274N/A root_dir = os.path.normpath(os.path.join(pwd, os.pardir, "proto", "root_" + arch))
466N/Apkgs_dir = os.path.normpath(os.path.join(pwd, os.pardir, "packages", arch))
466N/Aextern_dir = os.path.normpath(os.path.join(pwd, "extern"))
466N/A
23N/Apy_install_dir = 'usr/lib/python2.4/vendor-packages'
466N/A
466N/Ascripts_dir = 'usr/bin'
466N/Alib_dir = 'usr/lib'
466N/Asvc_method_dir = 'lib/svc/method'
466N/A
466N/Aman1_dir = 'usr/share/man/cat1'
466N/Aman1m_dir = 'usr/share/man/cat1m'
466N/Aman5_dir = 'usr/share/man/cat5'
1431N/Aresource_dir = 'usr/share/lib/pkg'
1633N/Asmf_dir = 'var/svc/manifest/application'
1633N/Azones_dir = 'etc/zones'
1633N/Abrand_dir = 'usr/lib/brand/ipkg'
1633N/A
466N/Ascripts_sunos = {
466N/A scripts_dir: [
466N/A ['client.py', 'pkg'],
1633N/A ['publish.py', 'pkgsend'],
1633N/A ['pull.py', 'pkgrecv'],
1633N/A ['packagemanager.py', 'packagemanager'],
1633N/A ['updatemanager.py', 'pm-updatemanager'],
1633N/A ],
1633N/A lib_dir: [
3143N/A ['depot.py', 'pkg.depotd'],
2230N/A ['updatemanagernotifier.py', 'updatemanagernotifier'],
1968N/A ],
1633N/A svc_method_dir: [
2515N/A ['svc/svc-pkg-depot', 'svc-pkg-depot'],
2816N/A ],
2816N/A }
1937N/A
382N/Ascripts_windows = {
2230N/A scripts_dir: [
2230N/A ['client.py', 'client.py'],
2230N/A ['publish.py', 'publish.py'],
2230N/A ['pull.py', 'pull.py'],
2028N/A ['scripts/pkg.bat', 'pkg.bat'],
1968N/A ['scripts/pkgsend.bat', 'pkgsend.bat'],
1968N/A ['scripts/pkgrecv.bat', 'pkgrecv.bat'],
2028N/A ],
1968N/A lib_dir: [
1968N/A ['depot.py', 'depot.py'],
1968N/A ['scripts/pkg.depotd.bat', 'pkg.depotd.bat'],
2028N/A ],
2028N/A }
2028N/A
1968N/Ascripts_other_unix = {
1968N/A scripts_dir: [
1968N/A ['client.py', 'client.py'],
1968N/A ['pull.py', 'pull.py'],
1968N/A ['publish.py', 'publish.py'],
1968N/A ['scripts/pkg.sh', 'pkg'],
589N/A ['scripts/pkgsend.sh', 'pkgsend'],
589N/A ['scripts/pkgrecv.sh', 'pkgrecv'],
589N/A ],
589N/A lib_dir: [
1431N/A ['depot.py', 'depot.py'],
1431N/A ['scripts/pkg.depotd.sh', 'pkg.depotd'],
1431N/A ],
1431N/A }
1431N/A
858N/A# indexed by 'osname'
1633N/Ascripts = {
2962N/A "sunos": scripts_sunos,
3053N/A "linux": scripts_other_unix,
2515N/A "windows": scripts_windows,
2515N/A "darwin": scripts_other_unix,
466N/A "unknown": scripts_sunos,
466N/A }
466N/A
466N/Aman1_files = [
466N/A 'man/packagemanager.1',
466N/A 'man/pkg.1',
466N/A 'man/pkgsend.1',
466N/A 'man/pkgrecv.1',
466N/A 'man/pm-updatemanager.1',
589N/A ]
589N/Aman1m_files = [
589N/A 'man/pkg.depotd.1m'
1191N/A ]
1191N/Aman5_files = [
1191N/A 'man/pkg.5'
1191N/A ]
1191N/Apackages = [
2816N/A 'pkg',
2816N/A 'pkg.actions',
589N/A 'pkg.bundle',
589N/A 'pkg.client',
589N/A 'pkg.portable',
589N/A 'pkg.publish',
812N/A 'pkg.server'
812N/A ]
812N/A
812N/Aweb_files = []
812N/Afor entry in os.walk("web"):
812N/A web_dir, dirs, files = entry
812N/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
812N/A if f != "Makefile"
812N/A ]))
812N/A
812N/Azones_files = [
1475N/A 'brand/SUNWipkg.xml',
1475N/A ]
1475N/Abrand_files = [
1475N/A 'brand/config.xml',
975N/A 'brand/platform.xml',
975N/A 'brand/pkgcreatezone',
975N/A 'brand/attach',
975N/A 'brand/clone',
1633N/A 'brand/detach',
1633N/A 'brand/prestate',
1633N/A 'brand/poststate',
1633N/A 'brand/query',
2028N/A 'brand/uninstall',
1633N/A 'brand/common.ksh',
3143N/A ]
1633N/Asmf_files = [
14N/A 'svc/pkg-server.xml',
382N/A 'svc/pkg-update.xml',
429N/A ]
14N/Apspawn_srcs = [
404N/A 'modules/pspawn.c'
404N/A ]
30N/Aelf_srcs = [
382N/A 'modules/elf.c',
30N/A 'modules/elfextract.c',
791N/A 'modules/liblist.c',
2728N/A ]
2728N/Aarch_srcs = [
689N/A 'modules/arch.c'
1968N/A ]
1968N/A_actions_srcs = [
1968N/A 'modules/actions/_actions.c'
1968N/A ]
1191N/Ainclude_dirs = [ 'modules' ]
258N/Alint_flags = [ '-u', '-axms', '-erroff=E_NAME_DEF_NOT_USED2' ]
1968N/A
2816N/A# Runs the test suite with the code coverage suite (figleaf) turned on, and
382N/A# outputs a coverage report.
1968N/A# TODO: Make the cov report format an option (html, ast, cov, etc)
30N/Aclass cov_func(Command):
589N/A description = "Runs figleaf code coverage suite"
589N/A user_options = []
1968N/A def initialize_options(self):
589N/A pass
589N/A def finalize_options(self):
589N/A pass
589N/A def run(self):
1968N/A if not os.path.isdir(FLDIR):
589N/A install_sw(FL, FLVER, FLARC, FLDIR, FLURL, FLIDIR,
1968N/A FLHASH)
466N/A # Run the test suite with coverage enabled
466N/A os.putenv('PYEXE', sys.executable)
2230N/A os.chdir(os.path.join(pwd, "tests"))
1968N/A # Reconstruct the cmdline and send that to run.py
1968N/A os.environ["PKGCOVERAGE"] = "1"
1431N/A cmd = [sys.executable, "run.py"]
1968N/A subprocess.call(cmd)
1968N/A print "Generating coverage report in directory: '%s/cov_report'" % \
54N/A pwd
1968N/A os.system("figleaf2html -d cov_report .figleaf")
1968N/A
2515N/A# Runs lint on the extension module source code
2816N/Aclass lint_func(Command):
2816N/A description = "Runs various lint tools over IPS extension source code"
2816N/A user_options = []
2816N/A
1475N/A def initialize_options(self):
2230N/A pass
466N/A
1633N/A def finalize_options(self):
1633N/A pass
135N/A
2230N/A # Make string shell-friendly
2230N/A @staticmethod
2230N/A def escape(astring):
135N/A return astring.replace(' ', '\\ ')
135N/A
1968N/A def run(self):
135N/A # assumes lint is on the $PATH
1968N/A if osname == 'sunos' or osname == "linux":
382N/A archcmd = ['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())] + \
3194N/A arch_srcs
3158N/A elfcmd = ['lint'] + lint_flags + \
3194N/A ["%s%s" % ("-I", k) for k in include_dirs] + \
382N/A ['-I' + self.escape(get_python_inc())] + \
3194N/A ["%s%s" % ("-l", k) for k in elf_libraries] + \
3158N/A elf_srcs
3194N/A _actionscmd = ['lint'] + lint_flags + \
1968N/A ["%s%s" % ("-I", k) for k in include_dirs] + \
382N/A ['-I' + self.escape(get_python_inc())] + \
1968N/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] + \
1968N/A ['-I' + self.escape(get_python_inc())] + \
1968N/A pspawn_srcs
812N/A
1968N/A print(" ".join(archcmd))
589N/A os.system(" ".join(archcmd))
1968N/A print(" ".join(elfcmd))
858N/A os.system(" ".join(elfcmd))
858N/A print(" ".join(_actionscmd))
1968N/A os.system(" ".join(_actionscmd))
858N/A print(" ".join(pspawncmd))
858N/A os.system(" ".join(pspawncmd))
858N/A
858N/A proto = os.path.join(root_dir, py_install_dir)
858N/A sys.path.insert(0, proto)
858N/A
858N/A # Insert tests directory onto sys.path so any custom checkers
1968N/A # can be found.
2962N/A sys.path.insert(0, os.path.join(pwd, 'tests'))
2962N/A print(sys.path)
2962N/A
2962N/A # assumes pylint is accessible on the sys.path
2962N/A from pylint import lint
2962N/A scriptlist = [ 'setup.py' ]
2962N/A for d, m in scripts_sunos.items():
2962N/A for a in m:
2962N/A # specify the filenames of the scripts, in addition
2962N/A # to the package names themselves
1431N/A scriptlist.append(os.path.join(root_dir, d, a[1]))
1431N/A
3194N/A # For some reason, the load-plugins option, when used in the
3194N/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',
1431N/A os.path.join(pwd, 'tests', 'pylintrc')] +
1431N/A scriptlist + packages)
1431N/A
1431N/Aclass install_func(_install):
1431N/A def initialize_options(self):
1431N/A _install.initialize_options(self)
1431N/A
1431N/A # PRIVATE_BUILD set in the environment tells us to put the build
1431N/A # directory into the .pyc files, rather than the final
1431N/A # installation directory.
1431N/A private_build = os.getenv("PRIVATE_BUILD", None)
3158N/A
1968N/A if private_build is None:
1542N/A self.install_lib = py_install_dir
1542N/A self.install_data = os.path.sep
2515N/A self.root = root_dir
2515N/A else:
1968N/A self.install_lib = os.path.join(root_dir, py_install_dir)
3158N/A self.install_data = root_dir
1968N/A
1633N/A # This is used when installing scripts, below, but it isn't a
1633N/A # standard distutils variable.
589N/A self.root_dir = root_dir
1968N/A
1902N/A def run(self):
1968N/A """
1968N/A At the end of the install function, we need to rename some files
1968N/A because distutils provides no way to rename files as they are
1191N/A placed in their install locations.
2816N/A Also, make sure that cherrypy and other external dependencies
2816N/A are installed.
2816N/A """
3194N/A for f in man1_files + man1m_files + man5_files:
3194N/A file_util.copy_file(f + ".txt", f, update=1)
3194N/A
1191N/A _install.run(self)
2816N/A
2816N/A for d, files in scripts[osname].iteritems():
2816N/A for (srcname, dstname) in files:
2816N/A dst_dir = util.change_root(self.root_dir, d)
2816N/A dst_path = util.change_root(self.root_dir,
589N/A os.path.join(d, dstname))
589N/A dir_util.mkpath(dst_dir, verbose = True)
589N/A file_util.copy_file(srcname, dst_path, update = True)
589N/A # make scripts executable
589N/A os.chmod(dst_path,
589N/A os.stat(dst_path).st_mode
3234N/A | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)
765N/A
765N/A install_sw(CP, CPVER, CPARC, CPDIR, CPURL, CPIDIR, CPHASH)
765N/A if "BUILD_PYOPENSSL" in os.environ and \
3194N/A os.environ["BUILD_PYOPENSSL"] != "":
3194N/A #
3194N/A # Include /usr/sfw/lib in the build environment
3194N/A # to ensure that this builds and runs on older
589N/A # nevada builds, before openssl moved out of /usr/sfw.
765N/A #
765N/A saveenv = os.environ.copy()
3194N/A if osname == "sunos":
3194N/A os.environ["CFLAGS"] = "-I/usr/sfw/include " + \
3194N/A os.environ.get("CFLAGS", "")
765N/A os.environ["LDFLAGS"] = \
765N/A "-L/usr/sfw/lib -R/usr/sfw/lib " + \
1968N/A os.environ.get("LDFLAGS", "")
3234N/A install_sw(PO, POVER, POARC, PODIR, POURL, POIDIR,
1968N/A POHASH)
135N/A os.environ = saveenv
1968N/A install_sw(MAKO, MAKOVER, MAKOARC, MAKODIR, MAKOURL, MAKOIDIR,
157N/A MAKOHASH)
382N/A install_sw(PLY, PLYVER, PLYARC, PLYDIR, PLYURL, PLYIDIR,
429N/A PLYHASH)
429N/A
2028N/A # Remove some bits that we're not going to package, but be sure
2028N/A # not to complain if we try to remove them twice.
429N/A def onerror(func, path, exc_info):
429N/A if exc_info[1].errno != errno.ENOENT:
429N/A raise
429N/A
429N/A for dir in ("cherrypy/scaffold", "cherrypy/test",
429N/A "cherrypy/tutorial"):
429N/A shutil.rmtree(os.path.join(root_dir, py_install_dir, dir),
2028N/A onerror=onerror)
1968N/A try:
1968N/A os.remove(os.path.join(root_dir, "usr/bin/mako-render"))
1968N/A except EnvironmentError, e:
1968N/A if e.errno != errno.ENOENT:
1968N/A raise
1968N/A
1968N/Adef hash_sw(swname, swarc, swhash):
1968N/A if swhash == None:
1968N/A return True
1968N/A
812N/A print "checksumming %s" % swname
1968N/A hash = sha.new()
1968N/A f = open(swarc, 'r')
1968N/A while True:
1968N/A data = f.read(65536)
1968N/A if data == "":
3194N/A break
3194N/A hash.update(data)
3194N/A f.close()
1968N/A
3194N/A if hash.hexdigest() == swhash:
3194N/A return True
1968N/A else:
3194N/A print "bad checksum! %s != %s" % (swhash, hash.hexdigest())
3194N/A return False
1968N/A
812N/A
1968N/Adef install_sw(swname, swver, swarc, swdir, swurl, swidir, swhash):
1968N/A swarc = os.path.join(extern_dir, swarc)
1968N/A swdir = os.path.join(extern_dir, swdir)
1968N/A if not os.path.exists(extern_dir):
1968N/A os.mkdir(extern_dir)
3194N/A
3194N/A if not os.path.exists(swarc):
3194N/A print "downloading %s" % swname
1968N/A try:
3194N/A fname, hdr = urllib.urlretrieve(swurl, swarc)
3194N/A except IOError:
1968N/A pass
3194N/A if not os.path.exists(swarc) or \
3194N/A (hdr.gettype() != "application/x-gzip" and
1968N/A hdr.gettype() != "application/x-tar"):
812N/A print "Unable to retrieve %s.\nPlease retrieve the file " \
1968N/A "and place it at: %s\n" % (swurl, swarc)
1968N/A # remove a partial download or error message from proxy
812N/A remove_sw(swname)
1968N/A sys.exit(1)
3194N/A if not os.path.exists(swdir):
3194N/A if not hash_sw(swname, swarc, swhash):
3194N/A sys.exit(1)
3194N/A
812N/A print "unpacking %s" % swname
1968N/A tar = tarfile.open(swarc)
812N/A # extractall doesn't exist until python 2.5
812N/A for m in tar.getmembers():
873N/A tar.extract(m, extern_dir)
873N/A tar.close()
873N/A swinst_dir = os.path.join(root_dir, py_install_dir, swidir)
3194N/A if not os.path.exists(swinst_dir):
3194N/A print "installing %s" % swname
3194N/A args = ['python', 'setup.py', 'install',
3194N/A '--root=%s' % root_dir,
812N/A '--install-lib=%s' % py_install_dir,
1968N/A '--install-data=%s' % py_install_dir]
812N/A ret = subprocess.Popen(args, cwd = swdir).wait()
812N/A if ret != 0:
3194N/A print "install failed and returned %d." % ret
3194N/A print "Command was: %s" % " ".join(args)
3194N/A sys.exit(1)
1968N/A
1475N/A
1968N/Adef remove_sw(swname):
975N/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)
2230N/A
2230N/Aclass build_func(_build):
1968N/A def initialize_options(self):
2962N/A _build.initialize_options(self)
2962N/A self.build_base = build_dir
2962N/A
1968N/Adef get_hg_version():
1968N/A try:
3171N/A p = subprocess.Popen(['hg', 'id', '-i'], stdout = subprocess.PIPE)
3158N/A return p.communicate()[0].strip()
3171N/A except OSError:
3158N/A print >> sys.stderr, "ERROR: unable to obtain mercurial version"
3171N/A return "unknown"
3158N/A
382N/Adef syntax_check(filename):
3158N/A """ Run python's compiler over the file, and discard the results.
3158N/A Arrange to generate an exception if the file does not compile.
451N/A This is needed because distutil's own use of pycompile (in the
1633N/A distutils.utils module) is broken, and doesn't stop on error. """
1633N/A try:
1633N/A py_compile.compile(filename, os.devnull, doraise=True)
1968N/A except py_compile.PyCompileError, e:
1968N/A raise DistutilsError("%s: failed syntax check: %s" %
1968N/A (filename, e))
1968N/A
1968N/A
1968N/Aclass build_py_func(_build_py):
1968N/A # override the build_module method to do VERSION substitution on pkg/__init__.py
1968N/A def build_module (self, module, module_file, package):
1968N/A
1968N/A if module == "__init__" and package == "pkg":
1968N/A versionre = '(?m)^VERSION[^"]*"([^"]*)"'
1968N/A # Grab the previously-built version out of the build
2515N/A # tree.
2515N/A try:
1968N/A ocontent = \
2230N/A file(self.get_module_outfile(self.build_lib,
1968N/A [package], module)).read()
1968N/A ov = re.search(versionre, ocontent).group(1)
1542N/A except IOError:
1542N/A ov = None
445N/A v = get_hg_version()
466N/A vstr = 'VERSION = "%s"' % v
1542N/A # If the versions haven't changed, there's no need to
1633N/A # recompile.
1633N/A if v == ov:
1020N/A return
1020N/A
1020N/A mcontent = file(module_file).read()
1020N/A mcontent = re.sub(versionre, vstr, mcontent)
1020N/A tmpfd, tmp_file = tempfile.mkstemp()
2515N/A os.write(tmpfd, mcontent)
2515N/A os.close(tmpfd)
2515N/A print "doing version substitution: ", v
2515N/A rv = _build_py.build_module(self, module, tmp_file, package)
2515N/A os.unlink(tmp_file)
2515N/A return rv
2515N/A
2515N/A # Will raise a DistutilsError on failure.
2515N/A syntax_check(module_file)
2515N/A
2515N/A return _build_py.build_module(self, module, module_file, package)
451N/A
1968N/Aclass clean_func(_clean):
2230N/A def initialize_options(self):
2230N/A _clean.initialize_options(self)
2230N/A self.build_base = build_dir
2230N/A
2230N/Aclass clobber_func(Command):
2230N/A user_options = []
2230N/A description = "Deletes any and all files created by setup"
2230N/A
2230N/A def initialize_options(self):
2230N/A pass
2515N/A def finalize_options(self):
2515N/A pass
1902N/A def run(self):
1968N/A # nuke everything
1968N/A print("deleting " + dist_dir)
1968N/A shutil.rmtree(dist_dir, True)
1968N/A print("deleting " + build_dir)
1968N/A shutil.rmtree(build_dir, True)
1968N/A print("deleting " + root_dir)
1968N/A shutil.rmtree(root_dir, True)
1968N/A print("deleting " + pkgs_dir)
812N/A shutil.rmtree(pkgs_dir, True)
812N/A print("deleting " + extern_dir)
812N/A shutil.rmtree(extern_dir, True)
812N/A
1968N/Aclass test_func(Command):
1968N/A # NOTE: these options need to be in sync with tests/run.py
1968N/A user_options = [("verbosemode", 'v', "run tests in verbose mode"),
1968N/A ("genbaseline", 'g', "generate test baseline"),
1968N/A ("parseable", 'p', "parseable output"),
1968N/A ("baselinefile=", 'b', "baseline file <file>"),
1968N/A ("only=", "o", "only <regex>")]
1968N/A description = "Runs unit and functional tests"
1968N/A
1968N/A def initialize_options(self):
1968N/A self.only = ""
1968N/A self.baselinefile = ""
1968N/A self.verbosemode = 0
1968N/A self.parseable = 0
1968N/A self.genbaseline = 0
1968N/A def finalize_options(self):
1968N/A pass
812N/A def run(self):
429N/A os.putenv('PYEXE', sys.executable)
429N/A os.chdir(os.path.join(pwd, "tests"))
2028N/A
1836N/A # Reconstruct the cmdline and send that to run.py
2230N/A cmd = [sys.executable, "run.py"]
3171N/A args = ""
1836N/A if "test" in sys.argv:
3158N/A args = sys.argv[sys.argv.index("test")+1:]
429N/A cmd.extend(args)
612N/A subprocess.call(cmd)
1542N/A
1968N/Aclass dist_func(_bdist):
1968N/A def initialize_options(self):
1968N/A _bdist.initialize_options(self)
1968N/A self.dist_dir = dist_dir
1968N/A
1968N/A
1968N/A# These are set to real values based on the platform, down below
1968N/Acompile_args = None
1968N/Alink_args = None
1968N/Aext_modules = [
1968N/A Extension(
1968N/A 'actions._actions',
1968N/A _actions_srcs,
1968N/A include_dirs = include_dirs,
1968N/A extra_compile_args = compile_args,
1968N/A extra_link_args = link_args
1968N/A ),
1968N/A ]
1968N/Aelf_libraries = None
1968N/Adata_files = web_files
1968N/Acmdclasses = {
1968N/A 'install': install_func,
1968N/A 'build': build_func,
1968N/A 'build_py': build_py_func,
1968N/A 'bdist': dist_func,
1968N/A 'lint': lint_func,
1968N/A 'clean': clean_func,
1968N/A 'clobber': clobber_func,
1968N/A 'coverage': cov_func,
1968N/A 'test': test_func,
1968N/A }
1968N/A
1968N/A# all builds of IPS should have manpages
812N/Adata_files += [
1968N/A (man1_dir, man1_files),
2028N/A (man1m_dir, man1m_files),
812N/A (man5_dir, man5_files),
812N/A ]
812N/A
812N/Aif osname == 'sunos':
812N/A # Solaris-specific extensions are added here
3273N/A data_files += [
3273N/A (zones_dir, zones_files),
3273N/A (brand_dir, brand_files),
3273N/A (smf_dir, smf_files),
3273N/A ]
812N/A
812N/Aif osname == 'sunos' or osname == "linux":
812N/A # Unix platforms which the elf extension has been ported to
3171N/A # are specified here, so they are built automatically
1836N/A elf_libraries = ['elf']
3158N/A ext_modules += [
1836N/A Extension(
3158N/A 'elf',
3158N/A elf_srcs,
812N/A include_dirs = include_dirs,
3339N/A libraries = elf_libraries,
812N/A extra_compile_args = compile_args,
812N/A extra_link_args = link_args
1968N/A ),
1968N/A ]
1968N/A
3158N/A # Solaris has built-in md library and Solaris-specific arch extension
1968N/A # All others use OpenSSL and cross-platform arch module
1968N/A if osname == 'sunos':
1968N/A elf_libraries += [ 'md' ]
1968N/A ext_modules += [
1968N/A Extension(
1968N/A 'arch',
1968N/A arch_srcs,
1968N/A include_dirs = include_dirs,
812N/A extra_compile_args = compile_args,
3158N/A extra_link_args = link_args,
812N/A define_macros = [('_FILE_OFFSET_BITS', '64')]
812N/A ),
812N/A Extension(
812N/A 'pspawn',
812N/A pspawn_srcs,
3234N/A include_dirs = include_dirs,
1968N/A extra_compile_args = compile_args,
1968N/A extra_link_args = link_args,
1968N/A define_macros = [('_FILE_OFFSET_BITS', '64')]
812N/A ),
3339N/A ]
3339N/A else:
812N/A elf_libraries += [ 'ssl' ]
812N/A
812N/Asetup(cmdclass = cmdclasses,
3171N/A name = 'ips',
1836N/A version = '1.0',
3158N/A package_dir = {'pkg':'modules'},
812N/A packages = packages,
3171N/A data_files = data_files,
1836N/A ext_package = 'pkg',
1836N/A ext_modules = ext_modules,
3158N/A )
812N/A