blob: 43688455ba0ddfca85cf96ab281a371b6f78bc9a [file] [log] [blame]
ojan@chromium.org7cb9d152012-11-20 19:58:45 +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
68 latest_cached_build = cached_builds.pop()
69 while latest_cached_build in current_builds and len(cached_builds):
70 latest_cached_build = cached_builds.pop()
71
72 for step in fetch_json(cached_build_json_url(master_url, builder, latest_cached_build))['steps']:
73 step_name = step['name']
zandobersek@gmail.com99123c52013-05-06 17:55:57 +000074 if step_name != 'layout-test':
ojan@chromium.org7cb9d152012-11-20 19:58:45 +000075 continue
76
zandobersek@gmail.com99123c52013-05-06 17:55:57 +000077 # Adjust for backwards compatibility
78 step_name = 'layout-tests'
79
ojan@chromium.org7cb9d152012-11-20 19:58:45 +000080 if step_name not in tests_object:
81 tests_object[step_name] = {'builders': []}
82 tests_object[step_name]['builders'].append(builder)
83
84 for step_name in tests_object:
85 tests_object[step_name]['builders'].sort()
86
87
88def main():
89 option_parser = optparse.OptionParser()
90 option_parser.add_option('-v', '--verbose', action='store_true', default=False, help='Print debug logging')
91 options, args = option_parser.parse_args()
92
93 logging.getLogger().setLevel(logging.DEBUG if options.verbose else logging.INFO)
94
95 masters = [
ojan@chromium.org7cb9d152012-11-20 19:58:45 +000096 {'name': 'webkit.org', 'url': 'http://build.webkit.org'},
97 ]
98
99 insert_builder_and_test_data(masters)
100
101 json_file_prefix = ('// This file is auto-generated by Tools/TestResultServer/generate_builders_json.py. It should not be manually modified.\n'
zandobersek@gmail.com99123c52013-05-06 17:55:57 +0000102 '// It uses jsonp instead of proper json because we want to be able to load it from a file URL for local testing.\n'
ojan@chromium.org7cb9d152012-11-20 19:58:45 +0000103 'LOAD_BUILDBOT_DATA(')
104 json_file_suffix = ');\n';
105
106 json_file = open(os.path.join('static-dashboards', 'builders.jsonp'), 'w')
107 json_file.write(json_file_prefix + json.dumps(masters, separators=(', ', ': '), indent=4, sort_keys=True) + json_file_suffix)
108
109
110if __name__ == "__main__":
111 main()