2023-12-12 23:19:21 +00:00
|
|
|
<?php
|
|
|
|
|
|
2024-02-09 23:36:19 +00:00
|
|
|
use Targets\TargetDescriptionFiles\Services\DiscoveryService;
|
|
|
|
|
use Targets\TargetDescriptionFiles\Services\Xml\XmlService;
|
|
|
|
|
use Targets\TargetDescriptionFiles\TargetFamily;
|
2023-12-12 23:19:21 +00:00
|
|
|
|
|
|
|
|
define('TDF_DIR_PATH', $argv[1] ?? null);
|
2024-05-17 23:24:06 +01:00
|
|
|
define('OUTPUT_PATH', $argv[2] ?? null);
|
2024-03-02 01:59:55 +00:00
|
|
|
define('TDF_OUTPUT_PATH', $argv[3] ?? null);
|
2023-12-12 23:19:21 +00:00
|
|
|
|
|
|
|
|
if (empty(TDF_DIR_PATH)) {
|
|
|
|
|
print 'Missing TDF directory path. Aborting' . PHP_EOL;
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-09 23:36:19 +00:00
|
|
|
if (!file_exists(TDF_DIR_PATH)) {
|
|
|
|
|
print 'Invalid TDF directory path - "' . TDF_DIR_PATH . '" does not exist' . PHP_EOL;
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-17 23:24:06 +01:00
|
|
|
if (empty(OUTPUT_PATH)) {
|
2023-12-12 23:19:21 +00:00
|
|
|
print 'Missing TDF mapping output path. Aborting' . PHP_EOL;
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (empty(TDF_OUTPUT_PATH)) {
|
|
|
|
|
print 'Missing TDF output path. Aborting' . PHP_EOL;
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-17 23:24:06 +01:00
|
|
|
if (!file_exists(dirname(OUTPUT_PATH))) {
|
|
|
|
|
mkdir(dirname(OUTPUT_PATH), 0700, true);
|
2023-12-12 23:19:21 +00:00
|
|
|
}
|
|
|
|
|
|
2024-02-09 23:36:19 +00:00
|
|
|
require_once __DIR__ . '/Targets/TargetDescriptionFiles/Services/DiscoveryService.php';
|
|
|
|
|
require_once __DIR__ . '/Targets/TargetDescriptionFiles/Services/Xml/XmlService.php';
|
|
|
|
|
require_once __DIR__ . '/Targets/TargetDescriptionFiles/TargetFamily.php';
|
|
|
|
|
|
2024-12-28 01:33:36 +00:00
|
|
|
require_once __DIR__ . '/Targets/TargetDescriptionFiles/Avr8/Avr8TargetDescriptionFile.php';
|
2023-12-17 17:57:35 +00:00
|
|
|
|
2024-02-09 23:36:19 +00:00
|
|
|
$discoveryService = new DiscoveryService();
|
|
|
|
|
$xmlService = new XmlService();
|
2023-12-12 23:19:21 +00:00
|
|
|
|
2024-02-09 23:36:19 +00:00
|
|
|
$xmlFiles = $discoveryService->findTargetDescriptionFiles(TDF_DIR_PATH);
|
2024-03-25 18:57:05 +00:00
|
|
|
print count($xmlFiles) . ' target description files found in ' . TDF_DIR_PATH . PHP_EOL . PHP_EOL;
|
2023-12-12 23:19:21 +00:00
|
|
|
|
|
|
|
|
const MAP_ENTRY_TEMPLATE = '{"@CONFIG_VALUE@", {"@TARGET_NAME@", "@CONFIG_VALUE@", @TARGET_FAMILY@, "@TDF_PATH@"}}';
|
|
|
|
|
|
|
|
|
|
$entries = [];
|
|
|
|
|
|
|
|
|
|
foreach ($xmlFiles as $xmlFile) {
|
|
|
|
|
$xmlFilePath = $xmlFile->getPathname();
|
|
|
|
|
|
|
|
|
|
print 'Processing ' . $xmlFilePath . PHP_EOL;
|
|
|
|
|
|
2024-02-09 23:36:19 +00:00
|
|
|
$xmlDocument = new \DOMDocument();
|
|
|
|
|
$xmlDocument->load($xmlFilePath);
|
|
|
|
|
$targetDescriptionFile = $xmlService->fromXml($xmlDocument);
|
|
|
|
|
|
|
|
|
|
$relativeTdfPath = $targetDescriptionFile->getFamily()->value . '/'
|
|
|
|
|
. strtoupper($targetDescriptionFile->getName()) . '.xml';
|
2023-12-12 23:19:21 +00:00
|
|
|
|
|
|
|
|
$entries[] = str_replace(
|
|
|
|
|
['@CONFIG_VALUE@', '@TARGET_NAME@', '@TARGET_FAMILY@', '@TDF_PATH@'],
|
|
|
|
|
[
|
2024-02-09 23:36:19 +00:00
|
|
|
$targetDescriptionFile->getConfigurationValue(),
|
|
|
|
|
$targetDescriptionFile->getName(),
|
2024-05-17 23:24:06 +01:00
|
|
|
match ($targetDescriptionFile->getFamily()) {
|
2024-03-02 01:59:55 +00:00
|
|
|
TargetFamily::AVR_8 => 'Targets::TargetFamily::AVR_8',
|
|
|
|
|
TargetFamily::RISC_V => 'Targets::TargetFamily::RISC_V',
|
|
|
|
|
},
|
2023-12-12 23:19:21 +00:00
|
|
|
$relativeTdfPath,
|
|
|
|
|
],
|
|
|
|
|
MAP_ENTRY_TEMPLATE
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$tdfDestinationPath = TDF_OUTPUT_PATH . '/' . $relativeTdfPath;
|
|
|
|
|
|
|
|
|
|
$tdfDestinationDirPath = dirname($tdfDestinationPath);
|
|
|
|
|
if (!file_exists($tdfDestinationDirPath)) {
|
|
|
|
|
mkdir($tdfDestinationDirPath, 0700, true);
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-09 23:36:19 +00:00
|
|
|
if (!copy($xmlFilePath, $tdfDestinationPath)) {
|
2023-12-12 23:19:21 +00:00
|
|
|
print 'FATAL ERROR: Failed to copy TDF file to ' . $tdfDestinationPath . PHP_EOL;
|
|
|
|
|
print 'Aborting' . PHP_EOL;
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-17 23:24:06 +01:00
|
|
|
file_put_contents(OUTPUT_PATH, implode(',' . PHP_EOL, $entries));
|
2023-12-12 23:19:21 +00:00
|
|
|
|
|
|
|
|
print PHP_EOL;
|
|
|
|
|
print 'Processed ' . count($xmlFiles) . ' TDFs.' . PHP_EOL;
|
2024-05-17 23:24:06 +01:00
|
|
|
print 'Generated brief target descriptors at ' . OUTPUT_PATH . PHP_EOL;
|
2023-12-12 23:19:21 +00:00
|
|
|
print 'Done' . PHP_EOL;
|