ENH: converted macro to use variables and fixed some case issues with some function blockers
This commit is contained in:
parent
553f7a04d0
commit
dec5cc1082
|
@ -27,7 +27,7 @@ IsFunctionBlocked(const cmListFileFunction& lff, cmMakefile &mf)
|
||||||
}
|
}
|
||||||
|
|
||||||
// at end of for each execute recorded commands
|
// at end of for each execute recorded commands
|
||||||
if (lff.m_Name == "ENDFOREACH")
|
if (cmSystemTools::LowerCase(lff.m_Name) == "endforeach")
|
||||||
{
|
{
|
||||||
std::vector<std::string> expandedArguments;
|
std::vector<std::string> expandedArguments;
|
||||||
mf.ExpandArguments(lff.m_Arguments, expandedArguments);
|
mf.ExpandArguments(lff.m_Arguments, expandedArguments);
|
||||||
|
@ -72,7 +72,7 @@ IsFunctionBlocked(const cmListFileFunction& lff, cmMakefile &mf)
|
||||||
bool cmForEachFunctionBlocker::
|
bool cmForEachFunctionBlocker::
|
||||||
ShouldRemove(const cmListFileFunction& lff, cmMakefile& mf)
|
ShouldRemove(const cmListFileFunction& lff, cmMakefile& mf)
|
||||||
{
|
{
|
||||||
if(lff.m_Name == "ENDFOREACH")
|
if(cmSystemTools::LowerCase(lff.m_Name) == "endforeach")
|
||||||
{
|
{
|
||||||
std::vector<std::string> expandedArguments;
|
std::vector<std::string> expandedArguments;
|
||||||
mf.ExpandArguments(lff.m_Arguments, expandedArguments);
|
mf.ExpandArguments(lff.m_Arguments, expandedArguments);
|
||||||
|
|
|
@ -25,19 +25,20 @@ IsFunctionBlocked(const cmListFileFunction& lff, cmMakefile &mf)
|
||||||
const char* name = lff.m_Name.c_str();
|
const char* name = lff.m_Name.c_str();
|
||||||
const std::vector<cmListFileArgument>& args = lff.m_Arguments;
|
const std::vector<cmListFileArgument>& args = lff.m_Arguments;
|
||||||
// always let if statements through
|
// always let if statements through
|
||||||
if (!strcmp(name,"IF"))
|
if (cmSystemTools::LowerCase(lff.m_Name) == "if")
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// watch for our ELSE or ENDIF
|
// watch for our ELSE or ENDIF
|
||||||
if (!strcmp(name,"ELSE") || !strcmp(name,"ENDIF"))
|
if (cmSystemTools::LowerCase(lff.m_Name) == "else" ||
|
||||||
|
cmSystemTools::LowerCase(lff.m_Name) == "endif")
|
||||||
{
|
{
|
||||||
if (args == m_Args)
|
if (args == m_Args)
|
||||||
{
|
{
|
||||||
// if it was an else statement then we should change state
|
// if it was an else statement then we should change state
|
||||||
// and block this Else Command
|
// and block this Else Command
|
||||||
if (!strcmp(name,"ELSE"))
|
if (cmSystemTools::LowerCase(lff.m_Name) == "else")
|
||||||
{
|
{
|
||||||
m_IsBlocking = !m_IsBlocking;
|
m_IsBlocking = !m_IsBlocking;
|
||||||
return true;
|
return true;
|
||||||
|
@ -72,7 +73,7 @@ IsFunctionBlocked(const cmListFileFunction& lff, cmMakefile &mf)
|
||||||
bool cmIfFunctionBlocker::ShouldRemove(const cmListFileFunction& lff,
|
bool cmIfFunctionBlocker::ShouldRemove(const cmListFileFunction& lff,
|
||||||
cmMakefile&)
|
cmMakefile&)
|
||||||
{
|
{
|
||||||
if (lff.m_Name == "ENDIF")
|
if (cmSystemTools::LowerCase(lff.m_Name) == "endif")
|
||||||
{
|
{
|
||||||
if (lff.m_Arguments == m_Args)
|
if (lff.m_Arguments == m_Args)
|
||||||
{
|
{
|
||||||
|
|
|
@ -112,53 +112,21 @@ bool cmMacroHelperCommand::InvokeInitialPass
|
||||||
// declare varuiables for ARGV ARGN but do not compute until needed
|
// declare varuiables for ARGV ARGN but do not compute until needed
|
||||||
std::string argvDef;
|
std::string argvDef;
|
||||||
std::string argnDef;
|
std::string argnDef;
|
||||||
bool argnDefInitialized = false;
|
|
||||||
bool argvDefInitialized = false;
|
bool argvDefInitialized = false;
|
||||||
|
|
||||||
// Invoke all the functions that were collected in the block.
|
// save the current definitions of all vars that we will be setting
|
||||||
cmListFileFunction newLFF;
|
std::string oldARGC;
|
||||||
// for each function
|
if (m_Makefile->GetDefinition("ARGC"))
|
||||||
for(unsigned int c = 0; c < m_Functions.size(); ++c)
|
|
||||||
{
|
{
|
||||||
// Replace the formal arguments and then invoke the command.
|
oldARGC = m_Makefile->GetDefinition("ARGC");
|
||||||
newLFF.m_Arguments.clear();
|
|
||||||
newLFF.m_Arguments.reserve(m_Functions[c].m_Arguments.size());
|
|
||||||
newLFF.m_Name = m_Functions[c].m_Name;
|
|
||||||
newLFF.m_FilePath = m_Functions[c].m_FilePath;
|
|
||||||
newLFF.m_Line = m_Functions[c].m_Line;
|
|
||||||
const char* def =
|
|
||||||
m_Makefile->GetDefinition("CMAKE_MACRO_REPORT_DEFINITION_LOCATION");
|
|
||||||
bool macroReportLocation = false;
|
|
||||||
if(def && !cmSystemTools::IsOff(def))
|
|
||||||
{
|
|
||||||
macroReportLocation = true;
|
|
||||||
}
|
}
|
||||||
|
m_Makefile->AddDefinition("ARGC",argcDef.c_str());
|
||||||
|
|
||||||
// for each argument of the current function
|
// store ARGN, ARGV
|
||||||
for (std::vector<cmListFileArgument>::const_iterator k =
|
std::vector<std::string> oldARGVArgs;
|
||||||
m_Functions[c].m_Arguments.begin();
|
|
||||||
k != m_Functions[c].m_Arguments.end(); ++k)
|
|
||||||
{
|
|
||||||
tmps = k->Value;
|
|
||||||
// replace formal arguments
|
|
||||||
for (unsigned int j = 1; j < m_Args.size(); ++j)
|
|
||||||
{
|
|
||||||
variable = "${";
|
|
||||||
variable += m_Args[j];
|
|
||||||
variable += "}";
|
|
||||||
cmSystemTools::ReplaceString(tmps, variable.c_str(),
|
|
||||||
expandedArgs[j-1].c_str());
|
|
||||||
}
|
|
||||||
// replace argc
|
|
||||||
cmSystemTools::ReplaceString(tmps, "${ARGC}",argcDef.c_str());
|
|
||||||
|
|
||||||
// repleace ARGN
|
|
||||||
if (tmps.find("${ARGN}") != std::string::npos)
|
|
||||||
{
|
|
||||||
if (!argnDefInitialized)
|
|
||||||
{
|
|
||||||
std::vector<std::string>::const_iterator eit;
|
std::vector<std::string>::const_iterator eit;
|
||||||
std::vector<std::string>::size_type cnt = 0;
|
std::vector<std::string>::size_type cnt = 0;
|
||||||
|
char argvName[60];
|
||||||
for ( eit = expandedArgs.begin(); eit != expandedArgs.end(); ++eit )
|
for ( eit = expandedArgs.begin(); eit != expandedArgs.end(); ++eit )
|
||||||
{
|
{
|
||||||
if ( cnt >= m_Args.size()-1 )
|
if ( cnt >= m_Args.size()-1 )
|
||||||
|
@ -169,81 +137,79 @@ bool cmMacroHelperCommand::InvokeInitialPass
|
||||||
}
|
}
|
||||||
argnDef += *eit;
|
argnDef += *eit;
|
||||||
}
|
}
|
||||||
cnt ++;
|
|
||||||
}
|
|
||||||
argnDefInitialized = true;
|
|
||||||
}
|
|
||||||
cmSystemTools::ReplaceString(tmps, "${ARGN}", argnDef.c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
// if the current argument of the current function has ${ARGV in it
|
|
||||||
// then try replacing ARGV values
|
|
||||||
if (tmps.find("${ARGV") != std::string::npos)
|
|
||||||
{
|
|
||||||
char argvName[60];
|
|
||||||
|
|
||||||
// repleace ARGV, compute it only once
|
|
||||||
if (!argvDefInitialized)
|
|
||||||
{
|
|
||||||
std::vector<std::string>::const_iterator eit;
|
|
||||||
for ( eit = expandedArgs.begin(); eit != expandedArgs.end(); ++eit )
|
|
||||||
{
|
|
||||||
if ( argvDef.size() > 0 )
|
if ( argvDef.size() > 0 )
|
||||||
{
|
{
|
||||||
argvDef += ";";
|
argvDef += ";";
|
||||||
}
|
}
|
||||||
argvDef += *eit;
|
argvDef += *eit;
|
||||||
}
|
oldARGVArgs.push_back(std::string());
|
||||||
argvDefInitialized = true;
|
sprintf(argvName,"ARGV%i",cnt);
|
||||||
}
|
if (m_Makefile->GetDefinition(argvName))
|
||||||
cmSystemTools::ReplaceString(tmps, "${ARGV}", argvDef.c_str());
|
|
||||||
|
|
||||||
// also replace the ARGV1 ARGV2 ... etc
|
|
||||||
for (unsigned int t = 0; t < expandedArgs.size(); ++t)
|
|
||||||
{
|
{
|
||||||
sprintf(argvName,"${ARGV%i}",t);
|
oldARGVArgs[cnt] = m_Makefile->GetDefinition(argvName);
|
||||||
cmSystemTools::ReplaceString(tmps, argvName,
|
|
||||||
expandedArgs[t].c_str());
|
|
||||||
}
|
}
|
||||||
|
m_Makefile->AddDefinition(argvName,eit->c_str());
|
||||||
|
cnt++;
|
||||||
|
}
|
||||||
|
std::string oldARGN;
|
||||||
|
if (m_Makefile->GetDefinition("ARGN"))
|
||||||
|
{
|
||||||
|
oldARGN = m_Makefile->GetDefinition("ARGN");
|
||||||
|
}
|
||||||
|
m_Makefile->AddDefinition("ARGN",argnDef.c_str());
|
||||||
|
std::string oldARGV;
|
||||||
|
if (m_Makefile->GetDefinition("ARGV"))
|
||||||
|
{
|
||||||
|
oldARGV = m_Makefile->GetDefinition("ARGV");
|
||||||
|
}
|
||||||
|
m_Makefile->AddDefinition("ARGV",argvDef.c_str());
|
||||||
|
|
||||||
|
// store old defs for formal args
|
||||||
|
std::vector<std::string> oldFormalArgs;
|
||||||
|
for (unsigned int j = 1; j < m_Args.size(); ++j)
|
||||||
|
{
|
||||||
|
oldFormalArgs.push_back(std::string());
|
||||||
|
if (m_Makefile->GetDefinition(m_Args[j].c_str()))
|
||||||
|
{
|
||||||
|
oldFormalArgs[j-1] = m_Makefile->GetDefinition(m_Args[j].c_str());
|
||||||
|
}
|
||||||
|
m_Makefile->AddDefinition(m_Args[j].c_str(),expandedArgs[j-1].c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
arg.Value = tmps;
|
// Invoke all the functions that were collected in the block.
|
||||||
arg.Quoted = k->Quoted;
|
for(unsigned int c = 0; c < m_Functions.size(); ++c)
|
||||||
if(macroReportLocation)
|
|
||||||
{
|
{
|
||||||
// Report the location of the argument where the macro was
|
if(!m_Makefile->ExecuteCommand(m_Functions[c]))
|
||||||
// defined.
|
|
||||||
arg.FilePath = k->FilePath;
|
|
||||||
arg.Line = k->Line;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Report the location of the argument where the macro was
|
|
||||||
// invoked.
|
|
||||||
if (args.size())
|
|
||||||
{
|
|
||||||
arg.FilePath = args[0].FilePath;
|
|
||||||
arg.Line = args[0].Line;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
arg.FilePath = "Unknown";
|
|
||||||
arg.Line = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
newLFF.m_Arguments.push_back(arg);
|
|
||||||
}
|
|
||||||
if(!m_Makefile->ExecuteCommand(newLFF))
|
|
||||||
{
|
{
|
||||||
cmOStringStream error;
|
cmOStringStream error;
|
||||||
error << "Error in cmake code at\n"
|
error << "Error in cmake code at\n"
|
||||||
<< args[0].FilePath << ":" << args[0].Line << ":\n"
|
<< args[0].FilePath << ":" << args[0].Line << "\n"
|
||||||
<< "A command failed during the invocation of macro \""
|
<< "A command failed during the invocation of macro \""
|
||||||
<< this->m_Args[0].c_str() << "\".";
|
<< this->m_Args[0].c_str() << "\".\nThe failing line "
|
||||||
|
<< "in the macro definition was at\n"
|
||||||
|
<< m_Functions[c].m_FilePath << ":"
|
||||||
|
<< m_Functions[c].m_Line << "\n";
|
||||||
cmSystemTools::Error(error.str().c_str());
|
cmSystemTools::Error(error.str().c_str());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// restore all args
|
||||||
|
m_Makefile->AddDefinition("ARGC",oldARGC.c_str());
|
||||||
|
m_Makefile->AddDefinition("ARGN",oldARGN.c_str());
|
||||||
|
m_Makefile->AddDefinition("ARGV",oldARGV.c_str());
|
||||||
|
// restore old defs for formal args
|
||||||
|
for (unsigned int j = 1; j < m_Args.size(); ++j)
|
||||||
|
{
|
||||||
|
m_Makefile->AddDefinition(m_Args[j].c_str(),oldFormalArgs[j-1].c_str());
|
||||||
|
}
|
||||||
|
// restore old defs for formal args
|
||||||
|
for (unsigned int j = 0; j < oldARGVArgs.size(); ++j)
|
||||||
|
{
|
||||||
|
sprintf(argvName,"ARGV%i",j);
|
||||||
|
m_Makefile->AddDefinition(argvName,oldARGVArgs[j].c_str());
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -252,7 +218,7 @@ IsFunctionBlocked(const cmListFileFunction& lff, cmMakefile &mf)
|
||||||
{
|
{
|
||||||
// record commands until we hit the ENDMACRO
|
// record commands until we hit the ENDMACRO
|
||||||
// at the ENDMACRO call we shift gears and start looking for invocations
|
// at the ENDMACRO call we shift gears and start looking for invocations
|
||||||
if(lff.m_Name == "ENDMACRO")
|
if(cmSystemTools::LowerCase(lff.m_Name) == "endmacro")
|
||||||
{
|
{
|
||||||
std::vector<std::string> expandedArguments;
|
std::vector<std::string> expandedArguments;
|
||||||
mf.ExpandArguments(lff.m_Arguments, expandedArguments);
|
mf.ExpandArguments(lff.m_Arguments, expandedArguments);
|
||||||
|
@ -292,7 +258,7 @@ IsFunctionBlocked(const cmListFileFunction& lff, cmMakefile &mf)
|
||||||
bool cmMacroFunctionBlocker::
|
bool cmMacroFunctionBlocker::
|
||||||
ShouldRemove(const cmListFileFunction& lff, cmMakefile &mf)
|
ShouldRemove(const cmListFileFunction& lff, cmMakefile &mf)
|
||||||
{
|
{
|
||||||
if(lff.m_Name == "ENDMACRO")
|
if(cmSystemTools::LowerCase(lff.m_Name) == "endmacro")
|
||||||
{
|
{
|
||||||
std::vector<std::string> expandedArguments;
|
std::vector<std::string> expandedArguments;
|
||||||
mf.ExpandArguments(lff.m_Arguments, expandedArguments);
|
mf.ExpandArguments(lff.m_Arguments, expandedArguments);
|
||||||
|
|
|
@ -28,7 +28,7 @@ IsFunctionBlocked(const cmListFileFunction& lff, cmMakefile &mf)
|
||||||
}
|
}
|
||||||
|
|
||||||
// at end of for each execute recorded commands
|
// at end of for each execute recorded commands
|
||||||
if (lff.m_Name == "ENDWHILE")
|
if (cmSystemTools::LowerCase(lff.m_Name) == "endwhile")
|
||||||
{
|
{
|
||||||
char* errorString = 0;
|
char* errorString = 0;
|
||||||
|
|
||||||
|
@ -64,7 +64,7 @@ IsFunctionBlocked(const cmListFileFunction& lff, cmMakefile &mf)
|
||||||
bool cmWhileFunctionBlocker::
|
bool cmWhileFunctionBlocker::
|
||||||
ShouldRemove(const cmListFileFunction& lff, cmMakefile& )
|
ShouldRemove(const cmListFileFunction& lff, cmMakefile& )
|
||||||
{
|
{
|
||||||
if(lff.m_Name == "ENDWHILE")
|
if(cmSystemTools::LowerCase(lff.m_Name) == "endwhile")
|
||||||
{
|
{
|
||||||
if (lff.m_Arguments == m_Args)
|
if (lff.m_Arguments == m_Args)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue