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

Function ReadWithPrefix

Source/cmLoadCacheCommand.cxx:93–162  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

91}
92
93static bool ReadWithPrefix(std::vector<std::string> const& args,
94 cmExecutionStatus& status)
95{
96 // Make sure we have a prefix.
97 if (args.size() < 3) {
98 status.SetError("READ_WITH_PREFIX form must specify a prefix.");
99 return false;
100 }
101
102 // Make sure the cache file exists.
103 std::string cacheFile = args[0] + "/CMakeCache.txt";
104 if (!cmSystemTools::FileExists(cacheFile)) {
105 std::string e = "Cannot load cache file from " + cacheFile;
106 status.SetError(e);
107 return false;
108 }
109
110 // Prepare the table of variables to read.
111 std::string const& prefix = args[2];
112 std::set<std::string> const variablesToRead(args.begin() + 3, args.end());
113
114 // Read the cache file.
115 cmsys::ifstream fin(cacheFile.c_str());
116
117 cmMakefile& mf = status.GetMakefile();
118
119 // This is a big hack read loop to overcome a buggy ifstream
120 // implementation on HP-UX. This should work on all platforms even
121 // for small buffer sizes.
122 int const bufferSize = 4096;
123 char buffer[bufferSize];
124 std::string line;
125 while (fin) {
126 // Read a block of the file.
127 fin.read(buffer, bufferSize);
128 if (fin.gcount()) {
129 // Parse for newlines directly.
130 char const* i = buffer;
131 char const* end = buffer + fin.gcount();
132 while (i != end) {
133 char const* begin = i;
134 while (i != end && *i != '\n') {
135 ++i;
136 }
137 if (i == begin || *(i - 1) != '\r') {
138 // Include this portion of the line.
139 line += std::string(begin, i - begin);
140 } else {
141 // Include this portion of the line.
142 // Don't include the \r in a \r\n pair.
143 line += std::string(begin, i - 1 - begin);
144 }
145 if (i != end) {
146 // Completed a line.
147 CheckLine(mf, prefix, variablesToRead, line.c_str());
148 line.clear();
149
150 // Skip the newline character.

Callers 1

cmLoadCacheCommandFunction · 0.85

Calls 11

CheckLineFunction · 0.85
c_strMethod · 0.80
FileExistsFunction · 0.50
sizeMethod · 0.45
SetErrorMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
GetMakefileMethod · 0.45
readMethod · 0.45
clearMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…