OLD | NEW |
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2017 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 |
4 """ | 5 """ |
5 This retrieves the latest warnings from the Chrome /analyze build machine, and | 6 This retrieves the latest warnings from the Chrome /analyze build machine, and |
6 does a diff. | 7 does a diff. |
7 This script is intended to be run from retrieve_latest_warnings.bat which | 8 This script is intended to be run from retrieve_latest_warnings.bat which |
8 fills out the functionality. | 9 fills out the functionality. |
9 """ | 10 """ |
10 | 11 |
11 import urllib | |
12 import sys | |
13 import glob | 12 import glob |
14 import os | 13 import os |
| 14 import subprocess |
| 15 import sys |
| 16 import urllib |
15 | 17 |
16 if len(sys.argv) < 2: | 18 if len(sys.argv) < 2: |
17 print "Missing build number." | 19 print 'Missing build number.' |
18 sys.exit(10) | 20 sys.exit(10) |
19 | 21 |
20 buildNumber = int(sys.argv[1]) | 22 build_number = int(sys.argv[1]) |
21 | 23 |
22 baseURL = "http://build.chromium.org/p/chromium.fyi/builders/" + \ | 24 base_url = 'http://build.chromium.org/p/chromium.fyi/builders/' + \ |
23 "Chromium%20Windows%20Analyze/" | 25 'Chromium%20Windows%20Analyze/' |
24 | 26 |
25 print "Finding recent builds on %s" % baseURL | 27 print 'Finding recent builds on %s' % base_url |
26 baseData = urllib.urlopen(baseURL).read() | 28 base_data = urllib.urlopen(base_url).read() |
27 recentOff = baseData.find("Recent Builds:") | 29 recent_off = base_data.find('Recent Builds:') |
28 buildPattern = 'success</td> <td><a href="' + \ | 30 build_marker = 'success</td> <td><a href="' + \ |
29 '../../builders/Chromium%20Windows%20Analyze/builds/' | 31 '../../builders/Chromium%20Windows%20Analyze/builds/' |
30 # For some reason I couldn't get regular expressions to work on this data. | 32 # For some reason I couldn't get regular expressions to work on this data. |
31 latestBuildOff = baseData.find(buildPattern, recentOff) + len(buildPattern) | 33 latest_build_off = base_data.find(build_marker, recent_off) + len(build_marker) |
32 if latestBuildOff < len(buildPattern): | 34 if latest_build_off < len(build_marker): |
33 print "Couldn't find successful build." | 35 print 'Couldn\'t find successful build.' |
34 sys.exit(10) | 36 sys.exit(10) |
35 latestEndOff = baseData.find('"', latestBuildOff) | 37 latest_end_off = base_data.find('"', latest_build_off) |
36 latestBuildStr = baseData[latestBuildOff:latestEndOff] | 38 latest_build_str = base_data[latest_build_off:latest_end_off] |
37 maxBuildNumber = int(latestBuildStr) | 39 max_build_number = int(latest_build_str) |
38 if buildNumber > maxBuildNumber: | 40 if build_number > max_build_number: |
39 print "Requested build number (%d) is too high. Maximum is %d." % \ | 41 print 'Requested build number (%d) is too high. Maximum is %d.' % \ |
40 (buildNumber, maxBuildNumber) | 42 (build_number, max_build_number) |
41 sys.exit(10) | 43 sys.exit(10) |
42 # Treat negative numbers specially | 44 # Treat negative numbers specially |
43 if sys.argv[1][0] == '-': | 45 if sys.argv[1][0] == '-': |
44 buildNumber = maxBuildNumber + buildNumber | 46 build_number = max_build_number + build_number |
45 if buildNumber < 0: | 47 if build_number < 0: |
46 buildNumber = 0 | 48 build_number = 0 |
47 print "Retrieving build number %d of %d" % (buildNumber, maxBuildNumber) | 49 print 'Retrieving build number %d of %d' % (build_number, max_build_number) |
48 | 50 |
49 # Found the last summary results in the current directory | 51 # Found the last summary results in the current directory |
50 results = glob.glob("analyze*_summary.txt") | 52 results = glob.glob('analyze*_summary.txt') |
51 results.sort() | 53 results.sort() |
52 previous = "%04d" % (buildNumber - 1) | 54 previous = '%04d' % (build_number - 1) |
53 if results: | 55 if results: |
54 possiblePrevious = results[-1][7:11] | 56 possible_previous = results[-1][7:11] |
55 if int(possiblePrevious) == buildNumber: | 57 if int(possible_previous) == build_number: |
56 if len(results) > 1: | 58 if len(results) > 1: |
57 previous = results[-2][7:11] | 59 previous = results[-2][7:11] |
58 else: | 60 else: |
59 previous = possiblePrevious | 61 previous = possible_previous |
60 | 62 |
61 dataURL = baseURL + "builds/" + str(buildNumber) + "/steps/compile/logs/stdio" | 63 data_descriptor = 'chromium/bb/chromium.fyi/Chromium_Windows_Analyze/' + \ |
62 revisionURL = baseURL + "builds/" + str(buildNumber) | 64 '%d/+/recipes/steps/compile/0/stdout' % build_number |
| 65 revision_url = base_url + 'builds/' + str(build_number) |
63 | 66 |
64 # Retrieve the revision | 67 # Retrieve the revision |
65 revisionData = urllib.urlopen(revisionURL).read() | 68 revisionData = urllib.urlopen(revision_url).read() |
66 key = "Got Revision</td><td>" | 69 key = 'Got Revision</td><td>' |
67 Off = revisionData.find(key) + len(key) | 70 off = revisionData.find(key) + len(key) |
68 if Off > len(key): | 71 if off > len(key): |
69 revision = revisionData[Off: Off + 40] | 72 revision = revisionData[off: off + 40] |
70 print "Revision is '%s'" % revision | 73 print 'Revision is "%s"' % revision |
71 print "Environment variables can be set with set_analyze_revision.bat" | 74 print 'Environment variables can be set with set_analyze_revision.bat' |
72 payload = "set ANALYZE_REVISION=%s\r\n" % revision | 75 payload = 'set ANALYZE_REVISION=%s\r\n' % revision |
73 payload += "set ANALYZE_BUILD_NUMBER=%04d\r\n" % buildNumber | 76 payload += 'set ANALYZE_BUILD_NUMBER=%04d\r\n' % build_number |
74 payload += "set ANALYZE_PREV_BUILD_NUMBER=%s\r\n" % previous | 77 payload += 'set ANALYZE_PREV_BUILD_NUMBER=%s\r\n' % previous |
75 open("set_analyze_revision.bat", "wt").write(payload) | 78 open('set_analyze_revision.bat', 'wt').write(payload) |
76 | 79 |
77 # Retrieve the raw warning data | 80 # Retrieve the raw warning data |
78 print "Retrieving raw build results. Please wait." | 81 print 'Retrieving raw build results. Please wait.' |
79 data = urllib.urlopen(dataURL).read() | 82 # Results are now retrieved using logdog. Instructions on how to install the |
80 if data.count("status: SUCCESS") == 0: | 83 # logdog tool can be found here: |
81 print "Build failed or is incomplete." | 84 # https://bugs.chromium.org/p/chromium/issues/detail?id=698429#c1 |
82 else: | 85 # In particular, from c:\src\logdog_cipd_root: |
83 # Fix up "'" and '"' | 86 # > depot_tools\cipd init |
84 data = data.replace("'", "'").replace(""", '"') | 87 # > depot_tools\cipd install infra/tools/luci/logdog/logdog/windows-amd64 |
85 # Fix up '<' and '>' | 88 command = r'c:\src\logdog_cipd_root\logdog.exe cat %s' % data_descriptor |
86 data = data.replace("<", "<").replace(">", ">") | 89 data = str(subprocess.check_output(command)) |
87 # Fix up '&' | 90 if 'ANALYZE_REPO' in os.environ: |
88 data = data.replace("&", "&") | 91 source_path = r'e:\b\build\slave\chromium_windows_analyze\build\src' |
89 # Fix up random spans | 92 dest_path = os.path.join(os.environ['ANALYZE_REPO'], 'src') |
90 data = data.replace('</span><span class="stdout">', '') | 93 data = data.replace(source_path, dest_path) |
91 # Fix up the source paths to match my local /analyze repo | 94 output_name = 'analyze%04d_full.txt' % build_number |
92 if "ANALYZE_REPO" in os.environ: | 95 open(output_name, 'w').write(data) |
93 sourcePath = r"e:\b\build\slave\chromium_windows_analyze\build\src" | 96 print 'Done. Data is in %s' % output_name |
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: | 97 else: |
100 print "No revision information found!" | 98 print 'No revision information found!' |
OLD | NEW |