Debian Codegraph @

cmake/tribits/dashboard_driver/tdd_driver.py

raw
1 #!/usr/bin/env python3
2
3 # @HEADER
4 # *****************************************************************************
5 # TriBITS: Tribal Build, Integrate, and Test System
6 #
7 # Copyright 2013-2016 NTESS and the TriBITS contributors.
8 # SPDX-License-Identifier: BSD-3-Clause
9 # *****************************************************************************
10 # @HEADER
11
12 # Prerequisites:
13 # - python is version 2.4 or later
14
15 import glob
16 import os
17 import shutil
18 import sys
19
20 # See if we should be verbose and print everything!
21 if "TDD_DEBUG_VERBOSE" in os.environ:
22 verboseEnvValue = os.environ["TDD_DEBUG_VERBOSE"]
23 if verboseEnvValue == "1":
24 verbose = True
25 else:
26 verbose = False
27 else:
28 verbose = False
29
30
31 # tribitsDDDir is the directory where *this* script is:
32 #
33 this_path = os.path.abspath(os.path.realpath(__file__))
34 tribitsDDDir = os.path.dirname(this_path)
35 print "tribitsDDDir = '"+tribitsDDDir+"'"
36
37 # Load the general script support python code
38 pythonUtilsDir = os.path.join(tribitsDDDir, "../python_utils")
39 sys.path = [pythonUtilsDir] + sys.path
40 from GeneralScriptSupport import *
41
42
43 def install_ctest(tddDashboardRootDir, tribitsDir):
44
45 # dashboardToolsDir is the directory to which any needed tools will be downloaded.
46 #
47 dashboardToolsDir = tddDashboardRootDir + "/tools"
48 print "dashboardToolsDir = '"+dashboardToolsDir+"'"
49
50 # Make sure tools directory exists:
51 #
52 if not os.path.exists(dashboardToolsDir):
53 os.makedirs(dashboardToolsDir)
54 if not os.path.exists(dashboardToolsDir):
55 print "error: could not create directory \"" + dashboardToolsDir + "\""
56 sys.exit(1)
57
58 # Download and install CMake/CTest to use for the outer driver
59 #
60 cmakeTddDownloadBaseDir = dashboardToolsDir + "/cmake-TDD"
61
62 TDD_CMAKE_INSTALLER_TYPE = "release"
63 if "TDD_CMAKE_INSTALLER_TYPE" in os.environ:
64 TDD_CMAKE_INSTALLER_TYPE = os.environ["TDD_CMAKE_INSTALLER_TYPE"]
65
66 TDD_FORCE_CMAKE_INSTALL = "1"
67 if "TDD_FORCE_CMAKE_INSTALL" in os.environ:
68 TDD_FORCE_CMAKE_INSTALL = os.environ["TDD_FORCE_CMAKE_INSTALL"]
69
70 TDD_HTTP_PROXY = ""
71 if "TDD_HTTP_PROXY" in os.environ:
72 TDD_HTTP_PROXY = os.environ["TDD_HTTP_PROXY"]
73
74 # Only install cmake-TDD if necessary or if requested.
75 # (Requires network connectivity; avoid when possible.)
76 #
77
78 print "\n***"
79 print "*** Downloading and installing CMake to \"" + cmakeTddDownloadBaseDir + "\"..."
80 print "***\n"
81
82 installMasterCMake = False
83 if not os.path.exists(cmakeTddDownloadBaseDir):
84 print "Forcing install of master CMake because '"+cmakeTddDownloadBaseDir+"' does not exist!"
85 installMasterCMake = True
86 elif TDD_FORCE_CMAKE_INSTALL == "1":
87 print "Forcing install of master CMake because" \
88 + " TDD_FORCE_CMAKE_INSTALL == 1!"
89 installMasterCMake = True
90 else:
91 print "Leaving current CMake in place ..." \
92
93 if installMasterCMake:
94
95 cmnd = sys.executable + " " \
96 + tribitsDir + "/python_utils/download-cmake.py" \
97 + " --skip-detect" \
98 + " --install-dir="+cmakeTddDownloadBaseDir \
99 + " --installer-type="+TDD_CMAKE_INSTALLER_TYPE
100
101 if TDD_HTTP_PROXY:
102 cmnd += " --http-proxy="+TDD_HTTP_PROXY
103
104 try:
105 echoRunSysCmnd( cmnd,
106 timeCmnd = True,
107 workingDir = dashboardToolsDir \
108 )
109 except Exception, e:
110 print "WARNING! The following command failed!\n"+cmnd
111 print "However, not updating CMake is not the end of the world!"
112
113
114 # Find ctest under cmakeTddDownloadBaseDir:
115 #
116 ctestGlobStr = glob.glob(cmakeTddDownloadBaseDir + "/bin/ctest*")
117 if 0 == len(ctestGlobStr):
118 ctestGlobStr = glob.glob(cmakeTddDownloadBaseDir + "/*/bin/ctest*")
119 if 0 == len(ctestGlobStr):
120 ctestGlobStr = glob.glob(cmakeTddDownloadBaseDir + "/*/*/bin/ctest*")
121 if 1 != len(ctestGlobStr):
122 print "error: could not find ctest executable after download..."
123 sys.exit(2)
124
125 ctestExe = ctestGlobStr[0]
126
127 return ctestExe
128
129
130 def invoke_ctest(ctestExe, script, tddDashboardRootDir, environment = {}):
131 """
132 Invokes CTest using the executable given by the ctestExe argument,
133 the script file specified by the script argument, in the working
134 directory specified by the tddDashboardRootDir argument and the set of
135 environment variables specified in the environment map.
136 """
137 # We have to pass parameters to CTest through environment
138 # variables. It would be nice to have another way to do this, but
139 # until ctest supports something like CMake's -D argument, this is
140 # how it has to be done.
141 if environment:
142 print "environment =", environment
143
144 cmd = ctestExe
145 if verbose:
146 cmd = ctestExe + " -VV"
147 ctestRtn = echoRunSysCmnd(
148 cmd + " -S" + " " + script,
149 throwExcept=False,
150 timeCmnd=True,
151 workingDir=tddDashboardRootDir,
152 extraEnv = environment
153 )
154
155 print "ctestRtn: '" + str(ctestRtn) + "'"
156
157 if ctestRtn != 0:
158 print "error: ctest returned non-zero error value, script will exit with " + str(ctestRtn)
159
160 # Propagate ctest return value
161 #
162 return ctestRtn
163
164
165 def run_driver(ctestSourceDirectory, projectRepoBaseDir):
166 """
167 Run the dashboard driver. The ctestSourceDirectory argument specifies
168 where the directory that CTest will run over. There should be a
169 CMakeLists.txt file in this location. The projectRepoBaseDir argument
170 specifies root of the source code repository for the project.
171 """
172 origDir = os.getcwd()
173 try:
174 print "\n******************************************************************"
175 print "*** Tribits Driver Dashboard tdd_driver.py ***"
176 print "******************************************************************\n"
177
178 print "\nPWD=\""+os.getcwd()+"\"...\n"
179 print "projectRepoBaseDir = '" + projectRepoBaseDir + "'"
180 print "tribitsDDDir = '" + tribitsDDDir + "'"
181
182 # tribitsDir is the root directory of the TriBITS system:
183 #
184 tribitsDir = os.path.abspath(os.path.join(tribitsDDDir, ".."))
185 print "tribitsDir = '"+tribitsDir+"'"
186
187 # dashboardBaseDir is the parent directory of our containing source tree,
188 # which we compute relative to tribitsDir:
189 #
190 tddDashboardRootDir = os.path.dirname(projectRepoBaseDir)
191 if "TDD_DASHBOARD_ROOT" in os.environ:
192 tddDashboardRootDir = os.environ["TDD_DASHBOARD_ROOT"]
193 print "tddDashboardRootDir = '"+tddDashboardRootDir+"'"
194
195 os.chdir(tddDashboardRootDir)
196 if verbose: "\nNew PWD = '"+os.getcwd()+"'"
197
198 tddUseSystemCTest = False
199 if "TRIBITS_TDD_USE_SYSTEM_CTEST" in os.environ \
200 and os.environ["TRIBITS_TDD_USE_SYSTEM_CTEST"] == "1" \
201 :
202 tddUseSystemCTest = True
203 print "tddUseSystemCTest =", tddUseSystemCTest
204
205 if tddUseSystemCTest:
206 ctestExe = getCmndOutput("which ctest", True, False)
207 else:
208 ctestExe = install_ctest(tddDashboardRootDir, tribitsDir)
209
210 print "\nctestExe = '" + ctestExe + "'"
211 if not os.path.exists(ctestExe):
212 print "error: ctest does not exist after installation..."
213 sys.exit(3)
214
215 # Escape any spaces in the path of the ctest exe. This has to be done
216 # here instead of where we set the ctestExe the first time because
217 # the check for existence cannot handle the "\"
218 #
219 ctestExe = ctestExe.replace(" ", "\ ")
220
221 # Verify ctest works with a simple --version call first:
222 #
223
224 ctestVersion = getCmndOutput(ctestExe+" --version", True, False)
225 print "ctestVersion = '"+ctestVersion+"'"
226
227 # Run one driver dashboard for this source tree:
228 #
229
230 print "\n***"
231 print "*** Running the main dashboards as CTest tests .."
232 print "***\n"
233 sys.exit(
234 invoke_ctest(ctestExe,
235 os.path.join(tribitsDDDir, "TribitsDriverDashboard.cmake"),
236 tddDashboardRootDir,
237 {
238 "TDD_DASHBOARD_ROOT" : tddDashboardRootDir,
239 "CTEST_SOURCE_DIRECTORY" : ctestSourceDirectory,
240 "CTEST_UPDATE_DIRECTORY" : projectRepoBaseDir,
241 "CTEST_BINARY_DIRECTORY" : tddDashboardRootDir+"/TDD_BUILD",
242 }
243 )
244 )
245
246 finally:
247 os.chdir(origDir)