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