10 # Disable certificate checking because it always fails on Windows
11 # We verify the checksum anyway.
12 ctx = ssl.create_default_context()
13 ctx.check_hostname = False
14 ctx.verify_mode = ssl.CERT_NONE
16 base_url = 'https://www.nasm.us/pub/nasm/releasebuilds/{0}/{1}/nasm-{0}-{1}.zip'
17 arch = 'win64' if sys.argv[2] == 'x86_64' else 'win32'
18 url = base_url.format(sys.argv[1], arch)
19 zip_sha256 = sys.argv[3]
20 source_dir = os.path.join(os.environ['MESON_SOURCE_ROOT'], os.environ['MESON_SUBDIR'])
21 dest = os.path.basename(url)
22 dest_path = os.path.join(source_dir, dest)
25 hasher = hashlib.sha256()
26 with open(zipf, 'rb') as f:
27 hasher.update(f.read())
28 return hasher.hexdigest()
30 if os.path.isfile(dest_path):
31 found_sha256 = get_sha256(dest_path)
32 if found_sha256 == zip_sha256:
33 print('{} already downloaded'.format(dest))
36 print('{} checksum mismatch, redownloading'.format(dest))
38 print('Downloading {} to {}'.format(url, dest))
39 with open(dest_path, 'wb') as d:
40 f = urllib.request.urlopen(url, context=ctx)
43 found_sha256 = get_sha256(dest_path)
44 if found_sha256 != zip_sha256:
45 print('SHA256 of downloaded file {} was {} instead of {}'
46 ''.format(dest, found_sha256, zip_sha256))
49 print('Extracting {}'.format(dest))
50 zf = zipfile.ZipFile(dest_path, "r")
51 zf.extractall(path=source_dir)