summaryrefslogtreecommitdiffstats
path: root/Source/cmcmd.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2015-02-05 21:48:16 (GMT)
committerBrad King <brad.king@kitware.com>2015-02-06 13:36:51 (GMT)
commit8521fdf56e4908676c28c6bbdda3f1fb2284d3d7 (patch)
treec3df791d24c06b677cf09bd02c3e791534272ccc /Source/cmcmd.cxx
parent69ac6d27555cd4819d0c7f40e4471c6f885e23ab (diff)
downloadCMake-8521fdf56e4908676c28c6bbdda3f1fb2284d3d7.zip
CMake-8521fdf56e4908676c28c6bbdda3f1fb2284d3d7.tar.gz
CMake-8521fdf56e4908676c28c6bbdda3f1fb2284d3d7.tar.bz2
Makefile: Fix output during parallel builds (#12991)
Replace use of separate "cmake -E cmake_progress_report" and "cmake -E cmake_echo_color" commands to report the progress and message portions of build output lines with --progress-* options to the latter to print everything with a single command. The line buffering of the stdout FILE stream should cause the whole line to be printed with one atomic write. This will avoid inter-mixing of line-wise messages from different processes during a parallel build.
Diffstat (limited to 'Source/cmcmd.cxx')
-rw-r--r--Source/cmcmd.cxx117
1 files changed, 75 insertions, 42 deletions
diff --git a/Source/cmcmd.cxx b/Source/cmcmd.cxx
index 6b04d26..5260cb0 100644
--- a/Source/cmcmd.cxx
+++ b/Source/cmcmd.cxx
@@ -534,48 +534,9 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
// Command to report progress for a build
else if (args[1] == "cmake_progress_report" && args.size() >= 3)
{
- std::string dirName = args[2];
- dirName += "/Progress";
- std::string fName;
- FILE *progFile;
-
- // read the count
- fName = dirName;
- fName += "/count.txt";
- progFile = cmsys::SystemTools::Fopen(fName,"r");
- int count = 0;
- if (!progFile)
- {
- return 0;
- }
- else
- {
- if (1!=fscanf(progFile,"%i",&count))
- {
- cmSystemTools::Message("Could not read from progress file.");
- }
- fclose(progFile);
- }
- unsigned int i;
- for (i = 3; i < args.size(); ++i)
- {
- fName = dirName;
- fName += "/";
- fName += args[i];
- progFile = cmsys::SystemTools::Fopen(fName,"w");
- if (progFile)
- {
- fprintf(progFile,"empty");
- fclose(progFile);
- }
- }
- int fileNum = static_cast<int>
- (cmsys::Directory::GetNumberOfFilesInDirectory(dirName));
- if (count > 0)
- {
- // print the progress
- fprintf(stdout,"[%3i%%] ",((fileNum-3)*100)/count);
- }
+ // This has been superseded by cmake_echo_color --progress-*
+ // options. We leave it here to avoid errors if somehow this
+ // is invoked by an existing makefile without regenerating.
return 0;
}
@@ -987,6 +948,65 @@ bool cmcmd::SymlinkInternal(std::string const& file, std::string const& link)
}
//----------------------------------------------------------------------------
+static void cmcmdProgressReport(std::string const& dir,
+ std::string const& num)
+{
+ std::string dirName = dir;
+ dirName += "/Progress";
+ std::string fName;
+ FILE *progFile;
+
+ // read the count
+ fName = dirName;
+ fName += "/count.txt";
+ progFile = cmsys::SystemTools::Fopen(fName,"r");
+ int count = 0;
+ if (!progFile)
+ {
+ return;
+ }
+ else
+ {
+ if (1!=fscanf(progFile,"%i",&count))
+ {
+ cmSystemTools::Message("Could not read from progress file.");
+ }
+ fclose(progFile);
+ }
+ const char* last = num.c_str();
+ for(const char* c = last;; ++c)
+ {
+ if (*c == ',' || *c == '\0')
+ {
+ if (c != last)
+ {
+ fName = dirName;
+ fName += "/";
+ fName.append(last, c-last);
+ progFile = cmsys::SystemTools::Fopen(fName,"w");
+ if (progFile)
+ {
+ fprintf(progFile,"empty");
+ fclose(progFile);
+ }
+ }
+ if(*c == '\0')
+ {
+ break;
+ }
+ last = c + 1;
+ }
+ }
+ int fileNum = static_cast<int>
+ (cmsys::Directory::GetNumberOfFilesInDirectory(dirName));
+ if (count > 0)
+ {
+ // print the progress
+ fprintf(stdout,"[%3i%%] ",((fileNum-3)*100)/count);
+ }
+}
+
+//----------------------------------------------------------------------------
int cmcmd::ExecuteEchoColor(std::vector<std::string>& args)
{
// The arguments are
@@ -996,6 +1016,7 @@ int cmcmd::ExecuteEchoColor(std::vector<std::string>& args)
bool enabled = true;
int color = cmsysTerminal_Color_Normal;
bool newline = true;
+ std::string progressDir;
for(unsigned int i=2; i < args.size(); ++i)
{
if(args[i].find("--switch=") == 0)
@@ -1014,6 +1035,18 @@ int cmcmd::ExecuteEchoColor(std::vector<std::string>& args)
}
}
}
+ else if(cmHasLiteralPrefix(args[i], "--progress-dir="))
+ {
+ progressDir = args[i].substr(15);
+ }
+ else if(cmHasLiteralPrefix(args[i], "--progress-num="))
+ {
+ if (!progressDir.empty())
+ {
+ std::string const& progressNum = args[i].substr(15);
+ cmcmdProgressReport(progressDir, progressNum);
+ }
+ }
else if(args[i] == "--normal")
{
color = cmsysTerminal_Color_Normal;