cmState::GetCacheEntryProperty: return cmProp

This commit is contained in:
Vitaly Stakhovsky 2020-03-25 14:00:00 -04:00
parent ea54f8d441
commit a7f2ff16a4
11 changed files with 32 additions and 29 deletions

View File

@ -71,11 +71,11 @@ cmCursesCacheEntryComposite::cmCursesCacheEntryComposite(
break;
}
case cmStateEnums::STRING: {
const char* stringsProp = state->GetCacheEntryProperty(key, "STRINGS");
cmProp stringsProp = state->GetCacheEntryProperty(key, "STRINGS");
if (stringsProp) {
auto ow =
cm::make_unique<cmCursesOptionsWidget>(this->EntryWidth, 1, 1, 1);
for (std::string const& opt : cmExpandedList(stringsProp)) {
for (std::string const& opt : cmExpandedList(*stringsProp)) {
ow->AddOption(opt);
}
ow->SetOption(*value);

View File

@ -407,9 +407,10 @@ void cmCursesMainForm::UpdateStatusBar(cm::optional<std::string> message)
auto cmakeState = this->CMakeInstance->GetState();
cmProp existingValue = cmakeState->GetCacheEntryValue(labelValue);
if (existingValue) {
auto help = cmakeState->GetCacheEntryProperty(labelValue, "HELPSTRING");
cmProp help =
cmakeState->GetCacheEntryProperty(labelValue, "HELPSTRING");
if (help) {
bar += help;
bar += *help;
}
}
}
@ -802,7 +803,7 @@ void cmCursesMainForm::HandleInput()
cmCursesWidget* lbl = reinterpret_cast<cmCursesWidget*>(
field_userptr(this->Fields[findex - 2]));
const char* curField = lbl->GetValue();
const char* helpString = nullptr;
cmProp helpString = nullptr;
cmProp existingValue =
this->CMakeInstance->GetState()->GetCacheEntryValue(curField);
@ -813,7 +814,7 @@ void cmCursesMainForm::HandleInput()
if (helpString) {
this->HelpMessage[1] =
cmStrCat("Current option is: ", curField, '\n',
"Help string for this option is: ", helpString, '\n');
"Help string for this option is: ", *helpString, '\n');
} else {
this->HelpMessage[1] = "";
}

View File

@ -306,8 +306,9 @@ QCMakePropertyList QCMake::properties() const
QCMakeProperty prop;
prop.Key = QString::fromLocal8Bit(key.c_str());
prop.Help =
QString::fromLocal8Bit(state->GetCacheEntryProperty(key, "HELPSTRING"));
if (cmProp hs = state->GetCacheEntryProperty(key, "HELPSTRING")) {
prop.Help = QString::fromLocal8Bit(hs->c_str());
}
prop.Value = QString::fromLocal8Bit(cachedValue->c_str());
prop.Advanced = state->GetCacheEntryPropertyAsBool(key, "ADVANCED");
if (t == cmStateEnums::BOOL) {
@ -319,10 +320,10 @@ QCMakePropertyList QCMake::properties() const
prop.Type = QCMakeProperty::FILEPATH;
} else if (t == cmStateEnums::STRING) {
prop.Type = QCMakeProperty::STRING;
const char* stringsProperty =
state->GetCacheEntryProperty(key, "STRINGS");
cmProp stringsProperty = state->GetCacheEntryProperty(key, "STRINGS");
if (stringsProperty) {
prop.Strings = QString::fromLocal8Bit(stringsProperty).split(";");
prop.Strings =
QString::fromLocal8Bit(stringsProperty->c_str()).split(";");
}
}

View File

@ -94,7 +94,8 @@ Json::Value Cache::DumpEntryProperty(std::string const& name,
{
Json::Value property = Json::objectValue;
property["name"] = prop;
property["value"] = this->State->GetCacheEntryProperty(name, prop);
cmProp p = this->State->GetCacheEntryProperty(name, prop);
property["value"] = p ? *p : "";
return property;
}
}

View File

@ -312,9 +312,9 @@ bool cmFindBase::CheckForVariableInCache()
return true;
}
if (cached) {
const char* hs =
cmProp hs =
state->GetCacheEntryProperty(this->VariableName, "HELPSTRING");
this->VariableDocumentation = hs ? hs : "(none)";
this->VariableDocumentation = hs ? *hs : "(none)";
}
}
return false;

