Browse Source

cmakemain: Return the SCRIPT_MODE exit code if it was set

We determine it via checking cmake.Run() return code and
ScriptModeExitCode. If ScriptModeExitCode is zero, then we would return
1 if retcode was non-zero. Otherwise it will be returned if retcode was
  also non-zero.
leha-bot 1 năm trước cách đây
mục cha
commit
4f160f7906
2 tập tin đã thay đổi với 8 bổ sung5 xóa
  1. 1 1
      Source/cmake.cxx
  2. 7 4
      Source/cmakemain.cxx

+ 1 - 1
Source/cmake.cxx

@@ -2820,7 +2820,7 @@ int cmake::Run(const std::vector<std::string>& args, bool noconfigure)
     if (cmSystemTools::GetErrorOccurredFlag()) {
       return -1;
     }
-    return 0;
+    return this->HasScriptModeExitCode() ? this->GetScriptModeExitCode() : 0;
   }
 
   // If MAKEFLAGS are given in the environment, remove the environment

+ 7 - 4
Source/cmakemain.cxx

@@ -389,13 +389,16 @@ int do_cmake(int ac, char const* const* av)
     }
   }
 
-  // Always return a non-negative value.  Windows tools do not always
-  // interpret negative return values as errors.
+  // Always return a non-negative value (except exit code from SCRIPT_MODE).
+  // Windows tools do not always interpret negative return values as errors.
   if (res != 0) {
+    auto scriptModeExitCode =
+      cm.HasScriptModeExitCode() ? cm.GetScriptModeExitCode() : 0;
+    res = scriptModeExitCode ? scriptModeExitCode : 1;
 #ifdef CMake_ENABLE_DEBUGGER
-    cm.StopDebuggerIfNeeded(1);
+    cm.StopDebuggerIfNeeded(res);
 #endif
-    return 1;
+    return res;
   }
 #ifdef CMake_ENABLE_DEBUGGER
   cm.StopDebuggerIfNeeded(0);