meson: fix up wrong escaping of variables in gl and plugins-base .pc file
authorTim-Philipp Müller <tim@centricular.com>
Sun, 16 May 2021 23:33:44 +0000 (00:33 +0100)
committerGStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Mon, 17 May 2021 14:49:38 +0000 (14:49 +0000)
Workaround for pkg.generate() escaping spaces in pc variables
that shouldn't be escaped. Perhaps going back to configure_file()
would be a better option though. Really needs a fix in Meson.

Fixes https://gitlab.freedesktop.org/gstreamer/gst-plugins-base/-/issues/884

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-base/-/merge_requests/1150>

gst-libs/gst/gl/meson.build
meson.build
scripts/meson-pkg-config-file-fixup.py [new file with mode: 0755]

index 05ea91b..7694883 100644 (file)
@@ -1058,6 +1058,11 @@ if build_gstgl
     description : 'Streaming media framework, OpenGL plugins libraries',
   )
 
+  # Desperate times, desperate measures... fix up escaping of our variables
+  run_command(meson_pkg_config_file_fixup_script,
+    'gstreamer-gl-1.0', 'gl_platforms', 'gl_winsys', 'gl_apis',
+    check: true)
+
   pkgconfig.generate(
     libraries : [gstgl, gl_lib_deps],
     subdirs : pkgconfig_subdirs,
index db64239..5977377 100644 (file)
@@ -447,6 +447,8 @@ pkgconfig_variables = ['exec_prefix=${prefix}',
     'libexecdir=${prefix}/libexec']
 pkgconfig_subdirs = ['gstreamer-1.0']
 
+meson_pkg_config_file_fixup_script = find_program('scripts/meson-pkg-config-file-fixup.py')
+
 python3 = import('python').find_installation()
 subdir('gst-libs')
 subdir('gst')
@@ -483,6 +485,11 @@ pkgconfig.generate(
   description : 'Streaming media framework, base plugins libraries',
 )
 
+# Desperate times, desperate measures... fix up escaping of our variables
+run_command(meson_pkg_config_file_fixup_script,
+  'gstreamer-plugins-base-1.0', 'libraries',
+  check: true)
+
 if have_orcc
   update_orc_dist_files = find_program('scripts/update-orc-dist-files.py')
 
diff --git a/scripts/meson-pkg-config-file-fixup.py b/scripts/meson-pkg-config-file-fixup.py
new file mode 100755 (executable)
index 0000000..ef92d89
--- /dev/null
@@ -0,0 +1,55 @@
+#!/usr/bin/env python3
+#
+# meson-pkg-config-file-fixup.py PC_FILE VAR1,VAR2,VAR3
+#
+# Fix up escaping of custom variables in meson-generated .pc file
+#
+# Copyright (C) 2021 Tim-Philipp Müller <tim centricular com>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Library General Public
+# License as published by the Free Software Foundation; either
+# version 2 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Library General Public License for more details.
+#
+# You should have received a copy of the GNU Library General Public
+# License along with this library; if not, write to the
+# Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+# Boston, MA 02110-1301, USA.
+
+import os
+import sys
+
+if len(sys.argv) < 3:
+  sys.exit('Usage: {} PC_FILE_BASE_NAME VAR1 [VAR2 [VAR3 ..]]'.format(sys.argv[0]))
+
+pc_name = sys.argv[1]
+pc_vars = sys.argv[2:]
+
+build_root = os.environ['MESON_BUILD_ROOT']
+
+# Poking into the private dir is not entirely kosher of course..
+pc_files = [
+  os.path.join(build_root, 'meson-private', pc_name + '.pc'),
+  os.path.join(build_root, 'meson-uninstalled', pc_name + '-uninstalled.pc')
+]
+
+for pc_file in pc_files:
+  out_lines = ''
+
+  with open(pc_file, 'r') as f:
+    for line in f:
+      r = line.strip().split('=', 1)
+      if len(r) == 2 and r[0] in pc_vars:
+        out_lines += '{}={}\n'.format(r[0], r[1].replace('\\ ', ' '))
+      else:
+        out_lines += line
+
+  with open(pc_file, 'w') as f_new:
+      f_new.write(out_lines)
+
+sys.exit(0)