Skip to content

Commit 3a342b1

Browse files
committed
Merge pull request #12 from codebendercc/dev
Merge Dev into Master
2 parents d87f0af + b70cb74 commit 3a342b1

File tree

1 file changed

+45
-33
lines changed

1 file changed

+45
-33
lines changed

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

Lines changed: 45 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ function main($request, $compiler_config)
7575
if ($tmp["success"] == false)
7676
return $tmp;
7777

78+
// Add the compiler temp directory to the compiler_config struct.
79+
$compiler_config["compiler_dir"] = $compiler_dir;
80+
7881
// Step 1(part 2): Extract the library files included in the request.
7982
$files["libs"] = array();
8083
foreach($libraries as $library => $library_files){
@@ -111,6 +114,21 @@ function main($request, $compiler_config)
111114
if ($tmp["success"] == false)
112115
return array_merge($tmp, ($ARCHIVE_OPTION ===true) ? array("archive" => $ARCHIVE_PATH) : array());
113116

117+
// Log the names of the project files and the libraries used in it.
118+
$req_elements = array();
119+
$req_elements[] = "Files: ";
120+
foreach ($request["files"] as $file) {
121+
$req_elements[] = $file["filename"];
122+
}
123+
124+
if ($request["libraries"]) {
125+
$req_elements[] = "Libraries: ";
126+
foreach ($request["libraries"] as $key => $var) {
127+
$req_elements[] = $key;
128+
}
129+
}
130+
$this->compiler_logger->addInfo($compiler_config["compiler_dir"] . " - " . implode(" ", $req_elements));
131+
114132
// Step 4: Syntax-check and compile source files.
115133
//Use the include paths for the AVR headers that are bundled with each Arduino SDK version
116134
//These may differ between linux and MAC OS versions of the Arduino core files, so check before including
@@ -138,24 +156,6 @@ function main($request, $compiler_config)
138156
//handleCompile sets any include directories needed and calls the doCompile function, which does the actual compilation
139157
$ret = $this->handleCompile("$compiler_dir/files", $files["sketch_files"], $compiler_config, $CC, $CFLAGS, $CPP, $CPPFLAGS, $AS, $ASFLAGS, $CLANG, $CLANG_FLAGS, $core_includes, $target_arch, $clang_target_arch, $include_directories["main"], $format);
140158

141-
// If clang output was different than gcc output, log the filenames and library names.
142-
if (array_key_exists("clang_diff", $ret)) {
143-
144-
$req_elements = array();
145-
$req_elements[] = "Files: ";
146-
foreach ($request["files"] as $file) {
147-
$req_elements[] = $file["filename"];
148-
}
149-
150-
if ($request["libraries"]) {
151-
$req_elements[] = "Libraries: ";
152-
foreach ($request["libraries"] as $key => $var) {
153-
$req_elements[] = $key;
154-
}
155-
}
156-
$this->compiler_logger->addInfo(implode(" ", $req_elements));
157-
}
158-
159159
if ($ARCHIVE_OPTION === true){
160160
$arch_ret = $this->createArchive($compiler_dir, $TEMP_DIR, $ARCHIVE_DIR, $ARCHIVE_PATH);
161161
if ($arch_ret["success"] === false)
@@ -348,6 +348,10 @@ function main($request, $compiler_config)
348348
}
349349

350350
if ($ret_link){
351+
352+
// Log the fact that an error occurred during linking
353+
$this->compiler_logger->addInfo($compiler_config["compiler_dir"] . " - An error occurred during linking: " . json_encode(implode("\n", $output)));
354+
351355
if ($ARCHIVE_OPTION === true){
352356
$arch_ret = $this->createArchive($compiler_dir, $TEMP_DIR, $ARCHIVE_DIR, $ARCHIVE_PATH);
353357
if ($arch_ret["success"] === false)
@@ -658,21 +662,20 @@ private function doCompile($compiler_config, &$files, $dir, $CC, $CFLAGS, $CPP,
658662
if (array_diff(array_keys($clangElements), array_keys($gccElements))) {
659663
$resp["old_message"] = $output;
660664

661-
$this->compiler_logger->addInfo("Mismatch between clang and gcc output found.");
662-
$new_clang_output = $this->cleanUpClangOutput($output);
665+
$this->compiler_logger->addInfo($compiler_config["compiler_dir"] . " - Mismatch between clang and gcc output found.");
666+
$new_clang_output = $this->cleanUpClangOutput($output, $compiler_config);
663667

664668
$clangElements = $this->getClangErrorFileList ($new_clang_output);
665669
if (array_diff(array_keys($clangElements), array_keys($gccElements)))
666-
$this->compiler_logger->addInfo("Clang still reports errors in different files than gcc.");
670+
$this->compiler_logger->addInfo($compiler_config["compiler_dir"] . " - Clang still reports errors in different files than gcc.");
667671
else
668-
$this->compiler_logger->addInfo("Clang reports errors in the same files as gcc.");
672+
$this->compiler_logger->addInfo($compiler_config["compiler_dir"] . " - Clang reports errors in the same files as gcc.");
669673

670-
$this->compiler_logger->addInfo("Gcc output: " . $avr_output);
671-
$this->compiler_logger->addInfo("Clang initial output: " . $output);
672-
$this->compiler_logger->addInfo("Clang reformated output: " . $new_clang_output);
674+
$this->compiler_logger->addInfo($compiler_config["compiler_dir"] . " - Gcc output: " . json_encode($avr_output));
675+
$this->compiler_logger->addInfo($compiler_config["compiler_dir"] . " - Clang initial output: " . json_encode($output));
676+
$this->compiler_logger->addInfo($compiler_config["compiler_dir"] . " - Clang reformated output: " . json_encode($new_clang_output));
673677

674678
$resp["message"] = $new_clang_output;
675-
return array_merge($resp, array("clang_diff" => true));
676679
}
677680

678681
return $resp;
@@ -1098,7 +1101,7 @@ private function getGccErrorFileList ($avr_output) {
10981101
return $gcc_elements;
10991102
}
11001103

1101-
private function cleanUpClangOutput ($clang_output) {
1104+
private function cleanUpClangOutput ($clang_output, $compiler_config) {
11021105

11031106
$clang_output = strip_tags($clang_output);
11041107
$content_line_array = explode("\n", $clang_output);
@@ -1122,20 +1125,26 @@ private function cleanUpClangOutput ($clang_output) {
11221125

11231126
if ($header_found === false) {
11241127
if (preg_match('/(\/compiler\.\w+\/libraries\/)/', $header)
1125-
|| strpos($header, "core") !== false
1128+
|| strpos($header, $compiler_config["arduino_cores_dir"]) !== false
1129+
|| (array_key_exists("external_core_files", $compiler_config)
1130+
&& strpos($header, $compiler_config["external_core_files"]) !== false)
11261131
|| strpos($header, "note:") !== false
1132+
|| strpos($header, "in asm") !== false
11271133
|| strpos($body, "in asm") !== false) {
11281134

11291135
if (preg_match('/(\/compiler\.\w+\/libraries\/)/', $header) && $libFound === false) {
1130-
$this->compiler_logger->addInfo("Clang reports library issue.");
1136+
$this->compiler_logger->addInfo($compiler_config["compiler_dir"] . " - Clang reports library issue.");
11311137
$libFound = true;
11321138
}
1133-
if (strpos($header, "core") !== false && $coreFound === false) {
1134-
$this->compiler_logger->addInfo("Clang reports core issue.");
1139+
if ((strpos($header, $compiler_config["arduino_cores_dir"]) !== false
1140+
|| (array_key_exists("external_core_files", $compiler_config)
1141+
&& strpos($header, $compiler_config["external_core_files"]) !== false))
1142+
&& $coreFound === false) {
1143+
$this->compiler_logger->addInfo($compiler_config["compiler_dir"] . " - Clang reports core issue.");
11351144
$coreFound = true;
11361145
}
11371146
if (strpos($body, "in asm") !== false && $asmFound === false) {
1138-
$this->compiler_logger->addInfo("Clang reports assembly issue.");
1147+
$this->compiler_logger->addInfo($compiler_config["compiler_dir"] . " - Clang reports assembly issue.");
11391148
$asmFound = true;
11401149
}
11411150
$header = "";
@@ -1157,8 +1166,11 @@ private function cleanUpClangOutput ($clang_output) {
11571166

11581167
if (!array_key_exists($key + 1, $content_line_array)) {
11591168
if (!preg_match('/(\/compiler\.\w+\/libraries\/)/', $header)
1160-
&& strpos($header, "core") === false
1169+
&& strpos($header, $compiler_config["arduino_cores_dir"]) === false
1170+
&& (array_key_exists("external_core_files", $compiler_config)
1171+
&& strpos($header, $compiler_config["external_core_files"]) === false)
11611172
&& strpos($header, "note:") === false
1173+
&& strpos($header, "in asm") === false
11621174
&& strpos($body, "in asm") === false) {
11631175
if ($header != "" && $body != "") {
11641176
$final .= $header ."\n";

0 commit comments

Comments
 (0)