From df36d9d698e205e55e7c9d7a2e45f497a1c6effb Mon Sep 17 00:00:00 2001 From: Nav Date: Sat, 3 Dec 2022 22:13:04 +0000 Subject: [PATCH] Added duplicate target ID detection in AVR8 TDF validation script --- build/scripts/Avr8TargetDescriptionFiles.php | 25 ++++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/build/scripts/Avr8TargetDescriptionFiles.php b/build/scripts/Avr8TargetDescriptionFiles.php index 65bb5ee2..43bf47f0 100644 --- a/build/scripts/Avr8TargetDescriptionFiles.php +++ b/build/scripts/Avr8TargetDescriptionFiles.php @@ -34,14 +34,28 @@ $avrTdfs = TargetDescriptionFiles\Factory::loadAvr8Tdfs(); print "Processing " . count($avrTdfs) . " AVR8 TDFs...\n\n"; +$processedTargetIds = []; + foreach ($avrTdfs as $avrTdf) { print "Processing AVR8 TDF for target " . $avrTdf->targetName . "\n"; + $strippedTargetName = str_replace([' '] , '_', $avrTdf->targetName); + $id = strtolower($strippedTargetName); + + if (in_array($id, $processedTargetIds)) { + print "\033[31m" . PHP_EOL; + print "FATAL ERROR: duplicate AVR8 target ID detected: " . $id . PHP_EOL . PHP_EOL + . "TDF Path: " . realpath($avrTdf->filePath); + print "\033[0m" . PHP_EOL; + exit(1); + } + if (!empty(($validationFailures = $avrTdf->validate()))) { - print "\033[31m\n"; - print "FATAL ERROR: AVR8 TDF failed validation - failure reasons:\n" - . implode("\n", $validationFailures) . "\n\nTDF Path: " . realpath($avrTdf->filePath); - print "\033[0m\n\n"; + print "\033[31m" . PHP_EOL; + print "FATAL ERROR: AVR8 TDF failed validation - failure reasons:" . PHP_EOL + . implode(PHP_EOL, $validationFailures) . PHP_EOL . PHP_EOL . "TDF Path: " + . realpath($avrTdf->filePath); + print "\033[0m" . PHP_EOL; exit(1); } @@ -64,7 +78,6 @@ foreach ($avrTdfs as $avrTdf) { mkdir($destinationFilePath, 0700, true); } - $strippedTargetName = str_replace([' '] , '_', $avrTdf->targetName); $destinationFilePath .= "/" . strtoupper($strippedTargetName) . ".xml"; $relativeDestinationFilePath .= "/" . strtoupper($strippedTargetName) . ".xml"; @@ -79,6 +92,8 @@ foreach ($avrTdfs as $avrTdf) { 'targetName' => $strippedTargetName, 'targetDescriptionFilePath' => $relativeDestinationFilePath, ]; + + $processedTargetIds[] = $id; } if (file_put_contents(AVR_TDF_MAPPING_FILE_PATH, json_encode($tdfMapping, JSON_PRETTY_PRINT)) === false) {