From e5838b892c8f8041868d3ee08110261cde13e098 Mon Sep 17 00:00:00 2001 From: marha Date: Tue, 4 Aug 2009 11:56:03 +0000 Subject: - Made copy command recursive when copying a directory. - When -q is specified output nothing. - Solved problem when mhmake is run from inside Visual Studio (output of cl.exe was send directly to the IDE instead of stdout) - Added strip function - Now use the svn info command to get the revision from the working copy. - Removed VC6 solution file. --- tools/mhmake/src/build.cpp | 81 +++++++++++++++++++++++++++++------- tools/mhmake/src/functions.cpp | 15 +++++++ tools/mhmake/src/mhmake.cpp | 9 ++++ tools/mhmake/src/mhmakefileparser.h | 1 + tools/mhmake/src/util.cpp | 82 +++++++++---------------------------- tools/mhmake/src/util.h | 2 +- 6 files changed, 112 insertions(+), 78 deletions(-) (limited to 'tools/mhmake/src') diff --git a/tools/mhmake/src/build.cpp b/tools/mhmake/src/build.cpp index 865ac8e2c..feae1eb25 100644 --- a/tools/mhmake/src/build.cpp +++ b/tools/mhmake/src/build.cpp @@ -296,7 +296,7 @@ found: #endif /*****************************************************************************/ -static string SearchCommand(const string &Command, const string &Extension="") +string SearchCommand(const string &Command, const string &Extension="") { char FullCommand[MAX_PATH]=""; unsigned long Size=sizeof(FullCommand); @@ -499,14 +499,13 @@ static bool CopyFile(refptr pSrc, refptr pDest) static bool CopyDir(refptr pDir,refptr pDest,const string WildSearch="*") { bool Error=true; - string Dir=pDir->GetFullFileName()+OSPATHSEP; - string Pattern=Dir+WildSearch; + string Pattern=pDir->GetFullFileName()+OSPATHSEP+WildSearch; #ifdef WIN32 WIN32_FIND_DATA FindData; HANDLE hFind=FindFirstFile(Pattern.c_str(),&FindData); if (hFind==INVALID_HANDLE_VALUE) { - return Error; + return false; } do @@ -514,20 +513,41 @@ static bool CopyDir(refptr pDir,refptr pDest,const string Wi /* Only handle items which are not . and .. */ if (FindData.cFileName[0]!='.' || (FindData.cFileName[1] && (FindData.cFileName[1]!='.' || FindData.cFileName[2])) ) { - string FileName=Dir+FindData.cFileName; - refptr pSrc=GetFileInfo(FileName); + if (FindData.dwFileAttributes&FILE_ATTRIBUTE_HIDDEN) + continue; + refptr pSrc=GetFileInfo(FindData.cFileName,pDir); if (pSrc->IsDir()) { - /* Currently we do not do a recursion */ + refptr pNewDest=GetFileInfo(FindData.cFileName,pDest); + if (!pNewDest->IsDir()) + { + if (pNewDest->Exists()) + { + cerr << pNewDest->GetFullFileName() << " exists and is not a directory.\n"; + Error = false; + goto exit; + } + if (!CreateDirectory(pNewDest->GetFullFileName().c_str(),NULL)) + { + cerr << "Error creating directory " << pNewDest->GetFullFileName() << endl; + Error = false; + goto exit; + } + pNewDest->InvalidateDate(); + } + Error = CopyDir(pSrc,pNewDest); + if (!Error) goto exit; } else { Error = CopyFile(pSrc,pDest); + if (!Error) goto exit; } } } while (FindNextFile(hFind,&FindData)); +exit: FindClose(hFind); #else glob_t Res; @@ -536,18 +556,43 @@ static bool CopyDir(refptr pDir,refptr pDest,const string Wi for (int i=0; i pSrc=GetFileInfo(Res.gl_pathv[i]); + if (pSrc->IsDir()) { - Res.gl_pathv[i][Len]=0; - /* Do not recurs for the moment: Error = CopyDir(Res.gl_pathv[i]); */ + *(strrchr(Res.gl_pathv[i],'/'))='\0'; + const char *SrcDirName=strrchr(Res.gl_pathv[i],'/')+1; + + if (SrcDirName[0]=='.') + continue; + + refptr pNewDest=GetFileInfo(SrcDirName,pDest); + if (!pNewDest->IsDir()) + { + if (pNewDest->Exists()) + { + cerr << pNewDest->GetFullFileName() << " exists and is not a directory.\n"; + Error = false; + goto exit; + } + if (-1==mkdir(pNewDest->GetFullFileName().c_str(),0777)) + { + cerr << "Error creating directory " << pNewDest->GetFullFileName() << endl; + Error = false; + goto exit; + } + pNewDest->InvalidateDate(); + } + Error = CopyDir(pSrc,pNewDest); + if (!Error) goto exit; } else { Error = CopyFile(GetFileInfo(Res.gl_pathv[i]),pDest); + if (!Error) goto exit; } } +exit: globfree(&Res); #endif @@ -638,7 +683,11 @@ static bool CopyFiles(const string &Params) /* Now check if there is a wildcard */ if (SrcFileName.find('*')!=string::npos) { - CopyDir(pSrc->GetDir(), pDest, pSrc->GetName()); + if (!CopyDir(pSrc->GetDir(), pDest, pSrc->GetName())) + { + cerr << "copy: Error copying directory: " << Params << endl; + return false; + } } else { @@ -958,7 +1007,7 @@ string mhmakefileparser::GetFullCommand(string Command) return pFound->second; } -static bool OsExeCommand(const string &Command,const string &Params,bool IgnoreError,string *pOutput) +bool OsExeCommand(const string &Command,const string &Params,bool IgnoreError,string *pOutput) { #ifdef WIN32 STARTUPINFO StartupInfo; @@ -1299,7 +1348,7 @@ bool mhmakefileparser::ExecuteCommand(string Command,string *pOutput) if (i==Params.size()) { if (Command!="del" && Command!="touch" && Command!="copy" && Command!="echo") - Command=GetFullCommand(Command);// + Params; + Command=GetFullCommand(Command); #ifndef WIN32 if (Command.substr(0,GetComspec().size())==GetComspec()) { @@ -1584,7 +1633,9 @@ mh_time_t mhmakefileparser::BuildTarget(const refptr &Target,bool bChe pMakefile->InitEnv(); // Make sure that the exports are set in the evironment #ifdef _DEBUG - if (!g_GenProjectTree) + if (!g_GenProjectTree && !g_Quiet) +#else + if (!g_Quiet) #endif cout << "Building " << Target->GetFullFileName()< mhmakefileparser::m_Functions; @@ -624,6 +625,20 @@ string mhmakefileparser::f_words(const string & Arg) const return szNumber; } +/////////////////////////////////////////////////////////////////////////////// +// Removes leading and trailing space +string mhmakefileparser::f_strip(const string & Arg) const +{ + string::const_iterator pFirst=Arg.begin(); + string::const_iterator pLast=Arg.end(); + while (strchr(" \t",*pFirst) && pFirst!=pLast) pFirst++; + if (pFirst==pLast) + return ""; + while (strchr(" \t",*(--pLast))); + pLast++; + return Arg.substr(pFirst-Arg.begin(),pLast-pFirst); +} + /////////////////////////////////////////////////////////////////////////////// static string dir(const string &FileName,const string &) { diff --git a/tools/mhmake/src/mhmake.cpp b/tools/mhmake/src/mhmake.cpp index 7e9b117b2..375621fb4 100644 --- a/tools/mhmake/src/mhmake.cpp +++ b/tools/mhmake/src/mhmake.cpp @@ -50,6 +50,15 @@ int __CDECL main(int argc, char* argv[]) //_CrtSetBreakAlloc(44); #endif + #ifdef WIN32 + /* Remove the VS_UNICODE_OUTPUT environment variable. This variable is set when running from + * the Visual Studio IDE and is causing the output of cl.exe to send the output directly to the IDE instead + * of sending it to stdout. This is causing all scripts that are calling cl.exe and intercept the + * output to fail. + */ + putenv("VS_UNICODE_OUTPUT="); + #endif + try { mhmakefileparser::InitBuildTime(); diff --git a/tools/mhmake/src/mhmakefileparser.h b/tools/mhmake/src/mhmakefileparser.h index 9d41c393d..84d69a878 100644 --- a/tools/mhmake/src/mhmakefileparser.h +++ b/tools/mhmake/src/mhmakefileparser.h @@ -209,6 +209,7 @@ public: string f_filterout(const string & Arg) const; string f_word(const string & Arg) const; string f_words(const string & Arg) const; + string f_strip(const string & Arg) const; const refptr GetFirstTarget() const { diff --git a/tools/mhmake/src/util.cpp b/tools/mhmake/src/util.cpp index 2e0b7dea6..824c94b4d 100644 --- a/tools/mhmake/src/util.cpp +++ b/tools/mhmake/src/util.cpp @@ -255,6 +255,9 @@ refptr LOADEDMAKEFILES::find(const loadedmakefile &ToSearch) LOADEDMAKEFILES g_LoadedMakefiles; +bool OsExeCommand(const string &Command,const string &Params,bool IgnoreError,string *pOutput); +string SearchCommand(const string &Command, const string &Extension=""); + /////////////////////////////////////////////////////////////////////////////// loadedmakefile::loadedmakefile_statics::loadedmakefile_statics() { @@ -266,79 +269,34 @@ loadedmakefile::loadedmakefile_statics::loadedmakefile_statics() m_MhMakeConf=GetFileInfo(pEnv); // Get the revision of the working copy - // We do it the fastest way: this means just parsing the entries file in the .svn directory of the mhmakeconf directory - string EntriesFile=m_MhMakeConf->GetFullFileName()+OSPATHSEPSTR".svn"OSPATHSEPSTR"entries"; - FILE *pFile=fopen(EntriesFile.c_str(),"r"); - if (!pFile) - { - /* Entries file cannot be opened. Maybe it is not an svn working copy, so ignore it */ - #ifdef _DEBUG - if (g_PrintAdditionalInfo) cout<<"Warning: Assuming no subversion working copy: Error opening "<GetFullFileName(),false,&Output); } - #endif - *pEnd='\0'; - m_GlobalCommandLineVars[WC_URL]=pUrl; - } - if (!strncmp(Line," revision=\"",13)) - { - char *pRevision=Line+13; - char *pEnd=strchr(pRevision,'"'); - #ifdef _DEBUG - if (!pEnd) + catch (int) { - cerr<<"Format of entries file in .svn directory must have been changed. Update mhmake!\n"; - exit(1); - } - #endif - *pEnd='\0'; - m_GlobalCommandLineVars[WC_REVISION]=pRevision; - break; - } + Ret=false; } - } - else + + char *pTok=strtok((char*)Output.c_str(),"\n"); // doing this is changing string, so this is very dangerous !!! + while (pTok) { - /* This is the new format */ - fgets(Line,sizeof(Line),pFile); - fgets(Line,sizeof(Line),pFile); - if (fgets(Line,sizeof(Line),pFile)) + if (!strncmp(pTok,"URL: ",5)) { - Line[strlen(Line)-1]=0; - m_GlobalCommandLineVars[WC_REVISION]=Line; + m_GlobalCommandLineVars[WC_URL]=pTok+5+7; } - if (fgets(Line,sizeof(Line),pFile)) + else if (!strncmp(pTok,"Revision: ",10)) { - Line[strlen(Line)-1]=0; - m_GlobalCommandLineVars[WC_URL]=Line+7; - } + m_GlobalCommandLineVars[WC_REVISION]=pTok+10; + break; } + pTok=strtok(NULL,"\n"); } - fclose(pFile); } } diff --git a/tools/mhmake/src/util.h b/tools/mhmake/src/util.h index 0b3005d54..8d71e4ca5 100644 --- a/tools/mhmake/src/util.h +++ b/tools/mhmake/src/util.h @@ -50,7 +50,7 @@ #define PLATFORM "linux" #endif -#define MHMAKEVER "1.3.14" +#define MHMAKEVER "1.3.21" #define MAKEDEPFILE ".makefile.dep" -- cgit v1.2.3