/** * Compile solution * * @param __self - task to be compiled * @param __cur_testing_dir - current testing directory * @param __cur_data_dir - directory with current data * @oaram __params - collecting params to return to WebIFACE * @return TRUE on success, FALSE or value less than zero in case of error */ static BOOL compile_solution (wt_task_t *__self, const char *__cur_testing_dir, const char *__cur_data_dir, assarr_t *__params) { char cmd[32768]; /* Generate command */ strcpy (cmd, ""); build_compiler_command (__self, __cur_testing_dir, __cur_data_dir, cmd); assarr_set_value (__params, "COMPILER_COMMAND", strdup (cmd)); /* Compile command not defined */ if (!strcmp (cmd, "")) { INF_DEBUG_LOG ("Task %ld. Compiler's command is undefined\n", __self->sid); TASK_LOG (*__self, "\n--------\nFatal error: Compiler command is " "undefined.\nTesting aborted.\n"); REPORT (__params, "Compiler command is undefined."); return -1; } if (!run_compiler (__self, cmd, __cur_testing_dir, __cur_data_dir, __params)) { return FALSE; } /* Some more checking */ return post_compiling_check (__self, __cur_testing_dir, __cur_data_dir, __params); }
int main(int argc, char **argv) { if(argc < 2) { puts("usage: win32_run_compiler cmd"); return 1; } int exit_code; int ret = run_compiler(argv[1], &exit_code); if(ret) return ret; if(exit_code == 0) fprintf(stderr, "@~good~@\n"); fclose(stderr); return 0; }
ParseFactsResult extract_facts_worker(const CompilerGuard& compiler, const std::string& filename, const char* code, int len, int maxRetries, bool verboseErrors ) { auto extract = [&](const CompilerGuard& c) { auto result = c->extract_facts(filename, folly::StringPiece(code, len)); return FactsJSONString { result }; }; auto internal_error = false; return run_compiler( compiler, maxRetries, verboseErrors, extract, internal_error); }
CompilerResult CompilerPool::compile(const char* code, int len, const char* filename, const MD5& md5, const Native::FuncTable& nativeFuncs, bool forDebuggerEval, AsmCallbacks* callbacks, bool& internal_error ) { auto compile = [&](const CompilerGuard& c) { return c->compile(filename, md5, folly::StringPiece(code, len), nativeFuncs, forDebuggerEval, callbacks); }; return run_compiler( CompilerGuard(*this), m_options.maxRetries, m_options.verboseErrors, compile, internal_error); }
compile_res_t compile(lang_t lang, char *src_path, char *exe_path, char *cerr_info) { pid_t pid = 0; if(access(cerr_file_path, F_OK) == -1) { if(creat(cerr_file_path, 0666)) { DBG("create compile error file failed."); return eCIe; } } else { if(truncate(cerr_file_path, 0)) //clear the compile error information file { DBG("clear compile error file failed."); return eCIe; } } int cerr_fd = open(cerr_file_path, O_WRONLY); if(cerr_fd < 0) { DBG("open compile error file failed."); return eCIe; } strcpy(exe_path, work_dir); strcat(exe_path, "exe/"); switch(lang) { case eC: case eCpp: case ePascal: strcat(exe_path, "main"); break; case eJava: strcat(exe_path, "Main.class"); break; case ePython: strcat(exe_path, "main.pyc"); break; default: break; } //[work_dir]/exe/[exe_file] DBG("exe_path:%s", exe_path); if((pid = fork()) == 0) /* create compiler process */ { dup2(cerr_fd, STDOUT_FILENO); dup2(cerr_fd, STDERR_FILENO); if(run_compiler(lang, src_path, exe_path)) { DBG("run_compiler error."); return eCIe; } } else if(pid < 0) { DBG("create compiler process failed."); return eCIe; } wait(pid); close(cerr_fd); unsigned long cerr_file_size = 0; struct stat buf; if(stat(cerr_file_path, &buf) < 0) { return eCIe; } cerr_file_size = (unsigned long)buf.st_size; if(!cerr_file_size) { if(access(exe_path, F_OK) == -1) { DBG("create exe file failed."); return eCIe; } return eCOk; } cerr_fd = open(cerr_file_path, O_RDONLY); int n = read(cerr_fd, cerr_info, cerr_file_size); close(cerr_fd); return eCErr; }