Skip to content

Commit

Permalink
Optimize CLikeCompiler._get_file_from_list()
Browse files Browse the repository at this point in the history
  • Loading branch information
bruchar1 committed Jan 28, 2025
1 parent 0a5563a commit 68349f1
Showing 1 changed file with 7 additions and 7 deletions.
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))
# 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(str(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

0 comments on commit 68349f1

Please sign in to comment.