зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1319156 - part 3 - tests for Rust library features, frontend and backend; r=chmanchester
This commit also adds an overdue test for plain Rust libraries in the recursivemake backend, but said test also serves to ensure that we don't emit features for a library if none were defined in moz.build.
This commit is contained in:
Родитель
1c12d3858c
Коммит
baaec10678
|
@ -52,6 +52,26 @@ CONFIGS = defaultdict(lambda: {
|
|||
'COMPILE_ENVIRONMENT': '1',
|
||||
},
|
||||
},
|
||||
'rust-library': {
|
||||
'defines': {},
|
||||
'non_global_defines': [],
|
||||
'substs': {
|
||||
'COMPILE_ENVIRONMENT': '1',
|
||||
'RUST_TARGET': 'x86_64-unknown-linux-gnu',
|
||||
'LIB_PREFIX': 'lib',
|
||||
'LIB_SUFFIX': 'a',
|
||||
},
|
||||
},
|
||||
'rust-library-features': {
|
||||
'defines': {},
|
||||
'non_global_defines': [],
|
||||
'substs': {
|
||||
'COMPILE_ENVIRONMENT': '1',
|
||||
'RUST_TARGET': 'x86_64-unknown-linux-gnu',
|
||||
'LIB_PREFIX': 'lib',
|
||||
'LIB_SUFFIX': 'a',
|
||||
},
|
||||
},
|
||||
'rust-programs': {
|
||||
'defines': {},
|
||||
'non_global_defines': [],
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
[package]
|
||||
name = "gkrust"
|
||||
version = "0.1.0"
|
||||
authors = [
|
||||
"Nobody <nobody@mozilla.org>",
|
||||
]
|
||||
|
||||
[lib]
|
||||
crate-type = ["staticlib"]
|
||||
|
||||
[profile.dev]
|
||||
panic = "abort"
|
||||
|
||||
[profile.release]
|
||||
panic = "abort"
|
|
@ -0,0 +1,19 @@
|
|||
# Any copyright is dedicated to the Public Domain.
|
||||
# http://creativecommons.org/publicdomain/zero/1.0/
|
||||
|
||||
@template
|
||||
def Library(name):
|
||||
'''Template for libraries.'''
|
||||
LIBRARY_NAME = name
|
||||
|
||||
|
||||
@template
|
||||
def RustLibrary(name, features):
|
||||
'''Template for Rust libraries.'''
|
||||
Library(name)
|
||||
|
||||
IS_RUST_LIBRARY = True
|
||||
RUST_LIBRARY_FEATURES = features
|
||||
|
||||
|
||||
RustLibrary('gkrust', ['musthave', 'cantlivewithout'])
|
|
@ -0,0 +1,15 @@
|
|||
[package]
|
||||
name = "gkrust"
|
||||
version = "0.1.0"
|
||||
authors = [
|
||||
"Nobody <nobody@mozilla.org>",
|
||||
]
|
||||
|
||||
[lib]
|
||||
crate-type = ["staticlib"]
|
||||
|
||||
[profile.dev]
|
||||
panic = "abort"
|
||||
|
||||
[profile.release]
|
||||
panic = "abort"
|
|
@ -0,0 +1,18 @@
|
|||
# Any copyright is dedicated to the Public Domain.
|
||||
# http://creativecommons.org/publicdomain/zero/1.0/
|
||||
|
||||
@template
|
||||
def Library(name):
|
||||
'''Template for libraries.'''
|
||||
LIBRARY_NAME = name
|
||||
|
||||
|
||||
@template
|
||||
def RustLibrary(name):
|
||||
'''Template for Rust libraries.'''
|
||||
Library(name)
|
||||
|
||||
IS_RUST_LIBRARY = True
|
||||
|
||||
|
||||
RustLibrary('gkrust')
|
|
@ -735,6 +735,35 @@ class TestRecursiveMakeBackend(BackendTester):
|
|||
found = [str for str in lines if str.startswith('LOCAL_INCLUDES')]
|
||||
self.assertEqual(found, expected)
|
||||
|
||||
def test_rust_library(self):
|
||||
"""Test that a Rust library is written to backend.mk correctly."""
|
||||
env = self._consume('rust-library', RecursiveMakeBackend)
|
||||
|
||||
backend_path = mozpath.join(env.topobjdir, 'backend.mk')
|
||||
lines = [l.strip() for l in open(backend_path, 'rt').readlines()[2:]]
|
||||
|
||||
expected = [
|
||||
'RUST_LIBRARY_FILE := x86_64-unknown-linux-gnu/release/libgkrust.a',
|
||||
'CARGO_FILE := $(srcdir)/Cargo.toml',
|
||||
]
|
||||
|
||||
self.assertEqual(lines, expected)
|
||||
|
||||
def test_rust_library_with_features(self):
|
||||
"""Test that a Rust library with features is written to backend.mk correctly."""
|
||||
env = self._consume('rust-library-features', RecursiveMakeBackend)
|
||||
|
||||
backend_path = mozpath.join(env.topobjdir, 'backend.mk')
|
||||
lines = [l.strip() for l in open(backend_path, 'rt').readlines()[2:]]
|
||||
|
||||
expected = [
|
||||
'RUST_LIBRARY_FILE := x86_64-unknown-linux-gnu/release/libgkrust.a',
|
||||
'CARGO_FILE := $(srcdir)/Cargo.toml',
|
||||
'RUST_LIBRARY_FEATURES := musthave cantlivewithout',
|
||||
]
|
||||
|
||||
self.assertEqual(lines, expected)
|
||||
|
||||
def test_rust_programs(self):
|
||||
"""Test that {HOST_,}RUST_PROGRAMS are written to backend.mk correctly."""
|
||||
env = self._consume('rust-programs', RecursiveMakeBackend)
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
[package]
|
||||
name = "random-crate"
|
||||
version = "0.1.0"
|
||||
authors = [
|
||||
"Nobody <nobody@mozilla.org>",
|
||||
]
|
||||
|
||||
[lib]
|
||||
crate-type = ["staticlib"]
|
||||
|
||||
[profile.dev]
|
||||
panic = "abort"
|
||||
|
||||
[profile.release]
|
||||
panic = "abort"
|
|
@ -0,0 +1,19 @@
|
|||
# Any copyright is dedicated to the Public Domain.
|
||||
# http://creativecommons.org/publicdomain/zero/1.0/
|
||||
|
||||
@template
|
||||
def Library(name):
|
||||
'''Template for libraries.'''
|
||||
LIBRARY_NAME = name
|
||||
|
||||
|
||||
@template
|
||||
def RustLibrary(name, features):
|
||||
'''Template for Rust libraries.'''
|
||||
Library(name)
|
||||
|
||||
IS_RUST_LIBRARY = True
|
||||
RUST_LIBRARY_FEATURES = features
|
||||
|
||||
|
||||
RustLibrary('random-crate', ['musthave', 'cantlivewithout', 'musthave'])
|
|
@ -0,0 +1,15 @@
|
|||
[package]
|
||||
name = "random-crate"
|
||||
version = "0.1.0"
|
||||
authors = [
|
||||
"Nobody <nobody@mozilla.org>",
|
||||
]
|
||||
|
||||
[lib]
|
||||
crate-type = ["staticlib"]
|
||||
|
||||
[profile.dev]
|
||||
panic = "abort"
|
||||
|
||||
[profile.release]
|
||||
panic = "abort"
|
|
@ -0,0 +1,19 @@
|
|||
# Any copyright is dedicated to the Public Domain.
|
||||
# http://creativecommons.org/publicdomain/zero/1.0/
|
||||
|
||||
@template
|
||||
def Library(name):
|
||||
'''Template for libraries.'''
|
||||
LIBRARY_NAME = name
|
||||
|
||||
|
||||
@template
|
||||
def RustLibrary(name, features):
|
||||
'''Template for Rust libraries.'''
|
||||
Library(name)
|
||||
|
||||
IS_RUST_LIBRARY = True
|
||||
RUST_LIBRARY_FEATURES = features
|
||||
|
||||
|
||||
RustLibrary('random-crate', ['musthave', 'cantlivewithout'])
|
|
@ -1083,6 +1083,23 @@ class TestEmitterBasic(unittest.TestCase):
|
|||
'Cannot link multiple Rust libraries'):
|
||||
self.read_topsrcdir(reader)
|
||||
|
||||
def test_rust_library_features(self):
|
||||
'''Test that RustLibrary features are correctly emitted.'''
|
||||
reader = self.reader('rust-library-features',
|
||||
extra_substs=dict(RUST_TARGET='i686-pc-windows-msvc'))
|
||||
objs = self.read_topsrcdir(reader)
|
||||
self.assertEqual(len(objs), 1)
|
||||
lib = objs[0]
|
||||
self.assertIsInstance(lib, RustLibrary)
|
||||
self.assertEqual(lib.features, ['musthave', 'cantlivewithout'])
|
||||
|
||||
def test_rust_library_duplicate_features(self):
|
||||
'''Test that duplicate RustLibrary features are rejected.'''
|
||||
reader = self.reader('rust-library-duplicate-features')
|
||||
with self.assertRaisesRegexp(SandboxValidationError,
|
||||
'features for .* should not contain duplicates'):
|
||||
self.read_topsrcdir(reader)
|
||||
|
||||
def test_rust_program_no_cargo_toml(self):
|
||||
'''Test that specifying RUST_PROGRAMS without a Cargo.toml fails.'''
|
||||
reader = self.reader('rust-program-no-cargo-toml')
|
||||
|
|
Загрузка…
Ссылка в новой задаче