exclude PluginsFieldTrialTest.NoPrefLeftBehind from valgrind bot
[chromium-blink-merge.git] / tools / win / new_analyze_warnings / retrieve_warnings.py
blob33c5d407797406a3ad542db082c858c9fabc4e6f
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.
4 """
5 This retrieves the latest warnings from the Chrome /analyze build machine, and
6 does a diff.
7 This script is intended to be run from retrieve_latest_warnings.bat which
8 fills out the functionality.
9 """
11 import urllib
12 import sys
13 import glob
14 import os
16 if len(sys.argv) < 2:
17 print "Missing build number."
18 sys.exit(10)
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."
34 sys.exit(10)
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)
41 sys.exit(10)
42 # Treat negative numbers specially
43 if sys.argv[1][0] == '-':
44 buildNumber = maxBuildNumber + buildNumber
45 if buildNumber < 0:
46 buildNumber = 0
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")
51 results.sort()
52 previous = "%04d" % (buildNumber - 1)
53 if results:
54 possiblePrevious = results[-1][7:11]
55 if int(possiblePrevious) == buildNumber:
56 if len(results) > 1:
57 previous = results[-2][7:11]
58 else:
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)
68 if Off > 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."
82 else:
83 # Fix up "'" and '"'
84 data = data.replace("&#39;", "'").replace("&#34;", '"')
85 # Fix up '<' and '>'
86 data = data.replace("&lt;", "<").replace("&gt;", ">")
87 # Fix up '&'
88 data = data.replace("&amp;", "&")
89 # Fix up random spans
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
99 else:
100 print "No revision information found!"