appveyor: add error handler to fix shutil.rmtree on Windows

This commit is contained in:
Ralph Lange
2020-02-20 09:15:35 +01:00
parent 28aeda558b
commit 2847f78ab2
2 changed files with 9 additions and 3 deletions

View File

@@ -165,7 +165,7 @@ class TestAddDependency(unittest.TestCase):
def setUp(self):
os.environ['SETUP_PATH'] = '.:appveyor'
if os.path.exists(self.location):
shutil.rmtree(self.location)
shutil.rmtree(self.location, onerror=do.remove_readonly)
do.clear_lists()
os.chdir(builddir)
do.source_set('defaults')

View File

@@ -4,7 +4,8 @@
from __future__ import print_function
import sys, os, shutil, fileinput
import sys, os, stat, shutil
import fileinput
import logging
import subprocess as sp
import distutils.util
@@ -37,6 +38,11 @@ def clear_lists():
del modules_to_compile[:]
setup.clear()
# Error-handler to make shutil.rmtree delete read-only files on Windows
def remove_readonly(func, path, excinfo):
os.chmod(path, stat.S_IWRITE)
func(path)
# source_set(setup)
#
# Source a settings file (extension .set) found in the setup_dirs path
@@ -190,7 +196,7 @@ def add_dependency(dep, tag):
logger.debug('Found checked_out commit %s, git head is %s', checked_out, head)
if head != checked_out:
logger.debug('Dependency %s out of date - removing', dep)
shutil.rmtree(place)
shutil.rmtree(place, onerror=remove_readonly)
else:
print('Found {0} of dependency {1} up-to-date in {2}'.format(tag, dep, place))