Big change of build

1. use ant to build all JARs and ISOs
2. waf install results from ant
3. arrange wscript_build in function style, which is more readable
This commit is contained in:
Frank Zhang 2010-12-06 13:24:40 -08:00
parent ade1b2665b
commit 7cafe6d7c0
4 changed files with 300 additions and 452 deletions

View File

@ -472,7 +472,7 @@
<target name="build-servers" depends="-init, build-server" />
<target name="build-opensource" depends="-init, build-server, build-agent, build-console-proxy, build-scripts, build-ui">
<target name="build-opensource" depends="-init, build-server, build-agent, build-console-proxy, build-scripts, build-ui, package-oss-systemvm-iso">
<copy overwrite="true" todir="${dist.dir}">
<fileset dir="${base.dir}/build/deploy/">
<include name="deploy-agent.sh" />

View File

@ -135,7 +135,7 @@
</zip>
</target>
<target name="build-all" depends="build-opensource, build-ui, build-war-oss, package-oss-systemvm-iso">
<target name="build-all" depends="build-opensource, build-ui, build-war-oss">
</target>
<target name="build-war-oss" depends="-init-package" description="Compile the GWT client UI and builds WAR file.">

View File

@ -269,7 +269,7 @@ def runant(tsk):
_join(environ["ANT_HOME"],"bin","ant"),
"-Dthirdparty.classpath=%s"%(tsk.env.CLASSPATH.replace(os.pathsep,",")),
]
stanzas += tsk.generator.antargs + tsk.generator.anttgts
stanzas += tsk.generator.antargs
ret = Utils.exec_command(" ".join(stanzas),cwd=tsk.generator.bld.srcnode.abspath(),env=environ,log=True)
if ret != 0: raise Utils.WafError("Ant command %s failed with error value %s"%(stanzas,ret))
return ret
@ -515,7 +515,6 @@ def dist_hook():
# so downloaders won't have to cry every time they download a "source"
# package over 90 MB in size
[ shutil.rmtree(f) for f in _glob(_join("*","bin")) if _isdir(f) ]
[ shutil.rmtree(f) for f in [ _join("build","deploy") ] if _isdir(f) ]
[ shutil.rmtree(f) for f in _glob(_join("cloudstack-proprietary","thirdparty","*")) if _isdir(f) ]
[ shutil.rmtree(f) for f in [ _join("cloudstack-proprietary","tools") ] if _isdir(f) ]

View File

