[gtk/wip/otte/build: 1/6] build: Set proper defaults for media backends




commit 30eb178a58b5807586a9ce939d0a1221a8427472
Author: Benjamin Otte <otte redhat com>
Date:   Thu Apr 1 17:59:18 2021 +0200

    build: Set proper defaults for media backends
    
    GTK supports webm playback, which means a backend should always be
    compiled.
    
    The ffmpeg backend however is incomplete (no audio) and as such, we
    don't want people to end up with it accidentally.
    
    Since we don't want to drag an entire gstreamer build into our ci
    on MacOs or msvc, explicitly disable the gstreame media backend there.

 .gitlab-ci.yml               |   7 ++
 .gitlab-ci/lineup-parameters | 211 +++++++++++++++++++++++++++++++++++++++++++
 meson_options.txt            |   8 +-
 3 files changed, 223 insertions(+), 3 deletions(-)
---
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index c100755896..1953c003fb 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -172,6 +172,7 @@ macos:
     - meson -Dx11-backend=false
             -Dbroadway-backend=true
             -Dmacos-backend=true
+            -Dmedia-gstreamer=disabled
             -Dintrospection=disabled
             -Dcpp_std=c++11
             -Dpixman:tests=disabled
@@ -192,6 +193,12 @@ vs2017-x64:
     - win32-ps
   needs: []
   script:
+    - meson -Dwin32-backend=true
+            -Dbroadway-backend=false
+            -Dmedia-gstreamer=disabled
+            -Dintrospection=disabled
+            _build
+    - ninja -C _build
     - .gitlab-ci/test-msvc.bat
   artifacts:
     when: always
