Split out JAVADIR detection to a separate file, and make non-Linux configure much more robust

This commit is contained in:
Manuel Amador (Rudd-O) 2010-09-03 17:51:39 -07:00
parent e7127054ca
commit fd43b5aee8
4 changed files with 92 additions and 89 deletions

22
tools/waf/javadir.py Normal file
View File

@ -0,0 +1,22 @@
#!/usr/bin/env python
import Options, Utils
import os
def detect(conf):
conf.check_message_1('Detecting JAVADIR')
javadir = getattr(Options.options, 'JAVADIR', '')
if javadir:
conf.env.JAVADIR = javadir
conf.check_message_2("%s (forced through --javadir)"%conf.env.JAVADIR,"GREEN")
else:
conf.env.JAVADIR = os.path.join(conf.env.DATADIR,'java')
conf.check_message_2("%s (using default ${DATADIR}/java directory)"%conf.env.JAVADIR,"GREEN")
def set_options(opt):
inst_dir = opt.get_option_group('--datadir') # get the group that contains bindir
if not inst_dir: raise Utils.WafError, "DATADIR not set. Did you load the gnu_dirs tool options with opt.tool_options('gnu_dirs') before running opt.tool_options('javadir')?"
inst_dir.add_option('--javadir', # add javadir to the group that contains bindir
help = 'Java class and jar files [Default: ${DATADIR}/java]',
default = '',
dest = 'JAVADIR')

View File

