generate_builders_json.py 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. #!/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. import json
  30. import logging
  31. import optparse
  32. import os
  33. import urllib2
  34. # FIXME: See if Tools/Scripts/webkitpy/layout_tests/port/builders.py should also read
  35. # the output json file here as its data source.
  36. def master_json_url(master_url):
  37. return master_url + '/json/builders'
  38. def builder_json_url(master_url, builder):
  39. return master_json_url(master_url) + '/' + urllib2.quote(builder)
  40. def cached_build_json_url(master_url, builder, build_number):
  41. return builder_json_url(master_url, builder) + '/builds/' + str(build_number)
  42. def fetch_json(url):
  43. logging.debug('Fetching %s' % url)
  44. return json.load(urllib2.urlopen(url))
  45. def insert_builder_and_test_data(masters):
  46. for master in masters:
  47. master_url = master['url']
  48. tests_object = {}
  49. master['tests'] = tests_object
  50. for builder in fetch_json(master_json_url(master_url)):
  51. build_data = fetch_json(builder_json_url(master_url, builder))
  52. cached_builds = build_data['cachedBuilds']
  53. current_builds = build_data['currentBuilds']
  54. latest_cached_build = cached_builds.pop()
  55. while latest_cached_build in current_builds and len(cached_builds):
  56. latest_cached_build = cached_builds.pop()
  57. for step in fetch_json(cached_build_json_url(master_url, builder, latest_cached_build))['steps']:
  58. step_name = step['name']
  59. if step_name != 'layout-test':
  60. continue
  61. # Adjust for backwards compatibility
  62. step_name = 'layout-tests'
  63. if step_name not in tests_object:
  64. tests_object[step_name] = {'builders': []}
  65. tests_object[step_name]['builders'].append(builder)
  66. for step_name in tests_object:
  67. tests_object[step_name]['builders'].sort()
  68. def main():
  69. option_parser = optparse.OptionParser()
  70. option_parser.add_option('-v', '--verbose', action='store_true', default=False, help='Print debug logging')
  71. options, args = option_parser.parse_args()
  72. logging.getLogger().setLevel(logging.DEBUG if options.verbose else logging.INFO)
  73. masters = [
  74. {'name': 'webkit.org', 'url': 'http://build.webkit.org'},
  75. ]
  76. insert_builder_and_test_data(masters)
  77. json_file_prefix = ('// This file is auto-generated by Tools/TestResultServer/generate_builders_json.py. It should not be manually modified.\n'
  78. '// It uses jsonp instead of proper json because we want to be able to load it from a file URL for local testing.\n'
  79. 'LOAD_BUILDBOT_DATA(')
  80. json_file_suffix = ');\n';
  81. json_file = open(os.path.join('static-dashboards', 'builders.jsonp'), 'w')
  82. json_file.write(json_file_prefix + json.dumps(masters, separators=(', ', ': '), indent=4, sort_keys=True) + json_file_suffix)
  83. if __name__ == "__main__":
  84. main()