From 73704ede42cdaa6e4a985329506d116db3425b3f Mon Sep 17 00:00:00 2001 From: Brad King Date: Wed, 19 Dec 2007 17:15:41 -0500 Subject: [PATCH] ENH: Enabled color printing of "Scanning dependencies of target ..." message. --- Source/cmLocalGenerator.h | 3 +- Source/cmLocalUnixMakefileGenerator3.cxx | 17 ++++++++--- Source/cmLocalUnixMakefileGenerator3.h | 3 +- Source/cmMakefileTargetGenerator.cxx | 5 +-- Source/cmSystemTools.cxx | 36 ++++++++++++++++++++++ Source/cmSystemTools.h | 6 ++++ Source/cmake.cxx | 39 +++++++++--------------- 7 files changed, 76 insertions(+), 33 deletions(-) diff --git a/Source/cmLocalGenerator.h b/Source/cmLocalGenerator.h index 40d3ea04b..dcb86bd51 100644 --- a/Source/cmLocalGenerator.h +++ b/Source/cmLocalGenerator.h @@ -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 diff --git a/Source/cmLocalUnixMakefileGenerator3.cxx b/Source/cmLocalUnixMakefileGenerator3.cxx index 52d12cd99..9e18a58ba 100644 --- a/Source/cmLocalUnixMakefileGenerator3.cxx +++ b/Source/cmLocalUnixMakefileGenerator3.cxx @@ -31,6 +31,7 @@ #ifdef CMAKE_BUILD_WITH_CMAKE # include "cmDependsFortran.h" # include "cmDependsJava.h" +# include #endif #include // 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); } diff --git a/Source/cmLocalUnixMakefileGenerator3.h b/Source/cmLocalUnixMakefileGenerator3.h index 970cd93c4..264749b91 100644 --- a/Source/cmLocalUnixMakefileGenerator3.h +++ b/Source/cmLocalUnixMakefileGenerator3.h @@ -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); diff --git a/Source/cmMakefileTargetGenerator.cxx b/Source/cmMakefileTargetGenerator.cxx index 265dee72a..eda3ac3b8 100644 --- a/Source/cmMakefileTargetGenerator.cxx +++ b/Source/cmMakefileTargetGenerator.cxx @@ -805,7 +805,7 @@ void cmMakefileTargetGenerator::WriteTargetDependRules() // cmake -E cmake_depends // // - // + // --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. diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx index 52e1ca24b..6829bdc90 100644 --- a/Source/cmSystemTools.cxx +++ b/Source/cmSystemTools.cxx @@ -23,6 +23,9 @@ #include #include #include +#if defined(CMAKE_BUILD_WITH_CMAKE) +# include +#endif #if defined(_WIN32) # include @@ -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 diff --git a/Source/cmSystemTools.h b/Source/cmSystemTools.h index bbc9ba65c..395b4d6b6 100644 --- a/Source/cmSystemTools.h +++ b/Source/cmSystemTools.h @@ -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; diff --git a/Source/cmake.cxx b/Source/cmake.cxx index baa9f59a9..dc1c0d26a 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -1365,6 +1365,7 @@ int cmake::ExecuteCMakeCommand(std::vector& 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& args) // -E cmake_depends // // - // + // [--color=$(COLOR)] // // All paths are provided. gen = args[2]; @@ -1381,6 +1382,13 @@ int cmake::ExecuteCMakeCommand(std::vector& 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& 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& args) // argv[0] == // 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& 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); } }