setup.py revision 383
409N/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#
20N/A
260N/Aimport os
20N/Aimport stat
20N/Aimport sys
20N/Aimport platform
22N/Aimport shutil
0N/Aimport code
50N/Aimport re
50N/Aimport subprocess
50N/Aimport string
50N/Aimport tempfile
50N/A
50N/Afrom distutils.core import setup, Extension
50N/Afrom distutils.cmd import Command
50N/Afrom distutils.command.install import install as _install
50N/Afrom distutils.command.build import build as _build
50N/Afrom distutils.command.build_py import build_py as _build_py
50N/Afrom distutils.command.bdist import bdist as _bdist
50N/Afrom distutils.command.clean import clean as _clean
50N/A
50N/Afrom distutils.sysconfig import get_python_inc
50N/Aimport distutils.file_util as file_util
50N/Aimport distutils.dir_util as dir_util
382N/Aimport distutils.util as util
382N/A
382N/Apwd = os.path.normpath(sys.path[0])
382N/A
382N/Aosname = platform.uname()[0].lower()
382N/Aostype = arch = 'unknown'
382N/Aif osname == 'sunos':
382N/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':
382N/A arch = osname
382N/A ostype = "windows"
382N/Aelif osname == 'darwin':
382N/A arch = osname
382N/A ostype = "posix"
382N/A
382N/Adist_dir = os.path.normpath(os.path.join(pwd, os.pardir, "proto", "dist_" + arch))
429N/Abuild_dir = os.path.normpath(os.path.join(pwd, os.pardir, "proto", "build_" + arch))
429N/Aroot_dir = os.path.normpath(os.path.join(pwd, os.pardir, "proto", "root_" + arch))
461N/A
461N/Apy_install_dir = 'usr/lib/python2.4/vendor-packages'
382N/A
26N/Ascripts_dir = 'usr/bin'
466N/Alib_dir = 'usr/lib'
0N/A
52N/Aman1_dir = 'usr/share/man/cat1'
451N/Aman1m_dir = 'usr/share/man/cat1m'
0N/Aman5_dir='usr/share/man/cat5'
382N/Aresource_dir = 'usr/share/lib/pkg'
382N/Asmf_dir = 'var/svc/manifest/application'
382N/Azones_dir = 'etc/zones'
452N/Abrand_dir = 'usr/lib/brand/ipkg'
382N/A
452N/Ascripts_sunos = {
382N/A scripts_dir : [
382N/A ['client.py', 'pkg'],
452N/A ['publish.py', 'pkgsend'],
382N/A ],
382N/A lib_dir : [
22N/A ['depot.py', 'pkg.depotd'],
114N/A ],
26N/A }
382N/A
382N/Ascripts_windows = {
428N/A scripts_dir : [
466N/A ['client.py', 'client.py'],
466N/A ['publish.py', 'publish.py'],
466N/A ['scripts/pkg.bat', 'pkg.bat'],
466N/A ['scripts/pkgsend.bat', 'pkgsend.bat'],
466N/A ],
23N/A lib_dir : [
466N/A ['depot.py', 'depot.py'],
466N/A ['scripts/pkg.depotd.bat', 'pkg.depotd.bat'],
466N/A ],
466N/A }
466N/A
466N/Ascripts_other_unix = {
466N/A scripts_dir : [
466N/A ['client.py', 'client.py'],
466N/A ['publish.py', 'publish.py'],
466N/A ['scripts/pkg.sh', 'pkg'],
466N/A ['scripts/pkgsend.sh', 'pkgsend'],
466N/A ],
26N/A lib_dir : [
461N/A ['depot.py', 'depot.py'],
466N/A ['scripts/pkg.depotd.sh', 'pkg.depotd'],
466N/A ],
382N/A }
135N/A
157N/A# indexed by 'osname'
461N/Ascripts = { "sunos" : scripts_sunos,
461N/A "linux" : scripts_other_unix,
461N/A "windows" : scripts_windows,
451N/A "darwin" : scripts_other_unix,
451N/A "unknown" : scripts_sunos,
466N/A }
466N/A
466N/Aman1_files= [
466N/A 'man/pkg.1.txt',
466N/A 'man/pkgsend.1.txt',
466N/A ]
466N/Aman1m_files = [
466N/A 'man/pkg.depotd.1m.txt'
466N/A ]
26N/Aman5_files = [
135N/A 'man/pkg.5.txt'
14N/A ]
382N/Apackages = [
429N/A 'pkg',
14N/A 'pkg.actions',
404N/A 'pkg.bundle',
404N/A 'pkg.client',
30N/A 'pkg.portable',
382N/A 'pkg.publish',
30N/A 'pkg.server',
382N/A ]
382N/A
382N/Aweb_files = [
382N/A 'web/pkg-block-icon.png',
382N/A 'web/pkg-block-logo.png',
429N/A 'web/pkg.css',
451N/A 'web/robots.txt',
461N/A ]
258N/A
382N/Azones_files = [
382N/A 'brand/SUNWipkg.xml',
382N/A ]
382N/A
30N/Abrand_files = [
466N/A 'brand/config.xml',
466N/A 'brand/platform.xml',
466N/A 'brand/pkgcreatezone',
466N/A ]
466N/Asmf_files = [
466N/A 'pkg-server.xml',
466N/A ]
466N/A
466N/Aelf_srcs = [
466N/A 'modules/elf.c',
466N/A 'modules/elfextract.c',
466N/A 'modules/liblist.c',
466N/A ]
466N/A
54N/Aarch_srcs = [
466N/A 'modules/arch.c'
466N/A ]
466N/A
466N/Ainclude_dirs = ['modules']
382N/A
466N/Alint_flags = [ '-u', '-axms', '-erroff=E_NAME_DEF_NOT_USED2' ]
135N/A
135N/A# Runs lint on the extension module source code
135N/Aclass lint_func(Command):
135N/A description = "Runs various lint tools over IPS extension source code"
382N/A user_options = []
135N/A
135N/A def initialize_options(self):
382N/A pass
382N/A
382N/A def finalize_options(self):
382N/A pass
382N/A
382N/A # Make string shell-friendly
382N/A @staticmethod
382N/A def escape(string):
382N/A return string.replace(' ', '\\ ')
382N/A
466N/A def run(self):
466N/A # assumes lint is on the $PATH
466N/A if osname == 'sunos' or osname == "linux":
466N/A archcmd = ['lint'] + lint_flags + ['-D_FILE_OFFSET_BITS=64'] + \
466N/A ["%s%s" % ("-I", k) for k in include_dirs] + \
466N/A ['-I' + self.escape(get_python_inc())] + \
135N/A arch_srcs
382N/A elfcmd = ['lint'] + lint_flags + \
157N/A ["%s%s" % ("-I", k) for k in include_dirs] + \
382N/A ['-I' + self.escape(get_python_inc())] + \
429N/A ["%s%s" % ("-l", k) for k in elf_libraries] + \
429N/A elf_srcs
429N/A
429N/A print(" ".join(archcmd))
429N/A os.system(" ".join(archcmd))
429N/A print(" ".join(elfcmd))
429N/A os.system(" ".join(elfcmd))
429N/A
429N/A proto = "%s/%s" % (root_dir, py_install_dir)
429N/A sys.path.insert(0, proto)
429N/A
451N/A # Insert tests directory onto sys.path so any custom checkers
451N/A # can be found.
451N/A sys.path.insert(0, os.path.join(pwd, 'tests'))
451N/A print(sys.path)
451N/A
451N/A # assumes pylint is accessible on the sys.path
451N/A from pylint import lint
451N/A scriptlist=[]
451N/A for dir,map in scripts_sunos.items():
451N/A for arr in map:
451N/A # specify the filenames of the scripts, in addition
451N/A # to the package names themselves
451N/A scriptlist.append(os.path.join(root_dir, dir, arr[1]))
451N/A
451N/A # For some reason, the load-plugins option, when used in the
461N/A # rcfile, does not work, so we put it here instead, to load
461N/A # our custom checkers.
135N/A lint.Run(['--load-plugins=multiplatform', '--rcfile',
466N/A os.path.join(pwd, 'tests', 'pylintrc')] +
382N/A scriptlist + packages)
466N/A
382N/A# Developer command to connect the local machine to the current
466N/A# repository's working copy's versions of the commands, modules, and supporting
466N/A# files.
451N/Aclass link_func(Command):
445N/A user_options = []
466N/A description = "Developer command to connect local machine to working " \
461N/A "copy of files in local repository"
466N/A
461N/A def initialize_options(self):
466N/A pass
466N/A def finalize_options(self):
451N/A pass
429N/A
429N/A def run(self):
429N/A os.system('mkdir -p /usr/share/lib/pkg')
429N/A os.system('mkdir -p /usr/lib/brand/ipkg')
429N/A os.system('mkdir -p /usr/share/man/cat1')
429N/A os.system('mkdir -p /usr/share/man/cat1m')
429N/A os.system('mkdir -p /usr/share/man/cat5')
429N/A
386N/A os.system('ln -sf ' + pwd + '/client.py /usr/bin/pkg')
382N/A os.system('ln -sf ' + pwd + '/publish.py /usr/bin/pkgsend')
382N/A os.system('ln -sf ' + pwd + '/depot.py /usr/bin/pkg.depotd')
382N/A os.system('ln -sf ' + pwd + '/modules ' + '/' + py_install_dir + '/pkg')
382N/A os.system('ln -sf ' + pwd + \
382N/A '/pkg-server.xml /var/svc/manifest/pkg-server.xml')
382N/A os.system('ln -sf ' + pwd + \
382N/A '/web/pkg-block-icon.png /usr/share/lib/pkg/pkg-block-icon.png')
382N/A os.system('ln -sf ' + pwd + \
382N/A '/web/pkg-block-logo.png /usr/share/lib/pkg/pkg-block-logo.png')
382N/A os.system('ln -sf ' + pwd + \
382N/A '/web/pkg.css /usr/share/lib/pkg/pkg.css')
382N/A os.system('ln -sf ' + pwd + \
382N/A '/brand/config.xml /usr/lib/brand/ipkg/config.xml')
461N/A os.system('ln -sf ' + pwd + \
461N/A '/brand/platform.xml /usr/lib/brand/ipkg/platform.xml')
461N/A os.system('ln -sf ' + pwd +
382N/A '/brand/pkgcreatezone /usr/lib/brand/ipkg/pkgcreatezone')
382N/A os.system('ln -sf ' + pwd + \
382N/A '/brand/SUNWipkg.xml /etc/zones/SUNWipkg.xml')
382N/A os.system('ln -sf ' + pwd + '/man/pkg.1.txt /usr/share/man/cat1/pkg.1')
382N/A os.system('ln -sf ' + pwd + \
382N/A '/man/pkgsend.1.txt /usr/share/man/cat1/pkgsend.1')
382N/A os.system('ln -sf ' + pwd + \
382N/A '/man/pkg.depotd.1m.txt /usr/share/man/cat1m/pkg.depotd.1m')
452N/A os.system('ln -sf ' + pwd + '/man/pkg.5.txt /usr/share/man/man5/pkg.5')
466N/A
466N/Aclass link_clean_func(Command):
382N/A user_options = []
382N/A description = "Cleans up links created by the \"link\" command"
466N/A
452N/A def initialize_options(self):
382N/A pass
382N/A def finalize_options(self):
466N/A pass
466N/A
466N/A def run(self):
466N/A
466N/A os.system('rm -f /usr/bin/pkg')
466N/A os.system('rm -f /usr/bin/pkgsend')
466N/A os.system('rm -f /usr/lib/pkg.depotd')
466N/A os.system('rm -f ' + '/' + py_install_dir + '/pkg')
466N/A os.system('rm -f /var/svc/manifest/pkg-server.xml')
466N/A os.system('rm -rf /usr/share/lib/pkg')
466N/A os.system('rm -rf /usr/lib/brand/ipkg')
466N/A os.system('rm -f /etc/zones/SUNWipkg.xml')
466N/A os.system('rm -f /usr/share/man/cat1/pkg.1')
466N/A os.system('rm -f /usr/share/man/cat1/pkgsend.1')
466N/A os.system('rm -f /usr/share/man/cat1m/pkg.depotd.1m')
466N/A os.system('rm -f /usr/share/man/man5/pkg.5')
466N/A
466N/Aclass install_func(_install):
466N/A def initialize_options(self):
466N/A _install.initialize_options(self)
466N/A # It's OK to have /'s here, python figures it out when writing files
466N/A self.install_purelib = py_install_dir
466N/A self.install_platlib = py_install_dir
466N/A self.root = root_dir
466N/A self.prefix = '.'
466N/A
466N/A # At the end of the install function, we need to rename some files
466N/A # because distutils provides no way to rename files as they are placed
466N/A # in their install locations
466N/A def run(self):
466N/A _install.run(self)
466N/A if ostype == 'posix':
466N/A # only rename manpages if building for unix-derived OS
466N/A for (dir, files) in [(man1_dir, man1_files), (man1m_dir,
382N/A man1m_files), (man5_dir, man5_files)]:
451N/A for file in files:
382N/A src = util.change_root(self.root, os.path.join(dir,
452N/A os.path.basename(file)))
452N/A if src.endswith('.txt'):
452N/A dst = src[:-4]
452N/A file_util.copy_file(src, dst, update=True)
452N/A
452N/A for dir, files in scripts[osname].iteritems():
382N/A for (srcname, dstname) in files:
382N/A dst_dir = util.change_root(self.root, dir)
382N/A dst_path = util.change_root(self.root,
382N/A os.path.join(dir, dstname))
382N/A dir_util.mkpath(dst_dir, verbose=True)
382N/A file_util.copy_file(srcname, dst_path, update=True)
382N/A # make scripts executable
382N/A os.chmod(dst_path, os.stat(dst_path).st_mode | stat.S_IEXEC)
382N/A
382N/Aclass build_func(_build):
382N/A def initialize_options(self):
145N/A _build.initialize_options(self)
451N/A self.build_base = build_dir
451N/A
451N/Adef get_hg_version():
451N/A try:
451N/A p = subprocess.Popen(['hg', 'id', '-i'], stdout=subprocess.PIPE)
451N/A return p.communicate()[0].strip()
451N/A except OSError:
451N/A print >>stderr, "ERROR: unable to obtain mercurial version"
451N/A return "unknown"
451N/A
451N/Aclass build_py_func(_build_py):
451N/A # override the build_module method to do VERSION substitution on pkg/__init__.py
451N/A def build_module (self, module, module_file, package):
451N/A if module == "__init__" and package == "pkg":
451N/A mcontent = file(module_file).read()
451N/A v = 'VERSION = "%s"' % get_hg_version()
451N/A mcontent = re.sub('(?m)^VERSION[^"]*"([^"]*)"', v, mcontent)
451N/A tmpfd, tmp_file = tempfile.mkstemp()
451N/A os.write(tmpfd, mcontent)
451N/A os.close(tmpfd)
451N/A print "doing version substitution: ", v
466N/A rv = _build_py.build_module(self, module, tmp_file, package)
466N/A os.unlink(tmp_file)
466N/A return rv
466N/A return _build_py.build_module(self, module, module_file, package)
466N/A
466N/Aclass clean_func(_clean):
466N/A def initialize_options(self):
466N/A _clean.initialize_options(self)
466N/A self.build_base = build_dir
466N/A
466N/Aclass clobber_func(Command):
466N/A user_options = []
217N/A description = "Deletes any and all files created by setup"
466N/A
466N/A def initialize_options(self):
466N/A pass
466N/A def finalize_options(self):
466N/A pass
466N/A def run(self):
466N/A # nuke everything
382N/A print("Deleting " + dist_dir)
466N/A shutil.rmtree(dist_dir, True)
466N/A print("Deleting " + build_dir)
217N/A shutil.rmtree(build_dir, True)
print("Deleting " + root_dir)
shutil.rmtree(root_dir, True)
class test_func(Command):
user_options = []
description = "Runs unit and functional tests"
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
os.putenv('PYEXE', sys.executable)
os.chdir(os.path.join(pwd, "tests"))
testlogfd, testlogpath = tempfile.mkstemp(suffix = '.pkg-test.log')
testlogfp = os.fdopen(testlogfd, "w")
print "Logging to %s" % testlogpath
subprocess.call([sys.executable, "api-complete.py"], stdout=testlogfp)
if ostype == 'posix':
subprocess.call([sys.executable, "cli-complete.py"], stdout=testlogfp)
if osname == 'sunos':
subprocess.call(["/bin/ksh", "memleaks.ksh"], stdout=testlogfp)
testlogfp.close()
class dist_func(_bdist):
def initialize_options(self):
_bdist.initialize_options(self)
self.dist_dir = dist_dir
# These are set to real values based on the platform, down below
ext_modules = None
compile_args = None
link_args = None
elf_libraries = None
data_files = [
(resource_dir, web_files),
]
cmdclasses={
'link' : link_func,
'linkclean' : link_clean_func,
'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,
)