#!/usr/bin/python # build_online_release # # Performs build in an online release directory, i.e. compiles, links and installs everything into global release dir # # If requested does svn update or checkout prior to build/install # - if checkout requested then checks out all packages in SVN online packages directory # - can check out a tagged version as well # # Default svn repository: https://halldsvn.jlab.org/repos/trunk/online/packages # Default svn tags repository: https://halldsvn.jlab.org/repos/tags/online/packages-tagName # # ejw, 23-May-2013 import os import sys import subprocess from optparse import OptionParser, OptionGroup # default repository URL's defaultRepo = 'https://halldsvn.jlab.org/repos/trunk/online/packages' defaultTagsRepo = 'https://halldsvn.jlab.org/repos/tags/online/packages' # create parser, define command line options, defaults and help strings description = '' epilog = 'Note...does not modify the SVN repository in any way, in particular it does NOT create tagged versions in SVN.' parser = OptionParser(usage="\n %prog [options] someReleaseDirectory\n\nBuilds/installs software in an existing online release directory someReleaseDirectory. Optionally can check out all online software packages from SVN into a new directory structure, or can update an existing directory structure to the latest SVN version. SVN version can be the default or a tagged version.\n\n\nExamples:\n\nTo check out online software into a new directory structure newRelease:\n build_online_release newRelease --checkout\n\nTo update and rebuild an existing release:\n build_online_release oldRelease --update\n\nTo just rebuild an existing release:\n build_online_release oldRelease\n\nNote: the default SVN repository is: https://halldsvn.jlab.org/repos/trunk/online/packages\n the default tags repository is: https://halldsvn.jlab.org/repos/tags/online/packages\n", description=description, epilog=epilog) # add Operation options group opGroup = OptionGroup(parser, "Operation Options","") opGroup.add_option("--checkout", dest="checkout", action="store_true", default=False, help="Check out code before build/install") opGroup.add_option("--update", dest="update", action="store_true", default=False, help="Update existing code before build/install") opGroup.add_option("--noBuild", dest="noBuild", action="store_true", default=False, help="Do not build anything") opGroup.add_option("--noCPP", dest="noCPP", action="store_true", default=False, help="Do not build C/C++") opGroup.add_option("--noJava", dest="noJava", action="store_true", default=False, help="Do not build Java") opGroup.add_option("--noInstall", dest="noInstall", action="store_true", default=False, help="Do not install") opGroup.add_option("--force", dest="force", action="store_true", default=False, help="Ignore errors in options") parser.add_option_group(opGroup) # add Repository options group repoGroup = OptionGroup(parser, "Repository Options","") repoGroup.add_option("--repo", dest="repo", action="store", default=defaultRepo, help="SVN repository URL") repoGroup.add_option("--tagsRepo", dest="tagsRepo", action="store", default=defaultTagsRepo, help="SVN repository URL for tagged versions") repoGroup.add_option("--tagName", dest="tagName", action="store", default="None", help="Tag name of tagged version") parser.add_option_group(repoGroup) # parse command line (options, args) = parser.parse_args() # get release/installation name if(len(args)<1): parser.print_help() sys.exit(0) releaseName = args[0] # check for consistent options if(options.force==False): if((options.checkout==True) and (options.update==True)): print '\n ?Cannot both checkout and update at the same time\n' sys.exit(0) elif(os.path.exists(releaseName) and (options.checkout==True)): print '\n ?Release ' + releaseName + ' already exists, cannot create a new one with the same name (try --update)\n' sys.exit(0) elif((not os.path.exists(releaseName)) and (options.update==True)): print '\n ?Release ' + releaseName + ' does not exist, cannot update (try --checkout)\n' sys.exit(0) elif((not os.path.exists(releaseName)) and (options.checkout==False)): print '\n ?Release ' + releaseName + ' does not exist, nothing to build/install (try --checkout)\n' sys.exit(0) # get full release dir name release_root = os.getcwd()+'/'+ releaseName # create top directory if needed if(not os.path.exists(releaseName)): os.makedirs(releaseName) # update or check out packages directory, use tagged version if requested, cd to packages dir when done os.chdir(releaseName) if(options.update==True): os.chdir('packages') os.system('svn update ') elif(options.checkout==True): repo=options.repo if(options.tagName != 'None'): repo = options.tagsRepo + '-' + options.tagName os.system('svn co ' + repo) # create SConstruct file in packages directory os.chdir('packages') os.system('cp buildScripts/scripts/SConstruct_for_package_dir SConstruct') else: os.chdir('packages') # now in packages directory # set Python path to point to this release env = dict(os.environ) env['PYTHONPATH'] = release_root+'/packages/buildScripts/scripts' # build and install for C/C++ if((options.noBuild==False) and (options.noCPP==False)): subprocess.call(['scons','SHOWBUILD=1'], env=env) if((options.noInstall==False) and (options.noCPP==False)): subprocess.call(['scons','ginstall','SHOWBUILD=1', env=env) # build and install for Java if((options.noBuild==False) and (options.noJava==False)): subprocess.call(['scons','java'], env=env) if((options.noInstall==False) and (options.noJava==False)): subprocess.call(['scons','ginstall','java', env=env) # done if(options.update==True): print '\n *** Release ' + releaseName + ' updated ***\n' elif(options.checkout==True): print '\n *** Release ' + releaseName + ' created ***\n' else: print '\n *** Release ' + releaseName + ' rebuilt ***\n' sys.exit(0)