From a943b5c4f3ed700f53c554b9f91942ad57047c18 Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 7 Feb 2013 08:53:50 -0500 Subject: [PATCH] Fail early if no current working directory exists Remove the old "nocwd" behavior that attempts to provide the "--help" output when no working directory is available. The long help output scrolls the real error message out of typical terminal sizes. Also execute as little code as possible when no working directory exists. --- Source/CPack/cpack.cxx | 5 ++--- Source/cmakemain.cxx | 8 +++----- Source/ctest.cxx | 5 ++--- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/Source/CPack/cpack.cxx b/Source/CPack/cpack.cxx index 0ba732269..b18891858 100644 --- a/Source/CPack/cpack.cxx +++ b/Source/CPack/cpack.cxx @@ -180,7 +180,6 @@ int main (int argc, char *argv[]) { cmSystemTools::FindExecutableDirectory(argv[0]); cmCPackLog log; - int nocwd = 0; log.SetErrorPrefix("CPack Error: "); log.SetWarningPrefix("CPack Warning: "); @@ -193,7 +192,7 @@ int main (int argc, char *argv[]) { cmCPack_Log(&log, cmCPackLog::LOG_ERROR, "Current working directory cannot be established." << std::endl); - nocwd = 1; + return 1; } std::string generator; @@ -297,7 +296,7 @@ int main (int argc, char *argv[]) * should launch cpack using "cpackConfigFile" if it exists * in the current directory. */ - if((doc.CheckOptions(argc, argv,"-G") || nocwd) && !(argc==1)) + if((doc.CheckOptions(argc, argv,"-G")) && !(argc==1)) { help = true; } diff --git a/Source/cmakemain.cxx b/Source/cmakemain.cxx index 11a426753..42678419e 100644 --- a/Source/cmakemain.cxx +++ b/Source/cmakemain.cxx @@ -344,19 +344,17 @@ int main(int ac, char** av) int do_cmake(int ac, char** av) { - int nocwd = 0; - if ( cmSystemTools::GetCurrentWorkingDirectory().size() == 0 ) { std::cerr << "Current working directory cannot be established." << std::endl; - nocwd = 1; + return 1; } #ifdef CMAKE_BUILD_WITH_CMAKE cmDocumentation doc; doc.addCMakeStandardDocSections(); - if(doc.CheckOptions(ac, av, "-E") || nocwd) + if(doc.CheckOptions(ac, av, "-E")) { // Construct and print requested documentation. cmake hcm; @@ -424,7 +422,7 @@ int do_cmake(int ac, char** av) return result; } #else - if ( nocwd || ac == 1 ) + if ( ac == 1 ) { std::cout << "Bootstrap CMake should not be used outside CMake build process." diff --git a/Source/ctest.cxx b/Source/ctest.cxx index d65077748..8de901ae8 100644 --- a/Source/ctest.cxx +++ b/Source/ctest.cxx @@ -273,14 +273,13 @@ int main (int argc, char *argv[]) return cmCTestLaunch::Main(argc, argv); } - int nocwd = 0; cmCTest inst; if ( cmSystemTools::GetCurrentWorkingDirectory().size() == 0 ) { cmCTestLog(&inst, ERROR_MESSAGE, "Current working directory cannot be established." << std::endl); - nocwd = 1; + return 1; } // If there is a testing input file, check for documentation options @@ -298,7 +297,7 @@ int main (int argc, char *argv[]) } cmDocumentation doc; doc.addCTestStandardDocSections(); - if(doc.CheckOptions(argc, argv) || nocwd) + if(doc.CheckOptions(argc, argv)) { // Construct and print requested documentation. std::vector commands;