setup.py revision 2494
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#
1902N/A# Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
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
589N/Afrom distutils.core import setup, Extension
589N/Afrom distutils.cmd import Command
965N/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/Afrom distutils.dist import Distribution
1836N/A
1836N/Afrom distutils.sysconfig import get_python_inc
382N/Aimport distutils.file_util as file_util
812N/Aimport distutils.dir_util as dir_util
382N/Aimport distutils.util as util
382N/A
382N/Aosname = platform.uname()[0].lower()
1963N/Aostype = arch = 'unknown'
382N/Aif osname == 'sunos':
1963N/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':
26N/A arch = osname
689N/A ostype = "windows"
689N/Aelif osname == 'darwin':
466N/A arch = osname
0N/A ostype = "posix"
468N/Aelif osname == 'aix':
812N/A arch = "aix"
812N/A ostype = "posix"
52N/A
812N/Apwd = os.path.normpath(sys.path[0])
451N/A
0N/A#
382N/A# Unbuffer stdout and stderr. This helps to ensure that subprocess output
382N/A# is properly interleaved with output from this program.
382N/A#
452N/Asys.stdout = os.fdopen(sys.stdout.fileno(), "w", 0)
382N/Asys.stderr = os.fdopen(sys.stderr.fileno(), "w", 0)
452N/A
382N/Adist_dir = os.path.normpath(os.path.join(pwd, os.pardir, "proto", "dist_" + arch))
382N/Abuild_dir = os.path.normpath(os.path.join(pwd, os.pardir, "proto", "build_" + arch))
751N/Aif "ROOT" in os.environ and os.environ["ROOT"] != "":
751N/A root_dir = os.environ["ROOT"]
382N/Aelse:
22N/A root_dir = os.path.normpath(os.path.join(pwd, os.pardir, "proto", "root_" + arch))
1836N/Apkgs_dir = os.path.normpath(os.path.join(pwd, os.pardir, "packages", arch))
1836N/Aextern_dir = os.path.normpath(os.path.join(pwd, "extern"))
1836N/A
1431N/Apy_install_dir = 'usr/lib/python2.6/vendor-packages'
1968N/A
873N/Ascripts_dir = 'usr/bin'
812N/Alib_dir = 'usr/lib'
1431N/Asvc_method_dir = 'lib/svc/method'
873N/A
1431N/Aman1_dir = 'usr/share/man/man1'
466N/Aman1m_dir = 'usr/share/man/man1m'
1431N/Aman5_dir = 'usr/share/man/man5'
466N/Aresource_dir = 'usr/share/lib/pkg'
466N/Asmf_app_dir = 'lib/svc/manifest/application/pkg'
466N/Aexecattrd_dir = 'etc/security/exec_attr.d'
23N/Aauthattrd_dir = 'etc/security/auth_attr.d'
466N/Asysrepo_dir = 'etc/pkg/sysrepo'
466N/Asysrepo_logs_dir = 'var/log/pkg/sysrepo'
466N/Asysrepo_cache_dir = 'var/cache/pkg/sysrepo'
466N/A
466N/A
466N/A# A list of source, destination tuples of modules which should be hardlinked
466N/A# together if the os supports it and otherwise copied.
466N/Ahardlink_modules = []
1431N/A
1633N/Ascripts_sunos = {
1633N/A scripts_dir: [
1633N/A ['client.py', 'pkg'],
1633N/A ['pkgdep.py', 'pkgdepend'],
466N/A ['pkgrepo.py', 'pkgrepo'],
466N/A ['util/publish/pkgdiff.py', 'pkgdiff'],
466N/A ['util/publish/pkgfmt.py', 'pkgfmt'],
1633N/A ['util/publish/pkglint.py', 'pkglint'],
1633N/A ['util/publish/pkgmerge.py', 'pkgmerge'],
1633N/A ['util/publish/pkgmogrify.py', 'pkgmogrify'],
1633N/A ['publish.py', 'pkgsend'],
1633N/A ['pull.py', 'pkgrecv'],
1633N/A ['sign.py', 'pkgsign'],
26N/A ['packagemanager.py', 'packagemanager'],
2028N/A ['updatemanager.py', 'pm-updatemanager'],
1968N/A ],
1633N/A lib_dir: [
1902N/A ['depot.py', 'pkg.depotd'],
1968N/A ['checkforupdates.py', 'pm-checkforupdates'],
1968N/A ['updatemanagernotifier.py', 'updatemanagernotifier'],
1937N/A ['launch.py', 'pm-launch'],
382N/A ['sysrepo.py', 'pkg.sysrepo'],
2028N/A ],
1968N/A svc_method_dir: [
1968N/A ['svc/svc-pkg-depot', 'svc-pkg-depot'],
2028N/A ['svc/svc-pkg-mdns', 'svc-pkg-mdns'],
1968N/A ['svc/svc-pkg-sysrepo', 'svc-pkg-sysrepo'],
1968N/A ],
1968N/A }
2028N/A
2028N/Ascripts_windows = {
2028N/A scripts_dir: [
1968N/A ['client.py', 'client.py'],
1968N/A ['pkgrepo.py', 'pkgrepo.py'],
1968N/A ['publish.py', 'publish.py'],
1968N/A ['pull.py', 'pull.py'],
1968N/A ['scripts/pkg.bat', 'pkg.bat'],
1968N/A ['scripts/pkgsend.bat', 'pkgsend.bat'],
589N/A ['scripts/pkgrecv.bat', 'pkgrecv.bat'],
589N/A ],
589N/A lib_dir: [
589N/A ['depot.py', 'depot.py'],
1431N/A ['scripts/pkg.depotd.bat', 'pkg.depotd.bat'],
1431N/A ],
1431N/A }
1431N/A
1431N/Ascripts_other_unix = {
858N/A scripts_dir: [
1633N/A ['client.py', 'client.py'],
1633N/A ['pkgdep.py', 'pkgdep'],
1902N/A ['util/publish/pkgdiff.py', 'pkgdiff'],
1902N/A ['util/publish/pkgfmt.py', 'pkgfmt'],
2028N/A ['util/publish/pkgmogrify.py', 'pkgmogrify'],
466N/A ['pull.py', 'pull.py'],
466N/A ['publish.py', 'publish.py'],
466N/A ['scripts/pkg.sh', 'pkg'],
466N/A ['scripts/pkgsend.sh', 'pkgsend'],
466N/A ['scripts/pkgrecv.sh', 'pkgrecv'],
466N/A ],
466N/A lib_dir: [
466N/A ['depot.py', 'depot.py'],
466N/A ['scripts/pkg.depotd.sh', 'pkg.depotd'],
589N/A ],
589N/A }
589N/A
1191N/A# indexed by 'osname'
1191N/Ascripts = {
1191N/A "sunos": scripts_sunos,
1191N/A "linux": scripts_other_unix,
1191N/A "windows": scripts_windows,
589N/A "darwin": scripts_other_unix,
589N/A "aix" : scripts_other_unix,
589N/A "unknown": scripts_sunos,
589N/A }
812N/A
812N/Aman1_files = [
812N/A 'man/packagemanager.1',
812N/A 'man/pkg.1',
812N/A 'man/pkgdepend.1',
812N/A 'man/pkgdiff.1',
812N/A 'man/pkgfmt.1',
1968N/A 'man/pkglint.1',
1968N/A 'man/pkgmerge.1',
1968N/A 'man/pkgmogrify.1',
812N/A 'man/pkgsend.1',
812N/A 'man/pkgsign.1',
812N/A 'man/pkgrecv.1',
812N/A 'man/pkgrepo.1',
1475N/A 'man/pm-updatemanager.1',
1475N/A ]
1475N/Aman1m_files = [
1475N/A 'man/pkg.depotd.1m',
975N/A 'man/pkg.sysrepo.1m'
975N/A ]
975N/Aman5_files = [
975N/A 'man/pkg.5'
1633N/A ]
1633N/Apackages = [
1633N/A 'pkg',
1633N/A 'pkg.actions',
2028N/A 'pkg.bundle',
1633N/A 'pkg.client',
1633N/A 'pkg.client.linkedimage',
1633N/A 'pkg.client.transport',
14N/A 'pkg.file_layout',
382N/A 'pkg.flavor',
429N/A 'pkg.lint',
14N/A 'pkg.portable',
404N/A 'pkg.publish',
404N/A 'pkg.server'
30N/A ]
382N/A
30N/Apylint_targets = [
791N/A 'pkg.altroot',
689N/A 'pkg.client.linkedimage',
689N/A 'pkg.client.pkgdefs',
1968N/A ]
1968N/A
1968N/Aweb_files = []
1968N/Afor entry in os.walk("web"):
1968N/A web_dir, dirs, files = entry
1968N/A if not files:
1191N/A continue
1191N/A web_files.append((os.path.join(resource_dir, web_dir), [
258N/A os.path.join(web_dir, f) for f in files
1968N/A if f != "Makefile"
1968N/A ]))
382N/A
1968N/Asmf_app_files = [
30N/A 'svc/pkg-mdns.xml',
589N/A 'svc/pkg-server.xml',
589N/A 'svc/pkg-update.xml',
1968N/A 'svc/pkg-system-repository.xml',
589N/A 'svc/zoneproxy-client.xml',
589N/A 'svc/zoneproxyd.xml'
589N/A ]
589N/Aresource_files = [
1968N/A 'util/opensolaris.org.sections',
589N/A 'util/pkglintrc',
1968N/A ]
466N/Asysrepo_files = [
466N/A 'util/apache2/sysrepo/sysrepo_httpd.conf.mako',
1968N/A 'util/apache2/sysrepo/sysrepo_publisher_response.mako',
1968N/A ]
1431N/Asysrepo_log_stubs = [
1968N/A 'util/apache2/sysrepo/logs/access_log',
1968N/A 'util/apache2/sysrepo/logs/error_log',
54N/A ]
1968N/Aexecattrd_files = ['util/misc/exec_attr.d/SUNWipkg',
1968N/A 'util/misc/exec_attr.d/SUNWipkg-gui']
1968N/Aauthattrd_files = ['util/misc/auth_attr.d/SUNWipkg']
1968N/Asyscallat_srcs = [
1968N/A 'modules/syscallat.c'
1968N/A ]
1968N/Apspawn_srcs = [
1475N/A 'modules/pspawn.c'
1633N/A ]
466N/Aelf_srcs = [
1633N/A 'modules/elf.c',
1633N/A 'modules/elfextract.c',
135N/A 'modules/liblist.c',
135N/A ]
135N/Aarch_srcs = [
135N/A 'modules/arch.c'
1968N/A ]
135N/A_actions_srcs = [
1968N/A 'modules/actions/_actions.c'
382N/A ]
382N/Asolver_srcs = [
382N/A 'modules/solver/solver.c',
382N/A 'modules/solver/py_solver.c'
382N/A ]
382N/Asolver_link_args = ["-lm", "-lc"]
382N/Aif osname == 'sunos':
382N/A solver_link_args = ["-ztext"] + solver_link_args
1968N/A
382N/A# Runs lint on the extension module source code
1968N/Aclass pylint_func(Command):
1542N/A description = "Runs pylint tools over IPS python source code"
1542N/A user_options = []
1968N/A
1968N/A def initialize_options(self):
812N/A pass
1968N/A
589N/A def finalize_options(self):
1968N/A pass
858N/A
858N/A # Make string shell-friendly
1968N/A @staticmethod
858N/A def escape(astring):
858N/A return astring.replace(' ', '\\ ')
858N/A
858N/A def run(self, quiet=False):
858N/A proto = os.path.join(root_dir, py_install_dir)
858N/A sys.path.insert(0, proto)
858N/A
1968N/A # Insert tests directory onto sys.path so any custom checkers
1431N/A # can be found.
1431N/A sys.path.insert(0, os.path.join(pwd, 'tests'))
1431N/A # assumes pylint is accessible on the sys.path
1431N/A from pylint import lint
1431N/A
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 #
1431N/A # Unfortunately, pylint seems pretty fragile and will crash if
1431N/A # we try to run it over all the current pkg source. Hence for
1431N/A # now we only run it over a subset of the source. As source
1431N/A # files are made pylint clean they should be added to the
1431N/A # pylint_targets list.
1431N/A #
1431N/A args = ['--load-plugins=multiplatform']
1431N/A if quiet:
1968N/A args += ['--reports=no']
1542N/A args += ['--rcfile', os.path.join(pwd, 'tests', 'pylintrc')]
1542N/A args += pylint_targets
1968N/A lint.Run(args)
1968N/A
1968N/A
1968N/Aclass pylint_func_quiet(pylint_func):
1968N/A
1633N/A def run(self, quiet=False):
1633N/A pylint_func.run(self, quiet=True)
589N/A
1968N/A
1902N/Ainclude_dirs = [ 'modules' ]
1968N/Alint_flags = [ '-u', '-axms', '-erroff=E_NAME_DEF_NOT_USED2' ]
1968N/A
1968N/A# Runs lint on the extension module source code
1191N/Aclass clint_func(Command):
1191N/A description = "Runs lint tools over IPS C extension source code"
1191N/A user_options = []
1191N/A
1191N/A def initialize_options(self):
1191N/A pass
1191N/A
1191N/A def finalize_options(self):
1191N/A pass
1191N/A
1191N/A # Make string shell-friendly
1191N/A @staticmethod
1191N/A def escape(astring):
589N/A return astring.replace(' ', '\\ ')
589N/A
589N/A def run(self):
589N/A # assumes lint is on the $PATH
589N/A if osname == 'sunos' or osname == "linux":
589N/A archcmd = ['lint'] + lint_flags + ['-D_FILE_OFFSET_BITS=64'] + \
589N/A ["%s%s" % ("-I", k) for k in include_dirs] + \
765N/A ['-I' + self.escape(get_python_inc())] + \
765N/A arch_srcs
765N/A elfcmd = ['lint'] + lint_flags + \
765N/A ["%s%s" % ("-I", k) for k in include_dirs] + \
765N/A ['-I' + self.escape(get_python_inc())] + \
765N/A ["%s%s" % ("-l", k) for k in elf_libraries] + \
765N/A elf_srcs
589N/A _actionscmd = ['lint'] + lint_flags + \
765N/A ["%s%s" % ("-I", k) for k in include_dirs] + \
765N/A ['-I' + self.escape(get_python_inc())] + \
765N/A _actions_srcs
765N/A pspawncmd = ['lint'] + lint_flags + ['-D_FILE_OFFSET_BITS=64'] + \
765N/A ["%s%s" % ("-I", k) for k in include_dirs] + \
765N/A ['-I' + self.escape(get_python_inc())] + \
765N/A pspawn_srcs
1968N/A syscallatcmd = ['lint'] + lint_flags + ['-D_FILE_OFFSET_BITS=64'] + \
1968N/A ["%s%s" % ("-I", k) for k in include_dirs] + \
1968N/A ['-I' + self.escape(get_python_inc())] + \
135N/A syscallat_srcs
1968N/A
157N/A print(" ".join(archcmd))
382N/A os.system(" ".join(archcmd))
429N/A print(" ".join(elfcmd))
429N/A os.system(" ".join(elfcmd))
2028N/A print(" ".join(_actionscmd))
2028N/A os.system(" ".join(_actionscmd))
429N/A print(" ".join(pspawncmd))
429N/A os.system(" ".join(pspawncmd))
429N/A print(" ".join(syscallatcmd))
429N/A os.system(" ".join(syscallatcmd))
429N/A
429N/A
429N/A# Runs both C and Python lint
2028N/Aclass lint_func(Command):
1968N/A description = "Runs C and Python lint checkers"
1968N/A user_options = []
1968N/A
1968N/A def initialize_options(self):
1968N/A pass
1968N/A
1968N/A def finalize_options(self):
1968N/A pass
1968N/A
1968N/A # Make string shell-friendly
1937N/A @staticmethod
1937N/A def escape(astring):
812N/A return astring.replace(' ', '\\ ')
1968N/A
1968N/A def run(self):
1968N/A clint_func(Distribution()).run()
1968N/A pylint_func(Distribution()).run()
1968N/A
812N/Aclass install_func(_install):
812N/A def initialize_options(self):
812N/A _install.initialize_options(self)
1968N/A
812N/A # PRIVATE_BUILD set in the environment tells us to put the build
812N/A # directory into the .pyc files, rather than the final
1968N/A # installation directory.
812N/A private_build = os.getenv("PRIVATE_BUILD", None)
812N/A
1968N/A if private_build is None:
812N/A self.install_lib = py_install_dir
1968N/A self.install_data = os.path.sep
1968N/A self.root = root_dir
1968N/A else:
1968N/A self.install_lib = os.path.join(root_dir, py_install_dir)
1968N/A self.install_data = root_dir
812N/A
812N/A # This is used when installing scripts, below, but it isn't a
812N/A # standard distutils variable.
1968N/A self.root_dir = root_dir
812N/A
812N/A def run(self):
1968N/A """
812N/A At the end of the install function, we need to rename some files
812N/A because distutils provides no way to rename files as they are
1968N/A placed in their install locations.
812N/A Also, make sure that cherrypy and other external dependencies
1968N/A are installed.
1968N/A """
812N/A
1968N/A _install.run(self)
812N/A
812N/A for o_src, o_dest in hardlink_modules:
1968N/A for e in [".py", ".pyc"]:
1968N/A src = util.change_root(self.root_dir, o_src + e)
812N/A dest = util.change_root(
1968N/A self.root_dir, o_dest + e)
812N/A if ostype == "posix":
812N/A if os.path.exists(dest) and \
873N/A os.stat(src)[stat.ST_INO] != \
873N/A os.stat(dest)[stat.ST_INO]:
873N/A os.remove(dest)
873N/A file_util.copy_file(src, dest,
873N/A link="hard", update=1)
873N/A else:
873N/A file_util.copy_file(src, dest, update=1)
812N/A
1968N/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)
1968N/A file_util.copy_file(srcname, dst_path, update = True)
1475N/A # make scripts executable
1968N/A os.chmod(dst_path,
975N/A os.stat(dst_path).st_mode
1968N/A | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)
1968N/A
1968N/Adef hash_sw(swname, swarc, swhash):
1968N/A if swhash == None:
1968N/A return True
1968N/A
1968N/A print "checksumming %s" % swname
1968N/A hash = hashlib.sha1()
1968N/A f = open(swarc, "rb")
1968N/A while True:
873N/A data = f.read(65536)
873N/A if data == "":
1968N/A break
1968N/A hash.update(data)
873N/A f.close()
873N/A
382N/A if hash.hexdigest() == swhash:
466N/A return True
466N/A else:
451N/A print >> sys.stderr, "bad checksum! %s != %s" % \
1633N/A (swhash, hash.hexdigest())
1633N/A return False
1633N/A
1968N/Adef prep_sw(swname, swarc, swdir, swurl, 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)
1968N/A
1968N/A if not os.path.exists(swarc):
1968N/A print "downloading %s" % swname
1968N/A try:
1968N/A fname, hdr = urllib.urlretrieve(swurl, swarc)
1968N/A except IOError:
1968N/A pass
1968N/A if not os.path.exists(swarc):
1968N/A print >> sys.stderr, "Unable to retrieve %s.\n" \
1968N/A "Please retrieve the file " \
1542N/A "and place it at: %s\n" % (swurl, swarc)
1542N/A # remove a partial download or error message from proxy
445N/A remove_sw(swname)
466N/A sys.exit(1)
1542N/A if not os.path.exists(swdir):
1633N/A if not hash_sw(swname, swarc, swhash):
1633N/A sys.exit(1)
1020N/A
1020N/A print "unpacking %s" % swname
1020N/A tar = tarfile.open(swarc)
1020N/A # extractall doesn't exist until python 2.5
1020N/A for m in tar.getmembers():
451N/A tar.extract(m, extern_dir)
1968N/A tar.close()
1968N/A
1968N/A # If there are patches, apply them now.
1968N/A patchdir = os.path.join("patch", swname)
1902N/A already_patched = os.path.join(swdir, ".patched")
1902N/A if os.path.exists(patchdir) and not os.path.exists(already_patched):
1902N/A patches = os.listdir(patchdir)
1968N/A for p in patches:
1968N/A patchpath = os.path.join(os.path.pardir,
1968N/A os.path.pardir, patchdir, p)
1968N/A print "Applying %s to %s" % (p, swname)
1968N/A args = ["patch", "-d", swdir, "-i", patchpath, "-p0"]
1968N/A if osname == "windows":
1968N/A args.append("--binary")
1968N/A ret = subprocess.Popen(args).wait()
812N/A if ret != 0:
812N/A print >> sys.stderr, \
812N/A "patch failed and returned %d." % ret
812N/A print >> sys.stderr, \
1968N/A "Command was: %s" % " ".join(args)
1968N/A sys.exit(1)
1968N/A file(already_patched, "w").close()
1968N/A
1968N/Adef run_cmd(args, swdir, env=None):
1968N/A if env is None:
1968N/A env = os.environ
1968N/A ret = subprocess.Popen(args, cwd=swdir, env=env).wait()
1968N/A if ret != 0:
1968N/A print >> sys.stderr, \
1968N/A "install failed and returned %d." % ret
1968N/A print >> sys.stderr, \
1968N/A "Command was: %s" % " ".join(args)
1968N/A sys.exit(1)
1968N/A
1968N/Adef remove_sw(swname):
1968N/A print("deleting %s" % swname)
812N/A for file in os.listdir(extern_dir):
429N/A if fnmatch.fnmatch(file, "%s*" % swname):
429N/A fpath = os.path.join(extern_dir, file)
2028N/A if os.path.isfile(fpath):
1836N/A os.unlink(fpath)
1836N/A else:
1836N/A shutil.rmtree(fpath, True)
1836N/A
1836N/Aclass build_func(_build):
429N/A def initialize_options(self):
612N/A _build.initialize_options(self)
1542N/A self.build_base = build_dir
1968N/A
1968N/Adef get_hg_version():
1968N/A try:
1968N/A p = subprocess.Popen(['hg', 'id', '-i'], stdout = subprocess.PIPE)
1968N/A return p.communicate()[0].strip()
1968N/A except OSError:
1968N/A print >> sys.stderr, "ERROR: unable to obtain mercurial version"
1968N/A return "unknown"
1968N/A
1968N/Adef syntax_check(filename):
1968N/A """ Run python's compiler over the file, and discard the results.
1968N/A Arrange to generate an exception if the file does not compile.
1968N/A This is needed because distutil's own use of pycompile (in the
1968N/A distutils.utils module) is broken, and doesn't stop on error. """
1968N/A try:
1968N/A py_compile.compile(filename, os.devnull, doraise=True)
386N/A except py_compile.PyCompileError, e:
1968N/A res = ""
1968N/A for err in e.exc_value:
1968N/A if isinstance(err, basestring):
1968N/A res += err + "\n"
1968N/A continue
1968N/A
1968N/A # Assume it's a tuple of (filename, lineno, col, code)
1968N/A fname, line, col, code = err
1968N/A res += "line %d, column %s, in %s:\n%s" % (line,
1968N/A col or "unknown", fname, code)
1968N/A
1968N/A raise DistutilsError(res)
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":
812N/A versionre = '(?m)^VERSION[^"]*"([^"]*)"'
1968N/A # Grab the previously-built version out of the build
2028N/A # tree.
812N/A try:
812N/A ocontent = \
812N/A file(self.get_module_outfile(self.build_lib,
812N/A [package], module)).read()
812N/A ov = re.search(versionre, ocontent).group(1)
812N/A except IOError:
812N/A ov = None
812N/A v = get_hg_version()
812N/A vstr = 'VERSION = "%s"' % v
873N/A # If the versions haven't changed, there's no need to
1836N/A # recompile.
1836N/A if v == ov:
1836N/A return
1836N/A
812N/A mcontent = file(module_file).read()
812N/A mcontent = re.sub(versionre, vstr, mcontent)
812N/A tmpfd, tmp_file = tempfile.mkstemp()
812N/A os.write(tmpfd, mcontent)
1968N/A os.close(tmpfd)
1968N/A print "doing version substitution: ", v
1968N/A rv = _build_py.build_module(self, module, tmp_file, package)
1968N/A os.unlink(tmp_file)
1968N/A return rv
1968N/A
1968N/A # Will raise a DistutilsError on failure.
1968N/A syntax_check(module_file)
1968N/A
1968N/A return _build_py.build_module(self, module, module_file, package)
1968N/A
1968N/Aclass clean_func(_clean):
812N/A def initialize_options(self):
1968N/A _clean.initialize_options(self)
812N/A self.build_base = build_dir
812N/A
812N/Aclass clobber_func(Command):
812N/A user_options = []
812N/A description = "Deletes any and all files created by setup"
1968N/A
1968N/A def initialize_options(self):
1968N/A pass
1968N/A def finalize_options(self):
812N/A pass
812N/A def run(self):
812N/A # nuke everything
812N/A print("deleting " + dist_dir)
812N/A shutil.rmtree(dist_dir, True)
873N/A print("deleting " + build_dir)
1836N/A shutil.rmtree(build_dir, True)
1836N/A print("deleting " + root_dir)
812N/A shutil.rmtree(root_dir, True)
873N/A print("deleting " + pkgs_dir)
1836N/A shutil.rmtree(pkgs_dir, True)
1836N/A print("deleting " + extern_dir)
1836N/A shutil.rmtree(extern_dir, True)
812N/A
812N/Aclass test_func(Command):
812N/A # NOTE: these options need to be in sync with tests/run.py and the
812N/A # list of options stored in initialize_options below. The first entry
1968N/A # in each tuple must be the exact name of a member variable.
812N/A user_options = [
452N/A ("archivedir=", 'a', "archive failed tests <dir>"),
466N/A ("baselinefile=", 'b', "baseline file <file>"),
858N/A ("coverage", "c", "collect code coverage data"),
382N/A ("genbaseline", 'g', "generate test baseline"),
466N/A ("only=", "o", "only <regex>"),
965N/A ("parseable", 'p', "parseable output"),
858N/A ("port=", "z", "lowest port to start a depot on"),
1937N/A ("timing", "t", "timing file <file>"),
1836N/A ("verbosemode", 'v', "run tests in verbose mode"),
382N/A ("enableguitests", 'u', "enable IPS GUI tests, disabled by default"),
858N/A ("stoponerr", 'x', "stop when a baseline mismatch occurs"),
858N/A ("debugoutput", 'd', "emit debugging output"),
858N/A ("showonexpectedfail", 'f',
382N/A "show all failure info, even for expected fails"),
742N/A ("startattest=", 's', "start at indicated test"),
858N/A ]
466N/A description = "Runs unit and functional tests"
466N/A
1968N/A def initialize_options(self):
858N/A self.only = ""
858N/A self.baselinefile = ""
858N/A self.verbosemode = 0
858N/A self.parseable = 0
858N/A self.genbaseline = 0
858N/A self.timing = 0
858N/A self.coverage = 0
858N/A self.stoponerr = 0
858N/A self.debugoutput = 0
858N/A self.showonexpectedfail = 0
858N/A self.startattest = ""
466N/A self.archivedir = ""
466N/A self.port = 12001
466N/A
466N/A def finalize_options(self):
466N/A pass
466N/A
466N/A def run(self):
466N/A
466N/A os.putenv('PYEXE', sys.executable)
466N/A os.chdir(os.path.join(pwd, "tests"))
466N/A
466N/A # Reconstruct the cmdline and send that to run.py
1968N/A cmd = [sys.executable, "run.py"]
466N/A args = ""
466N/A if "test" in sys.argv:
466N/A args = sys.argv[sys.argv.index("test")+1:]
466N/A cmd.extend(args)
466N/A subprocess.call(cmd)
466N/A
466N/Aclass dist_func(_bdist):
466N/A def initialize_options(self):
466N/A _bdist.initialize_options(self)
466N/A self.dist_dir = dist_dir
466N/A
466N/A# These are set to real values based on the platform, down below
466N/Acompile_args = None
466N/Aif osname in ("sunos", "linux", "darwin"):
466N/A compile_args = [ "-O3" ]
1968N/Alink_args = None
1968N/Aext_modules = [
1968N/A Extension(
466N/A 'actions._actions',
382N/A _actions_srcs,
612N/A include_dirs = include_dirs,
612N/A extra_compile_args = compile_args,
612N/A extra_link_args = link_args
612N/A ),
1431N/A Extension(
1431N/A 'solver',
2028N/A solver_srcs,
2028N/A include_dirs = include_dirs + ["."],
2028N/A extra_compile_args = compile_args,
2028N/A extra_link_args = solver_link_args,
2028N/A define_macros = [('_FILE_OFFSET_BITS', '64')]
2028N/A ),
2028N/A ]
2028N/Aelf_libraries = None
2028N/Adata_files = web_files
2028N/Acmdclasses = {
2028N/A 'install': install_func,
1431N/A 'build': build_func,
1968N/A 'build_py': build_py_func,
1968N/A 'bdist': dist_func,
1968N/A 'lint': lint_func,
2028N/A 'clint': clint_func,
2028N/A 'pylint': pylint_func,
2028N/A 'pylint_quiet': pylint_func_quiet,
2028N/A 'clean': clean_func,
1431N/A 'clobber': clobber_func,
1895N/A 'test': test_func,
1431N/A }
1431N/A
1672N/A# all builds of IPS should have manpages
1672N/Adata_files += [
1672N/A (man1_dir, man1_files),
1968N/A (man1m_dir, man1m_files),
1672N/A (man5_dir, man5_files),
1431N/A (resource_dir, resource_files),
1431N/A ]
2028N/A
2028N/Aif osname == 'sunos':
2028N/A # Solaris-specific extensions are added here
2028N/A data_files += [
2028N/A (smf_app_dir, smf_app_files),
2028N/A (execattrd_dir, execattrd_files),
612N/A (authattrd_dir, authattrd_files),
617N/A (sysrepo_dir, sysrepo_files),
2028N/A (sysrepo_logs_dir, sysrepo_log_stubs),
2028N/A (sysrepo_cache_dir, {})
2028N/A ]
2028N/A
2028N/Aif osname == 'sunos' or osname == "linux":
2028N/A # Unix platforms which the elf extension has been ported to
2028N/A # are specified here, so they are built automatically
2028N/A elf_libraries = ['elf']
2028N/A ext_modules += [
1431N/A Extension(
1431N/A 'elf',
1431N/A elf_srcs,
975N/A include_dirs = include_dirs,
1779N/A libraries = elf_libraries,
1431N/A extra_compile_args = compile_args,
1431N/A extra_link_args = link_args
617N/A ),
1542N/A ]
1542N/A
1542N/A # Solaris has built-in md library and Solaris-specific arch extension
2028N/A # All others use OpenSSL and cross-platform arch module
1542N/A if osname == 'sunos':
1542N/A elf_libraries += [ 'md' ]
1542N/A ext_modules += [
1542N/A Extension(
1779N/A 'arch',
1542N/A arch_srcs,
1542N/A include_dirs = include_dirs,
1542N/A extra_compile_args = compile_args,
1542N/A extra_link_args = link_args,
2028N/A define_macros = [('_FILE_OFFSET_BITS', '64')]
1542N/A ),
1542N/A Extension(
1542N/A 'pspawn',
1431N/A pspawn_srcs,
1431N/A include_dirs = include_dirs,
1968N/A extra_compile_args = compile_args,
1968N/A extra_link_args = link_args,
1431N/A define_macros = [('_FILE_OFFSET_BITS', '64')]
1968N/A ),
612N/A Extension(
451N/A 'syscallat',
382N/A syscallat_srcs,
452N/A include_dirs = include_dirs,
452N/A extra_compile_args = compile_args,
452N/A extra_link_args = link_args,
452N/A define_macros = [('_FILE_OFFSET_BITS', '64')]
873N/A ),
452N/A ]
382N/A else:
382N/A elf_libraries += [ 'ssl' ]
1431N/A
382N/Asetup(cmdclass = cmdclasses,
382N/A name = 'pkg',
382N/A version = '0.1',
145N/A package_dir = {'pkg':'modules'},
1968N/A packages = packages,
451N/A data_files = data_files,
451N/A ext_package = 'pkg',
451N/A ext_modules = ext_modules,
451N/A )
451N/A