2023-12-12 23:19:21 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Bloom\BuildScripts;
|
|
|
|
|
|
|
|
|
|
use Bloom\BuildScripts\TargetDescriptionFiles\TargetDescriptionFile;
|
2023-12-17 17:57:35 +00:00
|
|
|
use Bloom\BuildScripts\TargetDescriptionFiles\TargetFamily;
|
2023-12-12 23:19:21 +00:00
|
|
|
|
|
|
|
|
define('TDF_DIR_PATH', $argv[1] ?? null);
|
|
|
|
|
define('MAPPING_TEMPLATE_PATH', $argv[2] ?? null);
|
|
|
|
|
define('MAPPING_OUTPUT_PATH', $argv[3] ?? null);
|
|
|
|
|
define('TDF_OUTPUT_PATH', $argv[4] ?? null);
|
|
|
|
|
|
|
|
|
|
if (empty(TDF_DIR_PATH)) {
|
|
|
|
|
print 'Missing TDF directory path. Aborting' . PHP_EOL;
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (empty(MAPPING_TEMPLATE_PATH)) {
|
|
|
|
|
print 'Missing TDF mapping template path. Aborting' . PHP_EOL;
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (empty(MAPPING_OUTPUT_PATH)) {
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!file_exists(dirname(MAPPING_OUTPUT_PATH))) {
|
|
|
|
|
mkdir(dirname(MAPPING_OUTPUT_PATH), 0700);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
require_once __DIR__ . '/TargetDescriptionFiles/Factory.php';
|
2023-12-17 17:57:35 +00:00
|
|
|
require_once __DIR__ . '/TargetDescriptionFiles/TargetFamily.php';
|
|
|
|
|
|
2023-12-12 23:19:21 +00:00
|
|
|
require_once __DIR__ . '/TargetDescriptionFiles/AVR8/Avr8TargetDescriptionFile.php';
|
|
|
|
|
|
|
|
|
|
$xmlFiles = TargetDescriptionFiles\Factory::findXmlFiles(TDF_DIR_PATH);
|
|
|
|
|
print count($xmlFiles) . ' target descriptions files found in ' . TDF_DIR_PATH . PHP_EOL . PHP_EOL;
|
|
|
|
|
|
2023-12-17 17:57:35 +00:00
|
|
|
$targetFamilyMapping = [
|
|
|
|
|
TargetFamily::AVR_8->value => 'TargetFamily::AVR_8',
|
|
|
|
|
TargetFamily::RISC_V->value => 'TargetFamily::RISC_V',
|
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;
|
|
|
|
|
$targetDescriptionFile = TargetDescriptionFiles\Factory::loadTdfFromFile($xmlFilePath);
|
|
|
|
|
|
2023-12-17 17:57:35 +00:00
|
|
|
$relativeTdfPath = $targetDescriptionFile->targetFamily->value . '/'
|
2023-12-12 23:19:21 +00:00
|
|
|
. strtoupper($targetDescriptionFile->targetName) . '.xml';
|
|
|
|
|
|
|
|
|
|
$entries[] = str_replace(
|
|
|
|
|
['@CONFIG_VALUE@', '@TARGET_NAME@', '@TARGET_FAMILY@', '@TDF_PATH@'],
|
|
|
|
|
[
|
|
|
|
|
$targetDescriptionFile->configurationValue,
|
|
|
|
|
$targetDescriptionFile->targetName,
|
2023-12-17 17:57:35 +00:00
|
|
|
$targetFamilyMapping[$targetDescriptionFile->targetFamily->value],
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!copy($targetDescriptionFile->filePath, $tdfDestinationPath)) {
|
|
|
|
|
print 'FATAL ERROR: Failed to copy TDF file to ' . $tdfDestinationPath . PHP_EOL;
|
|
|
|
|
print 'Aborting' . PHP_EOL;
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
file_put_contents(
|
|
|
|
|
MAPPING_OUTPUT_PATH,
|
|
|
|
|
str_replace(
|
|
|
|
|
'//@MAPPING_PLACEHOLDER@',
|
|
|
|
|
implode(',' . PHP_EOL . str_repeat(' ', 12), $entries),
|
|
|
|
|
file_get_contents(MAPPING_TEMPLATE_PATH)
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
print PHP_EOL;
|
|
|
|
|
print 'Processed ' . count($xmlFiles) . ' TDFs.' . PHP_EOL;
|
|
|
|
|
print 'Generated TDF mapping at ' . MAPPING_OUTPUT_PATH . PHP_EOL;
|
|
|
|
|
print 'Done' . PHP_EOL;
|