diff options
author | Nirbheek Chauhan <nirbheek@centricular.com> | 2021-08-23 18:53:54 +0530 |
---|---|---|
committer | Nirbheek Chauhan <nirbheek@centricular.com> | 2021-08-28 23:44:52 +0530 |
commit | afd11f3383398dc8516751a42d6e92c38bd66cdb (patch) | |
tree | 71d7de996992d460b1364047a952a4597fcbabbe | |
parent | 879126a31c77622f594e70f205fcefd4556d9865 (diff) |
New subproject macos-bison-binary to provide bison on macOS
The version of bison that ships with macOS is too old, so we need to
provide our own version of it.
Fixes https://gitlab.freedesktop.org/gstreamer/gst-build/-/issues/174
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-build/-/merge_requests/257>
-rw-r--r-- | meson.build | 2 | ||||
-rw-r--r-- | subprojects/macos-bison-binary/.gitignore | 4 | ||||
-rw-r--r-- | subprojects/macos-bison-binary/README.md | 14 | ||||
-rwxr-xr-x | subprojects/macos-bison-binary/bison.py.in | 14 | ||||
-rw-r--r-- | subprojects/macos-bison-binary/download-binary.py | 77 | ||||
-rw-r--r-- | subprojects/macos-bison-binary/meson.build | 28 |
6 files changed, 139 insertions, 0 deletions
diff --git a/meson.build b/meson.build index 91ff608..5c76626 100644 --- a/meson.build +++ b/meson.build @@ -91,6 +91,8 @@ os.symlink(os.path.join('@1@', 'subprojects', '@0@'), if build_system == 'windows' subproject('win-flex-bison-binaries') subproject('win-nasm') +elif build_system == 'darwin' + subproject('macos-bison-binary') endif orc_subproject = subproject('orc', required: get_option('orc')) diff --git a/subprojects/macos-bison-binary/.gitignore b/subprojects/macos-bison-binary/.gitignore new file mode 100644 index 0000000..adaad82 --- /dev/null +++ b/subprojects/macos-bison-binary/.gitignore @@ -0,0 +1,4 @@ +*.sw[op] +*~ +*.tar.* +bison-3.7.6-macos-x86_64/ diff --git a/subprojects/macos-bison-binary/README.md b/subprojects/macos-bison-binary/README.md new file mode 100644 index 0000000..9b590d5 --- /dev/null +++ b/subprojects/macos-bison-binary/README.md @@ -0,0 +1,14 @@ +## How to generate binaries and update build files + +1. Download the latest bison source tarball +1. Extract, then build it with --prefix=/ +1. Install into some dir using `DESTDIR` +1. Delete all files except the following subdirs: `bin` `lib` `share/bison` `share/aclocal` +1. Rename installdir to `bison-$version-macos-$arch` where `$arch` follows Meson's CPU families list: + https://mesonbuild.com/Reference-tables.html#cpu-families +1. `tar -cvjf bison-$version-macos-$arch.tar.bz2 bison-$version-macos-$arch/` +1. Fetch sha256sum: `shasum -256 bison-$version-macos-$arch.tar.bz2` +1. Update sha256sum in `meson.build` +1. Update `project()` version in `meson.build` + +That's it! diff --git a/subprojects/macos-bison-binary/bison.py.in b/subprojects/macos-bison-binary/bison.py.in new file mode 100755 index 0000000..64807d0 --- /dev/null +++ b/subprojects/macos-bison-binary/bison.py.in @@ -0,0 +1,14 @@ +#!/usr/bin/env python3 + +import os +import sys +import pathlib +import subprocess + +srcdir = pathlib.Path("@SRCDIR@") +extractdir = pathlib.Path("@EXTRACTDIR@") +bison_path = srcdir / extractdir / 'bin/bison' +env = os.environ.copy() +env['BISON_PKGDATADIR'] = str(srcdir / extractdir / 'share/bison') +ret = subprocess.run([str(bison_path)] + sys.argv[1:], check=False, env=env) +sys.exit(ret.returncode) diff --git a/subprojects/macos-bison-binary/download-binary.py b/subprojects/macos-bison-binary/download-binary.py new file mode 100644 index 0000000..460e5b0 --- /dev/null +++ b/subprojects/macos-bison-binary/download-binary.py @@ -0,0 +1,77 @@ +#!/usr/bin/env python3 + +import os +import sys +import ssl +import tarfile +import hashlib +import urllib.request +import urllib.error + +# Disable certificate checking because it requires custom Python setup on macOS +ctx = ssl.create_default_context() +ctx.check_hostname = False +ctx.verify_mode = ssl.CERT_NONE + +EXTRACTDIR = 'bison-{}-macos-{}' +BASENAME = '{}.tar.bz2'.format(EXTRACTDIR) +GSTREAMER_URL = 'https://gstreamer.freedesktop.org/src/mirror/{}' + +version = sys.argv[1] +arch = sys.argv[2] +tar_sha256 = sys.argv[3] +source_dir = os.path.join(os.environ['MESON_SOURCE_ROOT'], os.environ['MESON_SUBDIR']) +dest = BASENAME.format(version, arch) +dest_path = os.path.join(source_dir, dest) +extract_path = EXTRACTDIR.format(version, arch) + +def get_sha256(tarf): + hasher = hashlib.sha256() + with open(tarf, 'rb') as f: + hasher.update(f.read()) + return hasher.hexdigest() + +def download(): + for url in (GSTREAMER_URL.format(dest),): + print('Downloading {} to {}'.format(url, dest), file=sys.stderr) + try: + with open(dest_path, 'wb') as d: + f = urllib.request.urlopen(url, context=ctx) + d.write(f.read()) + break + except urllib.error.URLError as ex: + print(ex, file=sys.stderr) + print('Failed to download from {!r}, trying mirror...'.format(url), file=sys.stderr) + continue + else: + curdir = os.path.dirname(sys.argv[0]) + print('Couldn\'t download {!r}! Try downloading it manually and ' + 'placing it into {!r}'.format(dest, curdir), file=sys.stderr) + +def print_extract_dir(): + 'Print the extracted directory name' + print(extract_path, end='') + +if os.path.isfile(dest_path): + found_sha256 = get_sha256(dest_path) + if found_sha256 == tar_sha256: + if os.path.isdir(os.path.join(source_dir, extract_path)): + print('{} already downloaded and extracted'.format(dest), file=sys.stderr) + print_extract_dir() + sys.exit(0) + else: + print('{} checksum mismatch, redownloading'.format(dest), file=sys.stderr) + download() +else: + download() + +found_sha256 = get_sha256(dest_path) +if found_sha256 != tar_sha256: + print('SHA256 of downloaded file {} was {} instead of {}' + ''.format(dest, found_sha256, tar_sha256), file=sys.stderr) + sys.exit(1) + +print('Extracting {}'.format(dest), file=sys.stderr) +tf = tarfile.open(dest_path, "r") +tf.extractall(path=source_dir) +print_extract_dir() diff --git a/subprojects/macos-bison-binary/meson.build b/subprojects/macos-bison-binary/meson.build new file mode 100644 index 0000000..7a1680f --- /dev/null +++ b/subprojects/macos-bison-binary/meson.build @@ -0,0 +1,28 @@ +project('win-flex-bison-binary', version : '3.7.6') + +py3 = import('python3').find_python() + +message('Downloading and extracting bison for macOS x64...') + +arch = host_machine.cpu_family() +tar_hash = '932f91d7c7fa0121abc3e5f8e54a7234b03d3de468c254ab8063ff8e6eb92a09' +if arch != 'x86_64' + warning('bison binary is untested on non-x86_64, please report whether this worked or not') + arch = 'x86_64' +endif + +ret = run_command(py3, files('download-binary.py'), meson.project_version(), arch, tar_hash) +if ret.returncode() != 0 + message(ret.stdout()) + error(ret.stderr()) +endif + +conf = configuration_data() +conf.set('SRCDIR', meson.project_source_root()) +conf.set('EXTRACTDIR', ret.stdout()) +bison_py = configure_file( + input: 'bison.py.in', + output: 'bison.py', + configuration: conf) + +meson.override_find_program('bison', find_program(bison_py)) |