Commit e63151ff authored by Alex Turbov's avatar Alex Turbov Committed by Brad King

cmake: Add an option to control what files needs to be traced

Even in relatively small projects using `--trace` (and `--trace-expand`)
may produce a lot of output.  When developing a custom module usually
one is interested in output of only a few particular modules.

Add a `--trace-source=<file>` option to enable tracing only a subset of
source files.  The final output would be only from requested modules,
ignoring anything else not matched to given filename(s).
parent 9e472556
......@@ -108,6 +108,11 @@ Options
Like ``--trace``, but with variables expanded.
``--trace-source=<file>``
Put cmake in trace mode, but output only lines of a specified file.
Multiple options are allowed.
``--warn-uninitialized``
Warn about uninitialized values.
......
cmake-trace-source
------------------
* The :manual:`cmake(1)` command learned a ``--trace-source=<file>`` option.
......@@ -37,6 +37,7 @@
#include <cmsys/FStream.hxx>
#include <cmsys/RegularExpression.hxx>
#include <cmsys/SystemTools.hxx>
#include <cmsys/auto_ptr.hxx>
#include <assert.h>
......@@ -175,8 +176,29 @@ cmListFileContext cmMakefile::GetExecutionContext() const
void cmMakefile::PrintCommandTrace(const cmListFileFunction& lff) const
{
// Check if current file in the list of requested to trace...
std::vector<std::string> const& trace_only_this_files =
this->GetCMakeInstance()->GetTraceSources();
std::string const& full_path = this->GetExecutionFilePath();
std::string const& only_filename = cmSystemTools::GetFilenameName(full_path);
bool trace = trace_only_this_files.empty();
if (!trace) {
for (std::vector<std::string>::const_iterator i =
trace_only_this_files.begin();
!trace && i != trace_only_this_files.end(); ++i) {
std::string::size_type const pos = full_path.rfind(*i);
trace = (pos != std::string::npos) &&
((pos + i->size()) == full_path.size()) &&
(only_filename == cmSystemTools::GetFilenameName(*i));
}
// Do nothing if current file wasn't requested for trace...
if (!trace) {
return;
}
}
std::ostringstream msg;
msg << this->GetExecutionFilePath() << "(" << lff.Line << "): ";
msg << full_path << "(" << lff.Line << "): ";
msg << lff.Name << "(";
bool expand = this->GetCMakeInstance()->GetTraceExpand();
std::string temp;
......
......@@ -589,6 +589,11 @@ void cmake::SetArgs(const std::vector<std::string>& args,
std::cout << "Running with expanded trace output on.\n";
this->SetTrace(true);
this->SetTraceExpand(true);
} else if (arg.find("--trace-source=", 0) == 0) {
std::string file = arg.substr(strlen("--trace-source="));
cmSystemTools::ConvertToUnixSlashes(file);
this->AddTraceSource(file);
this->SetTrace(true);
} else if (arg.find("--trace", 0) == 0) {
std::cout << "Running with trace output on.\n";
this->SetTrace(true);
......
......@@ -307,6 +307,14 @@ public:
void SetTrace(bool b) { this->Trace = b; }
bool GetTraceExpand() { return this->TraceExpand; }
void SetTraceExpand(bool b) { this->TraceExpand = b; }
void AddTraceSource(std::string const& file)
{
this->TraceOnlyThisSources.push_back(file);
}
std::vector<std::string> const& GetTraceSources() const
{
return this->TraceOnlyThisSources;
}
bool GetWarnUninitialized() { return this->WarnUninitialized; }
void SetWarnUninitialized(bool b) { this->WarnUninitialized = b; }
bool GetWarnUnused() { return this->WarnUnused; }
......@@ -481,6 +489,8 @@ private:
cmState* State;
cmState::Snapshot CurrentSnapshot;
std::vector<std::string> TraceOnlyThisSources;
void UpdateConversionPathTable();
// Print a list of valid generators to stderr.
......
......@@ -73,6 +73,8 @@ static const char* cmDocumentationOptions[][2] = {
{ "--debug-output", "Put cmake in a debug mode." },
{ "--trace", "Put cmake in trace mode." },
{ "--trace-expand", "Put cmake in trace mode with variable expansion." },
{ "--trace-source=<file>",
"Trace only this CMake file/module. Multiple options allowed." },
{ "--warn-uninitialized", "Warn about uninitialized values." },
{ "--warn-unused-vars", "Warn about unused variables." },
{ "--no-warn-unused-cli", "Don't warn about command line options." },
......
......@@ -264,6 +264,10 @@ set(RunCMake_TEST_OPTIONS --trace-expand)
run_cmake(trace-expand)
unset(RunCMake_TEST_OPTIONS)
set(RunCMake_TEST_OPTIONS --trace-source=trace-only-this-file.cmake)
run_cmake(trace-source)
unset(RunCMake_TEST_OPTIONS)
set(RunCMake_TEST_OPTIONS --debug-trycompile)
run_cmake(debug-trycompile)
unset(RunCMake_TEST_OPTIONS)
......
message(STATUS "trace particular file test passed")
^.*/trace-only-this-file.cmake\(1\): message\(STATUS trace particular file test passed \)$
message(STATUS "before include()")
include("trace-only-this-file.cmake")
message(STATUS "after include()")
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment