aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/backend/ninjabackend.py
diff options
context:
space:
mode:
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