From c7edaf9b7e0c66c30e262b6b236fbd9eb285967a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20Draszik?= Date: Mon, 2 Mar 2020 12:17:35 +0000 Subject: [PATCH] [PATCH] build: allow use of system-installed brotli MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit brotli is available as a shared library since 2016, so it makes sense to allow its use as a system-installed version. Some of the infrastructure was in place already (node.gyp and node.gypi), but some bits in the configure script here were missing. Add them, keeping the default as before, to use the bundled version. Refs: https://github.com/google/brotli/pull/421 Signed-off-by: André Draszik PR-URL: https://github.com/nodejs/node/pull/32046 Reviewed-By: Anna Henningsen Reviewed-By: James M Snell Reviewed-By: Michael Dawson Reviewed-By: Ben Noordhuis Reviewed-By: Richard Lau Gbp-Pq: Name system-brotli.patch --- configure.py | 43 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 37 insertions(+), 6 deletions(-) diff --git a/configure.py b/configure.py index 22861a10e..5a786142f 100755 --- a/configure.py +++ b/configure.py @@ -289,6 +289,27 @@ shared_optgroup.add_option('--shared-zlib-libpath', dest='shared_zlib_libpath', help='a directory to search for the shared zlib DLL') +shared_optgroup.add_option('--shared-brotli', + action='store_true', + dest='shared_brotli', + help='link to a shared brotli DLL instead of static linking') + +shared_optgroup.add_option('--shared-brotli-includes', + action='store', + dest='shared_brotli_includes', + help='directory containing brotli header files') + +shared_optgroup.add_option('--shared-brotli-libname', + action='store', + dest='shared_brotli_libname', + default='brotlidec,brotlienc', + help='alternative lib name to link to [default: %default]') + +shared_optgroup.add_option('--shared-brotli-libpath', + action='store', + dest='shared_brotli_libpath', + help='a directory to search for the shared brotli DLL') + shared_optgroup.add_option('--shared-cares', action='store_true', dest='shared_libcares', @@ -621,24 +642,32 @@ def b(value): else: return 'false' +def to_utf8(s): + return s if isinstance(s, str) else s.decode("utf-8") def pkg_config(pkg): """Run pkg-config on the specified package Returns ("-l flags", "-I flags", "-L flags", "version") otherwise (None, None, None, None)""" pkg_config = os.environ.get('PKG_CONFIG', 'pkg-config') + args = [] # Print pkg-config warnings on first round. retval = () for flag in ['--libs-only-l', '--cflags-only-I', '--libs-only-L', '--modversion']: + args += [flag] + if isinstance(pkg, list): + args += pkg + else: + args += [pkg] try: - proc = subprocess.Popen( - shlex.split(pkg_config) + ['--silence-errors', flag, pkg], - stdout=subprocess.PIPE) - val = proc.communicate()[0].strip() + proc = subprocess.Popen(shlex.split(pkg_config) + args, + stdout=subprocess.PIPE) + val = to_utf8(proc.communicate()[0]).strip() except OSError as e: if e.errno != errno.ENOENT: raise e # Unexpected error. return (None, None, None, None) # No pkg-config/pkgconf installed. retval += (val,) + args = ['--silence-errors'] return retval @@ -1125,12 +1154,13 @@ def configure_node(o): else: o['variables']['node_target_type'] = 'executable' -def configure_library(lib, output): +def configure_library(lib, output, pkgname=None): shared_lib = 'shared_' + lib output['variables']['node_' + shared_lib] = b(getattr(options, shared_lib)) if getattr(options, shared_lib): - (pkg_libs, pkg_cflags, pkg_libpath, pkg_modversion) = pkg_config(lib) + (pkg_libs, pkg_cflags, pkg_libpath, pkg_modversion) = ( + pkg_config(pkgname or lib)) if options.__dict__[shared_lib + '_includes']: output['include_dirs'] += [options.__dict__[shared_lib + '_includes']] @@ -1600,6 +1630,7 @@ configure_node(output) configure_library('zlib', output) configure_library('http_parser', output) configure_library('libuv', output) +configure_library('brotli', output, pkgname=['libbrotlidec', 'libbrotlienc']) configure_library('libcares', output) configure_library('nghttp2', output) # stay backwards compatible with shared cares builds -- 2.30.2