Replace NinjaBackend is_rust_target with build.uses_rust

we have two functions to do the exact same thing, and they're basically
implemented the same way. Instead, let's just use the BuildTarget one,
as it's more generally available.
pull/8158/head
Dylan Baker 4 years ago
parent c64d407076
commit 3ae115b57a
  1. 9
      mesonbuild/backend/ninjabackend.py
  2. 6
      mesonbuild/build.py
  3. 2
      mesonbuild/modules/unstable_rust.py

@ -691,13 +691,6 @@ int dummy;
src_block['sources'] += sources src_block['sources'] += sources
src_block['generated_sources'] += generated_sources src_block['generated_sources'] += generated_sources
def is_rust_target(self, target):
if len(target.sources) > 0:
first_file = target.sources[0]
if first_file.fname.endswith('.rs'):
return True
return False
def generate_target(self, target): def generate_target(self, target):
try: try:
if isinstance(target, build.BuildTarget): if isinstance(target, build.BuildTarget):
@ -723,7 +716,7 @@ int dummy;
if isinstance(target, build.Jar): if isinstance(target, build.Jar):
self.generate_jar_target(target) self.generate_jar_target(target)
return return
if self.is_rust_target(target): if target.uses_rust():
self.generate_rust_target(target) self.generate_rust_target(target)
return return
if 'cs' in target.compilers: if 'cs' in target.compilers:

@ -1412,7 +1412,7 @@ You probably should put it in link_with instead.''')
m = 'Could not get a dynamic linker for build target {!r}' m = 'Could not get a dynamic linker for build target {!r}'
raise AssertionError(m.format(self.name)) raise AssertionError(m.format(self.name))
def get_using_rustc(self) -> bool: def uses_rust(self) -> bool:
"""Is this target a rust target.""" """Is this target a rust target."""
return self.sources and self.sources[0].fname.endswith('.rs') return self.sources and self.sources[0].fname.endswith('.rs')
@ -1687,7 +1687,7 @@ class Executable(BuildTarget):
self.import_filename = self.gcc_import_filename self.import_filename = self.gcc_import_filename
if m.is_windows() and ('cs' in self.compilers or if m.is_windows() and ('cs' in self.compilers or
self.get_using_rustc() or self.uses_rust() or
self.get_using_msvc()): self.get_using_msvc()):
self.debug_filename = self.name + '.pdb' self.debug_filename = self.name + '.pdb'
@ -1877,7 +1877,7 @@ class SharedLibrary(BuildTarget):
suffix = 'dll' suffix = 'dll'
self.vs_import_filename = '{0}{1}.lib'.format(self.prefix if self.prefix is not None else '', self.name) self.vs_import_filename = '{0}{1}.lib'.format(self.prefix if self.prefix is not None else '', self.name)
self.gcc_import_filename = '{0}{1}.dll.a'.format(self.prefix if self.prefix is not None else 'lib', self.name) self.gcc_import_filename = '{0}{1}.dll.a'.format(self.prefix if self.prefix is not None else 'lib', self.name)
if self.get_using_rustc(): if self.uses_rust():
# Shared library is of the form foo.dll # Shared library is of the form foo.dll
prefix = '' prefix = ''
# Import library is called foo.dll.lib # Import library is called foo.dll.lib

@ -85,7 +85,7 @@ class RustModule(ExtensionModule):
base_target: BuildTarget = unholder(args[1]) base_target: BuildTarget = unholder(args[1])
if not isinstance(base_target, BuildTarget): if not isinstance(base_target, BuildTarget):
raise InterpreterException('Second positional argument to rustmod.test() must be a library or executable') raise InterpreterException('Second positional argument to rustmod.test() must be a library or executable')
if not base_target.get_using_rustc(): if not base_target.uses_rust():
raise InterpreterException('Second positional argument to rustmod.test() must be a rust based target') raise InterpreterException('Second positional argument to rustmod.test() must be a rust based target')
extra_args = stringlistify(kwargs.get('args', [])) extra_args = stringlistify(kwargs.get('args', []))

Loading…
Cancel
Save