@@ -27,6 +27,7 @@ class CompilerHandler
27
27
private $ utility ;
28
28
private $ compiler_logger ;
29
29
private $ object_directory ;
30
+ private $ logger_id ;
30
31
31
32
function __construct (PreprocessingHandler $ preprocHandl , PostprocessingHandler $ postprocHandl , UtilityHandler $ utilHandl , Logger $ logger , $ objdir )
32
33
{
@@ -116,21 +117,33 @@ function main($request, $compiler_config)
116
117
117
118
// Log the names of the project files and the libraries used in it.
118
119
if ($ format != "autocomplete " ) {
120
+ $ user_id = "" ;
121
+ $ sketch_id = "" ;
119
122
$ req_elements = array ();
120
123
$ req_elements [] = "Files: " ;
121
124
foreach ($ request ["files " ] as $ file ) {
122
125
$ 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
+ }
123
132
}
124
133
125
134
if ($ request ["libraries " ]) {
126
135
$ 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 " ];
129
139
}
130
140
}
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 ));
132
145
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 " );
134
147
}
135
148
136
149
// Step 4: Syntax-check and compile source files.
@@ -342,7 +355,7 @@ function main($request, $compiler_config)
342
355
if ($ ret_link ){
343
356
344
357
// 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 )));
346
359
347
360
$ returner = array (
348
361
"success " => false ,
@@ -657,42 +670,46 @@ private function doCompile($compiler_config, &$files, $dir, $CC, $CFLAGS, $CPP,
657
670
* and if significant differences are detected, return a modified version of the clang output.
658
671
*/
659
672
$ 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 )));
661
674
$ 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 )));
663
676
664
677
if (array_diff (array_keys ($ clangElements ), array_keys ($ gccElements ))) {
665
678
666
679
$ 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. " );
668
681
669
682
$ next_clang_output = $ this ->cleanUpClangOutput ($ output , $ compiler_config , "asm " );
670
683
671
684
$ 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 )));
673
686
674
687
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. " );
676
689
$ final_clang_output = $ this ->cleanUpClangOutput ($ next_clang_output , $ compiler_config , "non_asm " );
677
690
678
691
$ clangElements = $ this ->getClangErrorFileList ($ final_clang_output );
679
692
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. " );
681
694
}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. " );
683
696
}
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 ));
687
700
$ final_clang_output = $ this ->pathRemover ($ final_clang_output , $ compiler_config );
688
701
$ resp ["message " ] = $ final_clang_output ;
702
+ if ($ resp ["message " ] == "" )
703
+ $ resp ["message " ] = $ this ->pathRemover ($ output , $ compiler_config );
689
704
return $ resp ;
690
705
}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 ));
694
709
$ next_clang_output = $ this ->pathRemover ($ next_clang_output , $ compiler_config );
695
710
$ resp ["message " ] = $ next_clang_output ;
711
+ if ($ resp ["message " ] == "" )
712
+ $ resp ["message " ] = $ this ->pathRemover ($ output , $ compiler_config );
696
713
return $ resp ;
697
714
}
698
715
}
@@ -1141,40 +1158,37 @@ private function cleanUpClangOutput ($clang_output, $compiler_config, $option) {
1141
1158
if ((strpos ($ line , "In file included from " ) !== false
1142
1159
&& preg_match ('/([\w*\s*(!@#$%^&*()-+; \'{}\[\])*]+\.\w+:\d+:[\d+:]?)/ ' , $ line ))
1143
1160
|| (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 )) {
1147
1162
1148
1163
if ($ header_found === false ) {
1149
1164
if (($ option == "non_asm " && preg_match ('/(\/compiler\.\w+\/libraries\/)/ ' , $ header )
1150
1165
|| strpos ($ header , $ compiler_config ["arduino_cores_dir " ]) !== false
1151
1166
|| (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 ))
1154
1168
|| ($ option == "asm "
1155
1169
&& (strpos ($ header , "in asm " ) !== false
1156
1170
|| strpos ($ body , "in asm " ) !== false ))) {
1157
1171
1158
1172
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. " );
1160
1174
$ libFound = true ;
1161
1175
}
1162
1176
if ((strpos ($ header , $ compiler_config ["arduino_cores_dir " ]) !== false
1163
1177
|| (array_key_exists ("external_core_files " , $ compiler_config )
1164
1178
&& strpos ($ header , $ compiler_config ["external_core_files " ]) !== false ))
1165
1179
&& $ 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. " );
1167
1181
$ coreFound = true ;
1168
1182
}
1169
1183
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. " );
1171
1185
$ asmFound = true ;
1172
1186
}
1173
1187
$ header = "" ;
1174
1188
$ body = "" ;
1175
1189
}
1176
1190
1177
- if ($ header != "" && $ body != "" ) {
1191
+ if ($ header != "" ) {
1178
1192
if (strpos ($ header , "</font></b> " ) == 0 )
1179
1193
$ header = substr_replace ($ header , '' , 0 , 11 );
1180
1194
if (array_key_exists ($ key + 1 , $ content_line_array )
@@ -1197,29 +1211,28 @@ private function cleanUpClangOutput ($clang_output, $compiler_config, $option) {
1197
1211
&& strpos ($ header , $ compiler_config ["arduino_cores_dir " ]) === false
1198
1212
&& (array_key_exists ("external_core_files " , $ compiler_config )
1199
1213
&& strpos ($ header , $ compiler_config ["external_core_files " ]) === false )
1200
- && strpos ($ header , "note: " ) === false
1201
1214
&& $ option == "non_asm " )
1202
1215
|| ($ option == "asm "
1203
1216
&& strpos ($ header , "in asm " ) === false
1204
1217
&& strpos ($ body , "in asm " ) === false )) {
1205
- if ($ header != "" && $ body != "" ) {
1218
+ if ($ header != "" ) {
1206
1219
if (strpos ($ header , "</font></b> " ) == 0 )
1207
1220
$ header = substr_replace ($ header , '' , 0 , 11 );
1208
1221
$ final .= $ header ."\n" ;
1209
1222
$ final .= $ body . "\n" ;
1210
1223
}
1211
1224
}else {
1212
1225
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. " );
1214
1227
}
1215
1228
if ((strpos ($ header , $ compiler_config ["arduino_cores_dir " ]) !== false
1216
1229
|| (array_key_exists ("external_core_files " , $ compiler_config )
1217
1230
&& strpos ($ header , $ compiler_config ["external_core_files " ]) !== false ))
1218
1231
&& $ 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. " );
1220
1233
}
1221
1234
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. " );
1223
1236
}
1224
1237
}
1225
1238
}
@@ -1234,22 +1247,18 @@ private function cleanUpClangOutput ($clang_output, $compiler_config, $option) {
1234
1247
1235
1248
private function pathRemover ($ output , $ compiler_config ) {
1236
1249
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
-
1242
1250
// Remove any instance of "compiler.RANDOM/files/" folder name from the text
1243
1251
$ modified = str_replace ($ compiler_config ["compiler_dir " ] . "/files/ " , '' , $ output );
1244
1252
1245
1253
// Remove any remaining instance of "compiler.RANDOM/" folder name from the text.
1246
1254
$ modified = str_replace ($ compiler_config ["compiler_dir " ] . "/ " , '' , $ modified );
1247
1255
1248
1256
// 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 );
1250
1258
1251
1259
// 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 );
1253
1262
1254
1263
return $ modified ;
1255
1264
}
0 commit comments