From 5a54fa6e45ee10cf58ee1b6d2eb5522a24bb8745 Mon Sep 17 00:00:00 2001 From: marha Date: Thu, 12 Sep 2013 11:38:41 +0200 Subject: Some minor modifications Ignore pipe symbols when in dependency list Solved some linking problems in linux Solved problem calling svn info when using svn version from cygwin --- tools/mhmake/.gitignore | 2 + tools/mhmake/mhmake.vcxproj | 13 +-- tools/mhmake/src/curdir.cpp | 3 + tools/mhmake/src/mhmakefileparser.cpp | 2 +- tools/mhmake/src/mhmakelexer.l | 28 +++++-- tools/mhmake/src/mhmakeparser.y | 7 +- tools/mhmake/src/rule.cpp | 1 - tools/mhmake/src/util.cpp | 150 +++++++++++++++++----------------- tools/mhmake/src/util.h | 39 ++++++++- 9 files changed, 147 insertions(+), 98 deletions(-) create mode 100644 tools/mhmake/.gitignore diff --git a/tools/mhmake/.gitignore b/tools/mhmake/.gitignore new file mode 100644 index 000000000..d24abb6c4 --- /dev/null +++ b/tools/mhmake/.gitignore @@ -0,0 +1,2 @@ +Debug64 +Release64 diff --git a/tools/mhmake/mhmake.vcxproj b/tools/mhmake/mhmake.vcxproj index 2b395f11f..e50224eba 100644 --- a/tools/mhmake/mhmake.vcxproj +++ b/tools/mhmake/mhmake.vcxproj @@ -153,8 +153,6 @@ true - - Console false @@ -194,6 +192,7 @@ FastCall Default 4267;4996;4244;%(DisableSpecificWarnings) + $(TargetDir)$(TargetName).pdb NDEBUG;%(PreprocessorDefinitions) @@ -268,6 +267,7 @@ ProgramDatabase Default 4267;4996;4244;%(DisableSpecificWarnings) + $(TargetDir)$(TargetName).pdb _DEBUG;%(PreprocessorDefinitions) @@ -277,7 +277,6 @@ $(OutDir)\mhmake_dbg.exe true true - .\Debug/mhmake.pdb Console false @@ -307,7 +306,6 @@ Use stdafx.h $(Configuration)/mhmake.pch - $(IntDir) Level3 true ProgramDatabase @@ -322,7 +320,6 @@ true true - $(OutDir)\$(ProjectName).pdb true true Console @@ -360,13 +357,13 @@ Use stdafx.h $(Configuration)/mhmake.pch - $(IntDir) Level3 true ProgramDatabase FastCall Default 4267;4996;4244;%(DisableSpecificWarnings) + $(TargetDir)$(TargetName).pdb NDEBUG;%(PreprocessorDefinitions) @@ -376,7 +373,6 @@ $(Configuration)/mhmake.exe true true - $(OutDir)\$(ProjectName).pdb true true Console @@ -455,21 +451,18 @@ $(IntDir)%(Filename).cpp;$(IntDir)%(Filename).hpp;$(IntDir)location.hh;$(IntDir)position.hh;$(IntDir)stack.hh cmd.exe /c makebison.bat Debug64 - .\src\bison.cc;.\src\bison.h;%(AdditionalInputs) $(OutDir)%(Filename).cpp;$(OutDir)%(Filename).h;%(Outputs) cmd.exe /c makebison.bat Profile %(RelativeDir)bisondata/bison.m4;%(RelativeDir)bisondata/lalr1.cc;%(RelativeDir)bisondata/c++.m4;%(RelativeDir)bisondata/c.m4;%(RelativeDir)bisondata/location.cc $(IntDir)%(Filename).cpp;$(IntDir)%(Filename).hpp;$(IntDir)location.hh;$(IntDir)position.hh;$(IntDir)stack.hh cmd.exe /c makebison.bat Profile64 - .\src\bison.cc;.\src\bison.h;%(AdditionalInputs) $(OutDir)%(Filename).cpp;$(OutDir)%(Filename).h;%(Outputs) cmd.exe /c makebison.bat Release %(RelativeDir)bisondata/bison.m4;%(RelativeDir)bisondata/lalr1.cc;%(RelativeDir)bisondata/c++.m4;%(RelativeDir)bisondata/c.m4;%(RelativeDir)bisondata/location.cc $(IntDir)%(Filename).cpp;$(IntDir)%(Filename).hpp;$(IntDir)location.hh;$(IntDir)position.hh;$(IntDir)stack.hh cmd.exe /c makebison.bat Release64 - .\src\bison.cc;.\src\bison.h;%(AdditionalInputs) $(OutDir)%(Filename).cpp;$(OutDir)%(Filename).h;%(Outputs) diff --git a/tools/mhmake/src/curdir.cpp b/tools/mhmake/src/curdir.cpp index b87dc4f6f..d2b43ab52 100644 --- a/tools/mhmake/src/curdir.cpp +++ b/tools/mhmake/src/curdir.cpp @@ -23,9 +23,12 @@ #include "fileinfo.h" #include "curdir.h" #include "util.h" +#include "mhmakeparser.hpp" fileinfos g_FileInfos; // declare here since it is important that it is constructed before m_pcurrentdir curdir::initcurdir curdir::m_pCurrentDir; +loadedmakefile::loadedmakefile_statics loadedmakefile::sm_Statics; // Declare this here because this constructor is using g_FileInfos and m_pCurrentDir +LOADEDMAKEFILES g_LoadedMakefiles; // Declare it here otherwize problems in the destructor (still using items from g_FileInfos) /////////////////////////////////////////////////////////////////////////////// curdir::initcurdir::initcurdir() diff --git a/tools/mhmake/src/mhmakefileparser.cpp b/tools/mhmake/src/mhmakefileparser.cpp index 4a50d6edd..0731d1ce9 100644 --- a/tools/mhmake/src/mhmakefileparser.cpp +++ b/tools/mhmake/src/mhmakefileparser.cpp @@ -379,7 +379,7 @@ void mhmakefileparser::SplitToItems(const string &String,vector &Item { string Item; pTmp=NextItem(pTmp,Item); - if (!Item.empty()) + if (!Item.empty() && Item!="|") { Items.push_back(GetFileInfo(Item,m_MakeDir)); } diff --git a/tools/mhmake/src/mhmakelexer.l b/tools/mhmake/src/mhmakelexer.l index 9b933c305..e336fefbf 100644 --- a/tools/mhmake/src/mhmakelexer.l +++ b/tools/mhmake/src/mhmakelexer.l @@ -254,6 +254,20 @@ load_makefile { return yy::mhmakeparser::token::SPACE; } + /*---------------------------------------------------------------------------*/ +[ \t]*\|[ \t]*\\[ \t\r]*\n[ \t]* { + PRINTF(("%s %d: EQUAL: %s\n",m_InputFileName.c_str(),lineno(),yytext)); + inclineno(); + yylval->theString=" | "; + return yy::mhmakeparser::token::PIPE; +} + +[ \t]*\|[ \t]* { + PRINTF(("%s %d: EQUAL: %s\n",m_InputFileName.c_str(),lineno(),yytext)); + yylval->theString=" | "; + return yy::mhmakeparser::token::PIPE; +} + /*---------------------------------------------------------------------------*/ [ \t]*=[ \t]*\\[ \t\r]*\n[ \t]* { PRINTF(("%s %d: EQUAL: %s\n",m_InputFileName.c_str(),lineno(),yytext)); @@ -680,7 +694,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); @@ -690,14 +704,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; @@ -841,8 +855,8 @@ export { /*---------------------------------------------------------------------------*/ \r /* skip */ -[^\\\"\r\n$]+ | -[\\\$] | +[^\\\"\r\n$]+ | +[\\\$] | \\\" | \\# { yymore(); @@ -860,8 +874,8 @@ export { \r /* skip */ [^\\\'\r\n$]+ | -[\\\$] | -\\\' | +[\\\$] | +\\\' | \\# { yymore(); } diff --git a/tools/mhmake/src/mhmakeparser.y b/tools/mhmake/src/mhmakeparser.y index d8edb1d51..f9042f780 100644 --- a/tools/mhmake/src/mhmakeparser.y +++ b/tools/mhmake/src/mhmakeparser.y @@ -52,7 +52,7 @@ const char Test[]="dit is een test"; %token END 0 "end of file" %token COMMAND %token COMMA -%token STRING DOLLAREXPR EQUAL COLON DOUBLECOLON VARDEF VARVAL +%token STRING DOLLAREXPR PIPE EQUAL COLON DOUBLECOLON VARDEF VARVAL %token IMEQUAL PEQUAL OPTEQUAL PHONY AUTODEPS EXPORT NEWLINE INCLUDEMAK SPACE VPATH ENVVARS_TOIGNORE %type expression nonspaceexpression simpleexpression @@ -136,8 +136,8 @@ ruledef: expression_nocolorequal rulecolon maybeemptyexpression throw string("Empty left hand side in rule: ") + $1 + " : " + $3; } #endif - m_pMakefile->SplitToItems(m_pMakefile->ExpandExpression($1),*m_pMakefile->m_pCurrentItems); - m_pMakefile->SplitToItems(m_pMakefile->ExpandExpression($3),*m_pMakefile->m_pCurrentDeps); + m_pMakefile->SplitToItems(m_pMakefile->ExpandExpression($1), *m_pMakefile->m_pCurrentItems); + m_pMakefile->SplitToItems(m_pMakefile->ExpandExpression($3), *m_pMakefile->m_pCurrentDeps); m_pMakefile->m_DoubleColonRule= ($2==1) ; PRINTF(("Defining rule %s : %s\n",$1.c_str(),$3.c_str())); PRINTF((" Expanded to %s : %s\n",m_pMakefile->ExpandExpression($1).c_str(),m_pMakefile->ExpandExpression($3).c_str())); @@ -286,6 +286,7 @@ nonspaceexpression_nocolorequal: simpleexpression_nocolorequal | ; simpleexpression: simpleexpression_nocolorequal | + PIPE | EQUAL | COLON | DOUBLECOLON | diff --git a/tools/mhmake/src/rule.cpp b/tools/mhmake/src/rule.cpp index 35884e2f0..b3f682e95 100644 --- a/tools/mhmake/src/rule.cpp +++ b/tools/mhmake/src/rule.cpp @@ -32,7 +32,6 @@ vector IMPLICITRULE::m_ImplicitRules; makecommand g_MakeCommand; // Order is important since sm_Statics is using g_MakeCommand const string g_QuoteString("\""); // Order is important since sm_Statics is using g_QuoteString -loadedmakefile::loadedmakefile_statics loadedmakefile::sm_Statics; /////////////////////////////////////////////////////////////////////////////// static bool FindDep(fileinfo *pTarget, implicitruledep_t *pImplicitRule,refptr &Rule) diff --git a/tools/mhmake/src/util.cpp b/tools/mhmake/src/util.cpp index 9fe006e95..e1fcf0d27 100644 --- a/tools/mhmake/src/util.cpp +++ b/tools/mhmake/src/util.cpp @@ -335,92 +335,92 @@ refptr LOADEDMAKEFILES::find(const loadedmakefile &ToSearch) return refptr(); } -LOADEDMAKEFILES g_LoadedMakefiles; - /////////////////////////////////////////////////////////////////////////////// -loadedmakefile::loadedmakefile_statics::loadedmakefile_statics() +bool loadedmakefile::loadedmakefile_statics::GetSvnRevision(void) { - m_GlobalCommandLineVars[MAKE]=g_MakeCommand; - const char *pEnv=getenv(MHMAKECONF); - if (pEnv) - { - m_MhMakeConf=GetAbsFileInfo(pEnv); - m_GlobalCommandLineVars[MHMAKECONF]=QuoteFileName(m_MhMakeConf->GetFullFileName()); + // Get the revision of the working copy + // We do it with the svn info command (do it without path arguments, only current directory, to avoid problems with path names and junctions/links - // Get the revision of the working copy - // We do it with the svn info command + string Output; + try + { + mhmakefileparser Dummy(m_MhMakeConf); + string SvnCommand=Dummy.SearchCommand("svn",EXEEXT); + Dummy.OsExeCommand(SvnCommand,string(" info"),false,&Output); + } + catch (string Message) + { + #ifdef _DEBUG + cerr << "Exception: " << Message << endl; + #endif + } - string Output; - try + char *pTok=strtok((char*)Output.c_str(),"\n"); // doing this is changing string, so this is very dangerous !!! + while (pTok) + { + if (!strncmp(pTok,"URL: ",5)) { - mhmakefileparser Dummy(curdir::GetCurDir()); - string SvnCommand=Dummy.SearchCommand("svn",EXEEXT); - #ifdef WIN32 - if (GetFileAttributes(m_MhMakeConf->GetFullFileName().c_str())&FILE_ATTRIBUTE_REPARSE_POINT) - { - WIN32_FIND_DATA FindData; - HANDLE hFind=FindFirstFile(m_MhMakeConf->GetFullFileName().c_str(),&FindData); - if (hFind!=INVALID_HANDLE_VALUE) - { - if (FindData.dwReserved0==IO_REPARSE_TAG_MOUNT_POINT) - { - HANDLE hDir = ::CreateFile(m_MhMakeConf->GetFullFileName().c_str(), GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_FLAG_OPEN_REPARSE_POINT | FILE_FLAG_BACKUP_SEMANTICS, NULL); - - BYTE buf[MAXIMUM_REPARSE_DATA_BUFFER_SIZE]; // We need a large buffer - REPARSE_MOUNTPOINT_DATA_BUFFER& ReparseBuffer = (REPARSE_MOUNTPOINT_DATA_BUFFER&)buf; - DWORD dwRet; - - if (::DeviceIoControl(hDir, FSCTL_GET_REPARSE_POINT, NULL, 0, &ReparseBuffer, MAXIMUM_REPARSE_DATA_BUFFER_SIZE, &dwRet, NULL)) - { - // Success - ::CloseHandle(hDir); - - LPCWSTR pPath = ReparseBuffer.ReparseTarget; - if (wcsncmp(pPath, L"\\??\\", 4) == 0) pPath += 4; // Skip 'non-parsed' prefix - char szPath[MAX_PATH]; - ::WideCharToMultiByte(CP_ACP, 0, pPath, -1, szPath, MAX_PATH, NULL, NULL); - Dummy.OsExeCommand(SvnCommand,string(" info ")+GetFileInfo(szPath,m_MhMakeConf->GetDir())->GetQuotedFullFileName(),false,&Output); - } - else - { // Error - ::CloseHandle(hDir); - } - } - FindClose(hFind); - } - } - #else - struct stat Stat; - lstat(m_MhMakeConf->GetFullFileName().c_str(),&Stat); - if (S_ISLNK(Stat.st_mode)) - { - char FileName[1024]; - int len=readlink(m_MhMakeConf->GetFullFileName().c_str(),FileName,sizeof(FileName)); - FileName[len]=0; - Dummy.OsExeCommand(SvnCommand,string(" info ")+GetFileInfo(FileName,m_MhMakeConf->GetDir())->GetQuotedFullFileName(),false,&Output); - } - #endif - else - Dummy.OsExeCommand(SvnCommand,string(" info ")+m_MhMakeConf->GetQuotedFullFileName(),false,&Output); + m_GlobalCommandLineVars[WC_URL]=pTok+5+7; } - catch (string Message) + else if (!strncmp(pTok,"Revision: ",10)) { + m_GlobalCommandLineVars[WC_REVISION]=pTok+10; + return true; } + pTok=strtok(NULL,"\n"); + } + return false; +} - char *pTok=strtok((char*)Output.c_str(),"\n"); // doing this is changing string, so this is very dangerous !!! - while (pTok) +/////////////////////////////////////////////////////////////////////////////// +bool loadedmakefile::loadedmakefile_statics::GetGitSvnRevision(void) +{ + // Get the revision of the working copy + // We do it with the svn info command + + string Output; + try + { + mhmakefileparser Dummy(m_MhMakeConf); + string GitCommand=Dummy.SearchCommand("git",EXEEXT); + Dummy.OsExeCommand(GitCommand,string(" svn info ."), false, &Output); + } + catch (string Message) + { + #ifdef _DEBUG + cerr << "Exception: " << Message << endl; + #endif + } + + char *pTok=strtok((char*)Output.c_str(),"\n"); // doing this is changing string, so this is very dangerous !!! + while (pTok) + { + if (!strncmp(pTok,"URL: ",5)) { - if (!strncmp(pTok,"URL: ",5)) - { - m_GlobalCommandLineVars[WC_URL]=pTok+5+7; - } - else if (!strncmp(pTok,"Revision: ",10)) - { - m_GlobalCommandLineVars[WC_REVISION]=pTok+10; - break; - } - pTok=strtok(NULL,"\n"); + m_GlobalCommandLineVars[WC_URL]=pTok+5+7; + } + else if (!strncmp(pTok,"Revision: ",10)) + { + m_GlobalCommandLineVars[WC_REVISION]=pTok+10; + return true; } + pTok=strtok(NULL,"\n"); + } + return false; +} + +/////////////////////////////////////////////////////////////////////////////// +loadedmakefile::loadedmakefile_statics::loadedmakefile_statics() +{ + m_GlobalCommandLineVars[MAKE]=g_MakeCommand; + const char *pEnv=getenv(MHMAKECONF); + if (pEnv) + { + m_MhMakeConf=GetAbsFileInfo(pEnv); + m_GlobalCommandLineVars[MHMAKECONF]=QuoteFileName(m_MhMakeConf->GetFullFileName()); + + if (!GetSvnRevision()) + GetGitSvnRevision(); } } diff --git a/tools/mhmake/src/util.h b/tools/mhmake/src/util.h index b1a18c3ed..01e766520 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.21" +#define MHMAKEVER "3.0.25" class makecommand { @@ -65,6 +65,24 @@ public: extern makecommand g_MakeCommand; +/////////////////////////////////////////////////////////////////////////////// +inline string unescapeString(const string &InStr) +{ + string OutStr; + string::const_iterator It=InStr.cbegin(); + string::const_iterator ItEnd=InStr.cend(); + while (It!=ItEnd) + { + char Ch=*It++; + if (Ch=='\\' && It!=ItEnd) + { + Ch=*It++; + } + OutStr+=Ch; + } + return OutStr; +} + /////////////////////////////////////////////////////////////////////////////// inline const char *NextItem(const char *pTmp,string &Output, const char *pToks=" \t") { @@ -202,6 +220,9 @@ struct loadedmakefile : public refbase fileinfo *m_MhMakeConf; loadedmakefile_statics(); + + bool GetSvnRevision(void); + bool GetGitSvnRevision(void); }; static loadedmakefile_statics sm_Statics; @@ -212,6 +233,11 @@ struct loadedmakefile : public refbase vector m_CommandLineTargets; refptr m_pMakefileParser; + loadedmakefile() + { + // Dummy, only used below + } + loadedmakefile(const fileinfo *pDir, vector &Args,const string &Makefile=g_EmptyString); void LoadMakefile(); @@ -261,11 +287,22 @@ struct loadedmakefile : public refbase } return 1; } +public: + fileinfo *GetMhMakeConf() + { + return sm_Statics.m_MhMakeConf; + } + }; class LOADEDMAKEFILES : public vector > { public: + LOADEDMAKEFILES() + { + loadedmakefile temp; + temp.GetMhMakeConf(); // Just to be here to control the order of destruction (sm_Statics may not be destructed before g_LoadedMakefiles) + } refptr find(const loadedmakefile &pToSearch); typedef vector >::iterator iterator; }; -- cgit v1.2.3