@@ -377,14 +377,44 @@ function main($request, $compiler_config)
377
377
378
378
if ($ ret_link )
379
379
{
380
-
380
+ $ originalLinkerOutput = implode ( "\n" , $ output );
381
381
// 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 ));
383
413
384
414
$ returner = array (
385
415
"success " => false ,
386
416
"step " => 7 ,
387
- "message " => implode ( "\n" , $ output ) );
417
+ "message " => $ linkerOutput );
388
418
389
419
if ($ compiler_config ['logging ' ] === true )
390
420
{
0 commit comments