Skip to content

Commit e1f3e6b

Browse files
committed
build: rework the meson cmake dependency patch
Review of mesonbuild/meson#16077 found the previous version silently dropped every relative source path passed to set_source_files_properties(), since the CMake trace does not absolutize them.
1 parent db5ae91 commit e1f3e6b

1 file changed

Lines changed: 37 additions & 48 deletions

File tree

.github/meson-cmake-generated-deps.patch

Lines changed: 37 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -6,56 +6,48 @@
66

77
+ # Object dependencies set via set_source_files_properties(... OBJECT_DEPENDS ...),
88
+ # mapping the source file to the files its compilation depends on
9-
+ self.object_depends: T.Dict[str, T.List[str]] = {}
9+
+ self.object_depends: T.Dict[Path, T.List[str]] = {}
1010
+
1111
# T.List of targes that were added with add_custom_command to generate files
1212
self.custom_targets: T.List[CMakeGeneratorTarget] = []
1313

14-
@@ -120,6 +124,7 @@
15-
'add_custom_target': self._cmake_add_custom_target,
16-
'set_property': self._cmake_set_property,
17-
'set_target_properties': self._cmake_set_target_properties,
18-
+ 'set_source_files_properties': self._cmake_set_source_files_properties,
19-
'target_compile_definitions': self._cmake_target_compile_definitions,
20-
'target_compile_options': self._cmake_target_compile_options,
21-
'target_include_directories': self._cmake_target_include_directories,
22-
@@ -605,6 +610,33 @@
14+
@@ -525,9 +529,10 @@
15+
else:
16+
tgt.properties[identifier] = value
2317

24-
self.targets[i].properties[name] = value
18+
- def do_source(src: str) -> None:
19+
- if identifier != 'HEADER_FILE_ONLY' or not self._str_to_bool(value):
20+
- return
21+
+ def resolve_source(src: str) -> Path:
22+
+ src_p = Path(src)
23+
+ if src_p.is_absolute():
24+
+ return src_p
2525

26-
+ def _cmake_set_source_files_properties(self, tline: CMakeTraceLine) -> None:
27-
+ # DOC: https://cmake.org/cmake/help/latest/command/set_source_files_properties.html
28-
+ args = list(tline.args)
29-
+
30-
+ sources: T.List[str] = []
31-
+ idx = 0
32-
+ while idx < len(args) and args[idx] != 'PROPERTIES':
33-
+ if args[idx] in {'DIRECTORY', 'TARGET_DIRECTORY'}:
34-
+ # skip the scope arguments
35-
+ idx += 1
36-
+ while idx < len(args) and args[idx] not in {'DIRECTORY', 'TARGET_DIRECTORY', 'PROPERTIES'}:
37-
+ idx += 1
38-
+ continue
39-
+ sources += args[idx].split(';')
40-
+ idx += 1
41-
+
42-
+ object_depends: T.List[str] = []
43-
+ idx += 1
44-
+ while idx + 1 < len(args):
45-
+ if args[idx] == 'OBJECT_DEPENDS':
46-
+ object_depends += args[idx + 1].split(';')
47-
+ idx += 2
48-
+
49-
+ if object_depends:
50-
+ for i in sources:
51-
+ self.object_depends.setdefault(i, []).extend(object_depends)
52-
+
53-
def _cmake_add_dependencies(self, tline: CMakeTraceLine) -> None:
54-
# DOC: https://cmake.org/cmake/help/latest/command/add_dependencies.html
55-
args = list(tline.args)
26+
current_src_dir = self.var_to_str('MESON_PS_CMAKE_CURRENT_SOURCE_DIR')
27+
if not current_src_dir:
28+
@@ -537,12 +542,14 @@
29+
'''))
30+
current_src_dir = '.'
31+
32+
- cur_p = Path(current_src_dir)
33+
- src_p = Path(src)
34+
+ return Path(current_src_dir) / src_p
35+
36+
- if not src_p.is_absolute():
37+
- src_p = cur_p / src_p
38+
- self.explicit_headers.add(src_p)
39+
+ def do_source(src: str) -> None:
40+
+ if identifier == 'HEADER_FILE_ONLY':
41+
+ if self._str_to_bool(value):
42+
+ self.explicit_headers.add(resolve_source(src))
43+
+ elif identifier == 'OBJECT_DEPENDS':
44+
+ self.object_depends.setdefault(resolve_source(src), []).extend(value)
45+
46+
if scope == 'TARGET':
47+
for i in targets:
5648
--- a/mesonbuild/cmake/interpreter.py
5749
+++ b/mesonbuild/cmake/interpreter.py
58-
@@ -382,6 +382,21 @@
50+
@@ -382,6 +382,18 @@
5951
elif self.type.upper() not in ['EXECUTABLE', 'OBJECT_LIBRARY']:
6052
mlog.warning('CMake: Target', mlog.bold(self.cmake_name), 'not found in CMake trace. This can lead to build errors')
6153

@@ -68,16 +60,13 @@
6860
+ p = x if x.is_absolute() else self.src_dir / x
6961
+ src_keys.add(p.resolve().as_posix())
7062
+ for src, deps in trace.object_depends.items():
71-
+ src_path = Path(src)
72-
+ if not src_path.is_absolute():
73-
+ continue
74-
+ if src_path.resolve().as_posix() in src_keys:
63+
+ if src.resolve().as_posix() in src_keys:
7564
+ self.depends_raw += deps
7665
+
7766
temp = []
7867
for cmd in self.link_libraries:
7968
# Let meson handle this arcane magic
80-
@@ -503,7 +518,14 @@
69+
@@ -503,7 +515,14 @@
8170
for arg in self.depends_raw:
8271
dep_tgt = output_target_map.target(arg)
8372
if dep_tgt:
@@ -93,7 +82,7 @@
9382

9483
def process_object_libs(self, obj_target_list: T.List['ConverterTarget'], linker_workaround: bool) -> None:
9584
# Try to detect the object library(s) from the generated input sources
96-
@@ -1131,12 +1153,24 @@
85+
@@ -1131,12 +1150,24 @@
9786
if i.name not in processed:
9887
process_target(i)
9988
objec_libs += [extract_tgt(i)]

0 commit comments

Comments
 (0)