Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speedup extract_objects #14109

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions mesonbuild/backend/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,8 +472,8 @@ def flatten_object_list(self, target: build.BuildTarget, proj_dir_to_build_root:
obj_list, deps = self._flatten_object_list(target, target.get_objects(), proj_dir_to_build_root)
return list(dict.fromkeys(obj_list)), deps

def determine_ext_objs(self, objects: build.ExtractedObjects, proj_dir_to_build_root: str = '') -> T.List[str]:
obj_list, _ = self._flatten_object_list(objects.target, [objects], proj_dir_to_build_root)
def determine_ext_objs(self, objects: build.ExtractedObjects) -> T.List[str]:
obj_list, _ = self._flatten_object_list(objects.target, [objects], '')
return list(dict.fromkeys(obj_list))

def _flatten_object_list(self, target: build.BuildTarget,
Expand All @@ -500,7 +500,12 @@ def _flatten_object_list(self, target: build.BuildTarget,
objs, d = self._flatten_object_list(obj.target, obj.objlist, proj_dir_to_build_root)
obj_list.extend(objs)
deps.extend(d)
obj_list.extend(self._determine_ext_objs(obj, proj_dir_to_build_root))
new_objs = self._determine_ext_objs(obj)
if proj_dir_to_build_root:
for o in new_objs:
obj_list.append(os.path.join(proj_dir_to_build_root, o))
else:
obj_list.extend(new_objs)
deps.append(obj.target)
else:
raise MesonException('Unknown data type in object list.')
Expand Down Expand Up @@ -825,6 +830,7 @@ def determine_rpath_dirs(self, target: T.Union[build.BuildTarget, build.CustomTa
return tuple(result)

@staticmethod
@lru_cache(maxsize=None)
def canonicalize_filename(fname: str) -> str:
parts = Path(fname).parts
hashed = ''
Expand Down Expand Up @@ -883,7 +889,8 @@ def object_filename_from_source(self, target: build.BuildTarget, compiler: Compi
return os.path.join(targetdir, ret)
return ret

def _determine_ext_objs(self, extobj: 'build.ExtractedObjects', proj_dir_to_build_root: str) -> T.List[str]:
@lru_cache(maxsize=None)
def _determine_ext_objs(self, extobj: 'build.ExtractedObjects') -> T.List[str]:
result: T.List[str] = []

targetdir = self.get_target_private_dir(extobj.target)
Expand All @@ -909,7 +916,7 @@ def _determine_ext_objs(self, extobj: 'build.ExtractedObjects', proj_dir_to_buil
compiler = extobj.target.compilers[lang]
if compiler.get_argument_syntax() == 'msvc':
objname = self.get_msvc_pch_objname(lang, pch)
result.append(os.path.join(proj_dir_to_build_root, targetdir, objname))
result.append(os.path.join(targetdir, objname))

# extobj could contain only objects and no sources
if not sources:
Expand All @@ -936,8 +943,7 @@ def _determine_ext_objs(self, extobj: 'build.ExtractedObjects', proj_dir_to_buil
for osrc in sources:
compiler = get_compiler_for_source(extobj.target.compilers.values(), osrc)
objname = self.object_filename_from_source(extobj.target, compiler, osrc, targetdir)
objpath = os.path.join(proj_dir_to_build_root, objname)
result.append(objpath)
result.append(objname)

return result

Expand Down
2 changes: 1 addition & 1 deletion mesonbuild/backend/ninjabackend.py
Original file line number Diff line number Diff line change
Expand Up @@ -3368,7 +3368,7 @@ def get_link_whole_args(self, linker: DynamicLinker, target):
objects_from_static_libs: T.List[ExtractedObjects] = []
for dep in target.link_whole_targets:
l = dep.extract_all_objects(False)
objects_from_static_libs += self.determine_ext_objs(l, '')
objects_from_static_libs += self.determine_ext_objs(l)
objects_from_static_libs.extend(self.flatten_object_list(dep)[0])

return objects_from_static_libs
Expand Down
Loading