setup.py revision 742
0N/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#
20N/A# Copyright 2008 Sun Microsystems, Inc. All rights reserved.
20N/A# Use is subject to license terms.
20N/A#
20N/A
22N/Aimport fnmatch
0N/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
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
0N/Afrom distutils.command.clean import clean as _clean
54N/A
26N/Afrom distutils.sysconfig import get_python_inc
0N/Aimport distutils.file_util as file_util
0N/Aimport distutils.dir_util as dir_util
0N/Aimport distutils.util as util
0N/A
52N/A# 3rd party software required for the build
0N/ACP = 'CherryPy'
22N/ACPIDIR = 'cherrypy'
0N/ACPVER = '3.1.0'
34N/ACPARC = '%s-%s.tar.gz' % (CP, CPVER)
22N/ACPDIR = '%s-%s' % (CP, CPVER)
22N/ACPURL = 'http://download.cherrypy.org/cherrypy/%s/%s' % (CPVER, CPARC)
22N/A
46N/APO = 'pyOpenSSL'
34N/APOIDIR = 'OpenSSL'
22N/APOVER = '0.7'
22N/APOARC = '%s-%s.tar.gz' % (PO, POVER)
26N/APODIR = '%s-%s' % (PO, POVER)
23N/APOURL = 'http://downloads.sourceforge.net/pyopenssl/%s' % (POARC)
23N/A
26N/AFL = 'figleaf'
26N/AFLIDIR = 'figleaf'
26N/AFLVER = 'latest'
26N/AFLARC = '%s-%s.tar.gz' % (FL, FLVER)
14N/AFLDIR = '%s-%s' % (FL, FLVER)
50N/AFLURL = 'http://darcs.idyll.org/~t/projects/%s' % FLARC
30N/A
14N/AMAKO = 'Mako'
0N/AMAKOIDIR = 'mako'
25N/AMAKOVER = '0.2.2'
0N/AMAKOARC = '%s-%s.tar.gz' % (MAKO, MAKOVER)
26N/AMAKODIR = '%s-%s' % (MAKO, MAKOVER)
26N/AMAKOURL = 'http://www.makotemplates.org/downloads/%s' % (MAKOARC)
50N/A
30N/Aosname = platform.uname()[0].lower()
50N/Aostype = arch = 'unknown'
50N/Aif osname == 'sunos':
50N/A arch = platform.processor()
30N/A ostype = "posix"
30N/Aelif osname == 'linux':
30N/A arch = "linux_" + platform.machine()
30N/A ostype = "posix"
30N/Aelif osname == 'windows':
30N/A arch = osname
30N/A ostype = "windows"
50N/Aelif osname == 'darwin':
45N/A arch = osname
30N/A ostype = "posix"
50N/A
45N/Apwd = os.path.normpath(sys.path[0])
30N/A
30N/A#
30N/A# Unbuffer stdout and stderr. This helps to ensure that subprocess output
30N/A# is properly interleaved with output from this program.
45N/A#
30N/Asys.stdout = os.fdopen(sys.stdout.fileno(), "w", 0)
50N/Asys.stderr = os.fdopen(sys.stderr.fileno(), "w", 0)
30N/A
30N/Adist_dir = os.path.normpath(os.path.join(pwd, os.pardir, "proto", "dist_" + arch))
30N/Abuild_dir = os.path.normpath(os.path.join(pwd, os.pardir, "proto", "build_" + arch))
30N/Aroot_dir = os.path.normpath(os.path.join(pwd, os.pardir, "proto", "root_" + arch))
30N/Apkgs_dir = os.path.normpath(os.path.join(pwd, os.pardir, "packages", arch))
30N/A
54N/Apy_install_dir = 'usr/lib/python2.4/vendor-packages'
54N/A
54N/Ascripts_dir = 'usr/bin'
54N/Alib_dir = 'usr/lib'
54N/Asvc_method_dir = 'lib/svc/method'
54N/A
54N/Aman1_dir = 'usr/share/man/cat1'
54N/Aman1m_dir = 'usr/share/man/cat1m'
54N/Aman5_dir = 'usr/share/man/cat5'
30N/Aresource_dir = 'usr/share/lib/pkg'
30N/Asmf_dir = 'var/svc/manifest/application'
30N/Azones_dir = 'etc/zones'
30N/Abrand_dir = 'usr/lib/brand/ipkg'
30N/A
30N/Ascripts_sunos = {
0N/A scripts_dir: [
0N/A ['client.py', 'pkg'],
22N/A ['publish.py', 'pkgsend'],
22N/A ['pull.py', 'pkgrecv'],
22N/A ['packagemanager.py', 'packagemanager'],
22N/A ['updatemanager.py', 'updatemanager'],
22N/A ],
22N/A lib_dir: [
26N/A ['depot.py', 'pkg.depotd'],
0N/A ['updatemanagernotifier.py', 'updatemanagernotifier'],
22N/A ],
22N/A svc_method_dir: [
22N/A ['svc-pkg-depot', 'svc-pkg-depot'],
22N/A ],
22N/A }
22N/A
22N/Ascripts_windows = {
22N/A scripts_dir: [
0N/A ['client.py', 'client.py'],
0N/A ['publish.py', 'publish.py'],
0N/A ['pull.py', 'pull.py'],
0N/A ['scripts/pkg.bat', 'pkg.bat'],
0N/A ['scripts/pkgsend.bat', 'pkgsend.bat'],
0N/A ['scripts/pkgrecv.bat', 'pkgrecv.bat'],
0N/A ],
22N/A lib_dir: [
26N/A ['depot.py', 'depot.py'],
22N/A ['scripts/pkg.depotd.bat', 'pkg.depotd.bat'],
26N/A ],
22N/A }
22N/A
22N/Ascripts_other_unix = {
22N/A scripts_dir: [
22N/A ['client.py', 'client.py'],
22N/A ['pull.py', 'pull.py'],
26N/A ['publish.py', 'publish.py'],
22N/A ['scripts/pkg.sh', 'pkg'],
26N/A ['scripts/pkgsend.sh', 'pkgsend'],
0N/A ['scripts/pkgrecv.sh', 'pkgrecv'],
0N/A ],
0N/A lib_dir: [
0N/A ['depot.py', 'depot.py'],
0N/A ['scripts/pkg.depotd.sh', 'pkg.depotd'],
0N/A ],
26N/A }
22N/A
0N/A# indexed by 'osname'
20N/Ascripts = {
34N/A "sunos": scripts_sunos,
21N/A "linux": scripts_other_unix,
34N/A "windows": scripts_windows,
0N/A "darwin": scripts_other_unix,
0N/A "unknown": scripts_sunos,
0N/A }
0N/A
26N/Aman1_files = [
0N/A 'man/pkg.1',
50N/A 'man/pkgsend.1',
26N/A 'man/pkgrecv.1',
50N/A ]
30N/Aman1m_files = [
50N/A 'man/pkg.depotd.1m'
26N/A ]
26N/Aman5_files = [
0N/A 'man/pkg.5'
0N/A ]
0N/Apackages = [
0N/A 'pkg',
22N/A 'pkg.actions',
22N/A 'pkg.bundle',
0N/A 'pkg.client',
0N/A 'pkg.portable',
26N/A 'pkg.publish',
26N/A 'pkg.server'
26N/A ]
26N/A
22N/Aweb_files = []
22N/Afor entry in os.walk("web"):
22N/A web_dir, dirs, files = entry
26N/A if not files:
26N/A continue
26N/A web_files.append((os.path.join(resource_dir, web_dir), [
26N/A os.path.join(web_dir, f) for f in files
37N/A if f != "Makefile"
26N/A ]))
26N/A
26N/Azones_files = [
26N/A 'brand/SUNWipkg.xml',
26N/A ]
37N/Abrand_files = [
37N/A 'brand/config.xml',
37N/A 'brand/platform.xml',
37N/A 'brand/pkgcreatezone',
37N/A ]
37N/Asmf_files = [
26N/A 'pkg-server.xml',
26N/A 'pkg-update.xml',
0N/A ]
0N/Apspawn_srcs = [
22N/A 'modules/pspawn.c'
22N/A ]
30N/Aelf_srcs = [
30N/A 'modules/elf.c',
0N/A 'modules/elfextract.c',
0N/A 'modules/liblist.c',
0N/A ]
0N/Aarch_srcs = [
25N/A 'modules/arch.c'
0N/A ]
30N/A_actions_srcs = [
30N/A 'modules/actions/_actions.c'
0N/A ]
0N/Ainclude_dirs = [ 'modules' ]
0N/Alint_flags = [ '-u', '-axms', '-erroff=E_NAME_DEF_NOT_USED2' ]
0N/A
0N/A# Runs the test suite with the code coverage suite (figleaf) turned on, and
0N/A# outputs a coverage report.
0N/A# TODO: Make the cov report format an option (html, ast, cov, etc)
0N/Aclass cov_func(Command):
0N/A description = "Runs figleaf code coverage suite"
25N/A user_options = []
0N/A def initialize_options(self):
30N/A pass
30N/A def finalize_options(self):
0N/A pass
22N/A def run(self):
22N/A if not os.path.isdir(FLDIR):
26N/A install_sw(FL, FLVER, FLARC, FLDIR, FLURL, FLIDIR)
26N/A # Run the test suite with coverage enabled
26N/A os.putenv('PYEXE', sys.executable)
26N/A os.chdir(os.path.join(pwd, "tests"))
26N/A # Reconstruct the cmdline and send that to run.py
26N/A os.environ["PKGCOVERAGE"] = "1"
26N/A cmd = [sys.executable, "run.py"]
26N/A subprocess.call(cmd)
52N/A print "Generating coverage report in directory: '%s/cov_report'" % \
52N/A pwd
26N/A os.system("figleaf2html -d cov_report .figleaf")
26N/A
22N/A# Runs lint on the extension module source code
22N/Aclass lint_func(Command):
description = "Runs various lint tools over IPS extension source code"
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
# Make string shell-friendly
@staticmethod
def escape(astring):
return astring.replace(' ', '\\ ')
def run(self):
# assumes lint is on the $PATH
if osname == 'sunos' or osname == "linux":
archcmd = ['lint'] + lint_flags + ['-D_FILE_OFFSET_BITS=64'] + \
["%s%s" % ("-I", k) for k in include_dirs] + \
['-I' + self.escape(get_python_inc())] + \
arch_srcs
elfcmd = ['lint'] + lint_flags + \
["%s%s" % ("-I", k) for k in include_dirs] + \
['-I' + self.escape(get_python_inc())] + \
["%s%s" % ("-l", k) for k in elf_libraries] + \
elf_srcs
_actionscmd = ['lint'] + lint_flags + \
["%s%s" % ("-I", k) for k in include_dirs] + \
['-I' + self.escape(get_python_inc())] + \
_actions_srcs
pspawncmd = ['lint'] + lint_flags + ['-D_FILE_OFFSET_BITS=64'] + \
["%s%s" % ("-I", k) for k in include_dirs] + \
['-I' + self.escape(get_python_inc())] + \
pspawn_srcs
print(" ".join(archcmd))
os.system(" ".join(archcmd))
print(" ".join(elfcmd))
os.system(" ".join(elfcmd))
print(" ".join(_actionscmd))
os.system(" ".join(_actionscmd))
print(" ".join(pspawncmd))
os.system(" ".join(pspawncmd))
proto = os.path.join(root_dir, py_install_dir)
sys.path.insert(0, proto)
# Insert tests directory onto sys.path so any custom checkers
# can be found.
sys.path.insert(0, os.path.join(pwd, 'tests'))
print(sys.path)
# assumes pylint is accessible on the sys.path
from pylint import lint
scriptlist = [ 'setup.py' ]
for d, m in scripts_sunos.items():
for a in m:
# specify the filenames of the scripts, in addition
# to the package names themselves
scriptlist.append(os.path.join(root_dir, d, a[1]))
# For some reason, the load-plugins option, when used in the
# rcfile, does not work, so we put it here instead, to load
# our custom checkers.
lint.Run(['--load-plugins=multiplatform', '--rcfile',
os.path.join(pwd, 'tests', 'pylintrc')] +
scriptlist + packages)
class install_func(_install):
def initialize_options(self):
_install.initialize_options(self)
# PRIVATE_BUILD set in the environment tells us to put the build
# directory into the .pyc files, rather than the final
# installation directory.
private_build = os.getenv("PRIVATE_BUILD", None)
# It's OK to have /'s here, python figures it out when writing files
if private_build is None:
self.install_lib = py_install_dir
self.install_data = "/"
self.root = root_dir
else:
self.install_lib = os.path.join(root_dir, py_install_dir)
self.install_data = root_dir
# This is used when installing scripts, below, but it isn't a
# standard distutils variable.
self.root_dir = root_dir
def run(self):
"""
At the end of the install function, we need to rename some files
because distutils provides no way to rename files as they are
placed in their install locations.
Also, make sure that cherrypy is installed.
"""
for f in man1_files + man1m_files + man5_files:
file_util.copy_file(f + ".txt", f, update=1)
_install.run(self)
for d, files in scripts[osname].iteritems():
for (srcname, dstname) in files:
dst_dir = util.change_root(self.root_dir, d)
dst_path = util.change_root(self.root_dir,
os.path.join(d, dstname))
dir_util.mkpath(dst_dir, verbose = True)
file_util.copy_file(srcname, dst_path, update = True)
# make scripts executable
os.chmod(dst_path,
os.stat(dst_path).st_mode | stat.S_IEXEC)
install_sw(CP, CPVER, CPARC, CPDIR, CPURL, CPIDIR)
install_sw(PO, POVER, POARC, PODIR, POURL, POIDIR)
install_sw(MAKO, MAKOVER, MAKOARC, MAKODIR, MAKOURL, MAKOIDIR)
def install_sw(swname, swver, swarc, swdir, swurl, swidir):
if not os.path.exists(swarc):
print "downloading %s" % swname
try:
fname, hdr = urllib.urlretrieve(swurl, swarc)
except IOError:
pass
if not os.path.exists(swarc) or \
(hdr.gettype() != "application/x-gzip" and
hdr.gettype() != "application/x-tar"):
print "Unable to retrieve %s.\nPlease retrieve the file " \
"and place it at: %s\n" % (swurl, swarc)
# remove a partial download or error message from proxy
remove_sw(swname)
sys.exit(1)
if not os.path.exists(swdir):
print "unpacking %s" % swname
tar = tarfile.open(swarc)
# extractall doesn't exist until python 2.5
for m in tar.getmembers():
tar.extract(m)
tar.close()
swinst_dir = os.path.join(root_dir, py_install_dir, swidir)
if not os.path.exists(swinst_dir):
print "installing %s" % swname
subprocess.Popen(['python', 'setup.py', 'install',
'--root=%s' % root_dir,
'--install-lib=%s' % py_install_dir,
'--install-data=%s' % py_install_dir],
cwd = swdir).wait()
def remove_sw(swname):
print("deleting %s" % swname)
for file in os.listdir("."):
if fnmatch.fnmatch(file, "%s*" % swname):
if os.path.isfile(file):
os.unlink(file)
else:
shutil.rmtree(file, True)
class build_func(_build):
def initialize_options(self):
_build.initialize_options(self)
self.build_base = build_dir
def get_hg_version():
try:
p = subprocess.Popen(['hg', 'id', '-i'], stdout = subprocess.PIPE)
return p.communicate()[0].strip()
except OSError:
print >> sys.stderr, "ERROR: unable to obtain mercurial version"
return "unknown"
class build_py_func(_build_py):
# override the build_module method to do VERSION substitution on pkg/__init__.py
def build_module (self, module, module_file, package):
if module == "__init__" and package == "pkg":
versionre = '(?m)^VERSION[^"]*"([^"]*)"'
# Grab the previously-built version out of the build
# tree.
try:
ocontent = \
file(self.get_module_outfile(self.build_lib,
[package], module)).read()
ov = re.search(versionre, ocontent).group(1)
except IOError:
ov = None
v = get_hg_version()
vstr = 'VERSION = "%s"' % v
# If the versions haven't changed, there's no need to
# recompile.
if v == ov:
return
mcontent = file(module_file).read()
mcontent = re.sub(versionre, vstr, mcontent)
tmpfd, tmp_file = tempfile.mkstemp()
os.write(tmpfd, mcontent)
os.close(tmpfd)
print "doing version substitution: ", v
rv = _build_py.build_module(self, module, tmp_file, package)
os.unlink(tmp_file)
return rv
return _build_py.build_module(self, module, module_file, package)
class clean_func(_clean):
def initialize_options(self):
_clean.initialize_options(self)
self.build_base = build_dir
class clobber_func(Command):
user_options = []
description = "Deletes any and all files created by setup"
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
# nuke everything
print("deleting " + dist_dir)
shutil.rmtree(dist_dir, True)
print("deleting " + build_dir)
shutil.rmtree(build_dir, True)
print("deleting " + root_dir)
shutil.rmtree(root_dir, True)
print("deleting " + pkgs_dir)
shutil.rmtree(pkgs_dir, True)
remove_sw(CP)
remove_sw(PO)
remove_sw(MAKO)
class test_func(Command):
# NOTE: these options need to be in sync with tests/run.py
user_options = [("verbosemode", 'v', "run tests in verbose mode"),
("genbaseline", 'g', "generate test baseline"),
("parseable", 'p', "parseable output"),
("baselinefile=", 'b', "baseline file <file>"),
("only=", "o", "only <regex>")]
description = "Runs unit and functional tests"
def initialize_options(self):
self.only = ""
self.baselinefile = ""
self.verbosemode = 0
self.parseable = 0
self.genbaseline = 0
def finalize_options(self):
pass
def run(self):
os.putenv('PYEXE', sys.executable)
os.chdir(os.path.join(pwd, "tests"))
# Reconstruct the cmdline and send that to run.py
cmd = [sys.executable, "run.py"]
args = ""
if "test" in sys.argv:
args = sys.argv[sys.argv.index("test")+1:]
cmd.extend(args)
subprocess.call(cmd)
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
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 = 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,
'coverage': cov_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')]
),
Extension(
'pspawn',
pspawn_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,
)