From 26a029d407be480d791972afb5975cf62c9360a6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 02:47:55 +0200 Subject: Adding upstream version 124.0.1. Signed-off-by: Daniel Baumann --- .../builds/meson/extract_freetype_version.py | 117 ++++++++++++++ .../builds/meson/extract_libtool_version.py | 115 +++++++++++++ .../builds/meson/generate_reference_docs.py | 89 +++++++++++ .../freetype2/builds/meson/parse_modules_cfg.py | 177 +++++++++++++++++++++ .../freetype2/builds/meson/process_ftoption_h.py | 115 +++++++++++++ 5 files changed, 613 insertions(+) create mode 100644 modules/freetype2/builds/meson/extract_freetype_version.py create mode 100644 modules/freetype2/builds/meson/extract_libtool_version.py create mode 100644 modules/freetype2/builds/meson/generate_reference_docs.py create mode 100644 modules/freetype2/builds/meson/parse_modules_cfg.py create mode 100644 modules/freetype2/builds/meson/process_ftoption_h.py (limited to 'modules/freetype2/builds/meson') diff --git a/modules/freetype2/builds/meson/extract_freetype_version.py b/modules/freetype2/builds/meson/extract_freetype_version.py new file mode 100644 index 0000000000..c4c60e7f1d --- /dev/null +++ b/modules/freetype2/builds/meson/extract_freetype_version.py @@ -0,0 +1,117 @@ +#!/usr/bin/env python3 +# +# Copyright (C) 2020-2023 by +# David Turner, Robert Wilhelm, and Werner Lemberg. +# +# This file is part of the FreeType project, and may only be used, modified, +# and distributed under the terms of the FreeType project license, +# LICENSE.TXT. By continuing to use, modify, or distribute this file you +# indicate that you have read the license and understand and accept it +# fully. + +"""Extract the FreeType version numbers from ``. + +This script parses the header to extract the version number defined there. +By default, the full dotted version number is printed, but `--major`, +`--minor` or `--patch` can be used to only print one of these values +instead. +""" + +from __future__ import print_function + +import argparse +import os +import re +import sys + +# Expected input: +# +# ... +# #define FREETYPE_MAJOR 2 +# #define FREETYPE_MINOR 10 +# #define FREETYPE_PATCH 2 +# ... + +RE_MAJOR = re.compile(r"^ \#define \s+ FREETYPE_MAJOR \s+ (.*) $", re.X) +RE_MINOR = re.compile(r"^ \#define \s+ FREETYPE_MINOR \s+ (.*) $", re.X) +RE_PATCH = re.compile(r"^ \#define \s+ FREETYPE_PATCH \s+ (.*) $", re.X) + + +def parse_freetype_header(header): + major = None + minor = None + patch = None + + for line in header.splitlines(): + line = line.rstrip() + m = RE_MAJOR.match(line) + if m: + assert major == None, "FREETYPE_MAJOR appears more than once!" + major = m.group(1) + continue + + m = RE_MINOR.match(line) + if m: + assert minor == None, "FREETYPE_MINOR appears more than once!" + minor = m.group(1) + continue + + m = RE_PATCH.match(line) + if m: + assert patch == None, "FREETYPE_PATCH appears more than once!" + patch = m.group(1) + continue + + assert ( + major and minor and patch + ), "This header is missing one of FREETYPE_MAJOR, FREETYPE_MINOR or FREETYPE_PATCH!" + + return (major, minor, patch) + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + + group = parser.add_mutually_exclusive_group() + group.add_argument( + "--major", + action="store_true", + help="Only print the major version number.", + ) + group.add_argument( + "--minor", + action="store_true", + help="Only print the minor version number.", + ) + group.add_argument( + "--patch", + action="store_true", + help="Only print the patch version number.", + ) + + parser.add_argument( + "input", + metavar="FREETYPE_H", + help="The input freetype.h header to parse.", + ) + + args = parser.parse_args() + with open(args.input) as f: + header = f.read() + + version = parse_freetype_header(header) + + if args.major: + print(version[0]) + elif args.minor: + print(version[1]) + elif args.patch: + print(version[2]) + else: + print("%s.%s.%s" % version) + + return 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/modules/freetype2/builds/meson/extract_libtool_version.py b/modules/freetype2/builds/meson/extract_libtool_version.py new file mode 100644 index 0000000000..6fac74c8ed --- /dev/null +++ b/modules/freetype2/builds/meson/extract_libtool_version.py @@ -0,0 +1,115 @@ +#!/usr/bin/env python3 +# +# Copyright (C) 2020-2023 by +# David Turner, Robert Wilhelm, and Werner Lemberg. +# +# This file is part of the FreeType project, and may only be used, modified, +# and distributed under the terms of the FreeType project license, +# LICENSE.TXT. By continuing to use, modify, or distribute this file you +# indicate that you have read the license and understand and accept it +# fully. + +"""Extract the libtool version from `configure.raw`. + +This script parses the `configure.raw` file to extract the libtool version +number. By default, the full dotted version number is printed, but +`--major`, `--minor` or `--patch` can be used to only print one of these +values instead. +""" + +from __future__ import print_function + +import argparse +import os +import re +import sys + +# Expected input: +# +# ... +# version_info='23:2:17' +# ... + +RE_VERSION_INFO = re.compile(r"^version_info='(\d+):(\d+):(\d+)'") + + +def parse_configure_raw(header): + major = None + minor = None + patch = None + + for line in header.splitlines(): + line = line.rstrip() + m = RE_VERSION_INFO.match(line) + if m: + assert major == None, "version_info appears more than once!" + major = m.group(1) + minor = m.group(2) + patch = m.group(3) + continue + + assert ( + major and minor and patch + ), "This input file is missing a version_info definition!" + + return (major, minor, patch) + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + + group = parser.add_mutually_exclusive_group() + group.add_argument( + "--major", + action="store_true", + help="Only print the major version number.", + ) + group.add_argument( + "--minor", + action="store_true", + help="Only print the minor version number.", + ) + group.add_argument( + "--patch", + action="store_true", + help="Only print the patch version number.", + ) + group.add_argument( + "--soversion", + action="store_true", + help="Only print the libtool library suffix.", + ) + + parser.add_argument( + "input", + metavar="CONFIGURE_RAW", + help="The input configure.raw file to parse.", + ) + + args = parser.parse_args() + with open(args.input) as f: + raw_file = f.read() + + version = parse_configure_raw(raw_file) + + if args.major: + print(version[0]) + elif args.minor: + print(version[1]) + elif args.patch: + print(version[2]) + elif args.soversion: + # Convert libtool version_info to the library suffix. + # (current,revision, age) -> (current - age, age, revision) + print( + "%d.%s.%s" + % (int(version[0]) - int(version[2]), version[2], version[1]) + ) + else: + print("%s.%s.%s" % version) + + return 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/modules/freetype2/builds/meson/generate_reference_docs.py b/modules/freetype2/builds/meson/generate_reference_docs.py new file mode 100644 index 0000000000..4208bb6771 --- /dev/null +++ b/modules/freetype2/builds/meson/generate_reference_docs.py @@ -0,0 +1,89 @@ +#!/usr/bin/env python3 +# +# Copyright (C) 2020-2023 by +# David Turner, Robert Wilhelm, and Werner Lemberg. +# +# This file is part of the FreeType project, and may only be used, modified, +# and distributed under the terms of the FreeType project license, +# LICENSE.TXT. By continuing to use, modify, or distribute this file you +# indicate that you have read the license and understand and accept it +# fully. + +"""Generate FreeType reference documentation.""" + +from __future__ import print_function + +import argparse +import glob +import os +import subprocess +import sys + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + + parser.add_argument( + "--input-dir", + required=True, + help="Top-level FreeType source directory.", + ) + + parser.add_argument( + "--version", required=True, help='FreeType version (e.g. "2.x.y").' + ) + + parser.add_argument( + "--output-dir", required=True, help="Output directory." + ) + + args = parser.parse_args() + + # Get the list of input files of interest. + include_dir = os.path.join(args.input_dir, "include") + include_config_dir = os.path.join(include_dir, "config") + include_cache_dir = os.path.join(include_dir, "cache") + + all_headers = ( + glob.glob(os.path.join(args.input_dir, "include", "freetype", "*.h")) + + glob.glob( + os.path.join( + args.input_dir, "include", "freetype", "config", "*.h" + ) + ) + + glob.glob( + os.path.join( + args.input_dir, "include", "freetype", "cache", "*.h" + ) + ) + ) + + if not os.path.exists(args.output_dir): + os.makedirs(args.output_dir) + else: + assert os.path.isdir(args.output_dir), ( + "Not a directory: " + args.output_dir + ) + + cmds = [ + sys.executable, + "-m", + "docwriter", + "--prefix=ft2", + "--title=FreeType-" + args.version, + "--site=reference", + "--output=" + args.output_dir, + ] + all_headers + + print("Running docwriter...") + subprocess.check_call(cmds) + + print("Building static site...") + subprocess.check_call( + [sys.executable, "-m", "mkdocs", "build"], cwd=args.output_dir + ) + return 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/modules/freetype2/builds/meson/parse_modules_cfg.py b/modules/freetype2/builds/meson/parse_modules_cfg.py new file mode 100644 index 0000000000..d48129fe72 --- /dev/null +++ b/modules/freetype2/builds/meson/parse_modules_cfg.py @@ -0,0 +1,177 @@ +#!/usr/bin/env python3 +# +# Copyright (C) 2020-2023 by +# David Turner, Robert Wilhelm, and Werner Lemberg. +# +# This file is part of the FreeType project, and may only be used, modified, +# and distributed under the terms of the FreeType project license, +# LICENSE.TXT. By continuing to use, modify, or distribute this file you +# indicate that you have read the license and understand and accept it +# fully. + +"""Parse modules.cfg and dump its output either as ftmodule.h or a list of +base extensions. +""" + +from __future__ import print_function + +import argparse +import os +import re +import sys + +# Expected input: +# +# ... +# FONT_MODULES += +# HINTING_MODULES += +# RASTER_MODULES += +# AUX_MODULES += +# BASE_EXTENSIONS += +# ... + + +def parse_modules_cfg(input_file): + + lists = { + "FONT_MODULES": [], + "HINTING_MODULES": [], + "RASTER_MODULES": [], + "AUX_MODULES": [], + "BASE_EXTENSIONS": [], + } + + for line in input_file.splitlines(): + line = line.rstrip() + # Ignore empty lines and those that start with a comment. + if not line or line[0] == "#": + continue + + items = line.split() + assert len(items) == 3 and items[1] == "+=", ( + "Unexpected input line [%s]" % line + ) + assert items[0] in lists, ( + "Unexpected configuration variable name " + items[0] + ) + + lists[items[0]].append(items[2]) + + return lists + + +def generate_ftmodule(lists): + result = "/* This is a generated file. */\n" + for driver in lists["FONT_MODULES"]: + if driver == "sfnt": # Special case for the sfnt 'driver'. + result += "FT_USE_MODULE( FT_Module_Class, sfnt_module_class )\n" + continue + + name = { + "truetype": "tt", + "type1": "t1", + "cid": "t1cid", + "type42": "t42", + "winfonts": "winfnt", + }.get(driver, driver) + result += ( + "FT_USE_MODULE( FT_Driver_ClassRec, %s_driver_class )\n" % name + ) + + for module in lists["HINTING_MODULES"]: + result += ( + "FT_USE_MODULE( FT_Module_Class, %s_module_class )\n" % module + ) + + for module in lists["RASTER_MODULES"]: + names = { + "raster": ("ft_raster1",), + "smooth": ("ft_smooth",), + "svg": ("ft_svg",), + "sdf": ("ft_sdf", "ft_bitmap_sdf"), + }.get(module) + for name in names: + result += ( + "FT_USE_MODULE( FT_Renderer_Class, %s_renderer_class )\n" % name + ) + + for module in lists["AUX_MODULES"]: + if module in ("psaux", "psnames", "otvalid", "gxvalid"): + name = { + "gxvalid": "gxv", + "otvalid": "otv", + }.get(module, module) + result += ( + "FT_USE_MODULE( FT_Module_Class, %s_module_class )\n" % name + ) + + result += "/* EOF */\n" + return result + + +def generate_main_modules(lists): + return "\n".join( + lists["FONT_MODULES"] + + lists["HINTING_MODULES"] + + lists["RASTER_MODULES"] + ) + + +def generate_aux_modules(lists): + return "\n".join(lists["AUX_MODULES"]) + + +def generate_base_extensions(lists): + return "\n".join(lists["BASE_EXTENSIONS"]) + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + + parser.add_argument( + "--format", + required=True, + choices=( + "ftmodule.h", + "main-modules", + "aux-modules", + "base-extensions-list", + ), + help="Select output format.", + ) + + parser.add_argument( + "input", + metavar="CONFIGURE_RAW", + help="The input configure.raw file to parse.", + ) + + parser.add_argument("--output", help="Output file (default is stdout).") + + args = parser.parse_args() + with open(args.input) as f: + input_data = f.read() + + lists = parse_modules_cfg(input_data) + + if args.format == "ftmodule.h": + result = generate_ftmodule(lists) + elif args.format == "main-modules": + result = generate_main_modules(lists) + elif args.format == "aux-modules": + result = generate_aux_modules(lists) + elif args.format == "base-extensions-list": + result = generate_base_extensions(lists) + else: + assert False, "Invalid output format!" + + if args.output: + with open(args.output, "w") as f: + f.write(result) + else: + print(result) + return 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/modules/freetype2/builds/meson/process_ftoption_h.py b/modules/freetype2/builds/meson/process_ftoption_h.py new file mode 100644 index 0000000000..98daa8c1e2 --- /dev/null +++ b/modules/freetype2/builds/meson/process_ftoption_h.py @@ -0,0 +1,115 @@ +#!/usr/bin/env python3 +# +# Copyright (C) 2020-2023 by +# David Turner, Robert Wilhelm, and Werner Lemberg. +# +# This file is part of the FreeType project, and may only be used, modified, +# and distributed under the terms of the FreeType project license, +# LICENSE.TXT. By continuing to use, modify, or distribute this file you +# indicate that you have read the license and understand and accept it +# fully. + +"""Toggle settings in `ftoption.h` file based on command-line arguments. + +This script takes an `ftoption.h` file as input and rewrites +`#define`/`#undef` lines in it based on `--enable=CONFIG_VARNAME` or +`--disable=CONFIG_VARNAME` arguments passed to it, where `CONFIG_VARNAME` is +configuration variable name, such as `FT_CONFIG_OPTION_USE_LZW`, that may +appear in the file. + +Note that if one of `CONFIG_VARNAME` is not found in the input file, this +script exits with an error message listing the missing variable names. +""" + +import argparse +import os +import re +import sys + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + + parser.add_argument( + "input", metavar="FTOPTION_H", help="Path to input ftoption.h file." + ) + + parser.add_argument("--output", help="Output to file instead of stdout.") + + parser.add_argument( + "--enable", + action="append", + default=[], + help="Enable a given build option (e.g. FT_CONFIG_OPTION_USE_LZW).", + ) + + parser.add_argument( + "--disable", + action="append", + default=[], + help="Disable a given build option.", + ) + + args = parser.parse_args() + + common_options = set(args.enable) & set(args.disable) + if common_options: + parser.error( + "Options cannot be both enabled and disabled: %s" + % sorted(common_options) + ) + return 1 + + with open(args.input) as f: + input_file = f.read() + + options_seen = set() + + new_lines = [] + for line in input_file.splitlines(): + # Expected formats: + # #define + # /* #define */ + # #undef + line = line.rstrip() + if line.startswith("/* #define ") and line.endswith(" */"): + option_name = line[11:-3].strip() + option_enabled = False + elif line.startswith("#define "): + option_name = line[8:].strip() + option_enabled = True + elif line.startswith("#undef "): + option_name = line[7:].strip() + option_enabled = False + else: + new_lines.append(line) + continue + + options_seen.add(option_name) + if option_enabled and option_name in args.disable: + line = "#undef " + option_name + elif not option_enabled and option_name in args.enable: + line = "#define " + option_name + new_lines.append(line) + + result = "\n".join(new_lines) + "\n" + + # Sanity check that all command-line options were actually processed. + cmdline_options = set(args.enable) | set(args.disable) + assert cmdline_options.issubset( + options_seen + ), "Could not find options in input file: " + ", ".join( + sorted(cmdline_options - options_seen) + ) + + if args.output: + with open(args.output, "w") as f: + f.write(result) + else: + print(result) + + return 0 + + +if __name__ == "__main__": + sys.exit(main()) -- cgit v1.2.3