Skip to content

Commit 252733d

Browse files
committed
Added extra parameter to Clang output cleanup function as well as more verbose logging durin clang output parsing.
1 parent 1ac3d60 commit 252733d

File tree

1 file changed

+49
-35
lines changed

1 file changed

+49
-35
lines changed

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

Lines changed: 49 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -667,26 +667,37 @@ private function doCompile($compiler_config, &$files, $dir, $CC, $CFLAGS, $CPP,
667667
$this->compiler_logger->addInfo($compiler_config["compiler_dir"] . " - Gcc reported files: " . implode(" | ", array_keys($gccElements)));
668668

669669
if (array_diff(array_keys($clangElements), array_keys($gccElements))) {
670-
$resp["old_message"] = $output;
671670

671+
$resp["old_message"] = $output;
672672
$this->compiler_logger->addInfo($compiler_config["compiler_dir"] . " - Mismatch between clang and gcc output found.");
673-
$new_clang_output = $this->cleanUpClangOutput($output, $compiler_config);
674-
675-
$clangElements = $this->getClangErrorFileList ($new_clang_output);
676-
if (array_diff(array_keys($clangElements), array_keys($gccElements)))
677-
$this->compiler_logger->addInfo($compiler_config["compiler_dir"] . " - Clang still reports errors in different files than gcc.");
678-
else
679-
$this->compiler_logger->addInfo($compiler_config["compiler_dir"] . " - Clang reports errors in the same files as gcc.");
680673

681-
$this->compiler_logger->addInfo($compiler_config["compiler_dir"] . " - Gcc output: " . json_encode($avr_output));
682-
$this->compiler_logger->addInfo($compiler_config["compiler_dir"] . " - Clang initial output: " . json_encode($output));
683-
$this->compiler_logger->addInfo($compiler_config["compiler_dir"] . " - Clang reformated output: " . json_encode($new_clang_output));
684-
685-
$resp["message"] = $new_clang_output;
674+
$next_clang_output = $this->cleanUpClangOutput ($output, $compiler_config, "asm");
675+
676+
$clangElements = $this->getClangErrorFileList ($next_clang_output);
677+
$this->compiler_logger->addInfo($compiler_config["compiler_dir"] . " - Clang reported files after removing asm: " . implode(" | ", array_keys($clangElements)));
678+
679+
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 messages.");
681+
$final_clang_output = $this->cleanUpClangOutput ($next_clang_output, $compiler_config, "non_asm");
682+
683+
$clangElements = $this->getClangErrorFileList ($final_clang_output);
684+
if (array_diff(array_keys($clangElements), array_keys($gccElements))) {
685+
$this->compiler_logger->addInfo($compiler_config["compiler_dir"] . " - Mismatch between clang and gcc output found after removing assembly/library/core messages.");
686+
}else {
687+
$this->compiler_logger->addInfo($compiler_config["compiler_dir"] . " - Clang and gcc issue solved. Both report same files with errors.");
688+
}
689+
$this->compiler_logger->addInfo($compiler_config["compiler_dir"] . " - Gcc output: " . json_encode($avr_output));
690+
$this->compiler_logger->addInfo($compiler_config["compiler_dir"] . " - Clang initial output: " . json_encode($output));
691+
$this->compiler_logger->addInfo($compiler_config["compiler_dir"] . " - Clang reformated output: " . json_encode($final_clang_output));
692+
$resp["message"] = $final_clang_output;
693+
}else {
694+
$this->compiler_logger->addInfo($compiler_config["compiler_dir"] . " - Gcc output: " . json_encode($avr_output));
695+
$this->compiler_logger->addInfo($compiler_config["compiler_dir"] . " - Clang initial output: " . json_encode($output));
696+
$this->compiler_logger->addInfo($compiler_config["compiler_dir"] . " - Clang reformated output: " . json_encode($next_clang_output));
697+
$resp["message"] = $next_clang_output;
698+
}
686699
}
687-
688700
return $resp;
689-
690701
}
691702
unset($output);
692703
if ($caching && $lock_check){
@@ -1108,7 +1119,7 @@ private function getGccErrorFileList ($avr_output) {
11081119
return $gcc_elements;
11091120
}
11101121

1111-
private function cleanUpClangOutput ($clang_output, $compiler_config) {
1122+
private function cleanUpClangOutput ($clang_output, $compiler_config, $option) {
11121123

11131124
$content_line_array = explode("\n", $clang_output);
11141125

@@ -1130,22 +1141,23 @@ private function cleanUpClangOutput ($clang_output, $compiler_config) {
11301141
&& strpos($line, "note:") !== false)) {
11311142

11321143
if ($header_found === false) {
1133-
if (preg_match('/(\/compiler\.\w+\/libraries\/)/', $header)
1134-
|| strpos($header, $compiler_config["arduino_cores_dir"]) !== false
1135-
|| (array_key_exists("external_core_files", $compiler_config)
1136-
&& strpos($header, $compiler_config["external_core_files"]) !== false)
1137-
|| strpos($header, "note:") !== false
1138-
|| strpos($header, "in asm") !== false
1139-
|| strpos($body, "in asm") !== false) {
1140-
1141-
if (preg_match('/(\/compiler\.\w+\/libraries\/)/', $header) && $libFound === false) {
1144+
if (($option == "non_asm" && preg_match('/(\/compiler\.\w+\/libraries\/)/', $header)
1145+
|| strpos($header, $compiler_config["arduino_cores_dir"]) !== false
1146+
|| (array_key_exists("external_core_files", $compiler_config)
1147+
&& strpos($header, $compiler_config["external_core_files"]) !== false)
1148+
|| strpos($header, "note:") !== false)
1149+
|| ($option == "asm"
1150+
&& (strpos($header, "in asm") !== false
1151+
|| strpos($body, "in asm") !== false))) {
1152+
1153+
if (preg_match('/(\/compiler\.\w+\/libraries\/)/', $header) && $libFound === false && $option != "asm") {
11421154
$this->compiler_logger->addInfo($compiler_config["compiler_dir"] . " - Clang reports library issue.");
11431155
$libFound = true;
11441156
}
11451157
if ((strpos($header, $compiler_config["arduino_cores_dir"]) !== false
1146-
|| (array_key_exists("external_core_files", $compiler_config)
1147-
&& strpos($header, $compiler_config["external_core_files"]) !== false))
1148-
&& $coreFound === false) {
1158+
|| (array_key_exists("external_core_files", $compiler_config)
1159+
&& strpos($header, $compiler_config["external_core_files"]) !== false))
1160+
&& $coreFound === false && $option != "asm") {
11491161
$this->compiler_logger->addInfo($compiler_config["compiler_dir"] . " - Clang reports core issue.");
11501162
$coreFound = true;
11511163
}
@@ -1176,13 +1188,15 @@ private function cleanUpClangOutput ($clang_output, $compiler_config) {
11761188
}
11771189

11781190
if (!array_key_exists($key + 1, $content_line_array)) {
1179-
if (!preg_match('/(\/compiler\.\w+\/libraries\/)/', $header)
1180-
&& strpos($header, $compiler_config["arduino_cores_dir"]) === false
1181-
&& (array_key_exists("external_core_files", $compiler_config)
1182-
&& strpos($header, $compiler_config["external_core_files"]) === false)
1183-
&& strpos($header, "note:") === false
1184-
&& strpos($header, "in asm") === false
1185-
&& strpos($body, "in asm") === false) {
1191+
if ((!preg_match('/(\/compiler\.\w+\/libraries\/)/', $header)
1192+
&& strpos($header, $compiler_config["arduino_cores_dir"]) === false
1193+
&& (array_key_exists("external_core_files", $compiler_config)
1194+
&& strpos($header, $compiler_config["external_core_files"]) === false)
1195+
&& strpos($header, "note:") === false
1196+
&& $option == "non_asm")
1197+
|| ($option == "asm"
1198+
&& strpos($header, "in asm") === false
1199+
&& strpos($body, "in asm") === false)) {
11861200
if ($header != "" && $body != "") {
11871201
if (strpos($header, "</font></b>") == 0)
11881202
$header = substr_replace($header, '', 0, 11);

0 commit comments

Comments
 (0)