@ -20,24 +20,16 @@ try:
except ImportError:
_chmod,_chown,pwd,stat,grp = (None,None,None,None,None)
required_env = [
"APISERVERLOG",
"MSLOG",
"PIDDIR",
"CPPATH",
"AGENTSIMULATORCLASSPATH",
"SYSTEMJAVADIR",
"USAGELOG",
"PLUGINJAVADIR",
]
for e in required_env:
if e not in bld.env: raise Utils.WafError("configure required: new variable %s added"%e)
# Global variables setup
sourcedir = bld.srcnode.abspath()
builddir = bld.path.abspath(bld.env)
buildpremium = _exists(_join(sourcedir,"cloudstack-proprietary"))
filelist = bld.path.ant_glob
distdir = Utils.relpath(_join(sourcedir,"dist"))
targetdir = Utils.relpath(_join(sourcedir,"target"))
def build_utils_docs ():
sccsinfo = _join(sourcedir,"sccs-info")
if _exists(sccsinfo): bld.install_files("${DOCDIR}","sccs-info")
@ -45,23 +37,22 @@ tgen = bld(features='subst', name='configure-info', source="configure-info.in",
tgen.dict = {"CONFIGUREVARS":bld.getconfig()}
bld.install_files("${DOCDIR}","configure-info")
# ==================== Java compilation ===========================
# discover ant targets and properties
antxmlfiles = _glob(_join("build","*.xml")) + _glob(_join("build","*.properties"))
if buildpremium: antxmlfiles += _glob(_join("build","premium","*.xml")) + _glob(_join("cloudstack-proprietary","build","*.xml"))
targets,antprops = Utils.discover_ant_targets_and_properties(antxmlfiles)
# compile jar files using ant
# ant only needs to be reinvoked if the version with build number changes
# we here trim all the depended targets from the target list:
def build_jars ():
Implementation_Version = bld.env.VERSION
buildnumber = Utils.getbuildnumber()
if buildnumber: Implementation_Version += "." + buildnumber
# this is to trigger recompilation / cache avoidance if the relevant environment for ant changes
ant_args = [
"build-all",
"-Dimpl.version=%s" % Implementation_Version,
"-Dtarget.dir=%s"%Utils.relpath(_join(builddir,"target")),
"-Ddist.dir=%s"%Utils.relpath(_join(builddir,"ant-dist")),
"-Dtarget.dir=%s" % targetdir,
"-Ddist.dir=%s" % distdir,
"-Dbase.dir=%s" % sourcedir,
"-f %s" % Utils.relpath (_join(sourcedir, "build.xml")),
]
if not buildpremium: ant_args += ["-DOSS=true"]
@ -69,24 +60,32 @@ tgen = bld(features='subst', name='version-info', source="version-info.in", targ
tgen.dict = { "Implementation_Version":Implementation_Version,"ant_args":ant_args }
bld.install_files("${DOCDIR}","version-info")
# compile jar files using ant
# ant only needs to be reinvoked if the version with build number changes
# we here trim all the depended targets from the target list:
build_targets = [ x[0] for x in targets ]
nondep_build_targets = list ( set([ x[0] for x in targets ]) - set([ x for dependencies in [ y[4] for y in targets ] for x in dependencies ]) )
ant_sources = " ".join(antxmlfiles + [ filelist(x[1] + "/**/*.java",src=True,bld=False,dir=False,flat=True) for x in targets ]) + ' version-info'
ant_jars = [ x[3] for x in targets ]
bld.srcnode.ensure_dir_node_from_path("target/jar")
bld.srcnode.ensure_dir_node_from_path("dist")
bld.path.ensure_dir_node_from_path("target/jar")
tgen = bld(rule=Utils.runant, name='runant', source=ant_sources, target=ant_jars, anttgts = nondep_build_targets, antargs=ant_args)
tgen = bld.new_task_gen (rule = Utils.runant,
name = "runant",
antargs = ant_args)
# install jar files
[ bld.install_files('${JAVADIR}',jar) for jar in ant_jars if _basename(jar).startswith("cloud-") ]
jarnode = bld.srcnode.find_dir ('target/jar')
jars_str = jarnode.ant_glob ('*.jar').split ()
ant_jars = []
excludes = ["cloud-xstream-1.3.1.jar", "cloud-commons-dbcp-1.2.2.jar",
"cloud-commons-httpclient-3.1.jar", "cloud-commons-pool-1.4.jar",
"cloud-servlet-api.jar", "cloud-commons-logging-1.1.1.jar",
"cloud-ws-commons-util-1.0.2.jar",
"cloud-commons-collections-3.2.1.jar", "vmware*.jar"]
# ======================= End Java compilation ======================
for a in jars_str:
if _basename (a).startswith ("cloud-") \
and not _basename (a) in excludes:
a = jarnode.abspath () + os.sep + a
ant_jars.append (a)
# =================== C / Python compilation =========================
bld.install_files ('${JAVADIR}', ant_jars)
def build_python_and_daemonize ():
obj = bld(features = 'py',name='pythonmodules')
obj.find_sources_in_dirs('python/lib', exts=['.py'])
@ -96,14 +95,14 @@ if bld.env.DISTRO not in ['Windows','Mac']:
name='daemonize',
features='cc cprogram',
source='daemonize/daemonize.c',
target='daemonize/cloud-daemonize')
# ===================== End C / Python compilation ==========================
target='daemonize/cloud-daemonize'
)
def build_premium ():
if buildpremium: bld.recurse(["cloudstack-proprietary/"],'build')
# ================ Third-party / dependency installation ===============
def build_dependences ():
excludes = ["cloud-xstream-1.3.1.jar", "cloud-commons-dbcp-1.2.2.jar",
"cloud-commons-httpclient-3.1.jar", "cloud-commons-pool-1.4.jar",
"cloud-servlet-api.jar", "cloud-commons-logging-1.1.1.jar",
@ -113,10 +112,7 @@ excludes = ["cloud-xstream-1.3.1.jar", "cloud-commons-dbcp-1.2.2.jar",
start_path = bld.path.find_dir ("deps")
bld.install_files('${JAVADIR}',start_path.ant_glob("*.jar", excl = excludes), cwd=start_path)
# =================== End 3rdparty/dep install ========================
# =================== Build install declaratoin of console proxy project ========
def build_console_proxy ():
# binary unsubstitutable files:
start_path = bld.path.find_dir ("console-proxy")
bld.install_files("${CPLIBDIR}",start_path.ant_glob("images/**",src=True,bld=False,dir=False,flat=True),cwd=start_path,relative_trick=True)
@ -126,11 +122,8 @@ bld.substitute('css/** js/** ui/** scripts/**',install_to="${CPLIBDIR}", cwd=sta
# config files (do not replace them if preserve config option is true)
if not Options.options.PRESERVECONFIG: bld.install_files_filtered("${CPSYSCONFDIR}","conf.dom0/*", cwd=start_path)
# ================== End console proxy ===================
# ================ Creation of patch.tgz's ============================
def build_patches ():
# done here because the patches require substituted files
start_path = bld.path.find_dir ("patches")
bld.substitute("*/**",name="patchsubst", cwd = start_path)
@ -150,187 +143,22 @@ for virttech in Utils.to_list(start_path.ant_glob("*",dir=True)):
rename = lambda x: re.sub(".subst$","",x),
)
bld.path = tmp
# ================== End creation of patch.tgz's ====================
# ================== systemvm patch creation ====================
deps = " ".join( Utils.to_list(
"""
deps/cloud-xmlrpc-client-3.1.3.jar
deps/cloud-xmlrpc-common-3.1.3.jar
deps/cloud-log4j.jar
deps/cloud-gson.jar
deps/cloud-apache-log4j-extras-1.0.jar
deps/cloud-libvirt-0.4.5.jar
deps/cloud-jna.jar
deps/cloud-cglib.jar
deps/cloud-commons-codec-1.4.jar
deps/cloud-commons-httpclient-3.1.jar
deps/cloud-commons-logging-1.1.1.jar
deps/cloud-commons-pool-1.4.jar
deps/cloud-ws-commons-util-1.0.2.jar
deps/cloud-commons-collections-3.2.1.jar
"""
) )
thirdparties = " ".join( Utils.to_list(
"""
cloudstack-proprietary/thirdparty/xmlrpc-client-3.1.3.jar
cloudstack-proprietary/thirdparty/xmlrpc-common-3.1.3.jar
cloudstack-proprietary/thirdparty/ws-commons-util-1.0.2.jar
cloudstack-proprietary/thirdparty/log4j-1.2.15.jar
cloudstack-proprietary/thirdparty/gson.jar
cloudstack-proprietary/thirdparty/apache-log4j-extras-1.0.jar
cloudstack-proprietary/thirdparty/commons-httpclient-3.1.jar
cloudstack-proprietary/thirdparty/commons-logging-1.1.1.jar
cloudstack-proprietary/thirdparty/commons-collections-3.2.1.jar
cloudstack-proprietary/thirdparty/commons-codec-1.4.jar
cloudstack-proprietary/thirdparty/commons-pool-1.4.jar
cloudstack-proprietary/thirdparty/libvirt-0.4.5.jar
cloudstack-proprietary/thirdparty/jna.jar
cloudstack-proprietary/thirdparty/cglib-nodep-2.2.jar
"""
) )
patterns = Utils.to_list(
"""
console-proxy/css/**
console-proxy/images/**
console-proxy/js/**
console-proxy/ui/**
console-proxy/conf/**
console-proxy/scripts/*.sh
console-proxy/vm-script/*.sh
scripts/storage/secondary/*sh
"""
)
premiumpatterns = patterns + ["cloudstack-proprietary/console-proxy-premium/certs/**"]
artifacts = "target/jar/VMOpsConsoleApplet.jar " + " ".join( "target/jar/cloud-%s.jar"%j for j in "console-proxy console-common agent utils api core".split() )
premiumartifacts = artifacts + " target/jar/cloud-console-proxy-premium.jar"
sources = " ".join( [ filelist(x,src=True,bld=False,dir=False,flat=True) for x in patterns ] )
premiumsources = " ".join( [ filelist(x,src=True,bld=False,dir=False,flat=True) for x in premiumpatterns ] )
systemfiles = [ (f,_join(".",_basename(f))) for f in bld.env.SYSTEMCLASSPATH.split(pathsep) ]
systems = " ".join( [ n[1] for n in systemfiles ] )
systemtargetdir = _join(builddir,".")
def copydeps(task):
Utils.check_dir(systemtargetdir)
for src,tgt in systemfiles: shutil.copy(src,systemtargetdir)
return 0
def zip_up(task):
tgt = task.outputs[0].bldpath(task.env)
if _exists(tgt): _unlink(tgt)
z = zipfile.ZipFile(tgt,"w")
for inp in task.inputs:
if inp.id&3==Node.BUILD:
src = inp.bldpath(task.env)
srcname = src
srcname = "/".join(srcname.split("/")[1:]) # chop off default/
if srcname.startswith("target/jar"): srcname = "/".join(srcname.split("/")[2:]) # chop off target/jar
else:
src = inp.srcpath(task.env)
srcname = src
srcname = "/".join(srcname.split("/")[1:]) # chop off ../
if srcname.startswith("cloudstack-proprietary"): srcname = "/".join(srcname.split("/")[1:]) # chop off cloudstack proprietary
srcname = "/".join(srcname.split("/")[1:]) # chop off project name
# post-process the paths
if True in [ srcname.startswith(strt) for strt in [ 'scripts/run','scripts/_run','scripts/config_ssl','scripts/config_auth','scripts/ssvm-check' ] ]:
srcname = "/".join(srcname.split("/")[1:])
elif srcname.startswith('storage'):
srcname = "scripts/" + srcname
elif srcname.startswith('VMOpsConsoleApplet'):
srcname = "applet/" + srcname
elif srcname.startswith('certs'):
srcname = srcname
z.write(src,srcname)
z.close()
return 0
bld.path.ensure_dir_node_from_path("target/oss")
bld.path.ensure_dir_node_from_path("target/premium")
def build_systemvm_patch ():
if bld.env.DISTRO not in ["Windows","Mac"]:
tgen = bld(
rule = copydeps,
source = 'wscript_configure',
target = systems,
name = 'getsystemjars',
)
tgen = bld(
rule = zip_up,
source = " ".join( [sources,artifacts,deps,systems] ),
target = 'target/oss/systemvm.zip',
name = 'systemvm_zip',
)
bld.install_files("${AGENTLIBDIR}/vms", "target/oss/systemvm.zip")
# patch creation
bld.install_files ("${AGENTLIBDIR}/vms", "%s/systemvm.zip" % distdir)
# ISO creation
bld.install_as("${AGENTLIBDIR}/vms/systemvm.iso", "%s/systemvm.iso" % distdir)
def build_systemvm_iso ():
if buildpremium:
tgen = bld(
rule = zip_up,
source = " ".join( [premiumsources,premiumartifacts,thirdparties] ),
target = 'target/premium/systemvm.zip',
name = 'systemvm-premium_zip',
)
#no need to install the premium one, we have ISOs below
#bld.install_files("${AGENTLIBDIR}/vms", "systemvm-premium.zip")
# ================== End systemvm patch creation ====================
# ================== systemvm ISO creation ====================
def iso_up(task):
tgt = task.outputs[0].bldpath(task.env)
if os.path.exists(tgt): os.unlink(tgt)
inps = []
for inp in task.inputs:
if inp.id&3==Node.BUILD:
src = inp.bldpath(task.env)
srcname = src
srcname = sep.join(srcname.split(sep)[1:]) # chop off default/
else:
src = inp.srcpath(task.env)
srcname = src
srcname = sep.join(srcname.split(sep)[1:]) # chop off ../
if task.generator.rename: srcname = task.generator.rename(srcname)
inps.append(srcname+'='+src)
ret = Utils.exec_command(
[
task.generator.env.MKISOFS,
"-quiet",
"-r",
"-graft-points",
"-o",tgt,
] + inps, shell=False)
if ret != 0: return ret
if bld.env.DISTRO not in ["Windows","Mac"]:
# systemvm.zip cannot be built on Windows or Mac because system deps do not exist there
tgen = bld(
rule = iso_up,
source = "patches/cloud-scripts.tgz target/oss/systemvm.zip patches/systemvm/debian/config/root/.ssh/authorized_keys",
target = 'target/oss/systemvm.iso',
name = 'systemvm_iso',
rename = lambda x: x.split(sep)[-1].replace('systemvm-',''),
)
bld.install_as("${AGENTLIBDIR}/vms/systemvm.iso", "target/oss/systemvm.iso")
if buildpremium:
tgen = bld(
rule = iso_up,
source = "patches/cloud-scripts.tgz target/premium/systemvm.zip patches/systemvm/debian/config/root/.ssh/authorized_keys",
target = 'target/premium/systemvm.iso',
name = 'systemvm-premium_iso',
rename = lambda x: x.split(sep)[-1].replace('systemvm-',''),
)
bld.install_as("${AGENTLIBDIR}/vms/systemvm-premium.iso", "target/premium/systemvm.iso")
# ================== End systemvm ISO creation ====================
bld.install_as("${AGENTLIBDIR}/vms/systemvm-premium.iso", "%s/systemvm-premium.iso" % distdir)
# =================== Empty directory / symlink creation on install target ====================
def build_dirs_symlinks ():
bld.createuser(bld.env.MSUSER,bld.env.MSENVIRON,'/bin/sh')
# 7. make log and cache dirs (this actually runs first)
@ -377,30 +205,17 @@ else:
for lnk,dst in symlinks: bld.symlink_as(lnk,Utils.subst_vars(dst,bld.env))
# ================== End empty directory / symlink creation on install target =====================
# =================== Subst / installation of agent scripts project ========
def build_scripts ():
start_path = bld.path.find_dir ("scripts")
bld.substitute('**',"${AGENTLIBDIR}/scripts",chmod=0755, cwd=start_path)
# ================== End agent scripts ===================
# ================== Subst / installation of scripts in bin directories ========================
def build_bin_exec_dirs ():
bld.install_files_filtered("${LIBEXECDIR}","*/libexec/* cloudstack-proprietary/*/libexec/*",chmod=0755)
bld.install_files_filtered("${BINDIR}","*/bindir/* cloudstack-proprietary/*/bindir/*",chmod=0755)
bld.install_files_filtered("${SBINDIR}","*/sbindir/* cloudstack-proprietary/*/sbindir/*",chmod=0755)
# ================== End subst / installation of scripts in bin directories ========================
# ================== Installation of scripts / bindirs / configuration files ===========================
# ================= build / install declarations of server project <- this is actually now in client project
def build_server_client ():
start_path = bld.path.find_dir("client/WEB-INF")
bld.install_files('${MSENVIRON}/webapps/client/WEB-INF',
start_path.ant_glob("**",src=True,bld=False,dir=False,flat=True),
@ -417,27 +232,24 @@ if not Options.options.PRESERVECONFIG:
start_path = bld.path.find_dir("server")
if not Options.options.PRESERVECONFIG:
bld.install_files_filtered("${SERVERSYSCONFDIR}","conf/*", cwd=start_path)
# ================= end build / install declarations of server project <- this is actually now in client project
# ================ build / install declarations of agent project =================
def build_agent ():
start_path = bld.path.find_dir ("agent")
bld.install_files("${AGENTLIBDIR}",
start_path.ant_glob("storagepatch/**",src=True,bld=False,dir=False,flat=True),
cwd=start_path,relative_trick=True)
if not Options.options.PRESERVECONFIG:
bld.install_files_filtered("${AGENTSYSCONFDIR}","conf/*", cwd = start_path)
# ================ build / install declarations of agent project =================
# =============== build / install declarations of client UI project =======================
def build_ui ():
# binary unsubstitutable files:
start_path = bld.path.find_dir ("ui")
bld.install_files ("${MSENVIRON}/webapps/client",start_path.ant_glob("*.ico **/*png **/*jpg **/*gif",src=True,bld=False,dir=False,flat=True),cwd=start_path,relative_trick=True)
# text substitutable files (substitute with tokens from the environment bld.env):
#bld.substitute ("ui/*html ui/**/*html ui/**/*js ui/**/*css ui/**/*properties ui/**/*jsp ui/*jsp",install_to="${MSENVIRON}/webapps/client")
bld.substitute ("*html **/*html **/*js **/*css **/*properties **/*jsp *jsp",install_to="${MSENVIRON}/webapps/client", cwd=start_path)
# =============== end build / install declarations of client UI project =======================
def build_conf_files ():
# apply distro-specific config on top of the 'all' generic cloud-management config
globspec = _join("*","distro",bld.env.DISTRO.lower(),"*") # matches premium/distro/centos/SYSCONFDIR
distrospecificdirs=_glob(globspec) + _glob(_join("cloudstack-proprietary",globspec))
@ -452,12 +264,11 @@ for dsdir in distrospecificdirs:
if Options.options.PRESERVECONFIG: continue
bld.install_files_filtered(dsdirwithvar, files, cwd=start_path, relative_trick=True,chmod=mode)
# install db data files
def build_db_files ():
bld.install_files_filtered("${SETUPDATADIR}",filelist("*/db/* cloudstack-proprietary/*/db/*",excl=Node.exclude_regs + "\ncloud-gate\ncloud-bridge"))
# ================== End installation of scripts / bindirs / configuration files ===========================
def build_plugins ():
# ====================== Feature-specific plugins ========================
for plugin in _glob(_join("plugins","*")) + _glob(_join("cloudstack-proprietary","plugins","*")):
@ -479,32 +290,70 @@ for vendor in _glob(_join("vendor","*")) + _glob(_join("cloudstack-proprietary",
# ====================== End vendor-specific plugins ====================
def build_xml_api_description ():
def generate_xml_api_description(task):
relationship = Utils.relpath(sourcedir,os.getcwd())
cp = [ _join(relationship,x) for x in task.generator.env.CLASSPATH.split(pathsep) ]
buildproducts = [ x.bldpath(task.env) for x in task.inputs ]
jarnames = ['utils','server','core', 'api']
props = "client/tomcatconf/commands.properties.in"
sources = []
for i in jarnames:
str = 'target/jar/cloud-%s.jar' % i
sources.append (str)
sources.append (props)
buildproducts = []
for i in sources:
path = bld.path.abspath() + os.sep + i
buildproducts.append (path)
jars = [ x for x in buildproducts if x.endswith("jar") ]
properties = [ x for x in buildproducts if x.endswith("properties") ]
properties = [ x for x in buildproducts if x.endswith("properties.in") ]
cp += jars
cp = pathsep.join(cp)
arguments = ["-f",",".join(properties),"-d",builddir]
ret = Utils.exec_command(["java","-cp",cp,"com.cloud.api.doc.ApiXmlDocWriter"]+arguments,log=True)
return ret
props = " client/tomcatconf/commands.properties"
jarnames = ['utils','server','core', 'api']
tgen = bld(
#TODO: We can't use 'source' token here because task_gen check if sources
# exist before all task_gen. This bring a problem that 'runant' task doesn't
# run when the check happen, which results in no source found at target/jar.
# Ask waf community to fix that
tgen = bld.new_task_gen (
rule = generate_xml_api_description,
source = " ".join( [ 'target/jar/cloud-%s.jar'%x for x in jarnames ] ) + props,
target = 'commands.xml',
name = 'xmlapi',
after = 'runant',
install_path="${CLIDIR}"
)
#bld.process_after(tgen)
bld.install_files("${PYTHONDIR}/cloudtool", 'cloud-cli/cloudtool/*')
bld.install_as("${PYTHONDIR}/cloudapis.py", 'cloud-cli/cloudapis/cloud.py')
# ====================== Magic! =========================================
# Get started to execute here
build_utils_docs ()
build_jars ()
build_python_and_daemonize ()
build_premium ()
#build_dependences ()
build_console_proxy ()
build_patches ()
build_systemvm_patch ()
build_systemvm_iso ()
build_dirs_symlinks ()
build_scripts ()
build_bin_exec_dirs ()
build_server_client ()
build_agent ()
build_ui ()
build_conf_files ()
build_db_files ()
build_plugins ()
build_xml_api_description ()
# ====================== Magic! =========================================
bld.use_the_magic()