aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/backend/ninjabackend.py
diff options
context:
space:
mode:
authorNirbheek Chauhan <nirbheek.chauhan@gmail.com>2018-07-09 09:45:02 -0700
committerGitHub <noreply@github.com>2018-07-09 09:45:02 -0700
commit8cfb8fd02c86e1667ded9a7841d77204f96a4a6d (patch)
tree8f268877d97a6fd07631353a01d0594442315dd0 /mesonbuild/backend/ninjabackend.py
parent28a2e658f884443ae0afbf3ea8929c8c2005b34c (diff)
downloadmeson-8cfb8fd02c86e1667ded9a7841d77204f96a4a6d.zip
meson-8cfb8fd02c86e1667ded9a7841d77204f96a4a6d.tar.gz
meson-8cfb8fd02c86e1667ded9a7841d77204f96a4a6d.tar.bz2
Fix searching of shared libraries on OpenBSD (#3851)
* get_library_naming: Use templates instead of suffix/prefix pairs This commit does not change functionality, and merely sets the groundwork for a more flexibly naming implementation. * find_library: Fix manual searching on OpenBSD On OpenBSD, shared libraries are called libfoo.so.X.Y where X is the major version and Y is the minor version. We were assuming that it's libfoo.so and not finding shared libraries at all while doing manual searching, which meant we'd link statically instead. See: https://www.openbsd.org/faq/ports/specialtopics.html#SharedLibs Now we use file globbing to do searching, and pick the first one that's a real file. Closes https://github.com/mesonbuild/meson/issues/3844 * find_library: Fix priority of library search in OpenBSD Also add unit tests for the library naming function so that it's absolutely clear what the priority list of naming is. Testing is done with mocking on Linux to ensure that local testing is easy
Diffstat (limited to 'mesonbuild/backend/ninjabackend.py')
-rw-r--r--mesonbuild/backend/ninjabackend.py45
1 files changed, 28 insertions, 17 deletions
diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py
index 3ee543d..09c4904 100644
--- a/mesonbuild/backend/ninjabackend.py
+++ b/mesonbuild/backend/ninjabackend.py
@@ -12,7 +12,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-import os, pickle, re, shlex, subprocess
+import os
+import re
+import shlex
+import pickle
+import subprocess
from collections import OrderedDict
import itertools
from pathlib import PurePath
@@ -24,7 +28,7 @@ from .. import build
from .. import mlog
from .. import dependencies
from .. import compilers
-from ..compilers import CompilerArgs, get_macos_dylib_install_name
+from ..compilers import CompilerArgs, CCompiler, get_macos_dylib_install_name
from ..linkers import ArLinker
from ..mesonlib import File, MesonException, OrderedSet
from ..mesonlib import get_compiler_for_source, has_path_sep
@@ -2476,13 +2480,18 @@ rule FORTRAN_DEP_HACK%s
target_args = self.build_target_link_arguments(linker, target.link_whole_targets)
return linker.get_link_whole_for(target_args) if len(target_args) else []
- def guess_library_absolute_path(self, libname, search_dirs, prefixes, suffixes):
- for directory in search_dirs:
- for suffix in suffixes:
- for prefix in prefixes:
- trial = os.path.join(directory, prefix + libname + '.' + suffix)
- if os.path.isfile(trial):
- return trial
+ @staticmethod
+ def guess_library_absolute_path(linker, libname, search_dirs, patterns):
+ for d in search_dirs:
+ for p in patterns:
+ trial = CCompiler._get_trials_from_pattern(p, d, libname)
+ if not trial:
+ continue
+ trial = CCompiler._get_file_from_list(trial)
+ if not trial:
+ continue
+ # Return the first result
+ return trial
def guess_external_link_dependencies(self, linker, target, commands, internal):
# Ideally the linker would generate dependency information that could be used.
@@ -2531,17 +2540,19 @@ rule FORTRAN_DEP_HACK%s
# TODO The get_library_naming requirement currently excludes link targets that use d or fortran as their main linker
if hasattr(linker, 'get_library_naming'):
search_dirs = list(search_dirs) + linker.get_library_dirs()
- prefixes_static, suffixes_static = linker.get_library_naming(self.environment, 'static', strict=True)
- prefixes_shared, suffixes_shared = linker.get_library_naming(self.environment, 'shared', strict=True)
+ static_patterns = linker.get_library_naming(self.environment, 'static', strict=True)
+ shared_patterns = linker.get_library_naming(self.environment, 'shared', strict=True)
for libname in libs:
# be conservative and record most likely shared and static resolution, because we don't know exactly
# which one the linker will prefer
- static_resolution = self.guess_library_absolute_path(libname, search_dirs, prefixes_static, suffixes_static)
- shared_resolution = self.guess_library_absolute_path(libname, search_dirs, prefixes_shared, suffixes_shared)
- if static_resolution:
- guessed_dependencies.append(os.path.realpath(static_resolution))
- if shared_resolution:
- guessed_dependencies.append(os.path.realpath(shared_resolution))
+ staticlibs = self.guess_library_absolute_path(linker, libname,
+ search_dirs, static_patterns)
+ sharedlibs = self.guess_library_absolute_path(linker, libname,
+ search_dirs, shared_patterns)
+ if staticlibs:
+ guessed_dependencies.append(os.path.realpath(staticlibs))
+ if sharedlibs:
+ guessed_dependencies.append(os.path.realpath(sharedlibs))
return guessed_dependencies + absolute_libs