blob: 0b666f8aa02dfd8d9c4291fea5730fca6bdd7fcf [file] [log] [blame]
Torne (Richard Coles)926b0012013-03-28 15:32:48 +00001#!/usr/bin/env python
2# Copyright (C) 2011 Google Inc. All rights reserved.
3#
4# Redistribution and use in source and binary forms, with or without
5# modification, are permitted provided that the following conditions are
6# met:
7#
8# * Redistributions of source code must retain the above copyright
9# notice, this list of conditions and the following disclaimer.
10# * Redistributions in binary form must reproduce the above
11# copyright notice, this list of conditions and the following disclaimer
12# in the documentation and/or other materials provided with the
13# distribution.
14# * Neither the name of Google Inc. nor the names of its
15# contributors may be used to endorse or promote products derived from
16# this software without specific prior written permission.
17#
18# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
30import json
31import logging
32import optparse
33import os
34import urllib2
35
36# FIXME: See if Tools/Scripts/webkitpy/layout_tests/port/builders.py should also read
37# the output json file here as its data source.
38
39
40def master_json_url(master_url):
41 return master_url + '/json/builders'
42
43
44def builder_json_url(master_url, builder):
45 return master_json_url(master_url) + '/' + urllib2.quote(builder)
46
47
48def cached_build_json_url(master_url, builder, build_number):
49 return builder_json_url(master_url, builder) + '/builds/' + str(build_number)
50
51
52def fetch_json(url):
53 logging.debug('Fetching %s' % url)
54 return json.load(urllib2.urlopen(url))
55
56
57def insert_builder_and_test_data(masters):
58 for master in masters:
59 master_url = master['url']
60 tests_object = {}
61 master['tests'] = tests_object
62
63 for builder in fetch_json(master_json_url(master_url)):
64 build_data = fetch_json(builder_json_url(master_url, builder))
65 cached_builds = build_data['cachedBuilds']
66 current_builds = build_data['currentBuilds']
67
Torne (Richard Coles)5267f702013-06-11 10:57:24 +010068 if len(cached_builds) == 0:
69 print 'warning: empty list of cached builds for', builder
70 continue
71
Torne (Richard Coles)926b0012013-03-28 15:32:48 +000072 latest_cached_build = cached_builds.pop()
73 while latest_cached_build in current_builds and len(cached_builds):
74 latest_cached_build = cached_builds.pop()
75
76 for step in fetch_json(cached_build_json_url(master_url, builder, latest_cached_build))['steps']:
77 step_name = step['name']
Torne (Richard Coles)5267f702013-06-11 10:57:24 +010078 is_test_step = 'test' in step_name and 'archive' not in step_name
79 if not is_test_step:
Torne (Richard Coles)926b0012013-03-28 15:32:48 +000080 continue
81
Torne (Richard Coles)5267f702013-06-11 10:57:24 +010082 # The chromium bots call this step webkit-tests, but the files stored at
83 # test-results.appspot.com use layout-tests as the test suite name, so normalize to that.
84 if step_name == 'webkit_tests':
85 step_name = 'layout-tests'
86
Torne (Richard Coles)926b0012013-03-28 15:32:48 +000087 if step_name not in tests_object:
88 tests_object[step_name] = {'builders': []}
89 tests_object[step_name]['builders'].append(builder)
90
Torne (Richard Coles)5267f702013-06-11 10:57:24 +010091 for step_name in tests_object:
92 tests_object[step_name]['builders'].sort()
Torne (Richard Coles)926b0012013-03-28 15:32:48 +000093
94
95def main():
96 option_parser = optparse.OptionParser()
97 option_parser.add_option('-v', '--verbose', action='store_true', default=False, help='Print debug logging')
98 options, args = option_parser.parse_args()
99
100 logging.getLogger().setLevel(logging.DEBUG if options.verbose else logging.INFO)
101
102 masters = [
Torne (Richard Coles)5267f702013-06-11 10:57:24 +0100103 {'name': 'ChromiumWin', 'url': 'http://build.chromium.org/p/chromium.win', 'groups': ['@ToT Chromium']},
104 {'name': 'ChromiumMac', 'url': 'http://build.chromium.org/p/chromium.mac', 'groups': ['@ToT Chromium']},
105 {'name': 'ChromiumLinux', 'url': 'http://build.chromium.org/p/chromium.linux', 'groups': ['@ToT Chromium']},
106 {'name': 'ChromiumChromiumOS', 'url': 'http://build.chromium.org/p/chromium.chromiumos', 'groups': ['@ToT ChromeOS']},
107 {'name': 'ChromiumGPU', 'url': 'http://build.chromium.org/p/chromium.gpu', 'groups': ['@ToT Chromium']},
108 {'name': 'ChromiumGPUFYI', 'url': 'http://build.chromium.org/p/chromium.gpu.fyi', 'groups': ['@ToT Chromium FYI']},
109 {'name': 'ChromiumPerfAv', 'url': 'http://build.chromium.org/p/chromium.perf_av', 'groups': ['@ToT Chromium']},
110 {'name': 'ChromiumWebkit', 'url': 'http://build.chromium.org/p/chromium.webkit', 'groups': ['@ToT Chromium', '@ToT Blink']},
111 {'name': 'ChromiumFYI', 'url': 'http://build.chromium.org/p/chromium.fyi', 'groups': ['@ToT Chromium FYI']},
Torne (Richard Coles)926b0012013-03-28 15:32:48 +0000112 ]
113
114 insert_builder_and_test_data(masters)
115
116 json_file_prefix = ('// This file is auto-generated by Tools/TestResultServer/generate_builders_json.py. It should not be manually modified.\n'
117 '// It uses jsonp instead of proper json because we want to be able to load it from a file URL in Chrome for local testing.\n'
118 'LOAD_BUILDBOT_DATA(')
119 json_file_suffix = ');\n';
120
Torne (Richard Coles)5267f702013-06-11 10:57:24 +0100121 output_data = {'masters': masters}
122
Torne (Richard Coles)926b0012013-03-28 15:32:48 +0000123 json_file = open(os.path.join('static-dashboards', 'builders.jsonp'), 'w')
Torne (Richard Coles)5267f702013-06-11 10:57:24 +0100124 json_file.write(json_file_prefix + json.dumps(output_data, separators=(', ', ': '), indent=4, sort_keys=True) + json_file_suffix)
Torne (Richard Coles)926b0012013-03-28 15:32:48 +0000125
126
127if __name__ == "__main__":
128 main()