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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
|
From 0a008a6c7ecee19f35c8b7ab17b1470d0d1a8a15 Mon Sep 17 00:00:00 2001
From: Jan Tojnar <jtojnar@gmail.com>
Date: Sat, 26 Mar 2022 02:26:27 +0100
Subject: [PATCH] gnome: Fix gtkdoc when using multiple Apple frameworks
The `-framework Foundation -framework CoreFoundation` ended up
de-duplicated by OrderedSet into `-framework Foundation CoreFoundation`.
Picked from https://github.com/mesonbuild/meson/pull/10186
Also pick https://github.com/mesonbuild/meson/commit/68e684d51f1e469e0d9f4b499ffda15146cad98a when resolving conflict.
diff --git a/mesonbuild/modules/gnome.py b/mesonbuild/modules/gnome.py
index 7113f28d2..d3269b53f 100644
--- a/mesonbuild/modules/gnome.py
+++ b/mesonbuild/modules/gnome.py
@@ -384,13 +384,14 @@ class GnomeModule(ExtensionModule):
def _get_link_args(self, state, lib, depends, include_rpath=False,
use_gir_args=False):
link_command = []
+ new_depends = list(depends)
# Construct link args
if isinstance(lib, build.SharedLibrary):
libdir = os.path.join(state.environment.get_build_dir(), state.backend.get_target_dir(lib))
link_command.append('-L' + libdir)
if include_rpath:
link_command.append('-Wl,-rpath,' + libdir)
- depends.append(lib)
+ new_depends.append(lib)
# Needed for the following binutils bug:
# https://github.com/mesonbuild/meson/issues/1911
# However, g-ir-scanner does not understand -Wl,-rpath
@@ -404,18 +405,24 @@ class GnomeModule(ExtensionModule):
link_command.append('--extra-library=' + lib.name)
else:
link_command.append('-l' + lib.name)
- return link_command
-
- def _get_dependencies_flags(self, deps, state, depends, include_rpath=False,
- use_gir_args=False, separate_nodedup=False):
- cflags = OrderedSet()
- internal_ldflags = OrderedSet()
- external_ldflags = OrderedSet()
+ return link_command, new_depends
+
+ def _get_dependencies_flags_raw(
+ self, deps,
+ state,
+ depends,
+ include_rpath: bool = False,
+ use_gir_args: bool = False,
+ ) -> T.Tuple[OrderedSet[str], OrderedSet[T.Union[str, T.Tuple[str, str]]], OrderedSet[T.Union[str, T.Tuple[str, str]]], OrderedSet[str],
+ T.List]:
+ cflags: OrderedSet[str] = OrderedSet()
# External linker flags that can't be de-duped reliably because they
- # require two args in order, such as -framework AVFoundation
- external_ldflags_nodedup = []
- gi_includes = OrderedSet()
+ # require two args in order, such as -framework AVFoundation will be stored as a tuple.
+ internal_ldflags: OrderedSet[T.Union[str, T.Tuple[str, str]]] = OrderedSet()
+ external_ldflags: OrderedSet[T.Union[str, T.Tuple[str, str]]] = OrderedSet()
+ gi_includes: OrderedSet[str] = OrderedSet()
deps = mesonlib.listify(deps)
+ depends = list(depends)
for dep in deps:
if isinstance(dep, Dependency):
@@ -427,21 +434,20 @@ class GnomeModule(ExtensionModule):
cflags.update(state.get_include_args(dep.include_directories))
for lib in dep.libraries:
if isinstance(lib, build.SharedLibrary):
- internal_ldflags.update(self._get_link_args(state, lib, depends, include_rpath))
- libdepflags = self._get_dependencies_flags(lib.get_external_deps(), state, depends, include_rpath,
- use_gir_args, True)
+ _ld, depends = self._get_link_args(state, lib, depends, include_rpath)
+ internal_ldflags.update(_ld)
+ libdepflags = self._get_dependencies_flags_raw(lib.get_external_deps(), state, depends, include_rpath,
+ use_gir_args)
cflags.update(libdepflags[0])
internal_ldflags.update(libdepflags[1])
external_ldflags.update(libdepflags[2])
- external_ldflags_nodedup += libdepflags[3]
- gi_includes.update(libdepflags[4])
- extdepflags = self._get_dependencies_flags(dep.ext_deps, state, depends, include_rpath,
- use_gir_args, True)
+ gi_includes.update(libdepflags[3])
+ extdepflags = self._get_dependencies_flags_raw(dep.ext_deps, state, depends, include_rpath,
+ use_gir_args)
cflags.update(extdepflags[0])
internal_ldflags.update(extdepflags[1])
external_ldflags.update(extdepflags[2])
- external_ldflags_nodedup += extdepflags[3]
- gi_includes.update(extdepflags[4])
+ gi_includes.update(extdepflags[3])
for source in dep.sources:
if isinstance(source, GirTarget):
gi_includes.update([os.path.join(state.environment.get_build_dir(),
@@ -469,7 +475,7 @@ class GnomeModule(ExtensionModule):
# If it's a framework arg, slurp the framework name too
# to preserve the order of arguments
if lib == '-framework':
- external_ldflags_nodedup += [lib, next(ldflags)]
+ external_ldflags.update([(lib, next(ldflags))])
else:
external_ldflags.update([lib])
elif isinstance(dep, (build.StaticLibrary, build.SharedLibrary)):
@@ -480,21 +486,43 @@ class GnomeModule(ExtensionModule):
continue
if use_gir_args and self._gir_has_option('--extra-library'):
- def fix_ldflags(ldflags):
- fixed_ldflags = OrderedSet()
+ def fix_ldflags(ldflags: T.Iterable[T.Union[str, T.Tuple[str, str]]]) -> OrderedSet[T.Union[str, T.Tuple[str, str]]]:
+ fixed_ldflags: OrderedSet[T.Union[str, T.Tuple[str, str]]] = OrderedSet()
for ldflag in ldflags:
- if ldflag.startswith("-l"):
+ if isinstance(ldflag, str) and ldflag.startswith("-l"):
ldflag = ldflag.replace('-l', '--extra-library=', 1)
fixed_ldflags.add(ldflag)
return fixed_ldflags
internal_ldflags = fix_ldflags(internal_ldflags)
external_ldflags = fix_ldflags(external_ldflags)
- if not separate_nodedup:
- external_ldflags.update(external_ldflags_nodedup)
- return cflags, internal_ldflags, external_ldflags, gi_includes
- else:
- return cflags, internal_ldflags, external_ldflags, external_ldflags_nodedup, gi_includes
+ return cflags, internal_ldflags, external_ldflags, gi_includes, depends
+
+ def _get_dependencies_flags(
+ self, deps,
+ state,
+ depends,
+ include_rpath: bool = False,
+ use_gir_args: bool = False,
+ ) -> T.Tuple[OrderedSet[str], T.List[str], T.List[str], OrderedSet[str],
+ T.List]:
+
+ cflags, internal_ldflags_raw, external_ldflags_raw, gi_includes, depends = self._get_dependencies_flags_raw(deps, state, depends, include_rpath, use_gir_args)
+ internal_ldflags: T.List[str] = []
+ external_ldflags: T.List[str] = []
+
+ # Extract non-deduplicable argument groups out of the tuples.
+ for ldflag in internal_ldflags_raw:
+ if isinstance(ldflag, str):
+ internal_ldflags.append(ldflag)
+ else:
+ internal_ldflags.extend(ldflag)
+ for ldflag in external_ldflags_raw:
+ if isinstance(ldflag, str):
+ external_ldflags.append(ldflag)
+ else:
+ external_ldflags.extend(ldflag)
+ return cflags, internal_ldflags, external_ldflags, gi_includes, depends
def _unwrap_gir_target(self, girtarget, state):
if not isinstance(girtarget, (build.Executable, build.SharedLibrary,
build.StaticLibrary)):
@@ -875,7 +903,7 @@ class GnomeModule(ExtensionModule):
# ldflags will be misinterpreted by gir scanner (showing
# spurious dependencies) but building GStreamer fails if they
# are not used here.
- dep_cflags, dep_internal_ldflags, dep_external_ldflags, gi_includes = \
+ dep_cflags, dep_internal_ldflags, dep_external_ldflags, gi_includes, depends = \
self._get_dependencies_flags(deps, state, depends, use_gir_args=True)
scan_cflags = []
scan_cflags += list(self._get_scanner_cflags(cflags))
@@ -1170,7 +1198,7 @@ class GnomeModule(ExtensionModule):
deps = extract_as_list(kwargs, 'dependencies')
cflags = []
cflags.extend(mesonlib.stringlistify(kwargs.pop('c_args', [])))
- deps_cflags, internal_ldflags, external_ldflags, gi_includes = \
+ deps_cflags, internal_ldflags, external_ldflags, gi_includes, depends = \
self._get_dependencies_flags(deps, state, depends, include_rpath=True)
inc_dirs = mesonlib.extract_as_list(kwargs, 'include_directories')
for incd in inc_dirs:
|