aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles Brunet <charles.brunet@optelgroup.com>2023-08-09 08:40:20 -0400
committerXavier Claessens <xclaesse@gmail.com>2023-08-09 09:44:15 -0400
commit711e4e3b069313df7e0c9912d316fecd197b2ce0 (patch)
treef470d6accd4ef506818e8fcec153deba5082853b
parentb91244c3b7f77578d601502628bceb9e92183387 (diff)
downloadmeson-711e4e3b069313df7e0c9912d316fecd197b2ce0.zip
meson-711e4e3b069313df7e0c9912d316fecd197b2ce0.tar.gz
meson-711e4e3b069313df7e0c9912d316fecd197b2ce0.tar.bz2
Optimize CLikeCompiler._get_file_from_list()
Simplify and optimize the function. When not on Mac OS, it was iterating two times the list when there were no files in it.
-rw-r--r--mesonbuild/compilers/mixins/clike.py24
1 files changed, 11 insertions, 13 deletions
diff --git a/mesonbuild/compilers/mixins/clike.py b/mesonbuild/compilers/mixins/clike.py
index 251a7bf..f333357 100644
--- a/mesonbuild/compilers/mixins/clike.py
+++ b/mesonbuild/compilers/mixins/clike.py
@@ -1090,27 +1090,25 @@ class CLikeCompiler(Compiler):
return [f]
@staticmethod
- def _get_file_from_list(env: 'Environment', paths: T.List[Path]) -> Path:
+ def _get_file_from_list(env: Environment, paths: T.List[Path]) -> 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.
'''
- # If not building on macOS for Darwin, do a simple file check
- if not env.machines.host.is_darwin() or not env.machines.build.is_darwin():
- for p in paths:
- if p.is_file():
- return p
- # Run `lipo` and check if the library supports the arch we want
for p in paths:
- if not p.is_file():
- continue
- archs = mesonlib.darwin_get_object_archs(str(p))
- if archs and env.machines.host.cpu_family in archs:
+ if p.is_file():
+
+ 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))
+ 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
- else:
- mlog.debug(f'Rejected {p}, supports {archs} but need {env.machines.host.cpu_family}')
+
return None
@functools.lru_cache()