From e8b5c21263b6dd5da35b418be0741c190a4e12cb Mon Sep 17 00:00:00 2001 From: Mike Hommey Date: Fri, 16 Aug 2019 14:35:36 +0000 Subject: [PATCH] Bug 1573566 - Don't make HostRustLibrary indirectly inherit from StaticLibrary. r=froydnj So that isinstance(foo, StaticLibrary) doesn't end up being true for HostRustLibrary. Instead, it now inherits from HostLibrary. Differential Revision: https://phabricator.services.mozilla.com/D42248 --HG-- extra : moz-landing-system : lando --- python/mozbuild/mozbuild/backend/common.py | 3 +- .../mozbuild/backend/recursivemake.py | 3 +- python/mozbuild/mozbuild/frontend/data.py | 37 ++++++++++++++----- 3 files changed, 31 insertions(+), 12 deletions(-) diff --git a/python/mozbuild/mozbuild/backend/common.py b/python/mozbuild/mozbuild/backend/common.py index 0d4578b35fd5..df17c069f352 100644 --- a/python/mozbuild/mozbuild/backend/common.py +++ b/python/mozbuild/mozbuild/backend/common.py @@ -32,6 +32,7 @@ from mozbuild.frontend.data import ( GeneratedSources, GnProjectData, HostLibrary, + HostRustLibrary, HostGeneratedSources, IPDLCollection, LocalizedPreprocessedFiles, @@ -276,7 +277,7 @@ class CommonBackend(BuildBackend): system_libs = not isinstance(input_bin, (HostLibrary, StaticLibrary)) for lib in input_bin.linked_libraries: - if isinstance(lib, RustLibrary): + if isinstance(lib, (HostRustLibrary, RustLibrary)): continue elif isinstance(lib, (HostLibrary, StaticLibrary)): expand(lib, True, system_libs) diff --git a/python/mozbuild/mozbuild/backend/recursivemake.py b/python/mozbuild/mozbuild/backend/recursivemake.py index ea17ac8fee95..d679095eef44 100644 --- a/python/mozbuild/mozbuild/backend/recursivemake.py +++ b/python/mozbuild/mozbuild/backend/recursivemake.py @@ -46,6 +46,7 @@ from ..frontend.data import ( HostGeneratedSources, HostLibrary, HostProgram, + HostRustLibrary, HostRustProgram, HostSimpleProgram, HostSources, @@ -678,7 +679,7 @@ class RecursiveMakeBackend(CommonBackend): elif isinstance(obj, InstallationTarget): self._process_installation_target(obj, backend_file) - elif isinstance(obj, RustLibrary): + elif isinstance(obj, (RustLibrary, HostRustLibrary)): self.backend_input_files.add(obj.cargo_file) self._process_rust_library(obj, backend_file) # No need to call _process_linked_libraries, because Rust diff --git a/python/mozbuild/mozbuild/frontend/data.py b/python/mozbuild/mozbuild/frontend/data.py index 751682f35394..f6f1ee03a32a 100644 --- a/python/mozbuild/mozbuild/frontend/data.py +++ b/python/mozbuild/mozbuild/frontend/data.py @@ -670,9 +670,8 @@ class StaticLibrary(Library): self.no_expand_lib = no_expand_lib -class RustLibrary(StaticLibrary): - """Context derived container object for a static library""" - __slots__ = ( +class BaseRustLibrary(object): + slots = ( 'cargo_file', 'crate_type', 'dependencies', @@ -681,13 +680,9 @@ class RustLibrary(StaticLibrary): 'target_dir', 'output_category', ) - TARGET_SUBST_VAR = 'RUST_TARGET' - FEATURES_VAR = 'RUST_LIBRARY_FEATURES' - LIB_FILE_VAR = 'RUST_LIBRARY_FILE' - def __init__(self, context, basename, cargo_file, crate_type, dependencies, - features, target_dir, **args): - StaticLibrary.__init__(self, context, basename, **args) + def init(self, context, basename, cargo_file, crate_type, dependencies, + features, target_dir): self.cargo_file = cargo_file self.crate_type = crate_type # We need to adjust our naming here because cargo replaces '-' in @@ -715,6 +710,21 @@ class RustLibrary(StaticLibrary): self.deps_path = mozpath.join(build_dir, 'deps') +class RustLibrary(StaticLibrary, BaseRustLibrary): + """Context derived container object for a rust static library""" + KIND = 'target' + TARGET_SUBST_VAR = 'RUST_TARGET' + FEATURES_VAR = 'RUST_LIBRARY_FEATURES' + LIB_FILE_VAR = 'RUST_LIBRARY_FILE' + __slots__ = BaseRustLibrary.slots + + def __init__(self, context, basename, cargo_file, crate_type, dependencies, + features, target_dir, link_into=None): + StaticLibrary.__init__(self, context, basename, link_into=link_into) + BaseRustLibrary.init(self, context, basename, cargo_file, + crate_type, dependencies, features, target_dir) + + class SharedLibrary(Library): """Context derived container object for a shared library""" __slots__ = ( @@ -830,12 +840,19 @@ class HostLibrary(HostMixin, BaseLibrary): KIND = 'host' -class HostRustLibrary(HostMixin, RustLibrary): +class HostRustLibrary(HostLibrary, BaseRustLibrary): """Context derived container object for a host rust library""" KIND = 'host' TARGET_SUBST_VAR = 'RUST_HOST_TARGET' FEATURES_VAR = 'HOST_RUST_LIBRARY_FEATURES' LIB_FILE_VAR = 'HOST_RUST_LIBRARY_FILE' + __slots__ = BaseRustLibrary.slots + + def __init__(self, context, basename, cargo_file, crate_type, dependencies, + features, target_dir): + HostLibrary.__init__(self, context, basename) + BaseRustLibrary.init(self, context, basename, cargo_file, + crate_type, dependencies, features, target_dir) class TestManifest(ContextDerived):