Skip to content

Commit 24d413a

Browse files
authored
Add Source and Binary directory to build (#3471)
Add the ability to store the source and binary directory of an incoming build. This information will be available in CMake soon See https://gitlab.kitware.com/cmake/cmake/-/issues/27628
1 parent 0da14e2 commit 24d413a

9 files changed

Lines changed: 134 additions & 1 deletion

File tree

app/Http/Submission/Handlers/BuildHandler.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ class BuildHandler extends AbstractXmlHandler implements ActionableBuildInterfac
6969
private string $BuildStamp;
7070
private string $Generator;
7171
private string $PullRequest = '';
72+
private ?string $SourceDirectory = null;
73+
private ?string $BinaryDirectory = null;
7274
private ?BuildErrorFilter $BuildErrorFilter = null;
7375
protected static ?string $schema_file = '/app/Validators/Schemas/Build.xsd';
7476

@@ -344,6 +346,8 @@ public function endElement($parser, $name): void
344346
$build->StartTime = $start_time;
345347
$build->EndTime = $end_time;
346348
$build->SubmitTime = $submit_time;
349+
$build->SourceDirectory = $this->SourceDirectory;
350+
$build->BinaryDirectory = $this->BinaryDirectory;
347351
if (empty($subproject)) {
348352
$build->SetSubProject($this->SubProjectName);
349353
} else {
@@ -566,6 +570,12 @@ public function text($parser, $data): void
566570
case 'BUILDCOMMAND':
567571
$this->BuildCommand = htmlspecialchars_decode($data);
568572
break;
573+
case 'SOURCEDIRECTORY':
574+
$this->SourceDirectory = $data;
575+
break;
576+
case 'BINARYDIRECTORY':
577+
$this->BinaryDirectory = $data;
578+
break;
569579
}
570580
} elseif ($this->getParent() === 'ACTION') {
571581
if (!$this->Error instanceof BuildFailure) {

app/Models/Build.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@
4747
* @property string $osversion
4848
* @property string $compilername
4949
* @property string $compilerversion
50+
* @property ?string $sourcedirectory
51+
* @property ?string $binarydirectory
5052
*
5153
* @method static Builder<Build> betweenDates(?Carbon $starttime, ?Carbon $endtime)
5254
*
@@ -95,6 +97,8 @@ class Build extends Model
9597
'osversion',
9698
'compilername',
9799
'compilerversion',
100+
'sourcedirectory',
101+
'binarydirectory',
98102
];
99103

100104
protected $casts = [

app/Validators/Schemas/Build.xsd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
<xs:element name="Labels" type="LabelsType" />
3636
<xs:element name="StartDateTime" type="xs:string" />
3737
<xs:element name="StartBuildTime" type="xs:unsignedInt" />
38+
<xs:element name="SourceDirectory" type="xs:string" minOccurs="0" />
39+
<xs:element name="BinaryDirectory" type="xs:string" minOccurs="0" />
3840
<xs:element name="BuildCommand" type="xs:string" />
3941
<xs:element name="Error">
4042
<xs:complexType>

app/cdash/app/Model/Build.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ class Build
6666
public ?string $OSVersion = null;
6767
public ?string $CompilerName = null;
6868
public ?string $CompilerVersion = null;
69+
public ?string $SourceDirectory = null;
70+
public ?string $BinaryDirectory = null;
6971
public int $BuildErrorCount;
7072
public int $TestFailedCount;
7173

@@ -364,6 +366,8 @@ public function FillFromId($buildid): void
364366
$this->OSVersion = $model->osversion;
365367
$this->CompilerName = $model->compilername;
366368
$this->CompilerVersion = $model->compilerversion;
369+
$this->SourceDirectory = $model->sourcedirectory;
370+
$this->BinaryDirectory = $model->binarydirectory;
367371

368372
$subprojectid = $this->QuerySubProjectId($buildid);
369373
if ($subprojectid) {
@@ -1715,7 +1719,12 @@ public function UpdateBuild($buildid, $newErrors, $newWarnings): void
17151719
if ($this->CompilerVersion !== null && $this->CompilerVersion !== $build->compilerversion) {
17161720
$fields_to_update['compilerversion'] = $this->CompilerVersion;
17171721
}
1718-
1722+
if ($this->SourceDirectory !== null && $this->SourceDirectory !== $build->sourcedirectory) {
1723+
$fields_to_update['sourcedirectory'] = $this->SourceDirectory;
1724+
}
1725+
if ($this->BinaryDirectory !== null && $this->BinaryDirectory !== $build->binarydirectory) {
1726+
$fields_to_update['binarydirectory'] = $this->BinaryDirectory;
1727+
}
17191728
if (!empty($fields_to_update)) {
17201729
$build->update($fields_to_update);
17211730
}
@@ -2213,6 +2222,8 @@ public function AddBuild(int $nbuilderrors = -1, int $nbuildwarnings = -1): bool
22132222
'osversion' => $this->OSVersion,
22142223
'compilername' => $this->CompilerName,
22152224
'compilerversion' => $this->CompilerVersion,
2225+
'sourcedirectory' => $this->SourceDirectory,
2226+
'binarydirectory' => $this->BinaryDirectory,
22162227
])->id;
22172228
$build_created = true;
22182229
$this->AssignToGroup();

app/cdash/tests/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,8 @@ add_feature_test(/Feature/Submission/Instrumentation/BuildInstrumentationTest)
336336

337337
add_feature_test(/Feature/Submission/Tests/TestXMLTest)
338338

339+
add_feature_test(/Feature/Submission/Tests/BuildXMLTest)
340+
339341
add_browser_test(/Browser/Pages/SitesIdPageTest)
340342

341343
add_browser_test(/Browser/Pages/ProjectSitesPageTest)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Support\Facades\DB;
5+
6+
return new class extends Migration {
7+
/**
8+
* Run the migrations.
9+
*/
10+
public function up(): void
11+
{
12+
DB::statement('ALTER TABLE build ADD COLUMN sourcedirectory text');
13+
DB::statement('ALTER TABLE build ADD COLUMN binarydirectory text');
14+
}
15+
16+
/**
17+
* Reverse the migrations.
18+
*/
19+
public function down(): void
20+
{
21+
}
22+
};

graphql/schema.graphql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,10 @@ type Build {
691691
"The command used to drive the build. Example: /usr/local/bin/cmake --build . --config Release"
692692
command: String! @filterable
693693

694+
sourceDirectory: String @filterable @rename(attribute: "sourcedirectory")
695+
696+
binaryDirectory: String @filterable @rename(attribute: "binarydirectory")
697+
694698
"The number of errors generated during the configuration step."
695699
configureErrorsCount: Int @rename(attribute: "configureerrors")
696700

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
3+
namespace Tests\Feature\Submission\Tests;
4+
5+
use App\Models\Project;
6+
use Tests\TestCase;
7+
use Tests\Traits\CreatesProjects;
8+
use Tests\Traits\CreatesSubmissions;
9+
10+
class BuildXMLTest extends TestCase
11+
{
12+
use CreatesProjects;
13+
use CreatesSubmissions;
14+
15+
private Project $project;
16+
17+
protected function setUp(): void
18+
{
19+
parent::setUp();
20+
21+
$this->project = $this->makePublicProject();
22+
}
23+
24+
protected function tearDown(): void
25+
{
26+
$this->project->delete();
27+
28+
parent::tearDown();
29+
}
30+
31+
/**
32+
* Test parsing a valid Build.xml file that contains
33+
* the Source and Binary directories
34+
*/
35+
public function testBuildDirectoriesHandling(): void
36+
{
37+
$this->submitFiles($this->project->name, [
38+
base_path(
39+
'tests/Feature/Submission/Tests/data/with_build_source_binary_directories.xml'
40+
),
41+
]);
42+
43+
$this->graphQL('
44+
query build($id: ID) {
45+
build(id: $id) {
46+
sourceDirectory
47+
binaryDirectory
48+
}
49+
}
50+
', [
51+
'id' => $this->project->builds()->firstOrFail()->id,
52+
])->assertExactJson([
53+
'data' => [
54+
'build' => [
55+
'sourceDirectory' => '/home/user/Work/cmake',
56+
'binaryDirectory' => '/home/user/Work/cmake-build',
57+
],
58+
],
59+
]);
60+
}
61+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Site BuildName="dummy_test_name"
3+
BuildStamp="dummy_stamp"
4+
Name="dummy_name"
5+
>
6+
<Build>
7+
<StartDateTime>Feb 23 10:47 EST</StartDateTime>
8+
<StartBuildTime>1771861653</StartBuildTime>
9+
<SourceDirectory>/home/user/Work/cmake</SourceDirectory>
10+
<BinaryDirectory>/home/user/Work/cmake-build</BinaryDirectory>
11+
<BuildCommand>/usr/local/bin/cmake --build . --config "Release"</BuildCommand>
12+
<Log Encoding="base64" Compression="bin/gzip"/>
13+
<EndDateTime>Feb 23 10:47 EST</EndDateTime>
14+
<EndBuildTime>1771861655</EndBuildTime>
15+
<ElapsedMinutes>0</ElapsedMinutes>
16+
</Build>
17+
</Site>

0 commit comments

Comments
 (0)