ENH: Enabled color printing of "Scanning dependencies of target ..." message.

This commit is contained in:
Brad King 2007-12-19 17:15:41 -05:00
parent f0824c7a19
commit 73704ede42
7 changed files with 76 additions and 33 deletions

View File

@ -163,7 +163,8 @@ public:
/** Called from command-line hook to update dependencies. */
virtual bool UpdateDependencies(const char* /* tgtInfo */,
bool /*verbose*/)
bool /*verbose*/,
bool /*color*/)
{ return true; }
/** Compute the list of link libraries and directories for the given

View File

@ -31,6 +31,7 @@
#ifdef CMAKE_BUILD_WITH_CMAKE
# include "cmDependsFortran.h"
# include "cmDependsJava.h"
# include <cmsys/Terminal.h>
#endif
#include <memory> // auto_ptr
@ -1225,7 +1226,8 @@ cmLocalUnixMakefileGenerator3
//----------------------------------------------------------------------------
bool cmLocalUnixMakefileGenerator3::UpdateDependencies(const char* tgtInfo,
bool verbose)
bool verbose,
bool color)
{
std::string dir = cmSystemTools::GetFilenamePath(tgtInfo);
std::string internalDependFile = dir + "/depend.internal";
@ -1242,11 +1244,18 @@ bool cmLocalUnixMakefileGenerator3::UpdateDependencies(const char* tgtInfo,
if(!checker.Check(dependFile.c_str(), internalDependFile.c_str()))
{
// The dependencies must be regenerated.
// TODO: Make this like cmLocalUnixMakefileGenerator3::EchoDepend
std::string targetName = cmSystemTools::GetFilenameName(dir);
targetName = targetName.substr(0, targetName.length()-4);
fprintf(stdout, "Scanning dependencies of target %s\n", targetName.c_str());
std::string message = "Scanning dependencies of target ";
message += targetName;
#ifdef CMAKE_BUILD_WITH_CMAKE
cmSystemTools::MakefileColorEcho(
cmsysTerminal_Color_ForegroundMagenta |
cmsysTerminal_Color_ForegroundBold,
message.c_str(), true, color);
#else
fprintf(stdout, "%s\n", message.c_str());
#endif
return this->ScanDependencies(tgtInfo);
}

View File

@ -200,7 +200,8 @@ public:
/** Called from command-line hook to bring dependencies up to date
for a target. */
virtual bool UpdateDependencies(const char* tgtInfo, bool verbose);
virtual bool UpdateDependencies(const char* tgtInfo,
bool verbose, bool color);
/** Called from command-line hook to scan dependencies. */
bool ScanDependencies(const char* tgtInfo);

View File

@ -805,7 +805,7 @@ void cmMakefileTargetGenerator::WriteTargetDependRules()
// cmake -E cmake_depends <generator>
// <home-src-dir> <start-src-dir>
// <home-out-dir> <start-out-dir>
// <dep-info>
// <dep-info> --color=$(COLOR)
//
// This gives the dependency scanner enough information to recreate
// the state of our local generator sufficiently for its needs.
@ -824,7 +824,8 @@ void cmMakefileTargetGenerator::WriteTargetDependRules()
cmLocalGenerator::FULL, cmLocalGenerator::SHELL)
<< " "
<< this->Convert(this->InfoFileNameFull.c_str(),
cmLocalGenerator::FULL, cmLocalGenerator::SHELL);
cmLocalGenerator::FULL, cmLocalGenerator::SHELL)
<< " --color=$(COLOR)";
commands.push_back(depCmd.str());
// Make sure all custom command outputs in this target are built.

View File

@ -23,6 +23,9 @@
#include <cmsys/RegularExpression.hxx>
#include <cmsys/Directory.hxx>
#include <cmsys/System.h>
#if defined(CMAKE_BUILD_WITH_CMAKE)
# include <cmsys/Terminal.h>
#endif
#if defined(_WIN32)
# include <windows.h>
@ -2087,3 +2090,36 @@ const char* cmSystemTools::GetExecutableDirectory()
{
return cmSystemToolsExecutableDirectory.c_str();
}
//----------------------------------------------------------------------------
#if defined(CMAKE_BUILD_WITH_CMAKE)
void cmSystemTools::MakefileColorEcho(int color, const char* message,
bool newline, bool enabled)
{
// On some platforms (an MSYS prompt) cmsysTerminal may not be able
// to determine whether the stream is displayed on a tty. In this
// case it assumes no unless we tell it otherwise. Since we want
// color messages to be displayed for users we will assume yes.
// However, we can test for some situations when the answer is most
// likely no.
int assumeTTY = cmsysTerminal_Color_AssumeTTY;
if(cmSystemTools::GetEnv("DART_TEST_FROM_DART") ||
cmSystemTools::GetEnv("DASHBOARD_TEST_FROM_CTEST") ||
cmSystemTools::GetEnv("CTEST_INTERACTIVE_DEBUG_MODE"))
{
// Avoid printing color escapes during dashboard builds.
assumeTTY = 0;
}
if(enabled)
{
cmsysTerminal_cfprintf(color | assumeTTY, stdout, "%s%s",
message, newline? "\n" : "");
}
else
{
// Color is disabled. Print without color.
fprintf(stdout, "%s%s", message, newline? "\n" : "");
}
}
#endif

