From 7cafe6d7c02ce6b7bd12eaac08dd3b0f45640456 Mon Sep 17 00:00:00 2001 From: Frank Zhang Date: Mon, 6 Dec 2010 13:24:40 -0800 Subject: [PATCH] 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 --- build/build-cloud.xml | 2 +- build/package.xml | 2 +- wscript | 3 +- wscript_build | 745 +++++++++++++++++------------------------- 4 files changed, 300 insertions(+), 452 deletions(-) diff --git a/build/build-cloud.xml b/build/build-cloud.xml index 9c0202bf89d..ce5551e0ce1 100755 --- a/build/build-cloud.xml +++ b/build/build-cloud.xml @@ -472,7 +472,7 @@ - + diff --git a/build/package.xml b/build/package.xml index 5bc293f05e5..7ff154bf165 100755 --- a/build/package.xml +++ b/build/package.xml @@ -135,7 +135,7 @@ - + diff --git a/wscript b/wscript index 663b9787219..941ced0e591 100644 --- a/wscript +++ b/wscript @@ -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) ] diff --git a/wscript_build b/wscript_build index 2f8db7651bb..8c1f9e28455 100644 --- a/wscript_build +++ b/wscript_build @@ -20,491 +20,340 @@ 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")) -sccsinfo = _join(sourcedir,"sccs-info") -if _exists(sccsinfo): bld.install_files("${DOCDIR}","sccs-info") +def build_utils_docs (): + sccsinfo = _join(sourcedir,"sccs-info") + if _exists(sccsinfo): bld.install_files("${DOCDIR}","sccs-info") -tgen = bld(features='subst', name='configure-info', source="configure-info.in", target="configure-info") -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) - -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 = [ - "-Dimpl.version=%s"%Implementation_Version, - "-Dtarget.dir=%s"%Utils.relpath(_join(builddir,"target")), - "-Ddist.dir=%s"%Utils.relpath(_join(builddir,"ant-dist")), -] -if not buildpremium: ant_args += ["-DOSS=true"] - -tgen = bld(features='subst', name='version-info', source="version-info.in", target="version-info") -tgen.dict = { "Implementation_Version":Implementation_Version,"ant_args":ant_args } -bld.install_files("${DOCDIR}","version-info") + tgen = bld(features='subst', name='configure-info', source="configure-info.in", target="configure-info") + tgen.dict = {"CONFIGUREVARS":bld.getconfig()} + bld.install_files("${DOCDIR}","configure-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 ] +def build_jars (): + Implementation_Version = bld.env.VERSION + buildnumber = Utils.getbuildnumber() + if buildnumber: Implementation_Version += "." + buildnumber -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) + # 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" % targetdir, + "-Ddist.dir=%s" % distdir, + "-Dbase.dir=%s" % sourcedir, + "-f %s" % Utils.relpath (_join(sourcedir, "build.xml")), + ] + if not buildpremium: ant_args += ["-DOSS=true"] -# install jar files -[ bld.install_files('${JAVADIR}',jar) for jar in ant_jars if _basename(jar).startswith("cloud-") ] + tgen = bld(features='subst', name='version-info', source="version-info.in", target="version-info") + tgen.dict = { "Implementation_Version":Implementation_Version,"ant_args":ant_args } + bld.install_files("${DOCDIR}","version-info") -# ======================= End Java compilation ====================== + bld.srcnode.ensure_dir_node_from_path("target/jar") + bld.srcnode.ensure_dir_node_from_path("dist") -# =================== C / Python compilation ========================= + tgen = bld.new_task_gen (rule = Utils.runant, + name = "runant", + antargs = ant_args) -obj = bld(features = 'py',name='pythonmodules') -obj.find_sources_in_dirs('python/lib', exts=['.py']) + 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"] -if bld.env.DISTRO not in ['Windows','Mac']: - # build / install declarations of the daemonization utility - except for Windows - bld( - name='daemonize', - features='cc cprogram', - source='daemonize/daemonize.c', - target='daemonize/cloud-daemonize') -# ===================== End C / Python 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) + + bld.install_files ('${JAVADIR}', ant_jars) -if buildpremium: bld.recurse(["cloudstack-proprietary/"],'build') +def build_python_and_daemonize (): + obj = bld(features = 'py',name='pythonmodules') + obj.find_sources_in_dirs('python/lib', exts=['.py']) -# ================ Third-party / dependency installation =============== + if bld.env.DISTRO not in ['Windows','Mac']: + # build / install declarations of the daemonization utility - except for Windows + bld( + name='daemonize', + features='cc cprogram', + source='daemonize/daemonize.c', + target='daemonize/cloud-daemonize' + ) -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"] - -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 ======================== +def build_premium (): + if buildpremium: bld.recurse(["cloudstack-proprietary/"],'build') -# =================== Build install declaratoin of console proxy project ======== -# 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) +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", + "cloud-ws-commons-util-1.0.2.jar", + "cloud-commons-collections-3.2.1.jar", "vmware*.jar"] -# text substitutable files (substitute with tokens from the environment bld.env): -bld.substitute('css/** js/** ui/** scripts/**',install_to="${CPLIBDIR}", cwd=start_path) + start_path = bld.path.find_dir ("deps") + bld.install_files('${JAVADIR}',start_path.ant_glob("*.jar", excl = excludes), cwd=start_path) -# 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 =================== +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) + + # text substitutable files (substitute with tokens from the environment bld.env): + bld.substitute('css/** js/** ui/** scripts/**',install_to="${CPLIBDIR}", cwd=start_path) + + # 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) + +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) + + for virttech in Utils.to_list(start_path.ant_glob("*",dir=True)): + if virttech in ["shared"]: continue + patchfiles = start_path.ant_glob('shared/** %s/debian/config/**'%virttech,src=False,bld=True,dir=False,flat=True) + + tmp = bld.path + bld.path = start_path + tgen = bld( + features = 'tar',#Utils.tar_up, + source = patchfiles, + target = 'cloud-scripts.tgz', + name = 'cloud-scripts_tgz', + root = os.path.join("patches", virttech + "/debian/config"), + rename = lambda x: re.sub(".subst$","",x), + ) + bld.path = tmp -# ================ Creation of patch.tgz's ============================ - -# done here because the patches require substituted files -start_path = bld.path.find_dir ("patches") -bld.substitute("*/**",name="patchsubst", cwd = start_path) - -for virttech in Utils.to_list(start_path.ant_glob("*",dir=True)): - if virttech in ["shared"]: continue - patchfiles = start_path.ant_glob('shared/** %s/debian/config/**'%virttech,src=False,bld=True,dir=False,flat=True) - - tmp = bld.path - bld.path = start_path - tgen = bld( - features = 'tar',#Utils.tar_up, - source = patchfiles, - target = 'cloud-scripts.tgz', - name = 'cloud-scripts_tgz', - root = os.path.join("patches", virttech + "/debian/config"), - 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") -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") - -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 ==================== +def build_systemvm_patch (): + if bld.env.DISTRO not in ["Windows","Mac"]: + # 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: + bld.install_as("${AGENTLIBDIR}/vms/systemvm-premium.iso", "%s/systemvm-premium.iso" % distdir) # =================== Empty directory / symlink creation on install target ==================== -bld.createuser(bld.env.MSUSER,bld.env.MSENVIRON,'/bin/sh') - -# 7. make log and cache dirs (this actually runs first) -if bld.env.DISTRO in 'Windows Mac': pass -else: - x = ("root",bld.env.MSUSER) - directories = [ - ("${MSLOGDIR}",0770,x), - ("${AGENTLOGDIR}",0770,x), - ("${USAGELOGDIR}",0770,x), - ("${CPLOGDIR}",0770,x), - ("${IPALLOCATORLOGDIR}",0770,x), - ("${LOCALSTATEDIR}/cache/${MSPATH}",0770,x), - ("${LOCALSTATEDIR}/cache/${MSPATH}/temp",0770,x), - ("${LOCALSTATEDIR}/cache/${MSPATH}/work",0770,x), - ("${SHAREDSTATEDIR}/${MSPATH}",0770,x), - ("${MSMNTDIR}",0770,x), - ("${MSCONF}/Catalina",0770,x), - ("${MSCONF}/Catalina/localhost",0770,x), - ("${MSCONF}/Catalina/localhost/client",0770,x), - ("${PIDDIR}",0755,("root","root")), - ("${LOCKDIR}",0755,("root","root")), - ] +def build_dirs_symlinks (): + bld.createuser(bld.env.MSUSER,bld.env.MSENVIRON,'/bin/sh') - for a,mode,owner in directories: - s = bld.subst_add_destdir(a,bld) - if Options.is_install: - bld.install_dir(a) - bld.setownership(a,owner[0],owner[1],mode) + # 7. make log and cache dirs (this actually runs first) + if bld.env.DISTRO in 'Windows Mac': pass + else: + x = ("root",bld.env.MSUSER) + directories = [ + ("${MSLOGDIR}",0770,x), + ("${AGENTLOGDIR}",0770,x), + ("${USAGELOGDIR}",0770,x), + ("${CPLOGDIR}",0770,x), + ("${IPALLOCATORLOGDIR}",0770,x), + ("${LOCALSTATEDIR}/cache/${MSPATH}",0770,x), + ("${LOCALSTATEDIR}/cache/${MSPATH}/temp",0770,x), + ("${LOCALSTATEDIR}/cache/${MSPATH}/work",0770,x), + ("${SHAREDSTATEDIR}/${MSPATH}",0770,x), + ("${MSMNTDIR}",0770,x), + ("${MSCONF}/Catalina",0770,x), + ("${MSCONF}/Catalina/localhost",0770,x), + ("${MSCONF}/Catalina/localhost/client",0770,x), + ("${PIDDIR}",0755,("root","root")), + ("${LOCKDIR}",0755,("root","root")), + ] + + for a,mode,owner in directories: + s = bld.subst_add_destdir(a,bld) + if Options.is_install: + bld.install_dir(a) + bld.setownership(a,owner[0],owner[1],mode) + + # 8. create environment symlinks + symlinks = [ + ('${MSENVIRON}/bin', '${TOMCATHOME}/bin'), + ('${MSENVIRON}/lib', '${TOMCATHOME}/lib'), + ('${MSENVIRON}/logs', "${MSLOGDIR}"), + ('${MSENVIRON}/temp', '${LOCALSTATEDIR}/cache/${MSPATH}/temp'), + ('${MSENVIRON}/work','${LOCALSTATEDIR}/cache/${MSPATH}/work'), + ('${MSENVIRON}/conf', '${SYSCONFDIR}/${MSPATH}'), + ("${AGENTLIBDIR}/css", '${CPLIBDIR}/css'), + ("${AGENTLIBDIR}/images", '${CPLIBDIR}/images'), + ("${AGENTLIBDIR}/js", '${CPLIBDIR}/js'), + ("${AGENTLIBDIR}/ui", '${CPLIBDIR}/ui'), + ] + + for lnk,dst in symlinks: bld.symlink_as(lnk,Utils.subst_vars(dst,bld.env)) + + +def build_scripts (): + start_path = bld.path.find_dir ("scripts") + bld.substitute('**',"${AGENTLIBDIR}/scripts",chmod=0755, cwd=start_path) + +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) + +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), + cwd=start_path,relative_trick=True) - # 8. create environment symlinks - symlinks = [ - ('${MSENVIRON}/bin', '${TOMCATHOME}/bin'), - ('${MSENVIRON}/lib', '${TOMCATHOME}/lib'), - ('${MSENVIRON}/logs', "${MSLOGDIR}"), - ('${MSENVIRON}/temp', '${LOCALSTATEDIR}/cache/${MSPATH}/temp'), - ('${MSENVIRON}/work','${LOCALSTATEDIR}/cache/${MSPATH}/work'), - ('${MSENVIRON}/conf', '${SYSCONFDIR}/${MSPATH}'), - ("${AGENTLIBDIR}/css", '${CPLIBDIR}/css'), - ("${AGENTLIBDIR}/images", '${CPLIBDIR}/images'), - ("${AGENTLIBDIR}/js", '${CPLIBDIR}/js'), - ("${AGENTLIBDIR}/ui", '${CPLIBDIR}/ui'), - ] + start_path = bld.path.find_dir("client") + bld.install_files("${MSCONF}/resources",'WEB-INF/classes/resources/*.properties',chmod=0640, cwd=start_path) - 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 ======== - -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 ======================== - -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 -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), - cwd=start_path,relative_trick=True) - -start_path = bld.path.find_dir("client") -bld.install_files("${MSCONF}/resources",'WEB-INF/classes/resources/*.properties',chmod=0640, cwd=start_path) - -if not Options.options.PRESERVECONFIG: - bld.install_files_filtered("${MSCONF}","tomcatconf/*", cwd=start_path) - bld.install_files("${MSCONF}",'tomcatconf/db.properties',chmod=0640, cwd=start_path) - bld.setownership("${MSCONF}/db.properties","root",bld.env.MSUSER) - -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 ================= -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 ======================= -# 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 ======================= - -# 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)) -for dsdir in distrospecificdirs: - start_path = bld.srcnode.find_dir(dsdir) - subpath,varname = _split(dsdir) - dsdirwithvar = _join("${%s}"%varname) - files = filelist('%s/**'%dsdir,src=True,bld=False,dir=False,flat=True) - mode = 0644 - if "SYSCONFDIR" in dsdir: - mode = 0755 - if Options.options.PRESERVECONFIG: continue - bld.install_files_filtered(dsdirwithvar, files, cwd=start_path, relative_trick=True,chmod=mode) - -# install db data 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 =========================== - - -# ====================== Feature-specific plugins ======================== - -for plugin in _glob(_join("plugins","*")) + _glob(_join("cloudstack-proprietary","plugins","*")): - if not _exists(_join(plugin,"build.xml")): continue - pluginname = _basename(plugin) - target = 'target/jar/cloud-%s.jar' % pluginname - sources = filelist( '%s/**/*.java' % plugin.replace(sep,"/") , src=True, bld=False, dir=False ) - tgen = bld(rule=lambda x: runant("compile-%s"%pluginname), name='compile_%s'%pluginname, source=sources, target=target, after='runant') - bld.install_files('${PLUGINJAVADIR}',target) - -# ====================== End feature-specific plugins ==================== - - -# ====================== Vendor-specific plugins ======================== - -for vendor in _glob(_join("vendor","*")) + _glob(_join("cloudstack-proprietary","vendor","*")): if not Options.options.PRESERVECONFIG: - bld.install_files_filtered("${MSCONF}/%s"%vendor,filelist("%s/tomcatconf/*"%vendor)) + bld.install_files_filtered("${MSCONF}","tomcatconf/*", cwd=start_path) + bld.install_files("${MSCONF}",'tomcatconf/db.properties',chmod=0640, cwd=start_path) + bld.setownership("${MSCONF}/db.properties","root",bld.env.MSUSER) + + start_path = bld.path.find_dir("server") + if not Options.options.PRESERVECONFIG: + bld.install_files_filtered("${SERVERSYSCONFDIR}","conf/*", cwd=start_path) -# ====================== End vendor-specific plugins ==================== +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) -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 ] - jars = [ x for x in buildproducts if x.endswith("jar") ] - properties = [ x for x in buildproducts if x.endswith("properties") ] - 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( - 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) +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 ("*html **/*html **/*js **/*css **/*properties **/*jsp *jsp",install_to="${MSENVIRON}/webapps/client", cwd=start_path) -bld.install_files("${PYTHONDIR}/cloudtool", 'cloud-cli/cloudtool/*') -bld.install_as("${PYTHONDIR}/cloudapis.py", 'cloud-cli/cloudapis/cloud.py') +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)) + for dsdir in distrospecificdirs: + start_path = bld.srcnode.find_dir(dsdir) + subpath,varname = _split(dsdir) + dsdirwithvar = _join("${%s}"%varname) + files = filelist('%s/**'%dsdir,src=True,bld=False,dir=False,flat=True) + mode = 0644 + if "SYSCONFDIR" in dsdir: + mode = 0755 + if Options.options.PRESERVECONFIG: continue + bld.install_files_filtered(dsdirwithvar, files, cwd=start_path, relative_trick=True,chmod=mode) + +def build_db_files (): + bld.install_files_filtered("${SETUPDATADIR}",filelist("*/db/* cloudstack-proprietary/*/db/*",excl=Node.exclude_regs + "\ncloud-gate\ncloud-bridge")) + + +def build_plugins (): + # ====================== Feature-specific plugins ======================== + + for plugin in _glob(_join("plugins","*")) + _glob(_join("cloudstack-proprietary","plugins","*")): + if not _exists(_join(plugin,"build.xml")): continue + pluginname = _basename(plugin) + target = 'target/jar/cloud-%s.jar' % pluginname + sources = filelist( '%s/**/*.java' % plugin.replace(sep,"/") , src=True, bld=False, dir=False ) + tgen = bld(rule=lambda x: runant("compile-%s"%pluginname), name='compile_%s'%pluginname, source=sources, target=target, after='runant') + bld.install_files('${PLUGINJAVADIR}',target) + + # ====================== End feature-specific plugins ==================== + + + # ====================== Vendor-specific plugins ======================== + + for vendor in _glob(_join("vendor","*")) + _glob(_join("cloudstack-proprietary","vendor","*")): + if not Options.options.PRESERVECONFIG: + bld.install_files_filtered("${MSCONF}/%s"%vendor,filelist("%s/tomcatconf/*"%vendor)) + + # ====================== 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) ] + + 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.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 + + #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, + target = 'commands.xml', + name = 'xmlapi', + after = 'runant', + install_path="${CLIDIR}" + ) + + bld.install_files("${PYTHONDIR}/cloudtool", 'cloud-cli/cloudtool/*') + bld.install_as("${PYTHONDIR}/cloudapis.py", 'cloud-cli/cloudapis/cloud.py') + + + +# 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()