def changesInSVN(moduleDir, workingDir, log): changesAtAll = False for module in reposModules: log.write("[tbox] Checking for updates [%s] [%s]\n" % (workingDir, module)) moduleDir = os.path.join(workingDir, module) print "[%s] [%s] [%s]" % (workingDir, module, moduleDir) os.chdir(moduleDir) outputList = hardhatutil.executeCommandReturnOutputRetry( [svnProgram, "up"]) hardhatutil.dumpOutputList(outputList, log) if NeedsUpdate(outputList): changesAtAll = True print "" + module + " needs updating" else: # print "NO, unchanged" log.write("Module unchanged" + "\n") log.write(separator) log.write("Done with SVN\n") return changesAtAll
def doUploadToStaging(buildmode, workingDir, buildVersion, log): print "doUploadToStaging..." if buildmode == "debug": dbgStr = "DEBUG=1" else: dbgStr = "" buildRoot = os.path.join(workingDir, 'external') print 'Setting BUILD_ROOT=', buildRoot log.write('Setting BUILD_ROOT=' + buildRoot + '\n') os.putenv('BUILD_ROOT', buildRoot) os.chdir(buildRoot) uploadDir = os.path.join(buildRoot, buildVersion) if not os.path.exists(uploadDir): os.mkdir(uploadDir) try: upload = ' uploadworld UPLOAD=' + uploadDir print "Doing make " + dbgStr + upload log.write("Doing make " + dbgStr + upload + "\n") outputList = hardhatutil.executeCommandReturnOutput( [buildenv['make'], dbgStr, upload]) hardhatutil.dumpOutputList(outputList, log) log.write(separator) except hardhatutil.ExternalCommandErrorWithOutputList, e: print "upload error" log.write("***Error during upload***\n") log.write(separator) log.write("Build log:" + "\n") hardhatutil.dumpOutputList(e.outputList, log) log.write(separator) raise e
def changesInSVN(workingDir, log): changesDict = {} os.chdir(workingDir) for module in reposModules: log.write("[tbox] Checking for updates [%s] [%s]\n" % (workingDir, module)) moduleDir = os.path.join(workingDir, module) changesDict[module] = False print "[%s] [%s] [%s]" % (workingDir, module, moduleDir) os.chdir(moduleDir) outputList = hardhatutil.executeCommandReturnOutputRetry( [svnProgram, "up"]) hardhatutil.dumpOutputList(outputList, log) if NeedsUpdate(outputList): changesDict[module] = True log.write("%s needs updating\n" % module) else: log.write("%s unchanged\n" % module) log.write(separator) log.write("Done with SVN\n") return changesDict
def doTests(hardhatScript, mode, workingDir, outputDir, buildVersion, log): testDir = os.path.join(workingDir, "chandler") os.chdir(testDir) if mode == "debug": dashT = '-dvt' else: dashT = '-vrt' try: # test print "Testing " + mode log.write(separator) log.write("Testing " + mode + " ...\n") print "hardhatScript [%s]" % hardhatScript outputList = hardhatutil.executeCommandReturnOutput( [hardhatScript, dashT]) hardhatutil.dumpOutputList(outputList, log) except Exception, e: print "a testing error" doCopyLog("***Error during tests***", workingDir, logPath, log) forceBuildNextCycle(log, workingDir) return "test_failed"
def changesInSVN(workingDir, log): changesDict = {} os.chdir(workingDir) for module in reposModules: log.write("[tbox] Checking for updates [%s] [%s]\n" % (workingDir, module)) moduleDir = os.path.join(workingDir, module) changesDict[module] = False print "[%s] [%s] [%s]" % (workingDir, module, moduleDir) os.chdir(moduleDir) outputList = hardhatutil.executeCommandReturnOutputRetry([svnProgram, "up"]) hardhatutil.dumpOutputList(outputList, log) if NeedsUpdate(outputList): changesDict[module] = True log.write("%s needs updating\n" % module) else: log.write("%s unchanged\n" % module) log.write(separator) log.write("Done with SVN\n") return changesDict
def changesInSVN(moduleDir, workingDir, log): changesAtAll = False for module in reposModules: log.write("[tbox] Checking for updates [%s] [%s]\n" % (workingDir, module)) moduleDir = os.path.join(workingDir, module) print "[%s] [%s] [%s]" % (workingDir, module, moduleDir) os.chdir(moduleDir) outputList = hardhatutil.executeCommandReturnOutputRetry([svnProgram, "up"]) hardhatutil.dumpOutputList(outputList, log) if NeedsUpdate(outputList): changesAtAll = True print "" + module + " needs updating" else: # print "NO, unchanged" log.write("Module unchanged" + "\n") log.write(separator) log.write("Done with SVN\n") return changesAtAll
def doInstall(buildmode, workingDir, log, cleanFirst=False): # for our purposes, we do not really do a build # we will update chandler from SVN, and grab new tarballs when they appear if buildmode == "debug": dbgStr = "DEBUG=1" else: dbgStr = "" if cleanFirst: clean = " clean " else: clean = " " moduleDir = os.path.join(workingDir, mainModule) os.chdir(moduleDir) print "Doing make " + dbgStr + clean + "install strip\n" log.write("Doing make " + dbgStr + clean + "install strip\n") try: outputList = hardhatutil.executeCommandReturnOutput( [buildenv['make'], dbgStr, clean, "install", "strip"]) hardhatutil.dumpOutputList(outputList, log) except hardhatutil.ExternalCommandErrorWithOutputList, e: print "build error" log.write("***Error during build***\n") log.write(separator) log.write("Build log:" + "\n") hardhatutil.dumpOutputList(e.outputList, log) log.write(separator) forceBuildNextCycle(log, workingDir) raise e
def doDistribution(workingDir, log, outputDir, buildVersion, buildVersionEscaped): log.write(separator) log.write("[tbox] Creating distribution files\n") for (module, target, distSource, fileGlob) in reposDist: moduleDir = os.path.join(workingDir, module) print "Distribution [%s]" % module try: os.chdir(moduleDir) outputList = hardhatutil.executeCommandReturnOutput( [antProgram, target]) hardhatutil.dumpOutputList(outputList, log) sourceDir = os.path.join(moduleDir, distSource) targetDir = os.path.join(outputDir, buildVersion) if not os.path.exists(targetDir): os.mkdir(targetDir) print sourceDir, targetDir log.write("[tbox] Moving %s to %s\n" % (sourceDir, targetDir)) hardhatlib.copyFiles(sourceDir, targetDir, fileGlob) except Exception, e: doCopyLog("***Error during distribution building process*** ", workingDir, logPath, log) raise e
def doDistribution(workingDir, log, outputDir, buildVersion, buildVersionEscaped): log.write(separator) log.write("[tbox] Creating distribution files\n") for (module, target, distSource, fileGlob) in reposDist: moduleDir = os.path.join(workingDir, module) print "Distribution [%s]" % module try: os.chdir(moduleDir) outputList = hardhatutil.executeCommandReturnOutput([antProgram, target]) hardhatutil.dumpOutputList(outputList, log) sourceDir = os.path.join(moduleDir, distSource) targetDir = os.path.join(outputDir, buildVersion) if not os.path.exists(targetDir): os.mkdir(targetDir) print sourceDir, targetDir log.write("[tbox] Moving %s to %s\n" % (sourceDir, targetDir)) hardhatlib.copyFiles(sourceDir, targetDir, fileGlob) except Exception, e: doCopyLog("***Error during distribution building process*** ", workingDir, logPath, log) raise e
def doInstall(buildmode, workingDir, log, cleanFirst=False): # for our purposes, we do not really do a build # we will update chandler from SVN, and grab new tarballs when they appear if buildmode == "debug": dbgStr = "DEBUG=1" else: dbgStr = "" if cleanFirst: clean = " clean " else: clean = " " moduleDir = os.path.join(workingDir, mainModule) os.chdir(moduleDir) print "Doing make " + dbgStr + clean + "install strip\n" log.write("Doing make " + dbgStr + clean + "install strip\n") try: outputList = hardhatutil.executeCommandReturnOutput( [buildenv['make'], dbgStr, clean, "install", "strip" ]) hardhatutil.dumpOutputList(outputList, log) except hardhatutil.ExternalCommandErrorWithOutputList, e: print "build error" log.write("***Error during build***\n") log.write(separator) log.write("Build log:" + "\n") hardhatutil.dumpOutputList(e.outputList, log) log.write(separator) forceBuildNextCycle(log, workingDir) raise e
def doDistribution(releaseMode, workingDir, log, outputDir, buildVersion, buildVersionEscaped, hardhatScript): # Create end-user, developer distributions chanDir = os.path.join(workingDir, 'chandler') os.chdir(chanDir) print "Making distribution files for " + releaseMode log.write(separator) log.write("Making distribution files for " + releaseMode + "\n") if releaseMode == "debug": distOption = "-dD" else: distOption = "-D" try: outputList = hardhatutil.executeCommandReturnOutput([ hardhatScript, "-o", os.path.join(outputDir, buildVersion), distOption, buildVersionEscaped ]) hardhatutil.dumpOutputList(outputList, log) except Exception, e: doCopyLog("***Error during distribution building process*** ", workingDir, logPath, log) forceBuildNextCycle(log, workingDir) raise e
def doBuild(buildmode, workingDir, log, svnChanges, clean='realclean'): # We only build external if there were changes in it # We build internal if external or internal were changed # We never build in chandler, because there is nothing to build if buildmode == "debug": dbgStr = "DEBUG=1" else: dbgStr = "" buildRoot = os.path.join(workingDir, 'external') print 'Setting BUILD_ROOT=', buildRoot log.write('Setting BUILD_ROOT=' + buildRoot + '\n') os.putenv('BUILD_ROOT', buildRoot) try: for module in reposModules: print module, "..." log.write("- - - - " + module + " - - - - - - -\n") if module == 'external' and not svnChanges['external']: print 'Nothing to be done for module', module log.write('Nothing to be done for module ' + module + '\n') log.write(separator) continue if module == 'internal' and not svnChanges['external'] and not svnChanges['internal']: print 'Nothing to be done for module', module log.write('Nothing to be done for module ' + module + '\n') log.write(separator) continue if module == 'chandler': print 'Nothing to be done for module', module log.write('Nothing to be done for module ' + module + '\n') log.write(separator) continue moduleDir = os.path.join(workingDir, module) print "cd", moduleDir log.write("cd " + moduleDir + "\n") os.chdir(moduleDir) buildCmds = ' all binaries install' print "Doing make " + dbgStr + " " + clean + buildCmds + "\n" log.write("Doing make " + dbgStr + " " + clean + buildCmds + "\n") outputList = hardhatutil.executeCommandReturnOutput( [buildenv['make'], dbgStr, clean, buildCmds ]) hardhatutil.dumpOutputList(outputList, log) log.write(separator) except hardhatutil.ExternalCommandErrorWithOutputList, e: print "build error" log.write("***Error during build***\n") log.write(separator) log.write("Build log:" + "\n") hardhatutil.dumpOutputList(e.outputList, log) log.write(separator) forceBuildNextCycle(log, workingDir) raise e
def doRealclean(log, workingDir): try: # If make install fails, it will almost certainly fail next time # as well - the typical case has been bad binaries packages. # So what we do here is try to do realclean which will force # the build to get new binaries tarballs next time, and if fixed # binaries were uploaded in the meanwhile we'll recover # automatically. This will also sort us out of corrupted debug/release. print "Doing make realclean\n" log.write("Doing make realclean\n") moduleDir = os.path.join(workingDir, mainModule) os.chdir(moduleDir) outputList = hardhatutil.executeCommandReturnOutput( [buildenv['make'], "realclean"]) hardhatutil.dumpOutputList(outputList, log) except: print "make realclean failed\n" log.write("make realclean failed\n")
def doBuild(workingDir, log): log.write("[tbox] Building\n") for (module, target) in reposBuild: moduleDir = os.path.join(workingDir, module) mavenDir = os.path.join(workingDir, "..", "tbox_maven", module) print "Building [%s]" % module try: os.chdir(moduleDir) outputList = hardhatutil.executeCommandReturnOutput([antProgram, "-Dmaven.home.local=" + mavenDir, target]) hardhatutil.dumpOutputList(outputList, log) except: log.write("[tbox] Build failed for [%s]\n" % module)
def doDistribution(releaseMode, workingDir, log, outputDir, buildVersion, buildVersionEscaped, hardhatScript): # Create end-user, developer distributions print "Making distribution files for " + releaseMode log.write(separator) log.write("Making distribution files for " + releaseMode + "\n") if releaseMode == "debug": distOption = "-dD" else: distOption = "-D" try: outputList = hardhatutil.executeCommandReturnOutput( [hardhatScript, "-o", os.path.join(outputDir, buildVersion), distOption, buildVersionEscaped]) hardhatutil.dumpOutputList(outputList, log) except Exception, e: doCopyLog("***Error during distribution building process*** ", workingDir, logPath, log) forceBuildNextCycle(log, workingDir) raise e
def doBuild(workingDir, log): log.write("[tbox] Building\n") for (module, target) in reposBuild: moduleDir = os.path.join(workingDir, module) mavenDir = os.path.join(workingDir, '..', 'tbox_maven', module) print "Building [%s]" % module try: os.chdir(moduleDir) outputList = hardhatutil.executeCommandReturnOutput( [antProgram, '-Dmaven.home.local=' + mavenDir, target]) hardhatutil.dumpOutputList(outputList, log) except: log.write("[tbox] Build failed for [%s]\n" % module)
def doTests(workingDir, log): log.write("[tbox] Running unit tests\n") for (module, target) in reposTest: moduleDir = os.path.join(workingDir, module) print "Testing [%s]" % module try: os.chdir(moduleDir) outputList = hardhatutil.executeCommandReturnOutput([antProgram, target]) hardhatutil.dumpOutputList(outputList, log) except Exception, e: doCopyLog("***Error during tests***", workingDir, logPath, log) return "test_failed" else: doCopyLog("Tests successful", workingDir, logPath, log)
def main(): curDir = os.path.abspath(os.getcwd()) path = os.environ.get('PATH', os.environ.get('path')) svnProgram = hardhatutil.findInPath(path, "svn") if os.path.exists(stopFile): os.remove(stopFile) go = 1 firstRound = 1 while go: os.chdir(curDir) if not firstRound: print "Sleeping 5 minutes" time.sleep(5 * 60) nowString = time.strftime("%Y-%m-%d %H:%M:%S") # check SVN for any new hardhat script try: # bring this hardhat directory up to date outputList = hardhatutil.executeCommandReturnOutputRetry( [svnProgram, "-q", "update"]) hardhatutil.dumpOutputList(outputList) except: raise TinderbuildError, "Error updating HardHat" try: # launch the real build script outputList = hardhatutil.executeCommandReturnOutput( [os.path.join(curDir, 'tinderbox.py'), ' '.join(sys.argv[1:])]) hardhatutil.dumpOutputList(outputList) except: raise TinderbuildError, "Failed to launch build script" if os.path.exists(stopFile): go = 0 firstRound = 0
def doTests(workingDir, log): log.write("[tbox] Running unit tests\n") for (module, target) in reposTest: moduleDir = os.path.join(workingDir, module) print "Testing [%s]" % module try: os.chdir(moduleDir) outputList = hardhatutil.executeCommandReturnOutput( [antProgram, target]) hardhatutil.dumpOutputList(outputList, log) except Exception, e: doCopyLog("***Error during tests***", workingDir, logPath, log) return "test_failed" else: doCopyLog("Tests successful", workingDir, logPath, log)
def Start(hardhatScript, workingDir, buildVersion, clobber, log, skipTests=False, upload=False): # make sure workingDir is absolute workingDir = os.path.abspath(workingDir) os.chdir(workingDir) # remove outputDir and create it outputDir = os.path.join(workingDir, "output") if os.path.exists(outputDir): hardhatutil.rmdirRecursive(outputDir) os.mkdir(outputDir) buildVersionEscaped = "\'" + buildVersion + "\'" buildVersionEscaped = buildVersionEscaped.replace(" ", "|") sourceChanged = False log.write("[tbox] Pulling source tree\n") for (module, moduleSource) in reposModules: moduleDir = os.path.join(workingDir, module) if os.path.exists(moduleDir): log.write("[tbox] Checking for source updates\n") print "updating %s" % module os.chdir(moduleDir) outputList = hardhatutil.executeCommandReturnOutputRetry( [svnProgram, "up"]) hardhatutil.dumpOutputList(outputList, log) if NeedsUpdate(outputList): sourceChanged = True log.write("[tbox] %s modified\n" % module) else: log.write("[tbox] %s unchanged\n" % module) else: svnSource = os.path.join(reposRoot, moduleSource) log.write("[tbox] Retrieving source tree [%s]\n" % svnSource) print "pulling %s" % module os.chdir(workingDir) outputList = hardhatutil.executeCommandReturnOutputRetry( [svnProgram, "-q", "co", svnSource, module]) hardhatutil.dumpOutputList(outputList, log) sourceChanged = True os.chdir(workingDir) doBuild(workingDir, log) if skipTests: ret = 'success' else: ret = doTests(workingDir, log) if sourceChanged: doDistribution(workingDir, log, outputDir, buildVersion, buildVersionEscaped) changes = "-changes" else: changes = "-nochanges" print ret + changes return ret + changes
buildVersionEscaped = buildVersionEscaped.replace(" ", "|") if not os.path.exists(chanDir): # Initialize sources print "Setup source tree..." log.write("- - - - tree setup - - - - - - -\n") for module in reposModules: svnSource = os.path.join(reposRoot, reposBase, module) log.write("[tbox] Retrieving source tree [%s]\n" % svnSource) outputList = hardhatutil.executeCommandReturnOutputRetry( [svnProgram, "-q", "co", svnSource, module]) hardhatutil.dumpOutputList(outputList, log) os.chdir(chanDir) for releaseMode in releaseModes: doInstall(releaseMode, workingDir, log) doDistribution(releaseMode, workingDir, log, outputDir, buildVersion, buildVersionEscaped, hardhatScript) if skipTests: ret = 'success' else: ret = doTests(hardhatScript, releaseMode, workingDir, outputDir, buildVersion, log) if ret != 'success':
def doBuild(buildmode, workingDir, log, svnChanges, clean='realclean'): # We only build external if there were changes in it # We build internal if external or internal were changed # We never build in chandler, because there is nothing to build if buildmode == "debug": dbgStr = "DEBUG=1" else: dbgStr = "" buildRoot = os.path.join(workingDir, 'external') print 'Setting BUILD_ROOT=', buildRoot log.write('Setting BUILD_ROOT=' + buildRoot + '\n') os.putenv('BUILD_ROOT', buildRoot) try: for module in reposModules: print module, "..." log.write("- - - - " + module + " - - - - - - -\n") if module == 'external' and not svnChanges['external']: print 'Nothing to be done for module', module log.write('Nothing to be done for module ' + module + '\n') log.write(separator) continue if module == 'internal' and not svnChanges[ 'external'] and not svnChanges['internal']: print 'Nothing to be done for module', module log.write('Nothing to be done for module ' + module + '\n') log.write(separator) continue if module == 'chandler': print 'Nothing to be done for module', module log.write('Nothing to be done for module ' + module + '\n') log.write(separator) continue moduleDir = os.path.join(workingDir, module) print "cd", moduleDir log.write("cd " + moduleDir + "\n") os.chdir(moduleDir) buildCmds = ' all binaries install' print "Doing make " + dbgStr + " " + clean + buildCmds + "\n" log.write("Doing make " + dbgStr + " " + clean + buildCmds + "\n") outputList = hardhatutil.executeCommandReturnOutput( [buildenv['make'], dbgStr, clean, buildCmds]) hardhatutil.dumpOutputList(outputList, log) log.write(separator) except hardhatutil.ExternalCommandErrorWithOutputList, e: print "build error" log.write("***Error during build***\n") log.write(separator) log.write("Build log:" + "\n") hardhatutil.dumpOutputList(e.outputList, log) log.write(separator) forceBuildNextCycle(log, workingDir) raise e
def Start(hardhatScript, workingDir, buildVersion, clobber, log, skipTests=False, upload=False): # make sure workingDir is absolute workingDir = os.path.abspath(workingDir) os.chdir(workingDir) # remove outputDir and create it outputDir = os.path.join(workingDir, "output") if os.path.exists(outputDir): hardhatutil.rmdirRecursive(outputDir) os.mkdir(outputDir) buildVersionEscaped = "'" + buildVersion + "'" buildVersionEscaped = buildVersionEscaped.replace(" ", "|") sourceChanged = False log.write("[tbox] Pulling source tree\n") for (module, moduleSource) in reposModules: moduleDir = os.path.join(workingDir, module) if os.path.exists(moduleDir): log.write("[tbox] Checking for source updates\n") print "updating %s" % module os.chdir(moduleDir) outputList = hardhatutil.executeCommandReturnOutputRetry([svnProgram, "up"]) hardhatutil.dumpOutputList(outputList, log) if NeedsUpdate(outputList): sourceChanged = True log.write("[tbox] %s modified\n" % module) else: log.write("[tbox] %s unchanged\n" % module) else: svnSource = os.path.join(reposRoot, moduleSource) log.write("[tbox] Retrieving source tree [%s]\n" % svnSource) print "pulling %s" % module os.chdir(workingDir) outputList = hardhatutil.executeCommandReturnOutputRetry([svnProgram, "-q", "co", svnSource, module]) hardhatutil.dumpOutputList(outputList, log) sourceChanged = True os.chdir(workingDir) doBuild(workingDir, log) if skipTests: ret = "success" else: ret = doTests(workingDir, log) if sourceChanged: doDistribution(workingDir, log, outputDir, buildVersion, buildVersionEscaped) changes = "-changes" else: changes = "-nochanges" print ret + changes return ret + changes
# Initialize sources print "Setup source tree..." log.write("- - - - tree setup - - - - - - -\n") svnChanges = {} clean = '' for module in reposModules: svnSource = os.path.join(reposRoot, reposBase, module) log.write("[tbox] Retrieving source tree [%s]\n" % svnSource) outputList = hardhatutil.executeCommandReturnOutputRetry( [svnProgram, "-q", "co", svnSource, module]) hardhatutil.dumpOutputList(outputList, log) svnChanges[module] = True for releaseMode in releaseModes: doBuild(releaseMode, workingDir, log, svnChanges, clean) if upload: doUploadToStaging(releaseMode, workingDir, buildVersion, log) clean = 'clean' for releaseMode in releaseModes: doDistribution(releaseMode, workingDir, log, outputDir, buildVersion, buildVersionEscaped, hardhatScript) if skipTests: