From 85e49c19d40f963af83b12795dea4b14e65ab950 Mon Sep 17 00:00:00 2001 From: Nirbheek Chauhan Date: Thu, 17 May 2018 13:55:43 +0530 Subject: [PATCH] Add a new subproject 'win-flex-bison-binaries' This subproject will download and provide win32 binaries for flex and/or bison if they aren't found at configure time on Windows. --- meson.build | 8 +++ .../win-flex-bison-binaries/.gitignore | 9 ++++ .../download-binary.py | 50 +++++++++++++++++++ .../win-flex-bison-binaries/meson.build | 25 ++++++++++ 4 files changed, 92 insertions(+) create mode 100644 subprojects/win-flex-bison-binaries/.gitignore create mode 100644 subprojects/win-flex-bison-binaries/download-binary.py create mode 100644 subprojects/win-flex-bison-binaries/meson.build diff --git a/meson.build b/meson.build index 5c423cb7cd..9134abff02 100644 --- a/meson.build +++ b/meson.build @@ -14,6 +14,7 @@ subprojects = [ 'gst-plugins-good', ] +build_system = build_machine.system() cc = meson.get_compiler('c') # Make it possible to use msys2 built zlib which fails @@ -130,6 +131,13 @@ foreach custom_subproj: get_option('custom_subprojects').split(',') endif endforeach +# On Windows, if flex/bison aren't found, we use a subproject to get them +flex = find_program('flex', 'win_flex', required : build_system != 'windows') +bison = find_program('bison', 'win_bison', required : build_system != 'windows') +if not flex.found() or not bison.found() + subproject('win-flex-bison-binaries') +endif + message('Building subprojects: ' + ', '.join(subprojects)) foreach subproj: subprojects subproject(subproj, version: gst_version) diff --git a/subprojects/win-flex-bison-binaries/.gitignore b/subprojects/win-flex-bison-binaries/.gitignore new file mode 100644 index 0000000000..dd180b4d63 --- /dev/null +++ b/subprojects/win-flex-bison-binaries/.gitignore @@ -0,0 +1,9 @@ +*.sw[op] +*~ +custom_build_rules +data/ +FlexLexer.h +README.txt +UNISTD_ERROR.readme +*.exe +*.zip diff --git a/subprojects/win-flex-bison-binaries/download-binary.py b/subprojects/win-flex-bison-binaries/download-binary.py new file mode 100644 index 0000000000..16f69c95f1 --- /dev/null +++ b/subprojects/win-flex-bison-binaries/download-binary.py @@ -0,0 +1,50 @@ +#!/usr/bin/env python3 + +import os +import sys +import ssl +import zipfile +import hashlib +import urllib.request + +# Disable certificate checking because it always fails on Windows +# We verify the checksum anyway. +ctx = ssl.create_default_context() +ctx.check_hostname = False +ctx.verify_mode = ssl.CERT_NONE + +base_url = 'https://sourceforge.net/projects/winflexbison/files/win_flex_bison-{}.zip' +url = base_url.format(sys.argv[1]) +zip_sha256 = sys.argv[2] +source_dir = os.path.join(os.environ['MESON_SOURCE_ROOT'], os.environ['MESON_SUBDIR']) +dest = os.path.basename(url) +dest_path = os.path.join(source_dir, dest) + +def get_sha256(zipf): + hasher = hashlib.sha256() + with open(zipf, 'rb') as f: + hasher.update(f.read()) + return hasher.hexdigest() + +if os.path.isfile(dest_path): + found_sha256 = get_sha256(dest_path) + if found_sha256 == zip_sha256: + print('{} already downloaded'.format(dest)) + sys.exit(0) + else: + print('{} checksum mismatch, redownloading'.format(dest)) + +print('Downloading {} to {}'.format(url, dest)) +with open(dest_path, 'wb') as d: + f = urllib.request.urlopen(url, context=ctx) + d.write(f.read()) + +found_sha256 = get_sha256(dest_path) +if found_sha256 != zip_sha256: + print('SHA256 of downloaded file {} was {} instead of {}' + ''.format(dest, found_sha256, zip_sha256)) + sys.exit(1) + +print('Extracting {}'.format(dest)) +zf = zipfile.ZipFile(dest_path, "r") +zf.extractall(path=source_dir) diff --git a/subprojects/win-flex-bison-binaries/meson.build b/subprojects/win-flex-bison-binaries/meson.build new file mode 100644 index 0000000000..e56fea73c6 --- /dev/null +++ b/subprojects/win-flex-bison-binaries/meson.build @@ -0,0 +1,25 @@ +project('win-flex-bison-binary', version : '2.5.14') + +provide_flex = not find_program('flex', required : false).found() +provide_bison = not find_program('bison', required : false).found() + +if provide_flex or provide_bison + py3 = import('python3').find_python() + + message('Downloading and extracting win-flex-bison binaries...') + + zip_hash = '354c9aae02aca421c52abfda7fe3ce6c32ad07e25ff3f66e31da9437a0b906cf' + + ret = run_command(py3, files('download-binary.py'), meson.project_version(), zip_hash) + if ret.returncode() != 0 + message(ret.stdout()) + error(ret.stderr()) + endif + + if provide_flex + meson.override_find_program('flex', find_program('win_flex')) + endif + if provide_bison + meson.override_find_program('bison', find_program('win_bison')) + endif +endif