View File

@ -393,12 +393,13 @@ bool HandleCacheMode(cmExecutionStatus& status, const std::string& name,
return false;
}
const char* value = nullptr;
cmProp value = nullptr;
if (status.GetMakefile().GetState()->GetCacheEntryValue(name)) {
value = status.GetMakefile().GetState()->GetCacheEntryProperty(
name, propertyName);
}
StoreResult(infoType, status.GetMakefile(), variable, value);
StoreResult(infoType, status.GetMakefile(), variable,
value ? value->c_str() : nullptr);
return true;
}

View File

@ -450,7 +450,7 @@ cmServerResponse cmServerProtocol1::ProcessCache(
bool haveProperties = false;
for (auto const& prop : state->GetCacheEntryPropertyList(key)) {
haveProperties = true;
props[prop] = state->GetCacheEntryProperty(key, prop);
props[prop] = *state->GetCacheEntryProperty(key, prop);
}
if (haveProperties) {
entry[kPROPERTIES_KEY] = props;

View File

@ -206,15 +206,14 @@ std::vector<std::string> cmState::GetCacheEntryPropertyList(
return it.GetPropertyList();
}
const char* cmState::GetCacheEntryProperty(std::string const& key,
std::string const& propertyName)
cmProp cmState::GetCacheEntryProperty(std::string const& key,
std::string const& propertyName)
{
cmCacheManager::CacheIterator it = this->CacheManager->GetCacheIterator(key);
if (!it.PropertyExists(propertyName)) {
return nullptr;
}
cmProp retVal = it.GetProperty(propertyName);
return retVal ? retVal->c_str() : nullptr;
return it.GetProperty(propertyName);
}
bool cmState::GetCacheEntryPropertyAsBool(std::string const& key,

View File

@ -105,8 +105,8 @@ public:
void SetCacheEntryBoolProperty(std::string const& key,
std::string const& propertyName, bool value);
std::vector<std::string> GetCacheEntryPropertyList(std::string const& key);
const char* GetCacheEntryProperty(std::string const& key,
std::string const& propertyName);
cmProp GetCacheEntryProperty(std::string const& key,
std::string const& propertyName);
bool GetCacheEntryPropertyAsBool(std::string const& key,
std::string const& propertyName);
void AppendCacheEntryProperty(std::string const& key,

View File

@ -1409,9 +1409,9 @@ int cmake::HandleDeleteCacheVariables(const std::string& var)
cmProp existingValue = this->State->GetCacheEntryValue(save.key);
if (existingValue) {
save.type = this->State->GetCacheEntryType(save.key);
if (const char* help =
if (cmProp help =
this->State->GetCacheEntryProperty(save.key, "HELPSTRING")) {
save.help = help;
save.help = *help;
}
}
saved.push_back(std::move(save));

View File

@ -292,13 +292,13 @@ int do_cmake(int ac, char const* const* av)
cmStateEnums::CacheEntryType t = cm.GetState()->GetCacheEntryType(k);
if (t != cmStateEnums::INTERNAL && t != cmStateEnums::STATIC &&
t != cmStateEnums::UNINITIALIZED) {
const char* advancedProp =
cmProp advancedProp =
cm.GetState()->GetCacheEntryProperty(k, "ADVANCED");
if (list_all_cached || !advancedProp) {
if (list_help) {
std::cout << "// "
<< cm.GetState()->GetCacheEntryProperty(k, "HELPSTRING")
<< std::endl;
cmProp help =
cm.GetState()->GetCacheEntryProperty(k, "HELPSTRING");
std::cout << "// " << (help ? *help : "") << std::endl;
}
std::cout << k << ":" << cmState::CacheEntryTypeToString(t) << "="
<< cm.GetState()->GetSafeCacheEntryValue(k) << std::endl;