зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1143932 - Factor out sources processing code from emit_from_context; r=gps
This commit is contained in:
Родитель
64cfd6dd91
Коммит
b7facac379
|
@ -545,12 +545,6 @@ class TreeMetadataEmitter(LoggingMixin):
|
|||
yield XPIDLFile(context, mozpath.join(context.srcdir, idl),
|
||||
xpidl_module)
|
||||
|
||||
for symbol in ('SOURCES', 'HOST_SOURCES', 'UNIFIED_SOURCES'):
|
||||
for src in (context[symbol] or []):
|
||||
if not os.path.exists(mozpath.join(context.srcdir, src)):
|
||||
raise SandboxValidationError('File listed in %s does not '
|
||||
'exist: \'%s\'' % (symbol, src), context)
|
||||
|
||||
# Proxy some variables as-is until we have richer classes to represent
|
||||
# them. We should aim to keep this set small because it violates the
|
||||
# desired abstraction of the build definition away from makefiles.
|
||||
|
@ -595,78 +589,8 @@ class TreeMetadataEmitter(LoggingMixin):
|
|||
if context['NO_VISIBILITY_FLAGS']:
|
||||
passthru.variables['VISIBILITY_FLAGS'] = ''
|
||||
|
||||
no_pgo = context.get('NO_PGO')
|
||||
sources = context.get('SOURCES', [])
|
||||
no_pgo_sources = [f for f in sources if sources[f].no_pgo]
|
||||
if no_pgo:
|
||||
if no_pgo_sources:
|
||||
raise SandboxValidationError('NO_PGO and SOURCES[...].no_pgo '
|
||||
'cannot be set at the same time', context)
|
||||
passthru.variables['NO_PROFILE_GUIDED_OPTIMIZE'] = no_pgo
|
||||
if no_pgo_sources:
|
||||
passthru.variables['NO_PROFILE_GUIDED_OPTIMIZE'] = no_pgo_sources
|
||||
|
||||
# A map from "canonical suffixes" for a particular source file
|
||||
# language to the range of suffixes associated with that language.
|
||||
#
|
||||
# We deliberately don't list the canonical suffix in the suffix list
|
||||
# in the definition; we'll add it in programmatically after defining
|
||||
# things.
|
||||
suffix_map = {
|
||||
'.s': set(['.asm']),
|
||||
'.c': set(),
|
||||
'.m': set(),
|
||||
'.mm': set(),
|
||||
'.cpp': set(['.cc', '.cxx']),
|
||||
'.S': set(),
|
||||
}
|
||||
|
||||
# The inverse of the above, mapping suffixes to their canonical suffix.
|
||||
canonicalized_suffix_map = {}
|
||||
for suffix, alternatives in suffix_map.iteritems():
|
||||
alternatives.add(suffix)
|
||||
for a in alternatives:
|
||||
canonicalized_suffix_map[a] = suffix
|
||||
|
||||
def canonical_suffix_for_file(f):
|
||||
return canonicalized_suffix_map[mozpath.splitext(f)[1]]
|
||||
|
||||
# A map from moz.build variables to the canonical suffixes of file
|
||||
# kinds that can be listed therein.
|
||||
all_suffixes = list(suffix_map.keys())
|
||||
varmap = dict(
|
||||
SOURCES=(Sources, all_suffixes),
|
||||
HOST_SOURCES=(HostSources, ['.c', '.mm', '.cpp']),
|
||||
UNIFIED_SOURCES=(UnifiedSources, ['.c', '.mm', '.cpp']),
|
||||
GENERATED_SOURCES=(GeneratedSources, all_suffixes),
|
||||
)
|
||||
|
||||
for variable, (klass, suffixes) in varmap.items():
|
||||
allowed_suffixes = set().union(*[suffix_map[s] for s in suffixes])
|
||||
|
||||
# First ensure that we haven't been given filetypes that we don't
|
||||
# recognize.
|
||||
for f in context[variable]:
|
||||
ext = mozpath.splitext(f)[1]
|
||||
if ext not in allowed_suffixes:
|
||||
raise SandboxValidationError(
|
||||
'%s has an unknown file type.' % f, context)
|
||||
if variable.startswith('GENERATED_'):
|
||||
l = passthru.variables.setdefault('GARBAGE', [])
|
||||
l.append(f)
|
||||
|
||||
# Now sort the files to let groupby work.
|
||||
sorted_files = sorted(context[variable], key=canonical_suffix_for_file)
|
||||
for canonical_suffix, files in itertools.groupby(sorted_files, canonical_suffix_for_file):
|
||||
arglist = [context, list(files), canonical_suffix]
|
||||
if variable.startswith('UNIFIED_') and 'FILES_PER_UNIFIED_FILE' in context:
|
||||
arglist.append(context['FILES_PER_UNIFIED_FILE'])
|
||||
yield klass(*arglist)
|
||||
|
||||
sources_with_flags = [f for f in sources if sources[f].flags]
|
||||
for f in sources_with_flags:
|
||||
ext = mozpath.splitext(f)[1]
|
||||
yield PerSourceFlag(context, f, sources[f].flags)
|
||||
for obj in self._process_sources(context, passthru):
|
||||
yield obj
|
||||
|
||||
exports = context.get('EXPORTS')
|
||||
if exports:
|
||||
|
@ -871,6 +795,86 @@ class TreeMetadataEmitter(LoggingMixin):
|
|||
|
||||
return sub
|
||||
|
||||
def _process_sources(self, context, passthru):
|
||||
for symbol in ('SOURCES', 'HOST_SOURCES', 'UNIFIED_SOURCES'):
|
||||
for src in (context[symbol] or []):
|
||||
if not os.path.exists(mozpath.join(context.srcdir, src)):
|
||||
raise SandboxValidationError('File listed in %s does not '
|
||||
'exist: \'%s\'' % (symbol, src), context)
|
||||
|
||||
no_pgo = context.get('NO_PGO')
|
||||
sources = context.get('SOURCES', [])
|
||||
no_pgo_sources = [f for f in sources if sources[f].no_pgo]
|
||||
if no_pgo:
|
||||
if no_pgo_sources:
|
||||
raise SandboxValidationError('NO_PGO and SOURCES[...].no_pgo '
|
||||
'cannot be set at the same time', context)
|
||||
passthru.variables['NO_PROFILE_GUIDED_OPTIMIZE'] = no_pgo
|
||||
if no_pgo_sources:
|
||||
passthru.variables['NO_PROFILE_GUIDED_OPTIMIZE'] = no_pgo_sources
|
||||
|
||||
# A map from "canonical suffixes" for a particular source file
|
||||
# language to the range of suffixes associated with that language.
|
||||
#
|
||||
# We deliberately don't list the canonical suffix in the suffix list
|
||||
# in the definition; we'll add it in programmatically after defining
|
||||
# things.
|
||||
suffix_map = {
|
||||
'.s': set(['.asm']),
|
||||
'.c': set(),
|
||||
'.m': set(),
|
||||
'.mm': set(),
|
||||
'.cpp': set(['.cc', '.cxx']),
|
||||
'.S': set(),
|
||||
}
|
||||
|
||||
# The inverse of the above, mapping suffixes to their canonical suffix.
|
||||
canonicalized_suffix_map = {}
|
||||
for suffix, alternatives in suffix_map.iteritems():
|
||||
alternatives.add(suffix)
|
||||
for a in alternatives:
|
||||
canonicalized_suffix_map[a] = suffix
|
||||
|
||||
def canonical_suffix_for_file(f):
|
||||
return canonicalized_suffix_map[mozpath.splitext(f)[1]]
|
||||
|
||||
# A map from moz.build variables to the canonical suffixes of file
|
||||
# kinds that can be listed therein.
|
||||
all_suffixes = list(suffix_map.keys())
|
||||
varmap = dict(
|
||||
SOURCES=(Sources, all_suffixes),
|
||||
HOST_SOURCES=(HostSources, ['.c', '.mm', '.cpp']),
|
||||
UNIFIED_SOURCES=(UnifiedSources, ['.c', '.mm', '.cpp']),
|
||||
GENERATED_SOURCES=(GeneratedSources, all_suffixes),
|
||||
)
|
||||
|
||||
for variable, (klass, suffixes) in varmap.items():
|
||||
allowed_suffixes = set().union(*[suffix_map[s] for s in suffixes])
|
||||
|
||||
# First ensure that we haven't been given filetypes that we don't
|
||||
# recognize.
|
||||
for f in context[variable]:
|
||||
ext = mozpath.splitext(f)[1]
|
||||
if ext not in allowed_suffixes:
|
||||
raise SandboxValidationError(
|
||||
'%s has an unknown file type.' % f, context)
|
||||
if variable.startswith('GENERATED_'):
|
||||
l = passthru.variables.setdefault('GARBAGE', [])
|
||||
l.append(f)
|
||||
|
||||
# Now sort the files to let groupby work.
|
||||
sorted_files = sorted(context[variable], key=canonical_suffix_for_file)
|
||||
for canonical_suffix, files in itertools.groupby(sorted_files, canonical_suffix_for_file):
|
||||
arglist = [context, list(files), canonical_suffix]
|
||||
if variable.startswith('UNIFIED_') and 'FILES_PER_UNIFIED_FILE' in context:
|
||||
arglist.append(context['FILES_PER_UNIFIED_FILE'])
|
||||
yield klass(*arglist)
|
||||
|
||||
sources_with_flags = [f for f in sources if sources[f].flags]
|
||||
for f in sources_with_flags:
|
||||
ext = mozpath.splitext(f)[1]
|
||||
yield PerSourceFlag(context, f, sources[f].flags)
|
||||
|
||||
def _process_test_manifests(self, context):
|
||||
# While there are multiple test manifests, the behavior is very similar
|
||||
# across them. We enforce this by having common handling of all
|
||||
|
|
Загрузка…
Ссылка в новой задаче