11 # Disable certificate checking because it requires custom Python setup on macOS
12 ctx = ssl.create_default_context()
13 ctx.check_hostname = False
14 ctx.verify_mode = ssl.CERT_NONE
16 EXTRACTDIR = 'bison-{}-macos-{}'
17 BASENAME = '{}.tar.bz2'.format(EXTRACTDIR)
18 GSTREAMER_URL = 'https://gstreamer.freedesktop.org/src/mirror/{}'
22 tar_sha256 = sys.argv[3]
23 source_dir = os.path.join(os.environ['MESON_SOURCE_ROOT'], os.environ['MESON_SUBDIR'])
24 dest = BASENAME.format(version, arch)
25 dest_path = os.path.join(source_dir, dest)
26 extract_path = EXTRACTDIR.format(version, arch)
29 hasher = hashlib.sha256()
30 with open(tarf, 'rb') as f:
31 hasher.update(f.read())
32 return hasher.hexdigest()
35 for url in (GSTREAMER_URL.format(dest),):
36 print('Downloading {} to {}'.format(url, dest), file=sys.stderr)
38 with open(dest_path, 'wb') as d:
39 f = urllib.request.urlopen(url, context=ctx)
42 except urllib.error.URLError as ex:
43 print(ex, file=sys.stderr)
44 print('Failed to download from {!r}, trying mirror...'.format(url), file=sys.stderr)
47 curdir = os.path.dirname(sys.argv[0])
48 print('Couldn\'t download {!r}! Try downloading it manually and '
49 'placing it into {!r}'.format(dest, curdir), file=sys.stderr)
51 def print_extract_dir():
52 'Print the extracted directory name'
53 print(extract_path, end='')
55 if os.path.isfile(dest_path):
56 found_sha256 = get_sha256(dest_path)
57 if found_sha256 == tar_sha256:
58 if os.path.isdir(os.path.join(source_dir, extract_path)):
59 print('{} already downloaded and extracted'.format(dest), file=sys.stderr)
63 print('{} checksum mismatch, redownloading'.format(dest), file=sys.stderr)
68 found_sha256 = get_sha256(dest_path)
69 if found_sha256 != tar_sha256:
70 print('SHA256 of downloaded file {} was {} instead of {}'
71 ''.format(dest, found_sha256, tar_sha256), file=sys.stderr)
74 print('Extracting {}'.format(dest), file=sys.stderr)
75 tf = tarfile.open(dest_path, "r")
76 tf.extractall(path=source_dir)