Package buildbot :: Package steps :: Module vstudio
[frames] | no frames]

Source Code for Module buildbot.steps.vstudio

  1  # Visual studio steps 
  2   
  3  from buildbot.steps.shell import ShellCommand 
  4  from buildbot.process.buildstep import LogLineObserver 
  5  from buildbot.status.builder import SUCCESS, WARNINGS, FAILURE 
  6   
  7  import re 
  8   
  9    
10 -def addEnvPath(env, name, value):
11 """ concat a path for this name """ 12 try: 13 oldval = env[name] 14 if not oldval.endswith(';'): 15 oldval = oldval + ';' 16 except KeyError: 17 oldval = "" 18 if not value.endswith(';'): 19 value = value + ';' 20 env[name] = oldval + value
21
22 -class MSLogLineObserver(LogLineObserver):
23 24 _re_delimitor = re.compile(r'^(\d+>)?-{5}.+-{5}$') 25 _re_file = re.compile(r'^(\d+>)?[^ ]+\.(cpp|c)$') 26 _re_warning = re.compile(r' : warning [A-Z]+[0-9]+:') 27 _re_error = re.compile(r' error [A-Z]+[0-9]+\s?: ') 28 29 nbFiles = 0 30 nbProjects = 0 31 nbWarnings = 0 32 nbErrors = 0 33 34 logwarnings = None 35 logerrors = None 36
37 - def __init__(self, logwarnings, logerrors, **kwargs):
38 LogLineObserver.__init__(self, **kwargs) 39 self.logwarnings = logwarnings 40 self.logerrors = logerrors 41 self.stdoutParser.delimiter = "\r\n" 42 self.stderrParser.delimiter = "\r\n"
43
44 - def outLineReceived(self, line):
45 if self._re_delimitor.search(line): 46 self.nbProjects += 1 47 self.logwarnings.addStdout("%s\n" % line) 48 self.logerrors.addStdout("%s\n" % line) 49 self.step.setProgress('projects', self.nbProjects) 50 elif self._re_file.search(line): 51 self.nbFiles += 1 52 self.step.setProgress('files', self.nbFiles) 53 elif self._re_warning.search(line): 54 self.nbWarnings += 1 55 self.logwarnings.addStdout("%s\n" % line) 56 self.step.setProgress('warnings', self.nbWarnings) 57 elif self._re_error.search("%s\n" % line): 58 # error is no progres indication 59 self.nbErrors += 1 60 self.logerrors.addStderr("%s\n" % line)
61 62
63 -class VisualStudio(ShellCommand):
64 name = "compile" 65 description = "compiling" 66 descriptionDone = "compile" 67 68 logobserver = None 69 70 installdir = None 71 72 # One of build, or rebuild 73 mode = "rebuild" 74 75 projectfile = None 76 config = None 77 useenv = False 78 PATH = [] 79 INCLUDE = [] 80 LIB = [] 81
82 - def __init__(self, **kwargs):
83 # cleanup kwargs 84 if 'installdir' in kwargs: 85 self.installdir = kwargs['installdir'] 86 del kwargs['installdir'] 87 if 'mode' in kwargs: 88 self.config = kwargs['mode'] 89 del kwargs['mode'] 90 if 'projectfile' in kwargs: 91 self.projectfile = kwargs['projectfile'] 92 del kwargs['projectfile'] 93 if 'config' in kwargs: 94 self.config = kwargs['config'] 95 del kwargs['config'] 96 if 'useenv' in kwargs: 97 self.useenv = kwargs['useenv'] 98 del kwargs['useenv'] 99 # one of those next two forces the usage of env variables 100 if 'INCLUDE' in kwargs: 101 self.useenv = True 102 self.INCLUDE = kwargs['INCLUDE'] 103 del kwargs['INCLUDE'] 104 if 'LIB' in kwargs: 105 self.useenv = True 106 self.LIB = kwargs['LIB'] 107 del kwargs['LIB'] 108 if 'PATH' in kwargs: 109 self.PATH = kwargs['PATH'] 110 del kwargs['PATH'] 111 112 # always upcall ! 113 ShellCommand.__init__(self, **kwargs)
114
115 - def setupProgress(self):
116 self.progressMetrics += ('projects', 'files', 'warnings',) 117 return ShellCommand.setupProgress(self)
118
119 - def setupLogfiles(self, cmd, logfiles):
120 logwarnings = self.addLog("warnings") 121 logerrors = self.addLog("errors") 122 self.logobserver = MSLogLineObserver(logwarnings, logerrors) 123 self.addLogObserver('stdio', self.logobserver) 124 ShellCommand.setupLogfiles(self, cmd, logfiles)
125 126
127 - def setupEnvironment(self, cmd):
128 ShellCommand.setupEnvironment(self, cmd) 129 if cmd.args['env'] is None: 130 cmd.args['env'] = {} 131 132 # setup the custom one, those one goes first 133 for path in self.PATH: 134 addEnvPath(cmd.args['env'], "PATH", path) 135 for path in self.INCLUDE: 136 addEnvPath(cmd.args['env'], "INCLUDE", path) 137 for path in self.LIB: 138 addEnvPath(cmd.args['env'], "LIB", path)
139 140
141 - def describe(self, done=False):
142 description = ShellCommand.describe(self, done) 143 if done: 144 description.append('%d projects' % self.step_status.getStatistic('projects', 0)) 145 description.append('%d files' % self.step_status.getStatistic('files', 0)) 146 warnings = self.step_status.getStatistic('warnings', 0) 147 if warnings > 0: 148 description.append('%d warnings' % warnings) 149 errors = self.step_status.getStatistic('errors', 0) 150 if errors > 0: 151 description.append('%d errors' % errors) 152 return description
153
154 - def createSummary(self, log):
155 self.step_status.setStatistic('projects', self.logobserver.nbProjects) 156 self.step_status.setStatistic('files', self.logobserver.nbFiles) 157 self.step_status.setStatistic('warnings', self.logobserver.nbWarnings) 158 self.step_status.setStatistic('errors', self.logobserver.nbErrors)
159
160 - def evaluateCommand(self, cmd):
161 if self.logobserver.nbErrors > 0: 162 return FAILURE 163 if self.logobserver.nbWarnings > 0: 164 return WARNINGS 165 else: 166 return SUCCESS
167
168 - def finished(self, result):
169 self.getLog("warnings").finish() 170 self.getLog("errors").finish() 171 ShellCommand.finished(self, result)
172
173 -class VC6(VisualStudio):
174
175 - def __init__(self, **kwargs):
176 177 # always upcall ! 178 VisualStudio.__init__(self, **kwargs)
179
180 - def setupEnvironment(self, cmd):
181 VisualStudio.setupEnvironment(self, cmd) 182 183 if self.installdir: 184 installdir = self.installdir 185 else: 186 installdir = 'C:\\Program Files\\Microsoft Visual Studio' 187 188 # Root of Visual Developer Studio Common files. 189 VSCommonDir = installdir + '\\Common' 190 MSVCDir = installdir + '\\VC98' 191 MSDevDir = VSCommonDir + '\\msdev98' 192 193 194 addEnvPath(cmd.args['env'], "PATH", MSDevDir + '\\BIN') 195 addEnvPath(cmd.args['env'], "PATH", MSVCDir + '\\BIN') 196 addEnvPath(cmd.args['env'], "PATH", VSCommonDir + '\\TOOLS\\WINNT') 197 addEnvPath(cmd.args['env'], "PATH", VSCommonDir + '\\TOOLS') 198 199 addEnvPath(cmd.args['env'], "INCLUDE", MSVCDir + '\\INCLUDE') 200 addEnvPath(cmd.args['env'], "INCLUDE", MSVCDir + '\\ATL\\INCLUDE') 201 addEnvPath(cmd.args['env'], "INCLUDE", MSVCDir + '\\MFC\\INCLUDE') 202 203 addEnvPath(cmd.args['env'], "LIB", MSVCDir + '\\LIB') 204 addEnvPath(cmd.args['env'], "LIB", MSVCDir + '\\MFC\\LIB')
205
206 - def start(self):
207 command = ["msdev"] 208 command.append(self.projectfile) 209 command.append("/MAKE") 210 command.append("ALL - " + self.config) 211 if self.mode == "rebuild": 212 command.append("/REBUILD") 213 else: 214 command.append("/BUILD") 215 if self.useenv: 216 command.append("/USEENV") 217 self.setCommand(command) 218 return VisualStudio.start(self)
219
220 -class VC7(VisualStudio):
221
222 - def __init__(self, **kwargs):
223 224 # always upcall ! 225 VisualStudio.__init__(self, **kwargs)
226
227 - def setupEnvironment(self, cmd):
228 VisualStudio.setupEnvironment(self, cmd) 229 230 if self.installdir: 231 installdir = self.installdir 232 else: 233 installdir = 'C:\\Program Files\\Microsoft Visual Studio .NET 2003' 234 235 VSInstallDir = installdir + '\\Common7\\IDE' 236 VCInstallDir = installdir 237 MSVCDir = installdir + '\\VC7' 238 239 addEnvPath(cmd.args['env'], "PATH", VSInstallDir) 240 addEnvPath(cmd.args['env'], "PATH", MSVCDir + '\\BIN') 241 addEnvPath(cmd.args['env'], "PATH", VCInstallDir + '\\Common7\\Tools') 242 addEnvPath(cmd.args['env'], "PATH", VCInstallDir + '\\Common7\\Tools\\bin') 243 244 addEnvPath(cmd.args['env'], "INCLUDE", MSVCDir + '\\INCLUDE') 245 addEnvPath(cmd.args['env'], "INCLUDE", MSVCDir + '\\ATLMFC\\INCLUDE') 246 addEnvPath(cmd.args['env'], "INCLUDE", MSVCDir + '\\PlatformSDK\\include') 247 addEnvPath(cmd.args['env'], "INCLUDE", VCInstallDir + '\\SDK\\v1.1\\include') 248 249 addEnvPath(cmd.args['env'], "LIB", MSVCDir + '\\LIB') 250 addEnvPath(cmd.args['env'], "LIB", MSVCDir + '\\ATLMFC\\LIB') 251 addEnvPath(cmd.args['env'], "LIB", MSVCDir + '\\PlatformSDK\\lib') 252 addEnvPath(cmd.args['env'], "LIB", VCInstallDir + '\\SDK\\v1.1\\lib')
253
254 - def start(self):
255 command = ["devenv"] 256 command.append(self.projectfile) 257 if self.mode == "rebuild": 258 command.append("/Rebuild") 259 else: 260 command.append("/Build") 261 command.append(self.config) 262 if self.useenv: 263 command.append("/UseEnv") 264 self.setCommand(command) 265 return VisualStudio.start(self)
266 267 #alias VC7 as VS2003 268 VS2003 = VC7 269
270 -class VC8(VisualStudio):
271 272 # Our ones 273 arch = "x86" 274
275 - def __init__(self, **kwargs):
276 277 # cleanup kwargs 278 if 'arch' in kwargs: 279 self.arch = kwargs['arch'] 280 del kwargs['arch'] 281 282 # always upcall ! 283 VisualStudio.__init__(self, **kwargs)
284
285 - def setupEnvironment(self, cmd):
286 VisualStudio.setupEnvironment(self, cmd) 287 288 if self.installdir: 289 installdir = self.installdir 290 else: 291 installdir = 'C:\\Program Files\\Microsoft Visual Studio 8' 292 293 VSInstallDir = installdir 294 VCInstallDir = installdir + '\\VC' 295 296 addEnvPath(cmd.args['env'], "PATH", VSInstallDir + '\\Common7\\IDE') 297 if self.arch == "x64": 298 addEnvPath(cmd.args['env'], "PATH", VCInstallDir + '\\BIN\\x86_amd64') 299 addEnvPath(cmd.args['env'], "PATH", VCInstallDir + '\\BIN') 300 addEnvPath(cmd.args['env'], "PATH", VSInstallDir + '\\Common7\\Tools') 301 addEnvPath(cmd.args['env'], "PATH", VSInstallDir + '\\Common7\\Tools\\bin') 302 addEnvPath(cmd.args['env'], "PATH", VCInstallDir + '\\PlatformSDK\\bin') 303 addEnvPath(cmd.args['env'], "PATH", VSInstallDir + '\\SDK\\v2.0\\bin') 304 addEnvPath(cmd.args['env'], "PATH", VCInstallDir + '\\VCPackages') 305 addEnvPath(cmd.args['env'], "PATH", r'${PATH}') 306 307 addEnvPath(cmd.args['env'], "INCLUDE", VCInstallDir + '\\INCLUDE') 308 addEnvPath(cmd.args['env'], "INCLUDE", VCInstallDir + '\\ATLMFC\\include') 309 addEnvPath(cmd.args['env'], "INCLUDE", VCInstallDir + '\\PlatformSDK\\include') 310 311 archsuffix = '' 312 if self.arch == "x64": 313 archsuffix = '\\amd64' 314 addEnvPath(cmd.args['env'], "LIB", VCInstallDir + '\\LIB' + archsuffix) 315 addEnvPath(cmd.args['env'], "LIB", VCInstallDir + '\\ATLMFC\\LIB' + archsuffix) 316 addEnvPath(cmd.args['env'], "LIB", VCInstallDir + '\\PlatformSDK\\lib' + archsuffix) 317 addEnvPath(cmd.args['env'], "LIB", VSInstallDir + '\\SDK\\v2.0\\lib' + archsuffix)
318 319 # the start method is the same as for VC7
320 - def start(self):
321 command = ["devenv"] 322 command.append(self.projectfile) 323 if self.mode == "rebuild": 324 command.append("/Rebuild") 325 else: 326 command.append("/Build") 327 command.append(self.config) 328 if self.useenv: 329 command.append("/UseEnv") 330 self.setCommand(command) 331 return VisualStudio.start(self)
332 333 #alias VC8 as VS2005 334 VS2005 = VC8 335