Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 119 additions & 4 deletions app/Http/Controllers/BuildController.php
Original file line number Diff line number Diff line change
Expand Up @@ -928,14 +928,14 @@ public function apiViewBuildError(): JsonResponse
$resolvedBuildErrors = $this->build->GetResolvedBuildErrors($type);
if ($resolvedBuildErrors !== false) {
while ($resolvedBuildError = $resolvedBuildErrors->fetch()) {
$this->addErrorResponse(BuildError::marshal($resolvedBuildError, $this->project, $revision), $response);
$this->addErrorResponse(self::marshalBuildError($resolvedBuildError, $this->project, $revision), $response);
}
}

// Build failure table
$resolvedBuildFailures = $this->build->GetResolvedBuildFailures($type);
foreach ($resolvedBuildFailures as $resolvedBuildFailure) {
$marshaledResolvedBuildFailure = BuildFailure::marshal($resolvedBuildFailure, $this->project, $revision, false, $buildfailure);
$marshaledResolvedBuildFailure = self::marshalBuildFailure($resolvedBuildFailure, $this->project, $revision, false, $buildfailure);

if ($this->project->DisplayLabels) {
get_labels_JSON_from_query_results('
Expand Down Expand Up @@ -968,14 +968,14 @@ public function apiViewBuildError(): JsonResponse
$buildErrors = $this->build->GetErrors($filter_error_properties);

foreach ($buildErrors as $error) {
$this->addErrorResponse(BuildError::marshal($error, $this->project, $revision), $response);
$this->addErrorResponse(self::marshalBuildError($error, $this->project, $revision), $response);
}

// Build failure table
$buildFailures = $this->build->GetFailures(['type' => $type]);

foreach ($buildFailures as $fail) {
$failure = BuildFailure::marshal($fail, $this->project, $revision, true, $buildfailure);
$failure = self::marshalBuildFailure($fail, $this->project, $revision, true, $buildfailure);

if ($this->project->DisplayLabels) {
$labels = RichBuildAlert::findOrFail((int) $fail['id'])->labels()->pluck('text');
Expand All @@ -995,6 +995,121 @@ public function apiViewBuildError(): JsonResponse
return response()->json(cast_data_for_JSON($response));
}

/**
* @return array{
* 'file': string,
* 'directory': string,
* }
*/
private static function GetSourceFileFromBuildError(array $data): array
{
$sourceFile = [];

// Detect if the source directory has already been replaced by CTest
// with /.../. If so, sourcefile is already a relative path from the
// root of the source tree.
if (str_contains($data['stdoutput'], '/.../')) {
$parts = explode('/', $data['sourcefile']);
$sourceFile['file'] = array_pop($parts);
$sourceFile['directory'] = implode('/', $parts);
} else {
$sourceFile['file'] = basename($data['sourcefile']);
$sourceFile['directory'] = dirname($data['sourcefile']);
}

return $sourceFile;
}

// Ideally $data would be loaded into $this
// need an id field?
/**
* Marshals the data of a particular build error into a serializable
* friendly format.
*
* Requires the $data of a build error, the $project, and the buildupdate.revision.
*
* @return array<string,mixed>
**/
public static function marshalBuildError(array $data, \CDash\Model\Project $project, $revision): array
{
deepEncodeHTMLEntities($data);

$sourceFile = self::GetSourceFileFromBuildError($data);

// When building without launchers, CTest truncates the source dir to
// /.../<project-name>/. Use this pattern to linkify compiler output.
$source_dir = "/\.\.\./[^/]+";

$marshaled = [
'new' => (int) ($data['newstatus'] ?? -1),
'logline' => (int) $data['logline'],
'cvsurl' => RepositoryUtils::get_diff_url($project->Id, $project->CvsUrl ?? '', $sourceFile['directory'], $sourceFile['file'], $revision),
'precontext' => '',
'text' => RepositoryUtils::linkify_compiler_output($project->CvsUrl ?? '', $source_dir, $revision, $data['stdoutput']),
'postcontext' => '',
'sourcefile' => $data['sourcefile'],
'sourceline' => $data['sourceline'],
];

if (isset($data['subprojectid'])) {
$marshaled['subprojectid'] = $data['subprojectid'];
$marshaled['subprojectname'] = $data['subprojectname'];
}

return $marshaled;
}

/**
* Marshal a build failure, this includes the build failure arguments.
**/
public static function marshalBuildFailure($data, \CDash\Model\Project $project, $revision, $linkifyOutput, $buildfailure): array
{
deepEncodeHTMLEntities($data);

$marshaled = array_merge([
'language' => $data['language'],
'sourcefile' => $data['sourcefile'],
'targetname' => $data['targetname'],
'outputfile' => $data['outputfile'],
'outputtype' => $data['outputtype'],
'workingdirectory' => $data['workingdirectory'],
'exitcondition' => $data['exitcondition'],
], $buildfailure->GetBuildFailureArguments((int) $data['id']));

$marshaled['stderror'] = $data['stderror'];
$marshaled['stdoutput'] = $data['stdoutput'];

if (isset($data['sourcefile'])) {
$file = basename($data['sourcefile']);
$directory = dirname($data['sourcefile']);

$source_dir = RepositoryUtils::get_source_dir($project->Id, $project->CvsUrl ?? '', $directory);
if (str_starts_with($directory, $source_dir)) {
$directory = substr($directory, strlen($source_dir));
}

$marshaled['cvsurl'] = RepositoryUtils::get_diff_url($project->Id,
$project->CvsUrl ?? '',
$directory,
$file,
$revision);

if ($source_dir !== null && $linkifyOutput) {
$marshaled['stderror'] = RepositoryUtils::linkify_compiler_output($project->CvsUrl ?? '', $source_dir,
$revision, $data['stderror']);
$marshaled['stdoutput'] = RepositoryUtils::linkify_compiler_output($project->CvsUrl ?? '', $source_dir,
$revision, $data['stdoutput']);
}
}

if (isset($data['subprojectid'])) {
$marshaled['subprojectid'] = $data['subprojectid'];
$marshaled['subprojectname'] = $data['subprojectname'];
}

return $marshaled;
}

public function manageBuildGroup(): View
{
$this->setProjectById(request()->integer('projectid'));
Expand Down
25 changes: 22 additions & 3 deletions app/cdash/app/Model/Build.php
Original file line number Diff line number Diff line change
Expand Up @@ -609,9 +609,28 @@ public function GetFailures(array $propertyFilters = [], int $fetchStyle = PDO::
if ($this->IsParentBuild()) {
$failures = $this->GetFailuresForChildren($fetchStyle);
} else {
$buildFailure = new BuildFailure();
$buildFailure->BuildId = $this->Id;
$failures = $buildFailure->GetFailuresForBuild($fetchStyle);
$sql = '
SELECT
bf.id,
bf.buildid,
bf.workingdirectory,
bf.sourcefile,
bf.newstatus,
bf.stdoutput,
bf.stderror,
bf.type,
bf.exitcondition,
bf.language,
bf.targetname,
bf.outputfile,
bf.outputtype
FROM buildfailure AS bf
WHERE bf.buildid=?
ORDER BY bf.id
';
$query = $this->PDO->prepare($sql);
pdo_execute($query, [$this->Id]);
$failures = $query->fetchAll($fetchStyle);
}

if ($failures !== false) {
Expand Down
65 changes: 0 additions & 65 deletions app/cdash/app/Model/BuildError.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
namespace CDash\Model;

use App\Models\BasicBuildAlert;
use App\Utils\RepositoryUtils;

/** BuildError */
class BuildError
Expand Down Expand Up @@ -60,70 +59,6 @@ public function Insert(): void
]);
}

/**
* @return array{
* 'file': string,
* 'directory': string,
* }
*/
private static function GetSourceFile(array $data): array
{
$sourceFile = [];

// Detect if the source directory has already been replaced by CTest
// with /.../. If so, sourcefile is already a relative path from the
// root of the source tree.
if (str_contains($data['stdoutput'], '/.../')) {
$parts = explode('/', $data['sourcefile']);
$sourceFile['file'] = array_pop($parts);
$sourceFile['directory'] = implode('/', $parts);
} else {
$sourceFile['file'] = basename($data['sourcefile']);
$sourceFile['directory'] = dirname($data['sourcefile']);
}

return $sourceFile;
}

// Ideally $data would be loaded into $this
// need an id field?
/**
* Marshals the data of a particular build error into a serializable
* friendly format.
*
* Requires the $data of a build error, the $project, and the buildupdate.revision.
*
* @return array<string,mixed>
**/
public static function marshal(array $data, Project $project, $revision): array
{
deepEncodeHTMLEntities($data);

$sourceFile = self::GetSourceFile($data);

// When building without launchers, CTest truncates the source dir to
// /.../<project-name>/. Use this pattern to linkify compiler output.
$source_dir = "/\.\.\./[^/]+";

$marshaled = [
'new' => (int) ($data['newstatus'] ?? -1),
'logline' => (int) $data['logline'],
'cvsurl' => RepositoryUtils::get_diff_url($project->Id, $project->CvsUrl, $sourceFile['directory'], $sourceFile['file'], $revision),
'precontext' => '',
'text' => RepositoryUtils::linkify_compiler_output($project->CvsUrl ?? '', $source_dir, $revision, $data['stdoutput']),
'postcontext' => '',
'sourcefile' => $data['sourcefile'],
'sourceline' => $data['sourceline'],
];

if (isset($data['subprojectid'])) {
$marshaled['subprojectid'] = $data['subprojectid'];
$marshaled['subprojectname'] = $data['subprojectname'];
}

return $marshaled;
}

/**
* Returns a self referencing URI for the current BuildError.
*/
Expand Down
Loading