diff options
author | marha <marha@users.sourceforge.net> | 2009-08-04 11:56:03 +0000 |
---|---|---|
committer | marha <marha@users.sourceforge.net> | 2009-08-04 11:56:03 +0000 |
commit | e5838b892c8f8041868d3ee08110261cde13e098 (patch) | |
tree | f69d9e97a800f62bcf8798199559b0d96abd14a9 | |
parent | e2cafb0970b536247274e86ae949beeb7ab1e814 (diff) | |
download | vcxsrv-e5838b892c8f8041868d3ee08110261cde13e098.tar.gz vcxsrv-e5838b892c8f8041868d3ee08110261cde13e098.tar.bz2 vcxsrv-e5838b892c8f8041868d3ee08110261cde13e098.zip |
- 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.
-rw-r--r-- | tools/mhmake/mhmakevc6.sln | 24 | ||||
-rw-r--r-- | tools/mhmake/src/build.cpp | 81 | ||||
-rw-r--r-- | tools/mhmake/src/functions.cpp | 15 | ||||
-rw-r--r-- | tools/mhmake/src/mhmake.cpp | 9 | ||||
-rw-r--r-- | tools/mhmake/src/mhmakefileparser.h | 1 | ||||
-rw-r--r-- | tools/mhmake/src/util.cpp | 82 | ||||
-rw-r--r-- | tools/mhmake/src/util.h | 2 |
7 files changed, 112 insertions, 102 deletions
diff --git a/tools/mhmake/mhmakevc6.sln b/tools/mhmake/mhmakevc6.sln deleted file mode 100644 index beeee4160..000000000 --- a/tools/mhmake/mhmakevc6.sln +++ /dev/null @@ -1,24 +0,0 @@ -Microsoft Visual Studio Solution File, Format Version 8.00
-Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mhmake", "mhmakevc6.vcproj", "{7F1669C8-7974-45DF-9B71-0E2A8DC44C06}"
- ProjectSection(ProjectDependencies) = postProject
- EndProjectSection
-EndProject
-Global
- GlobalSection(SolutionConfiguration) = preSolution
- Debug = Debug
- Profile = Profile
- Release = Release
- EndGlobalSection
- GlobalSection(ProjectConfiguration) = postSolution
- {7F1669C8-7974-45DF-9B71-0E2A8DC44C06}.Debug.ActiveCfg = Debug|Win32
- {7F1669C8-7974-45DF-9B71-0E2A8DC44C06}.Debug.Build.0 = Debug|Win32
- {7F1669C8-7974-45DF-9B71-0E2A8DC44C06}.Profile.ActiveCfg = Profile|Win32
- {7F1669C8-7974-45DF-9B71-0E2A8DC44C06}.Profile.Build.0 = Profile|Win32
- {7F1669C8-7974-45DF-9B71-0E2A8DC44C06}.Release.ActiveCfg = Release|Win32
- {7F1669C8-7974-45DF-9B71-0E2A8DC44C06}.Release.Build.0 = Release|Win32
- EndGlobalSection
- GlobalSection(ExtensibilityGlobals) = postSolution
- EndGlobalSection
- GlobalSection(ExtensibilityAddIns) = postSolution
- EndGlobalSection
-EndGlobal
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<fileinfo> pSrc, refptr<fileinfo> pDest) static bool CopyDir(refptr<fileinfo> pDir,refptr<fileinfo> 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<fileinfo> pDir,refptr<fileinfo> 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<fileinfo> pSrc=GetFileInfo(FileName);
+ if (FindData.dwFileAttributes&FILE_ATTRIBUTE_HIDDEN)
+ continue;
+ refptr<fileinfo> pSrc=GetFileInfo(FindData.cFileName,pDir);
if (pSrc->IsDir())
{
- /* Currently we do not do a recursion */
+ refptr<fileinfo> 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<fileinfo> pDir,refptr<fileinfo> pDest,const string Wi for (int i=0; i<Res.gl_pathc; i++)
{
- int Len=strlen(Res.gl_pathv[i])-1;
- if (Res.gl_pathv[i][Len]=='/')
+ refptr<fileinfo> 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<fileinfo> 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<fileinfo> &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()<<endl;
}
diff --git a/tools/mhmake/src/functions.cpp b/tools/mhmake/src/functions.cpp index 4ae9ddd2e..9564610f8 100644 --- a/tools/mhmake/src/functions.cpp +++ b/tools/mhmake/src/functions.cpp @@ -51,6 +51,7 @@ funcdef mhmakefileparser::m_FunctionsDef[]= { ,{"filter-out" ,&mhmakefileparser::f_filterout}
,{"word" ,&mhmakefileparser::f_word}
,{"words" ,&mhmakefileparser::f_words}
+ ,{"strip" ,&mhmakefileparser::f_strip}
};
map<string,function_f> mhmakefileparser::m_Functions;
@@ -625,6 +626,20 @@ string mhmakefileparser::f_words(const string & Arg) const }
///////////////////////////////////////////////////////////////////////////////
+// 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 &)
{
int Pos=FileName.find_last_of(OSPATHSEP);
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<fileinfo> 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<loadedmakefile> 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 "<<EntriesFile<<endl;
- #endif
- return;
- }
+ // We do it with the svn info command
- /* Check the format of this file, if it is 8 it is the new format else it is the old format. We do
- * this by inspecting the first line of the file
- */
- char Line[255];
- if (fgets(Line,sizeof(Line),pFile))
- {
- int iVersion=atoi(Line);
- if (iVersion<8)
- {
- // This is the old format
- while (fgets(Line,sizeof(Line),pFile))
- {
- if (!strncmp(Line," url=\"",8))
+ string Output;
+ bool Ret;
+ try
{
- char *pUrl=Line+8+7;
- char *pEnd=strchr(pUrl,'"');
- #ifdef _DEBUG
- if (!pEnd)
- {
- cerr<<"Format of entries file in .svn directory must have been changed. Update mhmake!\n";
- exit(1);
+ string SvnCommand=SearchCommand("svn",EXEEXT);
+ Ret=OsExeCommand(SvnCommand,string(" info ")+m_MhMakeConf->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"
|