Auto merge of #22734 - learning:patch-msvc-install, r=jdm

Fix BadZipfile error while install msvc dependencies

<!-- Please describe your changes on the following line: -->
Fix BadZipfile error while install msvc dependencies

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix #22727

<!-- Either: -->
- [X] These changes do not require tests because it's a patch to `mach`

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/22734)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2019-01-21 13:49:48 -05:00 committed by GitHub
commit 6bce9a1d1b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -12,6 +12,7 @@ import platform
import shutil import shutil
import subprocess import subprocess
from subprocess import PIPE from subprocess import PIPE
from zipfile import BadZipfile
import servo.packages as packages import servo.packages as packages
from servo.util import extract, download_file, host_triple from servo.util import extract, download_file, host_triple
@ -300,6 +301,21 @@ def windows_msvc(context, force=False):
return True return True
return False return False
def prepare_file(zip_path, full_spec):
if not os.path.isfile(zip_path):
zip_url = "{}{}.zip".format(deps_url, full_spec)
download_file(full_spec, zip_url, zip_path)
print("Extracting {}...".format(full_spec), end='')
try:
extract(zip_path, deps_dir)
except BadZipfile:
print("\nError: %s.zip is not a valid zip file, redownload..." % full_spec)
os.remove(zip_path)
prepare_file(zip_path, full_spec)
else:
print("done")
to_install = {} to_install = {}
for package in packages.WINDOWS_MSVC: for package in packages.WINDOWS_MSVC:
# Don't install CMake if it already exists in PATH # Don't install CMake if it already exists in PATH
@ -321,13 +337,7 @@ def windows_msvc(context, force=False):
os.makedirs(parent_dir) os.makedirs(parent_dir)
zip_path = package_dir(package) + ".zip" zip_path = package_dir(package) + ".zip"
if not os.path.isfile(zip_path): prepare_file(zip_path, full_spec)
zip_url = "{}{}.zip".format(deps_url, full_spec)
download_file(full_spec, zip_url, zip_path)
print("Extracting {}...".format(full_spec), end='')
extract(zip_path, deps_dir)
print("done")
extracted_path = os.path.join(deps_dir, full_spec) extracted_path = os.path.join(deps_dir, full_spec)
os.rename(extracted_path, package_dir(package)) os.rename(extracted_path, package_dir(package))