| 2574 | } |
| 2575 | |
| 2576 | MessageType cmMakefile::ExpandVariablesInStringImpl( |
| 2577 | std::string& errorstr, std::string& source, bool escapeQuotes, |
| 2578 | bool noEscapes, bool atOnly, char const* filename, long line, |
| 2579 | bool replaceAt) const |
| 2580 | { |
| 2581 | // This method replaces ${VAR} and @VAR@ where VAR is looked up |
| 2582 | // with GetDefinition(), if not found in the map, nothing is expanded. |
| 2583 | // It also supports the $ENV{VAR} syntax where VAR is looked up in |
| 2584 | // the current environment variables. |
| 2585 | |
| 2586 | char const* in = source.c_str(); |
| 2587 | char const* last = in; |
| 2588 | std::string result; |
| 2589 | result.reserve(source.size()); |
| 2590 | std::vector<t_lookup> openstack; |
| 2591 | bool error = false; |
| 2592 | bool done = false; |
| 2593 | MessageType mtype = MessageType::LOG; |
| 2594 | |
| 2595 | cmState* state = this->GetCMakeInstance()->GetState(); |
| 2596 | |
| 2597 | static std::string const lineVar = "CMAKE_CURRENT_LIST_LINE"; |
| 2598 | do { |
| 2599 | char inc = *in; |
| 2600 | switch (inc) { |
| 2601 | case '}': |
| 2602 | if (!openstack.empty()) { |
| 2603 | t_lookup var = openstack.back(); |
| 2604 | openstack.pop_back(); |
| 2605 | result.append(last, in - last); |
| 2606 | std::string const& lookup = result.substr(var.loc); |
| 2607 | cmValue value = nullptr; |
| 2608 | std::string varresult; |
| 2609 | std::string svalue; |
| 2610 | switch (var.domain) { |
| 2611 | case NORMAL: |
| 2612 | if (filename && lookup == lineVar) { |
| 2613 | cmListFileContext const& top = this->Backtrace.Top(); |
| 2614 | if (top.DeferId) { |
| 2615 | varresult = cmStrCat("DEFERRED:"_s, *top.DeferId); |
| 2616 | } else { |
| 2617 | varresult = std::to_string(line); |
| 2618 | } |
| 2619 | } else { |
| 2620 | value = this->GetDefinition(lookup); |
| 2621 | } |
| 2622 | break; |
| 2623 | case ENVIRONMENT: |
| 2624 | if (cmSystemTools::GetEnv(lookup, svalue)) { |
| 2625 | value = cmValue(svalue); |
| 2626 | } |
| 2627 | break; |
| 2628 | case CACHE: |
| 2629 | value = state->GetCacheEntryValue(lookup); |
| 2630 | break; |
| 2631 | } |
| 2632 | // Get the string we're meant to append to. |
| 2633 | if (value) { |
no test coverage detected