]> granicus.if.org Git - icu/commitdiff
ICU-20555 Fix Windows build failures with long paths: Use PowerShell when command...
authorJeff Genovy <29107334+jefgen@users.noreply.github.com>
Tue, 27 Aug 2019 23:57:50 +0000 (16:57 -0700)
committerJeff Genovy <29107334+jefgen@users.noreply.github.com>
Thu, 29 Aug 2019 19:22:56 +0000 (12:22 -0700)
icu4c/source/python/icutools/databuilder/renderers/common_exec.py

index 26c4c8ae55c375e3a1d7a0aef19081af60d5d7b9..838b121afe565856ab9dbca347a0ce420ce3feed 100644 (file)
@@ -98,7 +98,7 @@ def run_helper(request, common_vars, platform, tool_dir, verbose, tool_cfg=None,
             if platform == "windows":
                 # Note: this / to \ substitution may be too aggressive?
                 command_line = command_line.replace("/", "\\")
-            returncode = run_shell_command(command_line, verbose)
+            returncode = run_shell_command(command_line, platform, verbose)
             if returncode != 0:
                 return returncode
         return 0
@@ -111,23 +111,36 @@ def run_helper(request, common_vars, platform, tool_dir, verbose, tool_cfg=None,
         if platform == "windows":
             # Note: this / to \ substitution may be too aggressive?
             command_line = command_line.replace("/", "\\")
-        returncode = run_shell_command(command_line, verbose)
+        returncode = run_shell_command(command_line, platform, verbose)
         return returncode
     assert False
 
-def run_shell_command(command_line, verbose):
+def run_shell_command(command_line, platform, verbose):
+    changed_windows_comspec = False
+    # If the command line length on Windows exceeds the absolute maximum that CMD supports (8191), then
+    # we temporarily switch over to use PowerShell for the command, and then switch back to CMD.
+    # We don't want to use PowerShell for everything though, as it tends to be slower.
+    if (platform == "windows") and (len(command_line) > 8190):
+        if verbose:
+            print("Command length exceeds the max length for CMD on Windows, using PowerShell instead.")
+        previous_comspec = os.environ["COMSPEC"]
+        os.environ["COMSPEC"] = 'powershell'
+        changed_windows_comspec = True
     if verbose:
         print("Running: %s" % command_line)
-        return subprocess.call(
+        returncode = subprocess.call(
             command_line,
             shell = True
         )
     else:
         # Pipe output to /dev/null in quiet mode
         with open(os.devnull, "w") as devnull:
-            return subprocess.call(
+            returncode = subprocess.call(
                 command_line,
                 shell = True,
                 stdout = devnull,
                 stderr = devnull
             )
+    if changed_windows_comspec:
+        os.environ["COMSPEC"] = previous_comspec
+    return returncode