59 lines
1.8 KiB
PHP
59 lines
1.8 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace Bloom\BuildScripts;
|
||
|
|
|
||
|
|
define('TDF_DIR_PATH', $argv[1] ?? null);
|
||
|
|
|
||
|
|
if (empty(TDF_DIR_PATH)) {
|
||
|
|
print 'Missing TDF directory path. Aborting\n';
|
||
|
|
exit(1);
|
||
|
|
}
|
||
|
|
|
||
|
|
require_once __DIR__ . '/TargetDescriptionFiles/Factory.php';
|
||
|
|
|
||
|
|
$xmlFiles = TargetDescriptionFiles\Factory::findXmlFiles(TDF_DIR_PATH);
|
||
|
|
print count($xmlFiles) . ' target descriptions files found in ' . TDF_DIR_PATH . PHP_EOL . PHP_EOL;
|
||
|
|
|
||
|
|
$processedTargetConfigValues = [];
|
||
|
|
$failedValidationCount = 0;
|
||
|
|
|
||
|
|
foreach ($xmlFiles as $xmlFile) {
|
||
|
|
$xmlFilePath = $xmlFile->getPathname();
|
||
|
|
|
||
|
|
print 'Processing ' . $xmlFilePath . PHP_EOL;
|
||
|
|
$targetDescriptionFile = TargetDescriptionFiles\Factory::loadTdfFromFile($xmlFilePath);
|
||
|
|
|
||
|
|
$validationFailures = $targetDescriptionFile->validate();
|
||
|
|
if (in_array($targetDescriptionFile->configurationValue, $processedTargetConfigValues)) {
|
||
|
|
$validationFailures[] = 'Duplicate target configuration value ("'
|
||
|
|
. $targetDescriptionFile->configurationValue . '")';
|
||
|
|
}
|
||
|
|
|
||
|
|
if (!empty($validationFailures)) {
|
||
|
|
$failedValidationCount++;
|
||
|
|
|
||
|
|
print "\033[31m";
|
||
|
|
print 'Validation for ' . $xmlFilePath . ' failed' . PHP_EOL;
|
||
|
|
print count($validationFailures) . ' error(s) found:' . PHP_EOL;
|
||
|
|
print implode(PHP_EOL, $validationFailures);
|
||
|
|
print PHP_EOL . PHP_EOL;
|
||
|
|
|
||
|
|
} else {
|
||
|
|
print "\033[32m";
|
||
|
|
print 'Validation for ' . $xmlFilePath . ' passed' . PHP_EOL;
|
||
|
|
}
|
||
|
|
|
||
|
|
print "\033[0m";
|
||
|
|
|
||
|
|
$processedTargetConfigValues[] = $targetDescriptionFile->configurationValue;
|
||
|
|
}
|
||
|
|
|
||
|
|
print 'Validated ' . count($xmlFiles) . ' TDFs' . PHP_EOL;
|
||
|
|
print (($failedValidationCount > 0) ? "\033[31m" : "\033[32m");
|
||
|
|
print $failedValidationCount . ' failure(s)' . "\033[0m" . PHP_EOL;
|
||
|
|
print 'Done' . PHP_EOL;
|
||
|
|
|
||
|
|
if ($failedValidationCount > 0) {
|
||
|
|
exit(1);
|
||
|
|
}
|