MCPcopy Create free account
hub / github.com/Kitware/CMake / cmVariableWatchCommandVariableAccessed

Function cmVariableWatchCommandVariableAccessed

Source/cmVariableWatchCommand.cxx:28–78  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

26};
27
28void cmVariableWatchCommandVariableAccessed(std::string const& variable,
29 int access_type, void* client_data,
30 char const* newValue,
31 cmMakefile const* mf)
32{
33 cmVariableWatchCallbackData* data =
34 static_cast<cmVariableWatchCallbackData*>(client_data);
35
36 if (data->InCallback) {
37 return;
38 }
39 data->InCallback = true;
40
41 auto accessString = cmVariableWatch::GetAccessAsString(access_type);
42
43 /// Ultra bad!!
44 cmMakefile* makefile = const_cast<cmMakefile*>(mf);
45
46 std::string stack = *mf->GetProperty("LISTFILE_STACK");
47 if (!data->Command.empty()) {
48 cmValue const currentListFile =
49 mf->GetDefinition("CMAKE_CURRENT_LIST_FILE");
50 auto const fakeLineNo =
51 std::numeric_limits<decltype(cmListFileArgument::Line)>::max();
52
53 std::vector<cmListFileArgument> newLFFArgs{
54 { variable, cmListFileArgument::Quoted, fakeLineNo },
55 { accessString, cmListFileArgument::Quoted, fakeLineNo },
56 { newValue ? newValue : "", cmListFileArgument::Quoted, fakeLineNo },
57 { *currentListFile, cmListFileArgument::Quoted, fakeLineNo },
58 { stack, cmListFileArgument::Quoted, fakeLineNo }
59 };
60
61 cmListFileFunction newLFF{ data->Command, fakeLineNo, fakeLineNo,
62 std::move(newLFFArgs) };
63 cmExecutionStatus status(*makefile);
64 if (!makefile->ExecuteCommand(newLFF, status)) {
65 cmSystemTools::Error(
66 cmStrCat("Error in cmake code at\nUnknown:0:\nA command failed "
67 "during the invocation of callback \"",
68 data->Command, "\"."));
69 }
70 } else {
71 makefile->IssueMessage(
72 MessageType::LOG,
73 cmStrCat("Variable \"", variable, "\" was accessed using ", accessString,
74 " with value \"", (newValue ? newValue : ""), "\"."));
75 }
76
77 data->InCallback = false;
78}
79
80void deleteVariableWatchCallbackData(void* client_data)
81{

Callers

nothing calls this directly

Calls 8

moveFunction · 0.85
ExecuteCommandMethod · 0.80
ErrorClass · 0.70
cmStrCatFunction · 0.70
GetPropertyMethod · 0.45
emptyMethod · 0.45
GetDefinitionMethod · 0.45
IssueMessageMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…