| 1 |
# @HEADER |
| 2 |
# ***************************************************************************** |
| 3 |
# TriBITS: Tribal Build, Integrate, and Test System |
| 4 |
# |
| 5 |
# Copyright 2013-2016 NTESS and the TriBITS contributors. |
| 6 |
# SPDX-License-Identifier: BSD-3-Clause |
| 7 |
# ***************************************************************************** |
| 8 |
# @HEADER |
| 9 |
|
| 10 |
|
| 11 |
# |
| 12 |
# ToDo: |
| 13 |
# |
| 14 |
# (*) Create a TaskStatus class and use it to simplify the logic replacing |
| 15 |
# the simple bools. |
| 16 |
# |
| 17 |
|
| 18 |
# |
| 19 |
# General scripting support |
| 20 |
# |
| 21 |
# NOTE: Included first to check the version of python! |
| 22 |
# |
| 23 |
|
| 24 |
from __future__ import print_function |
| 25 |
import sys |
| 26 |
import os |
| 27 |
import time |
| 28 |
import pprint |
| 29 |
import re |
| 30 |
|
| 31 |
checkinTestBasePath = os.path.dirname(os.path.abspath(os.path.realpath(__file__))) |
| 32 |
|
| 33 |
sys.path = [checkinTestBasePath+"/../python_utils"] + sys.path |
| 34 |
|
| 35 |
from GeneralScriptSupport import * |
| 36 |
|
| 37 |
from CheckinTestConstants import * |
| 38 |
from TribitsDependencies import getProjectDependenciesFromXmlFile |
| 39 |
from TribitsDependencies import getDefaultDepsXmlInFile |
| 40 |
from TribitsPackageFilePathUtils import * |
| 41 |
from Python2and3 import s |
| 42 |
import gitdist |
| 43 |
|
| 44 |
pp = pprint.PrettyPrinter(indent=4) |
| 45 |
|
| 46 |
# Load some default dependencies for some unit tests |
| 47 |
projectDependenciesCache = None |
| 48 |
def getDefaultProjectDependenices(): |
| 49 |
return projectDependenciesCache |
| 50 |
|
| 51 |
|
| 52 |
def getGitRepoDir(srcDir, gitRepoName): |
| 53 |
if gitRepoName: |
| 54 |
return srcDir+"/"+gitRepoName |
| 55 |
return srcDir |
| 56 |
|
| 57 |
|
| 58 |
def getGitRepoFileExt(gitRepoName): |
| 59 |
if gitRepoName: |
| 60 |
return "."+gitRepoName |
| 61 |
return "" |
| 62 |
|
| 63 |
|
| 64 |
def getCommonConfigFileName(): |
| 65 |
return "COMMON.config" |
| 66 |
|
| 67 |
|
| 68 |
def getProjectDependenciesXmlFileName(projectName): |
| 69 |
return projectName+"PackageDependencies.xml" |
| 70 |
|
| 71 |
|
| 72 |
def getProjectDependenciesXmlGenerateOutputFileName(projectName): |
| 73 |
return projectName+"PackageDependencies.generate.out" |
| 74 |
|
| 75 |
|
| 76 |
def getProjectExtraReposPythonOutFile(projectName): |
| 77 |
return projectName+"ExtraRepos.py" |
| 78 |
|
| 79 |
|
| 80 |
def getTribitsGetExtraReposForCheckinTestOututFile(projectName): |
| 81 |
return projectName+"ExtraRepos.generate.out" |
| 82 |
|
| 83 |
|
| 84 |
def getBuildSpecificConfigFileName(buildTestCaseName): |
| 85 |
return buildTestCaseName+".config" |
| 86 |
|
| 87 |
|
| 88 |
def getInitialPullOutputFileName(gitRepoName): |
| 89 |
return "pullInitial"+getGitRepoFileExt(gitRepoName)+".out" |
| 90 |
|
| 91 |
|
| 92 |
def getInitialExtraPullOutputFileName(gitRepoName): |
| 93 |
return "pullInitialExtra"+getGitRepoFileExt(gitRepoName)+".out" |
| 94 |
|
| 95 |
|
| 96 |
def getInitialPullSuccessFileName(): |
| 97 |
return "pullInitial.success" |
| 98 |
|
| 99 |
|
| 100 |
def getModifiedFilesOutputFileName(gitRepoName): |
| 101 |
return "modifiedFiles"+getGitRepoFileExt(gitRepoName)+".out" |
| 102 |
|
| 103 |
|
| 104 |
def getFinalPullOutputFileName(gitRepoName): |
| 105 |
return "pullFinal"+getGitRepoFileExt(gitRepoName)+".out" |
| 106 |
|
| 107 |
|
| 108 |
def getConfigureOutputFileName(): |
| 109 |
return "configure.out" |
| 110 |
|
| 111 |
|
| 112 |
def getConfigureSuccessFileName(): |
| 113 |
return "configure.success" |
| 114 |
|
| 115 |
|
| 116 |
def getBuildOutputFileName(): |
| 117 |
return "make.out" |
| 118 |
|
| 119 |
|
| 120 |
def getBuildSuccessFileName(): |
| 121 |
return "make.success" |
| 122 |
|
| 123 |
|
| 124 |
def getTestOutputFileName(): |
| 125 |
return "ctest.out" |
| 126 |
|
| 127 |
|
| 128 |
def getTestSuccessFileName(): |
| 129 |
return "ctest.success" |
| 130 |
|
| 131 |
|
| 132 |
def getEmailBodyFileName(): |
| 133 |
return "email.out" |
| 134 |
|
| 135 |
|
| 136 |
def getEmailSuccessFileName(): |
| 137 |
return "email.success" |
| 138 |
|
| 139 |
|
| 140 |
def getFinalCommitBodyFileName(gitRepoName): |
| 141 |
return "commitFinalBody"+getGitRepoFileExt(gitRepoName)+".out" |
| 142 |
|
| 143 |
|
| 144 |
def getFinalCommitOutputFileName(gitRepoName): |
| 145 |
return "commitFinal"+getGitRepoFileExt(gitRepoName)+".out" |
| 146 |
|
| 147 |
|
| 148 |
def getCommitStatusEmailBodyFileName(): |
| 149 |
return "commitStatusEmailBody.out" |
| 150 |
|
| 151 |
|
| 152 |
def getPushOutputFileName(gitRepoName): |
| 153 |
return "push"+getGitRepoFileExt(gitRepoName)+".out" |
| 154 |
|
| 155 |
|
| 156 |
def getExtraCommandOutputFileName(): |
| 157 |
return "extraCommand.out" |
| 158 |
|
| 159 |
|
| 160 |
def getHostname(): |
| 161 |
return getCmndOutput("hostname", True) |
| 162 |
|
| 163 |
|
| 164 |
def getEmailAddressesSpaceString(emailAddressesCommasStr): |
| 165 |
emailAddressesList = emailAddressesCommasStr.split(',') |
| 166 |
return ' '.join(emailAddressesList) |
| 167 |
|
| 168 |
|
| 169 |
def performAnyBuildTestActions(inOptions): |
| 170 |
if inOptions.doConfigure or inOptions.doBuild \ |
| 171 |
or inOptions.doTest or inOptions.doAll or inOptions.localDoAll \ |
| 172 |
: |
| 173 |
return True |
| 174 |
return False |
| 175 |
|
| 176 |
|
| 177 |
def performAnyActions(inOptions): |
| 178 |
if performAnyBuildTestActions(inOptions) or inOptions.doPull: |
| 179 |
return True |
| 180 |
return False |
| 181 |
|
| 182 |
|
| 183 |
def doGenerateOutputFiles(inOptions): |
| 184 |
return performAnyActions(inOptions) |
| 185 |
|
| 186 |
|
| 187 |
def doRemoveOutputFiles(inOptions): |
| 188 |
return performAnyActions(inOptions) |
| 189 |
|
| 190 |
|
| 191 |
def assertAndSetupGit(inOptions): |
| 192 |
|
| 193 |
gitWhich = getCmndOutput("which git", True, False) |
| 194 |
if gitWhich == "" or re.match(".+no git.+", gitWhich): |
| 195 |
msg = "Error, the 'git' command is not in your path! (" + gitWhich + ")" |
| 196 |
print(msg) |
| 197 |
raise Exception(msg) |
| 198 |
else: |
| 199 |
setattr(inOptions, "git", "git") |
| 200 |
|
| 201 |
|
| 202 |
def assertGitRepoExists(inOptions, gitRepo): |
| 203 |
gitRepoDir = getGitRepoDir(inOptions.srcDir, gitRepo.repoDir) |
| 204 |
if not os.path.os.path.exists(gitRepoDir): |
| 205 |
raise Exception("Error, the specified git repo '"+gitRepo.repoName+"' directory" |
| 206 |
" '"+gitRepoDir+"' does not exist!") |
| 207 |
|
| 208 |
|
| 209 |
def assertPackageNames(optionName, packagesListStr): |
| 210 |
if not packagesListStr: |
| 211 |
return |
| 212 |
for packageName in packagesListStr.split(','): |
| 213 |
if getDefaultProjectDependenices().packageNameToID(packageName) == -1: |
| 214 |
validPackagesListStr = "" |
| 215 |
for i in range(getDefaultProjectDependenices().numPackages()): |
| 216 |
if validPackagesListStr != "": |
| 217 |
validPackagesListStr += ", " |
| 218 |
validPackagesListStr += getDefaultProjectDependenices().getPackageByID(i).packageName |
| 219 |
raise Exception("Error, invalid package name "+packageName+" in " \ |
| 220 |
+optionName+"="+packagesListStr \ |
| 221 |
+". The valid package names include: "+validPackagesListStr) |
| 222 |
|
| 223 |
|
| 224 |
def assertExtraBuildConfigFiles(extraBuilds): |
| 225 |
if not extraBuilds: |
| 226 |
return |
| 227 |
for extraBuild in extraBuilds.split(','): |
| 228 |
extraBuildConfigFile = extraBuild+".config" |
| 229 |
if not os.path.exists(extraBuildConfigFile): |
| 230 |
raise Exception("Error, the extra build configuration file " \ |
| 231 |
+extraBuildConfigFile+" does not exit!") |
| 232 |
|
| 233 |
|
| 234 |
class GitdistOptions: |
| 235 |
def __init__(self, useGit): |
| 236 |
self.useGit = useGit |
| 237 |
|
| 238 |
|
| 239 |
# Create a matching version of gitdist.getCmndOutout |
| 240 |
def getCmndOutputForGitDist(cmnd, rtnCode=False): |
| 241 |
return getCmndOutput(cmnd, rtnCode=rtnCode, throwOnError=False) |
| 242 |
|
| 243 |
|
| 244 |
def getRepoStats(inOptions, gitRepo_inout): |
| 245 |
gitRepoDir = getGitRepoDir(inOptions.srcDir, gitRepo_inout.repoDir) |
| 246 |
gitdistOptions = GitdistOptions(inOptions.git) |
| 247 |
pwd = os.getcwd() |
| 248 |
try: |
| 249 |
os.chdir(gitRepoDir) |
| 250 |
gitRepo_inout.gitRepoStats = \ |
| 251 |
gitdist.getRepoStats(gitdistOptions, getCmndOutputForGitDist) |
| 252 |
finally: |
| 253 |
os.chdir(pwd) |
| 254 |
|
| 255 |
|
| 256 |
def getReposStats(inOptions, tribitsGitRepos): |
| 257 |
hasChangesToPush = False |
| 258 |
repoStatTable = gitdist.RepoStatTable() |
| 259 |
repoIdx = 0 |
| 260 |
for gitRepo in tribitsGitRepos.gitRepoList(): |
| 261 |
getRepoStats(inOptions, gitRepo) |
| 262 |
if gitRepo.gitRepoStats.numCommitsInt() > 0: |
| 263 |
hasChangesToPush = True |
| 264 |
repoStatTableDirName = getRepoStatTableDirName(inOptions, gitRepo.repoDir) |
| 265 |
repoStatTable.insertRepoStat(repoStatTableDirName, gitRepo.gitRepoStats, repoIdx) |
| 266 |
repoIdx += 1 |
| 267 |
print(gitdist.createTable(repoStatTable.getTableData())) |
| 268 |
return hasChangesToPush |
| 269 |
# NOTE: Above, we could just call 'gitdist dist-repo-status' but by |
| 270 |
# printing the table here with the actually gitRepoStat data, we ensure |
| 271 |
# that it gets collected correctly and that the selection of repos is |
| 272 |
# exactly the same. |
| 273 |
|
| 274 |
|
| 275 |
def assertRepoHasBranchAndTrackingBranch(inOptions, gitRepo): |
| 276 |
repoName = gitRepo.repoName |
| 277 |
if repoName == "": |
| 278 |
repoNameEntry = "base repo" |
| 279 |
else: |
| 280 |
repoNameEntry = "repo '"+repoName+"'" |
| 281 |
gitRepoStats = gitRepo.gitRepoStats |
| 282 |
if gitRepoStats.branch == "HEAD": |
| 283 |
raise Exception("Error, the "+repoNameEntry+" is in a detached head state which" \ |
| 284 |
" is not allowed in this case!") |
| 285 |
if gitRepoStats.trackingBranch == "": |
| 286 |
raise Exception("Error, the "+repoNameEntry+" is not on a tracking branch which" \ |
| 287 |
" is not allowed in this case!") |
| 288 |
|
| 289 |
|
| 290 |
def pushToTrackingBranchArgs(gitRepo): |
| 291 |
(repo, trackingbranch) = gitRepo.gitRepoStats.trackingBranch.split("/") |
| 292 |
return repo+" "+gitRepo.gitRepoStats.branch+":"+trackingbranch |
| 293 |
|
| 294 |
|
| 295 |
def didSinglePullBringChanges(pullOutFileFullPath): |
| 296 |
pullOutFileStr = readStrFromFile(pullOutFileFullPath) |
| 297 |
#print("\npullOutFileStr:\n" + pullOutFileStr) |
| 298 |
alreadyUpToDateIdx = pullOutFileStr.find("Already up-to-date") |
| 299 |
#print("alreadyUpToDateIdx = "+str(alreadyUpToDateIdx)) |
| 300 |
return alreadyUpToDateIdx == -1 |
| 301 |
|
| 302 |
|
| 303 |
def executePull(gitRepo, inOptions, baseTestDir, outFile, pullFromRepo=None, |
| 304 |
doRebase=False)\ |
| 305 |
: |
| 306 |
cmnd = inOptions.git+" pull" |
| 307 |
if pullFromRepo: |
| 308 |
repoSpaceBranch = pullFromRepo.remoteRepo+" "+pullFromRepo.remoteBranch |
| 309 |
print("\nPulling in updates to local repo '" + gitRepo.repoName + "'" + |
| 310 |
" from '" + repoSpaceBranch + "' ...\n") |
| 311 |
cmnd += " " + repoSpaceBranch |
| 312 |
else: |
| 313 |
print("\nPulling in updates from '" + gitRepo.gitRepoStats.trackingBranch + |
| 314 |
"' ...") |
| 315 |
# NOTE: If you do 'git pull <remote> <branch>', then the list of locally |
| 316 |
# modified files will be wrong. I don't know why this is but if instead |
| 317 |
# you do a raw 'git pull', then the right list of files shows up. |
| 318 |
if doRebase: |
| 319 |
cmnd += " && "+inOptions.git+" rebase "+gitRepo.gitRepoStats.trackingBranch |
| 320 |
outFileFullPath = os.path.join(baseTestDir, outFile) |
| 321 |
(pullRtn, pullTimings) = echoRunSysCmnd( cmnd, |
| 322 |
workingDir=getGitRepoDir(inOptions.srcDir, gitRepo.repoDir), |
| 323 |
outFile=outFileFullPath, |
| 324 |
timeCmnd=True, returnTimeCmnd=True, throwExcept=False |
| 325 |
) |
| 326 |
if pullRtn == 0: |
| 327 |
pullGotChanges = didSinglePullBringChanges(outFileFullPath) |
| 328 |
if pullGotChanges: |
| 329 |
print("\n ==> '" + gitRepo.repoName + "': Pulled changes from this repo!") |
| 330 |
else: |
| 331 |
print("\n ==> '" + gitRepo.repoName + |
| 332 |
"': Did not pull any changes from this repo!") |
| 333 |
else: |
| 334 |
print("\n ==> '" + gitRepo.repoName + "': Pull failed!") |
| 335 |
pullGotChanges = False |
| 336 |
return (pullRtn, pullTimings, pullGotChanges) |
| 337 |
|
| 338 |
|
| 339 |
class Timings: |
| 340 |
def __init__(self): |
| 341 |
self.pull = -1.0 |
| 342 |
self.configure = -1.0 |
| 343 |
self.build = -1.0 |
| 344 |
self.test = -1.0 |
| 345 |
def deepCopy(self): |
| 346 |
copyTimings = Timings() |
| 347 |
copyTimings.pull = self.pull |
| 348 |
copyTimings.configure = self.configure |
| 349 |
copyTimings.build = self.build |
| 350 |
copyTimings.test = self.test |
| 351 |
return copyTimings |
| 352 |
def totalTime(self): |
| 353 |
tt = 0.0 |
| 354 |
if self.pull > 0: tt += self.pull |
| 355 |
if self.configure > 0: tt += self.configure |
| 356 |
if self.build > 0: tt += self.build |
| 357 |
if self.test > 0: tt += self.test |
| 358 |
return tt |
| 359 |
|
| 360 |
|
| 361 |
class GitRepo: |
| 362 |
def __init__(self, repoName, repoDir='', repoType='GIT', repoHasPackages=True, |
| 363 |
repoPrePost='POST' \ |
| 364 |
): |
| 365 |
self.repoName = repoName |
| 366 |
if repoDir: |
| 367 |
self.repoDir = repoDir |
| 368 |
else: |
| 369 |
self.repoDir = repoName |
| 370 |
self.repoType = repoType |
| 371 |
self.repoHasPackages = repoHasPackages |
| 372 |
self.repoPrePost = repoPrePost |
| 373 |
self.hasChanges = False |
| 374 |
self.gitRepoStats = None |
| 375 |
if (self.repoName and self.repoHasPackages) and (self.repoName != self.repoDir): |
| 376 |
raise Exception("ERROR! For extra repo '"+repoName+"', if repoHasPackages==True" \ |
| 377 |
+" then repoDir must be same as repo name, not '"+repoDir+"'!") |
| 378 |
if self.repoType != 'GIT': |
| 379 |
raise Exception("ERROR! For extra repo '"+repoName+"', the repo type" \ |
| 380 |
+" '"+self.repoType+"' is not supported by the checkin-test.py script, only 'GIT'!") |
| 381 |
def __str__(self): |
| 382 |
return "GitRepo{repoName='"+self.repoName+"'" \ |
| 383 |
+", repoDir='"+str(self.repoDir)+"'" \ |
| 384 |
+", repoType='"+str(self.repoType)+"'" \ |
| 385 |
+", repoHasPackages="+str(self.repoHasPackages) \ |
| 386 |
+", repoPrePost="+str(self.repoPrePost) \ |
| 387 |
+", hasChanges="+str(self.hasChanges) \ |
| 388 |
+"}" |
| 389 |
def __rep__(self): |
| 390 |
return str(self) |
| 391 |
|
| 392 |
|
| 393 |
def getExtraReposFilePath(inOptions): |
| 394 |
if inOptions.extraReposFile == "project": |
| 395 |
extraReposFile = inOptions.srcDir+"/cmake/ExtraRepositoriesList.cmake" |
| 396 |
else: |
| 397 |
extraReposFile = inOptions.extraReposFile |
| 398 |
return extraReposFile |
| 399 |
|
| 400 |
|
| 401 |
def getExtraReposPyFileFromCmakeFile(inOptions, extraReposPythonOutFile, \ |
| 402 |
consoleOutputFile = None, verbose=False \ |
| 403 |
): |
| 404 |
extraReposFile = getExtraReposFilePath(inOptions) |
| 405 |
printConsoleOutputFile = False |
| 406 |
if not consoleOutputFile: |
| 407 |
# Need to send output to a file so that you can read it back in again and |
| 408 |
# then print it out using the 'print' statement. This is needed so that |
| 409 |
# the output shows up in both the STDOUT and the checkin-test.out log |
| 410 |
# files! |
| 411 |
consoleOutputFile = "TribitsGetExtraReposForCheckinTest.out" |
| 412 |
printConsoleOutputFile = True |
| 413 |
cmnd = "\""+inOptions.withCmake+"\""+ \ |
| 414 |
" -DSUPPRESS_PRINT_VAR_OUTPUT=TRUE" \ |
| 415 |
" -DPROJECT_SOURCE_DIR="+inOptions.srcDir+ \ |
| 416 |
" -DTRIBITS_BASE_DIR="+inOptions.tribitsDir+ \ |
| 417 |
" -DEXTRA_REPOS_FILE="+extraReposFile+ \ |
| 418 |
" -DENABLE_KNOWN_EXTERNAL_REPOS_TYPE="+inOptions.extraReposType+ \ |
| 419 |
" -DEXTRA_REPOS="+inOptions.extraRepos+ \ |
| 420 |
" -DEXTRA_REPOS_PYTHON_OUT_FILE="+extraReposPythonOutFile |
| 421 |
if inOptions.ignoreMissingExtraRepos: |
| 422 |
cmnd += " -DIGNORE_MISSING_EXTRA_REPOSITORIES=TRUE" |
| 423 |
cmnd += \ |
| 424 |
" -P "+inOptions.tribitsDir+"/ci_support/TribitsGetExtraReposForCheckinTest.cmake" |
| 425 |
try: |
| 426 |
echoRunSysCmnd(cmnd, throwExcept=True, timeCmnd=True, outFile=consoleOutputFile, \ |
| 427 |
verbose=verbose) |
| 428 |
finally: |
| 429 |
if printConsoleOutputFile: |
| 430 |
print("\n" + open(consoleOutputFile, 'r').read()) |
| 431 |
|
| 432 |
|
| 433 |
def translateExtraReposPyToDictGitRepo(extraReposPyDict): |
| 434 |
repoName = extraReposPyDict['NAME'] |
| 435 |
repoDir = extraReposPyDict['DIR'] |
| 436 |
repoType = extraReposPyDict['REPOTYPE'] |
| 437 |
repoHasPackages = (extraReposPyDict['HASPKGS'] == 'HASPACKAGES') |
| 438 |
repoPrePost = extraReposPyDict['PREPOST'] |
| 439 |
return GitRepo(repoName, repoDir, repoType, repoHasPackages, repoPrePost) |
| 440 |
|
| 441 |
|
| 442 |
class TribitsGitRepos: |
| 443 |
|
| 444 |
def __init__(self): |
| 445 |
self.reset() |
| 446 |
self.__insertMainRepo() |
| 447 |
self.__initFinalize() |
| 448 |
|
| 449 |
def initFromCommandlineArguments(self, inOptions, consoleOutputFile=None, verbose=True): |
| 450 |
|
| 451 |
self.reset() |
| 452 |
|
| 453 |
self.__insertMainRepo() |
| 454 |
|
| 455 |
if inOptions.extraRepos!="" and \ |
| 456 |
(inOptions.extraReposFile=="" or inOptions.extraReposType=="") \ |
| 457 |
: |
| 458 |
# Just use the listed set of extra repos with no checking |
| 459 |
for extraRepoName in inOptions.extraRepos.split(","): |
| 460 |
extraRepo = GitRepo(extraRepoName) |
| 461 |
self.__gitRepoList.append(extraRepo) |
| 462 |
elif inOptions.extraReposFile!="" and inOptions.extraReposType!="": |
| 463 |
# Read in the extra repos from file and assert or ignore missing repos, etc. |
| 464 |
extraReposPythonOutFile = getProjectExtraReposPythonOutFile(inOptions.projectName) |
| 465 |
getExtraReposPyFileFromCmakeFile(inOptions, extraReposPythonOutFile, \ |
| 466 |
consoleOutputFile=consoleOutputFile, verbose=verbose) |
| 467 |
extraReposPyTxt = readStrFromFile(extraReposPythonOutFile) |
| 468 |
extraReposPyList = eval(extraReposPyTxt) |
| 469 |
for extraRepoDict in extraReposPyList: |
| 470 |
extraRepo = translateExtraReposPyToDictGitRepo(extraRepoDict) |
| 471 |
self.__gitRepoList.append(extraRepo) |
| 472 |
|
| 473 |
self.__initFinalize() |
| 474 |
|
| 475 |
def gitRepoList(self): |
| 476 |
return self.__gitRepoList |
| 477 |
|
| 478 |
def tribitsPreRepoNamesList(self): |
| 479 |
return self.__tribitsPreRepoNamesList |
| 480 |
|
| 481 |
def numTribitsPreRepos(self): |
| 482 |
return len(self.__tribitsPreRepoNamesList) |
| 483 |
|
| 484 |
def tribitsExtraRepoNamesList(self): |
| 485 |
return self.__tribitsExtraRepoNamesList |
| 486 |
|
| 487 |
def numTribitsExtraRepos(self): |
| 488 |
return len(self.__tribitsExtraRepoNamesList) |
| 489 |
|
| 490 |
def tribitsAllExtraRepoNamesList(self): |
| 491 |
return self.__tribitsAllExtraRepoNamesList |
| 492 |
|
| 493 |
def numTribitsAllExtraRepos(self): |
| 494 |
return len(self.__tribitsAllExtraRepoNamesList) |
| 495 |
|
| 496 |
def __str__(self): |
| 497 |
strRep = "{\n" |
| 498 |
strRep += " gitRepoList = " + self.__printReposList(self.__gitRepoList) |
| 499 |
strRep += " tribitsPreRepoNamesList = "+str(self.__tribitsPreRepoNamesList)+"\n" |
| 500 |
strRep += " tribitsExtraRepoNamesList = "+str(self.__tribitsExtraRepoNamesList)+"\n" |
| 501 |
strRep += " tribitsAllExtraRepoNamesList = "+str(self.__tribitsAllExtraRepoNamesList)+"\n" |
| 502 |
strRep += " }\n" |
| 503 |
return strRep |
| 504 |
|
| 505 |
def reset(self): |
| 506 |
self.__gitRepoList = [] |
| 507 |
self.__tribitsPreRepoNamesList = [] |
| 508 |
self.__tribitsExtraRepoNamesList = [] |
| 509 |
self.__tribitsAllRepoNamesList = [] |
| 510 |
return self |
| 511 |
|
| 512 |
# Private |
| 513 |
|
| 514 |
def __insertMainRepo(self): |
| 515 |
mainRepo = GitRepo("") |
| 516 |
self.__gitRepoList.append(mainRepo) |
| 517 |
|
| 518 |
def __printReposList(self, reposList): |
| 519 |
strRep = "[\n" |
| 520 |
for gitRepo in reposList: |
| 521 |
strRep += (" " + str(gitRepo) + ",\n") |
| 522 |
strRep += " ]\n" |
| 523 |
return strRep |
| 524 |
|
| 525 |
def __initFinalize(self): |
| 526 |
self.__tribitsPreRepoNamesList = [] |
| 527 |
self.__tribitsExtraRepoNamesList = [] |
| 528 |
self.__tribitsAllExtraRepoNamesList = [] |
| 529 |
for gitRepo in self.__gitRepoList: |
| 530 |
if gitRepo.repoName and gitRepo.repoHasPackages: |
| 531 |
self.__tribitsAllExtraRepoNamesList.append(gitRepo.repoName) |
| 532 |
if gitRepo.repoPrePost == 'PRE': |
| 533 |
self.__tribitsPreRepoNamesList.append(gitRepo.repoName) |
| 534 |
else: |
| 535 |
self.__tribitsExtraRepoNamesList.append(gitRepo.repoName) |
| 536 |
|
| 537 |
|
| 538 |
def createAndGetProjectDependencies(inOptions, baseTestDir, tribitsGitRepos): |
| 539 |
|
| 540 |
if tribitsGitRepos.numTribitsPreRepos() > 0: |
| 541 |
print("\nPulling in packages from PRE extra repos: " + |
| 542 |
','.join(tribitsGitRepos.tribitsPreRepoNamesList()) + " ...") |
| 543 |
if tribitsGitRepos.numTribitsExtraRepos() > 0: |
| 544 |
print("\nPulling in packages from POST extra repos: " + |
| 545 |
','.join(tribitsGitRepos.tribitsExtraRepoNamesList()) + " ...") |
| 546 |
for gitRepo in tribitsGitRepos.gitRepoList(): |
| 547 |
assertGitRepoExists(inOptions, gitRepo) |
| 548 |
projectDepsXmlFile = baseTestDir+"/"\ |
| 549 |
+getProjectDependenciesXmlFileName(inOptions.projectName) |
| 550 |
if not inOptions.skipDepsUpdate: |
| 551 |
# There are extra repos so we need to build a new list of Project |
| 552 |
# packages to include the add-on packages. |
| 553 |
cmakeArgumentList = [ |
| 554 |
"cmake", |
| 555 |
"-DPROJECT_NAME=%s" % inOptions.projectName, |
| 556 |
cmakeScopedDefine(inOptions.projectName, "TRIBITS_DIR", inOptions.tribitsDir), |
| 557 |
"-DPROJECT_SOURCE_DIR="+inOptions.srcDir, |
| 558 |
cmakeScopedDefine(inOptions.projectName, "PRE_REPOSITORIES", "\""+\ |
| 559 |
';'.join(tribitsGitRepos.tribitsPreRepoNamesList())+"\""), |
| 560 |
cmakeScopedDefine(inOptions.projectName, "EXTRA_REPOSITORIES", "\""+\ |
| 561 |
';'.join(tribitsGitRepos.tribitsExtraRepoNamesList())+"\""), |
| 562 |
cmakeScopedDefine(inOptions.projectName, "DEPS_XML_OUTPUT_FILE", projectDepsXmlFile), |
| 563 |
"-P %s/ci_support/TribitsDumpDepsXmlScript.cmake" % inOptions.tribitsDir, |
| 564 |
] |
| 565 |
cmnd = ' '.join(cmakeArgumentList) |
| 566 |
echoRunSysCmnd(cmnd, |
| 567 |
workingDir=baseTestDir, |
| 568 |
outFile=baseTestDir+"/"\ |
| 569 |
+getProjectDependenciesXmlGenerateOutputFileName(inOptions.projectName), |
| 570 |
timeCmnd=True) |
| 571 |
else: |
| 572 |
print("\nSkipping update of dependencies XML file on request!") |
| 573 |
|
| 574 |
projectDepsXmlFileOverride = os.environ.get("CHECKIN_TEST_DEPS_XML_FILE_OVERRIDE") |
| 575 |
if projectDepsXmlFileOverride: |
| 576 |
print("\nprojectDepsXmlFileOverride=" + projectDepsXmlFileOverride) |
| 577 |
projectDepsXmlFile = projectDepsXmlFileOverride |
| 578 |
|
| 579 |
global projectDependenciesCache |
| 580 |
projectDependenciesCache = getProjectDependenciesFromXmlFile(projectDepsXmlFile) |
| 581 |
|
| 582 |
|
| 583 |
class RemoteRepoAndBranch: |
| 584 |
|
| 585 |
def __init__(self, remoteRepo, remoteBranch): |
| 586 |
self.remoteRepo = remoteRepo |
| 587 |
self.remoteBranch = remoteBranch |
| 588 |
|
| 589 |
def __str__(self): |
| 590 |
return "RemoteRepoAndBranch{repoRepo='"+str(self.remoteRepo)+"'" \ |
| 591 |
+", remoteBranch='"+str(self.remoteBranch)+"'" \ |
| 592 |
+"}" |
| 593 |
|
| 594 |
|
| 595 |
class RepoExtraRemotePulls: |
| 596 |
|
| 597 |
def __init__(self, gitRepo, remoteRepoAndBranchList): |
| 598 |
self.gitRepo = gitRepo |
| 599 |
self.remoteRepoAndBranchList = remoteRepoAndBranchList |
| 600 |
|
| 601 |
|
| 602 |
def getLocalRepoRemoteRepoAndBranchFromExtraPullArg(extraPullArg): |
| 603 |
extraPullArgArray = extraPullArg.split(':') |
| 604 |
localRepo = "" |
| 605 |
remoteRepo = "" |
| 606 |
remoteBranch = "" |
| 607 |
matchesAllRepos = False |
| 608 |
extraPullArgArray_len = len(extraPullArgArray) |
| 609 |
if extraPullArgArray_len == 3: |
| 610 |
localRepo = extraPullArgArray[0] |
| 611 |
remoteRepo = extraPullArgArray[1] |
| 612 |
remoteBranch = extraPullArgArray[2] |
| 613 |
elif extraPullArgArray_len == 2: |
| 614 |
remoteRepo = extraPullArgArray[0] |
| 615 |
remoteBranch = extraPullArgArray[1] |
| 616 |
matchesAllRepos = True |
| 617 |
else: |
| 618 |
raise ValueError( |
| 619 |
"Error, the --extra-pull-from arg '"+extraPullArg+"' is not of the form" \ |
| 620 |
+ " <localreponame>:<remoterepo>:<remotebranch>!") |
| 621 |
if remoteRepo == "": |
| 622 |
raise ValueError( |
| 623 |
"Error, the --extra-pull-from arg '"+extraPullArg+"' has an empty <remoterepo>" \ |
| 624 |
+ " field in <localreponame>:<remoterepo>:<remotebranch>!") |
| 625 |
elif remoteBranch == "": |
| 626 |
raise ValueError( |
| 627 |
"Error, the --extra-pull-from arg '"+extraPullArg+"' has an empty <remotebranch>" \ |
| 628 |
+ " field in <localreponame>:<remoterepo>:<remotebranch>!") |
| 629 |
return (localRepo, remoteRepo, remoteBranch, matchesAllRepos) |
| 630 |
|
| 631 |
|
| 632 |
def matchExtraRepoLocalRepoMatchLocalRepo(repoName, extraRepoLocalRepoName): |
| 633 |
if repoName == extraRepoLocalRepoName: |
| 634 |
return True |
| 635 |
elif repoName == "" and extraRepoLocalRepoName == "BASE_REPO": |
| 636 |
return True |
| 637 |
return False |
| 638 |
|
| 639 |
|
| 640 |
def parseExtraPullFromArgs(gitRepoList, extraPullFromArgs): |
| 641 |
# Initialize an empty set of extra pulls |
| 642 |
repoExtraRemotePullsList = [] |
| 643 |
for gitRepo in gitRepoList: |
| 644 |
repoExtraRemotePullsList.append( |
| 645 |
RepoExtraRemotePulls(gitRepo, [])) |
| 646 |
# Parse the arguments and fill in the remote repos and branches |
| 647 |
if extraPullFromArgs: |
| 648 |
for extraPullFromArg in extraPullFromArgs.split(","): |
| 649 |
(localRepo, remoteRepo, remoteBranch, matchesAllRepos) = \ |
| 650 |
getLocalRepoRemoteRepoAndBranchFromExtraPullArg(extraPullFromArg) |
| 651 |
if matchesAllRepos: |
| 652 |
for repoExtraRemotePulls in repoExtraRemotePullsList: |
| 653 |
repoExtraRemotePulls.remoteRepoAndBranchList.append( |
| 654 |
RemoteRepoAndBranch(remoteRepo, remoteBranch) ) |
| 655 |
else: |
| 656 |
for repoExtraRemotePulls in repoExtraRemotePullsList: |
| 657 |
if repoExtraRemotePulls.gitRepo.repoName == localRepo: |
| 658 |
repoExtraRemotePulls.remoteRepoAndBranchList.append( |
| 659 |
RemoteRepoAndBranch(remoteRepo, remoteBranch) ) |
| 660 |
return repoExtraRemotePullsList |
| 661 |
|
| 662 |
|
| 663 |
class BuildTestCase: |
| 664 |
def __init__(self, name, runBuildTestCase, validPackageTypesList, |
| 665 |
isDefaultBuild, skipCaseIfNoChangeFromDefaultEnables, |
| 666 |
extraCMakeOptions, buildIdx \ |
| 667 |
): |
| 668 |
self.name = name |
| 669 |
self.runBuildTestCase = runBuildTestCase |
| 670 |
self.validPackageTypesList = validPackageTypesList |
| 671 |
self.isDefaultBuild = isDefaultBuild |
| 672 |
self.skipCaseIfNoChangeFromDefaultEnables = skipCaseIfNoChangeFromDefaultEnables |
| 673 |
self.extraCMakeOptions = extraCMakeOptions |
| 674 |
self.skippedConfigureDueToNoEnables = False |
| 675 |
self.buildIdx = buildIdx |
| 676 |
self.timings = Timings() |
| 677 |
|
| 678 |
|
| 679 |
def setBuildTestCaseInList(buildTestCaseList_inout, |
| 680 |
name, runBuildTestCase, validPackageTypesList, isDefaultBuild, |
| 681 |
skipCaseIfNoChangeFromDefaultEnables, extraCMakeOptions \ |
| 682 |
): |
| 683 |
buildTestCaseList_inout.append( |
| 684 |
BuildTestCase(name, runBuildTestCase, validPackageTypesList, isDefaultBuild, |
| 685 |
skipCaseIfNoChangeFromDefaultEnables, extraCMakeOptions, |
| 686 |
len(buildTestCaseList_inout) ) ) |
| 687 |
|
| 688 |
|
| 689 |
def writeDefaultCommonConfigFile(): |
| 690 |
|
| 691 |
commonConfigFileName = getCommonConfigFileName() |
| 692 |
|
| 693 |
if os.path.exists(commonConfigFileName): |
| 694 |
|
| 695 |
print("\nThe file " + commonConfigFileName + " already exists!") |
| 696 |
|
| 697 |
else: |
| 698 |
|
| 699 |
print("\nCreating a default skeleton file " + commonConfigFileName + " ...") |
| 700 |
|
| 701 |
commonConfigFileStr = \ |
| 702 |
"# Fill in the minimum CMake options that are needed to build and link\n" \ |
| 703 |
"# that are common to all builds such as the following:\n" \ |
| 704 |
"#\n" \ |
| 705 |
"#-DCMAKE_VERBOSE_MAKEFILE=ON\n" \ |
| 706 |
"#-DBUILD_SHARED_LIBS=ON\n" \ |
| 707 |
"#\n" \ |
| 708 |
"# NOTE: Please do not add any options here that would select what packages\n" \ |
| 709 |
"# get enabled or disabled.\n" |
| 710 |
|
| 711 |
writeStrToFile(commonConfigFileName, commonConfigFileStr) |
| 712 |
|
| 713 |
|
| 714 |
def writeDefaultBuildSpecificConfigFile(buildTestCaseName): |
| 715 |
|
| 716 |
serialOrMpi = buildTestCaseName.split('_')[0] |
| 717 |
|
| 718 |
buildSpecificConfigFileName = getBuildSpecificConfigFileName(buildTestCaseName) |
| 719 |
|
| 720 |
if os.path.exists(buildSpecificConfigFileName): |
| 721 |
|
| 722 |
print("\nThe file " + buildSpecificConfigFileName + " already exists!") |
| 723 |
|
| 724 |
else: |
| 725 |
|
| 726 |
# ToDo: Get rid of these! These are too specific! |
| 727 |
|
| 728 |
print("\nCreating a default skeleton file " + buildSpecificConfigFileName + |
| 729 |
" ...") |
| 730 |
|
| 731 |
buildSpecificConfigFileStr = \ |
| 732 |
"# Fill in the minimum CMake options that are needed to build and link\n" \ |
| 733 |
"# that are specific to the "+serialOrMpi+" build such as:\n" \ |
| 734 |
"#\n" \ |
| 735 |
"#-DBUILD_SHARED_LIBS=ON\n" \ |
| 736 |
"#\n" \ |
| 737 |
"# NOTE: Please do not add any options here that would change what packages\n" \ |
| 738 |
"# or TPLs get enabled or disabled.\n" |
| 739 |
|
| 740 |
writeStrToFile(buildSpecificConfigFileName, buildSpecificConfigFileStr) |
| 741 |
|
| 742 |
|
| 743 |
def assertNoIllegalEnables(projectName, fileName, cmakeOption): |
| 744 |
|
| 745 |
reTPlEnable = re.compile(r"-DTPL_ENABLE_.+") |
| 746 |
reProjectEnableOn = re.compile(r"-D%s_ENABLE_[a-zA-Z]+.+=ON" % projectName) |
| 747 |
|
| 748 |
success = True |
| 749 |
if reTPlEnable.match(cmakeOption): |
| 750 |
print(" ERROR: Illegal TPL enable " + cmakeOption + " in " + fileName+"!") |
| 751 |
success = False |
| 752 |
elif reProjectEnableOn.match(cmakeOption): |
| 753 |
print(" ERROR: Illegal enable " + cmakeOption + " in " + fileName + "!") |
| 754 |
success = False |
| 755 |
return success |
| 756 |
|
| 757 |
|
| 758 |
def readAndAppendCMakeOptions( |
| 759 |
projectName, |
| 760 |
fileName, |
| 761 |
cmakeOptions_inout, |
| 762 |
assertNoIllegalEnablesBool): |
| 763 |
|
| 764 |
success = True |
| 765 |
|
| 766 |
if not os.path.exists(fileName): |
| 767 |
return |
| 768 |
|
| 769 |
print("\nAppending options from " + fileName + ":") |
| 770 |
|
| 771 |
cmakeOptionsFile = open(fileName, 'r') |
| 772 |
|
| 773 |
for line in cmakeOptionsFile: |
| 774 |
if line[0] != '#': |
| 775 |
cmakeOption = line.strip() |
| 776 |
if cmakeOption == "": continue |
| 777 |
print(" Appending: " + cmakeOption) |
| 778 |
if assertNoIllegalEnablesBool: |
| 779 |
if not assertNoIllegalEnables(projectName, fileName, cmakeOption): |
| 780 |
success = False |
| 781 |
cmakeOptions_inout.append(cmakeOption) |
| 782 |
|
| 783 |
return success |
| 784 |
|
| 785 |
|
| 786 |
reModifiedFiles = re.compile(r"^[MAD]\t(.+)$") |
| 787 |
|
| 788 |
|
| 789 |
def getCurrentDiffOutput(gitRepo, inOptions, baseTestDir): |
| 790 |
if gitRepo.gitRepoStats.numCommitsInt() > 0: |
| 791 |
echoRunSysCmnd( |
| 792 |
inOptions.git+" diff --name-status "+gitRepo.gitRepoStats.trackingBranch, |
| 793 |
workingDir=getGitRepoDir(inOptions.srcDir, gitRepo.repoDir), |
| 794 |
outFile=os.path.join(baseTestDir, getModifiedFilesOutputFileName(gitRepo.repoName)), |
| 795 |
timeCmnd=True |
| 796 |
) |
| 797 |
|
| 798 |
|
| 799 |
def repoHasModifiedFiles(gitRepo, baseTestDir): |
| 800 |
if gitRepo.gitRepoStats.numCommitsInt() > 0: |
| 801 |
modifiedFilesStr = readStrFromFile( |
| 802 |
baseTestDir+"/"+getModifiedFilesOutputFileName(gitRepo.repoName)) |
| 803 |
if modifiedFilesStr: |
| 804 |
return True |
| 805 |
return False |
| 806 |
|
| 807 |
|
| 808 |
def getCurrentDiffOutputAndLogModified(inOptions, gitRepo, baseTestDir): |
| 809 |
getCurrentDiffOutput(gitRepo, inOptions, baseTestDir) |
| 810 |
gitRepo.hasChanges = repoHasModifiedFiles(gitRepo, baseTestDir) |
| 811 |
if gitRepo.hasChanges: |
| 812 |
print("\n ==> '" + gitRepo.repoName + "': Has modified files!") |
| 813 |
else: |
| 814 |
print("\n ==> '" + gitRepo.repoName + "': Does *not* have any modified " + |
| 815 |
"files!") |
| 816 |
|
| 817 |
|
| 818 |
def extractPackageEnablesFromChangeStatus(changedFileDiffOutputStr, inOptions_inout, |
| 819 |
gitRepo, enablePackagesList_inout, verbose=True, |
| 820 |
projectDependenciesLocal=None, projectChangeLogic=DefaultProjectCiFileChangeLogic() ) \ |
| 821 |
: |
| 822 |
|
| 823 |
if not projectDependenciesLocal: |
| 824 |
projectDependenciesLocal = getDefaultProjectDependenices() |
| 825 |
|
| 826 |
modifiedFilesList = extractFilesListMatchingPattern( |
| 827 |
changedFileDiffOutputStr.splitlines(), reModifiedFiles ) |
| 828 |
|
| 829 |
for modifiedFileFullPath in modifiedFilesList: |
| 830 |
|
| 831 |
# Only look for global rebuild files in the master repo (not in extra repos) |
| 832 |
if gitRepo.repoName == '' and \ |
| 833 |
projectChangeLogic.isGlobalBuildFileRequiringGlobalRebuild(modifiedFileFullPath) \ |
| 834 |
: |
| 835 |
if inOptions_inout.enableAllPackages == 'auto': |
| 836 |
if verbose: |
| 837 |
print("\nModified file: '" + modifiedFileFullPath + "'\n" + |
| 838 |
" => Enabling all " + inOptions_inout.projectName + |
| 839 |
" packages!") |
| 840 |
inOptions_inout.enableAllPackages = 'on' |
| 841 |
|
| 842 |
if gitRepo.repoDir: |
| 843 |
modifiedFileFullPath = gitRepo.repoDir+"/"+modifiedFileFullPath |
| 844 |
#print("\nmodifiedFileFullPath =", modifiedFileFullPath) |
| 845 |
|
| 846 |
packageName = getPackageNameFromPath(projectDependenciesLocal, modifiedFileFullPath) |
| 847 |
if packageName and findInSequence(enablePackagesList_inout, packageName) == -1: |
| 848 |
if verbose: |
| 849 |
print("\nModified file: '" + modifiedFileFullPath + "'\n" + |
| 850 |
" => Enabling '" + packageName + "'!") |
| 851 |
enablePackagesList_inout.append(packageName) |
| 852 |
|
| 853 |
|
| 854 |
def createConfigureFile(cmakeOptions, baseCmnd, srcDir, configFileName): |
| 855 |
|
| 856 |
doConfigStr = "" |
| 857 |
|
| 858 |
doConfigStr += \ |
| 859 |
baseCmnd+ " \\\n" |
| 860 |
|
| 861 |
for opt in cmakeOptions: |
| 862 |
doConfigStr += opt + " \\\n" |
| 863 |
|
| 864 |
doConfigStr += \ |
| 865 |
"\"$@\"" |
| 866 |
|
| 867 |
if srcDir: |
| 868 |
doConfigStr += " \\\n"+srcDir |
| 869 |
|
| 870 |
doConfigStr += "\n" |
| 871 |
|
| 872 |
writeStrToFile(configFileName, doConfigStr) |
| 873 |
echoRunSysCmnd('chmod a+x '+configFileName) |
| 874 |
|
| 875 |
|
| 876 |
def formatMinutesStr(timeInMinutes): |
| 877 |
return ("%.2f" % timeInMinutes) + " min" |
| 878 |
|
| 879 |
|
| 880 |
def getStageStatus(stageName, stageDoBool, stagePassed, stageTiming): |
| 881 |
stageStatusStr = stageName + ": " |
| 882 |
if stageDoBool: |
| 883 |
if stagePassed: |
| 884 |
stageStatusStr += "Passed" |
| 885 |
else: |
| 886 |
stageStatusStr += "FAILED" |
| 887 |
stageStatusStr += " ("+formatMinutesStr(stageTiming)+")" |
| 888 |
else: |
| 889 |
stageStatusStr += "Not Performed" |
| 890 |
stageStatusStr += "\n" |
| 891 |
return stageStatusStr |
| 892 |
|
| 893 |
|
| 894 |
def getTotalTimeBeginStr(buildTestCaseName): |
| 895 |
return "Total time for "+buildTestCaseName |
| 896 |
|
| 897 |
|
| 898 |
def getTotalTimeLineStr(buildTestCaseName, timeInMin): |
| 899 |
return getTotalTimeBeginStr(buildTestCaseName)+" = "+formatMinutesStr(timeInMin) |
| 900 |
|
| 901 |
|
| 902 |
def getTimeInMinFromTotalTimeLine(buildTestCaseName, totalTimeLine): |
| 903 |
if not totalTimeLine: |
| 904 |
return -1.0 |
| 905 |
m = re.match(getTotalTimeBeginStr(buildTestCaseName)+r" = (.+) min", totalTimeLine) |
| 906 |
if m and m.groups(): |
| 907 |
return float(m.groups()[0]) |
| 908 |
else: |
| 909 |
return -1.0 |
| 910 |
|
| 911 |
|
| 912 |
reCtestFailTotal = re.compile(r".+, ([0-9]+) tests failed out of ([0-9]+)") |
| 913 |
|
| 914 |
|
| 915 |
def analyzeResultsSendEmail(inOptions, buildTestCase, |
| 916 |
enabledPackagesList, cmakeOptions, startingTime, timings ) \ |
| 917 |
: |
| 918 |
|
| 919 |
buildTestCaseName = buildTestCase.name |
| 920 |
|
| 921 |
print("") |
| 922 |
print("E.1) Determine what passed and failed ...") |
| 923 |
print("") |
| 924 |
|
| 925 |
success = False |
| 926 |
|
| 927 |
# Determine if the pull passed |
| 928 |
|
| 929 |
pullPassed = None |
| 930 |
pullOutputExists = False |
| 931 |
|
| 932 |
if inOptions.doPull: |
| 933 |
|
| 934 |
if os.path.exists("../"+getInitialPullOutputFileName("")): |
| 935 |
pullOutputExists = True |
| 936 |
|
| 937 |
if os.path.exists("../"+getInitialPullSuccessFileName()): |
| 938 |
print("\nThe pull passed!\n") |
| 939 |
pullPassed = True |
| 940 |
elif pullOutputExists: |
| 941 |
print("\nThe pull FAILED!\n") |
| 942 |
pullPassed = False |
| 943 |
else: |
| 944 |
print("\nThe pull was never attempted!\n") |
| 945 |
pullPassed = False |
| 946 |
|
| 947 |
else: |
| 948 |
|
| 949 |
print("\nThe pull step was not performed!\n") |
| 950 |
|
| 951 |
# Determine if the configured passed |
| 952 |
|
| 953 |
configurePassed = None |
| 954 |
configureOutputExists = False |
| 955 |
|
| 956 |
if inOptions.doConfigure: |
| 957 |
|
| 958 |
if os.path.exists(getConfigureOutputFileName()): |
| 959 |
configureOutputExists = True |
| 960 |
|
| 961 |
if os.path.exists(getConfigureSuccessFileName()): |
| 962 |
print("\nThe configure passed!\n") |
| 963 |
configurePassed = True |
| 964 |
elif configureOutputExists: |
| 965 |
print("\nThe configure FAILED!\n") |
| 966 |
configurePassed = False |
| 967 |
else: |
| 968 |
print("\nThe configure was never attempted!\n") |
| 969 |
configurePassed = False |
| 970 |
|
| 971 |
else: |
| 972 |
|
| 973 |
print("\nThe configure step was not performed!\n") |
| 974 |
|
| 975 |
# Determine if the build passed |
| 976 |
|
| 977 |
buildPassed = None |
| 978 |
buildOutputExists = False |
| 979 |
|
| 980 |
if inOptions.doBuild: |
| 981 |
|
| 982 |
if os.path.exists(getBuildOutputFileName()): |
| 983 |
buildOutputExists = True |
| 984 |
|
| 985 |
if os.path.exists(getBuildSuccessFileName()): |
| 986 |
print("\nThe build passed!\n") |
| 987 |
buildPassed = True |
| 988 |
elif buildOutputExists: |
| 989 |
print("\nThe build FAILED!\n") |
| 990 |
buildPassed = False |
| 991 |
else: |
| 992 |
print("\nThe build was never attempted!\n") |
| 993 |
buildPassed = False |
| 994 |
|
| 995 |
else: |
| 996 |
|
| 997 |
print("\nThe build step was not performed!\n") |
| 998 |
|
| 999 |
# Determine if the tests passed |
| 1000 |
|
| 1001 |
testsPassed = None |
| 1002 |
testOutputExists = False |
| 1003 |
|
| 1004 |
if inOptions.doTest: |
| 1005 |
|
| 1006 |
if os.path.exists(getTestOutputFileName()): |
| 1007 |
testOutputExists = True |
| 1008 |
|
| 1009 |
if not testOutputExists: |
| 1010 |
|
| 1011 |
print("\nThe tests were never even run!\n") |
| 1012 |
testsPassed = False |
| 1013 |
|
| 1014 |
else: # testOutputExists |
| 1015 |
|
| 1016 |
testResultsLine = getCmndOutput("grep 'tests failed out of' "+getTestOutputFileName(), |
| 1017 |
True, False) |
| 1018 |
|
| 1019 |
print("testResultsLine = '" + testResultsLine + "'") |
| 1020 |
|
| 1021 |
reCtestFailTotalMatch = reCtestFailTotal.match(testResultsLine) |
| 1022 |
|
| 1023 |
if reCtestFailTotalMatch: |
| 1024 |
numFailedTests = int(reCtestFailTotalMatch.group(1)) |
| 1025 |
numTotalTests = int(reCtestFailTotalMatch.group(2)) |
| 1026 |
numPassedTests = numTotalTests - numFailedTests |
| 1027 |
else: |
| 1028 |
numTotalTests = None |
| 1029 |
numPassedTests = None |
| 1030 |
testsPassed = False |
| 1031 |
|
| 1032 |
if not os.path.exists(getTestSuccessFileName()): |
| 1033 |
print("\nThe tests did not run and pass!\n") |
| 1034 |
testsPassed = False |
| 1035 |
elif numTotalTests == None: |
| 1036 |
print("\nCTest was invoked but no tests were run!\n") |
| 1037 |
testsPassed = False |
| 1038 |
elif numTotalTests == numPassedTests: |
| 1039 |
print("\nAll of the tests ran passed!\n") |
| 1040 |
testsPassed = True |
| 1041 |
else: |
| 1042 |
print("\n" + str(numTotalTests-numPassedTests) + " tests failed!\n") |
| 1043 |
testsPassed = False |
| 1044 |
|
| 1045 |
else: |
| 1046 |
|
| 1047 |
print("\nRunning the tests was not performed!\n") |
| 1048 |
|
| 1049 |
print("") |
| 1050 |
print("E.2) Construct the email message ...") |
| 1051 |
print("") |
| 1052 |
|
| 1053 |
# 2.a) Construct the subject line |
| 1054 |
|
| 1055 |
overallPassed = None |
| 1056 |
buildCaseStatus = "" |
| 1057 |
selectedFinalStatus = False |
| 1058 |
|
| 1059 |
if inOptions.doTest and not selectedFinalStatus: |
| 1060 |
if testOutputExists: |
| 1061 |
if numTotalTests: |
| 1062 |
buildCaseStatus += "passed="+str(numPassedTests)+",notpassed="+str(numFailedTests) |
| 1063 |
else: |
| 1064 |
buildCaseStatus += "no tests run" |
| 1065 |
if testsPassed and numTotalTests > 0: |
| 1066 |
overallPassed = True |
| 1067 |
else: |
| 1068 |
overallPassed = False |
| 1069 |
selectedFinalStatus = True |
| 1070 |
elif not inOptions.doBuild and not buildOutputExists: |
| 1071 |
buildCaseStatus += "no active build exists" |
| 1072 |
overallPassed = False |
| 1073 |
selectedFinalStatus = True |
| 1074 |
|
| 1075 |
if inOptions.doBuild and not selectedFinalStatus: |
| 1076 |
if buildPassed: |
| 1077 |
buildCaseStatus += "build-only passed" |
| 1078 |
overallPassed = True |
| 1079 |
selectedFinalStatus = True |
| 1080 |
elif buildOutputExists: |
| 1081 |
buildCaseStatus += "build failed" |
| 1082 |
overallPassed = False |
| 1083 |
selectedFinalStatus = True |
| 1084 |
|
| 1085 |
if inOptions.doConfigure and not selectedFinalStatus: |
| 1086 |
if configurePassed: |
| 1087 |
buildCaseStatus += "configure-only passed" |
| 1088 |
overallPassed = True |
| 1089 |
selectedFinalStatus = True |
| 1090 |
elif buildTestCase.skippedConfigureDueToNoEnables: |
| 1091 |
buildCaseStatus += "skipped configure, build, test due to no enabled packages" |
| 1092 |
overallPassed = True |
| 1093 |
selectedFinalStatus = True |
| 1094 |
elif configureOutputExists: |
| 1095 |
buildCaseStatus += "configure failed" |
| 1096 |
overallPassed = False |
| 1097 |
selectedFinalStatus = True |
| 1098 |
else: |
| 1099 |
buildCaseStatus += "pre-configure failed" |
| 1100 |
overallPassed = False |
| 1101 |
selectedFinalStatus = True |
| 1102 |
|
| 1103 |
if inOptions.doPull and not selectedFinalStatus: |
| 1104 |
if pullPassed: |
| 1105 |
buildCaseStatus += "pull-only passed" |
| 1106 |
overallPassed = True |
| 1107 |
selectedFinalStatus = True |
| 1108 |
elif pullOutputExists: |
| 1109 |
buildCaseStatus += "pull FAILED" |
| 1110 |
overallPassed = False |
| 1111 |
selectedFinalStatus = True |
| 1112 |
|
| 1113 |
if not selectedFinalStatus: |
| 1114 |
raise Exception("Error, final pass/fail status not found!") |
| 1115 |
|
| 1116 |
subjectLine = "%s/%s: %s" % (inOptions.projectName, buildTestCaseName, buildCaseStatus) |
| 1117 |
if overallPassed: |
| 1118 |
subjectLine = "passed: " + subjectLine |
| 1119 |
else: |
| 1120 |
subjectLine = "FAILED: " + subjectLine |
| 1121 |
|
| 1122 |
print("\nsubjectLine = '" + subjectLine + "'\n") |
| 1123 |
|
| 1124 |
success = overallPassed |
| 1125 |
|
| 1126 |
# 2.b) Construct the email body |
| 1127 |
|
| 1128 |
emailBody = subjectLine + "\n\n" |
| 1129 |
|
| 1130 |
emailBody += getCmndOutput("date", True) + "\n\n" |
| 1131 |
|
| 1132 |
emailBody += getEnableStatusList(inOptions, enabledPackagesList) |
| 1133 |
emailBody += "Hostname: " + getHostname() + "\n" |
| 1134 |
emailBody += "Source Dir: " + inOptions.srcDir + "\n" |
| 1135 |
emailBody += "Build Dir: " + os.getcwd() + "\n" |
| 1136 |
emailBody += "\nCMake Cache Variables: " + ' '.join(cmakeOptions) + "\n" |
| 1137 |
if inOptions.extraCmakeOptions: |
| 1138 |
emailBody += "Extra CMake Options: " + inOptions.extraCmakeOptions + "\n" |
| 1139 |
if inOptions.makeOptions: |
| 1140 |
emailBody += "Make Options: " + inOptions.makeOptions + "\n" |
| 1141 |
if inOptions.ctestOptions: |
| 1142 |
emailBody += "CTest Options: " + inOptions.ctestOptions + "\n" |
| 1143 |
emailBody += "\n" |
| 1144 |
emailBody += getStageStatus("Pull", inOptions.doPull, pullPassed, timings.pull) |
| 1145 |
emailBody += getStageStatus("Configure", inOptions.doConfigure, configurePassed, timings.configure) |
| 1146 |
emailBody += getStageStatus("Build", inOptions.doBuild, buildPassed, timings.build) |
| 1147 |
emailBody += getStageStatus("Test", inOptions.doTest, testsPassed, timings.test) |
| 1148 |
emailBody += "\n" |
| 1149 |
|
| 1150 |
if inOptions.doTest and testOutputExists and numTotalTests: |
| 1151 |
|
| 1152 |
fullCTestOutput = readStrFromFile(getTestOutputFileName()) |
| 1153 |
if inOptions.showAllTests: |
| 1154 |
emailBody += fullCTestOutput |
| 1155 |
else: |
| 1156 |
emailBody += extractLinesAfterRegex(fullCTestOutput, r".*\% tests passed.*") |
| 1157 |
|
| 1158 |
else: |
| 1159 |
|
| 1160 |
emailBody += "\n***\n*** WARNING: There are no test results!\n***\n\n" |
| 1161 |
|
| 1162 |
endingTime = time.time() |
| 1163 |
totalTime = (endingTime - startingTime) / 60.0 |
| 1164 |
|
| 1165 |
emailBody += "\n"+getTotalTimeLineStr(buildTestCaseName, totalTime)+"\n" |
| 1166 |
|
| 1167 |
#print("emailBody:\n\n\n\n", emailBody, "\n\n\n\n") |
| 1168 |
|
| 1169 |
writeStrToFile(getEmailBodyFileName(), emailBody) |
| 1170 |
|
| 1171 |
if overallPassed: |
| 1172 |
echoRunSysCmnd("touch "+getEmailSuccessFileName()) |
| 1173 |
|
| 1174 |
print("") |
| 1175 |
print("E.3) Send the email message ...") |
| 1176 |
print("") |
| 1177 |
|
| 1178 |
if inOptions.sendEmailTo and buildTestCase.skippedConfigureDueToNoEnables \ |
| 1179 |
and inOptions.abortGracefullyIfNoEnables \ |
| 1180 |
: |
| 1181 |
|
| 1182 |
print(buildTestCaseName + ": Skipping sending build/test case email " + |
| 1183 |
"because there were no enables and --abort-gracefully-if-no-" + |
| 1184 |
"enables was set!") |
| 1185 |
|
| 1186 |
elif inOptions.sendEmailTo and inOptions.sendBuildCaseEmail=="only-on-failure" \ |
| 1187 |
and overallPassed \ |
| 1188 |
: |
| 1189 |
|
| 1190 |
print(buildTestCaseName + ": Skipping sending build/test case email " + |
| 1191 |
"because everything passed and --send-build-case-email=only-on-" |
| 1192 |
"failure was set!") |
| 1193 |
|
| 1194 |
elif inOptions.sendEmailTo and inOptions.sendBuildCaseEmail=="never" \ |
| 1195 |
: |
| 1196 |
|
| 1197 |
print(buildTestCaseName + ": Skipping sending build/test case email " + |
| 1198 |
"because everything passed and --send-build-case-email=never was " + |
| 1199 |
"set!") |
| 1200 |
|
| 1201 |
elif inOptions.sendEmailTo and inOptions.sendEmailOnlyOnFailure and success: |
| 1202 |
|
| 1203 |
print(buildTestCaseName + ": Skipping sending build/test case email " + |
| 1204 |
"because it passed and --send-email-only-on-failure was set!") |
| 1205 |
|
| 1206 |
elif inOptions.sendEmailTo and buildTestCase.skippedConfigureDueToNoEnables \ |
| 1207 |
and not inOptions.skipCaseSendEmail \ |
| 1208 |
: |
| 1209 |
|
| 1210 |
print("\nSkipping sending final status email for " + buildTestCase.name + |
| 1211 |
" because it had no packages enabled and --skip-case-no-email was " + |
| 1212 |
"set!") |
| 1213 |
|
| 1214 |
elif inOptions.sendEmailTo: |
| 1215 |
|
| 1216 |
emailAddresses = getEmailAddressesSpaceString(inOptions.sendEmailTo) |
| 1217 |
echoRunSysCmnd("mailx -s \""+subjectLine+"\" "+emailAddresses+" < "+getEmailBodyFileName()) |
| 1218 |
|
| 1219 |
else: |
| 1220 |
|
| 1221 |
print("Not sending email because no email addresses were given!") |
| 1222 |
|
| 1223 |
# 3) Return final result |
| 1224 |
|
| 1225 |
return success |
| 1226 |
|
| 1227 |
|
| 1228 |
def getBuildTestCaseSummary(testCaseName, trimDown = True): |
| 1229 |
# Get the email file |
| 1230 |
absEmailBodyFileName = testCaseName+"/"+getEmailBodyFileName() |
| 1231 |
if os.path.exists(absEmailBodyFileName): |
| 1232 |
testCaseEmailStrArray = open(absEmailBodyFileName, 'r').readlines() |
| 1233 |
else: |
| 1234 |
testCaseEmailStrArray = None |
| 1235 |
# Get the first line (which is the summary) |
| 1236 |
testSummaryLine = None |
| 1237 |
if testCaseEmailStrArray: |
| 1238 |
summaryLine = testCaseEmailStrArray[0].strip() |
| 1239 |
if trimDown: |
| 1240 |
summaryLineArray = summaryLine.split(":") |
| 1241 |
testSummaryLine = summaryLineArray[0].strip() + ": " + summaryLineArray[2].strip() |
| 1242 |
else: |
| 1243 |
testSummaryLine = summaryLine |
| 1244 |
else: |
| 1245 |
testSummaryLine = \ |
| 1246 |
"Error, The build/test was never completed!" \ |
| 1247 |
" (the file '"+absEmailBodyFileName+"' does not exist.)" |
| 1248 |
return testSummaryLine |
| 1249 |
|
| 1250 |
|
| 1251 |
def getTestCaseEmailSummary(testCaseName, testCaseNum): |
| 1252 |
# Get the email file |
| 1253 |
absEmailBodyFileName = testCaseName+"/"+getEmailBodyFileName() |
| 1254 |
if os.path.exists(absEmailBodyFileName): |
| 1255 |
testCaseEmailStrArray = open(absEmailBodyFileName, 'r').readlines() |
| 1256 |
else: |
| 1257 |
testCaseEmailStrArray = None |
| 1258 |
# Write the entry |
| 1259 |
testCaseHeader = str(testCaseNum)+") "+testCaseName+" Results:" |
| 1260 |
summaryEmailSectionStr = \ |
| 1261 |
"\n"+testCaseHeader+ \ |
| 1262 |
"\n"+getStrUnderlineStr(len(testCaseHeader))+"\n" \ |
| 1263 |
"\n" |
| 1264 |
if testCaseEmailStrArray: |
| 1265 |
for line in testCaseEmailStrArray: |
| 1266 |
summaryEmailSectionStr += " " + line |
| 1267 |
summaryEmailSectionStr += "\n" |
| 1268 |
else: |
| 1269 |
summaryEmailSectionStr += \ |
| 1270 |
"Error, The build/test was never completed!" \ |
| 1271 |
" (the file '"+absEmailBodyFileName+"' does not exist.)\n" |
| 1272 |
return summaryEmailSectionStr |
| 1273 |
|
| 1274 |
|
| 1275 |
def getSummaryEmailSectionStr(inOptions, buildTestCaseList): |
| 1276 |
summaryEmailSectionStr = "" |
| 1277 |
for buildTestCase in buildTestCaseList: |
| 1278 |
if buildTestCase.runBuildTestCase and not buildTestCase.skippedConfigureDueToNoEnables: |
| 1279 |
summaryEmailSectionStr += \ |
| 1280 |
getTestCaseEmailSummary(buildTestCase.name, buildTestCase.buildIdx) |
| 1281 |
return summaryEmailSectionStr |
| 1282 |
|
| 1283 |
|
| 1284 |
def cmakeScopedDefine(projectName, name, value): |
| 1285 |
""" |
| 1286 |
Formats a CMake -D<projectName>_<name>=<value> argument. |
| 1287 |
""" |
| 1288 |
return '-D%s_%s=%s' % (projectName, name, value) |
| 1289 |
|
| 1290 |
|
| 1291 |
def getEnablesLists(inOptions, validPackageTypesList, isDefaultBuild, |
| 1292 |
skipCaseIfNoChangeFromDefaultEnables, tribitsGitRepos, |
| 1293 |
baseTestDir, verbose \ |
| 1294 |
): |
| 1295 |
|
| 1296 |
projectName = inOptions.projectName |
| 1297 |
cmakePkgOptions = [] |
| 1298 |
enablePackagesList = [] |
| 1299 |
gitRepoList = tribitsGitRepos.gitRepoList() |
| 1300 |
projectChangeLogic=getProjectCiFileChangeLogic(inOptions.srcDir) |
| 1301 |
|
| 1302 |
enableAllPackages = False |
| 1303 |
|
| 1304 |
if inOptions.enableAllPackages == "on": |
| 1305 |
if verbose: |
| 1306 |
print("\nEnabling all packages on request since " + |
| 1307 |
"--enable-all-packages=on! ...") |
| 1308 |
print("\nSkipping detection of changed packages since " + |
| 1309 |
"--enable-all-packages=on ...") |
| 1310 |
enableAllPackages = True |
| 1311 |
elif inOptions.enablePackages: |
| 1312 |
if verbose: |
| 1313 |
print("\nEnabling only the explicitly specified packages '" + |
| 1314 |
inOptions.enablePackages + "' ...") |
| 1315 |
enablePackagesList = inOptions.enablePackages.split(',') |
| 1316 |
else: |
| 1317 |
for gitRepo in gitRepoList: |
| 1318 |
diffOutFileName = baseTestDir+"/"+getModifiedFilesOutputFileName(gitRepo.repoName) |
| 1319 |
if verbose: |
| 1320 |
print("\nDetermining the set of packages to enable by examining " + |
| 1321 |
diffOutFileName + " ...") |
| 1322 |
if os.path.exists(diffOutFileName): |
| 1323 |
changedFileDiffOutputStr = open(diffOutFileName, 'r').read() |
| 1324 |
#print("\nchangedFileDiffOutputStr:\n", changedFileDiffOutputStr) |
| 1325 |
extractPackageEnablesFromChangeStatus(changedFileDiffOutputStr, inOptions, |
| 1326 |
gitRepo, enablePackagesList, verbose, projectChangeLogic=projectChangeLogic) |
| 1327 |
else: |
| 1328 |
if verbose: |
| 1329 |
print("\nThe file " + diffOutFileName + " does not exist!\n") |
| 1330 |
|
| 1331 |
if not enableAllPackages and inOptions.enableExtraPackages: |
| 1332 |
if verbose: |
| 1333 |
print("\nEnabling extra explicitly specified packages '" + |
| 1334 |
inOptions.enableExtraPackages + "' ...") |
| 1335 |
enablePackagesList += inOptions.enableExtraPackages.split(',') |
| 1336 |
|
| 1337 |
if verbose: |
| 1338 |
print("\nFull package enable list: [" + ','.join(enablePackagesList) + "]") |
| 1339 |
|
| 1340 |
if inOptions.disablePackages: |
| 1341 |
if verbose: |
| 1342 |
print("\nRemoving package enables: [" + inOptions.disablePackages + "]") |
| 1343 |
for disablePackage in inOptions.disablePackages.split(","): |
| 1344 |
packageIdx = findInSequence(enablePackagesList, disablePackage) |
| 1345 |
if packageIdx >= 0: |
| 1346 |
del enablePackagesList[packageIdx] |
| 1347 |
|
| 1348 |
if verbose: |
| 1349 |
print("\nFiltering the set of enabled packages according to allowed " + |
| 1350 |
"package types ...") |
| 1351 |
origEnablePackagesList = enablePackagesList[:] |
| 1352 |
enablePackagesList = getDefaultProjectDependenices().filterPackageNameList( |
| 1353 |
enablePackagesList, validPackageTypesList, verbose) |
| 1354 |
|
| 1355 |
if verbose: |
| 1356 |
print("\nFinal package enable list: [" + ','.join(enablePackagesList) + "]") |
| 1357 |
|
| 1358 |
if tribitsGitRepos.numTribitsAllExtraRepos() > 0: |
| 1359 |
cmakePkgOptions.extend( |
| 1360 |
[ |
| 1361 |
cmakeScopedDefine( |
| 1362 |
projectName, "PRE_REPOSITORIES:STRING", |
| 1363 |
','.join(tribitsGitRepos.tribitsPreRepoNamesList())), |
| 1364 |
cmakeScopedDefine( |
| 1365 |
projectName, "EXTRA_REPOSITORIES:STRING", |
| 1366 |
','.join(tribitsGitRepos.tribitsExtraRepoNamesList())), |
| 1367 |
cmakeScopedDefine( |
| 1368 |
projectName, "ENABLE_KNOWN_EXTERNAL_REPOS_TYPE", inOptions.extraReposType), |
| 1369 |
cmakeScopedDefine( |
| 1370 |
projectName, "EXTRAREPOS_FILE", getExtraReposFilePath(inOptions)), |
| 1371 |
] |
| 1372 |
) |
| 1373 |
|
| 1374 |
for pkg in enablePackagesList: |
| 1375 |
cmakePkgOptions.append(cmakeScopedDefine(projectName, "ENABLE_"+pkg+":BOOL", "ON")) |
| 1376 |
|
| 1377 |
cmakePkgOptions.append(cmakeScopedDefine(projectName, "ENABLE_ALL_OPTIONAL_PACKAGES:BOOL", "ON")) |
| 1378 |
|
| 1379 |
if inOptions.enableAllPackages == 'on': |
| 1380 |
cmakePkgOptions.append(cmakeScopedDefine(projectName, "ENABLE_ALL_PACKAGES:BOOL", "ON")) |
| 1381 |
|
| 1382 |
if inOptions.enableFwdPackages: |
| 1383 |
if verbose: |
| 1384 |
print("\nEnabling forward packages on request!") |
| 1385 |
cmakePkgOptions.append(cmakeScopedDefine(projectName, "ENABLE_ALL_FORWARD_DEP_PACKAGES:BOOL", "ON")) |
| 1386 |
else: |
| 1387 |
cmakePkgOptions.append(cmakeScopedDefine(projectName, "ENABLE_ALL_FORWARD_DEP_PACKAGES:BOOL", "OFF")) |
| 1388 |
|
| 1389 |
if inOptions.disablePackages: |
| 1390 |
if verbose: |
| 1391 |
print("\nAdding hard disables for specified packages '" + |
| 1392 |
inOptions.disablePackages + "' ...\n") |
| 1393 |
disablePackagesList = inOptions.disablePackages.split(',') |
| 1394 |
for pkg in disablePackagesList: |
| 1395 |
cmakePkgOptions.append(cmakeScopedDefine(projectName, "ENABLE_"+pkg+":BOOL", "OFF")) |
| 1396 |
|
| 1397 |
if verbose: |
| 1398 |
print("\ncmakePkgOptions: " + str(cmakePkgOptions)) |
| 1399 |
|
| 1400 |
return (cmakePkgOptions, enablePackagesList) |
| 1401 |
|
| 1402 |
|
| 1403 |
def runBuildTestCase(inOptions, tribitsGitRepos, buildTestCase, timings): |
| 1404 |
|
| 1405 |
success = True |
| 1406 |
|
| 1407 |
startingTime = time.time() |
| 1408 |
|
| 1409 |
baseTestDir = os.getcwd() |
| 1410 |
|
| 1411 |
buildTestCaseName = buildTestCase.name |
| 1412 |
|
| 1413 |
if not performAnyActions(inOptions): |
| 1414 |
print("\nNo other actions to perform!\n") |
| 1415 |
return success |
| 1416 |
|
| 1417 |
print("\nCreating a new build directory if it does not already exist ...") |
| 1418 |
createDir(buildTestCaseName) |
| 1419 |
|
| 1420 |
absBuildDir = os.path.join(baseTestDir, buildTestCaseName) |
| 1421 |
|
| 1422 |
echoChDir(absBuildDir) |
| 1423 |
|
| 1424 |
try: |
| 1425 |
|
| 1426 |
print("") |
| 1427 |
print("A) Get the CMake configure options (" + buildTestCaseName + ") ...") |
| 1428 |
print("") |
| 1429 |
|
| 1430 |
preConfigurePassed = True |
| 1431 |
projectName = inOptions.projectName |
| 1432 |
|
| 1433 |
# A.1) Set the base options |
| 1434 |
|
| 1435 |
cmakeBaseOptions = [] |
| 1436 |
if inOptions.useNinja: |
| 1437 |
cmakeBaseOptions.append("-GNinja") |
| 1438 |
if inOptions.extraCmakeOptions: |
| 1439 |
cmakeBaseOptions.extend(commandLineOptionsToList(inOptions.extraCmakeOptions)) |
| 1440 |
cmakeBaseOptions.append(cmakeScopedDefine(projectName, |
| 1441 |
"TRIBITS_DIR:PATH", inOptions.tribitsDir)) |
| 1442 |
cmakeBaseOptions.append(cmakeScopedDefine(projectName, |
| 1443 |
"ENABLE_TESTS:BOOL", "ON")) |
| 1444 |
cmakeBaseOptions.append(cmakeScopedDefine(projectName, |
| 1445 |
"TEST_CATEGORIES:STRING", inOptions.testCategories)) |
| 1446 |
cmakeBaseOptions.append(cmakeScopedDefine(projectName, |
| 1447 |
"ALLOW_NO_PACKAGES:BOOL", "OFF")) |
| 1448 |
|
| 1449 |
if inOptions.ctestTimeOut: |
| 1450 |
cmakeBaseOptions.append(("-DDART_TESTING_TIMEOUT:STRING="+str(inOptions.ctestTimeOut))) |
| 1451 |
|
| 1452 |
cmakeBaseOptions.extend(buildTestCase.extraCMakeOptions) |
| 1453 |
|
| 1454 |
result = readAndAppendCMakeOptions( |
| 1455 |
inOptions.projectName, |
| 1456 |
os.path.join("..", getCommonConfigFileName()), |
| 1457 |
cmakeBaseOptions, |
| 1458 |
True) |
| 1459 |
if not result: preConfigurePassed = False |
| 1460 |
|
| 1461 |
result = readAndAppendCMakeOptions( |
| 1462 |
inOptions.projectName, |
| 1463 |
os.path.join("..", getBuildSpecificConfigFileName(buildTestCaseName)), |
| 1464 |
cmakeBaseOptions, |
| 1465 |
buildTestCase.isDefaultBuild) |
| 1466 |
if not result: preConfigurePassed = False |
| 1467 |
|
| 1468 |
print("\ncmakeBaseOptions: " + str(cmakeBaseOptions)) |
| 1469 |
|
| 1470 |
# A.2) Set the package enable options |
| 1471 |
|
| 1472 |
cmakePkgOptions = [] |
| 1473 |
enablePackagesList = [] |
| 1474 |
|
| 1475 |
if preConfigurePassed: |
| 1476 |
(cmakePkgOptions, enablePackagesList) = \ |
| 1477 |
getEnablesLists(inOptions, buildTestCase.validPackageTypesList, |
| 1478 |
buildTestCase.isDefaultBuild, |
| 1479 |
buildTestCase.skipCaseIfNoChangeFromDefaultEnables, tribitsGitRepos, |
| 1480 |
baseTestDir, True) |
| 1481 |
|
| 1482 |
# A.3) Set the combined options |
| 1483 |
|
| 1484 |
cmakeOptions = [] |
| 1485 |
|
| 1486 |
if preConfigurePassed: |
| 1487 |
|
| 1488 |
cmakeOptions = cmakeBaseOptions + cmakePkgOptions |
| 1489 |
|
| 1490 |
print("\ncmakeOptions = " + str(cmakeOptions)) |
| 1491 |
|
| 1492 |
print("\nCreating base configure file do-configure.base ...") |
| 1493 |
createConfigureFile(cmakeBaseOptions, "cmake", inOptions.srcDir, |
| 1494 |
"do-configure.base") |
| 1495 |
|
| 1496 |
print("\nCreating package-enabled configure file do-configure ...") |
| 1497 |
createConfigureFile(cmakePkgOptions, "./do-configure.base", None, "do-configure") |
| 1498 |
|
| 1499 |
print("") |
| 1500 |
print("B) Do the configuration with CMake (" + buildTestCaseName + ") ...") |
| 1501 |
print("") |
| 1502 |
|
| 1503 |
configurePassed = False |
| 1504 |
|
| 1505 |
if inOptions.doConfigure and not preConfigurePassed: |
| 1506 |
|
| 1507 |
print("\nSKIPPED: " + buildTestCaseName + " configure skipped because " + |
| 1508 |
"pre-configure failed (see above)!\n") |
| 1509 |
|
| 1510 |
elif not (enablePackagesList or inOptions.enableAllPackages == 'on'): |
| 1511 |
|
| 1512 |
print("\nSKIPPED: " + buildTestCaseName + " configure skipped because " + |
| 1513 |
"no packages are enabled!\n") |
| 1514 |
buildTestCase.skippedConfigureDueToNoEnables = True |
| 1515 |
|
| 1516 |
elif inOptions.doConfigure: |
| 1517 |
|
| 1518 |
removeIfExists("CMakeCache.txt") |
| 1519 |
removeDirIfExists("CMakeFiles") |
| 1520 |
|
| 1521 |
cmnd = "./do-configure" |
| 1522 |
|
| 1523 |
(configureRtn, timings.configure) = echoRunSysCmnd(cmnd, |
| 1524 |
outFile=getConfigureOutputFileName(), |
| 1525 |
timeCmnd=True, returnTimeCmnd=True, throwExcept=False |
| 1526 |
) |
| 1527 |
|
| 1528 |
if configureRtn == 0: |
| 1529 |
print("\nConfigure passed!\n") |
| 1530 |
echoRunSysCmnd("touch "+getConfigureSuccessFileName()) |
| 1531 |
configurePassed = True |
| 1532 |
else: |
| 1533 |
print("\nConfigure failed returning " + str(configureRtn) + "!\n") |
| 1534 |
raise Exception("Configure failed!") |
| 1535 |
|
| 1536 |
else: |
| 1537 |
|
| 1538 |
print("\nSkipping configure on request!\n") |
| 1539 |
if os.path.exists(getConfigureSuccessFileName()): |
| 1540 |
print("\nA current successful configure exists!\n") |
| 1541 |
configurePassed = True |
| 1542 |
else: |
| 1543 |
print("\nFAILED: A current successful configure does *not* exist!\n") |
| 1544 |
|
| 1545 |
print("") |
| 1546 |
print("C) Do the build ("+buildTestCaseName+") ...") |
| 1547 |
print("") |
| 1548 |
|
| 1549 |
buildPassed = False |
| 1550 |
|
| 1551 |
if inOptions.doBuild and configurePassed: |
| 1552 |
|
| 1553 |
if inOptions.useNinja: |
| 1554 |
cmnd = "ninja" |
| 1555 |
else: |
| 1556 |
cmnd = "make" |
| 1557 |
if inOptions.makeOptions: |
| 1558 |
cmnd += " " + inOptions.makeOptions |
| 1559 |
|
| 1560 |
(buildRtn, timings.build) = echoRunSysCmnd(cmnd, |
| 1561 |
outFile=getBuildOutputFileName(), |
| 1562 |
timeCmnd=True, returnTimeCmnd=True, throwExcept=False |
| 1563 |
) |
| 1564 |
|
| 1565 |
if buildRtn == 0: |
| 1566 |
print("\nBuild passed!\n") |
| 1567 |
echoRunSysCmnd("touch "+getBuildSuccessFileName()) |
| 1568 |
buildPassed = True |
| 1569 |
else: |
| 1570 |
print("\nBuild failed returning " + str(buildRtn) + "!\n") |
| 1571 |
raise Exception("Build failed!") |
| 1572 |
|
| 1573 |
elif inOptions.doBuild and not configurePassed: |
| 1574 |
|
| 1575 |
print("\nSKIPPED: " + buildTestCaseName + " build skipped because " + |
| 1576 |
"configure did not pass!\n") |
| 1577 |
|
| 1578 |
else: |
| 1579 |
|
| 1580 |
print("\nSkipping the build on request!\n") |
| 1581 |
if os.path.exists(getBuildSuccessFileName()): |
| 1582 |
print("\nA current successful build exists!\n") |
| 1583 |
buildPassed = True |
| 1584 |
else: |
| 1585 |
print("\nFAILED: A current successful build does *not* exist!\n") |
| 1586 |
|
| 1587 |
print("") |
| 1588 |
print("D) Run the tests (" + buildTestCaseName + ") ...") |
| 1589 |
print("") |
| 1590 |
|
| 1591 |
testPassed = False |
| 1592 |
|
| 1593 |
if inOptions.doTest and buildPassed: |
| 1594 |
|
| 1595 |
cmnd = "ctest" |
| 1596 |
if inOptions.ctestOptions: |
| 1597 |
cmnd += " " + inOptions.ctestOptions |
| 1598 |
|
| 1599 |
(testRtn, timings.test) = echoRunSysCmnd(cmnd, |
| 1600 |
outFile=getTestOutputFileName(), |
| 1601 |
timeCmnd=True, returnTimeCmnd=True, throwExcept=False |
| 1602 |
) |
| 1603 |
|
| 1604 |
if testRtn == 0: |
| 1605 |
print("\nNo tests failed!\n") |
| 1606 |
echoRunSysCmnd("touch "+getTestSuccessFileName()) |
| 1607 |
else: |
| 1608 |
errStr = "FAILED: ctest failed returning "+str(testRtn)+"!" |
| 1609 |
print("\n" + errStr + "\n") |
| 1610 |
raise Exception(errStr) |
| 1611 |
|
| 1612 |
elif inOptions.doTest and buildTestCase.skippedConfigureDueToNoEnables: |
| 1613 |
|
| 1614 |
print("\nSKIPPED: " + buildTestCaseName + " tests skipped because no " + |
| 1615 |
"packages are enabled!") |
| 1616 |
echoRunSysCmnd("touch "+getTestSuccessFileName()) |
| 1617 |
# NOTE: We have to create this test success file because the presents of |
| 1618 |
# this file is used to determine in the build/test case is successful |
| 1619 |
# and therefore is okay to push. This is needed when the script is run |
| 1620 |
# a second time to determine if a build/test is successful and therefore |
| 1621 |
# allow a push. |
| 1622 |
|
| 1623 |
else: |
| 1624 |
|
| 1625 |
print("\nSkipping the tests on request!\n") |
| 1626 |
|
| 1627 |
except Exception as e: |
| 1628 |
|
| 1629 |
success = False |
| 1630 |
printStackTrace() |
| 1631 |
|
| 1632 |
print("") |
| 1633 |
print("E) Analyze the overall results and send email notification (" + |
| 1634 |
buildTestCaseName + ") ...") |
| 1635 |
print("") |
| 1636 |
|
| 1637 |
if performAnyActions(inOptions): |
| 1638 |
|
| 1639 |
result = analyzeResultsSendEmail(inOptions, buildTestCase, |
| 1640 |
enablePackagesList, cmakeOptions, startingTime, timings) |
| 1641 |
if not result: success = False |
| 1642 |
|
| 1643 |
else: |
| 1644 |
|
| 1645 |
print("No actions performed, nothing to analyze!") |
| 1646 |
|
| 1647 |
return success |
| 1648 |
|
| 1649 |
|
| 1650 |
def cleanBuildTestCaseOutputFiles(runBuildTestCaseBool, inOptions, baseTestDir, buildTestCaseName): |
| 1651 |
|
| 1652 |
if runBuildTestCaseBool and not os.path.exists(buildTestCaseName): |
| 1653 |
|
| 1654 |
print("\nSkipping cleaning build/test files for " + buildTestCaseName + |
| 1655 |
" because dir does not exist!\n") |
| 1656 |
|
| 1657 |
elif runBuildTestCaseBool and os.path.exists(buildTestCaseName): |
| 1658 |
|
| 1659 |
if inOptions.wipeClean: |
| 1660 |
|
| 1661 |
print("\nRemoving the existing build directory " + buildTestCaseName + |
| 1662 |
" (--wipe-clean) ...") |
| 1663 |
removeDirIfExists(buildTestCaseName) |
| 1664 |
|
| 1665 |
elif doRemoveOutputFiles(inOptions): |
| 1666 |
|
| 1667 |
echoChDir(buildTestCaseName) |
| 1668 |
if inOptions.doConfigure or inOptions.doPull: |
| 1669 |
removeIfExists(getConfigureOutputFileName()) |
| 1670 |
removeIfExists(getConfigureSuccessFileName()) |
| 1671 |
if inOptions.doBuild or inOptions.doConfigure or inOptions.doPull: |
| 1672 |
removeIfExists(getBuildOutputFileName()) |
| 1673 |
removeIfExists(getBuildSuccessFileName()) |
| 1674 |
if inOptions.doTest or inOptions.doBuild or inOptions.doConfigure or inOptions.doPull: |
| 1675 |
removeIfExists(getTestOutputFileName()) |
| 1676 |
removeIfExists(getTestSuccessFileName()) |
| 1677 |
removeIfExists(getEmailBodyFileName()) |
| 1678 |
removeIfExists(getEmailSuccessFileName()) |
| 1679 |
echoChDir("..") |
| 1680 |
|
| 1681 |
def cleanBuildTestCaseSuccessFiles(runBuildTestCaseBool, inOptions, baseTestDir, \ |
| 1682 |
buildTestCaseName \ |
| 1683 |
): |
| 1684 |
|
| 1685 |
removeIfExists(buildTestCaseName+"/"+getConfigureSuccessFileName()) |
| 1686 |
removeIfExists(buildTestCaseName+"/"+getBuildSuccessFileName()) |
| 1687 |
removeIfExists(buildTestCaseName+"/"+getTestSuccessFileName()) |
| 1688 |
removeIfExists(buildTestCaseName+"/"+getEmailSuccessFileName()) |
| 1689 |
removeIfExists(buildTestCaseName+"/"+getEmailBodyFileName()) |
| 1690 |
# NOTE: ABove, we need to delete the 'email.out' file otherwise it will get |
| 1691 |
# picked up in a later run of just a status check. But this info is not |
| 1692 |
# really last because it is duplicated in the file |
| 1693 |
# commitStatusEmailBody.out. |
| 1694 |
|
| 1695 |
|
| 1696 |
def cleanSuccessFiles(buildTestCaseList, inOptions, baseTestDir): |
| 1697 |
print("\nRemoving *.success files ...\n") |
| 1698 |
removeIfExists(getInitialPullSuccessFileName()) |
| 1699 |
for buildTestCase in buildTestCaseList: |
| 1700 |
cleanBuildTestCaseSuccessFiles( |
| 1701 |
buildTestCase.runBuildTestCase, inOptions, baseTestDir, buildTestCase.name) |
| 1702 |
|
| 1703 |
|
| 1704 |
def runBuildTestCaseDriver(inOptions, tribitsGitRepos, baseTestDir, buildTestCase, timings): |
| 1705 |
|
| 1706 |
success = True |
| 1707 |
|
| 1708 |
buildTestCaseName = buildTestCase.name |
| 1709 |
|
| 1710 |
print("\n***") |
| 1711 |
print("*** Doing build and test of "+buildTestCaseName+" ...") |
| 1712 |
print("***\n") |
| 1713 |
|
| 1714 |
if buildTestCase.runBuildTestCase: |
| 1715 |
|
| 1716 |
try: |
| 1717 |
echoChDir(baseTestDir) |
| 1718 |
writeDefaultBuildSpecificConfigFile(buildTestCaseName) |
| 1719 |
result = runBuildTestCase(inOptions, tribitsGitRepos, buildTestCase, timings) |
| 1720 |
if not result: success = False |
| 1721 |
except Exception as e: |
| 1722 |
success = False |
| 1723 |
printStackTrace() |
| 1724 |
|
| 1725 |
else: |
| 1726 |
|
| 1727 |
print("\nSkipping " + buildTestCaseName + " build/test on request!\n") |
| 1728 |
|
| 1729 |
return success |
| 1730 |
|
| 1731 |
|
| 1732 |
def checkBuildTestCaseStatus(buildTestCase, inOptions): |
| 1733 |
|
| 1734 |
runBuildTestCaseBool = buildTestCase.runBuildTestCase |
| 1735 |
buildTestCaseName = buildTestCase.name |
| 1736 |
skippedConfigureDueToNoEnables = buildTestCase.skippedConfigureDueToNoEnables |
| 1737 |
|
| 1738 |
statusMsg = None |
| 1739 |
timeInMin = -1.0 |
| 1740 |
|
| 1741 |
if not runBuildTestCaseBool: |
| 1742 |
buildTestCaseActionsPass = True |
| 1743 |
buildTestCaseOkayToCommit = True |
| 1744 |
statusMsg = \ |
| 1745 |
"Test case "+buildTestCaseName+" was not run! => Does not affect push readiness!" |
| 1746 |
return (buildTestCaseActionsPass, buildTestCaseOkayToCommit, statusMsg, timeInMin) |
| 1747 |
|
| 1748 |
if skippedConfigureDueToNoEnables: |
| 1749 |
buildTestCaseActionsPass = True |
| 1750 |
buildTestCaseOkayToCommit = True |
| 1751 |
statusMsg = \ |
| 1752 |
"Skipped configure, build, test due to no enabled packages! => Does not affect push readiness!" |
| 1753 |
return (buildTestCaseActionsPass, buildTestCaseOkayToCommit, statusMsg, timeInMin) |
| 1754 |
|
| 1755 |
if not os.path.exists(buildTestCaseName) and not performAnyBuildTestActions(inOptions): |
| 1756 |
buildTestCaseActionsPass = True |
| 1757 |
buildTestCaseOkayToCommit = False |
| 1758 |
statusMsg = "No configure, build, or test for "+buildTestCaseName+" was requested!" |
| 1759 |
return (buildTestCaseActionsPass, buildTestCaseOkayToCommit, statusMsg, timeInMin) |
| 1760 |
|
| 1761 |
if not os.path.exists(buildTestCaseName): |
| 1762 |
buildTestCaseActionsPass = False |
| 1763 |
buildTestCaseOkayToCommit = False |
| 1764 |
statusMsg = "The directory "+buildTestCaseName+" does not exist!" |
| 1765 |
|
| 1766 |
emailSuccessFileName = buildTestCaseName+"/"+getEmailSuccessFileName() |
| 1767 |
if os.path.exists(emailSuccessFileName): |
| 1768 |
buildTestCaseActionsPass = True |
| 1769 |
else: |
| 1770 |
buildTestCaseActionsPass = False |
| 1771 |
|
| 1772 |
testSuccessFileName = buildTestCaseName+"/"+getTestSuccessFileName() |
| 1773 |
if os.path.exists(testSuccessFileName): |
| 1774 |
buildTestCaseOkayToCommit = True |
| 1775 |
else: |
| 1776 |
buildTestCaseOkayToCommit = False |
| 1777 |
|
| 1778 |
if not statusMsg: |
| 1779 |
statusMsg = getBuildTestCaseSummary(buildTestCaseName) |
| 1780 |
|
| 1781 |
emailBodyFileName = buildTestCaseName+"/"+getEmailBodyFileName() |
| 1782 |
if os.path.exists(emailBodyFileName): |
| 1783 |
timeInMinLine = getCmndOutput("grep '"+getTotalTimeBeginStr(buildTestCaseName)+"' " + \ |
| 1784 |
emailBodyFileName, True, False) |
| 1785 |
timeInMin = getTimeInMinFromTotalTimeLine(buildTestCaseName, timeInMinLine) |
| 1786 |
|
| 1787 |
return (buildTestCaseActionsPass, buildTestCaseOkayToCommit, statusMsg, timeInMin) |
| 1788 |
|
| 1789 |
|
| 1790 |
def getUserCommitMessageStr(inOptions): |
| 1791 |
|
| 1792 |
absCommitMsgHeaderFile = inOptions.commitMsgHeaderFile |
| 1793 |
if not os.path.isabs(absCommitMsgHeaderFile): |
| 1794 |
absCommitMsgHeaderFile = os.path.join(inOptions.srcDir, absCommitMsgHeaderFile) |
| 1795 |
|
| 1796 |
print("\nExtracting commit message subject and header from the file '" + |
| 1797 |
absCommitMsgHeaderFile + "' ...\n") |
| 1798 |
|
| 1799 |
commitMsgHeaderFileStr = open(absCommitMsgHeaderFile, 'r').read() |
| 1800 |
|
| 1801 |
commitEmailBodyStr = commitMsgHeaderFileStr |
| 1802 |
|
| 1803 |
return commitEmailBodyStr |
| 1804 |
|
| 1805 |
|
| 1806 |
def getAutomatedStatusSummaryHeaderKeyStr(): |
| 1807 |
return "Build/Test Cases Summary" |
| 1808 |
|
| 1809 |
|
| 1810 |
def getAutomatedStatusSummaryHeaderStr(): |
| 1811 |
|
| 1812 |
commitEmailBodyStr = "\n" \ |
| 1813 |
+getAutomatedStatusSummaryHeaderKeyStr()+"\n" |
| 1814 |
|
| 1815 |
return commitEmailBodyStr |
| 1816 |
|
| 1817 |
|
| 1818 |
def getEnableStatusList(inOptions, enabledPackagesList): |
| 1819 |
enabledStatusStr = "" |
| 1820 |
enabledStatusStr += "Enabled Packages: " + ', '.join(enabledPackagesList) + "\n" |
| 1821 |
if inOptions.disablePackages: |
| 1822 |
enabledStatusStr += "Disabled Packages: " + inOptions.disablePackages + "\n" |
| 1823 |
if inOptions.enableAllPackages == "on": |
| 1824 |
enabledStatusStr += "Enabled all Packages\n" |
| 1825 |
elif inOptions.enableFwdPackages: |
| 1826 |
enabledStatusStr += "Enabled all Forward Packages\n" |
| 1827 |
return enabledStatusStr |
| 1828 |
|
| 1829 |
|
| 1830 |
# Extract the original log message from the output from: |
| 1831 |
# |
| 1832 |
# git cat-file -p HEAD |
| 1833 |
# |
| 1834 |
# This function strips off the git-generated header info and strips off the |
| 1835 |
# trailing build/test summary data. |
| 1836 |
# |
| 1837 |
# NOTE: This function assumes that there will be at least one blank line |
| 1838 |
# between the build/test summary data block and the original text message. If |
| 1839 |
# there is not, this function will throw! |
| 1840 |
# |
| 1841 |
def getLastCommitMessageStrFromRawCommitLogStr(rawLogOutput): |
| 1842 |
|
| 1843 |
origLogStrList = [] |
| 1844 |
pastHeader = False |
| 1845 |
numBlankLines = 0 |
| 1846 |
lastNumBlankLines = 0 |
| 1847 |
foundStatusHeader = False |
| 1848 |
for line in rawLogOutput.splitlines(): |
| 1849 |
#print("\nline = '" + line + "'\n") |
| 1850 |
if pastHeader: |
| 1851 |
origLogStrList.append(line) |
| 1852 |
if line == "": |
| 1853 |
numBlankLines += 1 |
| 1854 |
elif numBlankLines > 0: |
| 1855 |
lastNumBlankLines = numBlankLines |
| 1856 |
numBlankLines = 0 |
| 1857 |
if line == getAutomatedStatusSummaryHeaderKeyStr(): |
| 1858 |
foundStatusHeader = True |
| 1859 |
break |
| 1860 |
if line == "": |
| 1861 |
pastHeader = True |
| 1862 |
|
| 1863 |
if foundStatusHeader: |
| 1864 |
#print("\nlastNumBlankLines =", lastNumBlankLines) |
| 1865 |
#print("origLogStrList[-1] = '" + origLogStrList[-1] + "'") |
| 1866 |
#print("origLogStrList[-2] = '" + origLogStrList[-2] + "'") |
| 1867 |
if origLogStrList[-2] != "": |
| 1868 |
raise Exception("Error, there must be at least one blank line before the" \ |
| 1869 |
" build/test summary block! This is a corrupted commit message. Please" \ |
| 1870 |
" use 'git commit --amend' and manually remove the 'Build/test Cases Summary' block.") |
| 1871 |
origLogStrList = origLogStrList[0:-lastNumBlankLines] |
| 1872 |
lastCommitMessageStr = '\n'.join(origLogStrList) |
| 1873 |
else: |
| 1874 |
lastCommitMessageStr = ('\n'.join(origLogStrList))+'\n' |
| 1875 |
lastNumBlankLines = -1 # Flag we did not find status header |
| 1876 |
|
| 1877 |
return (lastCommitMessageStr, lastNumBlankLines) |
| 1878 |
|
| 1879 |
|
| 1880 |
def getLastCommitMessageStr(inOptions, gitRepo): |
| 1881 |
|
| 1882 |
# Get the raw output from the last current commit log |
| 1883 |
rawLogOutput = getCmndOutput( |
| 1884 |
inOptions.git+" cat-file -p HEAD", |
| 1885 |
workingDir=getGitRepoDir(inOptions.srcDir, gitRepo.repoDir) |
| 1886 |
) |
| 1887 |
|
| 1888 |
return getLastCommitMessageStrFromRawCommitLogStr(rawLogOutput)[0] |
| 1889 |
|
| 1890 |
|
| 1891 |
def trimLineToLen(lineIn, numChars): |
| 1892 |
if len(lineIn) > numChars: |
| 1893 |
return lineIn[:numChars]+".." |
| 1894 |
return lineIn |
| 1895 |
|
| 1896 |
|
| 1897 |
def getLocalCommitsSummariesStr(inOptions, gitRepo): |
| 1898 |
|
| 1899 |
# Get the list of local commits other than this one |
| 1900 |
if gitRepo.gitRepoStats.numCommitsInt() > 0: |
| 1901 |
rawLocalCommitsStr = getCmndOutput( |
| 1902 |
inOptions.git+" log --oneline "+gitRepo.gitRepoStats.branch \ |
| 1903 |
+" ^"+gitRepo.gitRepoStats.trackingBranch, |
| 1904 |
True, |
| 1905 |
workingDir=getGitRepoDir(inOptions.srcDir, gitRepo.repoDir) |
| 1906 |
) |
| 1907 |
else: |
| 1908 |
rawLocalCommitsStr = "" |
| 1909 |
|
| 1910 |
if gitRepo.repoName: |
| 1911 |
repoName = gitRepo.repoName |
| 1912 |
repoNameModifier = " ("+gitRepo.repoName+")" |
| 1913 |
else: |
| 1914 |
repoName = "" |
| 1915 |
repoNameModifier = "" |
| 1916 |
|
| 1917 |
print("\nLocal commits for this build/test group" + repoNameModifier + ":" + |
| 1918 |
"\n----------------------------------------" ) |
| 1919 |
|
| 1920 |
if rawLocalCommitsStr == "\n" or rawLocalCommitsStr == "": |
| 1921 |
localCommitsExist = False |
| 1922 |
else: |
| 1923 |
localCommitsExist = True |
| 1924 |
|
| 1925 |
if localCommitsExist: |
| 1926 |
print(rawLocalCommitsStr) |
| 1927 |
else: |
| 1928 |
print("No local commits exit!") |
| 1929 |
|
| 1930 |
localCommitsStr = \ |
| 1931 |
"*** Commits for repo "+repoName+":" |
| 1932 |
if localCommitsExist: |
| 1933 |
for localCommitLine in rawLocalCommitsStr.splitlines(): |
| 1934 |
localCommitsStr += ("\n "+trimLineToLen(localCommitLine, 90)) |
| 1935 |
|
| 1936 |
return localCommitsStr |
| 1937 |
|
| 1938 |
|
| 1939 |
def getLocalCommitsSHA1ListStr(inOptions, gitRepo): |
| 1940 |
|
| 1941 |
# Get the raw output from the last current commit log |
| 1942 |
rawLocalCommitsStr = getCmndOutput( |
| 1943 |
inOptions.git+" log --pretty=format:'%h' "\ |
| 1944 |
+gitRepo.gitRepoStats.branch+" ^"+gitRepo.gitRepoStats.trackingBranch, |
| 1945 |
True, |
| 1946 |
workingDir=getGitRepoDir(inOptions.srcDir, gitRepo.repoDir) |
| 1947 |
) |
| 1948 |
|
| 1949 |
rawLocalCommitsArray = rawLocalCommitsStr.splitlines() |
| 1950 |
|
| 1951 |
if len(rawLocalCommitsArray) > 1: |
| 1952 |
return ("Other local commits for this build/test group: " |
| 1953 |
+ (", ".join(rawLocalCommitsArray[1:]))) + "\n" |
| 1954 |
return "" |
| 1955 |
|
| 1956 |
# NOTE: Above, you have to use: |
| 1957 |
# |
| 1958 |
# git log --pretty='%h' <currentbranch> ^<trackingbranch> |
| 1959 |
# |
| 1960 |
# and pop off the top commit as shown above instead of: |
| 1961 |
# |
| 1962 |
# git log --pretty='%h' <currentbranch>^ ^<trackingbranch> |
| 1963 |
# |
| 1964 |
# The latter returns nothing when the top commit is a merge commit. |
| 1965 |
|
| 1966 |
|
| 1967 |
def getLocalCommitsExist(inOptions, gitRepo): |
| 1968 |
if gitRepo.gitRepoStats.numCommitsInt() > 0: |
| 1969 |
return True |
| 1970 |
return False |
| 1971 |
|
| 1972 |
|
| 1973 |
def matchProjectName(line): |
| 1974 |
""" |
| 1975 |
Attempts to match and return the value of PROJECT_NAME in a line like |
| 1976 |
SET(PROJECT_NAME <name>) |
| 1977 |
If no match can be made, None is returned. |
| 1978 |
""" |
| 1979 |
matchRegex = r'\s*[Ss][Ee][Tt]\s*\(\s*PROJECT_NAME\s+([^\)\s]*)\s*\).*' |
| 1980 |
match = re.search(matchRegex, line) |
| 1981 |
if match: |
| 1982 |
return match.group(1) |
| 1983 |
else: |
| 1984 |
return None |
| 1985 |
|
| 1986 |
|
| 1987 |
def getProjectName(sourceDirectory): |
| 1988 |
""" |
| 1989 |
Reads the project name from <root>/ProjectName.cmake |
| 1990 |
""" |
| 1991 |
projectNameFile = os.path.join(sourceDirectory, 'ProjectName.cmake') |
| 1992 |
if not os.path.exists(projectNameFile): |
| 1993 |
raise Exception( |
| 1994 |
"%s is required to exist for a valid Tribits project." % projectNameFile) |
| 1995 |
content = open(projectNameFile, "r") |
| 1996 |
line = content.readline() |
| 1997 |
while line: |
| 1998 |
name = matchProjectName(line) |
| 1999 |
if name: |
| 2000 |
return name |
| 2001 |
line = content.readline() |
| 2002 |
raise Exception( |
| 2003 |
'The file %s does not set the PROJECT_NAME variable. ' + |
| 2004 |
'This is required of any Tribits project.') |
| 2005 |
|
| 2006 |
|
| 2007 |
def getRepoStatTableDirName(inOptions, repoDir): |
| 2008 |
if repoDir == "": |
| 2009 |
repoStatTableDirName = gitdist.getBaseRepoTblName( |
| 2010 |
gitdist.getBaseDirNameFromPath(os.path.abspath(inOptions.srcDir))) |
| 2011 |
else: |
| 2012 |
repoStatTableDirName = repoDir |
| 2013 |
return repoStatTableDirName |
| 2014 |
|
| 2015 |
|
| 2016 |
def checkinTest(tribitsDir, inOptions, configuration={}): |
| 2017 |
""" |
| 2018 |
Main function for checkin testing. |
| 2019 |
""" |
| 2020 |
|
| 2021 |
if not inOptions.projectName: |
| 2022 |
inOptions.projectName = getProjectName(inOptions.srcDir) |
| 2023 |
|
| 2024 |
print("\n**********************************************") |
| 2025 |
print("*** Performing checkin testing of %s ***" % inOptions.projectName) |
| 2026 |
print("**********************************************") |
| 2027 |
|
| 2028 |
setattr(inOptions, "tribitsDir", tribitsDir) |
| 2029 |
|
| 2030 |
ciSupportDir = os.path.join(tribitsDir, 'ci_support') |
| 2031 |
setattr(inOptions, "ciSupportDir", ciSupportDir) |
| 2032 |
|
| 2033 |
print("\nciSupportDir = " + ciSupportDir) |
| 2034 |
|
| 2035 |
print("\nsrcDir = " + inOptions.srcDir) |
| 2036 |
|
| 2037 |
baseTestDir = os.getcwd() |
| 2038 |
print("\nbaseTestDir = " + baseTestDir) |
| 2039 |
|
| 2040 |
if inOptions.withoutDefaultBuilds: |
| 2041 |
inOptions.defaultBuilds = '' |
| 2042 |
|
| 2043 |
if inOptions.doAll: |
| 2044 |
inOptions.doPull = True |
| 2045 |
inOptions.doConfigure = True |
| 2046 |
inOptions.doBuild = True |
| 2047 |
inOptions.doTest = True |
| 2048 |
|
| 2049 |
if inOptions.localDoAll: |
| 2050 |
inOptions.allowNoPull = True |
| 2051 |
inOptions.doConfigure = True |
| 2052 |
inOptions.doBuild = True |
| 2053 |
inOptions.doTest = True |
| 2054 |
|
| 2055 |
assertAndSetupGit(inOptions) |
| 2056 |
|
| 2057 |
if inOptions.overallNumProcs: |
| 2058 |
inOptions.makeOptions = "-j"+inOptions.overallNumProcs+" "+inOptions.makeOptions |
| 2059 |
inOptions.ctestOptions = "-j"+inOptions.overallNumProcs+" "+inOptions.ctestOptions |
| 2060 |
|
| 2061 |
assertExtraBuildConfigFiles(inOptions.extraBuilds) |
| 2062 |
assertExtraBuildConfigFiles(inOptions.stExtraBuilds) |
| 2063 |
|
| 2064 |
if not inOptions.skipDepsUpdate: |
| 2065 |
removeIfExists(getProjectDependenciesXmlFileName(inOptions.projectName)) |
| 2066 |
removeIfExists(getProjectDependenciesXmlGenerateOutputFileName(inOptions.projectName)) |
| 2067 |
removeIfExists(getProjectExtraReposPythonOutFile(inOptions.projectName)) |
| 2068 |
|
| 2069 |
print("\n***") |
| 2070 |
print("*** 0) Read project dependencies files and build dependencies graph ...") |
| 2071 |
print("***") |
| 2072 |
|
| 2073 |
tribitsGitRepos = TribitsGitRepos() |
| 2074 |
tribitsGitRepos.initFromCommandlineArguments(inOptions) |
| 2075 |
#print("\ntribitsGitRepos =", tribitsGitRepos) |
| 2076 |
|
| 2077 |
createAndGetProjectDependencies(inOptions, baseTestDir, tribitsGitRepos) |
| 2078 |
|
| 2079 |
# Assert the names of packages passed in |
| 2080 |
assertPackageNames("--enable-packages", inOptions.enablePackages) |
| 2081 |
assertPackageNames("--enable-extra-packages", inOptions.enableExtraPackages) |
| 2082 |
assertPackageNames("--disable-packages", inOptions.disablePackages) |
| 2083 |
|
| 2084 |
success = True |
| 2085 |
|
| 2086 |
didAtLeastOnePush = False |
| 2087 |
|
| 2088 |
timings = Timings() |
| 2089 |
|
| 2090 |
subjectLine = None |
| 2091 |
|
| 2092 |
# Set up build/test cases array |
| 2093 |
|
| 2094 |
buildTestCaseList = [] |
| 2095 |
|
| 2096 |
cmakeConfig = configuration.get('cmake', {}) |
| 2097 |
|
| 2098 |
commonConfigOptions = cmakeConfig.get('common', []) |
| 2099 |
|
| 2100 |
defaultBuilds = cmakeConfig.get('default-builds', []) |
| 2101 |
requestedDefaultBuilds = inOptions.defaultBuilds |
| 2102 |
for buildname, buildopts in defaultBuilds: |
| 2103 |
setBuildTestCaseInList( |
| 2104 |
buildTestCaseList, |
| 2105 |
buildname, |
| 2106 |
buildname in requestedDefaultBuilds, |
| 2107 |
["PT"], |
| 2108 |
True, |
| 2109 |
False, |
| 2110 |
commonConfigOptions \ |
| 2111 |
+ [ cmakeScopedDefine(inOptions.projectName, |
| 2112 |
"ENABLE_SECONDARY_TESTED_CODE:BOOL", "OFF") ] \ |
| 2113 |
+ buildopts \ |
| 2114 |
) |
| 2115 |
|
| 2116 |
if inOptions.stExtraBuilds: |
| 2117 |
for ssExtraBuild in inOptions.stExtraBuilds.split(','): |
| 2118 |
setBuildTestCaseInList(buildTestCaseList, ssExtraBuild, True, |
| 2119 |
["PT", "ST"], False, True, []) |
| 2120 |
|
| 2121 |
allValidPackageTypesList = ["PT", "ST", "EX"] |
| 2122 |
|
| 2123 |
if inOptions.extraBuilds: |
| 2124 |
for extraBuild in inOptions.extraBuilds.split(','): |
| 2125 |
setBuildTestCaseInList(buildTestCaseList, extraBuild, True, |
| 2126 |
allValidPackageTypesList, False, False, []) |
| 2127 |
|
| 2128 |
try: |
| 2129 |
|
| 2130 |
print("\n***") |
| 2131 |
print("*** 1) Clean old output files ...") |
| 2132 |
print("***") |
| 2133 |
|
| 2134 |
if inOptions.doPull: |
| 2135 |
for gitRepo in tribitsGitRepos.gitRepoList(): |
| 2136 |
removeIfExists(getInitialPullOutputFileName(gitRepo.repoName)) |
| 2137 |
removeIfExists(getInitialExtraPullOutputFileName(gitRepo.repoName)) |
| 2138 |
removeIfExists(getInitialPullSuccessFileName()) |
| 2139 |
|
| 2140 |
for gitRepo in tribitsGitRepos.gitRepoList(): |
| 2141 |
removeIfExists(getFinalCommitBodyFileName(gitRepo.repoName)) |
| 2142 |
removeIfExists(getFinalCommitOutputFileName(gitRepo.repoName)) |
| 2143 |
removeIfExists(getCommitStatusEmailBodyFileName()) |
| 2144 |
|
| 2145 |
for gitRepo in tribitsGitRepos.gitRepoList(): |
| 2146 |
removeIfExists(getModifiedFilesOutputFileName(gitRepo.repoName)) |
| 2147 |
removeIfExists(getFinalPullOutputFileName(gitRepo.repoName)) |
| 2148 |
removeIfExists(getPushOutputFileName(gitRepo.repoName)) |
| 2149 |
|
| 2150 |
if inOptions.executeOnReadyToPush: |
| 2151 |
removeIfExists(getExtraCommandOutputFileName()) |
| 2152 |
|
| 2153 |
for buildTestCase in buildTestCaseList: |
| 2154 |
cleanBuildTestCaseOutputFiles( |
| 2155 |
buildTestCase.runBuildTestCase, inOptions, baseTestDir, buildTestCase.name) |
| 2156 |
|
| 2157 |
print("\n***") |
| 2158 |
print("*** 2) Get repo status") |
| 2159 |
print("***\n") |
| 2160 |
|
| 2161 |
hasChangesToPush = getReposStats(inOptions, tribitsGitRepos) |
| 2162 |
|
| 2163 |
# Determine if we will need to perform git diffs of |
| 2164 |
if inOptions.enableAllPackages == "on": |
| 2165 |
print("\n--enable-all-packages=on => git diffs w.r.t. tracking branch " + |
| 2166 |
"*will not* be needed to look for changed files!") |
| 2167 |
gitDiffsWrtTrackingBranchAreNeeded = False |
| 2168 |
elif (inOptions.enablePackages != "" and inOptions.enableAllPackages == "off"): |
| 2169 |
print("\n--enable-packages!='' and --enable-all-packages='off'" + |
| 2170 |
" => git diffs w.r.t. tracking branch *will not* be needed to " + |
| 2171 |
"look for changed files!") |
| 2172 |
gitDiffsWrtTrackingBranchAreNeeded = False |
| 2173 |
elif (inOptions.enablePackages == "" or inOptions.enableAllPackages == "auto"): |
| 2174 |
# If the user has not specified a set of packages to enable, or allows |
| 2175 |
# for logic that determines if all packages should be enabled (because |
| 2176 |
# base-level CMake files have changed), then we need to do git diffs to |
| 2177 |
# look for changed files. This is the default set of arguments. |
| 2178 |
print("\n--enable-packages='' or --enable-all-packages='auto'" + |
| 2179 |
" => git diffs w.r.t. tracking branch *will* be needed to look " + |
| 2180 |
"for changed files!") |
| 2181 |
gitDiffsWrtTrackingBranchAreNeeded = True |
| 2182 |
else: |
| 2183 |
# We should never get here, but just in case, let's do the diffs. |
| 2184 |
print("git diffs w.r.t. tracking branch may be needed to look for " + |
| 2185 |
"changed files?") |
| 2186 |
gitDiffsWrtTrackingBranchAreNeeded = True |
| 2187 |
|
| 2188 |
# Determine if all repos must be on a branch and have a tracking branch |
| 2189 |
if gitDiffsWrtTrackingBranchAreNeeded: |
| 2190 |
print("\nNeed git diffs w.r.t. tracking branch so all repos must be on a" + |
| 2191 |
" branch and have a tracking branch!") |
| 2192 |
reposMustHaveTrackingBranch = True |
| 2193 |
elif inOptions.doPull: |
| 2194 |
print("\nDoing a pull so all repos must be on a branch and have a " |
| 2195 |
"tracking branch!") |
| 2196 |
reposMustHaveTrackingBranch = True |
| 2197 |
elif inOptions.doPush: |
| 2198 |
print("\nDoing a push so all repos must be on a branch and have a " |
| 2199 |
"tracking branch!") |
| 2200 |
reposMustHaveTrackingBranch = True |
| 2201 |
else: |
| 2202 |
print("\nNo need for repos to be on a branch with a tracking branch!") |
| 2203 |
reposMustHaveTrackingBranch = False |
| 2204 |
|
| 2205 |
# Assert that all of the repos are on a branch with a tracking branch |
| 2206 |
if reposMustHaveTrackingBranch: |
| 2207 |
repoIdx = 0 |
| 2208 |
for gitRepo in tribitsGitRepos.gitRepoList(): |
| 2209 |
assertRepoHasBranchAndTrackingBranch(inOptions, gitRepo) |
| 2210 |
|
| 2211 |
print("\n***") |
| 2212 |
print("*** 3) Pull updated commits for %s ..." % inOptions.projectName) |
| 2213 |
print("***") |
| 2214 |
|
| 2215 |
reposAreClean = True |
| 2216 |
pullPassed = True |
| 2217 |
|
| 2218 |
doingAtLeastOnePull = inOptions.doPull |
| 2219 |
|
| 2220 |
pulledSomeChanges = False |
| 2221 |
pulledSomeExtraChanges = False |
| 2222 |
|
| 2223 |
if not doingAtLeastOnePull: |
| 2224 |
|
| 2225 |
print("\nSkipping all pulls on request!\n") |
| 2226 |
|
| 2227 |
if doingAtLeastOnePull and pullPassed: |
| 2228 |
|
| 2229 |
# |
| 2230 |
print("\n3.a) Check that there are no uncommitted and no new unknown " |
| 2231 |
"files before doing the pull(s) ...\n") |
| 2232 |
# |
| 2233 |
|
| 2234 |
repoIdx = 0 |
| 2235 |
print(tribitsGitRepos.gitRepoList()) |
| 2236 |
for gitRepo in tribitsGitRepos.gitRepoList(): |
| 2237 |
|
| 2238 |
print("\n3.a." + str(repoIdx) + ") Git Repo: '" + gitRepo.repoName + |
| 2239 |
"'") |
| 2240 |
|
| 2241 |
# See if the repo is clean |
| 2242 |
|
| 2243 |
if gitRepo.gitRepoStats.numModifiedInt() > 0: |
| 2244 |
repoNotCleanMsg = "\nERROR: There are changed uncommitted files => cannot continue!" |
| 2245 |
reposAreClean = False |
| 2246 |
|
| 2247 |
if gitRepo.gitRepoStats.numUntrackedInt() > 0: |
| 2248 |
repoNotCleanMsg = "\nERROR: There are newly created uncommitted files => Cannot continue!" |
| 2249 |
reposAreClean = False |
| 2250 |
|
| 2251 |
if not reposAreClean: |
| 2252 |
print(repoNotCleanMsg) |
| 2253 |
gitStatusOutput = getCmndOutput(inOptions.git+" status", True, throwOnError=False, |
| 2254 |
workingDir=getGitRepoDir(inOptions.srcDir, gitRepo.repoDir)) |
| 2255 |
print( |
| 2256 |
"\nOutput from 'git status':\n" + |
| 2257 |
"\n--------------------------------------------------------------\n" + |
| 2258 |
gitStatusOutput + |
| 2259 |
"\n--------------------------------------------------------------\n") |
| 2260 |
print( |
| 2261 |
"\nExplanation: In order to do a meaningful test to allow a push, all files\n" |
| 2262 |
"in the local repo must be committed. Otherwise, if there are changed but not\n" |
| 2263 |
"committed files or new unknown files that are used in the build or the test, then\n" |
| 2264 |
"what you are testing is *not* what you will be pushing. If you have changes that\n" |
| 2265 |
"you don't want to push, then try using 'git stash' before you run this script to\n" |
| 2266 |
"stash away all of the changes you don't want to push. That way, what you are testing\n" |
| 2267 |
"will be consistent with what you will be pushing.\n") |
| 2268 |
pullPassed = False |
| 2269 |
|
| 2270 |
#print("gitRepo =", gitRepo) |
| 2271 |
repoIdx += 1 |
| 2272 |
|
| 2273 |
if doingAtLeastOnePull and pullPassed: |
| 2274 |
|
| 2275 |
# NOTE: We want to pull first from the global repo and then from the |
| 2276 |
# extra repo so the extra repo's revisions will get rebased on top of |
| 2277 |
# the others. This is what you would want and expect for the remote |
| 2278 |
# test/push process where multiple pulls may be needed before it works. |
| 2279 |
|
| 2280 |
# |
| 2281 |
print("\n3.b) Pull updates from remote tracking branch ...") |
| 2282 |
# |
| 2283 |
|
| 2284 |
if inOptions.doPull and pullPassed: |
| 2285 |
repoIdx = 0 |
| 2286 |
for gitRepo in tribitsGitRepos.gitRepoList(): |
| 2287 |
print("\n3.b." + str(repoIdx) + ") Git Repo: " + gitRepo.repoName) |
| 2288 |
echoChDir(baseTestDir) |
| 2289 |
(pullRtn, pullTimings, pullGotChanges) = executePull( |
| 2290 |
gitRepo, |
| 2291 |
inOptions, baseTestDir, |
| 2292 |
getInitialPullOutputFileName(gitRepo.repoName)) |
| 2293 |
if pullGotChanges: |
| 2294 |
pulledSomeChanges = True |
| 2295 |
timings.pull += pullTimings |
| 2296 |
if pullRtn != 0: |
| 2297 |
print("\nPull failed!\n") |
| 2298 |
pullPassed = False |
| 2299 |
break |
| 2300 |
repoIdx += 1 |
| 2301 |
else: |
| 2302 |
print("\nSkipping initial pull from remote tracking branch!\n") |
| 2303 |
|
| 2304 |
# |
| 2305 |
print("\n3.c) Pull extra updates for --extra-pull-from='" + |
| 2306 |
inOptions.extraPullFrom + "' ...") |
| 2307 |
# |
| 2308 |
|
| 2309 |
timings.pull = 0 |
| 2310 |
|
| 2311 |
if inOptions.extraPullFrom and pullPassed: |
| 2312 |
repoExtraRemotePullsList = \ |
| 2313 |
parseExtraPullFromArgs(tribitsGitRepos.gitRepoList(), inOptions.extraPullFrom) |
| 2314 |
repoIdx = 0 |
| 2315 |
for repoExtraRemotePulls in repoExtraRemotePullsList: |
| 2316 |
gitRepo = repoExtraRemotePulls.gitRepo |
| 2317 |
remoteRepoAndBranchList = repoExtraRemotePulls.remoteRepoAndBranchList |
| 2318 |
if not remoteRepoAndBranchList: |
| 2319 |
continue |
| 2320 |
print("\n3.c." + str(repoIdx) + ") Git Repo: " + gitRepo.repoName) |
| 2321 |
echoChDir(baseTestDir) |
| 2322 |
for remoteRepoAndBranch in remoteRepoAndBranchList: |
| 2323 |
(pullRtn, pullTimings, pullGotChanges) = executePull( |
| 2324 |
gitRepo, |
| 2325 |
inOptions, baseTestDir, |
| 2326 |
getInitialExtraPullOutputFileName(gitRepo.repoName), |
| 2327 |
remoteRepoAndBranch ) |
| 2328 |
if pullGotChanges: |
| 2329 |
pulledSomeChanges = True |
| 2330 |
pulledSomeExtraChanges = True |
| 2331 |
timings.pull += pullTimings |
| 2332 |
if pullRtn != 0: |
| 2333 |
print("\nPull failed!\n") |
| 2334 |
pullPassed = False |
| 2335 |
break |
| 2336 |
if pullRtn != 0: |
| 2337 |
break |
| 2338 |
repoIdx += 1 |
| 2339 |
else: |
| 2340 |
print("\nSkipping extra pull from '" + inOptions.extraPullFrom + "'!\n") |
| 2341 |
|
| 2342 |
# Given overall status of the pulls and determine if to abort gracefully |
| 2343 |
if pulledSomeChanges: |
| 2344 |
print("\nThere where at least some changes pulled!") |
| 2345 |
else: |
| 2346 |
print("\nNo changes were pulled!") |
| 2347 |
|
| 2348 |
# Determine if extra changes were pulled and if to get repo status again |
| 2349 |
if pulledSomeExtraChanges: |
| 2350 |
print("\nExtra pull pulled new commits so need to get repo status " |
| 2351 |
"again ...\n") |
| 2352 |
if getReposStats(inOptions, tribitsGitRepos): |
| 2353 |
hasChangesToPush = True |
| 2354 |
|
| 2355 |
# |
| 2356 |
print("\nDetermine overall pull pass/fail ...\n") |
| 2357 |
# |
| 2358 |
|
| 2359 |
echoChDir(baseTestDir) |
| 2360 |
|
| 2361 |
# Check for prior successful initial pull |
| 2362 |
currentSuccessfullPullExists = os.path.exists(getInitialPullSuccessFileName()) |
| 2363 |
|
| 2364 |
if inOptions.doPull: |
| 2365 |
if pullPassed: |
| 2366 |
print("\nPull passed!\n") |
| 2367 |
echoRunSysCmnd("touch "+getInitialPullSuccessFileName()) |
| 2368 |
else: |
| 2369 |
print("\nPull failed!\n") |
| 2370 |
elif currentSuccessfullPullExists: |
| 2371 |
print("\nA previous pull was performed and was successful!") |
| 2372 |
pullPassed = True |
| 2373 |
elif inOptions.allowNoPull: |
| 2374 |
print("\nNot performing pull since --allow-no-pull was passed in\n") |
| 2375 |
pullPassed = True |
| 2376 |
else: |
| 2377 |
print("\nNo previous successful pull is still current!") |
| 2378 |
pullPassed = False |
| 2379 |
|
| 2380 |
# Update for current successful pull |
| 2381 |
currentSuccessfullPullExists = os.path.exists(getInitialPullSuccessFileName()) |
| 2382 |
|
| 2383 |
|
| 2384 |
print("\n***") |
| 2385 |
print("*** 4) Get the list of all the modified files ...") |
| 2386 |
print("***") |
| 2387 |
|
| 2388 |
if pullPassed: |
| 2389 |
if gitDiffsWrtTrackingBranchAreNeeded: |
| 2390 |
for gitRepo in tribitsGitRepos.gitRepoList(): |
| 2391 |
getCurrentDiffOutputAndLogModified(inOptions, gitRepo, baseTestDir) |
| 2392 |
else: |
| 2393 |
print("\nSkipping getting list of modified files because not " |
| 2394 |
"needed!\n") |
| 2395 |
else: |
| 2396 |
print("\nSkipping getting list of modified files because pull failed!\n") |
| 2397 |
|
| 2398 |
|
| 2399 |
print("\n***") |
| 2400 |
print("*** 5) Running the different build/test cases ...") |
| 2401 |
print("***") |
| 2402 |
|
| 2403 |
# Determine if we will run the build/test cases or not |
| 2404 |
|
| 2405 |
# Set runBuildCases flag and other logic |
| 2406 |
abortGracefullyDueToNoUpdates = False |
| 2407 |
abortGracefullyDueToNoChangesToPush = False |
| 2408 |
if not performAnyBuildTestActions(inOptions): |
| 2409 |
print("\nNot performing any build cases because no --configure, " + |
| 2410 |
"--build or --test was specified!\n") |
| 2411 |
runBuildCases = False |
| 2412 |
elif doingAtLeastOnePull: |
| 2413 |
if reposAreClean and not pulledSomeChanges and \ |
| 2414 |
inOptions.abortGracefullyIfNoChangesPulled \ |
| 2415 |
: |
| 2416 |
print("\nNot performing any build cases because pull did not bring " |
| 2417 |
"any *new* commits and --abort-gracefully-if-no-changes-pulled " |
| 2418 |
"was set!\n") |
| 2419 |
abortGracefullyDueToNoUpdates = True |
| 2420 |
runBuildCases = False |
| 2421 |
elif reposAreClean and not hasChangesToPush and \ |
| 2422 |
inOptions.abortGracefullyIfNoChangesToPush \ |
| 2423 |
: |
| 2424 |
print("\nNot performing any build cases because there are no local " |
| 2425 |
"changes to push and --abort-gracefully-if-no-changes-to-push!\n") |
| 2426 |
abortGracefullyDueToNoChangesToPush = True |
| 2427 |
runBuildCases = False |
| 2428 |
elif pullPassed: |
| 2429 |
print("\nThe pull passed, running the build/test cases ...\n") |
| 2430 |
runBuildCases = True |
| 2431 |
else: |
| 2432 |
print("\nNot running any build/test cases because the pull failed!\n") |
| 2433 |
runBuildCases = False |
| 2434 |
else: |
| 2435 |
if inOptions.allowNoPull: |
| 2436 |
print("\nNo pull was attempted but we are running the build/test cases " |
| 2437 |
"anyway because --allow-no-pull was specified ...\n") |
| 2438 |
runBuildCases = True |
| 2439 |
elif os.path.exists(getInitialPullSuccessFileName()): |
| 2440 |
print("\nA previous pull was successful, running build/test cases " |
| 2441 |
"...!\n") |
| 2442 |
runBuildCases = True |
| 2443 |
else: |
| 2444 |
print("\nNot running any build/test cases because no pull was " |
| 2445 |
"attempted!\n\nHint: Use --allow-no-pull to allow build/test " |
| 2446 |
"cases to run without having to do a pull first!") |
| 2447 |
runBuildCases = False |
| 2448 |
|
| 2449 |
# Run the build/test cases |
| 2450 |
|
| 2451 |
buildTestCasesPassed = True |
| 2452 |
|
| 2453 |
if runBuildCases: |
| 2454 |
|
| 2455 |
echoChDir(baseTestDir) |
| 2456 |
|
| 2457 |
writeDefaultCommonConfigFile() |
| 2458 |
|
| 2459 |
print("\nSetting up to run the build/test cases:") |
| 2460 |
for i in range(len(buildTestCaseList)): |
| 2461 |
buildTestCase = buildTestCaseList[i] |
| 2462 |
print(str(i) + ") " + buildTestCase.name + ": ", end="") |
| 2463 |
if buildTestCase.runBuildTestCase: |
| 2464 |
print("Will attempt to run!") |
| 2465 |
else: |
| 2466 |
print("Will *not* attempt to run on request!") |
| 2467 |
|
| 2468 |
for buildTestCase in buildTestCaseList: |
| 2469 |
buildTestCase.timings = timings.deepCopy() |
| 2470 |
result = runBuildTestCaseDriver( |
| 2471 |
inOptions, |
| 2472 |
tribitsGitRepos, |
| 2473 |
baseTestDir, |
| 2474 |
buildTestCase, |
| 2475 |
buildTestCase.timings |
| 2476 |
) |
| 2477 |
if not result: |
| 2478 |
buildTestCasesPassed = False |
| 2479 |
success = False |
| 2480 |
|
| 2481 |
|
| 2482 |
print("\n***") |
| 2483 |
print("*** 6) Determine overall success and push readiness ...") |
| 2484 |
print("***") |
| 2485 |
|
| 2486 |
okayToCommit = False |
| 2487 |
okayToPush = False |
| 2488 |
forcedCommitPush = False |
| 2489 |
abortedCommitPush = False |
| 2490 |
atLeastOneConfigureBuildAttemptPassed = False |
| 2491 |
|
| 2492 |
if inOptions.doPushReadinessCheck: |
| 2493 |
|
| 2494 |
echoChDir(baseTestDir) |
| 2495 |
|
| 2496 |
okayToCommit = success |
| 2497 |
subjectLine = None |
| 2498 |
|
| 2499 |
commitEmailBodyExtra = "" |
| 2500 |
shortCommitEmailBodyExtra = "" |
| 2501 |
|
| 2502 |
(cmakePkgOptions, enabledPackagesList) = \ |
| 2503 |
getEnablesLists(inOptions, allValidPackageTypesList, False, False, |
| 2504 |
tribitsGitRepos, baseTestDir, False) |
| 2505 |
|
| 2506 |
enableStatsListStr = getEnableStatusList(inOptions, enabledPackagesList) |
| 2507 |
commitEmailBodyExtra += enableStatsListStr |
| 2508 |
shortCommitEmailBodyExtra += enableStatsListStr |
| 2509 |
|
| 2510 |
commitEmailBodyExtra += \ |
| 2511 |
"\nBuild test results:" \ |
| 2512 |
"\n-------------------\n" |
| 2513 |
|
| 2514 |
for i in range(len(buildTestCaseList)): |
| 2515 |
buildTestCase = buildTestCaseList[i] |
| 2516 |
buildTestCaseName = buildTestCase.name |
| 2517 |
(buildTestCaseActionsPass, buildTestCaseOkayToCommit, statusMsg, timeInMin) = \ |
| 2518 |
checkBuildTestCaseStatus(buildTestCase, inOptions) |
| 2519 |
buildTestCaseStatusStr = str(i)+") "+buildTestCaseName+" => "+statusMsg |
| 2520 |
if not buildTestCaseOkayToCommit: |
| 2521 |
buildTestCaseStatusStr += " => Not ready to push!" |
| 2522 |
buildTestCaseStatusStr += " ("+formatMinutesStr(timeInMin)+")\n" |
| 2523 |
print(buildTestCaseStatusStr) |
| 2524 |
commitEmailBodyExtra += buildTestCaseStatusStr |
| 2525 |
shortCommitEmailBodyExtra += buildTestCaseStatusStr |
| 2526 |
#print("buildTestCaseActionsPass =", buildTestCaseActionsPass) |
| 2527 |
if not buildTestCaseActionsPass: |
| 2528 |
success = False |
| 2529 |
if not buildTestCaseOkayToCommit: |
| 2530 |
okayToCommit = False |
| 2531 |
#print("buildTestCaseOkayToCommit =", buildTestCaseOkayToCommit) |
| 2532 |
if buildTestCase.runBuildTestCase and buildTestCaseOkayToCommit \ |
| 2533 |
and not buildTestCase.skippedConfigureDueToNoEnables \ |
| 2534 |
: |
| 2535 |
#print("Setting atLeastOneConfigureBuildAttemptPassed=True") |
| 2536 |
atLeastOneConfigureBuildAttemptPassed = True |
| 2537 |
|
| 2538 |
if not atLeastOneConfigureBuildAttemptPassed: |
| 2539 |
print("\nThere were no successful attempts to configure/build/test!") |
| 2540 |
okayToCommit = False |
| 2541 |
|
| 2542 |
if not okayToCommit: |
| 2543 |
print("\nAt least one of the actions (pull, configure, built, test)" |
| 2544 |
" failed or was not performed correctly!\n") |
| 2545 |
|
| 2546 |
# Determine if we should do a forced push |
| 2547 |
if inOptions.doPushReadinessCheck and not okayToCommit and inOptions.forcePush \ |
| 2548 |
: |
| 2549 |
forcedPushMsg = \ |
| 2550 |
"\n***" \ |
| 2551 |
"\n*** WARNING: The acceptance criteria for doing a push has *not*" \ |
| 2552 |
"\n*** been met, but a push is being forced anyway by --force-push!" \ |
| 2553 |
"\n***\n" |
| 2554 |
print(forcedPushMsg) |
| 2555 |
okayToCommit = True |
| 2556 |
forcedCommitPush = True |
| 2557 |
|
| 2558 |
# Determine if a push is ready to try or not |
| 2559 |
|
| 2560 |
if okayToCommit: |
| 2561 |
if currentSuccessfullPullExists: |
| 2562 |
print("\nA current successful pull also exists => Ready for final " |
| 2563 |
"push!\n") |
| 2564 |
okayToPush = True |
| 2565 |
else: |
| 2566 |
commitEmailBodyExtra += \ |
| 2567 |
"\nA current successful pull does *not* exist => Not ready for final push!\n" \ |
| 2568 |
"\nExplanation: In order to safely push, the local working directory needs\n" \ |
| 2569 |
"to be up-to-date with the global repo or a full integration has not been\n" \ |
| 2570 |
"performed!\n" |
| 2571 |
print(commitEmailBodyExtra) |
| 2572 |
okayToPush = False |
| 2573 |
abortedCommitPush = True |
| 2574 |
else: |
| 2575 |
okayToPush = False |
| 2576 |
|
| 2577 |
if okayToPush: |
| 2578 |
print("\n => A PUSH IS READY TO BE PERFORMED!") |
| 2579 |
else: |
| 2580 |
print("\n => A PUSH IS *NOT* READY TO BE PERFORMED!") |
| 2581 |
|
| 2582 |
else: |
| 2583 |
|
| 2584 |
print("\nSkipping push readiness check on request!") |
| 2585 |
okayToCommit = False |
| 2586 |
okayToPush = False |
| 2587 |
|
| 2588 |
|
| 2589 |
print("\n***") |
| 2590 |
print("*** 7) Do final push ...") |
| 2591 |
print("***") |
| 2592 |
|
| 2593 |
# Attempt the final pull, commit amend, and push |
| 2594 |
|
| 2595 |
pullFinalPassed = True |
| 2596 |
amendFinalCommitPassed = True |
| 2597 |
pushPassed = True |
| 2598 |
didPush = False |
| 2599 |
|
| 2600 |
if not inOptions.doPush: |
| 2601 |
|
| 2602 |
print("\nNot doing the push but sending an email" |
| 2603 |
" about the commit/push readiness status ...") |
| 2604 |
|
| 2605 |
if okayToPush: |
| 2606 |
subjectLine = "READY TO PUSH" |
| 2607 |
else: |
| 2608 |
subjectLine = "NOT READY TO PUSH" |
| 2609 |
|
| 2610 |
elif not okayToPush: |
| 2611 |
|
| 2612 |
print("\nNot performing push due to prior errors\n") |
| 2613 |
pushPassed = False |
| 2614 |
|
| 2615 |
else: # inOptions.doPush and okayToPush: |
| 2616 |
|
| 2617 |
# |
| 2618 |
print("\n7.a) Performing a final pull to make sure there are no " |
| 2619 |
"conflicts for push ...\n") |
| 2620 |
# |
| 2621 |
|
| 2622 |
if not okayToPush: |
| 2623 |
|
| 2624 |
print("\nSkippng final pull due to prior errors!\n") |
| 2625 |
pullFinalPassed = False |
| 2626 |
|
| 2627 |
else: |
| 2628 |
|
| 2629 |
print("\nExplanation: In order to push, the local repo needs to be " |
| 2630 |
"up-to-date\nwith the global repo or the push will not be " |
| 2631 |
"allowed. Therefore, a pull\nbefore the push must be performed " |
| 2632 |
"if there are updates in the global reop\nregardless if --pull " |
| 2633 |
"was specified or not. Also, a rebase might be done in\norder " |
| 2634 |
"to get a linear history required by the hooks in the main " |
| 2635 |
"repository.\n") |
| 2636 |
|
| 2637 |
doFinalRebase = inOptions.rebase |
| 2638 |
if not doFinalRebase: |
| 2639 |
print("Skipping the final rebase on request! (see --no-rebase " |
| 2640 |
"option)") |
| 2641 |
|
| 2642 |
pullFinalPassed = True |
| 2643 |
|
| 2644 |
repoIdx = 0 |
| 2645 |
for gitRepo in tribitsGitRepos.gitRepoList(): |
| 2646 |
|
| 2647 |
print("\n7.a." + str(repoIdx) + ") Git Repo: '" + gitRepo.repoName + |
| 2648 |
"'") |
| 2649 |
|
| 2650 |
(pull2Rtn, pull2Time, pullGotChanges) = \ |
| 2651 |
executePull(gitRepo, inOptions, baseTestDir, |
| 2652 |
getFinalPullOutputFileName(gitRepo.repoName), None, |
| 2653 |
doFinalRebase ) |
| 2654 |
|
| 2655 |
if pull2Rtn != 0: |
| 2656 |
pullFinalPassed = False |
| 2657 |
break |
| 2658 |
|
| 2659 |
repoIdx += 1 |
| 2660 |
|
| 2661 |
if pullFinalPassed: |
| 2662 |
print("\nFinal pull passed!\n") |
| 2663 |
else: |
| 2664 |
print("\nFinal pull failed!\n") |
| 2665 |
|
| 2666 |
if not pullFinalPassed: okayToPush = False |
| 2667 |
|
| 2668 |
# |
| 2669 |
print("\n7.b) Amending the final commit message by appending test " |
| 2670 |
"results ...\n") |
| 2671 |
# |
| 2672 |
|
| 2673 |
if not inOptions.appendTestResults: |
| 2674 |
|
| 2675 |
print("\nSkipping appending test results on request (--no-append-test-" |
| 2676 |
"results)!\n") |
| 2677 |
|
| 2678 |
elif not okayToPush: |
| 2679 |
|
| 2680 |
print("\nSkippng appending test results due to prior errors!\n") |
| 2681 |
amendFinalCommitPassed = False |
| 2682 |
|
| 2683 |
else: # inOptions.appendTestResults and okayToPush |
| 2684 |
|
| 2685 |
print("\nAttempting to amend the final commit message ...\n") |
| 2686 |
|
| 2687 |
repoIdx = 0 |
| 2688 |
for gitRepo in tribitsGitRepos.gitRepoList(): |
| 2689 |
|
| 2690 |
print("\n7.b." + str(repoIdx) + ") Git Repo: '" + gitRepo.repoName + |
| 2691 |
"'") |
| 2692 |
|
| 2693 |
try: |
| 2694 |
|
| 2695 |
if gitRepo.gitRepoStats.numCommitsInt() > 0: |
| 2696 |
|
| 2697 |
# Get info about current commit and local commits |
| 2698 |
lastCommitMessageStr = getLastCommitMessageStr(inOptions, gitRepo) |
| 2699 |
localCommitSHA1ListStr = getLocalCommitsSHA1ListStr(inOptions, gitRepo) |
| 2700 |
|
| 2701 |
# Get then final commit message |
| 2702 |
finalCommitEmailBodyStr = lastCommitMessageStr |
| 2703 |
finalCommitEmailBodyStr += getAutomatedStatusSummaryHeaderStr() |
| 2704 |
finalCommitEmailBodyStr += shortCommitEmailBodyExtra |
| 2705 |
finalCommitEmailBodyStr += localCommitSHA1ListStr |
| 2706 |
if forcedCommitPush: |
| 2707 |
finalCommitEmailBodyStr += "WARNING: Forced the push!\n" |
| 2708 |
finalCommitEmailBodyFileName = getFinalCommitBodyFileName(gitRepo.repoName) |
| 2709 |
writeStrToFile(finalCommitEmailBodyFileName, finalCommitEmailBodyStr) |
| 2710 |
|
| 2711 |
# Amend the final commit message |
| 2712 |
commitAmendRtn = echoRunSysCmnd( |
| 2713 |
inOptions.git+" commit --amend" \ |
| 2714 |
" -F "+os.path.join(baseTestDir, finalCommitEmailBodyFileName), |
| 2715 |
workingDir=getGitRepoDir(inOptions.srcDir, gitRepo.repoDir), |
| 2716 |
outFile=os.path.join(baseTestDir, getFinalCommitOutputFileName(gitRepo.repoName)), |
| 2717 |
timeCmnd=True, throwExcept=False |
| 2718 |
) |
| 2719 |
|
| 2720 |
if commitAmendRtn != 0: |
| 2721 |
amendFinalCommitPassed = False |
| 2722 |
break |
| 2723 |
|
| 2724 |
else: |
| 2725 |
|
| 2726 |
print("\nSkipping amending last commit because there are no " |
| 2727 |
"local commits!\n") |
| 2728 |
|
| 2729 |
except Exception as e: |
| 2730 |
success = False |
| 2731 |
amendFinalCommitPassed = False |
| 2732 |
printStackTrace() |
| 2733 |
|
| 2734 |
repoIdx += 1 |
| 2735 |
|
| 2736 |
# end for |
| 2737 |
|
| 2738 |
if amendFinalCommitPassed: |
| 2739 |
print("\nAppending test results to last commit passed!\n") |
| 2740 |
else: |
| 2741 |
print("\nAppending test results to last commit failed!\n") |
| 2742 |
|
| 2743 |
if not amendFinalCommitPassed: okayToPush = False |
| 2744 |
|
| 2745 |
# End final pull and amend commit message block |
| 2746 |
|
| 2747 |
# Jump out if the above if block and get the list of local commits. You |
| 2748 |
# have to get this list after a final rebase and after the top commit is |
| 2749 |
# amended so that you get the right SHA1s. But you have to do this |
| 2750 |
# *before* the push or there will not be any local commits! |
| 2751 |
allLocalCommitSummariesStr = "" |
| 2752 |
if inOptions.doPushReadinessCheck: |
| 2753 |
repoIdx = 0 |
| 2754 |
for gitRepo in tribitsGitRepos.gitRepoList(): |
| 2755 |
localCommitSummariesStr = \ |
| 2756 |
getLocalCommitsSummariesStr(inOptions, gitRepo) |
| 2757 |
if allLocalCommitSummariesStr: |
| 2758 |
allLocalCommitSummariesStr += ("\n" + localCommitSummariesStr) |
| 2759 |
else: |
| 2760 |
allLocalCommitSummariesStr = localCommitSummariesStr |
| 2761 |
repoIdx += 1 |
| 2762 |
|
| 2763 |
# Jump back into the push block and do the actual push |
| 2764 |
if inOptions.doPush: |
| 2765 |
|
| 2766 |
# |
| 2767 |
print("\n7.c) Pushing the the local commits to the global repo ...\n") |
| 2768 |
# |
| 2769 |
|
| 2770 |
if not okayToPush: |
| 2771 |
|
| 2772 |
print("\nNot performing push due to prior errors!\n") |
| 2773 |
pushPassed = False |
| 2774 |
|
| 2775 |
else: |
| 2776 |
|
| 2777 |
print("\nAttempting to do the push ...") |
| 2778 |
|
| 2779 |
debugSkipPush = os.environ.get("CHECKIN_TEST_SKIP_PUSH","") |
| 2780 |
#print("debugSkipPush =", debugSkipPush) |
| 2781 |
#debugSkipPush = True |
| 2782 |
|
| 2783 |
repoIdx = 0 |
| 2784 |
for gitRepo in tribitsGitRepos.gitRepoList(): |
| 2785 |
|
| 2786 |
print("\n7.c." + str(repoIdx) + ") Git Repo: '" + gitRepo.repoName + |
| 2787 |
"'") |
| 2788 |
|
| 2789 |
if gitRepo.gitRepoStats.numCommitsInt() > 0: |
| 2790 |
|
| 2791 |
if not debugSkipPush: |
| 2792 |
pushRtn = echoRunSysCmnd( |
| 2793 |
inOptions.git+" push "+pushToTrackingBranchArgs(gitRepo), |
| 2794 |
workingDir=getGitRepoDir(inOptions.srcDir, gitRepo.repoDir), |
| 2795 |
outFile=os.path.join(baseTestDir, getPushOutputFileName(gitRepo.repoName)), |
| 2796 |
throwExcept=False, timeCmnd=True ) |
| 2797 |
didAtLeastOnePush = True |
| 2798 |
else: |
| 2799 |
print("\nSkipping push due to debug override ...") |
| 2800 |
pushRtn = 0 |
| 2801 |
|
| 2802 |
if pushRtn != 0: |
| 2803 |
pushPassed = False |
| 2804 |
break |
| 2805 |
|
| 2806 |
else: |
| 2807 |
|
| 2808 |
print("\nSkipping push to '" + gitRepo.repoName + "' because " + |
| 2809 |
"there are no commits!") |
| 2810 |
|
| 2811 |
repoIdx += 1 |
| 2812 |
|
| 2813 |
# end for |
| 2814 |
|
| 2815 |
if pushPassed: |
| 2816 |
if didAtLeastOnePush: |
| 2817 |
print("\nPush passed!\n") |
| 2818 |
didPush = True |
| 2819 |
else: |
| 2820 |
print("\nPush failed because the push was never attempted!") |
| 2821 |
else: |
| 2822 |
print("\nPush failed!\n") |
| 2823 |
|
| 2824 |
if not pushPassed: okayToPush = False |
| 2825 |
|
| 2826 |
# End push block |
| 2827 |
|
| 2828 |
print("\n***") |
| 2829 |
print("*** 8) Set up to run execute extra command on ready to push ...") |
| 2830 |
print("***") |
| 2831 |
|
| 2832 |
if inOptions.executeOnReadyToPush and not okayToPush: |
| 2833 |
|
| 2834 |
print("\nNot executing final command (" + inOptions.executeOnReadyToPush + |
| 2835 |
") since a push is not okay to be performed!\n") |
| 2836 |
|
| 2837 |
elif inOptions.executeOnReadyToPush and okayToPush: |
| 2838 |
|
| 2839 |
executeCmndStr = "\nExecuting final command ("+inOptions.executeOnReadyToPush+") since" \ |
| 2840 |
+" a push is okay to be performed!\n" |
| 2841 |
commitEmailBodyExtra += executeCmndStr |
| 2842 |
print(executeCmndStr) |
| 2843 |
|
| 2844 |
else: |
| 2845 |
|
| 2846 |
print("\nNot executing final command since none was given ...\n") |
| 2847 |
|
| 2848 |
|
| 2849 |
print("\n***") |
| 2850 |
print("*** 9) Create and send push (or readiness status) notification email ...") |
| 2851 |
print("***\n") |
| 2852 |
|
| 2853 |
allConfiguresAbortedDueToNoEnablesGracefullAbort = False |
| 2854 |
|
| 2855 |
if inOptions.doPushReadinessCheck: |
| 2856 |
|
| 2857 |
# |
| 2858 |
print("\n9.a) Getting final status to send out in the summary email ...\n") |
| 2859 |
# |
| 2860 |
|
| 2861 |
grepCheckinTestOutForFailed_msg = \ |
| 2862 |
"\n\nTo find out more about this failure, grep the 'checkin-test.out' log" \ |
| 2863 |
" file for 'failed'. In some cases, the failure will be obvious. In other" \ |
| 2864 |
" cases, a system command failed and the details about the failure will be in" \ |
| 2865 |
" the output file for the command that failed.\n\n" |
| 2866 |
|
| 2867 |
# Determine if all configures were aborted because no package enables |
| 2868 |
allConfiguresAbortedDueToNoEnablesGracefullAbort = True |
| 2869 |
for buildTestCase in buildTestCaseList: |
| 2870 |
if not buildTestCase.skippedConfigureDueToNoEnables: |
| 2871 |
allConfiguresAbortedDueToNoEnablesGracefullAbort = False |
| 2872 |
|
| 2873 |
if not pullPassed: |
| 2874 |
subjectLine = "INITIAL PULL FAILED" |
| 2875 |
commitEmailBodyExtra += "\n\nFailed because initial pull failed!" \ |
| 2876 |
+grepCheckinTestOutForFailed_msg |
| 2877 |
success = False |
| 2878 |
elif abortGracefullyDueToNoUpdates: |
| 2879 |
subjectLine = "ABORTED DUE TO NO UPDATES" |
| 2880 |
commitEmailBodyExtra += "\n\nAborted because no updates and --abort-gracefully-if-no-changes-pulled was set!\n\n" |
| 2881 |
success = True |
| 2882 |
elif abortGracefullyDueToNoChangesToPush: |
| 2883 |
subjectLine = "ABORTED DUE TO NO CHANGES TO PUSH" |
| 2884 |
commitEmailBodyExtra += "\n\nAborted because no changes to push and --abort-gracefully-if-no-changes-to-push was set!\n\n" |
| 2885 |
success = True |
| 2886 |
elif allConfiguresAbortedDueToNoEnablesGracefullAbort: |
| 2887 |
subjectLine = "ABORTED DUE TO NO ENABLES" |
| 2888 |
commitEmailBodyExtra += "\n\nAborted because no enables and --abort-gracefully-if-no-enables was set!\n\n" |
| 2889 |
success = True |
| 2890 |
elif not pullFinalPassed: |
| 2891 |
subjectLine = "FINAL PULL FAILED" |
| 2892 |
commitEmailBodyExtra += "\n\nFailed because the final pull failed!" \ |
| 2893 |
+grepCheckinTestOutForFailed_msg |
| 2894 |
success = False |
| 2895 |
elif not amendFinalCommitPassed: |
| 2896 |
subjectLine = "AMEND COMMIT FAILED" |
| 2897 |
commitEmailBodyExtra += "\n\nFailed because the final test commit amend failed!" \ |
| 2898 |
+grepCheckinTestOutForFailed_msg |
| 2899 |
success = False |
| 2900 |
elif inOptions.doPush and pushPassed and forcedCommitPush: |
| 2901 |
subjectLine = "DID FORCED PUSH" |
| 2902 |
commitEmailBodyExtra += forcedPushMsg |
| 2903 |
success = True |
| 2904 |
commitEmailBodyExtra += forcedPushMsg |
| 2905 |
elif not buildTestCasesPassed: |
| 2906 |
subjectLine = "FAILED CONFIGURE/BUILD/TEST" |
| 2907 |
commitEmailBodyExtra += "\n\nFailed because one of the build/test cases failed!\n" |
| 2908 |
success = False |
| 2909 |
elif inOptions.doPush: |
| 2910 |
if didPush and not forcedCommitPush: |
| 2911 |
subjectLine = "DID PUSH" |
| 2912 |
elif abortedCommitPush: |
| 2913 |
subjectLine = "ABORTED COMMIT/PUSH" |
| 2914 |
commitEmailBodyExtra += "\n\nCommit/push was never attempted since commit/push" \ |
| 2915 |
" criteria failed!\n\n" |
| 2916 |
success = False |
| 2917 |
else: |
| 2918 |
subjectLine = "PUSH FAILED" |
| 2919 |
commitEmailBodyExtra += "\n\nFailed because push failed!" \ |
| 2920 |
+grepCheckinTestOutForFailed_msg |
| 2921 |
success = False |
| 2922 |
else: |
| 2923 |
if okayToPush: |
| 2924 |
subjectLine = "PASSED (READY TO PUSH)" |
| 2925 |
else: |
| 2926 |
if success: |
| 2927 |
subjectLine = "PASSED" |
| 2928 |
else: |
| 2929 |
subjectLine = "FAILED" |
| 2930 |
subjectLine += " (NOT READY TO PUSH)" |
| 2931 |
|
| 2932 |
# |
| 2933 |
print("\n9.b) Create and send out push (or readiness status) notification email ...") |
| 2934 |
# |
| 2935 |
|
| 2936 |
subjectLine += ": %s: %s" % (inOptions.projectName, getHostname()) |
| 2937 |
|
| 2938 |
emailBodyStr = subjectLine + "\n\n" |
| 2939 |
emailBodyStr += getCmndOutput("date", True) + "\n\n" |
| 2940 |
emailBodyStr += commitEmailBodyExtra + "\n" |
| 2941 |
emailBodyStr += allLocalCommitSummariesStr + "\n" |
| 2942 |
emailBodyStr += getSummaryEmailSectionStr(inOptions, buildTestCaseList) |
| 2943 |
|
| 2944 |
print("\nCommit status email being sent:\n" |
| 2945 |
"--------------------------------\n\n\n\n" + emailBodyStr + |
| 2946 |
"\n\n\n\n") |
| 2947 |
|
| 2948 |
summaryCommitEmailBodyFileName = getCommitStatusEmailBodyFileName() |
| 2949 |
|
| 2950 |
writeStrToFile(summaryCommitEmailBodyFileName, emailBodyStr) |
| 2951 |
|
| 2952 |
if inOptions.sendEmailTo and abortGracefullyDueToNoUpdates: |
| 2953 |
|
| 2954 |
print("\nSkipping sending final email because there were no updates" |
| 2955 |
" and --abort-gracefully-if-no-changes-pulled was set!") |
| 2956 |
|
| 2957 |
elif inOptions.sendEmailTo and abortGracefullyDueToNoChangesToPush: |
| 2958 |
|
| 2959 |
print("\nSkipping sending final email because there are no local " |
| 2960 |
"changes to push and --abort-gracefully-if-no-changes-to-push " |
| 2961 |
"was set!") |
| 2962 |
|
| 2963 |
elif inOptions.sendEmailTo and allConfiguresAbortedDueToNoEnablesGracefullAbort: |
| 2964 |
|
| 2965 |
print("\nSkipping sending final email because there were no enables" |
| 2966 |
" and --abort-gracefully-if-no-enables was set!") |
| 2967 |
|
| 2968 |
elif inOptions.sendEmailTo and inOptions.sendEmailOnlyOnFailure and success: |
| 2969 |
|
| 2970 |
print("\nSkipping sending final email because it passed" |
| 2971 |
" and --send-email-only-on-failure was set!") |
| 2972 |
|
| 2973 |
elif inOptions.sendEmailTo: |
| 2974 |
|
| 2975 |
emailAddresses = getEmailAddressesSpaceString(inOptions.sendEmailTo) |
| 2976 |
if inOptions.sendEmailToOnPush and didPush: |
| 2977 |
emailAddresses += " " + getEmailAddressesSpaceString(inOptions.sendEmailToOnPush) |
| 2978 |
echoRunSysCmnd("mailx -s \""+subjectLine+"\" " \ |
| 2979 |
+emailAddresses+" < "+summaryCommitEmailBodyFileName) |
| 2980 |
|
| 2981 |
else: |
| 2982 |
|
| 2983 |
print("\nNot sending push readiness status email because --send-email-" |
| 2984 |
"to is empty!") |
| 2985 |
|
| 2986 |
else: |
| 2987 |
|
| 2988 |
print("\nNot performing push or sending out push readiness status on " |
| 2989 |
"request!") |
| 2990 |
|
| 2991 |
if pushPassed and didAtLeastOnePush and didPush: |
| 2992 |
cleanSuccessFiles(buildTestCaseList, inOptions, baseTestDir) |
| 2993 |
|
| 2994 |
print("\n***") |
| 2995 |
print("*** 10) Run execute extra command on ready to push ...") |
| 2996 |
print("***") |
| 2997 |
|
| 2998 |
if inOptions.executeOnReadyToPush and okayToPush: |
| 2999 |
|
| 3000 |
print(executeCmndStr) |
| 3001 |
|
| 3002 |
extraCommandRtn = echoRunSysCmnd( |
| 3003 |
inOptions.executeOnReadyToPush, |
| 3004 |
workingDir=baseTestDir, |
| 3005 |
outFile=os.path.join(baseTestDir, getExtraCommandOutputFileName()), |
| 3006 |
throwExcept=False, timeCmnd=True ) |
| 3007 |
|
| 3008 |
if extraCommandRtn == 0: |
| 3009 |
print("\nExtra command passed!\n") |
| 3010 |
else: |
| 3011 |
print("\nExtra command failed!\n") |
| 3012 |
success = False |
| 3013 |
|
| 3014 |
else: |
| 3015 |
|
| 3016 |
print("\nNot executing final command ...\n") |
| 3017 |
|
| 3018 |
|
| 3019 |
if not performAnyActions(inOptions) and not inOptions.doPush: |
| 3020 |
|
| 3021 |
print("\n***\n" |
| 3022 |
"*** WARNING: No actions were performed!\n" |
| 3023 |
"***\n" |
| 3024 |
"*** Hint: Specify --do-all to perform full integration pull/build/test\n" |
| 3025 |
"*** or --push to push the commits for a previously run test!\n" |
| 3026 |
"***\n\n") |
| 3027 |
|
| 3028 |
except Exception as e: |
| 3029 |
|
| 3030 |
success = False |
| 3031 |
printStackTrace() |
| 3032 |
|
| 3033 |
g_sysCmndInterceptor.assertAllCommandsRun() |
| 3034 |
|
| 3035 |
# Print the final status at the very end |
| 3036 |
if subjectLine: |
| 3037 |
print("\n\n" + subjectLine + "\n\n") |
| 3038 |
|
| 3039 |
return success |