1
0
mirror of https://github.com/Kitware/CMake.git synced 2025-10-19 02:17:27 +08:00

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; break;
} }
case cmStateEnums::STRING: { case cmStateEnums::STRING: {
const char* stringsProp = state->GetCacheEntryProperty(key, "STRINGS"); cmProp stringsProp = state->GetCacheEntryProperty(key, "STRINGS");
if (stringsProp) { if (stringsProp) {
auto ow = auto ow =
cm::make_unique<cmCursesOptionsWidget>(this->EntryWidth, 1, 1, 1); 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->AddOption(opt);
} }
ow->SetOption(*value); ow->SetOption(*value);

View File

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

View File

@@ -306,8 +306,9 @@ QCMakePropertyList QCMake::properties() const
QCMakeProperty prop; QCMakeProperty prop;
prop.Key = QString::fromLocal8Bit(key.c_str()); prop.Key = QString::fromLocal8Bit(key.c_str());
prop.Help = if (cmProp hs = state->GetCacheEntryProperty(key, "HELPSTRING")) {
QString::fromLocal8Bit(state->GetCacheEntryProperty(key, "HELPSTRING")); prop.Help = QString::fromLocal8Bit(hs->c_str());
}
prop.Value = QString::fromLocal8Bit(cachedValue->c_str()); prop.Value = QString::fromLocal8Bit(cachedValue->c_str());
prop.Advanced = state->GetCacheEntryPropertyAsBool(key, "ADVANCED"); prop.Advanced = state->GetCacheEntryPropertyAsBool(key, "ADVANCED");
if (t == cmStateEnums::BOOL) { if (t == cmStateEnums::BOOL) {
@@ -319,10 +320,10 @@ QCMakePropertyList QCMake::properties() const
prop.Type = QCMakeProperty::FILEPATH; prop.Type = QCMakeProperty::FILEPATH;
} else if (t == cmStateEnums::STRING) { } else if (t == cmStateEnums::STRING) {
prop.Type = QCMakeProperty::STRING; prop.Type = QCMakeProperty::STRING;
const char* stringsProperty = cmProp stringsProperty = state->GetCacheEntryProperty(key, "STRINGS");
state->GetCacheEntryProperty(key, "STRINGS");
if (stringsProperty) { 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; Json::Value property = Json::objectValue;
property["name"] = prop; property["name"] = prop;
property["value"] = this->State->GetCacheEntryProperty(name, prop); cmProp p = this->State->GetCacheEntryProperty(name, prop);
property["value"] = p ? *p : "";
return property; return property;
} }
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -1409,9 +1409,9 @@ int cmake::HandleDeleteCacheVariables(const std::string& var)
cmProp existingValue = this->State->GetCacheEntryValue(save.key); cmProp existingValue = this->State->GetCacheEntryValue(save.key);
if (existingValue) { if (existingValue) {
save.type = this->State->GetCacheEntryType(save.key); save.type = this->State->GetCacheEntryType(save.key);
if (const char* help = if (cmProp help =
this->State->GetCacheEntryProperty(save.key, "HELPSTRING")) { this->State->GetCacheEntryProperty(save.key, "HELPSTRING")) {
save.help = help; save.help = *help;
} }
} }
saved.push_back(std::move(save)); 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); cmStateEnums::CacheEntryType t = cm.GetState()->GetCacheEntryType(k);
if (t != cmStateEnums::INTERNAL && t != cmStateEnums::STATIC && if (t != cmStateEnums::INTERNAL && t != cmStateEnums::STATIC &&
t != cmStateEnums::UNINITIALIZED) { t != cmStateEnums::UNINITIALIZED) {
const char* advancedProp = cmProp advancedProp =
cm.GetState()->GetCacheEntryProperty(k, "ADVANCED"); cm.GetState()->GetCacheEntryProperty(k, "ADVANCED");
if (list_all_cached || !advancedProp) { if (list_all_cached || !advancedProp) {
if (list_help) { if (list_help) {
std::cout << "// " cmProp help =
<< cm.GetState()->GetCacheEntryProperty(k, "HELPSTRING") cm.GetState()->GetCacheEntryProperty(k, "HELPSTRING");
<< std::endl; std::cout << "// " << (help ? *help : "") << std::endl;
} }
std::cout << k << ":" << cmState::CacheEntryTypeToString(t) << "=" std::cout << k << ":" << cmState::CacheEntryTypeToString(t) << "="
<< cm.GetState()->GetSafeCacheEntryValue(k) << std::endl; << cm.GetState()->GetSafeCacheEntryValue(k) << std::endl;