diff --git a/.gitlab-ci/lineup-parameters b/.gitlab-ci/lineup-parameters
new file mode 100755
index 0000000000..c462917c1f
--- /dev/null
+++ b/.gitlab-ci/lineup-parameters
@@ -0,0 +1,211 @@
+#!/usr/bin/env python3
+#
+# Copyright © 2019 Michael Catanzaro <mcatanzaro gnome org>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program 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 General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# Based on original C lineup-parameters by Sébastien Wilmet <swilmet gnome org>
+# Rewritten in Python to allow simple execution from source directory.
+#
+# Usage: lineup-parameters [file]
+# If the file is not given, stdin is read.
+# The result is printed to stdout.
+#
+# The restrictions:
+# - The function name must be at column 0, followed by a space and an opening
+#   parenthesis;
+# - One parameter per line;
+# - A parameter must follow certain rules (see the regex in the code), but it
+#   doesn't accept all possibilities of the C language.
+# - The opening curly brace ("{") of the function must also be at column 0.
+#
+# If one restriction is missing, the function declaration is not modified.
+#
+# Example:
+#
+# gboolean
+# frobnitz (Frobnitz *frobnitz,
+#           gint magic_number,
+#           GError **error)
+# {
+#   ...
+# }
+#
+# Becomes:
+#
+# gboolean
+# frobnitz (Frobnitz  *frobnitz,
+#           gint       magic_number,
+#           GError   **error)
+# {
+#   ...
+# }
+#
+# TODO: support "..." vararg parameter
+
+import argparse
+import re
+import sys
+
+from typing import NamedTuple
+
+# https://regexr.com/ is your friend.
+functionNameRegex = re.compile(r'^(\w+) ?\(')
+parameterRegex = re.compile(
+    r'^\s*(?P<type>(const\s+)?\w+)'
+    r'\s+(?P<stars>\**)'
+    r'\s*(?P<name>\w+)'
+    r'\s*(?P<end>,|\))'
+    r'\s*$')
+openingCurlyBraceRegex = re.compile(r'^{\s*$')
+
+
+def matchFunctionName(line):
+    match = functionNameRegex.match(line)
+    if match:
+        functionName = match.group(1)
+        firstParamPosition = match.end(0)
+        return (functionName, firstParamPosition)
+    return (None, 0)
+
+
+class ParameterInfo(NamedTuple):
+    paramType: str
+    name: str
+    numStars: int
+    isLastParameter: bool
+
+
+def matchParameter(line):
+    _, firstParamPosition = matchFunctionName(line)
+    match = parameterRegex.match(line[firstParamPosition:])
+    if match is None:
+        return None
+    paramType = match.group('type')
+    assert(paramType is not None)
+    name = match.group('name')
+    assert(name is not None)
+    stars = match.group('stars')
+    numStars = len(stars) if stars is not None else 0
+    end = match.group('end')
+    isLastParameter = True if end is not None and end == ')' else False
+    return ParameterInfo(paramType, name, numStars, isLastParameter)
+
+
+def matchOpeningCurlyBrace(line):
+    return True if openingCurlyBraceRegex.match(line) is not None else False
+
+
+# Length returned is number of lines the declaration takes up
+def getFunctionDeclarationLength(remainingLines):
+    for i in range(len(remainingLines)):
+        currentLine = remainingLines[i]
+        parameterInfo = matchParameter(currentLine)
+        if parameterInfo is None:
+            return 0
+        if parameterInfo.isLastParameter:
+            if i + 1 == len(remainingLines):
+                return 0
+            nextLine = remainingLines[i + 1]
+            if not matchOpeningCurlyBrace(nextLine):
+                return 0
+            return i + 1
+    return 0
+
+
+def getParameterInfos(remainingLines, length):
+    parameterInfos = []
+    for i in range(length):
+        parameterInfos.append(matchParameter(remainingLines[i]))
+    return parameterInfos
+
+
+def computeSpacing(parameterInfos):
+    maxTypeLength = 0
+    maxStarsLength = 0
+    for parameterInfo in parameterInfos:
+        maxTypeLength = max(maxTypeLength, len(parameterInfo.paramType))
+        maxStarsLength = max(maxStarsLength, parameterInfo.numStars)
+    return (maxTypeLength, maxStarsLength)
+
+
+def printParameter(parameterInfo, maxTypeLength, maxStarsLength, outfile):
+    outfile.write(f'{parameterInfo.paramType:<{maxTypeLength + 1}}')
+    paramNamePaddedWithStars = f'{parameterInfo.name:*>{parameterInfo.numStars + len(parameterInfo.name)}}'
+    outfile.write(f'{paramNamePaddedWithStars:>{maxStarsLength + len(parameterInfo.name)}}')
+
+
+def printFunctionDeclaration(remainingLines, length, useTabs, outfile):
+    functionName, _ = matchFunctionName(remainingLines[0])
+    assert(functionName is not None)
+    outfile.write(f'{functionName} (')
+    numSpacesToParenthesis = len(functionName) + 2
+    whitespace = ''
+    if useTabs:
+        tabs = ''.ljust(numSpacesToParenthesis // 8, '\t')
+        spaces = ''.ljust(numSpacesToParenthesis % 8)
+        whitespace = tabs + spaces
+    else:
+        whitespace = ''.ljust(numSpacesToParenthesis)
+    parameterInfos = getParameterInfos(remainingLines, length)
+    maxTypeLength, maxStarsLength = computeSpacing(parameterInfos)
+    numParameters = len(parameterInfos)
+    for i in range(numParameters):
+        parameterInfo = parameterInfos[i]
+        if i != 0:
+            outfile.write(whitespace)
+        printParameter(parameterInfo, maxTypeLength, maxStarsLength, outfile)
+        if i + 1 != numParameters:
+            outfile.write(',\n')
+    outfile.write(')\n')
+
+
+def parseContents(infile, useTabs, outfile):
+    lines = infile.readlines()
+    i = 0
+    while i < len(lines):
+        line = lines[i]
+        functionName, _ = matchFunctionName(line)
+        if functionName is None:
+            outfile.write(line)
+            i += 1
+            continue
+        remainingLines = lines[i:]
+        length = getFunctionDeclarationLength(remainingLines)
+        if length == 0:
+            outfile.write(line)
+            i += 1
+            continue
+        printFunctionDeclaration(remainingLines, length, useTabs, outfile)
+        i += length
+
+
+if __name__ == "__main__":
+    parser = argparse.ArgumentParser(
+        description='Line up parameters of C functions')
+    parser.add_argument('infile', nargs='?',
+                        type=argparse.FileType('r'),
+                        default=sys.stdin,
+                        help='input C source file')
+    parser.add_argument('-o', metavar='outfile', nargs='?',
+                        type=argparse.FileType('w'),
+                        default=sys.stdout,
+                        help='where to output modified file')
+    parser.add_argument('--tabs', action='store_true',
+                        help='whether use tab characters in the output')
+    args = parser.parse_args()
+    parseContents(args.infile, args.tabs, args.o)
+    args.infile.close()
+    args.o.close()
+
diff --git a/meson_options.txt b/meson_options.txt
index 402caec5fb..2223cb7964 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -26,15 +26,17 @@ option('macos-backend',
        description : 'Enable the macOS gdk backend (only when building on macOS)')
 
 # Media backends
+# For distros: GTK guarantees support for WebM video (VP8 and VP9), so a supported build
+# should provide that.
 
 option('media-ffmpeg',
        type: 'feature',
-       value: 'auto',
-       description : 'Build the ffmpeg media backend')
+       value: 'disabled',
+       description : 'Build the experimental ffmpeg media backend')
 
 option('media-gstreamer',
        type: 'feature',
-       value: 'auto',
+       value: 'enabled',
        description : 'Build the gstreamer media backend')
 
 # Print backends


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]