1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3
4 # Copyright (C) 2018 Collabora Inc.
5 #
6 # SPDX-License-Identifier: LGPL-2.1-or-later
7 #
8 # This library is free software; you can redistribute it and/or
9 # modify it under the terms of the GNU Lesser General Public
10 # License as published by the Free Software Foundation; either
11 # version 2.1 of the License, or (at your option) any later version.
12 #
13 # This library is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 # Lesser General Public License for more details.
17 #
18 # You should have received a copy of the GNU Lesser General
19 # Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
20 #
21 # Author: Xavier Claessens <xavier.claessens@collabora.com>
22
23 import os
24 import sys
25 import tempfile
26 import subprocess
27
28 if "GLIB_TEST_COMPILATION" not in os.environ:
29 print(
30 """Test disabled because GLIB_TEST_COMPILATION is not set in the env.
31 If you wish to run this test, set GLIB_TEST_COMPILATION=1 in the env,
32 and make sure you have glib build dependencies installed, including
33 meson."""
34 )
35 sys.exit(77)
36
37 if len(sys.argv) != 2:
38 print("Usage: {} <gio-2.0.pc dir>".format(os.path.basename(sys.argv[0])))
39 sys.exit(1)
40
41 test_dir = os.path.dirname(sys.argv[0])
42
43 with tempfile.TemporaryDirectory() as builddir:
44 env = os.environ.copy()
45 env["PKG_CONFIG_PATH"] = sys.argv[1]
46 sourcedir = os.path.join(test_dir, "static-link")
47
48 # Ensure we can static link and run a test app
49 subprocess.check_call(["meson", sourcedir, builddir], env=env)
50 subprocess.check_call(["ninja", "-C", builddir, "test"], env=env)
51 # FIXME: This probably only works on Linux
52 out = subprocess.check_output(
53 ["ldd", os.path.join(builddir, "test-static-link")], env=env
54 ).decode()
55 if "libgio" in out:
56 print("test-static-link is dynamically linked on libgio")
57 exit(1)