| 332 | } |
| 333 | |
| 334 | void cmMakefile::PrintCommandTrace(cmListFileFunction const& lff, |
| 335 | cmListFileBacktrace const& bt, |
| 336 | CommandMissingFromStack missing) const |
| 337 | { |
| 338 | // Check if current file in the list of requested to trace... |
| 339 | std::vector<std::string> const& trace_only_this_files = |
| 340 | this->GetCMakeInstance()->GetTraceSources(); |
| 341 | std::string const& full_path = bt.Top().FilePath; |
| 342 | cm::string_view only_filename = |
| 343 | cmSystemTools::GetFilenameNameView(full_path); |
| 344 | bool trace = trace_only_this_files.empty(); |
| 345 | if (!trace) { |
| 346 | for (std::string const& file : trace_only_this_files) { |
| 347 | std::string::size_type const pos = full_path.rfind(file); |
| 348 | trace = (pos != std::string::npos) && |
| 349 | ((pos + file.size()) == full_path.size()) && |
| 350 | (only_filename == cmSystemTools::GetFilenameNameView(file)); |
| 351 | if (trace) { |
| 352 | break; |
| 353 | } |
| 354 | } |
| 355 | // Do nothing if current file wasn't requested for trace... |
| 356 | if (!trace) { |
| 357 | return; |
| 358 | } |
| 359 | } |
| 360 | |
| 361 | std::vector<std::string> args; |
| 362 | std::string temp; |
| 363 | bool expand = this->GetCMakeInstance()->GetTraceExpand(); |
| 364 | |
| 365 | args.reserve(lff.Arguments().size()); |
| 366 | for (cmListFileArgument const& arg : lff.Arguments()) { |
| 367 | if (expand && arg.Delim != cmListFileArgument::Bracket) { |
| 368 | temp = arg.Value; |
| 369 | this->ExpandVariablesInString(temp); |
| 370 | args.push_back(temp); |
| 371 | } else { |
| 372 | args.push_back(arg.Value); |
| 373 | } |
| 374 | } |
| 375 | cm::optional<std::string> const& deferId = bt.Top().DeferId; |
| 376 | |
| 377 | std::ostringstream msg; |
| 378 | switch (this->GetCMakeInstance()->GetTraceFormat()) { |
| 379 | case cmake::TraceFormat::JSONv1: { |
| 380 | #ifndef CMAKE_BOOTSTRAP |
| 381 | Json::Value val; |
| 382 | Json::StreamWriterBuilder builder; |
| 383 | builder["indentation"] = ""; |
| 384 | val["file"] = full_path; |
| 385 | val["line"] = static_cast<Json::Value::Int64>(lff.Line()); |
| 386 | if (lff.Line() != lff.LineEnd()) { |
| 387 | val["line_end"] = static_cast<Json::Value::Int64>(lff.LineEnd()); |
| 388 | } |
| 389 | if (deferId) { |
| 390 | val["defer"] = *deferId; |
| 391 | } |
no test coverage detected