View File

@ -358,6 +358,12 @@ public:
/** Get the directory containing the currently running executable. */
static const char* GetExecutableDirectory();
#if defined(CMAKE_BUILD_WITH_CMAKE)
/** Echo a message in color using KWSys's Terminal cprintf. */
static void MakefileColorEcho(int color, const char* message,
bool newline, bool enabled);
#endif
private:
static bool s_ForceUnixPaths;
static bool s_RunCommandHideConsole;

View File

@ -1365,6 +1365,7 @@ int cmake::ExecuteCMakeCommand(std::vector<std::string>& args)
std::string homeOutDir;
std::string startOutDir;
std::string depInfo;
bool color = true;
if(args.size() >= 8)
{
// Full signature:
@ -1372,7 +1373,7 @@ int cmake::ExecuteCMakeCommand(std::vector<std::string>& args)
// -E cmake_depends <generator>
// <home-src-dir> <start-src-dir>
// <home-out-dir> <start-out-dir>
// <dep-info>
// <dep-info> [--color=$(COLOR)]
//
// All paths are provided.
gen = args[2];
@ -1381,6 +1382,13 @@ int cmake::ExecuteCMakeCommand(std::vector<std::string>& args)
homeOutDir = args[5];
startOutDir = args[6];
depInfo = args[7];
if(args.size() >= 9 &&
args[8].length() > 8 &&
args[8].substr(0, 8) == "--color=")
{
// Enable or disable color based on the switch value.
color = cmSystemTools::IsOn(args[8].substr(8).c_str());
}
}
else
{
@ -1420,7 +1428,8 @@ int cmake::ExecuteCMakeCommand(std::vector<std::string>& args)
lgd->GetMakefile()->MakeStartDirectoriesCurrent();
// Actually scan dependencies.
return lgd->UpdateDependencies(depInfo.c_str(), verbose)? 0 : 2;
return lgd->UpdateDependencies(depInfo.c_str(),
verbose, color)? 0 : 2;
}
return 1;
}
@ -3020,21 +3029,6 @@ int cmake::ExecuteEchoColor(std::vector<std::string>& args)
// argv[0] == <cmake-executable>
// argv[1] == cmake_echo_color
// On some platforms (an MSYS prompt) cmsysTerminal may not be able
// to determine whether the stream is displayed on a tty. In this
// case it assumes no unless we tell it otherwise. Since we want
// color messages to be displayed for users we will assume yes.
// However, we can test for some situations when the answer is most
// likely no.
int assumeTTY = cmsysTerminal_Color_AssumeTTY;
if(cmSystemTools::GetEnv("DART_TEST_FROM_DART") ||
cmSystemTools::GetEnv("DASHBOARD_TEST_FROM_CTEST") ||
cmSystemTools::GetEnv("CTEST_INTERACTIVE_DEBUG_MODE"))
{
// Avoid printing color escapes during dashboard builds.
assumeTTY = 0;
}
bool enabled = true;
int color = cmsysTerminal_Color_Normal;
bool newline = true;
@ -3104,16 +3098,11 @@ int cmake::ExecuteEchoColor(std::vector<std::string>& args)
{
newline = true;
}
else if(enabled)
{
// Color is enabled. Print with the current color.
cmsysTerminal_cfprintf(color | assumeTTY, stdout, "%s%s",
args[i].c_str(), newline? "\n" : "");
}
else
{
// Color is disabled. Print without color.
fprintf(stdout, "%s%s", args[i].c_str(), newline? "\n" : "");
// Color is enabled. Print with the current color.
cmSystemTools::MakefileColorEcho(color, args[i].c_str(),
newline, enabled);
}
}