mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-08 10:44:56 +00:00
Bug 1293253 - part 10 - emit {Host,}RustProgram objects from the frontend; r=chmanchester
This commit is contained in:
parent
382b44652c
commit
880566d51c
@ -1343,6 +1343,20 @@ VARIABLES = {
|
||||
``HOST_BIN_SUFFIX``, the name will remain unchanged.
|
||||
"""),
|
||||
|
||||
'RUST_PROGRAMS': (StrictOrderingOnAppendList, list,
|
||||
"""Compile a list of Rust host executable names.
|
||||
|
||||
Each name in this variable corresponds to an executable built from
|
||||
the Cargo.toml in the same directory.
|
||||
"""),
|
||||
|
||||
'HOST_RUST_PROGRAMS': (StrictOrderingOnAppendList, list,
|
||||
"""Compile a list of Rust executable names.
|
||||
|
||||
Each name in this variable corresponds to an executable built from
|
||||
the Cargo.toml in the same directory.
|
||||
"""),
|
||||
|
||||
'CONFIGURE_SUBST_FILES': (ContextDerivedTypedList(SourcePath, StrictOrderingOnAppendList), list,
|
||||
"""Output files that will be generated using configure-like substitution.
|
||||
|
||||
|
@ -47,6 +47,7 @@ from .data import (
|
||||
HostDefines,
|
||||
HostLibrary,
|
||||
HostProgram,
|
||||
HostRustProgram,
|
||||
HostSimpleProgram,
|
||||
HostSources,
|
||||
InstallationTarget,
|
||||
@ -62,6 +63,7 @@ from .data import (
|
||||
PreprocessedWebIDLFile,
|
||||
Program,
|
||||
RustLibrary,
|
||||
RustProgram,
|
||||
SdkFiles,
|
||||
SharedLibrary,
|
||||
SimpleProgram,
|
||||
@ -555,6 +557,36 @@ class TreeMetadataEmitter(LoggingMixin):
|
||||
kind.replace('PROGRAM', 'USE_LIBS')))
|
||||
add_program(self._binaries[program], kind)
|
||||
|
||||
all_rust_programs = []
|
||||
for kind, cls in [('RUST_PROGRAMS', RustProgram),
|
||||
('HOST_RUST_PROGRAMS', HostRustProgram)]:
|
||||
programs = context[kind]
|
||||
if not programs:
|
||||
continue
|
||||
|
||||
all_rust_programs.append((programs, kind, cls))
|
||||
|
||||
# Verify Rust program definitions.
|
||||
if all_rust_programs:
|
||||
config, cargo_file = self._parse_cargo_file(context);
|
||||
bin_section = config.get('bin', None)
|
||||
if not bin_section:
|
||||
raise SandboxValidationError(
|
||||
'Cargo.toml in %s has no [bin] section' % context.srcdir,
|
||||
context)
|
||||
|
||||
defined_binaries = {b['name'] for b in bin_section}
|
||||
|
||||
for programs, kind, cls in all_rust_programs:
|
||||
for program in programs:
|
||||
if program not in defined_binaries:
|
||||
raise SandboxValidationError(
|
||||
'Cannot find Cargo.toml definition for %s' % program,
|
||||
context)
|
||||
|
||||
check_unique_binary(program, kind)
|
||||
self._binaries[program] = cls(context, program, cargo_file)
|
||||
|
||||
for kind, cls in [
|
||||
('SIMPLE_PROGRAMS', SimpleProgram),
|
||||
('CPP_UNIT_TESTS', SimpleProgram),
|
||||
|
@ -0,0 +1 @@
|
||||
HOST_RUST_PROGRAMS += ['none']
|
@ -0,0 +1,7 @@
|
||||
[package]
|
||||
authors = ["nobody <nobody@mozilla.org>"]
|
||||
name = "testing"
|
||||
version = "0.0.1"
|
||||
|
||||
[[bin]]
|
||||
name = "some"
|
@ -0,0 +1 @@
|
||||
HOST_RUST_PROGRAMS += ['none']
|
@ -0,0 +1,7 @@
|
||||
[package]
|
||||
authors = ["nobody <nobody@mozilla.org>"]
|
||||
name = "testing"
|
||||
version = "0.0.1"
|
||||
|
||||
[[bin]]
|
||||
name = "some"
|
@ -0,0 +1 @@
|
||||
HOST_RUST_PROGRAMS += ['some']
|
@ -0,0 +1 @@
|
||||
RUST_PROGRAMS += ['none']
|
@ -0,0 +1,7 @@
|
||||
[package]
|
||||
authors = ["nobody <nobody@mozilla.org>"]
|
||||
name = "testing"
|
||||
version = "0.0.1"
|
||||
|
||||
[[bin]]
|
||||
name = "some"
|
@ -0,0 +1 @@
|
||||
RUST_PROGRAMS += ['none']
|
@ -0,0 +1,7 @@
|
||||
[package]
|
||||
authors = ["nobody <nobody@mozilla.org>"]
|
||||
name = "testing"
|
||||
version = "0.0.1"
|
||||
|
||||
[[bin]]
|
||||
name = "some"
|
@ -0,0 +1 @@
|
||||
RUST_PROGRAMS += ['some']
|
@ -27,6 +27,7 @@ from mozbuild.frontend.data import (
|
||||
GeneratedFile,
|
||||
GeneratedSources,
|
||||
HostDefines,
|
||||
HostRustProgram,
|
||||
HostSources,
|
||||
IPDLFile,
|
||||
JARManifest,
|
||||
@ -34,6 +35,7 @@ from mozbuild.frontend.data import (
|
||||
LocalInclude,
|
||||
Program,
|
||||
RustLibrary,
|
||||
RustProgram,
|
||||
SdkFiles,
|
||||
SharedLibrary,
|
||||
SimpleProgram,
|
||||
@ -1081,6 +1083,58 @@ class TestEmitterBasic(unittest.TestCase):
|
||||
'Cannot link multiple Rust libraries'):
|
||||
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')
|
||||
with self.assertRaisesRegexp(SandboxValidationError,
|
||||
'No Cargo.toml file found'):
|
||||
self.read_topsrcdir(reader)
|
||||
|
||||
def test_host_rust_program_no_cargo_toml(self):
|
||||
'''Test that specifying HOST_RUST_PROGRAMS without a Cargo.toml fails.'''
|
||||
reader = self.reader('host-rust-program-no-cargo-toml')
|
||||
with self.assertRaisesRegexp(SandboxValidationError,
|
||||
'No Cargo.toml file found'):
|
||||
self.read_topsrcdir(reader)
|
||||
|
||||
def test_rust_program_nonexistent_name(self):
|
||||
'''Test that specifying RUST_PROGRAMS that don't exist in Cargo.toml
|
||||
correctly throws an error.'''
|
||||
reader = self.reader('rust-program-nonexistent-name')
|
||||
with self.assertRaisesRegexp(SandboxValidationError,
|
||||
'Cannot find Cargo.toml definition for'):
|
||||
self.read_topsrcdir(reader)
|
||||
|
||||
def test_host_rust_program_nonexistent_name(self):
|
||||
'''Test that specifying HOST_RUST_PROGRAMS that don't exist in
|
||||
Cargo.toml correctly throws an error.'''
|
||||
reader = self.reader('host-rust-program-nonexistent-name')
|
||||
with self.assertRaisesRegexp(SandboxValidationError,
|
||||
'Cannot find Cargo.toml definition for'):
|
||||
self.read_topsrcdir(reader)
|
||||
|
||||
def test_rust_programs(self):
|
||||
'''Test RUST_PROGRAMS emission.'''
|
||||
reader = self.reader('rust-programs',
|
||||
extra_substs=dict(RUST_TARGET='i686-pc-windows-msvc',
|
||||
BIN_SUFFIX='.exe'))
|
||||
objs = self.read_topsrcdir(reader)
|
||||
|
||||
self.assertEqual(len(objs), 1)
|
||||
self.assertIsInstance(objs[0], RustProgram)
|
||||
self.assertEqual(objs[0].name, 'some')
|
||||
|
||||
def test_host_rust_programs(self):
|
||||
'''Test HOST_RUST_PROGRAMS emission.'''
|
||||
reader = self.reader('host-rust-programs',
|
||||
extra_substs=dict(RUST_HOST_TARGET='i686-pc-windows-msvc',
|
||||
HOST_BIN_SUFFIX='.exe'))
|
||||
objs = self.read_topsrcdir(reader)
|
||||
|
||||
self.assertEqual(len(objs), 1)
|
||||
self.assertIsInstance(objs[0], HostRustProgram)
|
||||
self.assertEqual(objs[0].name, 'some')
|
||||
|
||||
def test_crate_dependency_path_resolution(self):
|
||||
'''Test recursive dependencies resolve with the correct paths.'''
|
||||
reader = self.reader('crate-dependency-path-resolution',
|
||||
|
Loading…
Reference in New Issue
Block a user