scripts: Switch from mkpath to makedirs
authorMike Schuchardt <mikes@lunarg.com>
Wed, 28 Apr 2021 19:10:06 +0000 (12:10 -0700)
committerMike Schuchardt <mikes@lunarg.com>
Thu, 29 Apr 2021 20:06:56 +0000 (13:06 -0700)
distutils.dir_util.mkpath will not re-create a directory if it has been
removed with shutil.rmtree because it caches the filesystem under the
hood. This was causing the clone retry to fail on the second iteration
every time.

Switch to using os.makedirs for equivalent functionality without the
cache.

scripts/update_deps.py

index ea21c9f..ffd928f 100755 (executable)
@@ -242,7 +242,6 @@ from __future__ import print_function
 
 import argparse
 import json
-import distutils.dir_util
 import os.path
 import subprocess
 import sys
@@ -275,6 +274,12 @@ def on_rm_error( func, path, exc_info):
     os.chmod( path, stat.S_IWRITE )
     os.unlink( path )
 
+def make_or_exist_dirs(path):
+    "Wrapper for os.makedirs that tolerates the directory already existing"
+    # Could use os.makedirs(path, exist_ok=True) if we drop python2
+    if not os.path.isdir(path):
+        os.makedirs(path)
+
 def command_output(cmd, directory, fail_ok=False):
     """Runs a command in a directory and returns its standard output stream.
 
@@ -346,7 +351,7 @@ class GoodRepo(object):
     def Clone(self, retries=10, retry_seconds=60):
         print('Cloning {n} into {d}'.format(n=self.name, d=self.repo_dir))
         for retry in range(retries):
-            distutils.dir_util.mkpath(self.repo_dir)
+            make_or_exist_dirs(self.repo_dir)
             try:
                 command_output(['git', 'clone', self.url, '.'], self.repo_dir)
                 # If we get here, we didn't raise an error
@@ -426,7 +431,7 @@ class GoodRepo(object):
             shutil.rmtree(self.install_dir)
 
         # Create and change to build directory
-        distutils.dir_util.mkpath(self.build_dir)
+        make_or_exist_dirs(self.build_dir)
         os.chdir(self.build_dir)
 
         cmake_cmd = [
@@ -665,7 +670,7 @@ def main():
     save_cwd = os.getcwd()
 
     # Create working "top" directory if needed
-    distutils.dir_util.mkpath(args.dir)
+    make_or_exist_dirs(args.dir)
     abs_top_dir = os.path.abspath(args.dir)
 
     repos = GetGoodRepos(args)