File: grab-gio-dll-paths.py

package info (click to toggle)
glib2.0 2.86.0-5
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 73,060 kB
  • sloc: ansic: 544,382; python: 9,702; sh: 1,612; xml: 1,482; perl: 1,222; cpp: 535; makefile: 321; javascript: 11
file content (68 lines) | stat: -rw-r--r-- 2,157 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env python3
#
# Copyright © 2024 Chun-wei Fan.
#
# SPDX-License-Identifier: LGPL-2.1-or-later
#
# Original author: Chun-wei Fan <fanc999@yahoo.com.tw>

"""
This script runs pkg-config against the uninstalled pkg-config files to obtain the
paths where the newly-built GLib and subproject DLLs reside
"""

import argparse
import os
import subprocess


def main():
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument("--build-path", required=True, help="Root build directory")
    parser.add_argument(
        "--pkg-config", help="pkg-config or compatible executable", default="pkg-config"
    )
    parser.add_argument(
        "--pkg-config-path",
        help="Additional paths to look for pkg-config .pc files",
    )
    args = parser.parse_args()
    build_path = args.build_path
    uninstalled_pc_path = os.path.join(build_path, "meson-uninstalled")
    if not os.path.isdir(uninstalled_pc_path):
        raise ValueError("%s is not a valid build path" % build_path)

    additional_pkg_config_paths = [uninstalled_pc_path]
    if args.pkg_config_path is not None:
        additional_pkg_config_paths += args.pkg_config_path.split(os.pathsep)

    if "PKG_CONFIG_PATH" in os.environ:
        additional_pkg_config_paths += os.environ["PKG_CONFIG_PATH"].split(os.pathsep)

    os.environ["PKG_CONFIG_PATH"] = os.pathsep.join(additional_pkg_config_paths)

    # The _giscanner Python module depends on GIO, so use gio-2.0-uninstalled.pc
    pkg_config_result = subprocess.run(
        [args.pkg_config, "--libs-only-L", "gio-2.0"],
        capture_output=True,
        text=True,
        check=True,
    )
    lib_args = pkg_config_result.stdout.split()
    libpaths = []
    for arg in lib_args:
        # Get rid of the "-L" prefix in the library paths
        if arg[2:] not in libpaths:
            libpaths.append(arg[2:])

    # Now append the paths in %PATH%, if the paths exist
    paths = os.environ["PATH"].split(os.pathsep)
    for path in paths:
        if os.path.isdir(path):
            libpaths.append(path)

    print(os.pathsep.join(libpaths).rstrip())


if __name__ == "__main__":
    main()