2 * Copyright (C) 2011 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
26 var builders = builders || {};
30 var kUpdateStepName = 'update';
31 var kUpdateScriptsStepName = 'update_scripts';
32 var kCompileStepName = 'compile';
33 var kWebKitTestsStepNames = ['webkit_tests', 'layout-test'];
35 var kCrashedOrHungOutputMarker = 'crashed or hung';
37 function buildBotURL(platform)
39 return config.kPlatforms[platform].buildConsoleURL;
42 function urlForBuildInfo(platform, builderName, buildNumber)
44 return buildBotURL(platform) + '/json/builders/' + encodeURIComponent(builderName) + '/builds/' + encodeURIComponent(buildNumber);
47 function didFail(step)
49 if (kWebKitTestsStepNames.indexOf(step.name) != -1) {
50 // run-webkit-tests fails to generate test coverage when it crashes or hangs.
51 // FIXME: Do build.webkit.org bots output this marker when the tests fail to run?
52 return step.text.indexOf(kCrashedOrHungOutputMarker) != -1;
54 // The first item in step.results is the success of the step:
55 // 0 == pass, 1 == warning, 2 == fail
56 return step.results[0] == 2;
59 function failingSteps(buildInfo)
61 return buildInfo.steps.filter(didFail);
64 function mostRecentCompletedBuildNumber(individualBuilderStatus)
66 if (!individualBuilderStatus)
69 for (var i = individualBuilderStatus.cachedBuilds.length - 1; i >= 0; --i) {
70 var buildNumber = individualBuilderStatus.cachedBuilds[i];
71 if (individualBuilderStatus.currentBuilds.indexOf(buildNumber) == -1)
78 var g_buildInfoCache = new base.AsynchronousCache(function(key, callback) {
79 var explodedKey = key.split('\n');
80 net.get(urlForBuildInfo(explodedKey[0], explodedKey[1], explodedKey[2]), callback);
83 builders.clearBuildInfoCache = function()
85 g_buildInfoCache.clear();
88 function fetchMostRecentBuildInfoByBuilder(platform, callback)
90 net.get(buildBotURL(platform) + '/json/builders', function(builderStatus) {
91 var buildInfoByBuilder = {};
92 var builderNames = Object.keys(builderStatus);
93 var requestTracker = new base.RequestTracker(builderNames.length, callback, [buildInfoByBuilder]);
94 builderNames.forEach(function(builderName) {
95 if (!config.builderApplies(builderName)) {
96 requestTracker.requestComplete();
100 var buildNumber = mostRecentCompletedBuildNumber(builderStatus[builderName]);
102 buildInfoByBuilder[builderName] = null;
103 requestTracker.requestComplete();
107 g_buildInfoCache.get(platform + '\n' + builderName + '\n' + buildNumber, function(buildInfo) {
108 buildInfoByBuilder[builderName] = buildInfo;
109 requestTracker.requestComplete();
115 builders.buildersFailingNonLayoutTests = function(callback)
117 fetchMostRecentBuildInfoByBuilder(config.currentPlatform, function(buildInfoByBuilder) {
118 var failureList = {};
119 $.each(buildInfoByBuilder, function(builderName, buildInfo) {
122 var failures = failingSteps(buildInfo);
124 failureList[builderName] = failures.map(function(failure) { return failure.name; });
126 callback(failureList);
130 builders.mostRecentBuildForBuilder = function(platform, builderName, callback) {
131 net.get(buildBotURL(platform) + '/json/builders/' + builderName, function(builderStatus) {
132 var cachedBuilds = builderStatus.cachedBuilds;
133 var mostRecentBuild = Math.max.apply(Math, cachedBuilds);
134 callback(mostRecentBuild);