@ -6,13 +6,15 @@ import Task
import os
def detect(conf):
if Options.platform == 'win32': return
if Options.platform == 'win32': raise Utils.WafError('the usermgmt tool only works on Linux')
if Options.platform == 'darwin': raise Utils.WafError('the usermgmt tool only works on Linux')
path_list = ["/usr/local/sbin","/usr/sbin","/sbin"] + os.environ.get('PATH','').split(os.pathsep)
conf.find_program("useradd",var='USERADD',mandatory=True,path_list=path_list)
conf.find_program("userdel",var='USERDEL',mandatory=True,path_list=path_list)
def set_options(opt):
if Options.platform == 'win32': return
if Options.platform == 'win32': raise Utils.WafError('the usermgmt tool only works on Linux')
if Options.platform == 'darwin': raise Utils.WafError('the usermgmt tool only works on Linux')
og = opt.get_option_group('--force')
og.add_option('--nochown',
action = 'store_true',
@ -30,6 +32,7 @@ Build.BuildContext.subst_add_destdir = staticmethod(_subst_add_destdir)
def _setownership(ctx,path,owner,group,mode=None):
if Options.platform == 'win32': return
if Options.platform == 'darwin': return
if not hasattr(os,"getuid"): return
if os.getuid() != 0: return
if Options.options.NOUSERMGMT: return
@ -71,6 +74,7 @@ Build.BuildContext.setownership = _setownership
def _createuser(ctx,user,homedir,shell):
if Options.platform == 'win32': return
if Options.platform == 'darwin': return
if not hasattr(os,"getuid"): return
if os.getuid() != 0: return
if Options.options.NOUSERMGMT: return

34
wscript
View File

@ -354,28 +354,24 @@ Build.BuildContext.substitute = _substitute
def set_options(opt):
"""Register command line options"""
opt.tool_options('gnu_dirs')
opt.tool_options('python')
opt.tool_options('tar',tooldir='tools/waf')
opt.tool_options('mkisofs',tooldir='tools/waf')
opt.tool_options('usermgmt',tooldir='tools/waf')
opt.tool_options('python')
if Options.platform not in ['darwin','win32']: opt.tool_options('usermgmt',tooldir='tools/waf')
if Options.platform not in ['darwin','win32']: opt.tool_options('javadir',tooldir='tools/waf')
opt.tool_options('tomcat',tooldir='tools/waf')
if Options.platform not in ['darwin',"win32"]: opt.tool_options('compiler_cc')
inst_dir = opt.get_option_group('--bindir') # get the group that contains bindir
inst_dir.add_option('--javadir', # add javadir to the group that contains bindir
help = 'Java class and jar files [Default: ${DATADIR}/java]',
default = '',
dest = 'JAVADIR')
inst_dir = opt.get_option_group('--srcdir') # get the group that contains the srcdir
inst_dir.add_option('--with-db-host', # add javadir to the group that contains bindir
inst_dir = opt.get_option_group('--srcdir')
inst_dir.add_option('--with-db-host',
help = 'Database host to use for waf deploydb [Default: 127.0.0.1]',
default = '127.0.0.1',
dest = 'DBHOST')
inst_dir.add_option('--with-db-user', # add javadir to the group that contains bindir
inst_dir.add_option('--with-db-user',
help = 'Database user to use for waf deploydb [Default: root]',
default = 'root',
dest = 'DBUSER')
inst_dir.add_option('--with-db-pw', # add javadir to the group that contains bindir
inst_dir.add_option('--with-db-pw',
help = 'Database password to use for waf deploydb [Default: ""]',
default = '',
dest = 'DBPW')
@ -393,7 +389,7 @@ def set_options(opt):
help = 'does ---no-dep-check',
default = False,
dest = 'NODEPCHECK')
inst_dir = opt.get_option_group('--force') # get the group that contains the force
inst_dir = opt.get_option_group('--force')
inst_dir.add_option('--preserve-config',
action='store_true',
help = 'do not install configuration files',
@ -402,7 +398,7 @@ def set_options(opt):
debugopts = optparse.OptionGroup(opt.parser,'run/debug options')
opt.add_option_group(debugopts)
debugopts.add_option('--debug-port', # add javadir to the group that contains bindir
debugopts.add_option('--debug-port',
help = 'Port on which the debugger will listen when running waf debug [Default: 8787]',
default = '8787',
dest = 'DEBUGPORT')
@ -419,15 +415,15 @@ def set_options(opt):
rpmopts = optparse.OptionGroup(opt.parser,'RPM/DEB build options')
opt.add_option_group(rpmopts)
rpmopts.add_option('--build-number', # add javadir to the group that contains bindir
rpmopts.add_option('--build-number',
help = 'Build number [Default: SVN revision number for builds from checkouts, or empty for builds from source releases]',
default = '',
dest = 'BUILDNUMBER')
rpmopts.add_option('--prerelease', # add javadir to the group that contains bindir
rpmopts.add_option('--prerelease',
help = 'Branch name to append to the release number (if specified, alter release number to be a prerelease); this option requires --build-number=X [Default: nothing]',
default = '',
dest = 'PRERELEASE')
rpmopts.add_option('--skip-dist', # add javadir to the group that contains bindir
rpmopts.add_option('--skip-dist',
action='store_true',
help = 'Normally, dist() is called during package build. This makes the package build assume that a distribution tarball has already been made, and use that. This option is also valid during distcheck and dist.',
default = False,
@ -435,7 +431,7 @@ def set_options(opt):
distopts = optparse.OptionGroup(opt.parser,'dist options')
opt.add_option_group(distopts)
distopts.add_option('--oss', # add javadir to the group that contains bindir
distopts.add_option('--oss',
help = 'Only include open source components',
action = 'store_true',
default = False,
@ -757,14 +753,14 @@ def debug(ctx):
@throws_command_errors
def run_agent(args):
"""runs the management server"""
"""runs the agent""" # FIXME: make this use the run/debug options
conf = _getbuildcontext()
if not _exists(_join(conf.env.LIBEXECDIR,"agent-runner")): Scripting.install(conf)
_check_call("sudo",[_join(conf.env.LIBEXECDIR,"agent-runner")])
@throws_command_errors
def run_console_proxy(args):
"""runs the management server"""
"""runs the console proxy""" # FIXME: make this use the run/debug options
conf = _getbuildcontext()
if not _exists(_join(conf.env.LIBEXECDIR,"console-proxy-runner")): Scripting.install(conf)
_check_call("sudo",[_join(conf.env.LIBEXECDIR,"console-proxy-runner")])

View File

@ -89,6 +89,8 @@ hard_deps = [
]
conf.env.VERSION = Utils.g_module.VERSION
conf.check_message_1('Detecting distribution')
if Options.platform == 'win32': conf.env.DISTRO = "Windows"
elif Options.platform == 'darwin': conf.env.DISTRO = "Mac"
@ -111,7 +113,6 @@ conf.check_message_2("%s"%conf.env.PREFIX,"GREEN")
conf.check_tool('misc')
conf.check_tool("gnu_dirs")
conf.check_tool('tar')
conf.check_tool('usermgmt')
try: conf.check_tool('mkisofs')
except Configure.ConfigurationError,e:
raise Configure.ConfigurationError, "The program genisoimage (or mkisofs) could not be found.\nOn Linux: ./waf installrpmdeps or ./waf installdebdeps according to your distro's package format.\nOn Windows: Use cygwin to install the mkisofs package, then ensure that the program is in your PATH."
@ -124,36 +125,10 @@ except ImportError,e:
raise Configure.ConfigurationError, "The Python MySQLdb module could not be found.\nOn Linux: ./waf installrpmdeps or ./waf installdebdeps according to your distro's package format.\nOn Windows: Install MySQL 5.1 on your machine, then install the Python MySQLdb module for Python %s.\nThe module for Python 2.6 / win32 / MySQL 5.1 is available here: http://soemin.googlecode.com/files/MySQL-python-1.2.3c1.win32-py2.6.exe"%conf.env.PYTHON_VERSION
conf.check_message_2('MySQLdb','GREEN')
if conf.env.DISTRO not in ["Windows","Mac"]:
conf.check_tool('compiler_cc')
conf.check_cc(lib='pthread')
conf.check_cc(lib='dl')
# waf uses slashes somewhere along the line in some paths. we fix them on windows.
if conf.env.DISTRO in ['Windows']:
for pth in [ x for x in conf.env.get_merged_dict().keys() if x.endswith("DIR") ]:
conf.env[pth] = conf.env[pth].replace("/","\\")
for a in "DBHOST DBUSER DBPW DBDIR".split():
conf.env[a] = getattr(Options.options, a, '')
try: conf.check_tool("tomcat")
except Configure.ConfigurationError,e:
conf.fatal("Tomcat directory %r not found. Either install Tomcat using ./waf installrpmdeps or ./waf installdebdeps, or manually install Tomcat to a directory in your system and set the environment variable TOMCAT_HOME to point to it."%conf.env.TOMCATHOME)
conf.check_message_1('Determining management server user name')
msuser = getattr(Options.options, 'MSUSER', '')
if msuser:
conf.env.MSUSER = msuser
conf.check_message_2("%s (forced through --tomcat-user)"%conf.env.MSUSER,"GREEN")
else:
if conf.env.DISTRO in ['Windows','Mac']:
conf.env.MSUSER = 'root'
conf.check_message_2("%s (not used on Windows or Mac)"%conf.env.MSUSER,"GREEN")
else:
conf.env.MSUSER = conf.env.PACKAGE
conf.check_message_2("%s (Linux default)"%conf.env.MSUSER,"GREEN")
conf.env.AGENTPATH = _join(conf.env.PACKAGE,"agent")
conf.env.CPPATH = _join(conf.env.PACKAGE,"console-proxy")
conf.env.MSPATH = _join(conf.env.PACKAGE,"management")
@ -172,34 +147,63 @@ else:
conf.env.MSLOGDIR = _join(conf.env.LOCALSTATEDIR,"log",conf.env.MSPATH)
conf.env.MSMNTDIR = _join(conf.env.SHAREDSTATEDIR,conf.env.PACKAGE,"mnt")
conf.env.PIDDIR = _join(conf.env.LOCALSTATEDIR,"run")
conf.env.LOCKDIR = _join(conf.env.LOCALSTATEDIR,"lock","subsys")
conf.check_message_1('Detecting JAVADIR')
javadir = getattr(Options.options, 'JAVADIR', '')
if javadir:
conf.env.JAVADIR = javadir
conf.check_message_2("%s (forced through --javadir)"%conf.env.JAVADIR,"GREEN")
elif conf.env.DISTRO in ['Windows','Mac']:
conf.env.JAVADIR = _join(conf.env['TOMCATHOME'],'lib')
conf.check_message_2("%s (using Tomcat's lib/ directory)"%conf.env.JAVADIR,"GREEN")
else:
conf.env.JAVADIR = _join(conf.env.DATADIR,'java')
conf.check_message_2("%s (using default ${DATADIR}/java directory)"%conf.env.JAVADIR,"GREEN")
if conf.env.DISTRO in ["Windows","Mac"]:
if conf.env.DISTRO in ['Windows','Mac']:
conf.env.PREMIUMJAVADIR = conf.env.JAVADIR
conf.env.PLUGINJAVADIR = conf.env.JAVADIR
conf.env.SYSTEMJAVADIR = conf.env.JAVADIR
else:
# waf uses slashes somewhere along the line in some paths. we fix them on windows.
for pth in [ x for x in conf.env.get_merged_dict().keys() if x.endswith("DIR") ]:
conf.env[pth] = conf.env[pth].replace("/","\\")
else:
conf.check_tool('compiler_cc')
conf.check_cc(lib='pthread')
conf.check_cc(lib='dl')
conf.check_tool('usermgmt')
conf.check_message_1('Determining management server user name')
msuser = getattr(Options.options, 'MSUSER', '')
if msuser:
conf.env.MSUSER = msuser
conf.check_message_2("%s (forced through --tomcat-user)"%conf.env.MSUSER,"GREEN")
else:
conf.env.MSUSER = conf.env.PACKAGE
conf.check_message_2("%s (Linux default)"%conf.env.MSUSER,"GREEN")
conf.check_tool("javadir")
conf.env.PREMIUMJAVADIR = _join(conf.env.JAVADIR,"%s-premium"%conf.env.PACKAGE)
conf.env.PLUGINJAVADIR = _join(conf.env.JAVADIR,"%s-plugins"%conf.env.PACKAGE)
conf.env.SYSTEMJAVADIR = "/usr/share/java"
conf.check_message_1('Database info for developer setup')
for a in "DBHOST DBUSER DBPW".split(): conf.env[a] = getattr(Options.options, a, '')
conf.check_message_2("user: %r, password: %r, host: %r"%(conf.env.DBUSER,conf.env.DBPW,conf.env.DBHOST),'GREEN')
in_javadir = lambda name: _join(conf.env.JAVADIR,_basename(name)) # $PREFIX/share/java
in_system_javadir = lambda name: _join(conf.env.SYSTEMJAVADIR,name) # /usr/share/java
in_premiumjavadir = lambda name: _join(conf.env.PREMIUMJAVADIR,name) # $PREFIX/share/java/cloud-premium
conf.env.AGENTLIBDIR = Utils.subst_vars(_join("${LIBDIR}","${AGENTPATH}"),conf.env)
conf.env.AGENTSYSCONFDIR = Utils.subst_vars(_join("${SYSCONFDIR}","${AGENTPATH}"),conf.env)
conf.env.AGENTLOGDIR = Utils.subst_vars(_join("${LOCALSTATEDIR}","log","${AGENTPATH}"),conf.env)
conf.env.USAGELOGDIR = Utils.subst_vars(_join("${LOCALSTATEDIR}","log","${USAGEPATH}"),conf.env)
conf.env.USAGESYSCONFDIR = Utils.subst_vars(_join("${SYSCONFDIR}","${USAGEPATH}"),conf.env)
conf.env.CPLIBDIR = Utils.subst_vars(_join("${LIBDIR}","${CPPATH}"),conf.env)
conf.env.CPSYSCONFDIR = Utils.subst_vars(_join("${SYSCONFDIR}","${CPPATH}"),conf.env)
conf.env.CPLOGDIR = Utils.subst_vars(_join("${LOCALSTATEDIR}","log","${CPPATH}"),conf.env)
conf.env.MSLOG = _join(conf.env.MSLOGDIR,"management-server.log")
conf.env.APISERVERLOG = _join(conf.env.MSLOGDIR,"api-server.log")
conf.env.AGENTLOG = _join(conf.env.AGENTLOGDIR,"agent.log")
conf.env.USAGELOG = _join(conf.env.USAGELOGDIR,"usage.log")
conf.env.CPLOG = _join(conf.env.CPLOGDIR,"console-proxy.log")
conf.env.SETUPDATADIR = Utils.subst_vars(_join("${DATADIR}","${SETUPPATH}"),conf.env)
conf.env.SERVERSYSCONFDIR = Utils.subst_vars(_join("${SYSCONFDIR}","${SERVERPATH}"),conf.env)
conf.env.PIDDIR = _join(conf.env.LOCALSTATEDIR,"run")
conf.env.LOCKDIR = _join(conf.env.LOCALSTATEDIR,"lock","subsys")
conf.check_message_1('Building classpaths')
# == Here we build the run-time classpaths ==
@ -250,30 +254,7 @@ compilecp+= _glob(_join(conf.env.TOMCATHOME,'lib',"*.jar"))
conf.env.CLASSPATH = pathsep.join(compilecp)
conf.check_message_2('Done','GREEN')
conf.env.VERSION = Utils.g_module.VERSION
conf.env.AGENTLIBDIR = Utils.subst_vars(_join("${LIBDIR}","${AGENTPATH}"),conf.env)
conf.env.AGENTSYSCONFDIR = Utils.subst_vars(_join("${SYSCONFDIR}","${AGENTPATH}"),conf.env)
conf.env.AGENTLOGDIR = Utils.subst_vars(_join("${LOCALSTATEDIR}","log","${AGENTPATH}"),conf.env)
conf.env.USAGELOGDIR = Utils.subst_vars(_join("${LOCALSTATEDIR}","log","${USAGEPATH}"),conf.env)
conf.env.USAGESYSCONFDIR = Utils.subst_vars(_join("${SYSCONFDIR}","${USAGEPATH}"),conf.env)
conf.env.CPLIBDIR = Utils.subst_vars(_join("${LIBDIR}","${CPPATH}"),conf.env)
conf.env.CPSYSCONFDIR = Utils.subst_vars(_join("${SYSCONFDIR}","${CPPATH}"),conf.env)
conf.env.CPLOGDIR = Utils.subst_vars(_join("${LOCALSTATEDIR}","log","${CPPATH}"),conf.env)
conf.env.MSLOG = _join(conf.env.MSLOGDIR,"management-server.log")
conf.env.APISERVERLOG = _join(conf.env.MSLOGDIR,"api-server.log")
conf.env.AGENTLOG = _join(conf.env.AGENTLOGDIR,"agent.log")
conf.env.USAGELOG = _join(conf.env.USAGELOGDIR,"usage.log")
conf.env.CPLOG = _join(conf.env.CPLOGDIR,"console-proxy.log")
conf.env.SETUPDATADIR = Utils.subst_vars(_join("${DATADIR}","${SETUPPATH}"),conf.env)
conf.env.SERVERSYSCONFDIR = Utils.subst_vars(_join("${SYSCONFDIR}","${SERVERPATH}"),conf.env)
# log4j config and property config files require backslash escapes on Windows
# log4j config and property config files require backslash escapes on Windows
if conf.env.DISTRO in ["Windows"]:
for log in "MSLOG APISERVERLOG AGENTLIBDIR USAGELOG AGENTLOG".split(): conf.env[log] = conf.env[log].replace("\\","\\\\")