cmListFileCache.cxx 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #include "cmListFileCache.h"
  4. #include <cassert>
  5. #include <memory>
  6. #include <sstream>
  7. #include <utility>
  8. #ifdef _WIN32
  9. # include <cmsys/Encoding.hxx>
  10. #endif
  11. #include "cmListFileLexer.h"
  12. #include "cmMessageType.h"
  13. #include "cmMessenger.h"
  14. #include "cmState.h"
  15. #include "cmStateDirectory.h"
  16. #include "cmStringAlgorithms.h"
  17. #include "cmSystemTools.h"
  18. struct cmListFileParser
  19. {
  20. cmListFileParser(cmListFile* lf, cmListFileBacktrace lfbt,
  21. cmMessenger* messenger);
  22. ~cmListFileParser();
  23. cmListFileParser(const cmListFileParser&) = delete;
  24. cmListFileParser& operator=(const cmListFileParser&) = delete;
  25. void IssueFileOpenError(std::string const& text) const;
  26. void IssueError(std::string const& text) const;
  27. bool ParseFile(const char* filename);
  28. bool ParseString(const char* str, const char* virtual_filename);
  29. bool Parse();
  30. bool ParseFunction(const char* name, long line);
  31. bool AddArgument(cmListFileLexer_Token* token,
  32. cmListFileArgument::Delimiter delim);
  33. cm::optional<cmListFileContext> CheckNesting() const;
  34. cmListFile* ListFile;
  35. cmListFileBacktrace Backtrace;
  36. cmMessenger* Messenger;
  37. const char* FileName;
  38. cmListFileLexer* Lexer;
  39. std::string FunctionName;
  40. long FunctionLine;
  41. std::vector<cmListFileArgument> FunctionArguments;
  42. enum
  43. {
  44. SeparationOkay,
  45. SeparationWarning,
  46. SeparationError
  47. } Separation;
  48. };
  49. cmListFileParser::cmListFileParser(cmListFile* lf, cmListFileBacktrace lfbt,
  50. cmMessenger* messenger)
  51. : ListFile(lf)
  52. , Backtrace(std::move(lfbt))
  53. , Messenger(messenger)
  54. , FileName(nullptr)
  55. , Lexer(cmListFileLexer_New())
  56. {
  57. }
  58. cmListFileParser::~cmListFileParser()
  59. {
  60. cmListFileLexer_Delete(this->Lexer);
  61. }
  62. void cmListFileParser::IssueFileOpenError(const std::string& text) const
  63. {
  64. this->Messenger->IssueMessage(MessageType::FATAL_ERROR, text,
  65. this->Backtrace);
  66. }
  67. void cmListFileParser::IssueError(const std::string& text) const
  68. {
  69. cmListFileContext lfc;
  70. lfc.FilePath = this->FileName;
  71. lfc.Line = cmListFileLexer_GetCurrentLine(this->Lexer);
  72. cmListFileBacktrace lfbt = this->Backtrace;
  73. lfbt = lfbt.Push(lfc);
  74. this->Messenger->IssueMessage(MessageType::FATAL_ERROR, text, lfbt);
  75. cmSystemTools::SetFatalErrorOccured();
  76. }
  77. bool cmListFileParser::ParseFile(const char* filename)
  78. {
  79. this->FileName = filename;
  80. #ifdef _WIN32
  81. std::string expandedFileName = cmsys::Encoding::ToNarrow(
  82. cmSystemTools::ConvertToWindowsExtendedPath(filename));
  83. filename = expandedFileName.c_str();
  84. #endif
  85. // Open the file.
  86. cmListFileLexer_BOM bom;
  87. if (!cmListFileLexer_SetFileName(this->Lexer, filename, &bom)) {
  88. this->IssueFileOpenError("cmListFileCache: error can not open file.");
  89. return false;
  90. }
  91. if (bom == cmListFileLexer_BOM_Broken) {
  92. cmListFileLexer_SetFileName(this->Lexer, nullptr, nullptr);
  93. this->IssueFileOpenError("Error while reading Byte-Order-Mark. "
  94. "File not seekable?");
  95. return false;
  96. }
  97. // Verify the Byte-Order-Mark, if any.
  98. if (bom != cmListFileLexer_BOM_None && bom != cmListFileLexer_BOM_UTF8) {
  99. cmListFileLexer_SetFileName(this->Lexer, nullptr, nullptr);
  100. this->IssueFileOpenError(
  101. "File starts with a Byte-Order-Mark that is not UTF-8.");
  102. return false;
  103. }
  104. return this->Parse();
  105. }
  106. bool cmListFileParser::ParseString(const char* str,
  107. const char* virtual_filename)
  108. {
  109. this->FileName = virtual_filename;
  110. if (!cmListFileLexer_SetString(this->Lexer, str)) {
  111. this->IssueFileOpenError("cmListFileCache: cannot allocate buffer.");
  112. return false;
  113. }
  114. return this->Parse();
  115. }
  116. bool cmListFileParser::Parse()
  117. {
  118. // Use a simple recursive-descent parser to process the token
  119. // stream.
  120. bool haveNewline = true;
  121. while (cmListFileLexer_Token* token = cmListFileLexer_Scan(this->Lexer)) {
  122. if (token->type == cmListFileLexer_Token_Space) {
  123. } else if (token->type == cmListFileLexer_Token_Newline) {
  124. haveNewline = true;
  125. } else if (token->type == cmListFileLexer_Token_CommentBracket) {
  126. haveNewline = false;
  127. } else if (token->type == cmListFileLexer_Token_Identifier) {
  128. if (haveNewline) {
  129. haveNewline = false;
  130. if (this->ParseFunction(token->text, token->line)) {
  131. this->ListFile->Functions.emplace_back(
  132. std::move(this->FunctionName), this->FunctionLine,
  133. std::move(this->FunctionArguments));
  134. } else {
  135. return false;
  136. }
  137. } else {
  138. std::ostringstream error;
  139. error << "Parse error. Expected a newline, got "
  140. << cmListFileLexer_GetTypeAsString(this->Lexer, token->type)
  141. << " with text \"" << token->text << "\".";
  142. this->IssueError(error.str());
  143. return false;
  144. }
  145. } else {
  146. std::ostringstream error;
  147. error << "Parse error. Expected a command name, got "
  148. << cmListFileLexer_GetTypeAsString(this->Lexer, token->type)
  149. << " with text \"" << token->text << "\".";
  150. this->IssueError(error.str());
  151. return false;
  152. }
  153. }
  154. // Check if all functions are nested properly.
  155. if (auto badNesting = this->CheckNesting()) {
  156. this->Messenger->IssueMessage(
  157. MessageType::FATAL_ERROR,
  158. "Flow control statements are not properly nested.",
  159. this->Backtrace.Push(*badNesting));
  160. cmSystemTools::SetFatalErrorOccured();
  161. return false;
  162. }
  163. return true;
  164. }
  165. bool cmListFile::ParseFile(const char* filename, cmMessenger* messenger,
  166. cmListFileBacktrace const& lfbt)
  167. {
  168. if (!cmSystemTools::FileExists(filename) ||
  169. cmSystemTools::FileIsDirectory(filename)) {
  170. return false;
  171. }
  172. bool parseError = false;
  173. {
  174. cmListFileParser parser(this, lfbt, messenger);
  175. parseError = !parser.ParseFile(filename);
  176. }
  177. return !parseError;
  178. }
  179. bool cmListFile::ParseString(const char* str, const char* virtual_filename,
  180. cmMessenger* messenger,
  181. const cmListFileBacktrace& lfbt)
  182. {
  183. bool parseError = false;
  184. {
  185. cmListFileParser parser(this, lfbt, messenger);
  186. parseError = !parser.ParseString(str, virtual_filename);
  187. }
  188. return !parseError;
  189. }
  190. bool cmListFileParser::ParseFunction(const char* name, long line)
  191. {
  192. // Ininitialize a new function call.
  193. this->FunctionName = name;
  194. this->FunctionLine = line;
  195. // Command name has already been parsed. Read the left paren.
  196. cmListFileLexer_Token* token;
  197. while ((token = cmListFileLexer_Scan(this->Lexer)) &&
  198. token->type == cmListFileLexer_Token_Space) {
  199. }
  200. if (!token) {
  201. std::ostringstream error;
  202. /* clang-format off */
  203. error << "Unexpected end of file.\n"
  204. << "Parse error. Function missing opening \"(\".";
  205. /* clang-format on */
  206. this->IssueError(error.str());
  207. return false;
  208. }
  209. if (token->type != cmListFileLexer_Token_ParenLeft) {
  210. std::ostringstream error;
  211. error << "Parse error. Expected \"(\", got "
  212. << cmListFileLexer_GetTypeAsString(this->Lexer, token->type)
  213. << " with text \"" << token->text << "\".";
  214. this->IssueError(error.str());
  215. return false;
  216. }
  217. // Arguments.
  218. unsigned long parenDepth = 0;
  219. this->Separation = SeparationOkay;
  220. while ((token = cmListFileLexer_Scan(this->Lexer))) {
  221. if (token->type == cmListFileLexer_Token_Space ||
  222. token->type == cmListFileLexer_Token_Newline) {
  223. this->Separation = SeparationOkay;
  224. continue;
  225. }
  226. if (token->type == cmListFileLexer_Token_ParenLeft) {
  227. parenDepth++;
  228. this->Separation = SeparationOkay;
  229. if (!this->AddArgument(token, cmListFileArgument::Unquoted)) {
  230. return false;
  231. }
  232. } else if (token->type == cmListFileLexer_Token_ParenRight) {
  233. if (parenDepth == 0) {
  234. return true;
  235. }
  236. parenDepth--;
  237. this->Separation = SeparationOkay;
  238. if (!this->AddArgument(token, cmListFileArgument::Unquoted)) {
  239. return false;
  240. }
  241. this->Separation = SeparationWarning;
  242. } else if (token->type == cmListFileLexer_Token_Identifier ||
  243. token->type == cmListFileLexer_Token_ArgumentUnquoted) {
  244. if (!this->AddArgument(token, cmListFileArgument::Unquoted)) {
  245. return false;
  246. }
  247. this->Separation = SeparationWarning;
  248. } else if (token->type == cmListFileLexer_Token_ArgumentQuoted) {
  249. if (!this->AddArgument(token, cmListFileArgument::Quoted)) {
  250. return false;
  251. }
  252. this->Separation = SeparationWarning;
  253. } else if (token->type == cmListFileLexer_Token_ArgumentBracket) {
  254. if (!this->AddArgument(token, cmListFileArgument::Bracket)) {
  255. return false;
  256. }
  257. this->Separation = SeparationError;
  258. } else if (token->type == cmListFileLexer_Token_CommentBracket) {
  259. this->Separation = SeparationError;
  260. } else {
  261. // Error.
  262. std::ostringstream error;
  263. error << "Parse error. Function missing ending \")\". "
  264. << "Instead found "
  265. << cmListFileLexer_GetTypeAsString(this->Lexer, token->type)
  266. << " with text \"" << token->text << "\".";
  267. this->IssueError(error.str());
  268. return false;
  269. }
  270. }
  271. std::ostringstream error;
  272. cmListFileContext lfc;
  273. lfc.FilePath = this->FileName;
  274. lfc.Line = line;
  275. cmListFileBacktrace lfbt = this->Backtrace;
  276. lfbt = lfbt.Push(lfc);
  277. error << "Parse error. Function missing ending \")\". "
  278. << "End of file reached.";
  279. this->Messenger->IssueMessage(MessageType::FATAL_ERROR, error.str(), lfbt);
  280. return false;
  281. }
  282. bool cmListFileParser::AddArgument(cmListFileLexer_Token* token,
  283. cmListFileArgument::Delimiter delim)
  284. {
  285. this->FunctionArguments.emplace_back(token->text, delim, token->line);
  286. if (this->Separation == SeparationOkay) {
  287. return true;
  288. }
  289. bool isError = (this->Separation == SeparationError ||
  290. delim == cmListFileArgument::Bracket);
  291. std::ostringstream m;
  292. cmListFileContext lfc;
  293. lfc.FilePath = this->FileName;
  294. lfc.Line = token->line;
  295. cmListFileBacktrace lfbt = this->Backtrace;
  296. lfbt = lfbt.Push(lfc);
  297. m << "Syntax " << (isError ? "Error" : "Warning") << " in cmake code at "
  298. << "column " << token->column << "\n"
  299. << "Argument not separated from preceding token by whitespace.";
  300. /* clang-format on */
  301. if (isError) {
  302. this->Messenger->IssueMessage(MessageType::FATAL_ERROR, m.str(), lfbt);
  303. return false;
  304. }
  305. this->Messenger->IssueMessage(MessageType::AUTHOR_WARNING, m.str(), lfbt);
  306. return true;
  307. }
  308. namespace {
  309. enum class NestingStateEnum
  310. {
  311. If,
  312. Else,
  313. While,
  314. Foreach,
  315. Function,
  316. Macro,
  317. };
  318. struct NestingState
  319. {
  320. NestingStateEnum State;
  321. cmListFileContext Context;
  322. };
  323. bool TopIs(std::vector<NestingState>& stack, NestingStateEnum state)
  324. {
  325. return !stack.empty() && stack.back().State == state;
  326. }
  327. }
  328. cm::optional<cmListFileContext> cmListFileParser::CheckNesting() const
  329. {
  330. std::vector<NestingState> stack;
  331. for (auto const& func : this->ListFile->Functions) {
  332. auto const& name = func.LowerCaseName();
  333. if (name == "if") {
  334. stack.push_back({
  335. NestingStateEnum::If,
  336. cmListFileContext::FromCommandContext(func, this->FileName),
  337. });
  338. } else if (name == "elseif") {
  339. if (!TopIs(stack, NestingStateEnum::If)) {
  340. return cmListFileContext::FromCommandContext(func, this->FileName);
  341. }
  342. stack.back() = {
  343. NestingStateEnum::If,
  344. cmListFileContext::FromCommandContext(func, this->FileName),
  345. };
  346. } else if (name == "else") {
  347. if (!TopIs(stack, NestingStateEnum::If)) {
  348. return cmListFileContext::FromCommandContext(func, this->FileName);
  349. }
  350. stack.back() = {
  351. NestingStateEnum::Else,
  352. cmListFileContext::FromCommandContext(func, this->FileName),
  353. };
  354. } else if (name == "endif") {
  355. if (!TopIs(stack, NestingStateEnum::If) &&
  356. !TopIs(stack, NestingStateEnum::Else)) {
  357. return cmListFileContext::FromCommandContext(func, this->FileName);
  358. }
  359. stack.pop_back();
  360. } else if (name == "while") {
  361. stack.push_back({
  362. NestingStateEnum::While,
  363. cmListFileContext::FromCommandContext(func, this->FileName),
  364. });
  365. } else if (name == "endwhile") {
  366. if (!TopIs(stack, NestingStateEnum::While)) {
  367. return cmListFileContext::FromCommandContext(func, this->FileName);
  368. }
  369. stack.pop_back();
  370. } else if (name == "foreach") {
  371. stack.push_back({
  372. NestingStateEnum::Foreach,
  373. cmListFileContext::FromCommandContext(func, this->FileName),
  374. });
  375. } else if (name == "endforeach") {
  376. if (!TopIs(stack, NestingStateEnum::Foreach)) {
  377. return cmListFileContext::FromCommandContext(func, this->FileName);
  378. }
  379. stack.pop_back();
  380. } else if (name == "function") {
  381. stack.push_back({
  382. NestingStateEnum::Function,
  383. cmListFileContext::FromCommandContext(func, this->FileName),
  384. });
  385. } else if (name == "endfunction") {
  386. if (!TopIs(stack, NestingStateEnum::Function)) {
  387. return cmListFileContext::FromCommandContext(func, this->FileName);
  388. }
  389. stack.pop_back();
  390. } else if (name == "macro") {
  391. stack.push_back({
  392. NestingStateEnum::Macro,
  393. cmListFileContext::FromCommandContext(func, this->FileName),
  394. });
  395. } else if (name == "endmacro") {
  396. if (!TopIs(stack, NestingStateEnum::Macro)) {
  397. return cmListFileContext::FromCommandContext(func, this->FileName);
  398. }
  399. stack.pop_back();
  400. }
  401. }
  402. if (!stack.empty()) {
  403. return stack.back().Context;
  404. }
  405. return cm::nullopt;
  406. }
  407. // We hold either the bottom scope of a directory or a call/file context.
  408. // Discriminate these cases via the parent pointer.
  409. struct cmListFileBacktrace::Entry
  410. {
  411. Entry(cmStateSnapshot bottom)
  412. : Bottom(bottom)
  413. {
  414. }
  415. Entry(std::shared_ptr<Entry const> parent, cmListFileContext lfc)
  416. : Context(std::move(lfc))
  417. , Parent(std::move(parent))
  418. {
  419. }
  420. ~Entry()
  421. {
  422. if (this->Parent) {
  423. this->Context.~cmListFileContext();
  424. } else {
  425. this->Bottom.~cmStateSnapshot();
  426. }
  427. }
  428. bool IsBottom() const { return !this->Parent; }
  429. union
  430. {
  431. cmStateSnapshot Bottom;
  432. cmListFileContext Context;
  433. };
  434. std::shared_ptr<Entry const> Parent;
  435. };
  436. cmListFileBacktrace::cmListFileBacktrace(cmStateSnapshot const& snapshot)
  437. : TopEntry(std::make_shared<Entry const>(snapshot.GetCallStackBottom()))
  438. {
  439. }
  440. /* NOLINTNEXTLINE(performance-unnecessary-value-param) */
  441. cmListFileBacktrace::cmListFileBacktrace(std::shared_ptr<Entry const> parent,
  442. cmListFileContext const& lfc)
  443. : TopEntry(std::make_shared<Entry const>(std::move(parent), lfc))
  444. {
  445. }
  446. cmListFileBacktrace::cmListFileBacktrace(std::shared_ptr<Entry const> top)
  447. : TopEntry(std::move(top))
  448. {
  449. }
  450. cmStateSnapshot cmListFileBacktrace::GetBottom() const
  451. {
  452. cmStateSnapshot bottom;
  453. if (Entry const* cur = this->TopEntry.get()) {
  454. while (Entry const* parent = cur->Parent.get()) {
  455. cur = parent;
  456. }
  457. bottom = cur->Bottom;
  458. }
  459. return bottom;
  460. }
  461. cmListFileBacktrace cmListFileBacktrace::Push(std::string const& file) const
  462. {
  463. // We are entering a file-level scope but have not yet reached
  464. // any specific line or command invocation within it. This context
  465. // is useful to print when it is at the top but otherwise can be
  466. // skipped during call stack printing.
  467. cmListFileContext lfc;
  468. lfc.FilePath = file;
  469. return this->Push(lfc);
  470. }
  471. cmListFileBacktrace cmListFileBacktrace::Push(
  472. cmListFileContext const& lfc) const
  473. {
  474. assert(this->TopEntry);
  475. assert(!this->TopEntry->IsBottom() || this->TopEntry->Bottom.IsValid());
  476. return cmListFileBacktrace(this->TopEntry, lfc);
  477. }
  478. cmListFileBacktrace cmListFileBacktrace::Pop() const
  479. {
  480. assert(this->TopEntry);
  481. assert(!this->TopEntry->IsBottom());
  482. return cmListFileBacktrace(this->TopEntry->Parent);
  483. }
  484. cmListFileContext const& cmListFileBacktrace::Top() const
  485. {
  486. assert(this->TopEntry);
  487. assert(!this->TopEntry->IsBottom());
  488. return this->TopEntry->Context;
  489. }
  490. void cmListFileBacktrace::PrintTitle(std::ostream& out) const
  491. {
  492. // The title exists only if we have a call on top of the bottom.
  493. if (!this->TopEntry || this->TopEntry->IsBottom()) {
  494. return;
  495. }
  496. cmListFileContext lfc = this->TopEntry->Context;
  497. cmStateSnapshot bottom = this->GetBottom();
  498. if (!bottom.GetState()->GetIsInTryCompile()) {
  499. lfc.FilePath = bottom.GetDirectory().ConvertToRelPathIfContained(
  500. bottom.GetState()->GetSourceDirectory(), lfc.FilePath);
  501. }
  502. out << (lfc.Line ? " at " : " in ") << lfc;
  503. }
  504. void cmListFileBacktrace::PrintCallStack(std::ostream& out) const
  505. {
  506. // The call stack exists only if we have at least two calls on top
  507. // of the bottom.
  508. if (!this->TopEntry || this->TopEntry->IsBottom() ||
  509. this->TopEntry->Parent->IsBottom()) {
  510. return;
  511. }
  512. bool first = true;
  513. cmStateSnapshot bottom = this->GetBottom();
  514. for (Entry const* cur = this->TopEntry->Parent.get(); !cur->IsBottom();
  515. cur = cur->Parent.get()) {
  516. if (cur->Context.Name.empty() &&
  517. cur->Context.Line != cmListFileContext::DeferPlaceholderLine) {
  518. // Skip this whole-file scope. When we get here we already will
  519. // have printed a more-specific context within the file.
  520. continue;
  521. }
  522. if (first) {
  523. first = false;
  524. out << "Call Stack (most recent call first):\n";
  525. }
  526. cmListFileContext lfc = cur->Context;
  527. if (!bottom.GetState()->GetIsInTryCompile()) {
  528. lfc.FilePath = bottom.GetDirectory().ConvertToRelPathIfContained(
  529. bottom.GetState()->GetSourceDirectory(), lfc.FilePath);
  530. }
  531. out << " " << lfc << "\n";
  532. }
  533. }
  534. size_t cmListFileBacktrace::Depth() const
  535. {
  536. size_t depth = 0;
  537. if (Entry const* cur = this->TopEntry.get()) {
  538. for (; !cur->IsBottom(); cur = cur->Parent.get()) {
  539. ++depth;
  540. }
  541. }
  542. return depth;
  543. }
  544. bool cmListFileBacktrace::Empty() const
  545. {
  546. return !this->TopEntry || this->TopEntry->IsBottom();
  547. }
  548. std::ostream& operator<<(std::ostream& os, cmListFileContext const& lfc)
  549. {
  550. os << lfc.FilePath;
  551. if (lfc.Line > 0) {
  552. os << ":" << lfc.Line;
  553. if (!lfc.Name.empty()) {
  554. os << " (" << lfc.Name << ")";
  555. }
  556. } else if (lfc.Line == cmListFileContext::DeferPlaceholderLine) {
  557. os << ":DEFERRED";
  558. }
  559. return os;
  560. }
  561. bool operator<(const cmListFileContext& lhs, const cmListFileContext& rhs)
  562. {
  563. if (lhs.Line != rhs.Line) {
  564. return lhs.Line < rhs.Line;
  565. }
  566. return lhs.FilePath < rhs.FilePath;
  567. }
  568. bool operator==(const cmListFileContext& lhs, const cmListFileContext& rhs)
  569. {
  570. return lhs.Line == rhs.Line && lhs.FilePath == rhs.FilePath;
  571. }
  572. bool operator!=(const cmListFileContext& lhs, const cmListFileContext& rhs)
  573. {
  574. return !(lhs == rhs);
  575. }
  576. std::ostream& operator<<(std::ostream& os, BT<std::string> const& s)
  577. {
  578. return os << s.Value;
  579. }
  580. std::vector<BT<std::string>> ExpandListWithBacktrace(
  581. std::string const& list, cmListFileBacktrace const& bt)
  582. {
  583. std::vector<BT<std::string>> result;
  584. std::vector<std::string> tmp = cmExpandedList(list);
  585. result.reserve(tmp.size());
  586. for (std::string& i : tmp) {
  587. result.emplace_back(std::move(i), bt);
  588. }
  589. return result;
  590. }