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

Optimize object filename from source #14200

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
4 changes: 3 additions & 1 deletion mesonbuild/backend/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,9 @@ def determine_rpath_dirs(self, target: T.Union[build.BuildTarget, build.CustomTa
@staticmethod
@lru_cache(maxsize=None)
def canonicalize_filename(fname: str) -> str:
parts = Path(fname).parts
if os.path.altsep is not None:
fname = fname.replace(os.path.altsep, os.path.sep)
parts = fname.split(os.path.sep)
hashed = ''
if len(parts) > 5:
temp = '/'.join(parts[-5:])
Expand Down
2 changes: 1 addition & 1 deletion mesonbuild/backend/vs2010backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -1463,7 +1463,7 @@ def add_non_makefile_vcxproj_elements(
if self.environment.is_source(src):
target_private_dir = self.relpath(self.get_target_private_dir(t),
self.get_target_dir(t))
rel_obj = self.object_filename_from_source(t, src, target_private_dir)
rel_obj = self.object_filename_from_source(t, compiler, src, target_private_dir)
bruchar1 marked this conversation as resolved.
Show resolved Hide resolved
extra_link_args.append(rel_obj)

extra_link_args.extend(self.flatten_object_list(t))
Expand Down
14 changes: 7 additions & 7 deletions mesonbuild/compilers/mixins/clike.py
Original file line number Diff line number Diff line change
Expand Up @@ -1090,34 +1090,34 @@ def tuple_key(x: str) -> T.Tuple[int, ...]:
return sorted(filtered, key=tuple_key, reverse=True)

@classmethod
def _get_trials_from_pattern(cls, pattern: str, directory: str, libname: str) -> T.List[Path]:
f = Path(directory) / pattern.format(libname)
def _get_trials_from_pattern(cls, pattern: str, directory: str, libname: str) -> T.List[str]:
f = os.path.join(directory, pattern.format(libname))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change overall looks good. There was never any real reason to use pathlib here especially since we spent a lot of time transforming strings into Path objects just to reconvert them back into strings.

# Globbing for OpenBSD
if '*' in pattern:
# NOTE: globbing matches directories and broken symlinks
# so we have to do an isfile test on it later
return [Path(x) for x in cls._sort_shlibs_openbsd(glob.glob(str(f)))]
return cls._sort_shlibs_openbsd(glob.glob(f))
return [f]

@staticmethod
def _get_file_from_list(env: Environment, paths: T.List[Path]) -> T.Optional[Path]:
def _get_file_from_list(env: Environment, paths: T.List[str]) -> T.Optional[Path]:
'''
We just check whether the library exists. We can't do a link check
because the library might have unresolved symbols that require other
libraries. On macOS we check if the library matches our target
architecture.
'''
for p in paths:
if p.is_file():
if os.path.isfile(p):

if env.machines.host.is_darwin() and env.machines.build.is_darwin():
# Run `lipo` and check if the library supports the arch we want
archs = mesonlib.darwin_get_object_archs(str(p))
archs = mesonlib.darwin_get_object_archs(p)
if not archs or env.machines.host.cpu_family not in archs:
mlog.debug(f'Rejected {p}, supports {archs} but need {env.machines.host.cpu_family}')
continue

return p
return Path(p)

return None

Expand Down
2 changes: 2 additions & 0 deletions mesonbuild/coredata.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from . import mlog, options
import pickle, os, uuid
import sys
from functools import lru_cache
from itertools import chain
from pathlib import PurePath
from collections import OrderedDict, abc
Expand Down Expand Up @@ -582,6 +583,7 @@ def get_external_args(self, for_machine: MachineChoice, lang: str) -> T.List[str
key = OptionKey(f'{lang}_args', machine=for_machine)
return T.cast('T.List[str]', self.optstore.get_value(key))

@lru_cache(maxsize=None)
def get_external_link_args(self, for_machine: MachineChoice, lang: str) -> T.List[str]:
# mypy cannot analyze type of OptionKey
key = OptionKey(f'{lang}_link_args', machine=for_machine)
Expand Down
3 changes: 3 additions & 0 deletions unittests/allplatformstests.py
Original file line number Diff line number Diff line change
Expand Up @@ -4456,12 +4456,15 @@ def test_env_flags_to_linker(self) -> None:

# Test a compiler that acts as a linker
with mock.patch.object(cc_type, 'INVOKES_LINKER', True):
env.coredata.get_external_link_args.cache_clear()
cc = detect_compiler_for(env, 'c', MachineChoice.HOST, True, '')
link_args = env.coredata.get_external_link_args(cc.for_machine, cc.language)
self.assertEqual(sorted(link_args), sorted(['-DCFLAG', '-flto']))


# And one that doesn't
with mock.patch.object(cc_type, 'INVOKES_LINKER', False):
env.coredata.get_external_link_args.cache_clear()
cc = detect_compiler_for(env, 'c', MachineChoice.HOST, True, '')
link_args = env.coredata.get_external_link_args(cc.for_machine, cc.language)
self.assertEqual(sorted(link_args), sorted(['-flto']))
Expand Down
Loading