From 3ae115b57ad7f8eca09c03f5bd6bf65604dcaf59 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Tue, 19 Jan 2021 10:12:38 -0800 Subject: [PATCH] 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. --- mesonbuild/backend/ninjabackend.py | 9 +-------- mesonbuild/build.py | 6 +++--- mesonbuild/modules/unstable_rust.py | 2 +- 3 files changed, 5 insertions(+), 12 deletions(-) diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py index d66708c59..d3350bba6 100644 --- a/mesonbuild/backend/ninjabackend.py +++ b/mesonbuild/backend/ninjabackend.py @@ -691,13 +691,6 @@ int dummy; src_block['sources'] += 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): try: if isinstance(target, build.BuildTarget): @@ -723,7 +716,7 @@ int dummy; if isinstance(target, build.Jar): self.generate_jar_target(target) return - if self.is_rust_target(target): + if target.uses_rust(): self.generate_rust_target(target) return if 'cs' in target.compilers: diff --git a/mesonbuild/build.py b/mesonbuild/build.py index 017b0f0f8..fa7c140ef 100644 --- a/mesonbuild/build.py +++ b/mesonbuild/build.py @@ -1412,7 +1412,7 @@ You probably should put it in link_with instead.''') m = 'Could not get a dynamic linker for build target {!r}' raise AssertionError(m.format(self.name)) - def get_using_rustc(self) -> bool: + def uses_rust(self) -> bool: """Is this target a rust target.""" return self.sources and self.sources[0].fname.endswith('.rs') @@ -1687,7 +1687,7 @@ class Executable(BuildTarget): self.import_filename = self.gcc_import_filename if m.is_windows() and ('cs' in self.compilers or - self.get_using_rustc() or + self.uses_rust() or self.get_using_msvc()): self.debug_filename = self.name + '.pdb' @@ -1877,7 +1877,7 @@ class SharedLibrary(BuildTarget): suffix = 'dll' 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) - if self.get_using_rustc(): + if self.uses_rust(): # Shared library is of the form foo.dll prefix = '' # Import library is called foo.dll.lib diff --git a/mesonbuild/modules/unstable_rust.py b/mesonbuild/modules/unstable_rust.py index 02369b643..d215376e7 100644 --- a/mesonbuild/modules/unstable_rust.py +++ b/mesonbuild/modules/unstable_rust.py @@ -85,7 +85,7 @@ class RustModule(ExtensionModule): base_target: BuildTarget = unholder(args[1]) if not isinstance(base_target, BuildTarget): 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') extra_args = stringlistify(kwargs.get('args', []))