Skip to content

Commit 0f3bb14

Browse files
committed
Create a unique logger id and use it in all compiler logger messages.
1 parent a2694e5 commit 0f3bb14

File tree

1 file changed

+33
-22
lines changed

1 file changed

+33
-22
lines changed

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

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class CompilerHandler
2727
private $utility;
2828
private $compiler_logger;
2929
private $object_directory;
30+
private $logger_id;
3031

3132
function __construct(PreprocessingHandler $preprocHandl, PostprocessingHandler $postprocHandl, UtilityHandler $utilHandl, Logger $logger, $objdir)
3233
{
@@ -116,10 +117,18 @@ function main($request, $compiler_config)
116117

117118
// Log the names of the project files and the libraries used in it.
118119
if ($format != "autocomplete") {
120+
$user_id = "";
121+
$sketch_id = "";
119122
$req_elements = array();
120123
$req_elements[] = "Files: ";
121124
foreach ($request["files"] as $file) {
122125
$req_elements[] = $file["filename"];
126+
if (strpos($file["filename"], ".txt") !== false) {
127+
if (strpos($file["filename"], "user_") !== false)
128+
$user_id = str_replace(".txt", "", str_replace("user_", "", $file["filename"]));
129+
else
130+
$sketch_id = str_replace(".txt", "", $file["filename"]);
131+
}
123132
}
124133

125134
if ($request["libraries"]) {
@@ -130,9 +139,11 @@ function main($request, $compiler_config)
130139
}
131140
}
132141

133-
$this->compiler_logger->addInfo($compiler_config["compiler_dir"] . " - " . implode(" ", $req_elements));
142+
$this->logger_id = microtime(true) . "_" . substr($compiler_config['compiler_dir'], -6) . "_user:$user_id" . "_project:$sketch_id";
143+
144+
$this->compiler_logger->addInfo($this->logger_id . " - " . implode(" ", $req_elements));
134145
if ($ARCHIVE_OPTION === true)
135-
$this->compiler_logger->addInfo($compiler_config["compiler_dir"] . " - " . "Archive file: $ARCHIVE_PATH");
146+
$this->compiler_logger->addInfo($this->logger_id . " - " . "Archive file: $ARCHIVE_PATH");
136147
}
137148

138149
// Step 4: Syntax-check and compile source files.
@@ -344,7 +355,7 @@ function main($request, $compiler_config)
344355
if ($ret_link){
345356

346357
// Log the fact that an error occurred during linking
347-
$this->compiler_logger->addInfo($compiler_config["compiler_dir"] . " - An error occurred during linking: " . json_encode(implode("\n", $output)));
358+
$this->compiler_logger->addInfo($this->logger_id . " - An error occurred during linking: " . json_encode(implode("\n", $output)));
348359

349360
$returner = array(
350361
"success" => false,
@@ -659,40 +670,40 @@ private function doCompile($compiler_config, &$files, $dir, $CC, $CFLAGS, $CPP,
659670
* and if significant differences are detected, return a modified version of the clang output.
660671
*/
661672
$clangElements = $this->getClangErrorFileList ($output);
662-
$this->compiler_logger->addInfo($compiler_config["compiler_dir"] . " - Clang reported files: " . implode(" | ", array_keys($clangElements)));
673+
$this->compiler_logger->addInfo($this->logger_id . " - Clang reported files: " . implode(" | ", array_keys($clangElements)));
663674
$gccElements = $this->getGccErrorFileList ($avr_output);
664-
$this->compiler_logger->addInfo($compiler_config["compiler_dir"] . " - Gcc reported files: " . implode(" | ", array_keys($gccElements)));
675+
$this->compiler_logger->addInfo($this->logger_id . " - Gcc reported files: " . implode(" | ", array_keys($gccElements)));
665676

666677
if (array_diff(array_keys($clangElements), array_keys($gccElements))) {
667678

668679
$resp["old_message"] = $output;
669-
$this->compiler_logger->addInfo($compiler_config["compiler_dir"] . " - Mismatch between clang and gcc output found.");
680+
$this->compiler_logger->addInfo($this->logger_id . " - Mismatch between clang and gcc output found.");
670681

671682
$next_clang_output = $this->cleanUpClangOutput ($output, $compiler_config, "asm");
672683

673684
$clangElements = $this->getClangErrorFileList ($next_clang_output);
674-
$this->compiler_logger->addInfo($compiler_config["compiler_dir"] . " - Clang reported files after removing asm: " . implode(" | ", array_keys($clangElements)));
685+
$this->compiler_logger->addInfo($this->logger_id . " - Clang reported files after removing asm: " . implode(" | ", array_keys($clangElements)));
675686

676687
if (array_diff(array_keys($clangElements), array_keys($gccElements))) {
677-
$this->compiler_logger->addInfo($compiler_config["compiler_dir"] . " - Mismatch between clang and gcc output found after removing assembly messages.");
688+
$this->compiler_logger->addInfo($this->logger_id . " - Mismatch between clang and gcc output found after removing assembly messages.");
678689
$final_clang_output = $this->cleanUpClangOutput ($next_clang_output, $compiler_config, "non_asm");
679690

680691
$clangElements = $this->getClangErrorFileList ($final_clang_output);
681692
if (array_diff(array_keys($clangElements), array_keys($gccElements))) {
682-
$this->compiler_logger->addInfo($compiler_config["compiler_dir"] . " - Mismatch between clang and gcc output found after removing assembly/library/core messages.");
693+
$this->compiler_logger->addInfo($this->logger_id . " - Mismatch between clang and gcc output found after removing assembly/library/core messages.");
683694
}else {
684-
$this->compiler_logger->addInfo($compiler_config["compiler_dir"] . " - Clang and gcc issue solved. Both report same files with errors.");
695+
$this->compiler_logger->addInfo($this->logger_id . " - Clang and gcc issue solved. Both report same files with errors.");
685696
}
686-
$this->compiler_logger->addInfo($compiler_config["compiler_dir"] . " - Gcc output: " . json_encode($avr_output));
687-
$this->compiler_logger->addInfo($compiler_config["compiler_dir"] . " - Clang initial output: " . json_encode($output));
688-
$this->compiler_logger->addInfo($compiler_config["compiler_dir"] . " - Clang reformated output: " . json_encode($final_clang_output));
697+
$this->compiler_logger->addInfo($this->logger_id . " - Gcc output: " . json_encode($avr_output));
698+
$this->compiler_logger->addInfo($this->logger_id . " - Clang initial output: " . json_encode($output));
699+
$this->compiler_logger->addInfo($this->logger_id . " - Clang reformated output: " . json_encode($final_clang_output));
689700
$final_clang_output = $this->pathRemover ($final_clang_output, $compiler_config);
690701
$resp["message"] = $final_clang_output;
691702
return $resp;
692703
}else {
693-
$this->compiler_logger->addInfo($compiler_config["compiler_dir"] . " - Gcc output: " . json_encode($avr_output));
694-
$this->compiler_logger->addInfo($compiler_config["compiler_dir"] . " - Clang initial output: " . json_encode($output));
695-
$this->compiler_logger->addInfo($compiler_config["compiler_dir"] . " - Clang reformated output: " . json_encode($next_clang_output));
704+
$this->compiler_logger->addInfo($this->logger_id . " - Gcc output: " . json_encode($avr_output));
705+
$this->compiler_logger->addInfo($this->logger_id . " - Clang initial output: " . json_encode($output));
706+
$this->compiler_logger->addInfo($this->logger_id . " - Clang reformated output: " . json_encode($next_clang_output));
696707
$next_clang_output = $this->pathRemover ($next_clang_output, $compiler_config);
697708
$resp["message"] = $next_clang_output;
698709
return $resp;
@@ -1158,18 +1169,18 @@ private function cleanUpClangOutput ($clang_output, $compiler_config, $option) {
11581169
|| strpos($body, "in asm") !== false))) {
11591170

11601171
if (preg_match('/(\/compiler\.\w+\/libraries\/)/', $header) && $libFound === false && $option != "asm") {
1161-
$this->compiler_logger->addInfo($compiler_config["compiler_dir"] . " - Clang reports library issue.");
1172+
$this->compiler_logger->addInfo($this->logger_id . " - Clang reports library issue.");
11621173
$libFound = true;
11631174
}
11641175
if ((strpos($header, $compiler_config["arduino_cores_dir"]) !== false
11651176
|| (array_key_exists("external_core_files", $compiler_config)
11661177
&& strpos($header, $compiler_config["external_core_files"]) !== false))
11671178
&& $coreFound === false && $option != "asm") {
1168-
$this->compiler_logger->addInfo($compiler_config["compiler_dir"] . " - Clang reports core issue.");
1179+
$this->compiler_logger->addInfo($this->logger_id . " - Clang reports core issue.");
11691180
$coreFound = true;
11701181
}
11711182
if ((strpos($header, "in asm") !== false || strpos($body, "in asm") !== false) && $asmFound === false && $option == "asm") {
1172-
$this->compiler_logger->addInfo($compiler_config["compiler_dir"] . " - Clang reports assembly issue.");
1183+
$this->compiler_logger->addInfo($this->logger_id . " - Clang reports assembly issue.");
11731184
$asmFound = true;
11741185
}
11751186
$header = "";
@@ -1212,16 +1223,16 @@ private function cleanUpClangOutput ($clang_output, $compiler_config, $option) {
12121223
}
12131224
}else {
12141225
if (preg_match('/(\/compiler\.\w+\/libraries\/)/', $header) && $libFound === false && $option != "asm") {
1215-
$this->compiler_logger->addInfo($compiler_config["compiler_dir"] . " - Clang reports library issue.");
1226+
$this->compiler_logger->addInfo($this->logger_id . " - Clang reports library issue.");
12161227
}
12171228
if ((strpos($header, $compiler_config["arduino_cores_dir"]) !== false
12181229
|| (array_key_exists("external_core_files", $compiler_config)
12191230
&& strpos($header, $compiler_config["external_core_files"]) !== false))
12201231
&& $coreFound === false && $option != "asm") {
1221-
$this->compiler_logger->addInfo($compiler_config["compiler_dir"] . " - Clang reports core issue.");
1232+
$this->compiler_logger->addInfo($this->logger_id . " - Clang reports core issue.");
12221233
}
12231234
if ((strpos($header, "in asm") !== false || strpos($body, "in asm") !== false) && $asmFound === false && $option == "asm") {
1224-
$this->compiler_logger->addInfo($compiler_config["compiler_dir"] . " - Clang reports assembly issue.");
1235+
$this->compiler_logger->addInfo($this->logger_id . " - Clang reports assembly issue.");
12251236
}
12261237
}
12271238
}

0 commit comments

Comments
 (0)