summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2025-11-13 09:43:55 -0800
committerDylan Baker <dylan@pnwbakers.com>2025-11-19 10:48:48 -0800
commit0c8dcc8138bf47a73ff3add1c1a09ee900797f03 (patch)
treeb0fd3ea6785bd606d58bc3f8022fff7d7c6ba3e5
parentc914f805c63f0ba45b1aaf489a4cc5545ff66b59 (diff)
downloadmeson-0c8dcc8138bf47a73ff3add1c1a09ee900797f03.tar.gz
compilers: Remove Environment parameter from Compiler.symbols_have_underscore_prefix
-rw-r--r--mesonbuild/compilers/compilers.py2
-rw-r--r--mesonbuild/compilers/mixins/clike.py21
-rw-r--r--mesonbuild/compilers/mixins/visualstudio.py6
-rw-r--r--mesonbuild/interpreter/compiler.py2
-rw-r--r--unittests/allplatformstests.py8
5 files changed, 19 insertions, 20 deletions
diff --git a/mesonbuild/compilers/compilers.py b/mesonbuild/compilers/compilers.py
index 023c263e5..64ef53cd6 100644
--- a/mesonbuild/compilers/compilers.py
+++ b/mesonbuild/compilers/compilers.py
@@ -574,7 +574,7 @@ class Compiler(HoldableObject, metaclass=abc.ABCMeta):
dependencies: T.Optional[T.List['Dependency']] = None) -> T.Tuple[bool, bool]:
raise EnvironmentException('%s does not support has_type ' % self.get_id())
- def symbols_have_underscore_prefix(self, env: 'Environment') -> bool:
+ def symbols_have_underscore_prefix(self) -> bool:
raise EnvironmentException('%s does not support symbols_have_underscore_prefix ' % self.get_id())
def get_exelist(self, ccache: bool = True) -> T.List[str]:
diff --git a/mesonbuild/compilers/mixins/clike.py b/mesonbuild/compilers/mixins/clike.py
index 7e46d6542..173a38317 100644
--- a/mesonbuild/compilers/mixins/clike.py
+++ b/mesonbuild/compilers/mixins/clike.py
@@ -888,7 +888,7 @@ class CLikeCompiler(Compiler):
return self.compiles(t, extra_args=extra_args,
dependencies=dependencies)
- def _symbols_have_underscore_prefix_searchbin(self, env: 'Environment') -> bool:
+ def _symbols_have_underscore_prefix_searchbin(self) -> bool:
'''
Check if symbols have underscore prefix by compiling a small test binary
and then searching the binary for the string,
@@ -922,7 +922,7 @@ class CLikeCompiler(Compiler):
return False
raise RuntimeError(f'BUG: {n!r} check did not find symbol string in binary')
- def _symbols_have_underscore_prefix_define(self, env: 'Environment') -> T.Optional[bool]:
+ def _symbols_have_underscore_prefix_define(self) -> T.Optional[bool]:
'''
Check if symbols have underscore prefix by querying the
__USER_LABEL_PREFIX__ define that most compilers provide
@@ -952,39 +952,38 @@ class CLikeCompiler(Compiler):
else:
return None
- def _symbols_have_underscore_prefix_list(self, env: 'Environment') -> T.Optional[bool]:
+ def _symbols_have_underscore_prefix_list(self) -> T.Optional[bool]:
'''
Check if symbols have underscore prefix by consulting a hardcoded
list of cases where we know the results.
Return if functions have underscore prefix or None if unknown.
'''
- m = env.machines[self.for_machine]
# Darwin always uses the underscore prefix, not matter what
- if m.is_darwin():
+ if self.info.is_darwin():
return True
# Windows uses the underscore prefix on x86 (32bit) only
- if m.is_windows() or m.is_cygwin():
- return m.cpu_family == 'x86'
+ if self.info.is_windows() or self.info.is_cygwin():
+ return self.info.cpu_family == 'x86'
return None
- def symbols_have_underscore_prefix(self, env: 'Environment') -> bool:
+ def symbols_have_underscore_prefix(self) -> bool:
'''
Check if the compiler prefixes an underscore to global C symbols
'''
# First, try to query the compiler directly
- result = self._symbols_have_underscore_prefix_define(env)
+ result = self._symbols_have_underscore_prefix_define()
if result is not None:
return result
# Else, try to consult a hardcoded list of cases we know
# absolutely have an underscore prefix
- result = self._symbols_have_underscore_prefix_list(env)
+ result = self._symbols_have_underscore_prefix_list()
if result is not None:
return result
# As a last resort, try search in a compiled binary, which is the
# most unreliable way of checking this, see #5482
- return self._symbols_have_underscore_prefix_searchbin(env)
+ return self._symbols_have_underscore_prefix_searchbin()
def _get_patterns(self, prefixes: T.List[str], suffixes: T.List[str], shared: bool = False) -> T.List[str]:
patterns: T.List[str] = []
diff --git a/mesonbuild/compilers/mixins/visualstudio.py b/mesonbuild/compilers/mixins/visualstudio.py
index f3d3ae96e..bd70ec1ab 100644
--- a/mesonbuild/compilers/mixins/visualstudio.py
+++ b/mesonbuild/compilers/mixins/visualstudio.py
@@ -367,7 +367,7 @@ class VisualStudioLikeCompiler(Compiler, metaclass=abc.ABCMeta):
def get_argument_syntax() -> str:
return 'msvc'
- def symbols_have_underscore_prefix(self, env: 'Environment') -> bool:
+ def symbols_have_underscore_prefix(self) -> bool:
'''
Check if the compiler prefixes an underscore to global C symbols.
@@ -377,12 +377,12 @@ class VisualStudioLikeCompiler(Compiler, metaclass=abc.ABCMeta):
'''
# Try to consult a hardcoded list of cases we know
# absolutely have an underscore prefix
- result = self._symbols_have_underscore_prefix_list(env)
+ result = self._symbols_have_underscore_prefix_list()
if result is not None:
return result
# As a last resort, try search in a compiled binary
- return self._symbols_have_underscore_prefix_searchbin(env)
+ return self._symbols_have_underscore_prefix_searchbin()
def get_pie_args(self) -> T.List[str]:
return []
diff --git a/mesonbuild/interpreter/compiler.py b/mesonbuild/interpreter/compiler.py
index 906caab16..0d5aa9505 100644
--- a/mesonbuild/interpreter/compiler.py
+++ b/mesonbuild/interpreter/compiler.py
@@ -319,7 +319,7 @@ class CompilerHolder(ObjectHolder['Compiler']):
Check if the compiler prefixes _ (underscore) to global C symbols
See: https://en.wikipedia.org/wiki/Name_mangling#C
'''
- return self.compiler.symbols_have_underscore_prefix(self.environment)
+ return self.compiler.symbols_have_underscore_prefix()
@typed_pos_args('compiler.has_member', str, str)
@typed_kwargs('compiler.has_member', _HAS_REQUIRED_KW, *_COMMON_KWS)
diff --git a/unittests/allplatformstests.py b/unittests/allplatformstests.py
index 3f78c72b4..385b195ea 100644
--- a/unittests/allplatformstests.py
+++ b/unittests/allplatformstests.py
@@ -2083,8 +2083,8 @@ class AllPlatformTests(BasePlatformTests):
against what was detected in the binary.
'''
env, cc = get_convincing_fake_env_and_cc(self.builddir, self.prefix)
- expected_uscore = cc._symbols_have_underscore_prefix_searchbin(env)
- list_uscore = cc._symbols_have_underscore_prefix_list(env)
+ expected_uscore = cc._symbols_have_underscore_prefix_searchbin()
+ list_uscore = cc._symbols_have_underscore_prefix_list()
if list_uscore is not None:
self.assertEqual(list_uscore, expected_uscore)
else:
@@ -2096,8 +2096,8 @@ class AllPlatformTests(BasePlatformTests):
against what was detected in the binary.
'''
env, cc = get_convincing_fake_env_and_cc(self.builddir, self.prefix)
- expected_uscore = cc._symbols_have_underscore_prefix_searchbin(env)
- define_uscore = cc._symbols_have_underscore_prefix_define(env)
+ expected_uscore = cc._symbols_have_underscore_prefix_searchbin()
+ define_uscore = cc._symbols_have_underscore_prefix_define()
if define_uscore is not None:
self.assertEqual(define_uscore, expected_uscore)
else: