Skip to content

Commit da47680

Browse files
committed
Merge branch 'dev'
2 parents 9b0f887 + 4196e57 commit da47680

File tree

2 files changed

+49
-40
lines changed

2 files changed

+49
-40
lines changed

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

Lines changed: 48 additions & 39 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,21 +117,33 @@ 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"]) {
126135
$req_elements[] = "Libraries: ";
127-
foreach ($request["libraries"] as $key => $var) {
128-
$req_elements[] = $key;
136+
foreach ($request["libraries"] as $libname => $libfiles) {
137+
foreach ($libfiles as $libfile)
138+
$req_elements[] = $libname . "/" . $libfile["filename"];
129139
}
130140
}
131-
$this->compiler_logger->addInfo($compiler_config["compiler_dir"] . " - " . implode(" ", $req_elements));
141+
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));
132145
if ($ARCHIVE_OPTION === true)
133-
$this->compiler_logger->addInfo($compiler_config["compiler_dir"] . " - " . "Archive file: $ARCHIVE_PATH");
146+
$this->compiler_logger->addInfo($this->logger_id . " - " . "Archive file: $ARCHIVE_PATH");
134147
}
135148

136149
// Step 4: Syntax-check and compile source files.
@@ -342,7 +355,7 @@ function main($request, $compiler_config)
342355
if ($ret_link){
343356

344357
// Log the fact that an error occurred during linking
345-
$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)));
346359

347360
$returner = array(
348361
"success" => false,
@@ -657,42 +670,46 @@ private function doCompile($compiler_config, &$files, $dir, $CC, $CFLAGS, $CPP,
657670
* and if significant differences are detected, return a modified version of the clang output.
658671
*/
659672
$clangElements = $this->getClangErrorFileList ($output);
660-
$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)));
661674
$gccElements = $this->getGccErrorFileList ($avr_output);
662-
$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)));
663676

664677
if (array_diff(array_keys($clangElements), array_keys($gccElements))) {
665678

666679
$resp["old_message"] = $output;
667-
$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.");
668681

669682
$next_clang_output = $this->cleanUpClangOutput ($output, $compiler_config, "asm");
670683

671684
$clangElements = $this->getClangErrorFileList ($next_clang_output);
672-
$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)));
673686

674687
if (array_diff(array_keys($clangElements), array_keys($gccElements))) {
675-
$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.");
676689
$final_clang_output = $this->cleanUpClangOutput ($next_clang_output, $compiler_config, "non_asm");
677690

678691
$clangElements = $this->getClangErrorFileList ($final_clang_output);
679692
if (array_diff(array_keys($clangElements), array_keys($gccElements))) {
680-
$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.");
681694
}else {
682-
$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.");
683696
}
684-
$this->compiler_logger->addInfo($compiler_config["compiler_dir"] . " - Gcc output: " . json_encode($avr_output));
685-
$this->compiler_logger->addInfo($compiler_config["compiler_dir"] . " - Clang initial output: " . json_encode($output));
686-
$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));
687700
$final_clang_output = $this->pathRemover ($final_clang_output, $compiler_config);
688701
$resp["message"] = $final_clang_output;
702+
if ($resp["message"] == "")
703+
$resp["message"] = $this->pathRemover ($output, $compiler_config);
689704
return $resp;
690705
}else {
691-
$this->compiler_logger->addInfo($compiler_config["compiler_dir"] . " - Gcc output: " . json_encode($avr_output));
692-
$this->compiler_logger->addInfo($compiler_config["compiler_dir"] . " - Clang initial output: " . json_encode($output));
693-
$this->compiler_logger->addInfo($compiler_config["compiler_dir"] . " - Clang reformated output: " . json_encode($next_clang_output));
706+
$this->compiler_logger->addInfo($this->logger_id . " - Gcc output: " . json_encode($avr_output));
707+
$this->compiler_logger->addInfo($this->logger_id . " - Clang initial output: " . json_encode($output));
708+
$this->compiler_logger->addInfo($this->logger_id . " - Clang reformated output: " . json_encode($next_clang_output));
694709
$next_clang_output = $this->pathRemover ($next_clang_output, $compiler_config);
695710
$resp["message"] = $next_clang_output;
711+
if ($resp["message"] == "")
712+
$resp["message"] = $this->pathRemover ($output, $compiler_config);
696713
return $resp;
697714
}
698715
}
@@ -1141,40 +1158,37 @@ private function cleanUpClangOutput ($clang_output, $compiler_config, $option) {
11411158
if ((strpos($line, "In file included from") !== false
11421159
&& preg_match('/([\w*\s*(!@#$%^&*()-+;\'{}\[\])*]+\.\w+:\d+:[\d+:]?)/', $line))
11431160
|| (preg_match('/([\w*\s*(!@#$%^&*()-+;\'{}\[\])*]+\.\w+:\d+:[\d+:]?)/', $line)
1144-
&& strpos($line, "error:") !== false)
1145-
|| (preg_match('/([\w*\s*(!@#$%^&*()-+;\'{}\[\])*]+\.\w+:\d+:[\d+:]?)/', $line)
1146-
&& strpos($line, "note:") !== false)) {
1161+
&& strpos($line, "error:") !== false)) {
11471162

11481163
if ($header_found === false) {
11491164
if (($option == "non_asm" && preg_match('/(\/compiler\.\w+\/libraries\/)/', $header)
11501165
|| strpos($header, $compiler_config["arduino_cores_dir"]) !== false
11511166
|| (array_key_exists("external_core_files", $compiler_config)
1152-
&& strpos($header, $compiler_config["external_core_files"]) !== false)
1153-
|| strpos($header, "note:") !== false)
1167+
&& strpos($header, $compiler_config["external_core_files"]) !== false))
11541168
|| ($option == "asm"
11551169
&& (strpos($header, "in asm") !== false
11561170
|| strpos($body, "in asm") !== false))) {
11571171

11581172
if (preg_match('/(\/compiler\.\w+\/libraries\/)/', $header) && $libFound === false && $option != "asm") {
1159-
$this->compiler_logger->addInfo($compiler_config["compiler_dir"] . " - Clang reports library issue.");
1173+
$this->compiler_logger->addInfo($this->logger_id . " - Clang reports library issue.");
11601174
$libFound = true;
11611175
}
11621176
if ((strpos($header, $compiler_config["arduino_cores_dir"]) !== false
11631177
|| (array_key_exists("external_core_files", $compiler_config)
11641178
&& strpos($header, $compiler_config["external_core_files"]) !== false))
11651179
&& $coreFound === false && $option != "asm") {
1166-
$this->compiler_logger->addInfo($compiler_config["compiler_dir"] . " - Clang reports core issue.");
1180+
$this->compiler_logger->addInfo($this->logger_id . " - Clang reports core issue.");
11671181
$coreFound = true;
11681182
}
11691183
if ((strpos($header, "in asm") !== false || strpos($body, "in asm") !== false) && $asmFound === false && $option == "asm") {
1170-
$this->compiler_logger->addInfo($compiler_config["compiler_dir"] . " - Clang reports assembly issue.");
1184+
$this->compiler_logger->addInfo($this->logger_id . " - Clang reports assembly issue.");
11711185
$asmFound = true;
11721186
}
11731187
$header = "";
11741188
$body = "";
11751189
}
11761190

1177-
if ($header != "" && $body != "") {
1191+
if ($header != "") {
11781192
if (strpos($header, "</font></b>") == 0)
11791193
$header = substr_replace($header, '', 0, 11);
11801194
if (array_key_exists($key + 1, $content_line_array)
@@ -1197,29 +1211,28 @@ private function cleanUpClangOutput ($clang_output, $compiler_config, $option) {
11971211
&& strpos($header, $compiler_config["arduino_cores_dir"]) === false
11981212
&& (array_key_exists("external_core_files", $compiler_config)
11991213
&& strpos($header, $compiler_config["external_core_files"]) === false)
1200-
&& strpos($header, "note:") === false
12011214
&& $option == "non_asm")
12021215
|| ($option == "asm"
12031216
&& strpos($header, "in asm") === false
12041217
&& strpos($body, "in asm") === false)) {
1205-
if ($header != "" && $body != "") {
1218+
if ($header != "") {
12061219
if (strpos($header, "</font></b>") == 0)
12071220
$header = substr_replace($header, '', 0, 11);
12081221
$final .= $header ."\n";
12091222
$final .= $body . "\n";
12101223
}
12111224
}else {
12121225
if (preg_match('/(\/compiler\.\w+\/libraries\/)/', $header) && $libFound === false && $option != "asm") {
1213-
$this->compiler_logger->addInfo($compiler_config["compiler_dir"] . " - Clang reports library issue.");
1226+
$this->compiler_logger->addInfo($this->logger_id . " - Clang reports library issue.");
12141227
}
12151228
if ((strpos($header, $compiler_config["arduino_cores_dir"]) !== false
12161229
|| (array_key_exists("external_core_files", $compiler_config)
12171230
&& strpos($header, $compiler_config["external_core_files"]) !== false))
12181231
&& $coreFound === false && $option != "asm") {
1219-
$this->compiler_logger->addInfo($compiler_config["compiler_dir"] . " - Clang reports core issue.");
1232+
$this->compiler_logger->addInfo($this->logger_id . " - Clang reports core issue.");
12201233
}
12211234
if ((strpos($header, "in asm") !== false || strpos($body, "in asm") !== false) && $asmFound === false && $option == "asm") {
1222-
$this->compiler_logger->addInfo($compiler_config["compiler_dir"] . " - Clang reports assembly issue.");
1235+
$this->compiler_logger->addInfo($this->logger_id . " - Clang reports assembly issue.");
12231236
}
12241237
}
12251238
}
@@ -1234,22 +1247,18 @@ private function cleanUpClangOutput ($clang_output, $compiler_config, $option) {
12341247

12351248
private function pathRemover ($output, $compiler_config) {
12361249

1237-
$core_pattern = "/" . str_replace("/", "\\/", $compiler_config["arduino_cores_dir"]) . "([.*\\S]*\\/)" . "/";
1238-
$external_core_pattern = "//";
1239-
if (isset($compiler_config["external_core_files"]) && $compiler_config["external_core_files"] != "")
1240-
$external_core_pattern = "/" . str_replace("/", "\\/", $compiler_config["external_core_files"]) . "([.*\\S]*\\/)" . "/";
1241-
12421250
// Remove any instance of "compiler.RANDOM/files/" folder name from the text
12431251
$modified = str_replace($compiler_config["compiler_dir"] . "/files/", '', $output);
12441252

12451253
// Remove any remaining instance of "compiler.RANDOM/" folder name from the text.
12461254
$modified = str_replace($compiler_config["compiler_dir"] . "/", '', $modified);
12471255

12481256
// Remove any instance of codebender arduino core files folder name from the text
1249-
$modified = preg_replace($core_pattern, '', $modified);
1257+
$modified = str_replace($compiler_config["arduino_cores_dir"] . "/v105/", '', $modified);
12501258

12511259
// Remove any instance of codebender external core file folder name from the text
1252-
$modified = preg_replace($external_core_pattern, '', $modified);
1260+
if (isset($compiler_config["external_core_files"]) && $compiler_config["external_core_files"] != "")
1261+
$modified = str_replace($compiler_config["external_core_files"], '', $modified);
12531262

12541263
return $modified;
12551264
}

Symfony/src/Codebender/CompilerBundle/Resources/config/services.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ services:
2020
class: "%postprocessing_handler.class%"
2121
compiler_logger:
2222
class: Symfony\Bridge\Monolog\Logger
23-
arguments: [compiler_logger_name]
23+
arguments: [cmplr_log]
2424
calls:
2525
- [pushHandler, [@compiler_log_handler]]
2626
compiler_log_handler:

0 commit comments

Comments
 (0)