diff options
author | marha <marha@users.sourceforge.net> | 2012-03-12 11:51:16 +0100 |
---|---|---|
committer | marha <marha@users.sourceforge.net> | 2012-03-12 11:51:16 +0100 |
commit | 96276c847a5c266f9f51f3ec4ece8fe3f1381c96 (patch) | |
tree | cced2f3df95ab841e860e39413203c93aebb6c07 /tools | |
parent | 2b6ab5ff6c32e8bda9f50e38d12367502d3dd32c (diff) | |
download | vcxsrv-96276c847a5c266f9f51f3ec4ece8fe3f1381c96.tar.gz vcxsrv-96276c847a5c266f9f51f3ec4ece8fe3f1381c96.tar.bz2 vcxsrv-96276c847a5c266f9f51f3ec4ece8fe3f1381c96.zip |
Made creation of temp files interprocess safe in windows
Fixes for 64-bit compilation
Implemented realpath function
Improved auodep scanning
Solved a problem in dependency scanning
Diffstat (limited to 'tools')
-rw-r--r-- | tools/mhmake/src/build.cpp | 78 | ||||
-rw-r--r-- | tools/mhmake/src/fileinfo.cpp | 2 | ||||
-rw-r--r-- | tools/mhmake/src/functions.cpp | 19 | ||||
-rw-r--r-- | tools/mhmake/src/mhmakefileparser.cpp | 6 | ||||
-rw-r--r-- | tools/mhmake/src/mhmakefileparser.h | 1 | ||||
-rw-r--r-- | tools/mhmake/src/mhmakelexer.l | 12 | ||||
-rw-r--r-- | tools/mhmake/src/util.h | 2 |
7 files changed, 83 insertions, 37 deletions
diff --git a/tools/mhmake/src/build.cpp b/tools/mhmake/src/build.cpp index ee79ad4f6..ba6a6e4da 100644 --- a/tools/mhmake/src/build.cpp +++ b/tools/mhmake/src/build.cpp @@ -771,12 +771,12 @@ string mhmakefileparser::GetFullCommand(const string &CommandIn) return pFound->second;
}
-static void CommandSep(const string &Command, int &EndPos, int &NextBegin)
+static void CommandSep(const string &Command, unsigned &EndPos, unsigned &NextBegin)
{
while (1)
{
EndPos=Command.find('&',NextBegin);
- if (EndPos==string::npos || !EndPos)
+ if (EndPos==(unsigned)string::npos || !EndPos)
{
// When there is only one command return that command, so we run %comspec% commands
// always via a temporary batch file. This is to avoid problems when quotes and pipe
@@ -790,15 +790,15 @@ static void CommandSep(const string &Command, int &EndPos, int &NextBegin) {
continue;
}
- if (NextBegin!=Command.length())
+ if (NextBegin<Command.length())
{
C=Command[NextBegin];
if (strchr("|<>",C))
{
continue;
}
- }
while (strchr(" \t|<>",Command[NextBegin])) NextBegin++;
+ }
while (strchr(" \t|<>",Command[EndPos])) EndPos--;
break;
};
@@ -817,30 +817,41 @@ mh_pid_t mhmakefileparser::OsExeCommand(const string &Command, const string &Par if (Command.substr(0,ComSpec.size())==ComSpec)
{
+ static char Filename[MAX_PATH];
+ static char *pFilenameOffset;
+
+ if (pFilenameOffset==NULL)
+ {
+ const char *pDir=getenv("TEMP");
+ if (!pDir)
+ pDir=getenv("TMP");
+ if (!pDir)
+ pDir=m_MakeDir->GetFullFileName().c_str();
+ sprintf(Filename, "%s\\tmp%d_", pDir, GetCurrentProcessId());
+ pFilenameOffset=Filename+strlen(Filename);
+ }
+
string tmpCommand=Command.substr(ComSpec.size(),Command.size());
FullCommandLine=ComSpec;
string ComspecCommandLine=tmpCommand+Params;
- int NextBegin=0;
- int EndPos=0;
+ unsigned NextBegin=0;
+ unsigned EndPos=0;
CommandSep(ComspecCommandLine,EndPos,NextBegin);
// We have multiple commands so create an temporary batch file
- FILE *pFile=(FILE*)1;
- char Filename[MAX_PATH];
- int Nr=1;
+ FILE *pFile;
while (1)
{
- sprintf(Filename,"%s\\tmp%d.bat",m_MakeDir->GetFullFileName().c_str(),Nr);
+ sprintf(pFilenameOffset,"%d.bat",rand());
pFile=fopen(Filename,"r");
if (!pFile)
break;
fclose(pFile);
- Nr++;
}
pFile=fopen(Filename,"w");
fprintf(pFile,"@echo off\n");
- int PrevPos=0;
- while (EndPos!=string::npos)
+ unsigned PrevPos=0;
+ while (EndPos!=(unsigned)string::npos)
{
string SubCommand=ComspecCommandLine.substr(PrevPos,EndPos-PrevPos+1);
fprintf(pFile,"%s\n",SubCommand.c_str());
@@ -1144,9 +1155,9 @@ string EscapeQuotes(const string &Params) string ToReplace(Quote);
int Inc=1;
- if (Pos==string::npos)
+ if (Pos==(int)string::npos)
{
- if (Pos2==string::npos)
+ if (Pos2==(int)string::npos)
break;
Pos=Pos2;
ToReplace=SemiColon;
@@ -1154,7 +1165,7 @@ string EscapeQuotes(const string &Params) }
else
{
- if (Pos2!=string::npos && Pos2<Pos)
+ if (Pos2!=(int)string::npos && Pos2<Pos)
{
Pos=Pos2;
ToReplace=SemiColon;
@@ -1171,6 +1182,29 @@ string EscapeQuotes(const string &Params) #endif
///////////////////////////////////////////////////////////////////////////////
+static bool NeedsShell(const string &Params)
+{
+ unsigned i;
+ int Detect=1;
+ for (i=0; i<Params.size(); i++)
+ {
+ char Char=Params[i];
+ if (Char=='"')
+ {
+ Detect=1-Detect;
+ }
+ else if (Detect)
+ {
+ if (strchr("<>|&",Char))
+ {
+ break;
+ }
+ }
+ }
+ return i!=Params.size();
+}
+
+///////////////////////////////////////////////////////////////////////////////
mh_pid_t mhmakefileparser::ExecuteCommand(string Command, bool &IgnoreError, string *pOutput)
{
bool Echo=true;
@@ -1218,15 +1252,7 @@ mh_pid_t mhmakefileparser::ExecuteCommand(string Command, bool &IgnoreError, str Command=Command.substr(StartCommandPos,EndCommandPos-StartCommandPos);
// If we have special characters in the params we always call the command via the shell
- unsigned i;
- for (i=0; i<Params.size(); i++)
- {
- if (strchr("<>|&",Params[i]))
- {
- break;
- }
- }
- if (i==Params.size())
+ if (!NeedsShell(Params))
{
if (Command!="del" && Command!="touch" && Command!="copy" && Command!="echo" && Command!="mkdir")
Command=GetFullCommand(Command);
@@ -1488,7 +1514,7 @@ mh_time_t mhmakefileparser::StartBuildTarget(fileinfo* pTarget,bool bCheckTarget #endif
if (ImplicitRuleDepsIt==ResultIt->first.end()) // All deps exists
{
- ThisYoungestDate=YoungestDate;
+ YoungestDate=ThisYoungestDate;
pRule=ResultIt->second;
pTarget->InsertDeps(ResultIt->first);
pTarget->SetRule(pRule); /* This is an implicit rule so do not add the target */
diff --git a/tools/mhmake/src/fileinfo.cpp b/tools/mhmake/src/fileinfo.cpp index 939a83ce6..9f4ae1ca1 100644 --- a/tools/mhmake/src/fileinfo.cpp +++ b/tools/mhmake/src/fileinfo.cpp @@ -42,7 +42,7 @@ string QuoteFileName(const string &Filename) #else
int Pos=0;
/* Escape the spaces with a backslash */
- while ((Pos=Ret.find_first_of(' ',Pos))!=string::npos)
+ while ((Pos=Ret.find_first_of(' ',Pos))!=(int)string::npos)
{
Ret=Ret.replace(Pos,1,"\\ ");
Pos+=2;
diff --git a/tools/mhmake/src/functions.cpp b/tools/mhmake/src/functions.cpp index 1071d2604..7393035cf 100644 --- a/tools/mhmake/src/functions.cpp +++ b/tools/mhmake/src/functions.cpp @@ -41,6 +41,7 @@ funcdef mhmakefileparser::m_FunctionsDef[]= { ,{"dir", &mhmakefileparser::f_dir}
,{"shell", &mhmakefileparser::f_shell}
,{"relpath", &mhmakefileparser::f_relpath}
+ ,{"realpath", &mhmakefileparser::f_realpath}
,{"toupper", &mhmakefileparser::f_toupper}
,{"tolower", &mhmakefileparser::f_tolower}
,{"exist", &mhmakefileparser::f_exist}
@@ -829,6 +830,24 @@ string mhmakefileparser::f_relpath(const string & FileNames) const }
///////////////////////////////////////////////////////////////////////////////
+static string realpath(const string &FileName,void *pvDir)
+{
+ const fileinfo *pDir=*(const fileinfo **)pvDir;
+ const fileinfo *pPath=GetFileInfo(FileName,pDir);
+ if (pPath->Exists())
+ return pPath->GetQuotedFullFileName();
+ else
+ return "";
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// Make a path name relative to the current directory
+string mhmakefileparser::f_realpath(const string & FileNames) const
+{
+ return IterList(ExpandExpression(FileNames),realpath,(void*)&m_MakeDir);
+}
+
+///////////////////////////////////////////////////////////////////////////////
static string makeupper(const string &FileName,void *)
{
string Ret=FileName;
diff --git a/tools/mhmake/src/mhmakefileparser.cpp b/tools/mhmake/src/mhmakefileparser.cpp index a359de117..d1f41b07f 100644 --- a/tools/mhmake/src/mhmakefileparser.cpp +++ b/tools/mhmake/src/mhmakefileparser.cpp @@ -517,7 +517,7 @@ void mhmakefileparser::GetAutoDeps(const fileinfo *pFirstDep, deps_t &Autodeps) Type[0]='"';
if (Ret=='i')
{
- Ret=fscanf(pIn,"mport %254[^\"\n]",IncludeList);
+ Ret=fscanf(pIn,"mport%*[ \t]%254[^\"\n]",IncludeList);
if (Ret==1)
{
if (IncludeList[0]!='*')
@@ -552,10 +552,10 @@ void mhmakefileparser::GetAutoDeps(const fileinfo *pFirstDep, deps_t &Autodeps) if (Ret=='#')
{
Ret=fscanf(pIn,"%*[ \t]");
- Ret=fscanf(pIn,"include %1[\"<]%254[^>\"]%*[\">]",(char*)&Type,IncludeList);
+ Ret=fscanf(pIn,"include%*[ \t]%1[\"<]%254[^>\"]%*[\">]",(char*)&Type,IncludeList);
}
else
- Ret=fscanf(pIn,"import %1[\"<]%254[^>\"]%*[\">]",(char*)&Type,IncludeList);
+ Ret=fscanf(pIn,"import%*[ \t]%1[\"<]%254[^>\"]%*[\">]",(char*)&Type,IncludeList);
if (Ret==2)
{
bFound=true;
diff --git a/tools/mhmake/src/mhmakefileparser.h b/tools/mhmake/src/mhmakefileparser.h index 82e783dd0..9ad13446c 100644 --- a/tools/mhmake/src/mhmakefileparser.h +++ b/tools/mhmake/src/mhmakefileparser.h @@ -290,6 +290,7 @@ public: string f_dir(const string & Arg) const;
string f_shell(const string & Arg) const;
string f_relpath(const string & Arg) const;
+ string f_realpath(const string & Arg) const;
string f_toupper(const string & Arg) const;
string f_tolower(const string & Arg) const;
string f_exist(const string & Arg) const;
diff --git a/tools/mhmake/src/mhmakelexer.l b/tools/mhmake/src/mhmakelexer.l index aa396ceaf..9dc1a23a0 100644 --- a/tools/mhmake/src/mhmakelexer.l +++ b/tools/mhmake/src/mhmakelexer.l @@ -59,7 +59,7 @@ static void SaveMakMd5(fileinfo *pTarget) static void ReplaceCurlyBraces(string &String)
{
int Pos=String.find_first_of('{',0);
- if (Pos!=string::npos)
+ if (Pos!=(int)string::npos)
{
/* if not { found, } will not be there eather (or it is a valid syntax, so it may generate an error) */
do
@@ -67,9 +67,9 @@ static void ReplaceCurlyBraces(string &String) String.replace(Pos,1,1,'(');
Pos=String.find_first_of('{',Pos);
}
- while (Pos!=string::npos);
+ while (Pos!=(int)string::npos);
Pos=0;
- while ((Pos=String.find_first_of('}',Pos))!=string::npos)
+ while ((Pos=String.find_first_of('}',Pos))!=(int)string::npos)
String.replace(Pos,1,1,')');
}
}
@@ -661,7 +661,7 @@ export { }
/*---------------------------------------------------------------------------*/
-([a-zA-Z0-9\\\._\~\-\+%\@<&;/\*\|]|\\\ |\\#)+\\[ \t\r]*\n {
+([a-zA-Z0-9\\\._\~\-\+%\@<&;/\*\|]|\\\ |\\#|\\\")+\\[ \t\r]*\n {
size_t EndIndex=yyleng;
while (strchr(" \t\r\n\\",yytext[--EndIndex]));
yyless(EndIndex+1);
@@ -671,14 +671,14 @@ export { return yy::mhmakeparser::token::STRING;
}
-([a-zA-Z0-9\\\._\~\-\+%\@<&;/\*\|]|\\\ |\\#)+\+= {
+([a-zA-Z0-9\\\._\~\-\+%\@<&;/\*\|]|\\\ |\\#|\\\")+\+= {
PRINTF(("%s %d: STRING: %s\n",m_InputFileName.c_str(),lineno(),yytext));
yyless(yyleng-2);
yylval->theString=(const char *)yytext;
return yy::mhmakeparser::token::STRING;
}
-([a-zA-Z0-9\\\._\~\-\+%\@<&;/\*\|\[\]]|\\\ |\\#)+ {
+([a-zA-Z0-9\\\._\~\-\+%\@<&;/\*\|\[\]]|\\\ |\\#|\\\")+ {
PRINTF(("%s %d: STRING: %s\n",m_InputFileName.c_str(),lineno(),yytext));
yylval->theString=(const char *)yytext;
return yy::mhmakeparser::token::STRING;
diff --git a/tools/mhmake/src/util.h b/tools/mhmake/src/util.h index adb154497..b4a17a6cf 100644 --- a/tools/mhmake/src/util.h +++ b/tools/mhmake/src/util.h @@ -50,7 +50,7 @@ #define PLATFORM "linux"
#endif
-#define MHMAKEVER "3.0.9"
+#define MHMAKEVER "3.0.15"
class makecommand
{
|