Bug 1303223 - Ensure that panic = 'abort' is specified for all toplevel Cargo.tomls, r=froydnj

MozReview-Commit-ID: GX0FJjDVA5q
This commit is contained in:
Michael Layzell 2016-09-13 17:03:06 -04:00
Родитель 817fe1571d
Коммит 73b988acc6
11 изменённых файлов: 127 добавлений и 0 удалений

Просмотреть файл

@ -423,6 +423,7 @@ class TreeMetadataEmitter(LoggingMixin):
'library %s does not match Cargo.toml-defined package %s' % (libname, crate_name),
context)
# Check that the [lib.crate-type] field is correct
lib_section = config.get('lib', None)
if not lib_section:
raise SandboxValidationError(
@ -441,6 +442,26 @@ class TreeMetadataEmitter(LoggingMixin):
'crate-type %s is not permitted for %s' % (crate_type, libname),
context)
# Check that the [profile.{dev,release}.panic] field is "abort"
profile_section = config.get('profile', None)
if not profile_section:
raise SandboxValidationError(
'Cargo.toml for %s has no [profile] section' % libname,
context)
for profile_name in ['dev', 'release']:
profile = profile_section.get(profile_name, None)
if not profile:
raise SandboxValidationError(
'Cargo.toml for %s has no [profile.%s] section' % (libname, profile_name),
context)
panic = profile.get('panic', None)
if panic != 'abort':
raise SandboxValidationError(
('Cargo.toml for %s does not specify `panic = "abort"`'
' in [profile.%s] section') % (libname, profile_name),
context)
return RustLibrary(context, libname, cargo_file, crate_type, **static_args)

Просмотреть файл

@ -10,3 +10,9 @@ crate-type = ["rlib"]
[dependencies]
deep-crate = { version = "0.1.0", path = "the/depths" }
[profile.dev]
panic = "abort"
[profile.release]
panic = "abort"

Просмотреть файл

@ -7,3 +7,9 @@ authors = [
[lib]
crate-type = ["rlib"]
[profile.dev]
panic = "abort"
[profile.release]
panic = "abort"

Просмотреть файл

@ -7,3 +7,9 @@ authors = [
[lib]
crate-type = ["dylib"]
[profile.dev]
panic = "abort"
[profile.release]
panic = "abort"

Просмотреть файл

@ -4,3 +4,9 @@ version = "0.1.0"
authors = [
"Nobody <nobody@mozilla.org>",
]
[profile.dev]
panic = "abort"
[profile.release]
panic = "abort"

Просмотреть файл

@ -4,3 +4,9 @@ version = "0.1.0"
authors = [
"Nobody <nobody@mozilla.org>",
]
[profile.dev]
panic = "abort"
[profile.release]
panic = "abort"

Просмотреть файл

@ -0,0 +1,12 @@
[package]
name = "random-crate"
version = "0.1.0"
authors = [
"Nobody <nobody@mozilla.org>",
]
[lib]
crate-type = ["rlib"]
[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('random-crate')

Просмотреть файл

@ -0,0 +1,14 @@
[package]
name = "random-crate"
version = "0.1.0"
authors = [
"Nobody <nobody@mozilla.org>",
]
[lib]
crate-type = ["rlib"]
[profile.dev]
panic = "unwind"
[profile.release]

Просмотреть файл

@ -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('random-crate')

Просмотреть файл

@ -1014,6 +1014,13 @@ class TestEmitterBasic(unittest.TestCase):
'Cargo.toml for.* has no \\[lib\\] section'):
self.read_topsrcdir(reader)
def test_rust_library_no_profile_section(self):
'''Test that a RustLibrary Cargo.toml with no [profile] section fails.'''
reader = self.reader('rust-library-no-profile-section')
with self.assertRaisesRegexp(SandboxValidationError,
'Cargo.toml for.* has no \\[profile\\.dev\\] section'):
self.read_topsrcdir(reader)
def test_rust_library_invalid_crate_type(self):
'''Test that a RustLibrary Cargo.toml has a permitted crate-type.'''
reader = self.reader('rust-library-invalid-crate-type')
@ -1021,6 +1028,13 @@ class TestEmitterBasic(unittest.TestCase):
'crate-type.* is not permitted'):
self.read_topsrcdir(reader)
def test_rust_library_non_abort_panic(self):
'''Test that a RustLibrary Cargo.toml has `panic = "abort" set'''
reader = self.reader('rust-library-non-abort-panic')
with self.assertRaisesRegexp(SandboxValidationError,
'does not specify `panic = "abort"`'):
self.read_topsrcdir(reader)
def test_rust_library_dash_folding(self):
'''Test that on-disk names of RustLibrary objects convert dashes to underscores.'''
reader = self.reader('rust-library-dash-folding',