From 95a8331edb4ba7b53abd796066165b29f70ff258 Mon Sep 17 00:00:00 2001 From: Alexander Neundorf Date: Tue, 17 Jul 2007 09:25:08 -0400 Subject: ENH: produce a lot more output when running with --debug-output -try to fix build error on HPUX Alex --- Source/cmGlobalGenerator.cxx | 3 ++ Source/cmGlobalGenerator.h | 7 ++++ Source/cmLocalGenerator.cxx | 5 +++ Source/cmMakefile.cxx | 31 ++++++++++------- Source/cmMessageCommand.cxx | 14 +------- Source/cmakemain.cxx | 83 +++++++++++++++++++++++++++++++++++++------- 6 files changed, 105 insertions(+), 38 deletions(-) diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index 31adcf1..9af5352 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -52,6 +52,7 @@ cmGlobalGenerator::cmGlobalGenerator() this->TryCompileTimeout = 0; this->ExtraGenerator = 0; + this->CurrentLocalGenerator = 0; } cmGlobalGenerator::~cmGlobalGenerator() @@ -845,12 +846,14 @@ void cmGlobalGenerator::Generate() // Generate project files for (i = 0; i < this->LocalGenerators.size(); ++i) { + this->SetCurrentLocalGenerator(this->LocalGenerators[i]); this->LocalGenerators[i]->Generate(); this->LocalGenerators[i]->GenerateInstallRules(); this->LocalGenerators[i]->GenerateTestFiles(); this->CMakeInstance->UpdateProgress("Generating", (i+1.0f)/this->LocalGenerators.size()); } + this->SetCurrentLocalGenerator(0); if (this->ExtraGenerator != 0) { diff --git a/Source/cmGlobalGenerator.h b/Source/cmGlobalGenerator.h index ccf00d7..540691f 100644 --- a/Source/cmGlobalGenerator.h +++ b/Source/cmGlobalGenerator.h @@ -122,6 +122,12 @@ public: const std::vector& GetLocalGenerators() const { return this->LocalGenerators;} + cmLocalGenerator* GetCurrentLocalGenerator() + {return this->CurrentLocalGenerator;} + + void SetCurrentLocalGenerator(cmLocalGenerator* lg) + {this->CurrentLocalGenerator = lg;} + void AddLocalGenerator(cmLocalGenerator *lg); ///! Set an generator for an "external makefile based project" @@ -235,6 +241,7 @@ protected: cmStdString ConfiguredFilesPath; cmake *CMakeInstance; std::vector LocalGenerators; + cmLocalGenerator* CurrentLocalGenerator; // map from project name to vector of local generators in that project std::map > ProjectMap; std::map > ProjectToTargetMap; diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index 5742fd5..5c8ee93 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -65,6 +65,9 @@ cmLocalGenerator::~cmLocalGenerator() void cmLocalGenerator::Configure() { + cmLocalGenerator* previousLg = this->GetGlobalGenerator()->GetCurrentLocalGenerator(); + this->GetGlobalGenerator()->SetCurrentLocalGenerator(this); + // make sure the CMakeFiles dir is there std::string filesDir = this->Makefile->GetStartOutputDirectory(); filesDir += cmake::GetCMakeFilesDirectory(); @@ -94,6 +97,8 @@ void cmLocalGenerator::Configure() this->UseRelativePaths = this->Makefile->IsOn("CMAKE_USE_RELATIVE_PATHS"); this->Configured = true; + + this->GetGlobalGenerator()->SetCurrentLocalGenerator(previousLg); } void cmLocalGenerator::SetupPathConversions() diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 7ed1f2b..2757ad3 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -306,7 +306,7 @@ bool cmMakefile::ExecuteCommand(const cmListFileFunction& lff) error << "Error in cmake code at\n" << lff.FilePath << ":" << lff.Line << ":\n" << rm->GetError() << std::endl - << "Current CMake stack: " << this->GetListFileStack().c_str(); + << "Called from: " << this->GetListFileStack().c_str(); cmSystemTools::Error(error.str().c_str()); return false; } @@ -323,7 +323,7 @@ bool cmMakefile::ExecuteCommand(const cmListFileFunction& lff) error << "Error in cmake code at\n" << lff.FilePath << ":" << lff.Line << ":\n" << usedCommand->GetError() << std::endl - << "Current CMake stack: " << this->GetListFileStack().c_str(); + << "Called from: " << this->GetListFileStack().c_str(); cmSystemTools::Error(error.str().c_str()); result = false; if ( this->GetCMakeInstance()->GetScriptMode() ) @@ -2607,7 +2607,7 @@ const char *cmMakefile::GetProperty(const char* prop, } else if (!strcmp("LISTFILE_STACK",prop)) { - for (std::deque::const_iterator i = this->ListFileStack.begin(); + for (std::deque::iterator i = this->ListFileStack.begin(); i != this->ListFileStack.end(); ++i) { if (i != this->ListFileStack.begin()) @@ -2774,17 +2774,24 @@ std::string cmMakefile::GetListFileStack() { cmOStringStream tmp; size_t depth = this->ListFileStack.size(); - std::deque::iterator it = this->ListFileStack.end(); - do + if (depth > 0) { - --it; - tmp << "\n["; - tmp << depth; - tmp << "]\t"; - tmp << *it; - depth--; + std::deque::iterator it = this->ListFileStack.end(); + do + { + if (depth != this->ListFileStack.size()) + { + tmp << "\n "; + } + --it; + tmp << "["; + tmp << depth; + tmp << "]\t"; + tmp << *it; + depth--; + } + while (it != this->ListFileStack.begin()); } - while (it != this->ListFileStack.begin()); return tmp.str(); } diff --git a/Source/cmMessageCommand.cxx b/Source/cmMessageCommand.cxx index 266bcf8..f77cfd5 100644 --- a/Source/cmMessageCommand.cxx +++ b/Source/cmMessageCommand.cxx @@ -59,14 +59,7 @@ bool cmMessageCommand::InitialPass(std::vector const& args) if (send_error || fatal_error) { - if( !this->Makefile->GetCMakeInstance()->GetDebugOutput()) - { - cmSystemTools::Error(message.c_str()); - } - else - { - this->SetError(message.c_str()); - } + cmSystemTools::Error(message.c_str()); } else { @@ -83,11 +76,6 @@ bool cmMessageCommand::InitialPass(std::vector const& args) { cmSystemTools::SetFatalErrorOccured(); } - // if debug is on then retru - if(this->Makefile->GetCMakeInstance()->GetDebugOutput()) - { - return (!send_error && !fatal_error); - } return true; } diff --git a/Source/cmakemain.cxx b/Source/cmakemain.cxx index 79ae833..70caeb8 100644 --- a/Source/cmakemain.cxx +++ b/Source/cmakemain.cxx @@ -19,6 +19,9 @@ #include "cmListFileCache.h" #include "cmakewizard.h" #include "cmSourceFile.h" +#include "cmGlobalGenerator.h" +#include "cmLocalGenerator.h" +#include "cmMakefile.h" #ifdef CMAKE_BUILD_WITH_CMAKE #include "cmDynamicLoader.h" @@ -172,7 +175,70 @@ static const cmDocumentationEntry cmDocumentationNOTE[] = #endif int do_cmake(int ac, char** av); -void updateProgress(const char *msg, float prog, void *cd); + +static cmMakefile* cmakemainGetMakefile(void *clientdata) +{ + cmake* cm = (cmake *)clientdata; + if(cm && cm->GetDebugOutput()) + { + cmGlobalGenerator* gg=cm->GetGlobalGenerator(); + if (gg) + { + cmLocalGenerator* lg=gg->GetCurrentLocalGenerator(); + if (lg) + { + cmMakefile* mf = lg->GetMakefile(); + return mf; + } + } + } + return 0; +} + +static std::string cmakemainGetStack(void *clientdata) +{ + std::string msg; + cmMakefile* mf=cmakemainGetMakefile(clientdata); + if (mf) + { + msg = mf->GetListFileStack(); + if (!msg.empty()) + { + msg = "\nCalled from: " + msg; + } + } + + return msg; +} + +static void cmakemainErrorCallback(const char* m, const char* title, bool& nomore, void *clientdata) +{ + std::cerr << m << cmakemainGetStack(clientdata) << std::endl << std::flush; +} + +static void cmakemainProgressCallback(const char *m, float prog, void* clientdata) +{ + cmMakefile* mf = cmakemainGetMakefile(clientdata); + std::string dir; + if ((mf) && (strstr(m, "Configuring")==m)) + { + dir = " "; + dir += mf->GetCurrentDirectory(); + } + else if ((mf) && (strstr(m, "Generating")==m)) + { + dir = " "; + dir += mf->GetCurrentOutputDirectory(); + } + + if ((prog < 0) || (!dir.empty())) + { + std::cout << "-- " << m << dir << cmakemainGetStack(clientdata) << std::endl; + } + + std::cout.flush(); +} + int main(int ac, char** av) { @@ -355,8 +421,10 @@ int do_cmake(int ac, char** av) return ret; } cmake cm; - cm.SetProgressCallback(updateProgress, 0); + cmSystemTools::SetErrorCallback(cmakemainErrorCallback, (void *)&cm); + cm.SetProgressCallback(cmakemainProgressCallback, (void *)&cm); cm.SetScriptMode(script_mode); + int res = cm.Run(args, view_only); if ( list_cached || list_all_cached ) { @@ -390,14 +458,3 @@ int do_cmake(int ac, char** av) return res; } -void updateProgress(const char *msg, float prog, void*) -{ - if ( prog < 0 ) - { - std::cout << "-- " << msg << std::endl; - } - //else - //{ - //std::cout << "-- " << msg << " " << prog << std::endl; - //} -} -- cgit v0.12