setup.py revision 591
409N/A#!/usr/bin/python2.4
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#
395N/A# Copyright 2008 Sun Microsystems, Inc. All rights reserved.
395N/A# Use is subject to license terms.
395N/A#
290N/A
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
290N/A
290N/Afrom distutils.core import setup, Extension
290N/Afrom distutils.cmd import Command
290N/Afrom distutils.command.install import install as _install
290N/Afrom distutils.command.build import build as _build
383N/Afrom distutils.command.build_py import build_py as _build_py
290N/Afrom distutils.command.bdist import bdist as _bdist
290N/Afrom distutils.command.clean import clean as _clean
290N/A
290N/Afrom distutils.sysconfig import get_python_inc
290N/Aimport distutils.file_util as file_util
290N/Aimport distutils.dir_util as dir_util
290N/Aimport distutils.util as util
290N/A
465N/A# 3rd party software required for the build
465N/ACP = 'CherryPy'
465N/ACPIDIR = 'cherrypy'
465N/ACPVER = '3.1.0'
465N/ACPARC = '%s-%s.tar.gz' % (CP, CPVER)
465N/ACPDIR = '%s-%s' % (CP, CPVER)
465N/ACPURL = 'http://download.cherrypy.org/cherrypy/%s/%s' % (CPVER, CPARC)
465N/A
465N/APO = 'pyOpenSSL'
465N/APOIDIR = 'OpenSSL'
465N/APOVER = '0.7'
465N/APOARC = '%s-%s.tar.gz' % (PO, POVER)
465N/APODIR = '%s-%s' % (PO, POVER)
465N/APOURL = 'http://downloads.sourceforge.net/pyopenssl/%s' % (POARC)
465N/A
290N/Aosname = platform.uname()[0].lower()
290N/Aostype = arch = 'unknown'
290N/Aif osname == 'sunos':
395N/A arch = platform.processor()
395N/A ostype = "posix"
290N/Aelif osname == 'linux':
395N/A arch = "linux_" + platform.machine()
395N/A ostype = "posix"
290N/Aelif osname == 'windows':
395N/A arch = osname
395N/A ostype = "windows"
290N/Aelif osname == 'darwin':
395N/A arch = osname
395N/A ostype = "posix"
290N/A
448N/Apwd = os.path.normpath(sys.path[0])
448N/A
534N/A#
534N/A# Unbuffer stdout and stderr. This helps to ensure that subprocess output
534N/A# is properly interleaved with output from this program.
534N/A#
534N/Asys.stdout = os.fdopen(sys.stdout.fileno(), "w", 0)
534N/Asys.stderr = os.fdopen(sys.stderr.fileno(), "w", 0)
534N/A
290N/Adist_dir = os.path.normpath(os.path.join(pwd, os.pardir, "proto", "dist_" + arch))
290N/Abuild_dir = os.path.normpath(os.path.join(pwd, os.pardir, "proto", "build_" + arch))
290N/Aroot_dir = os.path.normpath(os.path.join(pwd, os.pardir, "proto", "root_" + arch))
534N/Apkgs_dir = os.path.normpath(os.path.join(pwd, os.pardir, "packages", arch))
290N/A
290N/Apy_install_dir = 'usr/lib/python2.4/vendor-packages'
290N/A
290N/Ascripts_dir = 'usr/bin'
290N/Alib_dir = 'usr/lib'
290N/A
290N/Aman1_dir = 'usr/share/man/cat1'
290N/Aman1m_dir = 'usr/share/man/cat1m'
395N/Aman5_dir = 'usr/share/man/cat5'
290N/Aresource_dir = 'usr/share/lib/pkg'
290N/Asmf_dir = 'var/svc/manifest/application'
290N/Azones_dir = 'etc/zones'
290N/Abrand_dir = 'usr/lib/brand/ipkg'
290N/A
395N/Ascripts_sunos = {
430N/A scripts_dir: [
395N/A ['client.py', 'pkg'],
395N/A ['publish.py', 'pkgsend'],
395N/A ['pull.py', 'pkgrecv'],
424N/A ['packagemanager.py', 'packagemanager'],
578N/A ['updatemanager.py', 'updatemanager'],
395N/A ],
395N/A lib_dir: [
395N/A ['depot.py', 'pkg.depotd'],
578N/A ['updatemanagernotifier.py', 'updatemanagernotifier'],
395N/A ],
395N/A }
290N/A
290N/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'],
395N/A ['scripts/pkg.depotd.bat', 'pkg.depotd.bat'],
395N/A ],
395N/A }
290N/A
290N/Ascripts_other_unix = {
395N/A scripts_dir: [
395N/A ['client.py', 'client.py'],
395N/A ['pull.py', 'pull.py'],
395N/A ['publish.py', 'publish.py'],
395N/A ['scripts/pkg.sh', 'pkg'],
395N/A ['scripts/pkgsend.sh', 'pkgsend'],
395N/A ['scripts/pkgrecv.sh', 'pkgrecv'],
395N/A ],
395N/A lib_dir: [
395N/A ['depot.py', 'depot.py'],
395N/A ['scripts/pkg.depotd.sh', 'pkg.depotd'],
395N/A ],
395N/A }
290N/A
290N/A# indexed by 'osname'
430N/Ascripts = {
395N/A "sunos": scripts_sunos,
395N/A "linux": scripts_other_unix,
395N/A "windows": scripts_windows,
395N/A "darwin": scripts_other_unix,
395N/A "unknown": scripts_sunos,
395N/A }
290N/A
395N/Aman1_files = [
413N/A 'man/pkg.1',
413N/A 'man/pkgsend.1',
413N/A 'man/pkgrecv.1',
395N/A ]
395N/Aman1m_files = [
413N/A 'man/pkg.depotd.1m'
395N/A ]
395N/Aman5_files = [
413N/A 'man/pkg.5'
395N/A ]
395N/Apackages = [
395N/A 'pkg',
395N/A 'pkg.actions',
395N/A 'pkg.bundle',
395N/A 'pkg.client',
395N/A 'pkg.portable',
395N/A 'pkg.publish',
424N/A 'pkg.server'
395N/A ]
395N/Aweb_files = [
395N/A 'web/pkg-block-icon.png',
395N/A 'web/pkg-block-logo.png',
395N/A 'web/pkg.css',
451N/A 'web/feed-icon-32x32.png',
395N/A 'web/robots.txt',
395N/A ]
395N/Azones_files = [
395N/A 'brand/SUNWipkg.xml',
395N/A ]
395N/Abrand_files = [
395N/A 'brand/config.xml',
395N/A 'brand/platform.xml',
395N/A 'brand/pkgcreatezone',
395N/A ]
395N/Asmf_files = [
395N/A 'pkg-server.xml',
578N/A 'pkg-update.xml',
395N/A ]
395N/Aelf_srcs = [
395N/A 'modules/elf.c',
395N/A 'modules/elfextract.c',
395N/A 'modules/liblist.c',
395N/A ]
290N/Aarch_srcs = [
395N/A 'modules/arch.c'
395N/A ]
591N/A_actions_srcs = [
591N/A 'modules/actions/_actions.c'
591N/A ]
395N/Ainclude_dirs = [ 'modules' ]
395N/Alint_flags = [ '-u', '-axms', '-erroff=E_NAME_DEF_NOT_USED2' ]
290N/A
290N/A# Runs lint on the extension module source code
290N/Aclass lint_func(Command):
290N/A description = "Runs various lint tools over IPS extension source code"
290N/A user_options = []
290N/A
290N/A def initialize_options(self):
290N/A pass
290N/A
290N/A def finalize_options(self):
290N/A pass
290N/A
290N/A # Make string shell-friendly
290N/A @staticmethod
395N/A def escape(astring):
395N/A return astring.replace(' ', '\\ ')
290N/A
290N/A def run(self):
290N/A # assumes lint is on the $PATH
290N/A if osname == 'sunos' or osname == "linux":
290N/A archcmd = ['lint'] + lint_flags + ['-D_FILE_OFFSET_BITS=64'] + \
395N/A ["%s%s" % ("-I", k) for k in include_dirs] + \
395N/A ['-I' + self.escape(get_python_inc())] + \
395N/A arch_srcs
290N/A elfcmd = ['lint'] + lint_flags + \
395N/A ["%s%s" % ("-I", k) for k in include_dirs] + \
395N/A ['-I' + self.escape(get_python_inc())] + \
395N/A ["%s%s" % ("-l", k) for k in elf_libraries] + \
395N/A elf_srcs
591N/A _actionscmd = ['lint'] + lint_flags + \
591N/A ["%s%s" % ("-I", k) for k in include_dirs] + \
591N/A ['-I' + self.escape(get_python_inc())] + \
591N/A _actions_srcs
290N/A
290N/A print(" ".join(archcmd))
290N/A os.system(" ".join(archcmd))
290N/A print(" ".join(elfcmd))
290N/A os.system(" ".join(elfcmd))
591N/A print(" ".join(_actionscmd))
591N/A os.system(" ".join(_actionscmd))
290N/A
395N/A proto = os.path.join(root_dir, py_install_dir)
395N/A sys.path.insert(0, proto)
290N/A
395N/A # Insert tests directory onto sys.path so any custom checkers
395N/A # can be found.
395N/A sys.path.insert(0, os.path.join(pwd, 'tests'))
395N/A print(sys.path)
290N/A
290N/A # assumes pylint is accessible on the sys.path
290N/A from pylint import lint
395N/A scriptlist = [ 'setup.py' ]
395N/A for d, m in scripts_sunos.items():
395N/A for a in m:
395N/A # specify the filenames of the scripts, in addition
395N/A # to the package names themselves
395N/A scriptlist.append(os.path.join(root_dir, d, a[1]))
290N/A
290N/A # For some reason, the load-plugins option, when used in the
290N/A # rcfile, does not work, so we put it here instead, to load
290N/A # our custom checkers.
290N/A lint.Run(['--load-plugins=multiplatform', '--rcfile',
430N/A os.path.join(pwd, 'tests', 'pylintrc')] +
290N/A scriptlist + packages)
290N/A
395N/Aclass install_func(_install):
290N/A def initialize_options(self):
395N/A _install.initialize_options(self)
506N/A
506N/A # PRIVATE_BUILD set in the environment tells us to put the build
506N/A # directory into the .pyc files, rather than the final
506N/A # installation directory.
506N/A private_build = os.getenv("PRIVATE_BUILD", None)
506N/A
395N/A # It's OK to have /'s here, python figures it out when writing files
506N/A if private_build is None:
506N/A self.install_lib = py_install_dir
513N/A self.install_data = "/"
506N/A self.root = root_dir
506N/A else:
506N/A self.install_lib = os.path.join(root_dir, py_install_dir)
513N/A self.install_data = root_dir
506N/A
506N/A # This is used when installing scripts, below, but it isn't a
506N/A # standard distutils variable.
506N/A self.root_dir = root_dir
290N/A
290N/A def run(self):
395N/A """
395N/A At the end of the install function, we need to rename some files
395N/A because distutils provides no way to rename files as they are
395N/A placed in their install locations.
395N/A Also, make sure that cherrypy is installed.
395N/A """
413N/A for f in man1_files + man1m_files + man5_files:
413N/A file_util.copy_file(f + ".txt", f, update=1)
413N/A
395N/A _install.run(self)
290N/A
395N/A for d, files in scripts[osname].iteritems():
395N/A for (srcname, dstname) in files:
506N/A dst_dir = util.change_root(self.root_dir, d)
506N/A dst_path = util.change_root(self.root_dir,
395N/A os.path.join(d, dstname))
395N/A dir_util.mkpath(dst_dir, verbose = True)
395N/A file_util.copy_file(srcname, dst_path, update = True)
395N/A # make scripts executable
430N/A os.chmod(dst_path,
395N/A os.stat(dst_path).st_mode | stat.S_IEXEC)
290N/A
465N/A install_sw(CP, CPVER, CPARC, CPDIR, CPURL, CPIDIR)
465N/A install_sw(PO, POVER, POARC, PODIR, POURL, POIDIR)
290N/A
465N/Adef install_sw(swname, swver, swarc, swdir, swurl, swidir):
465N/A if not os.path.exists(swarc):
465N/A print "downloading %s" % swname
395N/A try:
465N/A fname, hdr = urllib.urlretrieve(swurl, swarc)
395N/A except IOError:
395N/A pass
465N/A if not os.path.exists(swarc) or \
465N/A (hdr.gettype() != "application/x-gzip" and
465N/A hdr.gettype() != "application/x-tar"):
395N/A print "Unable to retrieve %s.\nPlease retrieve the file " \
465N/A "and place it at: %s\n" % (swurl, swarc)
395N/A # remove a partial download or error message from proxy
465N/A remove_sw(swname)
395N/A sys.exit(1)
465N/A if not os.path.exists(swdir):
465N/A print "unpacking %s" % swname
465N/A tar = tarfile.open(swarc)
395N/A # extractall doesn't exist until python 2.5
395N/A for m in tar.getmembers():
395N/A tar.extract(m)
395N/A tar.close()
465N/A swinst_dir = os.path.join(root_dir, py_install_dir, swidir)
465N/A if not os.path.exists(swinst_dir):
465N/A print "installing %s" % swname
395N/A subprocess.Popen(['python', 'setup.py', 'install',
498N/A '--root=%s' % root_dir,
498N/A '--install-lib=%s' % py_install_dir,
498N/A '--install-data=%s' % py_install_dir],
498N/A cwd = swdir).wait()
290N/A
465N/A
465N/Adef remove_sw(swname):
465N/A print("deleting %s" % swname)
454N/A for file in os.listdir("."):
465N/A if fnmatch.fnmatch(file, "%s*" % swname):
454N/A if os.path.isfile(file):
454N/A os.unlink(file)
454N/A else:
454N/A shutil.rmtree(file, True)
465N/A
290N/Aclass build_func(_build):
430N/A def initialize_options(self):
395N/A _build.initialize_options(self)
395N/A self.build_base = build_dir
290N/A
383N/Adef get_hg_version():
383N/A try:
395N/A p = subprocess.Popen(['hg', 'id', '-i'], stdout = subprocess.PIPE)
383N/A return p.communicate()[0].strip()
383N/A except OSError:
384N/A print >> sys.stderr, "ERROR: unable to obtain mercurial version"
383N/A return "unknown"
383N/A
383N/Aclass build_py_func(_build_py):
383N/A # override the build_module method to do VERSION substitution on pkg/__init__.py
383N/A def build_module (self, module, module_file, package):
383N/A if module == "__init__" and package == "pkg":
422N/A versionre = '(?m)^VERSION[^"]*"([^"]*)"'
422N/A # Grab the previously-built version out of the build
422N/A # tree.
422N/A try:
422N/A ocontent = \
422N/A file(self.get_module_outfile(self.build_lib,
422N/A [package], module)).read()
422N/A ov = re.search(versionre, ocontent).group(1)
422N/A except IOError:
422N/A ov = None
422N/A v = get_hg_version()
422N/A vstr = 'VERSION = "%s"' % v
422N/A # If the versions haven't changed, there's no need to
422N/A # recompile.
422N/A if v == ov:
422N/A return
422N/A
383N/A mcontent = file(module_file).read()
422N/A mcontent = re.sub(versionre, vstr, mcontent)
383N/A tmpfd, tmp_file = tempfile.mkstemp()
383N/A os.write(tmpfd, mcontent)
383N/A os.close(tmpfd)
383N/A print "doing version substitution: ", v
383N/A rv = _build_py.build_module(self, module, tmp_file, package)
383N/A os.unlink(tmp_file)
383N/A return rv
422N/A
383N/A return _build_py.build_module(self, module, module_file, package)
383N/A
290N/Aclass clean_func(_clean):
430N/A def initialize_options(self):
395N/A _clean.initialize_options(self)
395N/A self.build_base = build_dir
290N/A
290N/Aclass clobber_func(Command):
290N/A user_options = []
290N/A description = "Deletes any and all files created by setup"
290N/A
290N/A def initialize_options(self):
290N/A pass
290N/A def finalize_options(self):
290N/A pass
290N/A def run(self):
290N/A # nuke everything
395N/A print("deleting " + dist_dir)
290N/A shutil.rmtree(dist_dir, True)
395N/A print("deleting " + build_dir)
290N/A shutil.rmtree(build_dir, True)
395N/A print("deleting " + root_dir)
290N/A shutil.rmtree(root_dir, True)
534N/A print("deleting " + pkgs_dir)
534N/A shutil.rmtree(pkgs_dir, True)
465N/A remove_sw(CP)
465N/A remove_sw(PO)
290N/A
290N/Aclass test_func(Command):
448N/A # NOTE: these options need to be in sync with tests/run.py
430N/A user_options = [("verbosemode", 'v', "run tests in verbose mode"),
448N/A ("genbaseline", 'g', "generate test baseline"),
448N/A ("parseable", 'p', "parseable output"),
448N/A ("baselinefile=", 'b', "baseline file <file>"),
448N/A ("only=", "o", "only <regex>")]
290N/A description = "Runs unit and functional tests"
290N/A
290N/A def initialize_options(self):
448N/A self.only = ""
448N/A self.baselinefile = ""
430N/A self.verbosemode = 0
448N/A self.parseable = 0
430N/A self.genbaseline = 0
290N/A def finalize_options(self):
290N/A pass
290N/A def run(self):
290N/A os.putenv('PYEXE', sys.executable)
290N/A os.chdir(os.path.join(pwd, "tests"))
290N/A
448N/A # Reconstruct the cmdline and send that to run.py
448N/A cmd = [sys.executable, "run.py"]
448N/A args = ""
448N/A if "test" in sys.argv:
448N/A args = sys.argv[sys.argv.index("test")+1:]
430N/A cmd.extend(args)
448N/A subprocess.call(cmd)
290N/A
290N/Aclass dist_func(_bdist):
290N/A def initialize_options(self):
430N/A _bdist.initialize_options(self)
395N/A self.dist_dir = dist_dir
290N/A
290N/A
290N/A# These are set to real values based on the platform, down below
290N/Aext_modules = None
290N/Acompile_args = None
290N/Alink_args = None
290N/Aelf_libraries = None
430N/Adata_files = [ (resource_dir, web_files) ]
395N/Acmdclasses = {
395N/A 'install': install_func,
395N/A 'build': build_func,
395N/A 'build_py': build_py_func,
395N/A 'bdist': dist_func,
395N/A 'lint': lint_func,
395N/A 'clean': clean_func,
395N/A 'clobber': clobber_func,
395N/A 'test': test_func,
395N/A }
290N/A
383N/A# all builds of IPS should have manpages
395N/Adata_files += [
395N/A (man1_dir, man1_files),
395N/A (man1m_dir, man1m_files),
395N/A (man5_dir, man5_files),
395N/A ]
290N/A
290N/Aif osname == 'sunos':
395N/A # Solaris-specific extensions are added here
395N/A data_files += [
395N/A (zones_dir, zones_files),
395N/A (brand_dir, brand_files),
395N/A (smf_dir, smf_files),
395N/A ]
290N/A
290N/Aif osname == 'sunos' or osname == "linux":
395N/A # Unix platforms which the elf extension has been ported to
395N/A # are specified here, so they are built automatically
395N/A elf_libraries = ['elf']
395N/A ext_modules = [
290N/A Extension(
395N/A 'elf',
395N/A elf_srcs,
395N/A include_dirs = include_dirs,
395N/A libraries = elf_libraries,
395N/A extra_compile_args = compile_args,
395N/A extra_link_args = link_args
395N/A ),
591N/A Extension(
591N/A 'actions._actions',
591N/A _actions_srcs,
591N/A include_dirs = include_dirs,
591N/A extra_compile_args = compile_args,
591N/A extra_link_args = link_args
591N/A ),
395N/A ]
290N/A
395N/A # Solaris has built-in md library and Solaris-specific arch extension
395N/A # All others use OpenSSL and cross-platform arch module
395N/A if osname == 'sunos':
395N/A elf_libraries += [ 'md' ]
395N/A ext_modules += [
395N/A Extension(
430N/A 'arch',
395N/A arch_srcs,
395N/A include_dirs = include_dirs,
395N/A extra_compile_args = compile_args,
395N/A extra_link_args = link_args,
395N/A define_macros = [('_FILE_OFFSET_BITS', '64')]
395N/A ),
395N/A ]
395N/A else:
395N/A elf_libraries += [ 'ssl' ]
395N/A
395N/Asetup(cmdclass = cmdclasses,
395N/A name = 'ips',
395N/A version = '1.0',
395N/A package_dir = {'pkg':'modules'},
395N/A packages = packages,
395N/A data_files = data_files,
395N/A ext_package = 'pkg',
395N/A ext_modules = ext_modules,
395N/A )