setup.py revision 613
290N/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#
290N/A# Copyright 2008 Sun Microsystems, Inc. All rights reserved.
290N/A# Use is subject to license terms.
290N/A#
290N/A
290N/Aimport fnmatch
290N/Aimport os
290N/Aimport platform
290N/Aimport stat
290N/Aimport sys
290N/Aimport shutil
290N/Aimport re
290N/Aimport subprocess
290N/Aimport tarfile
290N/Aimport tempfile
290N/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
290N/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
290N/A# 3rd party software required for the build
290N/ACP = 'CherryPy'
290N/ACPIDIR = 'cherrypy'
290N/ACPVER = '3.1.0'
290N/ACPARC = '%s-%s.tar.gz' % (CP, CPVER)
290N/ACPDIR = '%s-%s' % (CP, CPVER)
290N/ACPURL = 'http://download.cherrypy.org/cherrypy/%s/%s' % (CPVER, CPARC)
290N/A
290N/APO = 'pyOpenSSL'
290N/APOIDIR = 'OpenSSL'
290N/APOVER = '0.7'
290N/APOARC = '%s-%s.tar.gz' % (PO, POVER)
290N/APODIR = '%s-%s' % (PO, POVER)
290N/APOURL = 'http://downloads.sourceforge.net/pyopenssl/%s' % (POARC)
290N/A
290N/Aosname = platform.uname()[0].lower()
290N/Aostype = arch = 'unknown'
290N/Aif osname == 'sunos':
290N/A arch = platform.processor()
290N/A ostype = "posix"
290N/Aelif osname == 'linux':
290N/A arch = "linux_" + platform.machine()
290N/A ostype = "posix"
290N/Aelif osname == 'windows':
290N/A arch = osname
290N/A ostype = "windows"
290N/Aelif osname == 'darwin':
290N/A arch = osname
290N/A ostype = "posix"
290N/A
290N/Apwd = os.path.normpath(sys.path[0])
290N/A
290N/A#
290N/A# Unbuffer stdout and stderr. This helps to ensure that subprocess output
290N/A# is properly interleaved with output from this program.
290N/A#
290N/Asys.stdout = os.fdopen(sys.stdout.fileno(), "w", 0)
290N/Asys.stderr = os.fdopen(sys.stderr.fileno(), "w", 0)
290N/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))
290N/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'
290N/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
290N/Ascripts_sunos = {
290N/A scripts_dir: [
290N/A ['client.py', 'pkg'],
290N/A ['publish.py', 'pkgsend'],
290N/A ['pull.py', 'pkgrecv'],
290N/A ['packagemanager.py', 'packagemanager'],
290N/A ['updatemanager.py', 'updatemanager'],
290N/A ],
290N/A lib_dir: [
290N/A ['depot.py', 'pkg.depotd'],
290N/A ['updatemanagernotifier.py', 'updatemanagernotifier'],
290N/A ],
290N/A }
290N/A
290N/Ascripts_windows = {
290N/A scripts_dir: [
290N/A ['client.py', 'client.py'],
290N/A ['publish.py', 'publish.py'],
290N/A ['pull.py', 'pull.py'],
290N/A ['scripts/pkg.bat', 'pkg.bat'],
290N/A ['scripts/pkgsend.bat', 'pkgsend.bat'],
290N/A ['scripts/pkgrecv.bat', 'pkgrecv.bat'],
290N/A ],
290N/A lib_dir: [
290N/A ['depot.py', 'depot.py'],
290N/A ['scripts/pkg.depotd.bat', 'pkg.depotd.bat'],
290N/A ],
290N/A }
290N/A
290N/Ascripts_other_unix = {
290N/A scripts_dir: [
290N/A ['client.py', 'client.py'],
290N/A ['pull.py', 'pull.py'],
290N/A ['publish.py', 'publish.py'],
290N/A ['scripts/pkg.sh', 'pkg'],
290N/A ['scripts/pkgsend.sh', 'pkgsend'],
290N/A ['scripts/pkgrecv.sh', 'pkgrecv'],
290N/A ],
290N/A lib_dir: [
290N/A ['depot.py', 'depot.py'],
290N/A ['scripts/pkg.depotd.sh', 'pkg.depotd'],
290N/A ],
290N/A }
290N/A
290N/A# indexed by 'osname'
290N/Ascripts = {
290N/A "sunos": scripts_sunos,
290N/A "linux": scripts_other_unix,
290N/A "windows": scripts_windows,
290N/A "darwin": scripts_other_unix,
290N/A "unknown": scripts_sunos,
290N/A }
290N/A
290N/Aman1_files = [
290N/A 'man/pkg.1',
290N/A 'man/pkgsend.1',
290N/A 'man/pkgrecv.1',
290N/A ]
290N/Aman1m_files = [
290N/A 'man/pkg.depotd.1m'
290N/A ]
290N/Aman5_files = [
290N/A 'man/pkg.5'
290N/A ]
290N/Apackages = [
290N/A 'pkg',
290N/A 'pkg.actions',
290N/A 'pkg.bundle',
290N/A 'pkg.client',
290N/A 'pkg.portable',
290N/A 'pkg.publish',
290N/A 'pkg.server'
290N/A ]
290N/Aweb_files = [
290N/A 'web/pkg-block-icon.png',
290N/A 'web/pkg-block-logo.png',
290N/A 'web/pkg.css',
290N/A 'web/feed-icon-32x32.png',
290N/A 'web/robots.txt',
290N/A ]
290N/Azones_files = [
290N/A 'brand/SUNWipkg.xml',
290N/A ]
290N/Abrand_files = [
290N/A 'brand/config.xml',
290N/A 'brand/platform.xml',
290N/A 'brand/pkgcreatezone',
290N/A ]
290N/Asmf_files = [
290N/A 'pkg-server.xml',
290N/A 'pkg-update.xml',
290N/A ]
290N/Aelf_srcs = [
290N/A 'modules/elf.c',
290N/A 'modules/elfextract.c',
290N/A 'modules/liblist.c',
290N/A ]
290N/Aarch_srcs = [
290N/A 'modules/arch.c'
290N/A ]
290N/A_actions_srcs = [
290N/A 'modules/actions/_actions.c'
290N/A ]
290N/Ainclude_dirs = [ 'modules' ]
290N/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
290N/A def escape(astring):
290N/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'] + \
290N/A ["%s%s" % ("-I", k) for k in include_dirs] + \
290N/A ['-I' + self.escape(get_python_inc())] + \
290N/A arch_srcs
290N/A elfcmd = ['lint'] + lint_flags + \
290N/A ["%s%s" % ("-I", k) for k in include_dirs] + \
290N/A ['-I' + self.escape(get_python_inc())] + \
290N/A ["%s%s" % ("-l", k) for k in elf_libraries] + \
290N/A elf_srcs
290N/A _actionscmd = ['lint'] + lint_flags + \
290N/A ["%s%s" % ("-I", k) for k in include_dirs] + \
290N/A ['-I' + self.escape(get_python_inc())] + \
290N/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))
290N/A print(" ".join(_actionscmd))
290N/A os.system(" ".join(_actionscmd))
290N/A
290N/A proto = os.path.join(root_dir, py_install_dir)
290N/A sys.path.insert(0, proto)
290N/A
290N/A # Insert tests directory onto sys.path so any custom checkers
290N/A # can be found.
290N/A sys.path.insert(0, os.path.join(pwd, 'tests'))
290N/A print(sys.path)
290N/A
290N/A # assumes pylint is accessible on the sys.path
290N/A from pylint import lint
290N/A scriptlist = [ 'setup.py' ]
290N/A for d, m in scripts_sunos.items():
290N/A for a in m:
290N/A # specify the filenames of the scripts, in addition
290N/A # to the package names themselves
290N/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',
290N/A os.path.join(pwd, 'tests', 'pylintrc')] +
290N/A scriptlist + packages)
290N/A
290N/Aclass install_func(_install):
290N/A def initialize_options(self):
290N/A _install.initialize_options(self)
290N/A
290N/A # PRIVATE_BUILD set in the environment tells us to put the build
290N/A # directory into the .pyc files, rather than the final
290N/A # installation directory.
290N/A private_build = os.getenv("PRIVATE_BUILD", None)
290N/A
290N/A # It's OK to have /'s here, python figures it out when writing files
290N/A if private_build is None:
290N/A self.install_lib = py_install_dir
290N/A self.install_data = "/"
290N/A self.root = root_dir
290N/A else:
290N/A self.install_lib = os.path.join(root_dir, py_install_dir)
290N/A self.install_data = root_dir
290N/A
290N/A # This is used when installing scripts, below, but it isn't a
290N/A # standard distutils variable.
290N/A self.root_dir = root_dir
290N/A
290N/A def run(self):
290N/A """
290N/A At the end of the install function, we need to rename some files
290N/A because distutils provides no way to rename files as they are
290N/A placed in their install locations.
290N/A Also, make sure that cherrypy is installed.
290N/A """
290N/A for f in man1_files + man1m_files + man5_files:
290N/A file_util.copy_file(f + ".txt", f, update=1)
290N/A
290N/A _install.run(self)
290N/A
290N/A for d, files in scripts[osname].iteritems():
290N/A for (srcname, dstname) in files:
290N/A dst_dir = util.change_root(self.root_dir, d)
290N/A dst_path = util.change_root(self.root_dir,
290N/A os.path.join(d, dstname))
290N/A dir_util.mkpath(dst_dir, verbose = True)
290N/A file_util.copy_file(srcname, dst_path, update = True)
290N/A # make scripts executable
290N/A os.chmod(dst_path,
290N/A os.stat(dst_path).st_mode | stat.S_IEXEC)
290N/A
290N/A install_sw(CP, CPVER, CPARC, CPDIR, CPURL, CPIDIR)
290N/A install_sw(PO, POVER, POARC, PODIR, POURL, POIDIR)
290N/A
290N/Adef install_sw(swname, swver, swarc, swdir, swurl, swidir):
290N/A if not os.path.exists(swarc):
290N/A print "downloading %s" % swname
290N/A try:
290N/A fname, hdr = urllib.urlretrieve(swurl, swarc)
290N/A except IOError:
290N/A pass
290N/A if not os.path.exists(swarc) or \
290N/A (hdr.gettype() != "application/x-gzip" and
290N/A hdr.gettype() != "application/x-tar"):
290N/A print "Unable to retrieve %s.\nPlease retrieve the file " \
290N/A "and place it at: %s\n" % (swurl, swarc)
290N/A # remove a partial download or error message from proxy
290N/A remove_sw(swname)
290N/A sys.exit(1)
290N/A if not os.path.exists(swdir):
290N/A print "unpacking %s" % swname
290N/A tar = tarfile.open(swarc)
290N/A # extractall doesn't exist until python 2.5
290N/A for m in tar.getmembers():
290N/A tar.extract(m)
290N/A tar.close()
290N/A swinst_dir = os.path.join(root_dir, py_install_dir, swidir)
290N/A if not os.path.exists(swinst_dir):
290N/A print "installing %s" % swname
290N/A subprocess.Popen(['python', 'setup.py', 'install',
290N/A '--root=%s' % root_dir,
290N/A '--install-lib=%s' % py_install_dir,
290N/A '--install-data=%s' % py_install_dir],
290N/A cwd = swdir).wait()
290N/A
290N/A
290N/Adef remove_sw(swname):
290N/A print("deleting %s" % swname)
290N/A for file in os.listdir("."):
290N/A if fnmatch.fnmatch(file, "%s*" % swname):
290N/A if os.path.isfile(file):
290N/A os.unlink(file)
290N/A else:
290N/A shutil.rmtree(file, True)
290N/A
290N/Aclass build_func(_build):
290N/A def initialize_options(self):
290N/A _build.initialize_options(self)
290N/A self.build_base = build_dir
290N/A
290N/Adef get_hg_version():
290N/A try:
290N/A p = subprocess.Popen(['hg', 'id', '-i'], stdout = subprocess.PIPE)
290N/A return p.communicate()[0].strip()
290N/A except OSError:
290N/A print >> sys.stderr, "ERROR: unable to obtain mercurial version"
290N/A return "unknown"
290N/A
290N/Aclass build_py_func(_build_py):
290N/A # override the build_module method to do VERSION substitution on pkg/__init__.py
290N/A def build_module (self, module, module_file, package):
290N/A if module == "__init__" and package == "pkg":
290N/A versionre = '(?m)^VERSION[^"]*"([^"]*)"'
290N/A # Grab the previously-built version out of the build
290N/A # tree.
290N/A try:
290N/A ocontent = \
290N/A file(self.get_module_outfile(self.build_lib,
290N/A [package], module)).read()
290N/A ov = re.search(versionre, ocontent).group(1)
290N/A except IOError:
290N/A ov = None
290N/A v = get_hg_version()
290N/A vstr = 'VERSION = "%s"' % v
290N/A # If the versions haven't changed, there's no need to
290N/A # recompile.
290N/A if v == ov:
290N/A return
290N/A
290N/A mcontent = file(module_file).read()
290N/A mcontent = re.sub(versionre, vstr, mcontent)
290N/A tmpfd, tmp_file = tempfile.mkstemp()
290N/A os.write(tmpfd, mcontent)
290N/A os.close(tmpfd)
290N/A print "doing version substitution: ", v
290N/A rv = _build_py.build_module(self, module, tmp_file, package)
290N/A os.unlink(tmp_file)
290N/A return rv
290N/A
290N/A return _build_py.build_module(self, module, module_file, package)
290N/A
290N/Aclass clean_func(_clean):
290N/A def initialize_options(self):
290N/A _clean.initialize_options(self)
290N/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
290N/A print("deleting " + dist_dir)
290N/A shutil.rmtree(dist_dir, True)
290N/A print("deleting " + build_dir)
290N/A shutil.rmtree(build_dir, True)
290N/A print("deleting " + root_dir)
290N/A shutil.rmtree(root_dir, True)
290N/A print("deleting " + pkgs_dir)
290N/A shutil.rmtree(pkgs_dir, True)
290N/A remove_sw(CP)
290N/A remove_sw(PO)
290N/A
290N/Aclass test_func(Command):
290N/A # NOTE: these options need to be in sync with tests/run.py
290N/A user_options = [("verbosemode", 'v', "run tests in verbose mode"),
290N/A ("genbaseline", 'g', "generate test baseline"),
290N/A ("parseable", 'p', "parseable output"),
290N/A ("baselinefile=", 'b', "baseline file <file>"),
290N/A ("only=", "o", "only <regex>")]
290N/A description = "Runs unit and functional tests"
290N/A
290N/A def initialize_options(self):
290N/A self.only = ""
290N/A self.baselinefile = ""
290N/A self.verbosemode = 0
290N/A self.parseable = 0
290N/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
290N/A # Reconstruct the cmdline and send that to run.py
290N/A cmd = [sys.executable, "run.py"]
290N/A args = ""
290N/A if "test" in sys.argv:
290N/A args = sys.argv[sys.argv.index("test")+1:]
290N/A cmd.extend(args)
290N/A subprocess.call(cmd)
290N/A
290N/Aclass dist_func(_bdist):
290N/A def initialize_options(self):
290N/A _bdist.initialize_options(self)
290N/A self.dist_dir = dist_dir
290N/A
# These are set to real values based on the platform, down below
compile_args = None
link_args = None
ext_modules = [
Extension(
'actions._actions',
_actions_srcs,
include_dirs = include_dirs,
extra_compile_args = compile_args,
extra_link_args = link_args
),
]
elf_libraries = None
data_files = [ (resource_dir, 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),
(smf_dir, smf_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')]
),
]
else:
elf_libraries += [ 'ssl' ]
setup(cmdclass = cmdclasses,
name = 'ips',
version = '1.0',
package_dir = {'pkg':'modules'},
packages = packages,
data_files = data_files,
ext_package = 'pkg',
ext_modules = ext_modules,
)