Skip to content

Commit 9ccee4b

Browse files
committed
special handling for windows file renaming error.
During vcpkg installation, we sometimes see a permissions not granted for renaming a downloaded file. This fix tries to circumvent those issues by copying over the directory to the right name.
1 parent 529572f commit 9ccee4b

File tree

2 files changed

+51
-5
lines changed

2 files changed

+51
-5
lines changed

scripts/gha/build_desktop.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ def install_x86_support_libraries():
6565
utils.run_command(['apt', 'install', 'libsecret-1-dev:i386'], as_root=True)
6666

6767

68-
def install_cpp_dependencies_with_vcpkg(arch, msvc_runtime_library):
68+
def install_cpp_dependencies_with_vcpkg(arch, msvc_runtime_library,
69+
attempt_auto_fix=False):
6970
"""Install packages with vcpkg.
7071
7172
This does the following,
@@ -75,6 +76,13 @@ def install_cpp_dependencies_with_vcpkg(arch, msvc_runtime_library):
7576
Args:
7677
arch (str): Architecture (eg: 'x86', 'x64').
7778
msvc_runtime_library (str): Runtime library for MSVC (eg: 'static', 'dynamic').
79+
attempt_auto_fix (bool): In case of errors, try to auto fix.
80+
Returns:
81+
(bool): True if installation was successful.
82+
False if installation wasn't successful but auto fix was attempted
83+
and we should retry the installation.
84+
Raises:
85+
(ValueError): If installation wasn't successful and auto fix wasn't attempted.
7886
"""
7987

8088
# Install vcpkg executable if its not installed already
@@ -101,11 +109,14 @@ def install_cpp_dependencies_with_vcpkg(arch, msvc_runtime_library):
101109

102110
# Some errors in vcpkg installation are not bubbled up. Verify existence
103111
# of certain important directories before proceeding.
104-
utils.verify_vcpkg_build(vcpkg_triplet)
112+
success = utils.verify_vcpkg_build(vcpkg_triplet, attempt_auto_fix)
113+
if not success:
114+
return False
105115

106116
# Clear temporary directories and files created by vcpkg buildtrees
107117
# could be several GBs and cause github runners to run out of space
108118
utils.clean_vcpkg_temp_data()
119+
return True
109120

110121

111122
def cmake_configure(build_dir, arch, msvc_runtime_library='static',
@@ -180,7 +191,16 @@ def main():
180191
install_x86_support_libraries()
181192

182193
# Install platform dependent cpp dependencies with vcpkg
183-
install_cpp_dependencies_with_vcpkg(args.arch, args.msvc_runtime_library)
194+
# Try once with auto-fixing any errors (if any)
195+
success = install_cpp_dependencies_with_vcpkg(args.arch,
196+
args.msvc_runtime_library,
197+
attempt_auto_fix=True)
198+
if not success:
199+
# If auto-fix was attempted, give it one more try.
200+
# If it fails again, a ValueError will be raised and script will exit.
201+
install_cpp_dependencies_with_vcpkg(args.arch,
202+
args.msvc_runtime_library,
203+
attempt_auto_fix=False)
184204

185205
# CMake configure
186206
cmake_configure(args.build_dir, args.arch, args.msvc_runtime_library,

scripts/gha/utils.py

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,15 +169,41 @@ def get_vcpkg_installation_script_path():
169169
return script_absolute_path
170170

171171

172-
def verify_vcpkg_build(vcpkg_triplet):
173-
"""Check if vcpkg installation finished successfully."""
172+
def verify_vcpkg_build(vcpkg_triplet, attempt_auto_fix=False):
173+
"""Check if vcpkg installation finished successfully.
174+
175+
Args:
176+
vcpkg_triplet (str): Triplet name for vcpkg. Eg: 'x64-linux'
177+
attempt_auto_fix (bool): If installation failed, try fixing some errors.
178+
179+
Returns:
180+
(bool) True if everything looks good
181+
False if installation failed but auto fix was attempted.
182+
Caller should retry installation in this case.
183+
Raises:
184+
(ValueError) Installation failed and auto fix was not attempted
185+
"""
174186
# At the very least, we should have an "installed" directory under vcpkg triplet.
175187
vcpkg_root_dir_path = get_vcpkg_root_path()
176188
installed_triplets_dir_path = os.path.join(vcpkg_root_dir_path, 'installed', vcpkg_triplet)
177189
if not os.path.exists(installed_triplets_dir_path):
190+
if is_windows_os() and attempt_auto_fix:
191+
# On some Windows machines with NFS drives, we have seen errors
192+
# installing vcpkg due to permission issues while renaming temp directories.
193+
# Manually renaming and re-running script makes it go through.
194+
tools_dir_path = os.path.join(vcpkg_root_dir_path, 'downloads', 'tools')
195+
for name in os.listdir(tools_dir_path):
196+
if '.partial.' in name and os.path.isdir(os.path.join(tools_dir_path, name)):
197+
# Since we can't rename, lets copy the directory to one without partial in the name
198+
expected_name = name.split('.partial.')[0]
199+
shutil.copytree(os.path.join(tools_dir_path, name),
200+
os.path.join(tools_dir_path, expected_name))
201+
return False
202+
178203
raise ValueError("Could not find directory containing installed packages by vcpkg: {0}\n"
179204
"Please check if there were errors during "
180205
"vcpkg installation.".format(installed_triplets_dir_path))
206+
return True
181207

182208

183209
def clean_vcpkg_temp_data():

0 commit comments

Comments
 (0)