summaryrefslogtreecommitdiff
path: root/subprojects/macos-bison-binary
diff options
context:
space:
mode:
authorNirbheek Chauhan <nirbheek@centricular.com>2023-08-30 16:26:07 +0530
committerGStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org>2023-09-07 21:36:15 +0000
commite07ea8abe35d839a400a3cd7f6e0aa053c53bad4 (patch)
tree54faa0bdec95ef59e5ffa2f846cdc55053fdd478 /subprojects/macos-bison-binary
parent7851f988861feaefa62b767092bc0ebb0f198fa6 (diff)
macos-bison: Update to 3.8.2 and add an ARM64 build
Also includes a shell script to build bison and match pycodestyle. Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/5299>
Diffstat (limited to 'subprojects/macos-bison-binary')
-rw-r--r--subprojects/macos-bison-binary/.gitignore2
-rw-r--r--subprojects/macos-bison-binary/README.md13
-rwxr-xr-xsubprojects/macos-bison-binary/bison.py.in14
-rwxr-xr-xsubprojects/macos-bison-binary/build-bison.sh38
-rw-r--r--subprojects/macos-bison-binary/download-binary.py4
-rw-r--r--subprojects/macos-bison-binary/meson.build25
6 files changed, 56 insertions, 40 deletions
diff --git a/subprojects/macos-bison-binary/.gitignore b/subprojects/macos-bison-binary/.gitignore
index adaad829c4..f96974bd63 100644
--- a/subprojects/macos-bison-binary/.gitignore
+++ b/subprojects/macos-bison-binary/.gitignore
@@ -1,4 +1,4 @@
*.sw[op]
*~
*.tar.*
-bison-3.7.6-macos-x86_64/
+bison-*/
diff --git a/subprojects/macos-bison-binary/README.md b/subprojects/macos-bison-binary/README.md
index 9b590d500f..dfab7424f5 100644
--- a/subprojects/macos-bison-binary/README.md
+++ b/subprojects/macos-bison-binary/README.md
@@ -1,14 +1,7 @@
## 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`
+* Update version in meson.build
+* Run ./build-bison.sh
+* Do this on arm64 and x86_64 machines
That's it!
diff --git a/subprojects/macos-bison-binary/bison.py.in b/subprojects/macos-bison-binary/bison.py.in
deleted file mode 100755
index 64807d0a93..0000000000
--- a/subprojects/macos-bison-binary/bison.py.in
+++ /dev/null
@@ -1,14 +0,0 @@
-#!/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/build-bison.sh b/subprojects/macos-bison-binary/build-bison.sh
new file mode 100755
index 0000000000..276fe275ea
--- /dev/null
+++ b/subprojects/macos-bison-binary/build-bison.sh
@@ -0,0 +1,38 @@
+#!/bin/bash
+
+set -e
+
+if ! [[ -e meson.build ]] || ! grep -q "^project('macos-bison-binary'" meson.build; then
+ echo "Could not find macos-bison-binary meson.build"
+ exit 1
+fi
+
+VER="$(sed -n "s/project.*version.*'\(.*\)'.*/\1/p" meson.build)"
+ARCH=$(uname -m)
+[[ $ARCH = arm64 ]] && ARCH="aarch64"
+SRCDIR="bison-$VER"
+SRC="$SRCDIR.tar.gz"
+OUTDIR="bison-$VER-macos-$ARCH"
+OUT="bison-$VER-macos-$ARCH.tar.bz2"
+
+if ! [[ -e $SRC ]]; then
+ curl -O -L https://ftp.gnu.org/gnu/bison/$SRC
+fi
+
+TARGETDIR="$PWD"
+
+rm -rf $SRCDIR
+tar -xf $SRC && cd $SRCDIR
+./configure --prefix="$TARGETDIR/_install/" --enable-relocatable
+make -j8
+make install
+
+cd "$TARGETDIR"
+rm -rf _install/share/{info,man,doc}
+strip -u -r _install/bin/bison
+
+rm -rf "$OUTDIR"
+mv _install "$OUTDIR"
+tar -cvf "$OUT" "$OUTDIR"/
+CHECKSUM=$(shasum -a 256 "$OUT" | awk '{print $1}')
+sed -I '' -e "s/ '$ARCH': '.*'/ '$ARCH': '$CHECKSUM'/g" meson.build
diff --git a/subprojects/macos-bison-binary/download-binary.py b/subprojects/macos-bison-binary/download-binary.py
index 460e5b00b3..49fd28e308 100644
--- a/subprojects/macos-bison-binary/download-binary.py
+++ b/subprojects/macos-bison-binary/download-binary.py
@@ -25,12 +25,14 @@ 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)
@@ -48,10 +50,12 @@ def download():
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:
diff --git a/subprojects/macos-bison-binary/meson.build b/subprojects/macos-bison-binary/meson.build
index f257d58c94..6adf64bbee 100644
--- a/subprojects/macos-bison-binary/meson.build
+++ b/subprojects/macos-bison-binary/meson.build
@@ -1,21 +1,16 @@
-project('win-flex-bison-binary', version : '3.7.6')
+project('macos-bison-binary', version : '3.8.2')
-py3 = import('python3').find_python()
+arch = host_machine.cpu_family()
-message('Downloading and extracting bison for macOS x64...')
+message('Downloading and extracting bison for macOS @0@...'.format(arch))
-arch = 'x86_64' # run under emulation on arm64
-tar_hash = '932f91d7c7fa0121abc3e5f8e54a7234b03d3de468c254ab8063ff8e6eb92a09'
+checksum = {
+ 'x86_64': '325e78de481fa044f0f2177d4da332a1b580bda23fdaf37e7918c5fd55240254',
+ 'aarch64': '932f9ec3da7a9f6c9f596094f889038340a45e84dc03082cb10ffee84b5d7af0',
+}
-ret = run_command(py3, files('download-binary.py'), meson.project_version(), arch, tar_hash,
+py3 = import('python3').find_python()
+ret = run_command(py3, files('download-binary.py'), meson.project_version(), arch, checksum[arch],
check: true)
-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))
+meson.override_find_program('bison', find_program(meson.project_source_root() / ret.stdout() / 'bin/bison'))