File daemon.php changed (mode: 100644) (index 83d27a0..964f228) |
... |
... |
function runBuild($build) |
102 |
102 |
|
|
103 |
103 |
$build->setStatus('running'); |
$build->setStatus('running'); |
104 |
104 |
|
|
105 |
|
$output = ''; |
|
|
105 |
|
$rawOutput = ''; |
106 |
106 |
|
|
107 |
107 |
$buildPath = BUILDS_PATH . "/$build->buildername"; |
$buildPath = BUILDS_PATH . "/$build->buildername"; |
108 |
108 |
createPath($buildPath); |
createPath($buildPath); |
|
... |
... |
function runBuild($build) |
110 |
110 |
$handle = popen("cd $buildPath && " |
$handle = popen("cd $buildPath && " |
111 |
111 |
. BUILDERS_PATH . '/' . $build->buildername . ' 2>&1', 'r'); |
. BUILDERS_PATH . '/' . $build->buildername . ' 2>&1', 'r'); |
112 |
112 |
while (!feof($handle)) { |
while (!feof($handle)) { |
113 |
|
$output .= fgets($handle); |
|
|
113 |
|
$rawOutput .= fgets($handle); |
114 |
114 |
// TODO: append output to database record every N lines (e.g. 100) |
// TODO: append output to database record every N lines (e.g. 100) |
115 |
115 |
} |
} |
116 |
116 |
$exitcode = pclose($handle); |
$exitcode = pclose($handle); |
117 |
117 |
|
|
|
118 |
|
$output = makeReport($rawOutput); |
118 |
119 |
$build->setResult(($exitcode == 0) ? 'OK' : 'FAIL', $output, $exitcode); |
$build->setResult(($exitcode == 0) ? 'OK' : 'FAIL', $output, $exitcode); |
119 |
120 |
} |
} |
120 |
121 |
|
|
|
... |
... |
function createPath($path) |
137 |
138 |
return true; |
return true; |
138 |
139 |
} |
} |
139 |
140 |
|
|
|
141 |
|
/** |
|
142 |
|
* @brief Formats output to produce build report. |
|
143 |
|
* |
|
144 |
|
* Result consists of two parts separated by double newline symbol. The first |
|
145 |
|
* parts contains index of errors and warnings, the second one is formatted |
|
146 |
|
* output. |
|
147 |
|
* |
|
148 |
|
* @param rawOutput Output from builder script as is. |
|
149 |
|
* |
|
150 |
|
* @returns Multiline build report. |
|
151 |
|
*/ |
|
152 |
|
function makeReport($rawOutput) |
|
153 |
|
{ |
|
154 |
|
$errors = []; |
|
155 |
|
$warnings = []; |
|
156 |
|
|
|
157 |
|
$input = preg_split('/\n/', $rawOutput); |
|
158 |
|
$output = []; |
|
159 |
|
$msgnum = 1; |
|
160 |
|
foreach ($input as $line) { |
|
161 |
|
$re = '/^(.*)(error|warning|Error|Warning|ERROR|WARNING)(:\s+)(.*)$/'; |
|
162 |
|
preg_match($re, $line, $matches); |
|
163 |
|
if (sizeof($matches) == 0) { |
|
164 |
|
array_push($output, $line); |
|
165 |
|
continue; |
|
166 |
|
} |
|
167 |
|
|
|
168 |
|
$anchor = "<a name='m$msgnum'/>"; |
|
169 |
|
$link = "<a href='#m$msgnum'>" . htmlentities($matches[4]) . "</a>"; |
|
170 |
|
|
|
171 |
|
if (strcasecmp($matches[2], 'error') == 0) { |
|
172 |
|
array_push($errors, $link); |
|
173 |
|
$style = 'error'; |
|
174 |
|
} else { |
|
175 |
|
array_push($warnings, $link); |
|
176 |
|
$style = 'warning'; |
|
177 |
|
} |
|
178 |
|
|
|
179 |
|
$line = "$matches[1]" |
|
180 |
|
. "<span class='$style-title'>$matches[2]</span>" |
|
181 |
|
. "$matches[3]" |
|
182 |
|
. "<span class='$style-msg'>$matches[4]</span>"; |
|
183 |
|
|
|
184 |
|
array_push($output, $anchor . $line); |
|
185 |
|
|
|
186 |
|
++$msgnum; |
|
187 |
|
} |
|
188 |
|
|
|
189 |
|
$header = ''; |
|
190 |
|
if (sizeof($errors) != 0) { |
|
191 |
|
$header .= "Errors:<ol><li>"; |
|
192 |
|
$header .= join("</li><li>", $errors); |
|
193 |
|
$header .= "</li></ol>\n"; |
|
194 |
|
} |
|
195 |
|
if (sizeof($warnings) != 0) { |
|
196 |
|
$header .= "Warnings:<ol><li>"; |
|
197 |
|
$header .= join("</li><li>", $warnings); |
|
198 |
|
$header .= "</li></ol>\n"; |
|
199 |
|
} |
|
200 |
|
|
|
201 |
|
return $header . "\n\n" . join("\n", $output); |
|
202 |
|
} |
|
203 |
|
|
140 |
204 |
?> |
?> |