Skip to content

Commit

Permalink
Add build instrumentation handling logic
Browse files Browse the repository at this point in the history
  • Loading branch information
williamjallen committed Jan 14, 2025
1 parent 684a762 commit ee592af
Show file tree
Hide file tree
Showing 30 changed files with 1,240 additions and 266 deletions.
11 changes: 11 additions & 0 deletions app/Enums/BuildCommandType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace App\Enums;

enum BuildCommandType: int
{
case COMPILE_COMMAND = 0;
case LINK_COMMAND = 1;
case CMAKE_BUILD_COMMAND = 2;
case CUSTOM_COMMAND = 3;
}
8 changes: 0 additions & 8 deletions app/Enums/BuildMeasurementType.php

This file was deleted.

49 changes: 41 additions & 8 deletions app/Models/Build.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Models;

use App\Enums\BuildCommandType;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
Expand Down Expand Up @@ -214,14 +215,6 @@ public function buildGroups(): BelongsToMany
return $this->belongsToMany(BuildGroup::class, 'build2group', 'groupid', 'buildid');
}

/**
* @return HasMany<BuildMeasurement>
*/
public function measurements(): HasMany
{
return $this->hasMany(BuildMeasurement::class, 'buildid');
}

/**
* @return HasMany<Coverage>
*/
Expand All @@ -237,4 +230,44 @@ public function labels(): BelongsToMany
{
return $this->belongsToMany(Label::class, 'label2build', 'buildid', 'labelid');
}

/**
* @return HasMany<BuildCommand>
*/
public function commands(): HasMany
{
return $this->hasMany(BuildCommand::class, 'buildid');
}

/**
* @return HasMany<BuildCommand>
*/
public function compileCommands(): HasMany
{
return $this->commands()->where('type', BuildCommandType::COMPILE_COMMAND);
}

/**
* @return HasMany<BuildCommand>
*/
public function linkCommands(): HasMany
{
return $this->commands()->where('type', BuildCommandType::LINK_COMMAND);
}

/**
* @return HasMany<BuildCommand>
*/
public function cmakeBuildCommands(): HasMany
{
return $this->commands()->where('type', BuildCommandType::CMAKE_BUILD_COMMAND);
}

/**
* @return HasMany<BuildCommand>
*/
public function customCommands(): HasMany
{
return $this->commands()->where('type', BuildCommandType::CUSTOM_COMMAND);
}
}
81 changes: 81 additions & 0 deletions app/Models/BuildCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php

namespace App\Models;

use App\Enums\BuildCommandType;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;

/**
* @property int $id
* @property int $buildid
* @property BuildCommandType $type
* @property Carbon $starttime
* @property Carbon $endtime
* @property string $command
* @property string $binarydirectory
* @property string $returnvalue
* @property string $output
* @property string $language
* @property string $target
* @property string $targettype
* @property string $source
*
* @mixin Builder<BuildCommand>
*/
class BuildCommand extends Model
{
protected $table = 'buildcommands';

public $timestamps = false;

protected $fillable = [
'type',
'starttime',
'endtime',
'command',
'binarydirectory',
'returnvalue',
'output',
'language',
'target',
'targettype',
'source',
];

protected $casts = [
'id' => 'integer',
'buildid' => 'integer',
'type' => BuildCommandType::class,
'starttime' => 'datetime',
'endtime' => 'datetime',
];

/**
* @return BelongsTo<Build, self>
*/
public function build(): BelongsTo
{
return $this->belongsTo(Build::class, 'buildid');
}

/**
* @return HasMany<BuildMeasurement>
*/
public function measurements(): HasMany
{
return $this->hasMany(BuildMeasurement::class, 'buildcommandid');
}

/**
* @return BelongsToMany<Label>
*/
public function labels(): BelongsToMany
{
return $this->belongsToMany(Label::class, 'buildcommands2labels', 'buildcommandid', 'labelid');
}
}
19 changes: 3 additions & 16 deletions app/Models/BuildMeasurement.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,14 @@

namespace App\Models;

use App\Enums\BuildMeasurementType;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasOne;

/**
* @property int $id
* @property int $buildid
* @property int $buildcommandid
* @property string $name
* @property string $source
* @property BuildMeasurementType $type
* @property string $type
* @property string $value
*
* @mixin Builder<BuildMeasurement>
Expand All @@ -25,22 +22,12 @@ class BuildMeasurement extends Model

protected $fillable = [
'name',
'source',
'type',
'value',
];

protected $casts = [
'id' => 'integer',
'buildid' => 'integer',
'type' => BuildMeasurementType::class,
'buildcommandid' => 'integer',
];

/**
* @return HasOne<Build>
*/
public function build(): HasOne
{
return $this->hasOne(Build::class, 'id', 'buildid');
}
}
7 changes: 0 additions & 7 deletions app/Providers/GraphQLServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,12 @@

namespace App\Providers;

use App\Enums\BuildMeasurementType;
use GraphQL\Error\InvariantViolation;
use GraphQL\Type\Definition\PhpEnumType;
use Illuminate\Support\ServiceProvider;
use Nuwave\Lighthouse\Schema\TypeRegistry;

