The result of this utility command can now be optionally added to the cache

This commit is contained in:
Sebastien Barre 2001-10-23 17:49:13 -04:00
parent 10c54eb2a5
commit cc731ac548
2 changed files with 28 additions and 4 deletions

View File

@ -50,6 +50,17 @@ bool cmGetFilenameComponentCommand::InitialPass(std::vector<std::string> const&
return false;
}
// Check and see if the value has been stored in the cache
// already, if so use that value
if(args.size() == 4 && args[3] == "CACHE")
{
const char* cacheValue = m_Makefile->GetDefinition(args[0].c_str());
if(cacheValue && strcmp(cacheValue, "NOTFOUND"))
{
return true;
}
}
std::string result;
std::string filename = args[1];
m_Makefile->ExpandVariablesInString(filename);
@ -77,7 +88,18 @@ bool cmGetFilenameComponentCommand::InitialPass(std::vector<std::string> const&
return false;
}
m_Makefile->AddDefinition(args[0].c_str(), result.c_str());
if(args.size() == 4 && args[3] == "CACHE")
{
m_Makefile->AddCacheDefinition(args[0].c_str(),
result.c_str(),
"",
args[2] == "PATH" ? cmCacheManager::FILEPATH
: cmCacheManager::STRING);
}
else
{
m_Makefile->AddDefinition(args[0].c_str(), result.c_str());
}
return true;
}

View File

@ -48,7 +48,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* cmGetFilenameComponentCommand is a utility command used to get the path,
* name, extension or name without extension of a full filename.
* Warning: as a utility command, the resulting value is not put in the cache.
*/
class cmGetFilenameComponentCommand : public cmCommand
{
@ -92,11 +91,14 @@ public:
virtual const char* GetFullDocumentation()
{
return
"GET_FILENAME_COMPONENT(VarName FileName PATH|NAME|EXT|NAME_WE)\n"
"GET_FILENAME_COMPONENT(VarName FileName PATH|NAME|EXT|NAME_WE [CACHE])\n"
"Set VarName to be the path (PATH), file name (NAME), file "
"extension (EXT) or file name without extension (NAME_WE) of FileName.\n"
"Note that the path is converted to Unix slashes format and has no "
"trailing slashes. The longest file extension is always considered.";
"trailing slashes. The longest file extension is always considered.\n"
"Warning: as a utility command, the resulting value is not put in the "
"cache but in the definition list, unless you add the optional CACHE "
"parameter.";
}
cmTypeMacro(cmGetFilenameComponentCommand, cmCommand);