PageRenderTime 33ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/threadweaver/Scripts/buildinator_common.py

https://github.com/vasi/kdelibs
Python | 152 lines | 151 code | 1 blank | 0 comment | 3 complexity | 389ff245d25428fb7dc6ad19e0cc65df MD5 | raw file
  1. import re
  2. import os
  3. import sys
  4. import time
  5. import platform
  6. from buildinator_build_status import BuildStatus
  7. def CheckoutSubversionRevision (Status, SrcDir, LogDir):
  8. """Checks a certain revision of threadweaver out of KDESVN into SrcDir"""
  9. Cmd="svn co -r" + str(Status.revision) + ' ' + Status.svnUrl + ' ' \
  10. + SrcDir + ' ' \
  11. + "> " + LogDir + "/SubversionCheckout.log 2>&1"
  12. # print Cmd
  13. # print "Checking out revision " + str(Status.revision)
  14. ReturnCode = 0
  15. try:
  16. ReturnCode = os.system (Cmd)
  17. Status.checkoutStatus = 1 # success
  18. except:
  19. Status.checkoutStatus = 2 # failed
  20. return Status
  21. def CleanUp (Status, SrcDir, BuildDir):
  22. """Delete temporary src and build directories"""
  23. # build status is ignored here, but we may want to skip cleanup if some step of the build failed
  24. os.system ("rm -Rf " + SrcDir)
  25. os.system ("rm -Rf " + BuildDir)
  26. return Status
  27. def Build (Status, SrcDir, BuildDir, LogDir):
  28. """Build the sources in SrcDir in BuildDir/Prefix using Options for qmake"""
  29. BuildPath = BuildDir + "/" + Status.prefix
  30. # if exceptions occur, stop the script (no catching):
  31. os.system("mkdir -p " + BuildPath)
  32. rc = os.system("(cd " + BuildPath + " && qmake " \
  33. + Status.options + " " + SrcDir + '/' + Status.projectFile + ')' \
  34. + " > " + LogDir + "/qmake-" + Status.prefix + ".log 2>&1")
  35. if rc == 0:
  36. Status.configureStatus = 1 # success
  37. else:
  38. Status.configureStatus = 2 # failure
  39. rc = os.system("(cd " + BuildPath + " && make all " \
  40. + " > " + LogDir + "/make-all-" + Status.prefix + ".log 2>&1 )")
  41. # FIXME: find out about "success with warnings"
  42. if rc == 0:
  43. Status.compileStatus = 1 # success
  44. else:
  45. Status.compileStatus = 3 # failure
  46. return Status
  47. def Test (Status, BuildDir, Prefix, LogDir):
  48. """Run the unit tests in BuildDir/Prefix"""
  49. BuildPath = BuildDir + "/" + Prefix
  50. Cmd = "(cd " + BuildPath + " && make test " \
  51. + " > " + LogDir + "/make-test-" + Prefix + ".log 2>&1 )"
  52. Status.overallTestStatus = 1 # success
  53. for Step in range( Status.numberOfTestRuns ):
  54. rc =os.system(Cmd)
  55. if rc == 0:
  56. Status.testResults = Status.testResults + [ 1 ]
  57. else:
  58. Status.testResults = Status.testResults + [ 2 ]
  59. Status.overallTestStatus = 2 # failed
  60. return Status
  61. # the entry point for the whole build test process:
  62. def ExecuteBuildAndTest ( Status, WorkDir ):
  63. """This function runs the sequence of checking out, building and testing a revision"""
  64. SrcDir = WorkDir+ "/Src"
  65. BuildDir = WorkDir + "/Build"
  66. LogDir = WorkDir + "/Logs"
  67. MinimumTestRevision = -1
  68. Errors = False
  69. # common object, will be copied for the different runs
  70. Status.platform = platform.platform()
  71. BuildResults = [] # will hold a list of BuildStatus objects,one for every configuration
  72. # print "SrcDir: " + SrcDir
  73. # print "BuildDir: " + BuildDir
  74. # print "LogDir: " + LogDir
  75. # print
  76. try:
  77. for Directory in [ SrcDir, BuildDir, LogDir]:
  78. os.system ("mkdir -p " + Directory)
  79. # print "Clearing existing logs in " + LogDir
  80. os.system("rm -f " + LogDir + "/*")
  81. except:
  82. print "--> error: cannot make src or build directory, check permissions!"
  83. sys.exit (-2)
  84. Status = CheckoutSubversionRevision ( Status, SrcDir, LogDir)
  85. if Status.checkoutStatus != 1: # success
  86. return Status # return just this one object, since we cannot run the build without sources
  87. # a dictionary with the configuration name and qmake options:
  88. Options = { 'Debug' : 'CONFIG+=debug',
  89. 'Release' : 'CONFIG+=release' }
  90. for Prefix, Option in Options.items():
  91. # copy status over from status of common steps:
  92. CurrentStatus = BuildStatus( Status )
  93. CurrentStatus.options = Option
  94. CurrentStatus.prefix = Prefix
  95. # print 'Building with options "' + Option + '" in ' + Prefix
  96. CurrentStatus = Build (CurrentStatus, SrcDir, BuildDir, LogDir)
  97. if CurrentStatus.compileStatus == 1 or CurrentStatus.compileStatus == 2:
  98. # print "Build successful"
  99. if Status.revision < MinimumTestRevision:
  100. print "--> warning: not testing, no unit test in revisions below " + MinimumTestRevision
  101. else:
  102. # print "Executing initial unit test run"
  103. CurrentStatus = Test (CurrentStatus, BuildDir, Prefix, LogDir)
  104. if CurrentStatus.overallTestStatus == 1:
  105. # print "Tests successful"
  106. pass
  107. else:
  108. print "--> notice: tests failed!"
  109. else:
  110. print "--> error: build failed, no testing"
  111. if CurrentStatus.hasErrors(): Errors = True
  112. BuildResults = BuildResults + [ CurrentStatus ]
  113. # print "Cleaning up (deleting all in SrcDir and BuildDir, leave Logs) ..."
  114. if Errors:
  115. print '--> notice: not cleaning up because of previous errors'
  116. else:
  117. CleanUp (Status, SrcDir, BuildDir)
  118. return BuildResults
  119. # FIXME: return something useful
  120. def GetSvnLog ( SvnUrl ):
  121. """Retrieve the subversion log for a subversion URL and return it in a list."""
  122. Cmd = "svn log " + SvnUrl
  123. File = os.popen (Cmd, 'r')
  124. return File.readlines()
  125. def GetRevisionList( SvnUrl ):
  126. """Make an BuildStatus list of revisions, sorted latest-to-older"""
  127. Lines = GetSvnLog ( SvnUrl )
  128. RevisionLine = re.compile( '^r\d+\s')
  129. Revisions = []
  130. for Line in Lines:
  131. Match = RevisionLine.match( Line )
  132. if Match:
  133. Status = BuildStatus()
  134. Pieces = Line.split('|')
  135. Status.committer = Pieces[1].strip()
  136. Status.revision = int (Pieces[0].rstrip()[1:])
  137. Status.svnUrl = SvnUrl
  138. Revisions = Revisions + [ Status ]
  139. return Revisions