final class GraphQLServiceProvider extends ServiceProvider
{
/**
* @throws InvariantViolation
*/
public function boot(TypeRegistry $typeRegistry): void
{
$typeRegistry->register(new PhpEnumType(BuildMeasurementType::class));
}
}
23 changes: 21 additions & 2 deletions app/Utils/Stack.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@

namespace App\Utils;

use InvalidArgumentException;

/**
* @template T
*/
class Stack
{
/**
* @var array<mixed>
* @var array<T>
*/
private array $stack = [];

Expand All @@ -14,18 +19,29 @@ public function size(): int
return count($this->stack);
}

/**
* @param T $e
*
* @return self<T>
*/
public function push(mixed $e): self
{
$this->stack[] = $e;
return $this;
}

/**
* @return self<T>
*/
public function pop(): self
{
array_pop($this->stack);
return $this;
}

/**
* @return T
*/
public function top(): mixed
{
return $this->stack[count($this->stack) - 1];
Expand All @@ -36,10 +52,13 @@ public function isEmpty(): bool
return count($this->stack) === 0;
}

/**
* @return T
*/
public function at(int $index): mixed
{
if ($index < 0 || $index >= count($this->stack)) {
return false;
throw new InvalidArgumentException("Invalid stack index: $index");
}
return $this->stack[$index];
}
Expand Down
19 changes: 18 additions & 1 deletion app/cdash/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -222,11 +222,28 @@ set_tests_properties(/Feature/GraphQL/NoteTypeTest PROPERTIES DEPENDS /Feature/G
add_laravel_test(/Feature/GraphQL/BuildMeasurementTypeTest)
set_tests_properties(/Feature/GraphQL/BuildMeasurementTypeTest PROPERTIES DEPENDS /Feature/GraphQL/BuildTypeTest)

add_laravel_test(/Feature/GraphQL/CompileBuildCommandTypeTest)
set_tests_properties(/Feature/GraphQL/CompileBuildCommandTypeTest PROPERTIES DEPENDS /Feature/GraphQL/BuildTypeTest)

add_laravel_test(/Feature/GraphQL/CoverageTypeTest)
set_tests_properties(/Feature/GraphQL/CoverageTypeTest PROPERTIES DEPENDS /Feature/GraphQL/BuildTypeTest)

add_laravel_test(/Feature/GraphQL/LabelTypeTest)
set_tests_properties(/Feature/GraphQL/LabelTypeTest PROPERTIES DEPENDS /Feature/GraphQL/BuildTypeTest)

add_laravel_test(/Feature/PurgeUnusedProjectsCommand)
set_tests_properties(/Feature/PurgeUnusedProjectsCommand PROPERTIES DEPENDS "/Feature/GraphQL/TestTypeTest;/Feature/GraphQL/TestMeasurementTypeTest;/Feature/GraphQL/NoteTypeTest;/Feature/GraphQL/BuildMeasurementTypeTest;/Feature/GraphQL/CoverageTypeTest")
set_property(TEST /Feature/PurgeUnusedProjectsCommand PROPERTY DEPENDS
/Feature/GraphQL/TestTypeTest
/Feature/GraphQL/TestMeasurementTypeTest
/Feature/GraphQL/NoteTypeTest
/Feature/GraphQL/BuildMeasurementTypeTest
/Feature/GraphQL/CoverageTypeTest
/Feature/GraphQL/LabelTypeTest
/Feature/GraphQL/CompileBuildCommandTypeTest
/Feature/GraphQL/LinkBuildCommandTypeTest
/Feature/GraphQL/CMakeBuildCommandTypeTest
/Feature/GraphQL/CustomBuildCommandTypeTest
)

add_laravel_test(/Browser/Pages/ProjectSitesPageTest)
set_tests_properties(/Browser/Pages/ProjectSitesPageTest PROPERTIES DEPENDS /Feature/PurgeUnusedProjectsCommand)
Expand Down
29 changes: 29 additions & 0 deletions app/cdash/xml_handlers/abstract_xml_handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@

abstract class AbstractXmlHandler extends AbstractSubmissionHandler
{
/**
* @var Stack<string>
*/
private Stack $stack;
protected bool $Append = false;
protected Site $Site;
Expand Down Expand Up @@ -73,6 +76,11 @@ public static function validate(string $path): array
return $errors;
}

protected function hasParent(): bool
{
return $this->stack->size() > 1;
}

protected function getParent()
{
return $this->stack->at($this->stack->size() - 2);
Expand All @@ -83,6 +91,27 @@ protected function getElement()
return $this->stack->top();
}

protected function currentPathMatches(string $path): bool
{
$path = explode('.', $path);

// We can return early if this isn't even the right level of the document
if ($this->stack->size() !== count($path)) {
return false;
}

for ($i = 0; $i < $this->stack->size(); $i++) {
if ($path[$i] === '*') { // Wildcard matches any string at a given level (but only one level)
continue;
} elseif (strtoupper($path[$i]) === strtoupper((string) $this->stack->at($i))) { // Match the specified string
continue;
} else {
return false;
}
}
return true;
}

public function startElement($parser, $name, $attributes): void
{
$this->stack->push($name);
Expand Down
Loading

0 comments on commit ee592af

Please sign in to comment.