1 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
5 This retrieves the latest warnings from the Chrome /analyze build machine, and
7 This script is intended to be run from retrieve_latest_warnings.bat which
8 fills out the functionality.
17 print "Missing build number."
20 buildNumber
= int(sys
.argv
[1])
22 baseURL
= "http://build.chromium.org/p/chromium.fyi/builders/" + \
23 "Chromium%20Windows%20Analyze/"
25 print "Finding recent builds on %s" % baseURL
26 baseData
= urllib
.urlopen(baseURL
).read()
27 recentOff
= baseData
.find("Recent Builds:")
28 buildPattern
= 'success</td> <td><a href="' + \
29 '../../builders/Chromium%20Windows%20Analyze/builds/'
30 # For some reason I couldn't get regular expressions to work on this data.
31 latestBuildOff
= baseData
.find(buildPattern
, recentOff
) + len(buildPattern
)
32 if latestBuildOff
< len(buildPattern
):
33 print "Couldn't find successful build."
35 latestEndOff
= baseData
.find('"', latestBuildOff
)
36 latestBuildStr
= baseData
[latestBuildOff
:latestEndOff
]
37 maxBuildNumber
= int(latestBuildStr
)
38 if buildNumber
> maxBuildNumber
:
39 print "Requested build number (%d) is too high. Maximum is %d." % \
40 (buildNumber
, maxBuildNumber
)
42 # Treat negative numbers specially
43 if sys
.argv
[1][0] == '-':
44 buildNumber
= maxBuildNumber
+ buildNumber
47 print "Retrieving build number %d of %d" % (buildNumber
, maxBuildNumber
)
49 # Found the last summary results in the current directory
50 results
= glob
.glob("analyze*_summary.txt")
52 previous
= "%04d" % (buildNumber
- 1)
54 possiblePrevious
= results
[-1][7:11]
55 if int(possiblePrevious
) == buildNumber
:
57 previous
= results
[-2][7:11]
59 previous
= possiblePrevious
61 dataURL
= baseURL
+ "builds/" + str(buildNumber
) + "/steps/compile/logs/stdio"
62 revisionURL
= baseURL
+ "builds/" + str(buildNumber
)
64 # Retrieve the revision
65 revisionData
= urllib
.urlopen(revisionURL
).read()
66 key
= "Got Revision</td><td>"
67 Off
= revisionData
.find(key
) + len(key
)
69 revision
= revisionData
[Off
: Off
+ 40]
70 print "Revision is '%s'" % revision
71 print "Environment variables can be set with set_analyze_revision.bat"
72 payload
= "set ANALYZE_REVISION=%s\r\n" % revision
73 payload
+= "set ANALYZE_BUILD_NUMBER=%04d\r\n" % buildNumber
74 payload
+= "set ANALYZE_PREV_BUILD_NUMBER=%s\r\n" % previous
75 open("set_analyze_revision.bat", "wt").write(payload
)
77 # Retrieve the raw warning data
78 print "Retrieving raw build results. Please wait."
79 data
= urllib
.urlopen(dataURL
).read()
80 if data
.count("status: SUCCESS") == 0:
81 print "Build failed or is incomplete."
84 data
= data
.replace("'", "'").replace(""", '"')
86 data
= data
.replace("<", "<").replace(">", ">")
88 data
= data
.replace("&", "&")
90 data
= data
.replace('</span><span class="stdout">', '')
91 # Fix up the source paths to match my local /analyze repo
92 if "ANALYZE_REPO" in os
.environ
:
93 sourcePath
= r
"e:\b\build\slave\chromium_windows_analyze\build\src"
94 destPath
= os
.path
.join(os
.environ
["ANALYZE_REPO"], "src")
95 data
= data
.replace(sourcePath
, destPath
)
96 outputName
= "analyze%04d_full.txt" % buildNumber
97 open(outputName
, "w").write(data
)
98 print "Done. Data is in %s" % outputName
100 print "No revision information found!"