| 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 |
# General scripting support |
| 13 |
# |
| 14 |
# NOTE: Included first to check the version of python! |
| 15 |
# |
| 16 |
|
| 17 |
from TribitsDependencies import getProjectDependenciesFromXmlFile |
| 18 |
from GeneralScriptSupport import * |
| 19 |
import time |
| 20 |
|
| 21 |
|
| 22 |
# |
| 23 |
# Default logic to determine if a changed file should trigger testing all of |
| 24 |
# the packages. |
| 25 |
# |
| 26 |
# In general, any file at the top level <projectDir>/ or under the |
| 27 |
# <projectDir>/cmake/ directory with the extension *.cmake is considered a |
| 28 |
# file that requires a global rebuild of all packages. However, there are a |
| 29 |
# few special files that we don't want to have to do a global rebuild for by |
| 30 |
# default. |
| 31 |
# |
| 32 |
# PackagesList.cmake: This file gets modified frequently to add new packages |
| 33 |
# and rearrange packages. We don't need to do a global rebuild because this |
| 34 |
# list of packages is validated if we do even a single rebuild. If a package |
| 35 |
# line gets removed, the code that reads the Dependencies.cmake files will |
| 36 |
# fail and stop. However, this has the risk that if only the test test |
| 37 |
# category changes (e.g. from 'ST' to 'PT') then this would not trigger a |
| 38 |
# rebuild. But if the package itself was also modified, then that would be |
| 39 |
# sufficient for testing. |
| 40 |
# |
| 41 |
# TPLsList.cmake: This file also gets modified frequently. We don't need to |
| 42 |
# enable all packages either for the same reason as for the PackagesList.cmake |
| 43 |
# file. |
| 44 |
# |
| 45 |
# cmake/ctest/: These drive nightly automated builds and should not require |
| 46 |
# testing every package. |
| 47 |
# |
| 48 |
# cmake/TPLs/*.cmake: Any FileTPLSOMETHING.cmake file is assumed not to be |
| 49 |
# needed for Primary Tested code and therefore does not need to trigger a |
| 50 |
# global rebuild. |
| 51 |
# |
| 52 |
|
| 53 |
class DefaultProjectCiFileChangeLogic: |
| 54 |
|
| 55 |
def isGlobalBuildFileRequiringGlobalRebuild(self, modifiedFileFullPath): |
| 56 |
modifiedFileFullPathArray = getFilePathArray(modifiedFileFullPath) |
| 57 |
if len(modifiedFileFullPathArray)==1: |
| 58 |
# Files sitting directly under <projectDir>/ |
| 59 |
if modifiedFileFullPathArray[0] == "CMakeLists.txt": |
| 60 |
return True |
| 61 |
if modifiedFileFullPathArray[0] == 'PackagesList.cmake': |
| 62 |
return False |
| 63 |
if modifiedFileFullPathArray[0] == 'TPLsList.cmake': |
| 64 |
return False |
| 65 |
if modifiedFileFullPathArray[0].rfind(".cmake") != -1: |
| 66 |
return True |
| 67 |
elif modifiedFileFullPathArray[0] == 'cmake': |
| 68 |
# Files under <projectDir>/cmake/ |
| 69 |
if modifiedFileFullPathArray[1]=='ExtraRepositoriesList.cmake': |
| 70 |
return False |
| 71 |
if modifiedFileFullPathArray[1] == 'ctest': |
| 72 |
return False |
| 73 |
if modifiedFileFullPathArray[1] == 'TPLs': |
| 74 |
return False |
| 75 |
if modifiedFileFullPath.rfind("UnitTests/") != -1: |
| 76 |
return False |
| 77 |
if modifiedFileFullPath.rfind(".cmake") != -1: |
| 78 |
return True |
| 79 |
return False |
| 80 |
|
| 81 |
|
| 82 |
def getProjectCiFileChangeLogic(projectDir): |
| 83 |
|
| 84 |
if not projectDir: |
| 85 |
return DefaultProjectCiFileChangeLogic() |
| 86 |
else: |
| 87 |
projectCiFileChangeLogicFileBaseDir = os.path.join(projectDir, "cmake") |
| 88 |
projectCiFileChangeLogicFile = os.path.join( |
| 89 |
projectCiFileChangeLogicFileBaseDir, "ProjectCiFileChangeLogic.py") |
| 90 |
if not os.path.isfile(projectCiFileChangeLogicFile): |
| 91 |
return DefaultProjectCiFileChangeLogic() |
| 92 |
|
| 93 |
# Else, if we get here, then the file |
| 94 |
# <projectDir>/cmake/ProjectCiFileChangeLogic.py exists so lets read it in! |
| 95 |
|
| 96 |
tribitsDirPath = os.path.abspath( |
| 97 |
os.path.join( |
| 98 |
os.path.dirname(os.path.abspath(__file__)), |
| 99 |
"../..", "tribits" |
| 100 |
) |
| 101 |
) |
| 102 |
|
| 103 |
old_sys_path = sys.path |
| 104 |
|
| 105 |
try: |
| 106 |
sys.path = [projectCiFileChangeLogicFileBaseDir] + sys.path |
| 107 |
import ProjectCiFileChangeLogic |
| 108 |
return ProjectCiFileChangeLogic.ProjectCiFileChangeLogic() |
| 109 |
finally: |
| 110 |
sys.path = old_sys_path |
| 111 |
|
| 112 |
|
| 113 |
def getPackageStructFromPath(projectDependencies, fullPath): |
| 114 |
packageName = getPackageNameFromPath(projectDependencies, fullPath) |
| 115 |
if packageName: |
| 116 |
return projectDependencies.getPackageByName(packageName) |
| 117 |
return None |
| 118 |
|
| 119 |
|
| 120 |
def getPackageNameFromPath(projectDependencies, fullPath): |
| 121 |
return projectDependencies.getPackageNameFromPath(fullPath) |
| 122 |
|
| 123 |
|
| 124 |
def extractFilesListMatchingPattern(fileList_in, reMatachingPattern): |
| 125 |
fileList_out = [] |
| 126 |
for line in fileList_in: |
| 127 |
reFilePatternMatch = reMatachingPattern.match(line) |
| 128 |
if reFilePatternMatch: |
| 129 |
fileList_out.append(reFilePatternMatch.group(1).strip()) |
| 130 |
return fileList_out |
| 131 |
|
| 132 |
|
| 133 |
def getPackagesListFromFilePathsList(projectDependencies, filePathsList, |
| 134 |
allPackages=False, projectCiFileChangeLogic=DefaultProjectCiFileChangeLogic() \ |
| 135 |
): |
| 136 |
packagesList = [] |
| 137 |
enabledAllPackages = False |
| 138 |
for filePath in filePathsList: |
| 139 |
packageName = getPackageNameFromPath(projectDependencies, filePath) |
| 140 |
if findInSequence(packagesList, packageName) == -1 and packageName: |
| 141 |
packagesList.append(packageName.strip()) |
| 142 |
if allPackages \ |
| 143 |
and projectCiFileChangeLogic.isGlobalBuildFileRequiringGlobalRebuild(filePath) \ |
| 144 |
and not enabledAllPackages \ |
| 145 |
: |
| 146 |
packagesList.append("ALL_PACKAGES") |
| 147 |
enabledAllPackages = True |
| 148 |
return packagesList |
| 149 |
|
| 150 |
|
| 151 |
def getPackageCheckinEmailAddressesListFromFilePathsList( |
| 152 |
projectDependencies, filePathsList \ |
| 153 |
) \ |
| 154 |
: |
| 155 |
packageCheckinEmailAddresses = [] |
| 156 |
for filePath in filePathsList: |
| 157 |
packageStruct = getPackageStructFromPath(projectDependencies, filePath) |
| 158 |
if packageStruct: |
| 159 |
checkinEmail = packageStruct.emailAddresses.checkin |
| 160 |
else: |
| 161 |
checkinEmail = None |
| 162 |
if findInSequence(packageCheckinEmailAddresses, checkinEmail) == -1: |
| 163 |
packageCheckinEmailAddresses.append(checkinEmail) |
| 164 |
return packageCheckinEmailAddresses |