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:
Nathan Froyd 2016-12-02 11:39:15 -05:00
parent 1c12d3858c
commit baaec10678
11 changed files with 201 additions and 0 deletions

View File

@ -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': [],

View File

@ -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"

View File

@ -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'])

View File

@ -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"

View File

@ -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')

View File

@ -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)

View File

@ -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"

View File

@ -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'])

View File

@ -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"

View File

@ -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'])

View File

@ -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')