Bug 1303223 - Ensure that panic = 'abort' is specified for all toplevel Cargo.tomls, r=froydnj
authorMichael Layzell <michael@thelayzells.com>
Tue, 13 Sep 2016 17:03:06 -0400
changeset 314540 11a51ab63f0e1ec13aca6915b4528d528298fc93
parent 314539 665d28dc815d1c1203bcd10e6f74b7259234b9e8
child 314541 c0d14d50b6a043e624a50b6af6721415bb8bebb5
push id81920
push usermichael@thelayzells.com
push dateTue, 20 Sep 2016 17:59:01 +0000
treeherdermozilla-inbound@11a51ab63f0e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1303223
milestone52.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1303223 - Ensure that panic = 'abort' is specified for all toplevel Cargo.tomls, r=froydnj MozReview-Commit-ID: GX0FJjDVA5q
python/mozbuild/mozbuild/frontend/emitter.py
python/mozbuild/mozbuild/test/frontend/data/crate-dependency-path-resolution/Cargo.toml
python/mozbuild/mozbuild/test/frontend/data/rust-library-dash-folding/Cargo.toml
python/mozbuild/mozbuild/test/frontend/data/rust-library-invalid-crate-type/Cargo.toml
python/mozbuild/mozbuild/test/frontend/data/rust-library-name-mismatch/Cargo.toml
python/mozbuild/mozbuild/test/frontend/data/rust-library-no-lib-section/Cargo.toml
python/mozbuild/mozbuild/test/frontend/data/rust-library-no-profile-section/Cargo.toml
python/mozbuild/mozbuild/test/frontend/data/rust-library-no-profile-section/moz.build
python/mozbuild/mozbuild/test/frontend/data/rust-library-non-abort-panic/Cargo.toml
python/mozbuild/mozbuild/test/frontend/data/rust-library-non-abort-panic/moz.build
python/mozbuild/mozbuild/test/frontend/test_emitter.py
--- a/python/mozbuild/mozbuild/frontend/emitter.py
+++ b/python/mozbuild/mozbuild/frontend/emitter.py
@@ -418,16 +418,17 @@ class TreeMetadataEmitter(LoggingMixin):
         config = self._parse_cargo_file(cargo_file)
         crate_name = config['package']['name']
 
         if crate_name != libname:
             raise SandboxValidationError(
                 '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(
                 'Cargo.toml for %s has no [lib] section' % libname,
                 context)
 
         crate_type = lib_section.get('crate-type', None)
         if not crate_type:
@@ -436,16 +437,36 @@ class TreeMetadataEmitter(LoggingMixin):
                 context)
 
         crate_type = crate_type[0]
         if crate_type != 'rlib':
             raise SandboxValidationError(
                 '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)
 
     def _handle_linkables(self, context, passthru, generated_files):
         has_linkables = False
 
         for kind, cls in [('PROGRAM', Program), ('HOST_PROGRAM', HostProgram)]:
             program = context.get(kind)
--- a/python/mozbuild/mozbuild/test/frontend/data/crate-dependency-path-resolution/Cargo.toml
+++ b/python/mozbuild/mozbuild/test/frontend/data/crate-dependency-path-resolution/Cargo.toml
@@ -5,8 +5,14 @@ authors = [
   "Nobody <nobody@mozilla.org>",
 ]
 
 [lib]
 crate-type = ["rlib"]
 
 [dependencies]
 deep-crate = { version = "0.1.0", path = "the/depths" }
+
+[profile.dev]
+panic = "abort"
+
+[profile.release]
+panic = "abort"
--- a/python/mozbuild/mozbuild/test/frontend/data/rust-library-dash-folding/Cargo.toml
+++ b/python/mozbuild/mozbuild/test/frontend/data/rust-library-dash-folding/Cargo.toml
@@ -2,8 +2,14 @@
 name = "random-crate"
 version = "0.1.0"
 authors = [
   "Nobody <nobody@mozilla.org>",
 ]
 
 [lib]
 crate-type = ["rlib"]
+
+[profile.dev]
+panic = "abort"
+
+[profile.release]
+panic = "abort"
--- a/python/mozbuild/mozbuild/test/frontend/data/rust-library-invalid-crate-type/Cargo.toml
+++ b/python/mozbuild/mozbuild/test/frontend/data/rust-library-invalid-crate-type/Cargo.toml
@@ -2,8 +2,14 @@
 name = "random-crate"
 version = "0.1.0"
 authors = [
   "Nobody <nobody@mozilla.org>",
 ]
 
 [lib]
 crate-type = ["dylib"]
+
+[profile.dev]
+panic = "abort"
+
+[profile.release]
+panic = "abort"
--- a/python/mozbuild/mozbuild/test/frontend/data/rust-library-name-mismatch/Cargo.toml
+++ b/python/mozbuild/mozbuild/test/frontend/data/rust-library-name-mismatch/Cargo.toml
@@ -1,6 +1,12 @@
 [package]
 name = "deterministic-crate"
 version = "0.1.0"
 authors = [
   "Nobody <nobody@mozilla.org>",
 ]
+
+[profile.dev]
+panic = "abort"
+
+[profile.release]
+panic = "abort"
--- a/python/mozbuild/mozbuild/test/frontend/data/rust-library-no-lib-section/Cargo.toml
+++ b/python/mozbuild/mozbuild/test/frontend/data/rust-library-no-lib-section/Cargo.toml
@@ -1,6 +1,12 @@
 [package]
 name = "random-crate"
 version = "0.1.0"
 authors = [
   "Nobody <nobody@mozilla.org>",
 ]
+
+[profile.dev]
+panic = "abort"
+
+[profile.release]
+panic = "abort"
new file mode 100644
--- /dev/null
+++ b/python/mozbuild/mozbuild/test/frontend/data/rust-library-no-profile-section/Cargo.toml
@@ -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"
new file mode 100644
--- /dev/null
+++ b/python/mozbuild/mozbuild/test/frontend/data/rust-library-no-profile-section/moz.build
@@ -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')
new file mode 100644
--- /dev/null
+++ b/python/mozbuild/mozbuild/test/frontend/data/rust-library-non-abort-panic/Cargo.toml
@@ -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]
new file mode 100644
--- /dev/null
+++ b/python/mozbuild/mozbuild/test/frontend/data/rust-library-non-abort-panic/moz.build
@@ -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')
\ No newline at end of file
--- a/python/mozbuild/mozbuild/test/frontend/test_emitter.py
+++ b/python/mozbuild/mozbuild/test/frontend/test_emitter.py
@@ -1009,23 +1009,37 @@ class TestEmitterBasic(unittest.TestCase
 
     def test_rust_library_no_lib_section(self):
         '''Test that a RustLibrary Cargo.toml with no [lib] section fails.'''
         reader = self.reader('rust-library-no-lib-section')
         with self.assertRaisesRegexp(SandboxValidationError,
              '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')
         with self.assertRaisesRegexp(SandboxValidationError,
              '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',
                              extra_substs=dict(RUST_TARGET='i686-pc-windows-msvc'))
         objs = self.read_topsrcdir(reader)
 
         self.assertEqual(len(objs), 1)
         lib = objs[0]