setup.py revision 384
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
290N/Aimport os
290N/Aimport stat
290N/Aimport sys
290N/Aimport platform
290N/Aimport shutil
290N/Aimport code
383N/Aimport re
290N/Aimport subprocess
383N/Aimport string
384N/Aimport sys
290N/Aimport tempfile
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
290N/Apwd = os.path.normpath(sys.path[0])
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/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/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 ],
290N/A lib_dir : [
290N/A ['depot.py', 'pkg.depotd'],
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 ['scripts/pkg.bat', 'pkg.bat'],
290N/A ['scripts/pkgsend.bat', 'pkgsend.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 ['publish.py', 'publish.py'],
290N/A ['scripts/pkg.sh', 'pkg'],
290N/A ['scripts/pkgsend.sh', 'pkgsend'],
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 = { "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.txt',
290N/A 'man/pkgsend.1.txt',
290N/A ]
290N/Aman1m_files = [
290N/A 'man/pkg.depotd.1m.txt'
290N/A ]
290N/Aman5_files = [
290N/A 'man/pkg.5.txt'
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/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/robots.txt',
290N/A ]
290N/A
290N/Azones_files = [
290N/A 'brand/SUNWipkg.xml',
290N/A ]
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 ]
290N/A
290N/Aelf_srcs = [
290N/A 'modules/elf.c',
290N/A 'modules/elfextract.c',
290N/A 'modules/liblist.c',
290N/A ]
290N/A
290N/Aarch_srcs = [
290N/A 'modules/arch.c'
290N/A ]
290N/A
290N/Ainclude_dirs = ['modules']
290N/A
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(string):
290N/A return string.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
290N/A print(" ".join(archcmd))
290N/A os.system(" ".join(archcmd))
290N/A print(" ".join(elfcmd))
290N/A os.system(" ".join(elfcmd))
290N/A
290N/A proto = "%s/%s" % (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=[]
290N/A for dir,map in scripts_sunos.items():
290N/A for arr in map:
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, dir, arr[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/A# Developer command to connect the local machine to the current
290N/A# repository's working copy's versions of the commands, modules, and supporting
290N/A# files.
290N/Aclass link_func(Command):
290N/A user_options = []
290N/A description = "Developer command to connect local machine to working " \
290N/A "copy of files in local repository"
290N/A
290N/A def initialize_options(self):
290N/A pass
290N/A def finalize_options(self):
290N/A pass
290N/A
290N/A def run(self):
290N/A os.system('mkdir -p /usr/share/lib/pkg')
290N/A os.system('mkdir -p /usr/lib/brand/ipkg')
290N/A os.system('mkdir -p /usr/share/man/cat1')
290N/A os.system('mkdir -p /usr/share/man/cat1m')
290N/A os.system('mkdir -p /usr/share/man/cat5')
290N/A
290N/A os.system('ln -sf ' + pwd + '/client.py /usr/bin/pkg')
290N/A os.system('ln -sf ' + pwd + '/publish.py /usr/bin/pkgsend')
290N/A os.system('ln -sf ' + pwd + '/depot.py /usr/bin/pkg.depotd')
290N/A os.system('ln -sf ' + pwd + '/modules ' + '/' + py_install_dir + '/pkg')
290N/A os.system('ln -sf ' + pwd + \
290N/A '/pkg-server.xml /var/svc/manifest/pkg-server.xml')
290N/A os.system('ln -sf ' + pwd + \
290N/A '/web/pkg-block-icon.png /usr/share/lib/pkg/pkg-block-icon.png')
290N/A os.system('ln -sf ' + pwd + \
290N/A '/web/pkg-block-logo.png /usr/share/lib/pkg/pkg-block-logo.png')
290N/A os.system('ln -sf ' + pwd + \
290N/A '/web/pkg.css /usr/share/lib/pkg/pkg.css')
290N/A os.system('ln -sf ' + pwd + \
290N/A '/brand/config.xml /usr/lib/brand/ipkg/config.xml')
290N/A os.system('ln -sf ' + pwd + \
290N/A '/brand/platform.xml /usr/lib/brand/ipkg/platform.xml')
290N/A os.system('ln -sf ' + pwd +
290N/A '/brand/pkgcreatezone /usr/lib/brand/ipkg/pkgcreatezone')
290N/A os.system('ln -sf ' + pwd + \
290N/A '/brand/SUNWipkg.xml /etc/zones/SUNWipkg.xml')
290N/A os.system('ln -sf ' + pwd + '/man/pkg.1.txt /usr/share/man/cat1/pkg.1')
290N/A os.system('ln -sf ' + pwd + \
290N/A '/man/pkgsend.1.txt /usr/share/man/cat1/pkgsend.1')
290N/A os.system('ln -sf ' + pwd + \
290N/A '/man/pkg.depotd.1m.txt /usr/share/man/cat1m/pkg.depotd.1m')
290N/A os.system('ln -sf ' + pwd + '/man/pkg.5.txt /usr/share/man/man5/pkg.5')
290N/A
290N/Aclass link_clean_func(Command):
290N/A user_options = []
290N/A description = "Cleans up links created by the \"link\" command"
290N/A
290N/A def initialize_options(self):
290N/A pass
290N/A def finalize_options(self):
290N/A pass
290N/A
290N/A def run(self):
290N/A
290N/A os.system('rm -f /usr/bin/pkg')
290N/A os.system('rm -f /usr/bin/pkgsend')
290N/A os.system('rm -f /usr/lib/pkg.depotd')
290N/A os.system('rm -f ' + '/' + py_install_dir + '/pkg')
290N/A os.system('rm -f /var/svc/manifest/pkg-server.xml')
290N/A os.system('rm -rf /usr/share/lib/pkg')
290N/A os.system('rm -rf /usr/lib/brand/ipkg')
290N/A os.system('rm -f /etc/zones/SUNWipkg.xml')
290N/A os.system('rm -f /usr/share/man/cat1/pkg.1')
290N/A os.system('rm -f /usr/share/man/cat1/pkgsend.1')
290N/A os.system('rm -f /usr/share/man/cat1m/pkg.depotd.1m')
290N/A os.system('rm -f /usr/share/man/man5/pkg.5')
290N/A
290N/Aclass install_func(_install):
290N/A def initialize_options(self):
290N/A _install.initialize_options(self)
290N/A # It's OK to have /'s here, python figures it out when writing files
290N/A self.install_purelib = py_install_dir
290N/A self.install_platlib = py_install_dir
290N/A self.root = root_dir
290N/A self.prefix = '.'
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 placed
290N/A # in their install locations
290N/A def run(self):
290N/A _install.run(self)
290N/A if ostype == 'posix':
290N/A # only rename manpages if building for unix-derived OS
290N/A for (dir, files) in [(man1_dir, man1_files), (man1m_dir,
290N/A man1m_files), (man5_dir, man5_files)]:
290N/A for file in files:
290N/A src = util.change_root(self.root, os.path.join(dir,
290N/A os.path.basename(file)))
290N/A if src.endswith('.txt'):
290N/A dst = src[:-4]
290N/A file_util.copy_file(src, dst, update=True)
290N/A
290N/A for dir, files in scripts[osname].iteritems():
290N/A for (srcname, dstname) in files:
290N/A dst_dir = util.change_root(self.root, dir)
290N/A dst_path = util.change_root(self.root,
290N/A os.path.join(dir, 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, os.stat(dst_path).st_mode | stat.S_IEXEC)
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
383N/Adef get_hg_version():
383N/A try:
383N/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":
383N/A mcontent = file(module_file).read()
383N/A v = 'VERSION = "%s"' % get_hg_version()
383N/A mcontent = re.sub('(?m)^VERSION[^"]*"([^"]*)"', v, 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
383N/A return _build_py.build_module(self, module, module_file, package)
383N/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
290N/Aclass test_func(Command):
290N/A user_options = []
290N/A description = "Runs unit and functional tests"
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 os.putenv('PYEXE', sys.executable)
290N/A os.chdir(os.path.join(pwd, "tests"))
290N/A testlogfd, testlogpath = tempfile.mkstemp(suffix = '.pkg-test.log')
290N/A testlogfp = os.fdopen(testlogfd, "w")
290N/A print "Logging to %s" % testlogpath
290N/A
290N/A subprocess.call([sys.executable, "api-complete.py"], stdout=testlogfp)
290N/A
290N/A if ostype == 'posix':
290N/A subprocess.call([sys.executable, "cli-complete.py"], stdout=testlogfp)
290N/A if osname == 'sunos':
290N/A subprocess.call(["/bin/ksh", "memleaks.ksh"], stdout=testlogfp)
290N/A testlogfp.close()
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
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
290N/Adata_files = [
290N/A (resource_dir, web_files),
290N/A ]
290N/Acmdclasses={
290N/A 'link' : link_func,
290N/A 'linkclean' : link_clean_func,
290N/A 'install' : install_func,
290N/A 'build' : build_func,
383N/A 'build_py' : build_py_func,
290N/A 'bdist' : dist_func,
290N/A 'lint' : lint_func,
290N/A 'clean' : clean_func,
290N/A 'clobber' : clobber_func,
290N/A 'test' : test_func,
290N/A }
290N/A
383N/A# all builds of IPS should have manpages
383N/Adata_files += [
290N/A (man1_dir, man1_files),
290N/A (man1m_dir, man1m_files),
290N/A (man5_dir, man5_files),
290N/A ]
290N/A
290N/Aif osname == 'sunos':
290N/A # Solaris-specific extensions are added here
290N/A data_files += [
290N/A (zones_dir, zones_files),
290N/A (brand_dir, brand_files),
290N/A (smf_dir, smf_files),
290N/A ]
290N/A
290N/Aif osname == 'sunos' or osname == "linux":
290N/A # Unix platforms which the elf extension has been ported to
290N/A # are specified here, so they are built automatically
290N/A elf_libraries = ['elf']
290N/A ext_modules=[
290N/A Extension(
290N/A 'elf',
290N/A elf_srcs,
290N/A include_dirs=include_dirs,
290N/A libraries=elf_libraries,
290N/A extra_compile_args=compile_args,
290N/A extra_link_args=link_args
290N/A ),
290N/A ]
290N/A
290N/A # Solaris has built-in md library and Solaris-specific arch extension
290N/A # All others use OpenSSL and cross-platform arch module
290N/A if osname == 'sunos':
290N/A elf_libraries += ['md']
290N/A ext_modules += [
290N/A Extension(
290N/A 'arch',
290N/A arch_srcs,
290N/A include_dirs=include_dirs,
290N/A extra_compile_args=compile_args,
290N/A extra_link_args=link_args,
290N/A define_macros=[('_FILE_OFFSET_BITS', '64')]
290N/A ),
290N/A ]
290N/A else:
290N/A elf_libraries += ['ssl']
290N/A
290N/Asetup(cmdclass=cmdclasses,
290N/A name='ips',
290N/A version='1.0',
290N/A package_dir= {'pkg':'modules'},
290N/A packages=packages,
290N/A data_files=data_files,
290N/A ext_package='pkg',
290N/A ext_modules=ext_modules,
290N/A )