Bool CCompiler::OnCompileFail( ) { CL_TRACE("Enter CCompiler::OnCompileFail"); FileSystem::FileHandle compileLogFile = FileSystem::CreateFile(EFileType::E_FILE_TYPE_MEMORY); if( !compileLogFile->Open( m_compilerOutputFile, EAccesMode::E_ACCES_MODE_READ ) ) { CL_ERROR( "failed to open file:[%s]", m_compilerOutputFile.GetBuffer() ); return false; } u64 fileSize = compileLogFile->GetSize(); CString fileContent; fileContent.Resize(fileSize); if( !compileLogFile->Read( fileContent.GetBuffer(), fileSize, 1 ) ) { CL_ERROR( "failed to read file content for:[%s]" ,m_compilerOutputFile.GetBuffer() ); return false; } #define COMPILER_USE_FULL_DEVENV_OUTPUT #if !defined(COMPILER_USE_FULL_DEVENV_OUTPUT) //replace CompilerDummy.cpp with our file CString slnCppFileName = GetSolutionCppFileRaw(); CString sourceFileName = "CodSursa.cpp"; CRegex regexReplace( slnCppFileName ); fileContent = regexReplace.Replace( fileContent, sourceFileName); CL_TRACE("fileContent:\n[%s]\n=======================", fileContent.GetBuffer()); //CL_ERROR("fileContent:\n[%s]\n=======================", fileContent.GetBuffer()); const CString regexString = sourceFileName + "\\([0-9]+\\):.*error C[0-9]+:[^\n]*"; CRegex errorRegex( regexString, true ); CRegex::TCaptures errors; if( !errorRegex.Find( fileContent, errors ) ) { CL_ERROR( "failed to find errors in file:[%s]",m_compilerOutputFile.GetBuffer() ); return false; } for( u64 i=0; i<errors.GetSize(); i++ ) { const CString& error = errors[i]; m_compileErrors += error; } #else m_compileErrors = fileContent; #endif //COMPILER_USE_FULL_DEVENV_OUTPUT return true; // The OnCompileFailed step succeeded; }
/* set_sector: */ static void set_sector ( MbColony *colony, MbObject *sector ) { MbObject *t_mine; GList *l; MbsTaskFuncs funcs = { t_mine_init, t_mine_check, t_mine_process }; MB_COLONY_CLASS(parent_class)->set_sector(colony, sector); /* create the mine tasks */ t_mine = mb_task_find(MB_TASK(MB_COLONY_TOP_TASK(colony)), "work/mine"); ASSERT(t_mine); for (l = MB_SECTOR(sector)->veins; l; l = l->next) { MbObject *vein = l->data; MbObject *task; CL_TRACE("%s", MB_RESOURCE_NAME(MB_VEIN_RESOURCE(vein))); task = mb_task_get_child(MB_TASK(t_mine), MB_RESOURCE_NAME(MB_VEIN_RESOURCE(vein))); if (task) continue; task = mbs_task_new(MB_OBJECT_GAME(sector), MB_RESOURCE_NAME(MB_VEIN_RESOURCE(vein)), MB_POP_FLAG_ADULT_WORKER, MB_VEIN_RESOURCE(vein), &funcs); mb_task_add(MB_TASK(t_mine), task); l_object_unref(task); } }
Bool CCompiler::RunCompileStep ( ) { CL_TRACE("Enter CCompiler::RunCompileStep"); // remove the old .exe if exists; CPath::DeleteFile( GetCompiledExeFilePath() ); // run bat file to setup visual studio env settings; CString outputFileCommandLineParameter = (m_compilerOutputFile.GetLenght()==0)? "" : (" /Out " + StringUtils::Quote(m_compilerOutputFile) ); CString command = CString("devenv.exe ") + StringUtils::Quote( GetSolutionFile() ) + " /Rebuild \"Release|Win32\"" + outputFileCommandLineParameter; Bool rez = true; CString currDir; CPath::GetCurrPath(currDir); CPath::SetCurrPath( GetDevenvPath() ); if( !RunCommand(command) ) { CPath::SetCurrPath( currDir ); return false; } rez &= CPath::SetCurrPath( currDir ); return true; }
Bool CCompiler::RunPreCompileStep( ) { CL_TRACE("Enter CCompiler::RunPreCompileStep"); //if( !CopyCppFile() ) //{ // CL_ERROR("failed to copy cpp files"); // return false; //} if( !CopySourceCode( m_sourceCodeToCompile ) ) { CL_ERROR("failed to copy source"); return false; } // delete output file to have a clean compile log CPath::DeleteFile( m_compilerOutputFile ); CString pathToSettupBat; if( !ThGetEnvVariable(ms_vsEnvToolsVar, pathToSettupBat) ) { CL_ERROR("failed to get path to settup bat from env variable:[%s]", ms_vsEnvToolsVar ); return false; } CString vsSettupCommand = "call \"" + pathToSettupBat + ms_vsSetupBat + "\""; if( !RunCommand(vsSettupCommand) ) { return false; } return true; }
Bool CCompiler::RunCommand ( const CString& command ) { const char* ptr = command.GetBuffer(); CL_TRACE("Running command:[%s]", ptr ); int rezult = system(command.GetBuffer()); CL_TRACE("command [%s] has finished with result:[%d]", command.GetBuffer(), rezult ); if( rezult != 0 ) { return false; } return true; }
// main function to compile a file Bool CCompiler::Compile ( ) { CL_TRACE("Begining compiling..."); if( !RunPreCompileStep() ) { CL_ERROR( "failed to run precompile step\n" ); SetStatus( ECompilerStatus_InternalFail ); return false; } if( !RunCompileStep( ) ) { CL_TRACE("Compilation failed..Trying to retrive the errors"); if( OnCompileFail() ) { SetStatus( ECompilerStatus_CompileFailed ); return true; } else { SetStatus( ECompilerStatus_InternalFail ); return false; } } else { CL_TRACE("Compilation succeded...Trying go get the rezult of the program"); if( OnCompileSucceeded() ) { SetStatus( ECompilerStatus_CompileSucceeded ); return true; } else { SetStatus( ECompilerStatus_InternalFail ); return false; } } return true; // Compile step succeeded; }
Bool CCompiler::OnInit( const char* sourceCode, const char* programInput, const char* helperSolutionPath ) { CL_TRACE("Initializing Compiler with"); if( !sourceCode ) { CL_ERROR("Failed to init Compiler! Source code is NULL"); return false; } m_programInput = programInput; m_sourceCodeToCompile = sourceCode; if( !helperSolutionPath ) { CL_ERROR(" helper solution path not found"); return false; } // set helper solution path and validate it; m_helperSolutionPath = helperSolutionPath; if( !CPath::IsAbsolute(m_helperSolutionPath) ) { CL_ERROR("solution path provided is not absolute:[%s]", m_helperSolutionPath.GetBuffer() ); return false; } if( !CPath::DirectoryExists(m_helperSolutionPath) ) { CL_ERROR( "solution directoy does not exists:[%s]", m_helperSolutionPath.GetBuffer() ); return false; } if( !CPath::GetCurrPath( m_workingDir ) ) { CL_ERROR("initialization step failed. Cannot get current directory"); return false; } CPath::SetCurrPath( m_helperSolutionPath ); if( !CPath::GetAbsolutePath(ms_compilerLogFile, m_compilerOutputFile) ) { CL_ERROR( "failed to get absolute path from path:[%s]", ms_compilerLogFile ); return false; } // get path to devenv and validate it; CString vsToolsPath; ThGetEnvVariable( ms_vsEnvToolsVar, vsToolsPath ); vsToolsPath += "..\\IDE\\"; if( !CPath::GetAbsolutePath(vsToolsPath, m_devenvPath ) ) { CL_ERROR( " failed to get devenv absolute path from tools path:[%s]", vsToolsPath.GetBuffer() ); return false; } CString devenvExecutableFullPath = m_devenvPath + "devenv.exe"; if( !CPath::FileExists( devenvExecutableFullPath ) ) { CL_ERROR( "failed to get path to devenv.exe. We got [%s] but this file does not exists!", devenvExecutableFullPath.GetBuffer() ); return false; } CL_TRACE("Compile initialization succeeded"); return true; }
CCompiler::CCompiler() :m_compileStatus ( ECompilerStatus_InternalFail ) { CL_TRACE("Enter Compiler Constructor"); CPath::SetCurrPath(m_workingDir); }