зеркало из https://github.com/mozilla/gecko-dev.git
Backed out 7 changesets (bug 1231764) for apparently causing linux debug wpt bustage
Backed out changeset 4b71272c92cf (bug 1231764) Backed out changeset 234d8a930afa (bug 1231764) Backed out changeset f9b204c2f5a7 (bug 1231764) Backed out changeset f933119e57e4 (bug 1231764) Backed out changeset e3af0b1d3473 (bug 1231764) Backed out changeset 643b03aae1dd (bug 1231764) Backed out changeset a945dbf63410 (bug 1231764) --HG-- extra : rebase_source : e71360fa4b5e3e74859c82e74e183e13e6211c4c
This commit is contained in:
Родитель
9b60f9ebc6
Коммит
9605851be0
|
@ -11,13 +11,7 @@ def rust_compiler_names(value):
|
|||
if value:
|
||||
return ['rustc']
|
||||
|
||||
@depends('--enable-rust')
|
||||
def cargo_binary_names(value):
|
||||
if value:
|
||||
return ['cargo']
|
||||
|
||||
rustc = check_prog('RUSTC', rust_compiler_names, allow_missing=True)
|
||||
cargo = check_prog('CARGO', cargo_binary_names, allow_missing=True)
|
||||
|
||||
@depends_if(rustc)
|
||||
@checking('rustc version', lambda info: info.version)
|
||||
|
@ -29,20 +23,6 @@ def rustc_info(rustc):
|
|||
commit=info.get('commit-hash', 'unknown'),
|
||||
)
|
||||
|
||||
@depends_if(cargo)
|
||||
@checking('cargo support for --frozen')
|
||||
@imports('subprocess')
|
||||
def cargo_supports_frozen(cargo):
|
||||
try:
|
||||
lines = subprocess.check_output(
|
||||
[cargo, 'help', 'build']
|
||||
).splitlines()
|
||||
return any(' --frozen' in l for l in lines)
|
||||
except subprocess.CalledProcessError as e:
|
||||
die('Failed to call cargo: %s', e.message)
|
||||
|
||||
set_config('MOZ_CARGO_SUPPORTS_FROZEN', cargo_supports_frozen)
|
||||
|
||||
@depends('--enable-rust', rustc, rustc_info)
|
||||
@imports(_from='textwrap', _import='dedent')
|
||||
def rust_compiler(value, rustc, rustc_info):
|
||||
|
@ -119,7 +99,10 @@ def rust_target(rust_compiler, rustc, target, cross_compiling):
|
|||
}.get((target.cpu, os_or_kernel), None)
|
||||
|
||||
if rustc_target is None:
|
||||
die("Don't know how to translate {} for rustc".format(target.alias))
|
||||
if cross_compiling:
|
||||
die("Don't know how to translate {} for rustc".format(target.alias))
|
||||
# Fall back to implicit (native) target when not cross-compiling
|
||||
return None
|
||||
|
||||
# Check to see whether our rustc has a reasonably functional stdlib
|
||||
# for our chosen target.
|
||||
|
@ -152,7 +135,7 @@ def rust_target(rust_compiler, rustc, target, cross_compiling):
|
|||
os.remove(in_path)
|
||||
os.remove(out_path)
|
||||
# This target is usable.
|
||||
return rustc_target
|
||||
return target_arg
|
||||
|
||||
set_config('RUST_TARGET', rust_target)
|
||||
|
||||
|
|
|
@ -63,14 +63,6 @@ def Library(name):
|
|||
LIBRARY_NAME = name
|
||||
|
||||
|
||||
@template
|
||||
def RustLibrary(name):
|
||||
'''Template for Rust libraries.'''
|
||||
Library(name)
|
||||
|
||||
IS_RUST_LIBRARY = True
|
||||
|
||||
|
||||
@template
|
||||
def SharedLibrary(name):
|
||||
'''Template for shared libraries.'''
|
||||
|
|
|
@ -36,4 +36,3 @@ futures.pth:python/futures
|
|||
ecc.pth:python/PyECC
|
||||
xpcshell.pth:testing/xpcshell
|
||||
pyyaml.pth:python/pyyaml/lib
|
||||
pytoml.pth:python/pytoml
|
||||
|
|
|
@ -240,9 +240,10 @@ CMOBJS = $(notdir $(CMSRCS:.m=.$(OBJ_SUFFIX)))
|
|||
CMMOBJS = $(notdir $(CMMSRCS:.mm=.$(OBJ_SUFFIX)))
|
||||
# ASFILES can have different extensions (.s, .asm)
|
||||
ASOBJS = $(notdir $(addsuffix .$(OBJ_SUFFIX),$(basename $(ASFILES))))
|
||||
RSOBJS = $(addprefix lib,$(notdir $(RSSRCS:.rs=.rlib)))
|
||||
RS_STATICLIB_CRATE_OBJ = $(addprefix lib,$(notdir $(RS_STATICLIB_CRATE_SRC:.rs=.$(LIB_SUFFIX))))
|
||||
ifndef OBJS
|
||||
_OBJS = $(COBJS) $(SOBJS) $(CPPOBJS) $(CMOBJS) $(CMMOBJS) $(ASOBJS)
|
||||
_OBJS = $(COBJS) $(SOBJS) $(CPPOBJS) $(CMOBJS) $(CMMOBJS) $(ASOBJS) $(RSOBJS) $(RS_STATICLIB_CRATE_OBJ)
|
||||
OBJS = $(strip $(_OBJS))
|
||||
endif
|
||||
|
||||
|
@ -565,7 +566,7 @@ compile:: host target
|
|||
|
||||
host:: $(HOST_LIBRARY) $(HOST_PROGRAM) $(HOST_SIMPLE_PROGRAMS)
|
||||
|
||||
target:: $(LIBRARY) $(SHARED_LIBRARY) $(PROGRAM) $(SIMPLE_PROGRAMS) $(RUST_LIBRARY_FILE)
|
||||
target:: $(LIBRARY) $(SHARED_LIBRARY) $(PROGRAM) $(SIMPLE_PROGRAMS)
|
||||
|
||||
include $(MOZILLA_DIR)/config/makefiles/target_binaries.mk
|
||||
endif
|
||||
|
@ -914,32 +915,16 @@ $(ASOBJS):
|
|||
endif
|
||||
|
||||
ifdef MOZ_RUST
|
||||
ifdef CARGO_FILE
|
||||
|
||||
ifdef MOZ_DEBUG
|
||||
cargo_build_flags =
|
||||
else
|
||||
cargo_build_flags = --release
|
||||
endif
|
||||
ifdef MOZ_CARGO_SUPPORTS_FROZEN
|
||||
cargo_build_flags += --frozen
|
||||
endif
|
||||
|
||||
cargo_build_flags += --manifest-path $(CARGO_FILE)
|
||||
cargo_build_flags += --target=$(RUST_TARGET)
|
||||
|
||||
# Assume any system libraries rustc links against are already in the target's LIBS.
|
||||
#
|
||||
# We need to run cargo unconditionally, because cargo is the only thing that
|
||||
# has full visibility into how changes in Rust sources might affect the final
|
||||
# build.
|
||||
force-cargo-build:
|
||||
# Assume any system libraries rustc links against are already
|
||||
# in the target's LIBS.
|
||||
$(RSOBJS):
|
||||
$(REPORT_BUILD)
|
||||
env CARGO_TARGET_DIR=. RUSTC=$(RUSTC) $(CARGO) build $(cargo_build_flags) --
|
||||
$(RUSTC) $(RUST_TARGET) $(RUSTFLAGS) --crate-type rlib --emit dep-info=$(MDDEPDIR)/$(call mk_libname,$<).pp,link=$(call mk_libname,$<) $(_VPATH_SRCS)
|
||||
|
||||
$(RUST_LIBRARY_FILE): force-cargo-build
|
||||
endif # CARGO_FILE
|
||||
endif # MOZ_RUST
|
||||
$(RS_STATICLIB_CRATE_OBJ):
|
||||
$(REPORT_BUILD)
|
||||
$(RUSTC) $(RUST_TARGET) $(RUSTFLAGS) --crate-type staticlib $(RLIB_EXTERN_CRATE_OPTIONS) --emit dep-info=$(MDDEPDIR)/$(call mk_global_crate_libname,$(RS_STATICLIB_CRATE_SRC)).pp,link=$@ $(RS_STATICLIB_CRATE_SRC)
|
||||
endif
|
||||
|
||||
$(SOBJS):
|
||||
$(REPORT_BUILD)
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
[package]
|
||||
name = "mp4parse-gtest"
|
||||
version = "0.1.0"
|
||||
authors = ["nobody@mozilla.org"]
|
||||
|
||||
[lib]
|
||||
path = "hello.rs"
|
|
@ -37,6 +37,7 @@ if CONFIG['MOZ_WEBM_ENCODER']:
|
|||
]
|
||||
|
||||
if CONFIG['MOZ_RUST']:
|
||||
SOURCES += ['hello.rs',]
|
||||
UNIFIED_SOURCES += ['TestRust.cpp',]
|
||||
|
||||
|
||||
|
|
|
@ -1,26 +0,0 @@
|
|||
--- a/media/libstagefright/binding/mp4parse/Cargo.toml
|
||||
+++ b/media/libstagefright/binding/mp4parse/Cargo.toml
|
||||
@@ -17,23 +17,6 @@ exclude = [
|
||||
"*.mp4",
|
||||
]
|
||||
|
||||
-build = "build.rs"
|
||||
-
|
||||
-[dependencies]
|
||||
-byteorder = "0.5.0"
|
||||
-afl = { version = "0.1.1", optional = true }
|
||||
-afl-plugin = { version = "0.1.1", optional = true }
|
||||
-abort_on_panic = { version = "1.0.0", optional = true }
|
||||
-
|
||||
-[dev-dependencies]
|
||||
-test-assembler = "0.1.2"
|
||||
-
|
||||
-[build-dependencies]
|
||||
-rusty-cheddar = "0.3.2"
|
||||
-
|
||||
-[features]
|
||||
-fuzz = ["afl", "afl-plugin", "abort_on_panic"]
|
||||
-
|
||||
# Somewhat heavy-handed, but we want at least -Z force-overflow-checks=on.
|
||||
[profile.release]
|
||||
debug-assertions = true
|
|
@ -17,6 +17,23 @@ exclude = [
|
|||
"*.mp4",
|
||||
]
|
||||
|
||||
build = "build.rs"
|
||||
|
||||
[dependencies]
|
||||
byteorder = "0.5.0"
|
||||
afl = { version = "0.1.1", optional = true }
|
||||
afl-plugin = { version = "0.1.1", optional = true }
|
||||
abort_on_panic = { version = "1.0.0", optional = true }
|
||||
|
||||
[dev-dependencies]
|
||||
test-assembler = "0.1.2"
|
||||
|
||||
[build-dependencies]
|
||||
rusty-cheddar = "0.3.2"
|
||||
|
||||
[features]
|
||||
fuzz = ["afl", "afl-plugin", "abort_on_panic"]
|
||||
|
||||
# Somewhat heavy-handed, but we want at least -Z force-overflow-checks=on.
|
||||
[profile.release]
|
||||
debug-assertions = true
|
||||
|
|
|
@ -38,7 +38,6 @@ cp _upstream/byteorder/src/new.rs mp4parse/src/byteorder/new.rs
|
|||
echo "Applying patches..."
|
||||
patch -p4 < byteorder-mod.patch
|
||||
patch -p4 < mp4parse-mod.patch
|
||||
patch -p4 < mp4parse-cargo.patch
|
||||
|
||||
echo "Cleaning up..."
|
||||
rm -rf _upstream
|
||||
|
|
|
@ -80,6 +80,9 @@ SOURCES += [
|
|||
]
|
||||
|
||||
if CONFIG['MOZ_RUST']:
|
||||
SOURCES += [
|
||||
'binding/mp4parse/src/lib.rs',
|
||||
]
|
||||
EXPORTS += [
|
||||
'binding/include/mp4parse.h',
|
||||
]
|
||||
|
|
|
@ -30,6 +30,7 @@ from mozbuild.frontend.data import (
|
|||
GeneratedWebIDLFile,
|
||||
PreprocessedTestWebIDLFile,
|
||||
PreprocessedWebIDLFile,
|
||||
RustRlibLibrary,
|
||||
SharedLibrary,
|
||||
TestManifest,
|
||||
TestWebIDLFile,
|
||||
|
|
|
@ -59,7 +59,7 @@ from ..frontend.data import (
|
|||
ObjdirPreprocessedFiles,
|
||||
PerSourceFlag,
|
||||
Program,
|
||||
RustLibrary,
|
||||
RustRlibLibrary,
|
||||
SharedLibrary,
|
||||
SimpleProgram,
|
||||
Sources,
|
||||
|
@ -577,11 +577,9 @@ class RecursiveMakeBackend(CommonBackend):
|
|||
else:
|
||||
return False
|
||||
|
||||
elif isinstance(obj, RustLibrary):
|
||||
self.backend_input_files.add(obj.cargo_file)
|
||||
self._process_rust_library(obj, backend_file)
|
||||
# No need to call _process_linked_libraries, because Rust
|
||||
# libraries are self-contained objects at this point.
|
||||
elif isinstance(obj, RustRlibLibrary):
|
||||
# Nothing to do because |Sources| has done the work for us.
|
||||
pass
|
||||
|
||||
elif isinstance(obj, SharedLibrary):
|
||||
self._process_shared_library(obj, backend_file)
|
||||
|
@ -1164,6 +1162,17 @@ class RecursiveMakeBackend(CommonBackend):
|
|||
if libdef.symbols_file:
|
||||
backend_file.write('SYMBOLS_FILE := %s\n' % libdef.symbols_file)
|
||||
|
||||
rust_rlibs = [o for o in libdef.linked_libraries if isinstance(o, RustRlibLibrary)]
|
||||
if rust_rlibs:
|
||||
# write out Rust file with extern crate declarations.
|
||||
extern_crate_file = mozpath.join(libdef.objdir, 'rul.rs')
|
||||
with self._write_file(extern_crate_file) as f:
|
||||
f.write('// AUTOMATICALLY GENERATED. DO NOT EDIT.\n\n')
|
||||
for rlib in rust_rlibs:
|
||||
f.write('extern crate %s;\n' % rlib.crate_name)
|
||||
|
||||
backend_file.write('RS_STATICLIB_CRATE_SRC := %s\n' % extern_crate_file)
|
||||
|
||||
def _process_static_library(self, libdef, backend_file):
|
||||
backend_file.write_once('LIBRARY_NAME := %s\n' % libdef.basename)
|
||||
backend_file.write('FORCE_STATIC_LIB := 1\n')
|
||||
|
@ -1173,10 +1182,6 @@ class RecursiveMakeBackend(CommonBackend):
|
|||
if libdef.no_expand_lib:
|
||||
backend_file.write('NO_EXPAND_LIBS := 1\n')
|
||||
|
||||
def _process_rust_library(self, libdef, backend_file):
|
||||
backend_file.write_once('RUST_LIBRARY_FILE := %s\n' % libdef.import_name)
|
||||
backend_file.write('CARGO_FILE := $(srcdir)/Cargo.toml')
|
||||
|
||||
def _process_host_library(self, libdef, backend_file):
|
||||
backend_file.write('HOST_LIBRARY_NAME = %s\n' % libdef.basename)
|
||||
|
||||
|
@ -1187,7 +1192,7 @@ class RecursiveMakeBackend(CommonBackend):
|
|||
def _process_linked_libraries(self, obj, backend_file):
|
||||
def write_shared_and_system_libs(lib):
|
||||
for l in lib.linked_libraries:
|
||||
if isinstance(l, (StaticLibrary, RustLibrary)):
|
||||
if isinstance(l, StaticLibrary):
|
||||
write_shared_and_system_libs(l)
|
||||
else:
|
||||
backend_file.write_once('SHARED_LIBS += %s/%s\n'
|
||||
|
@ -1209,15 +1214,14 @@ class RecursiveMakeBackend(CommonBackend):
|
|||
self._build_target_for_obj(lib))
|
||||
relpath = pretty_relpath(lib)
|
||||
if isinstance(obj, Library):
|
||||
if isinstance(lib, RustLibrary):
|
||||
# We don't need to do anything here; we will handle
|
||||
# linkage for any RustLibrary elsewhere.
|
||||
continue
|
||||
elif isinstance(lib, StaticLibrary):
|
||||
if isinstance(lib, StaticLibrary):
|
||||
backend_file.write_once('STATIC_LIBS += %s/%s\n'
|
||||
% (relpath, lib.import_name))
|
||||
if isinstance(obj, SharedLibrary):
|
||||
write_shared_and_system_libs(lib)
|
||||
elif isinstance(lib, RustRlibLibrary):
|
||||
backend_file.write_once('RLIB_EXTERN_CRATE_OPTIONS += --extern %s=%s/%s\n'
|
||||
% (lib.crate_name, relpath, lib.rlib_filename))
|
||||
elif isinstance(obj, SharedLibrary):
|
||||
assert lib.variant != lib.COMPONENT
|
||||
backend_file.write_once('SHARED_LIBS += %s/%s\n'
|
||||
|
@ -1236,28 +1240,13 @@ class RecursiveMakeBackend(CommonBackend):
|
|||
backend_file.write_once('HOST_LIBS += %s/%s\n'
|
||||
% (relpath, lib.import_name))
|
||||
|
||||
# We have to link any Rust libraries after all intermediate static
|
||||
# libraries have been listed to ensure that the Rust libraries are
|
||||
# We have to link the Rust super-crate after all intermediate static
|
||||
# libraries have been listed to ensure that the Rust objects are
|
||||
# searched after the C/C++ objects that might reference Rust symbols.
|
||||
# Building Rust crates normally takes care of Rust->Rust linkage, but
|
||||
# we have to be careful: a savvy user might have specified that there
|
||||
# is a staticlib (that contains the Rust runtime) and several other
|
||||
# rlibs (which are plain archive files) to be linked into a given
|
||||
# library. We need to ensure that the staticlib comes after the
|
||||
# rlibs to ensure symbols are found correctly.
|
||||
if isinstance(obj, SharedLibrary) and any(isinstance(o, RustLibrary)
|
||||
# Building the Rust super-crate will take care of Rust->Rust linkage.
|
||||
if isinstance(obj, SharedLibrary) and any(isinstance(o, RustRlibLibrary)
|
||||
for o in obj.linked_libraries):
|
||||
libs = [l for l in obj.linked_libraries if isinstance(l, RustLibrary)]
|
||||
def name_cmp(l1, l2):
|
||||
if l1.crate_type == 'staticlib':
|
||||
return 1
|
||||
if l2.crate_type == 'staticlib':
|
||||
return -1
|
||||
return cmp(l1.basename, l2.basename)
|
||||
libs.sort(cmp=name_cmp)
|
||||
for l in libs:
|
||||
relpath = pretty_relpath(l)
|
||||
backend_file.write('STATIC_LIBS += %s/%s\n' % (relpath, l.import_name))
|
||||
backend_file.write('STATIC_LIBS += librul.$(LIB_SUFFIX)\n')
|
||||
|
||||
for lib in obj.linked_system_libs:
|
||||
if obj.KIND == 'target':
|
||||
|
@ -1450,6 +1439,7 @@ class RecursiveMakeBackend(CommonBackend):
|
|||
backend_file = self._get_backend_file_for(obj)
|
||||
|
||||
backend_file.write('RS_STATICLIB_CRATE_SRC := %s\n' % extern_crate_file)
|
||||
backend_file.write('STATIC_LIBS += librul.$(LIB_SUFFIX)\n')
|
||||
|
||||
def _handle_ipdl_sources(self, ipdl_dir, sorted_ipdl_sources,
|
||||
unified_ipdl_cppsrcs_mapping):
|
||||
|
|
|
@ -945,13 +945,6 @@ VARIABLES = {
|
|||
|
||||
"""),
|
||||
|
||||
'IS_RUST_LIBRARY': (bool, bool,
|
||||
"""Whether the current library defined by this moz.build is built by Rust.
|
||||
|
||||
The library defined by this moz.build should have a build definition in
|
||||
a Cargo.toml file that exists in this moz.build's directory.
|
||||
"""),
|
||||
|
||||
'UNIFIED_SOURCES': (ContextDerivedTypedList(SourcePath, StrictOrderingOnAppendList), list,
|
||||
"""Source code files that can be compiled together.
|
||||
|
||||
|
|
|
@ -445,6 +445,16 @@ class Library(BaseLibrary):
|
|||
self.is_sdk = is_sdk
|
||||
|
||||
|
||||
class RustRlibLibrary(Library):
|
||||
"""Context derived container object for a Rust rlib"""
|
||||
|
||||
def __init__(self, context, basename, crate_name, rlib_filename, link_into):
|
||||
Library.__init__(self, context, basename)
|
||||
self.crate_name = crate_name
|
||||
self.rlib_filename = rlib_filename
|
||||
self.link_into = link_into
|
||||
|
||||
|
||||
class StaticLibrary(Library):
|
||||
"""Context derived container object for a static library"""
|
||||
__slots__ = (
|
||||
|
@ -459,40 +469,6 @@ class StaticLibrary(Library):
|
|||
self.no_expand_lib = no_expand_lib
|
||||
|
||||
|
||||
class RustLibrary(StaticLibrary):
|
||||
"""Context derived container object for a static library"""
|
||||
__slots__ = (
|
||||
'cargo_file',
|
||||
'crate_type',
|
||||
)
|
||||
|
||||
def __init__(self, context, basename, cargo_file, crate_type, **args):
|
||||
StaticLibrary.__init__(self, context, basename, **args)
|
||||
self.cargo_file = cargo_file
|
||||
self.crate_type = crate_type
|
||||
# We need to adjust our naming here because cargo replaces '-' in
|
||||
# package names defined in Cargo.toml with underscores in actual
|
||||
# filenames. But we need to keep the basename consistent because
|
||||
# many other things in the build system depend on that.
|
||||
assert self.crate_type == 'staticlib'
|
||||
self.lib_name = '%s%s%s' % (
|
||||
context.config.lib_prefix,
|
||||
basename.replace('-', '_'),
|
||||
context.config.lib_suffix
|
||||
)
|
||||
# cargo creates several directories and places its build artifacts
|
||||
# in those directories. The directory structure depends not only
|
||||
# on the target, but also what sort of build we are doing.
|
||||
rust_build_kind = 'release'
|
||||
if context.config.substs.get('MOZ_DEBUG'):
|
||||
rust_build_kind = 'debug'
|
||||
self.import_name = '%s/%s/%s' % (
|
||||
context.config.substs['RUST_TARGET'],
|
||||
rust_build_kind,
|
||||
self.lib_name,
|
||||
)
|
||||
|
||||
|
||||
class SharedLibrary(Library):
|
||||
"""Context derived container object for a shared library"""
|
||||
__slots__ = (
|
||||
|
|
|
@ -20,7 +20,6 @@ from mozbuild.util import (
|
|||
|
||||
import mozpack.path as mozpath
|
||||
import mozinfo
|
||||
import pytoml
|
||||
|
||||
from .data import (
|
||||
AndroidAssetsDirs,
|
||||
|
@ -61,7 +60,7 @@ from .data import (
|
|||
PreprocessedTestWebIDLFile,
|
||||
PreprocessedWebIDLFile,
|
||||
Program,
|
||||
RustLibrary,
|
||||
RustRlibLibrary,
|
||||
SdkFiles,
|
||||
SharedLibrary,
|
||||
SimpleProgram,
|
||||
|
@ -129,8 +128,6 @@ class TreeMetadataEmitter(LoggingMixin):
|
|||
self._binaries = OrderedDict()
|
||||
self._linkage = []
|
||||
self._static_linking_shared = set()
|
||||
self._crate_verified_local = set()
|
||||
self._crate_directories = dict()
|
||||
|
||||
# Keep track of external paths (third party build systems), starting
|
||||
# from what we run a subconfigure in. We'll eliminate some directories
|
||||
|
@ -198,7 +195,7 @@ class TreeMetadataEmitter(LoggingMixin):
|
|||
def _emit_libs_derived(self, contexts):
|
||||
# First do FINAL_LIBRARY linkage.
|
||||
for lib in (l for libs in self._libs.values() for l in libs):
|
||||
if not isinstance(lib, (StaticLibrary, RustLibrary)) or not lib.link_into:
|
||||
if not isinstance(lib, (StaticLibrary, RustRlibLibrary)) or not lib.link_into:
|
||||
continue
|
||||
if lib.link_into not in self._libs:
|
||||
raise SandboxValidationError(
|
||||
|
@ -376,124 +373,6 @@ class TreeMetadataEmitter(LoggingMixin):
|
|||
else:
|
||||
return ExternalSharedLibrary(context, name)
|
||||
|
||||
def _parse_cargo_file(self, toml_file):
|
||||
"""Parse toml_file and return a Python object representation of it."""
|
||||
with open(toml_file, 'r') as f:
|
||||
return pytoml.load(f)
|
||||
|
||||
def _verify_deps(self, context, crate_dir, crate_name, dependencies, description='Dependency'):
|
||||
"""Verify that a crate's dependencies all specify local paths."""
|
||||
for dep_crate_name, values in dependencies.iteritems():
|
||||
# A simple version number.
|
||||
if isinstance(values, (str, unicode)):
|
||||
raise SandboxValidationError(
|
||||
'%s %s of crate %s does not list a path' % (description, dep_crate_name, crate_name),
|
||||
context)
|
||||
|
||||
dep_path = values.get('path', None)
|
||||
if not dep_path:
|
||||
raise SandboxValidationError(
|
||||
'%s %s of crate %s does not list a path' % (description, dep_crate_name, crate_name),
|
||||
context)
|
||||
|
||||
# Try to catch the case where somebody listed a
|
||||
# local path for development.
|
||||
if os.path.isabs(dep_path):
|
||||
raise SandboxValidationError(
|
||||
'%s %s of crate %s has a non-relative path' % (description, dep_crate_name, crate_name),
|
||||
context)
|
||||
|
||||
if not os.path.exists(mozpath.join(context.config.topsrcdir, crate_dir, dep_path)):
|
||||
raise SandboxValidationError(
|
||||
'%s %s of crate %s refers to a non-existent path' % (description, dep_crate_name, crate_name),
|
||||
context)
|
||||
|
||||
def _verify_local_paths(self, context, crate_dir, config):
|
||||
"""Verify that a Cargo.toml config specifies local paths for all its dependencies."""
|
||||
crate_name = config['package']['name']
|
||||
|
||||
# This is not exactly how cargo works (cargo would permit
|
||||
# identically-named packages with different versions in the same
|
||||
# library), but we want to try and avoid using multiple
|
||||
# different versions of a single package for code size reasons.
|
||||
if crate_name not in self._crate_directories:
|
||||
self._crate_directories[crate_name] = crate_dir
|
||||
else:
|
||||
previous_dir = self._crate_directories[crate_name]
|
||||
if crate_dir != previous_dir:
|
||||
raise SandboxValidationError(
|
||||
'Crate %s found at multiple paths: %s, %s' % (crate_name, crate_dir, previous_dir),
|
||||
context)
|
||||
|
||||
# This check should ideally be positioned when we're recursing through
|
||||
# dependencies, but then we would never get the chance to run the
|
||||
# duplicated names check above.
|
||||
if crate_name in self._crate_verified_local:
|
||||
return
|
||||
|
||||
crate_deps = config.get('dependencies', {})
|
||||
if crate_deps:
|
||||
self._verify_deps(context, crate_dir, crate_name, crate_deps)
|
||||
|
||||
has_custom_build = 'build' in config['package']
|
||||
build_deps = config.get('build-dependencies', {})
|
||||
if has_custom_build and build_deps:
|
||||
self._verify_deps(context, crate_dir, crate_name, build_deps,
|
||||
description='Build dependency')
|
||||
|
||||
# We have now verified that all the declared dependencies of
|
||||
# this crate have local paths. Now verify recursively.
|
||||
self._crate_verified_local.add(crate_name)
|
||||
|
||||
if crate_deps:
|
||||
for dep_crate_name, values in crate_deps.iteritems():
|
||||
rel_dep_dir = mozpath.normpath(mozpath.join(crate_dir, values['path']))
|
||||
dep_toml = mozpath.join(context.config.topsrcdir, rel_dep_dir, 'Cargo.toml')
|
||||
self._verify_local_paths(context, rel_dep_dir, self._parse_cargo_file(dep_toml))
|
||||
|
||||
if has_custom_build and build_deps:
|
||||
for dep_crate_name, values in build_deps.iteritems():
|
||||
rel_dep_dir = mozpath.normpath(mozpath.join(crate_dir, values['path']))
|
||||
dep_toml = mozpath.join(context.config.topsrcdir, rel_dep_dir, 'Cargo.toml')
|
||||
self._verify_local_paths(context, rel_dep_dir, self._parse_cargo_file(dep_toml))
|
||||
|
||||
def _rust_library(self, context, libname, static_args):
|
||||
# We need to note any Rust library for linking purposes.
|
||||
cargo_file = mozpath.join(context.srcdir, 'Cargo.toml')
|
||||
if not os.path.exists(cargo_file):
|
||||
raise SandboxValidationError(
|
||||
'No Cargo.toml file found in %s' % cargo_file, context)
|
||||
|
||||
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)
|
||||
|
||||
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:
|
||||
raise SandboxValidationError(
|
||||
'Can\'t determine a crate-type for %s from Cargo.toml' % libname,
|
||||
context)
|
||||
|
||||
crate_type = crate_type[0]
|
||||
if crate_type != 'staticlib':
|
||||
raise SandboxValidationError(
|
||||
'crate-type %s is not permitted for %s' % (crate_type, libname),
|
||||
context)
|
||||
|
||||
self._verify_local_paths(context, context.relsrcdir, config)
|
||||
|
||||
return RustLibrary(context, libname, cargo_file, crate_type, **static_args)
|
||||
|
||||
def _handle_linkables(self, context, passthru, generated_files):
|
||||
has_linkables = False
|
||||
|
||||
|
@ -701,25 +580,9 @@ class TreeMetadataEmitter(LoggingMixin):
|
|||
'generate_symbols_file', lib.symbols_file,
|
||||
[symbols_file], defines)
|
||||
if static_lib:
|
||||
is_rust_library = context.get('IS_RUST_LIBRARY')
|
||||
if is_rust_library:
|
||||
lib = self._rust_library(context, libname, static_args)
|
||||
else:
|
||||
lib = StaticLibrary(context, libname, **static_args)
|
||||
lib = StaticLibrary(context, libname, **static_args)
|
||||
self._libs[libname].append(lib)
|
||||
self._linkage.append((context, lib, 'USE_LIBS'))
|
||||
|
||||
# Multiple staticlibs for a library means multiple copies
|
||||
# of the Rust runtime, which will result in linking errors
|
||||
# later on.
|
||||
if is_rust_library:
|
||||
staticlibs = [l for l in self._libs[libname]
|
||||
if isinstance(l, RustLibrary) and l.crate_type == 'staticlib']
|
||||
if len(staticlibs) > 1:
|
||||
raise SandboxValidationError(
|
||||
'Cannot have multiple Rust staticlibs in %s: %s' % (libname, ', '.join(l.basename for l in staticlibs)),
|
||||
context)
|
||||
|
||||
has_linkables = True
|
||||
|
||||
if lib_defines:
|
||||
|
@ -734,6 +597,7 @@ class TreeMetadataEmitter(LoggingMixin):
|
|||
if not has_linkables:
|
||||
return
|
||||
|
||||
rust_sources = []
|
||||
sources = defaultdict(list)
|
||||
gen_sources = defaultdict(list)
|
||||
all_flags = {}
|
||||
|
@ -785,6 +649,7 @@ class TreeMetadataEmitter(LoggingMixin):
|
|||
'.m': set(),
|
||||
'.mm': set(),
|
||||
'.cpp': set(['.cc', '.cxx']),
|
||||
'.rs': set(),
|
||||
'.S': set(),
|
||||
}
|
||||
|
||||
|
@ -829,8 +694,41 @@ class TreeMetadataEmitter(LoggingMixin):
|
|||
'FILES_PER_UNIFIED_FILE' in context):
|
||||
arglist.append(context['FILES_PER_UNIFIED_FILE'])
|
||||
obj = cls(*arglist)
|
||||
|
||||
# Rust is special. Each Rust file that we compile
|
||||
# is a separate crate and gets compiled into its own
|
||||
# rlib file (Rust's equivalent of a .a file). When
|
||||
# we go to link Rust sources into a library or
|
||||
# executable, we have a separate, single crate that
|
||||
# gets compiled as a staticlib (like a rlib, but
|
||||
# includes the actual Rust runtime).
|
||||
if canonical_suffix == '.rs':
|
||||
if not final_lib:
|
||||
raise SandboxValidationError(
|
||||
'Rust sources must be destined for a FINAL_LIBRARY')
|
||||
# If we're building a shared library, we're going to
|
||||
# auto-generate a module that includes all of the rlib
|
||||
# files. This means we can't permit Rust files as
|
||||
# immediate inputs of the shared library.
|
||||
if libname and shared_lib:
|
||||
raise SandboxValidationError(
|
||||
'No Rust sources permitted as an immediate input of %s: %s' % (shlib, files))
|
||||
rust_sources.append(obj)
|
||||
yield obj
|
||||
|
||||
# Rust sources get translated into rlibs, which are essentially static
|
||||
# libraries. We need to note all of them for linking, too.
|
||||
if libname and static_lib:
|
||||
for s in rust_sources:
|
||||
for f in s.files:
|
||||
(base, _) = mozpath.splitext(mozpath.basename(f))
|
||||
crate_name = context.relsrcdir.replace('/', '_') + '_' + base
|
||||
rlib_filename = 'lib' + base + '.rlib'
|
||||
lib = RustRlibLibrary(context, libname, crate_name,
|
||||
rlib_filename, final_lib)
|
||||
self._libs[libname].append(lib)
|
||||
self._linkage.append((context, lib, 'USE_LIBS'))
|
||||
|
||||
for f, flags in all_flags.iteritems():
|
||||
if flags.flags:
|
||||
ext = mozpath.splitext(f)[1]
|
||||
|
|
|
@ -1,14 +0,0 @@
|
|||
[package]
|
||||
name = "random-crate"
|
||||
version = "0.1.0"
|
||||
authors = [
|
||||
"Nobody <nobody@mozilla.org>",
|
||||
]
|
||||
|
||||
build = "build.rs"
|
||||
|
||||
[lib]
|
||||
crate-type = ["staticlib"]
|
||||
|
||||
[build-dependencies]
|
||||
bogus = { version = "0.1.0", path = "/path/to/somewhere" }
|
|
@ -1,18 +0,0 @@
|
|||
# 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')
|
|
@ -1,14 +0,0 @@
|
|||
[package]
|
||||
name = "random-crate"
|
||||
version = "0.1.0"
|
||||
authors = [
|
||||
"Nobody <nobody@mozilla.org>",
|
||||
]
|
||||
|
||||
build = "build.rs"
|
||||
|
||||
[lib]
|
||||
crate-type = ["staticlib"]
|
||||
|
||||
[build-dependencies]
|
||||
bogus = { version = "0.1.0", path = "../bogus" }
|
|
@ -1,18 +0,0 @@
|
|||
# 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')
|
|
@ -1,12 +0,0 @@
|
|||
[package]
|
||||
name = "random-crate"
|
||||
version = "0.1.0"
|
||||
authors = [
|
||||
"Nobody <nobody@mozilla.org>",
|
||||
]
|
||||
|
||||
[lib]
|
||||
crate-type = ["staticlib"]
|
||||
|
||||
[dependencies]
|
||||
ok = { version = "0.1.0", path = "ok" }
|
|
@ -1,18 +0,0 @@
|
|||
# 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')
|
|
@ -1,11 +0,0 @@
|
|||
[package]
|
||||
name = "ok"
|
||||
version = "0.1.0"
|
||||
authors = [
|
||||
"Nobody <nobody@mozilla.org>",
|
||||
]
|
||||
|
||||
build = "build.rs"
|
||||
|
||||
[build-dependencies]
|
||||
bogus = { version = "0.1.0" }
|
|
@ -1,14 +0,0 @@
|
|||
[package]
|
||||
name = "random-crate"
|
||||
version = "0.1.0"
|
||||
authors = [
|
||||
"Nobody <nobody@mozilla.org>",
|
||||
]
|
||||
|
||||
build = "build.rs"
|
||||
|
||||
[lib]
|
||||
crate-type = ["staticlib"]
|
||||
|
||||
[build-dependencies]
|
||||
bogus = "0.1.0"
|
|
@ -1,18 +0,0 @@
|
|||
# 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')
|
|
@ -1,14 +0,0 @@
|
|||
[package]
|
||||
name = "random-crate"
|
||||
version = "0.1.0"
|
||||
authors = [
|
||||
"Nobody <nobody@mozilla.org>",
|
||||
]
|
||||
|
||||
build = "build.rs"
|
||||
|
||||
[lib]
|
||||
crate-type = ["staticlib"]
|
||||
|
||||
[build-dependencies]
|
||||
bogus = { version = "0.1.0" }
|
|
@ -1,18 +0,0 @@
|
|||
# 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')
|
|
@ -1,12 +0,0 @@
|
|||
[package]
|
||||
name = "random-crate"
|
||||
version = "0.1.0"
|
||||
authors = [
|
||||
"Nobody <nobody@mozilla.org>",
|
||||
]
|
||||
|
||||
[lib]
|
||||
crate-type = ["staticlib"]
|
||||
|
||||
[dependencies]
|
||||
bogus = { version = "0.1.0", path = "/path/to/somewhere" }
|
|
@ -1,18 +0,0 @@
|
|||
# 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')
|
|
@ -1,12 +0,0 @@
|
|||
[package]
|
||||
name = "random-crate"
|
||||
version = "0.1.0"
|
||||
authors = [
|
||||
"Nobody <nobody@mozilla.org>",
|
||||
]
|
||||
|
||||
[lib]
|
||||
crate-type = ["staticlib"]
|
||||
|
||||
[dependencies]
|
||||
bogus = { version = "0.1.0", path = "../bogus" }
|
|
@ -1,18 +0,0 @@
|
|||
# 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')
|
|
@ -1,12 +0,0 @@
|
|||
[package]
|
||||
name = "random-crate"
|
||||
version = "0.1.0"
|
||||
authors = [
|
||||
"Nobody <nobody@mozilla.org>",
|
||||
]
|
||||
|
||||
[lib]
|
||||
crate-type = ["staticlib"]
|
||||
|
||||
[dependencies]
|
||||
deep-crate = { version = "0.1.0", path = "the/depths" }
|
|
@ -1,18 +0,0 @@
|
|||
# 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')
|
|
@ -1,6 +0,0 @@
|
|||
[package]
|
||||
name = "shallow-crate"
|
||||
version = "0.1.0"
|
||||
authors = [
|
||||
"Nobody <nobody@mozilla.org>",
|
||||
]
|
|
@ -1,9 +0,0 @@
|
|||
[package]
|
||||
name = "deep-crate"
|
||||
version = "0.1.0"
|
||||
authors = [
|
||||
"Nobody <nobody@mozilla.org>",
|
||||
]
|
||||
|
||||
[dependencies]
|
||||
shallow-crate = { path = "../../shallow" }
|
|
@ -1,12 +0,0 @@
|
|||
[package]
|
||||
name = "random-crate"
|
||||
version = "0.1.0"
|
||||
authors = [
|
||||
"Nobody <nobody@mozilla.org>",
|
||||
]
|
||||
|
||||
[lib]
|
||||
crate-type = ["staticlib"]
|
||||
|
||||
[dependencies]
|
||||
ok = { version = "0.1.0", path = "ok" }
|
|
@ -1,18 +0,0 @@
|
|||
# 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')
|
|
@ -1,9 +0,0 @@
|
|||
[package]
|
||||
name = "ok"
|
||||
version = "0.1.0"
|
||||
authors = [
|
||||
"Nobody <nobody@mozilla.org>",
|
||||
]
|
||||
|
||||
[dependencies]
|
||||
bogus = { version = "0.1.0" }
|
|
@ -1,12 +0,0 @@
|
|||
[package]
|
||||
name = "random-crate"
|
||||
version = "0.1.0"
|
||||
authors = [
|
||||
"Nobody <nobody@mozilla.org>",
|
||||
]
|
||||
|
||||
[lib]
|
||||
crate-type = ["staticlib"]
|
||||
|
||||
[dependencies]
|
||||
bogus = "0.1.0"
|
|
@ -1,18 +0,0 @@
|
|||
# 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')
|
|
@ -1,12 +0,0 @@
|
|||
[package]
|
||||
name = "random-crate"
|
||||
version = "0.1.0"
|
||||
authors = [
|
||||
"Nobody <nobody@mozilla.org>",
|
||||
]
|
||||
|
||||
[lib]
|
||||
crate-type = ["staticlib"]
|
||||
|
||||
[dependencies]
|
||||
bogus = { version = "0.1.0" }
|
|
@ -1,18 +0,0 @@
|
|||
# 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')
|
|
@ -1,13 +0,0 @@
|
|||
[package]
|
||||
name = "random-crate"
|
||||
version = "0.1.0"
|
||||
authors = [
|
||||
"Nobody <nobody@mozilla.org>",
|
||||
]
|
||||
|
||||
[lib]
|
||||
crate-type = ["staticlib"]
|
||||
|
||||
[dependencies]
|
||||
crate-one = { path = "crate-one" }
|
||||
crate-two = { path = "crate-two" }
|
|
@ -1,9 +0,0 @@
|
|||
[package]
|
||||
name = "crate-one"
|
||||
version = "0.1.0"
|
||||
authors = [
|
||||
"Nobody <nobody@mozilla.org>",
|
||||
]
|
||||
|
||||
[dependencies]
|
||||
duplicate = { path = "duplicate" }
|
|
@ -1,6 +0,0 @@
|
|||
[package]
|
||||
name = "duplicate"
|
||||
version = "0.1.0"
|
||||
authors = [
|
||||
"Nobody <nobody@mozilla.org>",
|
||||
]
|
|
@ -1,9 +0,0 @@
|
|||
[package]
|
||||
name = "crate-two"
|
||||
version = "0.1.0"
|
||||
authors = [
|
||||
"Nobody <nobody@mozilla.org>",
|
||||
]
|
||||
|
||||
[dependencies]
|
||||
duplicate = { path = "duplicate" }
|
|
@ -1,6 +0,0 @@
|
|||
[package]
|
||||
name = "duplicate"
|
||||
version = "0.1.0"
|
||||
authors = [
|
||||
"Nobody <nobody@mozilla.org>",
|
||||
]
|
|
@ -1,18 +0,0 @@
|
|||
# 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')
|
|
@ -1,9 +0,0 @@
|
|||
[package]
|
||||
name = "random-crate"
|
||||
version = "0.1.0"
|
||||
authors = [
|
||||
"Nobody <nobody@mozilla.org>",
|
||||
]
|
||||
|
||||
[lib]
|
||||
crate-type = ["staticlib"]
|
|
@ -1,18 +0,0 @@
|
|||
# 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')
|
|
@ -1,9 +0,0 @@
|
|||
[package]
|
||||
name = "random-crate"
|
||||
version = "0.1.0"
|
||||
authors = [
|
||||
"Nobody <nobody@mozilla.org>",
|
||||
]
|
||||
|
||||
[lib]
|
||||
crate-type = ["dylib"]
|
|
@ -1,18 +0,0 @@
|
|||
# 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')
|
|
@ -1,6 +0,0 @@
|
|||
[package]
|
||||
name = "deterministic-crate"
|
||||
version = "0.1.0"
|
||||
authors = [
|
||||
"Nobody <nobody@mozilla.org>",
|
||||
]
|
|
@ -1,18 +0,0 @@
|
|||
# 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')
|
|
@ -1,18 +0,0 @@
|
|||
# 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')
|
|
@ -1,6 +0,0 @@
|
|||
[package]
|
||||
name = "random-crate"
|
||||
version = "0.1.0"
|
||||
authors = [
|
||||
"Nobody <nobody@mozilla.org>",
|
||||
]
|
|
@ -1,18 +0,0 @@
|
|||
# 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')
|
|
@ -30,7 +30,6 @@ from mozbuild.frontend.data import (
|
|||
JARManifest,
|
||||
LocalInclude,
|
||||
Program,
|
||||
RustLibrary,
|
||||
SdkFiles,
|
||||
SharedLibrary,
|
||||
SimpleProgram,
|
||||
|
@ -993,131 +992,6 @@ class TestEmitterBasic(unittest.TestCase):
|
|||
'Only source directory paths allowed in FINAL_TARGET_PP_FILES:'):
|
||||
self.read_topsrcdir(reader)
|
||||
|
||||
def test_crate_dependency_version_only(self):
|
||||
'''Test that including a crate with a version-only dependency fails.'''
|
||||
reader = self.reader('crate-dependency-version-only')
|
||||
with self.assertRaisesRegexp(SandboxValidationError,
|
||||
'Dependency.*of crate.*does not list a path'):
|
||||
self.read_topsrcdir(reader)
|
||||
|
||||
def test_crate_dependency_with_dict(self):
|
||||
'''Test that including a crate with a dict-using version-only dependency fails.'''
|
||||
reader = self.reader('crate-dependency-with-dict')
|
||||
with self.assertRaisesRegexp(SandboxValidationError,
|
||||
'Dependency.*of crate.*does not list a path'):
|
||||
self.read_topsrcdir(reader)
|
||||
|
||||
def test_crate_dependency_absolute_path(self):
|
||||
'''Test that including a crate with an absolute-path dependency fails.'''
|
||||
reader = self.reader('crate-dependency-absolute-path')
|
||||
with self.assertRaisesRegexp(SandboxValidationError,
|
||||
'Dependency.*of crate.*has a non-relative path'):
|
||||
self.read_topsrcdir(reader)
|
||||
|
||||
def test_crate_dependency_nonexistent_path(self):
|
||||
'''Test that including a crate with a non-existent dependency fails.'''
|
||||
reader = self.reader('crate-dependency-nonexistent-path')
|
||||
with self.assertRaisesRegexp(SandboxValidationError,
|
||||
'Dependency.*of crate.*refers to a non-existent path'):
|
||||
self.read_topsrcdir(reader)
|
||||
|
||||
def test_crate_build_dependency_version_only(self):
|
||||
'''Test that including a crate with a version-only dependency fails.'''
|
||||
reader = self.reader('crate-build-dependency-version-only')
|
||||
with self.assertRaisesRegexp(SandboxValidationError,
|
||||
'Build dependency.*of crate.*does not list a path'):
|
||||
self.read_topsrcdir(reader)
|
||||
|
||||
def test_crate_build_dependency_with_dict(self):
|
||||
'''Test that including a crate with a dict-using version-only dependency fails.'''
|
||||
reader = self.reader('crate-build-dependency-with-dict')
|
||||
with self.assertRaisesRegexp(SandboxValidationError,
|
||||
'Build dependency.*of crate.*does not list a path'):
|
||||
self.read_topsrcdir(reader)
|
||||
|
||||
def test_crate_build_dependency_absolute_path(self):
|
||||
'''Test that including a crate with an absolute-path dependency fails.'''
|
||||
reader = self.reader('crate-build-dependency-absolute-path')
|
||||
with self.assertRaisesRegexp(SandboxValidationError,
|
||||
'Build dependency.*of crate.*has a non-relative path'):
|
||||
self.read_topsrcdir(reader)
|
||||
|
||||
def test_crate_build_dependency_nonexistent_path(self):
|
||||
'''Test that including a crate with a non-existent dependency fails.'''
|
||||
reader = self.reader('crate-build-dependency-nonexistent-path')
|
||||
with self.assertRaisesRegexp(SandboxValidationError,
|
||||
'Build dependency.*of crate.*refers to a non-existent path'):
|
||||
self.read_topsrcdir(reader)
|
||||
|
||||
def test_crate_dependency_recursive(self):
|
||||
reader = self.reader('crate-dependency-recursive')
|
||||
with self.assertRaisesRegexp(SandboxValidationError,
|
||||
'Dependency.*of crate.*does not list a path'):
|
||||
self.read_topsrcdir(reader)
|
||||
|
||||
def test_crate_build_dependency_recursive(self):
|
||||
reader = self.reader('crate-build-dependency-recursive')
|
||||
with self.assertRaisesRegexp(SandboxValidationError,
|
||||
'Build dependency.*of crate.*does not list a path'):
|
||||
self.read_topsrcdir(reader)
|
||||
|
||||
def test_rust_library_no_cargo_toml(self):
|
||||
'''Test that defining a RustLibrary without a Cargo.toml fails.'''
|
||||
reader = self.reader('rust-library-no-cargo-toml')
|
||||
with self.assertRaisesRegexp(SandboxValidationError,
|
||||
'No Cargo.toml file found'):
|
||||
self.read_topsrcdir(reader)
|
||||
|
||||
def test_rust_library_name_mismatch(self):
|
||||
'''Test that defining a RustLibrary that doesn't match Cargo.toml fails.'''
|
||||
reader = self.reader('rust-library-name-mismatch')
|
||||
with self.assertRaisesRegexp(SandboxValidationError,
|
||||
'library.*does not match Cargo.toml-defined package'):
|
||||
self.read_topsrcdir(reader)
|
||||
|
||||
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_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_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]
|
||||
self.assertIsInstance(lib, RustLibrary)
|
||||
self.assertRegexpMatches(lib.lib_name, "random_crate")
|
||||
self.assertRegexpMatches(lib.import_name, "random_crate")
|
||||
self.assertRegexpMatches(lib.basename, "random-crate")
|
||||
|
||||
def test_crate_dependency_path_resolution(self):
|
||||
'''Test recursive dependencies resolve with the correct paths.'''
|
||||
reader = self.reader('crate-dependency-path-resolution',
|
||||
extra_substs=dict(RUST_TARGET='i686-pc-windows-msvc'))
|
||||
objs = self.read_topsrcdir(reader)
|
||||
|
||||
self.assertEqual(len(objs), 1)
|
||||
self.assertIsInstance(objs[0], RustLibrary)
|
||||
|
||||
def test_duplicate_crate_names(self):
|
||||
'''Test that crates are not duplicated in the tree.'''
|
||||
reader = self.reader('duplicated-crate-names')
|
||||
with self.assertRaisesRegexp(SandboxValidationError,
|
||||
'Crate.*found at multiple paths'):
|
||||
self.read_topsrcdir(reader)
|
||||
|
||||
def test_android_res_dirs(self):
|
||||
"""Test that ANDROID_RES_DIRS works properly."""
|
||||
reader = self.reader('android-res-dirs')
|
||||
|
|
|
@ -1,10 +0,0 @@
|
|||
Metadata-Version: 1.0
|
||||
Name: pytoml
|
||||
Version: 0.1.10
|
||||
Summary: A parser for TOML-0.4.0
|
||||
Home-page: https://github.com/avakar/pytoml
|
||||
Author: Martin Vejnár
|
||||
Author-email: avakar@ratatanek.cz
|
||||
License: MIT
|
||||
Description: UNKNOWN
|
||||
Platform: UNKNOWN
|
|
@ -1,3 +0,0 @@
|
|||
from .core import TomlError
|
||||
from .parser import load, loads
|
||||
from .writer import dump, dumps
|
|
@ -1,13 +0,0 @@
|
|||
class TomlError(RuntimeError):
|
||||
def __init__(self, message, line, col, filename):
|
||||
RuntimeError.__init__(self, message, line, col, filename)
|
||||
self.message = message
|
||||
self.line = line
|
||||
self.col = col
|
||||
self.filename = filename
|
||||
|
||||
def __str__(self):
|
||||
return '{}({}, {}): {}'.format(self.filename, self.line, self.col, self.message)
|
||||
|
||||
def __repr__(self):
|
||||
return 'TomlError({!r}, {!r}, {!r}, {!r})'.format(self.message, self.line, self.col, self.filename)
|
|
@ -1,366 +0,0 @@
|
|||
import string, re, sys, datetime
|
||||
from .core import TomlError
|
||||
|
||||
if sys.version_info[0] == 2:
|
||||
_chr = unichr
|
||||
else:
|
||||
_chr = chr
|
||||
|
||||
def load(fin, translate=lambda t, x, v: v):
|
||||
return loads(fin.read(), translate=translate, filename=fin.name)
|
||||
|
||||
def loads(s, filename='<string>', translate=lambda t, x, v: v):
|
||||
if isinstance(s, bytes):
|
||||
s = s.decode('utf-8')
|
||||
|
||||
s = s.replace('\r\n', '\n')
|
||||
|
||||
root = {}
|
||||
tables = {}
|
||||
scope = root
|
||||
|
||||
src = _Source(s, filename=filename)
|
||||
ast = _p_toml(src)
|
||||
|
||||
def error(msg):
|
||||
raise TomlError(msg, pos[0], pos[1], filename)
|
||||
|
||||
def process_value(v):
|
||||
kind, text, value, pos = v
|
||||
if kind == 'str' and value.startswith('\n'):
|
||||
value = value[1:]
|
||||
if kind == 'array':
|
||||
if value and any(k != value[0][0] for k, t, v, p in value[1:]):
|
||||
error('array-type-mismatch')
|
||||
value = [process_value(item) for item in value]
|
||||
elif kind == 'table':
|
||||
value = dict([(k, process_value(value[k])) for k in value])
|
||||
return translate(kind, text, value)
|
||||
|
||||
for kind, value, pos in ast:
|
||||
if kind == 'kv':
|
||||
k, v = value
|
||||
if k in scope:
|
||||
error('duplicate_keys. Key "{0}" was used more than once.'.format(k))
|
||||
scope[k] = process_value(v)
|
||||
else:
|
||||
is_table_array = (kind == 'table_array')
|
||||
cur = tables
|
||||
for name in value[:-1]:
|
||||
if isinstance(cur.get(name), list):
|
||||
d, cur = cur[name][-1]
|
||||
else:
|
||||
d, cur = cur.setdefault(name, (None, {}))
|
||||
|
||||
scope = {}
|
||||
name = value[-1]
|
||||
if name not in cur:
|
||||
if is_table_array:
|
||||
cur[name] = [(scope, {})]
|
||||
else:
|
||||
cur[name] = (scope, {})
|
||||
elif isinstance(cur[name], list):
|
||||
if not is_table_array:
|
||||
error('table_type_mismatch')
|
||||
cur[name].append((scope, {}))
|
||||
else:
|
||||
if is_table_array:
|
||||
error('table_type_mismatch')
|
||||
old_scope, next_table = cur[name]
|
||||
if old_scope is not None:
|
||||
error('duplicate_tables')
|
||||
cur[name] = (scope, next_table)
|
||||
|
||||
def merge_tables(scope, tables):
|
||||
if scope is None:
|
||||
scope = {}
|
||||
for k in tables:
|
||||
if k in scope:
|
||||
error('key_table_conflict')
|
||||
v = tables[k]
|
||||
if isinstance(v, list):
|
||||
scope[k] = [merge_tables(sc, tbl) for sc, tbl in v]
|
||||
else:
|
||||
scope[k] = merge_tables(v[0], v[1])
|
||||
return scope
|
||||
|
||||
return merge_tables(root, tables)
|
||||
|
||||
class _Source:
|
||||
def __init__(self, s, filename=None):
|
||||
self.s = s
|
||||
self._pos = (1, 1)
|
||||
self._last = None
|
||||
self._filename = filename
|
||||
self.backtrack_stack = []
|
||||
|
||||
def last(self):
|
||||
return self._last
|
||||
|
||||
def pos(self):
|
||||
return self._pos
|
||||
|
||||
def fail(self):
|
||||
return self._expect(None)
|
||||
|
||||
def consume_dot(self):
|
||||
if self.s:
|
||||
self._last = self.s[0]
|
||||
self.s = self[1:]
|
||||
self._advance(self._last)
|
||||
return self._last
|
||||
return None
|
||||
|
||||
def expect_dot(self):
|
||||
return self._expect(self.consume_dot())
|
||||
|
||||
def consume_eof(self):
|
||||
if not self.s:
|
||||
self._last = ''
|
||||
return True
|
||||
return False
|
||||
|
||||
def expect_eof(self):
|
||||
return self._expect(self.consume_eof())
|
||||
|
||||
def consume(self, s):
|
||||
if self.s.startswith(s):
|
||||
self.s = self.s[len(s):]
|
||||
self._last = s
|
||||
self._advance(s)
|
||||
return True
|
||||
return False
|
||||
|
||||
def expect(self, s):
|
||||
return self._expect(self.consume(s))
|
||||
|
||||
def consume_re(self, re):
|
||||
m = re.match(self.s)
|
||||
if m:
|
||||
self.s = self.s[len(m.group(0)):]
|
||||
self._last = m
|
||||
self._advance(m.group(0))
|
||||
return m
|
||||
return None
|
||||
|
||||
def expect_re(self, re):
|
||||
return self._expect(self.consume_re(re))
|
||||
|
||||
def __enter__(self):
|
||||
self.backtrack_stack.append((self.s, self._pos))
|
||||
|
||||
def __exit__(self, type, value, traceback):
|
||||
if type is None:
|
||||
self.backtrack_stack.pop()
|
||||
else:
|
||||
self.s, self._pos = self.backtrack_stack.pop()
|
||||
return type == TomlError
|
||||
|
||||
def commit(self):
|
||||
self.backtrack_stack[-1] = (self.s, self._pos)
|
||||
|
||||
def _expect(self, r):
|
||||
if not r:
|
||||
raise TomlError('msg', self._pos[0], self._pos[1], self._filename)
|
||||
return r
|
||||
|
||||
def _advance(self, s):
|
||||
suffix_pos = s.rfind('\n')
|
||||
if suffix_pos == -1:
|
||||
self._pos = (self._pos[0], self._pos[1] + len(s))
|
||||
else:
|
||||
self._pos = (self._pos[0] + s.count('\n'), len(s) - suffix_pos)
|
||||
|
||||
_ews_re = re.compile(r'(?:[ \t]|#[^\n]*\n|#[^\n]*\Z|\n)*')
|
||||
def _p_ews(s):
|
||||
s.expect_re(_ews_re)
|
||||
|
||||
_ws_re = re.compile(r'[ \t]*')
|
||||
def _p_ws(s):
|
||||
s.expect_re(_ws_re)
|
||||
|
||||
_escapes = { 'b': '\b', 'n': '\n', 'r': '\r', 't': '\t', '"': '"', '\'': '\'',
|
||||
'\\': '\\', '/': '/', 'f': '\f' }
|
||||
|
||||
_basicstr_re = re.compile(r'[^"\\\000-\037]*')
|
||||
_short_uni_re = re.compile(r'u([0-9a-fA-F]{4})')
|
||||
_long_uni_re = re.compile(r'U([0-9a-fA-F]{8})')
|
||||
_escapes_re = re.compile('[bnrt"\'\\\\/f]')
|
||||
_newline_esc_re = re.compile('\n[ \t\n]*')
|
||||
def _p_basicstr_content(s, content=_basicstr_re):
|
||||
res = []
|
||||
while True:
|
||||
res.append(s.expect_re(content).group(0))
|
||||
if not s.consume('\\'):
|
||||
break
|
||||
if s.consume_re(_newline_esc_re):
|
||||
pass
|
||||
elif s.consume_re(_short_uni_re) or s.consume_re(_long_uni_re):
|
||||
res.append(_chr(int(s.last().group(1), 16)))
|
||||
else:
|
||||
s.expect_re(_escapes_re)
|
||||
res.append(_escapes[s.last().group(0)])
|
||||
return ''.join(res)
|
||||
|
||||
_key_re = re.compile(r'[0-9a-zA-Z-_]+')
|
||||
def _p_key(s):
|
||||
with s:
|
||||
s.expect('"')
|
||||
r = _p_basicstr_content(s, _basicstr_re)
|
||||
s.expect('"')
|
||||
return r
|
||||
return s.expect_re(_key_re).group(0)
|
||||
|
||||
_float_re = re.compile(r'[+-]?(?:0|[1-9](?:_?\d)*)(?:\.\d(?:_?\d)*)?(?:[eE][+-]?(?:\d(?:_?\d)*))?')
|
||||
_datetime_re = re.compile(r'(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(\.\d+)?(?:Z|([+-]\d{2}):(\d{2}))')
|
||||
|
||||
_basicstr_ml_re = re.compile(r'(?:(?:|"|"")[^"\\\000-\011\013-\037])*')
|
||||
_litstr_re = re.compile(r"[^'\000-\037]*")
|
||||
_litstr_ml_re = re.compile(r"(?:(?:|'|'')(?:[^'\000-\011\013-\037]))*")
|
||||
def _p_value(s):
|
||||
pos = s.pos()
|
||||
|
||||
if s.consume('true'):
|
||||
return 'bool', s.last(), True, pos
|
||||
if s.consume('false'):
|
||||
return 'bool', s.last(), False, pos
|
||||
|
||||
if s.consume('"'):
|
||||
if s.consume('""'):
|
||||
r = _p_basicstr_content(s, _basicstr_ml_re)
|
||||
s.expect('"""')
|
||||
else:
|
||||
r = _p_basicstr_content(s, _basicstr_re)
|
||||
s.expect('"')
|
||||
return 'str', r, r, pos
|
||||
|
||||
if s.consume('\''):
|
||||
if s.consume('\'\''):
|
||||
r = s.expect_re(_litstr_ml_re).group(0)
|
||||
s.expect('\'\'\'')
|
||||
else:
|
||||
r = s.expect_re(_litstr_re).group(0)
|
||||
s.expect('\'')
|
||||
return 'str', r, r, pos
|
||||
|
||||
if s.consume_re(_datetime_re):
|
||||
m = s.last()
|
||||
s0 = m.group(0)
|
||||
r = map(int, m.groups()[:6])
|
||||
if m.group(7):
|
||||
micro = float(m.group(7))
|
||||
else:
|
||||
micro = 0
|
||||
|
||||
if m.group(8):
|
||||
g = int(m.group(8), 10) * 60 + int(m.group(9), 10)
|
||||
tz = _TimeZone(datetime.timedelta(0, g * 60))
|
||||
else:
|
||||
tz = _TimeZone(datetime.timedelta(0, 0))
|
||||
|
||||
y, m, d, H, M, S = r
|
||||
dt = datetime.datetime(y, m, d, H, M, S, int(micro * 1000000), tz)
|
||||
return 'datetime', s0, dt, pos
|
||||
|
||||
if s.consume_re(_float_re):
|
||||
m = s.last().group(0)
|
||||
r = m.replace('_','')
|
||||
if '.' in m or 'e' in m or 'E' in m:
|
||||
return 'float', m, float(r), pos
|
||||
else:
|
||||
return 'int', m, int(r, 10), pos
|
||||
|
||||
if s.consume('['):
|
||||
items = []
|
||||
with s:
|
||||
while True:
|
||||
_p_ews(s)
|
||||
items.append(_p_value(s))
|
||||
s.commit()
|
||||
_p_ews(s)
|
||||
s.expect(',')
|
||||
s.commit()
|
||||
_p_ews(s)
|
||||
s.expect(']')
|
||||
return 'array', None, items, pos
|
||||
|
||||
if s.consume('{'):
|
||||
_p_ws(s)
|
||||
items = {}
|
||||
if not s.consume('}'):
|
||||
k = _p_key(s)
|
||||
_p_ws(s)
|
||||
s.expect('=')
|
||||
_p_ws(s)
|
||||
items[k] = _p_value(s)
|
||||
_p_ws(s)
|
||||
while s.consume(','):
|
||||
_p_ws(s)
|
||||
k = _p_key(s)
|
||||
_p_ws(s)
|
||||
s.expect('=')
|
||||
_p_ws(s)
|
||||
items[k] = _p_value(s)
|
||||
_p_ws(s)
|
||||
s.expect('}')
|
||||
return 'table', None, items, pos
|
||||
|
||||
s.fail()
|
||||
|
||||
def _p_stmt(s):
|
||||
pos = s.pos()
|
||||
if s.consume( '['):
|
||||
is_array = s.consume('[')
|
||||
_p_ws(s)
|
||||
keys = [_p_key(s)]
|
||||
_p_ws(s)
|
||||
while s.consume('.'):
|
||||
_p_ws(s)
|
||||
keys.append(_p_key(s))
|
||||
_p_ws(s)
|
||||
s.expect(']')
|
||||
if is_array:
|
||||
s.expect(']')
|
||||
return 'table_array' if is_array else 'table', keys, pos
|
||||
|
||||
key = _p_key(s)
|
||||
_p_ws(s)
|
||||
s.expect('=')
|
||||
_p_ws(s)
|
||||
value = _p_value(s)
|
||||
return 'kv', (key, value), pos
|
||||
|
||||
_stmtsep_re = re.compile(r'(?:[ \t]*(?:#[^\n]*)?\n)+[ \t]*')
|
||||
def _p_toml(s):
|
||||
stmts = []
|
||||
_p_ews(s)
|
||||
with s:
|
||||
stmts.append(_p_stmt(s))
|
||||
while True:
|
||||
s.commit()
|
||||
s.expect_re(_stmtsep_re)
|
||||
stmts.append(_p_stmt(s))
|
||||
_p_ews(s)
|
||||
s.expect_eof()
|
||||
return stmts
|
||||
|
||||
class _TimeZone(datetime.tzinfo):
|
||||
def __init__(self, offset):
|
||||
self._offset = offset
|
||||
|
||||
def utcoffset(self, dt):
|
||||
return self._offset
|
||||
|
||||
def dst(self, dt):
|
||||
return None
|
||||
|
||||
def tzname(self, dt):
|
||||
m = self._offset.total_seconds() // 60
|
||||
if m < 0:
|
||||
res = '-'
|
||||
m = -m
|
||||
else:
|
||||
res = '+'
|
||||
h = m // 60
|
||||
m = m - h * 60
|
||||
return '{}{:.02}{:.02}'.format(res, h, m)
|
|
@ -1,120 +0,0 @@
|
|||
from __future__ import unicode_literals
|
||||
import io, datetime, sys
|
||||
|
||||
if sys.version_info[0] == 3:
|
||||
long = int
|
||||
unicode = str
|
||||
|
||||
|
||||
def dumps(obj, sort_keys=False):
|
||||
fout = io.StringIO()
|
||||
dump(fout, obj, sort_keys=sort_keys)
|
||||
return fout.getvalue()
|
||||
|
||||
|
||||
_escapes = {'\n': 'n', '\r': 'r', '\\': '\\', '\t': 't', '\b': 'b', '\f': 'f', '"': '"'}
|
||||
|
||||
|
||||
def _escape_string(s):
|
||||
res = []
|
||||
start = 0
|
||||
|
||||
def flush():
|
||||
if start != i:
|
||||
res.append(s[start:i])
|
||||
return i + 1
|
||||
|
||||
i = 0
|
||||
while i < len(s):
|
||||
c = s[i]
|
||||
if c in '"\\\n\r\t\b\f':
|
||||
start = flush()
|
||||
res.append('\\' + _escapes[c])
|
||||
elif ord(c) < 0x20:
|
||||
start = flush()
|
||||
res.append('\\u%04x' % ord(c))
|
||||
i += 1
|
||||
|
||||
flush()
|
||||
return '"' + ''.join(res) + '"'
|
||||
|
||||
|
||||
def _escape_id(s):
|
||||
if any(not c.isalnum() and c not in '-_' for c in s):
|
||||
return _escape_string(s)
|
||||
return s
|
||||
|
||||
|
||||
def _format_list(v):
|
||||
return '[{0}]'.format(', '.join(_format_value(obj) for obj in v))
|
||||
|
||||
# Formula from:
|
||||
# https://docs.python.org/2/library/datetime.html#datetime.timedelta.total_seconds
|
||||
# Once support for py26 is dropped, this can be replaced by td.total_seconds()
|
||||
def _total_seconds(td):
|
||||
return ((td.microseconds
|
||||
+ (td.seconds + td.days * 24 * 3600) * 10**6) / 10.0**6)
|
||||
|
||||
def _format_value(v):
|
||||
if isinstance(v, bool):
|
||||
return 'true' if v else 'false'
|
||||
if isinstance(v, int) or isinstance(v, long):
|
||||
return unicode(v)
|
||||
if isinstance(v, float):
|
||||
return '{0:.17f}'.format(v)
|
||||
elif isinstance(v, unicode) or isinstance(v, bytes):
|
||||
return _escape_string(v)
|
||||
elif isinstance(v, datetime.datetime):
|
||||
offs = v.utcoffset()
|
||||
offs = _total_seconds(offs) // 60 if offs is not None else 0
|
||||
|
||||
if offs == 0:
|
||||
suffix = 'Z'
|
||||
else:
|
||||
if offs > 0:
|
||||
suffix = '+'
|
||||
else:
|
||||
suffix = '-'
|
||||
offs = -offs
|
||||
suffix = '{0}{1:.02}{2:.02}'.format(suffix, offs // 60, offs % 60)
|
||||
|
||||
if v.microsecond:
|
||||
return v.strftime('%Y-%m-%dT%H:%M:%S.%f') + suffix
|
||||
else:
|
||||
return v.strftime('%Y-%m-%dT%H:%M:%S') + suffix
|
||||
elif isinstance(v, list):
|
||||
return _format_list(v)
|
||||
else:
|
||||
raise RuntimeError(v)
|
||||
|
||||
|
||||
def dump(fout, obj, sort_keys=False):
|
||||
tables = [((), obj, False)]
|
||||
|
||||
while tables:
|
||||
if sort_keys:
|
||||
tables.sort(key=lambda tup: tup[0], reverse=True)
|
||||
name, table, is_array = tables.pop()
|
||||
if name:
|
||||
section_name = '.'.join(_escape_id(c) for c in name)
|
||||
if is_array:
|
||||
fout.write('[[{0}]]\n'.format(section_name))
|
||||
else:
|
||||
fout.write('[{0}]\n'.format(section_name))
|
||||
|
||||
table_keys = sorted(table.keys()) if sort_keys else table.keys()
|
||||
for k in table_keys:
|
||||
v = table[k]
|
||||
if isinstance(v, dict):
|
||||
tables.append((name + (k,), v, False))
|
||||
elif isinstance(v, list) and v and all(isinstance(o, dict) for o in v):
|
||||
tables.extend((name + (k,), d, True) for d in reversed(v))
|
||||
elif v is None:
|
||||
# based on mojombo's comment: https://github.com/toml-lang/toml/issues/146#issuecomment-25019344
|
||||
fout.write(
|
||||
'#{} = null # To use: uncomment and replace null with value\n'.format(_escape_id(k)))
|
||||
else:
|
||||
fout.write('{0} = {1}\n'.format(_escape_id(k), _format_value(v)))
|
||||
|
||||
if tables:
|
||||
fout.write('\n')
|
|
@ -1,5 +0,0 @@
|
|||
[egg_info]
|
||||
tag_build =
|
||||
tag_date = 0
|
||||
tag_svn_revision = 0
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
# coding: utf-8
|
||||
|
||||
from setuptools import setup
|
||||
|
||||
setup(
|
||||
name='pytoml',
|
||||
version='0.1.10',
|
||||
|
||||
description='A parser for TOML-0.4.0',
|
||||
author='Martin Vejnár',
|
||||
author_email='avakar@ratatanek.cz',
|
||||
url='https://github.com/avakar/pytoml',
|
||||
license='MIT',
|
||||
|
||||
packages=['pytoml'],
|
||||
)
|
|
@ -1,100 +0,0 @@
|
|||
import os, json, sys, io, traceback, argparse
|
||||
import pytoml as toml
|
||||
|
||||
# Formula from:
|
||||
# https://docs.python.org/2/library/datetime.html#datetime.timedelta.total_seconds
|
||||
# Once support for py26 is dropped, this can be replaced by td.total_seconds()
|
||||
def _total_seconds(td):
|
||||
return ((td.microseconds
|
||||
+ (td.seconds + td.days * 24 * 3600) * 10**6) / 10.0**6)
|
||||
|
||||
def _testbench_literal(type, text, value):
|
||||
if type == 'table':
|
||||
return value
|
||||
if type == 'array':
|
||||
return { 'type': 'array', 'value': value }
|
||||
if type == 'datetime':
|
||||
offs = _total_seconds(value.tzinfo.utcoffset(value)) // 60
|
||||
offs = 'Z' if offs == 0 else '{}{}:{}'.format('-' if offs < 0 else '-', abs(offs) // 60, abs(offs) % 60)
|
||||
v = '{0:04}-{1:02}-{2:02}T{3:02}:{4:02}:{5:02}{6}'.format(value.year, value.month, value.day, value.hour, value.minute, value.second, offs)
|
||||
return { 'type': 'datetime', 'value': v }
|
||||
if type == 'bool':
|
||||
return { 'type': 'bool', 'value': 'true' if value else 'false' }
|
||||
if type == 'float':
|
||||
return { 'type': 'float', 'value': value }
|
||||
if type == 'str':
|
||||
return { 'type': 'string', 'value': value }
|
||||
if type == 'int':
|
||||
return { 'type': 'integer', 'value': str(value) }
|
||||
|
||||
def adjust_bench(v):
|
||||
if isinstance(v, dict):
|
||||
if v.get('type') == 'float':
|
||||
v['value'] = float(v['value'])
|
||||
return v
|
||||
return dict([(k, adjust_bench(v[k])) for k in v])
|
||||
if isinstance(v, list):
|
||||
return [adjust_bench(v) for v in v]
|
||||
return v
|
||||
|
||||
def _main():
|
||||
ap = argparse.ArgumentParser()
|
||||
ap.add_argument('-d', '--dir', action='append')
|
||||
ap.add_argument('testcase', nargs='*')
|
||||
args = ap.parse_args()
|
||||
|
||||
if not args.dir:
|
||||
args.dir = [os.path.join(os.path.split(__file__)[0], 'toml-test/tests')]
|
||||
|
||||
succeeded = []
|
||||
failed = []
|
||||
|
||||
for path in args.dir:
|
||||
if not os.path.isdir(path):
|
||||
print('error: not a dir: {0}'.format(path))
|
||||
return 2
|
||||
for top, dirnames, fnames in os.walk(path):
|
||||
for fname in fnames:
|
||||
if not fname.endswith('.toml'):
|
||||
continue
|
||||
|
||||
if args.testcase and not any(arg in fname for arg in args.testcase):
|
||||
continue
|
||||
|
||||
parse_error = None
|
||||
try:
|
||||
with open(os.path.join(top, fname), 'rb') as fin:
|
||||
parsed = toml.load(fin)
|
||||
except toml.TomlError:
|
||||
parsed = None
|
||||
parse_error = sys.exc_info()
|
||||
else:
|
||||
dumped = toml.dumps(parsed)
|
||||
parsed2 = toml.loads(dumped)
|
||||
if parsed != parsed2:
|
||||
failed.append((fname, None))
|
||||
continue
|
||||
|
||||
with open(os.path.join(top, fname), 'rb') as fin:
|
||||
parsed = toml.load(fin, translate=_testbench_literal)
|
||||
|
||||
try:
|
||||
with io.open(os.path.join(top, fname[:-5] + '.json'), 'rt', encoding='utf-8') as fin:
|
||||
bench = json.load(fin)
|
||||
except IOError:
|
||||
bench = None
|
||||
|
||||
if parsed != adjust_bench(bench):
|
||||
failed.append((fname, parsed, bench, parse_error))
|
||||
else:
|
||||
succeeded.append(fname)
|
||||
|
||||
for f, parsed, bench, e in failed:
|
||||
print('failed: {}\n{}\n{}'.format(f, json.dumps(parsed, indent=4), json.dumps(bench, indent=4)))
|
||||
if e:
|
||||
traceback.print_exception(*e)
|
||||
print('succeeded: {0}'.format(len(succeeded)))
|
||||
return 1 if failed or not succeeded else 0
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(_main())
|
|
@ -11,8 +11,3 @@ FINAL_TARGET = 'dist/bin/gtest'
|
|||
USE_LIBS += [
|
||||
'static:xul',
|
||||
]
|
||||
|
||||
if CONFIG['MOZ_RUST']:
|
||||
USE_LIBS += [
|
||||
'gkrust-gtest',
|
||||
]
|
||||
|
|
|
@ -1,11 +0,0 @@
|
|||
[root]
|
||||
name = "gkrust-gtest"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"mp4parse-gtest 0.1.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "mp4parse-gtest"
|
||||
version = "0.1.0"
|
||||
|
|
@ -1,36 +0,0 @@
|
|||
[package]
|
||||
name = "gkrust-gtest"
|
||||
version = "0.1.0"
|
||||
authors = ["nobody@mozilla.org"]
|
||||
license = "MPL-2.0"
|
||||
description = "Testing code for libgkrust"
|
||||
|
||||
[dependencies]
|
||||
mp4parse-gtest = { path = "../../../../dom/media/gtest" }
|
||||
|
||||
[lib]
|
||||
path = "lib.rs"
|
||||
crate-type = ["staticlib"]
|
||||
test = false
|
||||
doctest = false
|
||||
bench = false
|
||||
doc = false
|
||||
plugin = false
|
||||
harness = false
|
||||
|
||||
# Explicitly specify what our profiles use.
|
||||
[profile.dev]
|
||||
opt-level = 0
|
||||
debug = true
|
||||
rpath = false
|
||||
lto = false
|
||||
debug-assertions = true
|
||||
codegen-units = 1
|
||||
|
||||
[profile.release]
|
||||
opt-level = 2
|
||||
debug = true
|
||||
rpath = false
|
||||
lto = false
|
||||
debug-assertions = false
|
||||
codegen-units = 1
|
|
@ -1,5 +0,0 @@
|
|||
// This Source Code Form is subject to the terms of the Mozilla Public
|
||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
extern crate mp4parse_gtest;
|
|
@ -1,7 +0,0 @@
|
|||
# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
|
||||
# vim: set filetype=python:
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
RustLibrary('gkrust-gtest')
|
|
@ -384,11 +384,5 @@ if CONFIG['COMPILE_ENVIRONMENT']:
|
|||
]
|
||||
FINAL_TARGET_FILES += ['!dependentlibs.list']
|
||||
|
||||
# This library needs to be last to make XPCOM module registration work.
|
||||
# This needs to be last
|
||||
USE_LIBS += ['StaticXULComponentsEnd']
|
||||
|
||||
# The above library needs to be last for C++ purposes. This library,
|
||||
# however, is entirely composed of Rust code, and needs to come after
|
||||
# all the C++ code so any possible C++ -> Rust calls can be resolved.
|
||||
if CONFIG['MOZ_RUST']:
|
||||
USE_LIBS += ['gkrust']
|
||||
|
|
|
@ -1,11 +0,0 @@
|
|||
[root]
|
||||
name = "gkrust"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"mp4parse 0.4.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "mp4parse"
|
||||
version = "0.4.0"
|
||||
|
|
@ -1,36 +0,0 @@
|
|||
[package]
|
||||
name = "gkrust"
|
||||
version = "0.1.0"
|
||||
authors = ["nobody@mozilla.org"]
|
||||
license = "MPL-2.0"
|
||||
description = "Rust code for libxul"
|
||||
|
||||
[dependencies]
|
||||
mp4parse = { path = "../../../media/libstagefright/binding/mp4parse" }
|
||||
|
||||
[lib]
|
||||
path = "lib.rs"
|
||||
crate-type = ["staticlib"]
|
||||
test = false
|
||||
doctest = false
|
||||
bench = false
|
||||
doc = false
|
||||
plugin = false
|
||||
harness = false
|
||||
|
||||
# Explicitly specify what our profiles use.
|
||||
[profile.dev]
|
||||
opt-level = 0
|
||||
debug = true
|
||||
rpath = false
|
||||
lto = false
|
||||
debug-assertions = true
|
||||
codegen-units = 1
|
||||
|
||||
[profile.release]
|
||||
opt-level = 2
|
||||
debug = true
|
||||
rpath = false
|
||||
lto = false
|
||||
debug-assertions = false
|
||||
codegen-units = 1
|
|
@ -1,5 +0,0 @@
|
|||
// This Source Code Form is subject to the terms of the Mozilla Public
|
||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
extern crate mp4parse;
|
|
@ -1,7 +0,0 @@
|
|||
# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
|
||||
# vim: set filetype=python:
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
RustLibrary('gkrust')
|
|
@ -1,4 +1,3 @@
|
|||
# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
|
||||
# vim: set filetype=python:
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
|
@ -143,12 +142,6 @@ DIRS += [
|
|||
if CONFIG['MOZ_GIO_COMPONENT']:
|
||||
DIRS += ['/extensions/gio']
|
||||
|
||||
if CONFIG['MOZ_RUST']:
|
||||
DIRS += [
|
||||
'/toolkit/library/gtest/rust',
|
||||
'/toolkit/library/rust',
|
||||
]
|
||||
|
||||
DIRS += [
|
||||
'/toolkit/library/StaticXULComponentsEnd',
|
||||
'/toolkit/library',
|
||||
|
|
Загрузка…
Ссылка в новой задаче