Skip to content

Commit 1dda499

Browse files
authored
Merge pull request #185 from firebase/feature/fix-windows-vcpkg-rename-error
Feature/fix windows vcpkg rename error
2 parents cb29f36 + cdcccbc commit 1dda499

File tree

2 files changed

+68
-11
lines changed

2 files changed

+68
-11
lines changed

scripts/gha/build_desktop.py

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ 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):
6969
"""Install packages with vcpkg.
7070
7171
This does the following,
@@ -99,14 +99,36 @@ def install_cpp_dependencies_with_vcpkg(arch, msvc_runtime_library):
9999
utils.run_command([vcpkg_executable_file_path, 'install',
100100
'@' + vcpkg_response_file_path, '--disable-metrics'])
101101

102-
# Some errors in vcpkg installation are not bubbled up. Verify existence
103-
# of certain important directories before proceeding.
104-
utils.verify_vcpkg_build(vcpkg_triplet)
102+
def install_cpp_dependencies_with_vcpkg(arch, msvc_runtime_library, cleanup=True):
103+
"""Install packages with vcpkg and optionally cleanup any intermediates.
105104
106-
# Clear temporary directories and files created by vcpkg buildtrees
107-
# could be several GBs and cause github runners to run out of space
108-
utils.clean_vcpkg_temp_data()
105+
This is a wrapper over a low level installation function and attempts the
106+
installation twice, a second time after attempting to auto fix known issues.
109107
108+
Args:
109+
arch (str): Architecture (eg: 'x86', 'x64').
110+
msvc_runtime_library (str): Runtime library for MSVC (eg: 'static', 'dynamic').
111+
cleanup (bool): Clean up intermediate files used during installation.
112+
113+
Raises:
114+
(ValueError) If installation wasn't successful.
115+
"""
116+
_install_cpp_dependencies_with_vcpkg(arch, msvc_runtime_library)
117+
vcpkg_triplet = utils.get_vcpkg_triplet(arch, msvc_runtime_library)
118+
# Verify the installation with an attempt to auto fix any issues.
119+
success = utils.verify_vcpkg_build(vcpkg_triplet, attempt_auto_fix=True)
120+
if not success:
121+
print("Installation was not successful but auto fix was attempted. "
122+
"Retrying installation...")
123+
# Retry once more after attempted auto fix.
124+
_install_cpp_dependencies_with_vcpkg(arch, msvc_runtime_library)
125+
# Check for success again. If installation failed, this call will raise a ValueError.
126+
success = utils.verify_vcpkg_build(vcpkg_triplet, attempt_auto_fix=False)
127+
128+
if cleanup:
129+
# Clear temporary directories and files created by vcpkg buildtrees
130+
# could be several GBs and cause github runners to run out of space
131+
utils.clean_vcpkg_temp_data()
110132

111133
def cmake_configure(build_dir, arch, msvc_runtime_library='static',
112134
build_tests=True, config=None, target_format=None):
@@ -179,8 +201,13 @@ def main():
179201
if args.arch == 'x86' and utils.is_linux_os():
180202
install_x86_support_libraries()
181203

182-
# Install platform dependent cpp dependencies with vcpkg
183-
install_cpp_dependencies_with_vcpkg(args.arch, args.msvc_runtime_library)
204+
# Install C++ dependencies using vcpkg
205+
install_cpp_dependencies_with_vcpkg(args.arch, args.msvc_runtime_library,
206+
cleanup=True)
207+
208+
if args.vcpkg_step_only:
209+
print("Exiting without building the Firebase C++ SDK as just vcpkg step was requested.")
210+
return
184211

185212
# CMake configure
186213
cmake_configure(args.build_dir, args.arch, args.msvc_runtime_library,
@@ -219,6 +246,7 @@ def parse_cmdline_args():
219246
help='Runtime library for MSVC (static(/MT) or dynamic(/MD)')
220247
parser.add_argument('--build_dir', default='build', help='Output build directory')
221248
parser.add_argument('--build_tests', action='store_true', help='Build unit tests too')
249+
parser.add_argument('--vcpkg_step_only', action='store_true', help='Just install cpp packages using vcpkg and exit.')
222250
parser.add_argument('--config', default='Release', help='Release/Debug config')
223251
parser.add_argument('--target', nargs='+', help='A list of CMake build targets (eg: firebase_app firebase_auth)')
224252
parser.add_argument('--target_format', default=None, help='(Mac only) whether to output frameworks (default) or libraries.')

scripts/gha/utils.py

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,15 +169,44 @@ 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+
# In the specific windows error that we noticed, the error occurs while
197+
# trying to rename intermediate directories for donwloaded tools
198+
# like "powershell.partial.<pid>" to "powershell". Renaming via python
199+
# also runs into the same error. Workaround is to copy instead of rename.
200+
if '.partial.' in name and os.path.isdir(os.path.join(tools_dir_path, name)):
201+
expected_name = name.split('.partial.')[0]
202+
shutil.copytree(os.path.join(tools_dir_path, name),
203+
os.path.join(tools_dir_path, expected_name))
204+
return False
205+
178206
raise ValueError("Could not find directory containing installed packages by vcpkg: {0}\n"
179207
"Please check if there were errors during "
180208
"vcpkg installation.".format(installed_triplets_dir_path))
209+
return True
181210

182211

183212
def clean_vcpkg_temp_data():

0 commit comments

Comments
 (0)