Skip to content

Commit 1b07b90

Browse files
committed
Added coded that removes unnecessary paths info from linking error output
1 parent 5fd92ab commit 1b07b90

File tree

1 file changed

+33
-3
lines changed

1 file changed

+33
-3
lines changed

Symfony/src/Codebender/CompilerBundle/Handler/CompilerHandler.php

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -377,14 +377,44 @@ function main($request, $compiler_config)
377377

378378
if ($ret_link)
379379
{
380-
380+
$originalLinkerOutput = implode("\n", $output);
381381
// Log the fact that an error occurred during linking
382-
$this->compiler_logger->addInfo($this->logger_id." - An error occurred during linking: ".json_encode(implode("\n", $output)));
382+
$this->compiler_logger->addInfo($this->logger_id." - An error occurred during linking: ".json_encode($originalLinkerOutput));
383+
384+
/*
385+
* Removes our weird tmp directory paths from the linker error output
386+
*/
387+
// Prebuilt arduino core library files (.a files) are cached and stored in '/tmp/objectFilesDirectory'
388+
$linkerOutput = str_replace($this->object_directory .'/', '', $originalLinkerOutput);
389+
// Object files produced from sketch compilation are stored in the same folder with the project code (/tmp/compiler.RANDOM/files)
390+
$linkerOutput = str_replace("$compiler_dir/files/", '(file in sketch) ', $linkerOutput);
391+
/*
392+
* Of all the sub-directories of a library, only `utility` folder is currently taken under consideration,
393+
* so it's removed manually.
394+
* TODO: Find a unique way to mark library sub-folders in cached objects filenames
395+
*/
396+
$linkerOutput = str_replace('utility_______', 'utility/', $linkerOutput);
397+
398+
// Remove the cached object path from the core library, if it exists in the error output
399+
$boardConfig = "${mcu}_${f_cpu}_${core}_${variant}_${vid}_${pid}";
400+
$pathinfoResult = pathinfo(str_replace("/", "__", $CORE_DIR . "_"), PATHINFO_FILENAME);
401+
$linkerOutput = str_replace($pathinfoResult . "_______" . $boardConfig . "_______", '', $linkerOutput);
402+
403+
// Do the same for libraries' cached object files
404+
$linkerOutput = str_replace($boardConfig, '', $linkerOutput);
405+
// Handle both system and personal libraries and add a comment in order to make it clear where the file belongs
406+
$linkerOutput = preg_replace('/(______)(.*)(\d*_cb_personal_lib_)(.*)(_______)/', "(personal library file) $4/", $linkerOutput);
407+
$linkerOutput = preg_replace('/(______)(.*)(_______)/', '(library file) $2/', $linkerOutput);
408+
// Add a new line which makes the output look better
409+
$linkerOutput = str_replace('first defined here', "first defined here\n", $linkerOutput);
410+
411+
// Log linker reformatted output
412+
$this->compiler_logger->addInfo($this->logger_id." - Linker reformatted output: ".json_encode($linkerOutput));
383413

384414
$returner = array(
385415
"success" => false,
386416
"step" => 7,
387-
"message" => implode("\n", $output));
417+
"message" => $linkerOutput);
388418

389419
if ($compiler_config['logging'] === true)
390420
{

0 commit comments

Comments
 (0)