Bug 1416059 - Move ASFLAGS logic from config.mk to mozbuild. r=mshal

MozReview-Commit-ID: L7RSijG9uA

--HG--
extra : rebase_source : 480bfbf3cef7116e7657ad6320acc44f14b8a55a
This commit is contained in:
Chris Manchester 2017-11-10 16:58:16 -08:00
Родитель 72c380c671
Коммит 246c2b0583
9 изменённых файлов: 101 добавлений и 27 удалений

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

@ -132,25 +132,6 @@ TOUCH ?= touch
PYTHON_PATH = $(PYTHON) $(topsrcdir)/config/pythonpath.py PYTHON_PATH = $(PYTHON) $(topsrcdir)/config/pythonpath.py
# determine debug-related options
_DEBUG_ASFLAGS :=
ifneq (,$(MOZ_DEBUG)$(MOZ_DEBUG_SYMBOLS))
ifeq ($(AS),$(YASM))
ifeq ($(OS_ARCH)_$(GNU_CC),WINNT_)
_DEBUG_ASFLAGS += -g cv8
else
ifneq ($(OS_ARCH),Darwin)
_DEBUG_ASFLAGS += -g dwarf2
endif
endif
else
_DEBUG_ASFLAGS += $(MOZ_DEBUG_FLAGS)
endif
endif
ASFLAGS += $(_DEBUG_ASFLAGS)
# #
# Build using PIC by default # Build using PIC by default
# #
@ -223,7 +204,7 @@ COMPILE_CFLAGS = $(COMPUTED_CFLAGS) $(PGO_CFLAGS) $(_DEPEND_CFLAGS) $(MK_COMPILE
COMPILE_CXXFLAGS = $(COMPUTED_CXXFLAGS) $(PGO_CFLAGS) $(_DEPEND_CFLAGS) $(MK_COMPILE_DEFINES) COMPILE_CXXFLAGS = $(COMPUTED_CXXFLAGS) $(PGO_CFLAGS) $(_DEPEND_CFLAGS) $(MK_COMPILE_DEFINES)
COMPILE_CMFLAGS = $(OS_COMPILE_CMFLAGS) $(MOZBUILD_CMFLAGS) COMPILE_CMFLAGS = $(OS_COMPILE_CMFLAGS) $(MOZBUILD_CMFLAGS)
COMPILE_CMMFLAGS = $(OS_COMPILE_CMMFLAGS) $(MOZBUILD_CMMFLAGS) COMPILE_CMMFLAGS = $(OS_COMPILE_CMMFLAGS) $(MOZBUILD_CMMFLAGS)
ASFLAGS += $(MOZBUILD_ASFLAGS) ASFLAGS = $(COMPUTED_ASFLAGS)
HOST_CFLAGS = $(COMPUTED_HOST_CFLAGS) $(_DEPEND_CFLAGS) HOST_CFLAGS = $(COMPUTED_HOST_CFLAGS) $(_DEPEND_CFLAGS)
HOST_CXXFLAGS = $(COMPUTED_HOST_CXXFLAGS) $(_DEPEND_CFLAGS) HOST_CXXFLAGS = $(COMPUTED_HOST_CXXFLAGS) $(_DEPEND_CFLAGS)

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

@ -344,6 +344,31 @@ class HostCompileFlags(BaseCompileFlags):
return optimize_flags return optimize_flags
class AsmFlags(BaseCompileFlags):
def __init__(self, context):
self._context = context
self.flag_variables = (
('OS', context.config.substs.get('ASFLAGS'), ('ASFLAGS',)),
('DEBUG', self._debug_flags(), ('ASFLAGS',)),
('MOZBUILD', None, ('ASFLAGS',)),
)
BaseCompileFlags.__init__(self, context)
def _debug_flags(self):
debug_flags = []
if (self._context.config.substs.get('MOZ_DEBUG') or
self._context.config.substs.get('MOZ_DEBUG_SYMBOLS')):
if self._context.get('USE_YASM'):
if (self._context.config.substs.get('OS_ARCH') == 'WINNT' and
not self._context.config.substs.get('GNU_CC')):
debug_flags += ['-g', 'cv8']
elif self._context.config.substs.get('OS_ARCH') != 'Darwin':
debug_flags += ['-g', 'dwarf2']
else:
debug_flags += self._context.config.substs.get('MOZ_DEBUG_FLAGS', '').split()
return debug_flags
class LinkFlags(BaseCompileFlags): class LinkFlags(BaseCompileFlags):
def __init__(self, context): def __init__(self, context):
self._context = context self._context = context
@ -1955,6 +1980,11 @@ VARIABLES = {
directly. directly.
"""), """),
'ASM_FLAGS': (AsmFlags, dict,
"""Recipe for linker flags for this context. Not to be manipulated
directly.
"""),
'CFLAGS': (List, list, 'CFLAGS': (List, list,
"""Flags passed to the C compiler for all of the C source files """Flags passed to the C compiler for all of the C source files
declared in this directory. declared in this directory.
@ -2410,6 +2440,15 @@ SPECIAL_VARIABLES = {
# Deprecation hints. # Deprecation hints.
DEPRECATION_HINTS = { DEPRECATION_HINTS = {
'ASM_FLAGS': '''
Please use
ASFLAGS
instead of manipulating ASM_FLAGS directly.
''',
'CPP_UNIT_TESTS': ''' 'CPP_UNIT_TESTS': '''
Please use' Please use'

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

@ -133,6 +133,7 @@ class TreeMetadataEmitter(LoggingMixin):
self._compile_dirs = set() self._compile_dirs = set()
self._host_compile_dirs = set() self._host_compile_dirs = set()
self._rust_compile_dirs = set() self._rust_compile_dirs = set()
self._asm_compile_dirs = set()
self._compile_flags = dict() self._compile_flags = dict()
self._linkage = [] self._linkage = []
self._static_linking_shared = set() self._static_linking_shared = set()
@ -888,6 +889,8 @@ class TreeMetadataEmitter(LoggingMixin):
sorted_files, canonical_suffix_for_file): sorted_files, canonical_suffix_for_file):
if canonical_suffix in ('.cpp', '.mm'): if canonical_suffix in ('.cpp', '.mm'):
cxx_sources[variable] = True cxx_sources[variable] = True
elif canonical_suffix in ('.s', '.S'):
self._asm_compile_dirs.add(context.objdir)
arglist = [context, list(files), canonical_suffix] arglist = [context, list(files), canonical_suffix]
if variable.startswith('UNIFIED_'): if variable.startswith('UNIFIED_'):
arglist.append(context.get('FILES_PER_UNIFIED_FILE', 16)) arglist.append(context.get('FILES_PER_UNIFIED_FILE', 16))
@ -933,6 +936,7 @@ class TreeMetadataEmitter(LoggingMixin):
computed_flags = ComputedFlags(context, context['COMPILE_FLAGS']) computed_flags = ComputedFlags(context, context['COMPILE_FLAGS'])
computed_link_flags = ComputedFlags(context, context['LINK_FLAGS']) computed_link_flags = ComputedFlags(context, context['LINK_FLAGS'])
computed_host_flags = ComputedFlags(context, context['HOST_COMPILE_FLAGS']) computed_host_flags = ComputedFlags(context, context['HOST_COMPILE_FLAGS'])
computed_as_flags = ComputedFlags(context, context['ASM_FLAGS'])
# Proxy some variables as-is until we have richer classes to represent # 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 # them. We should aim to keep this set small because it violates the
@ -962,7 +966,7 @@ class TreeMetadataEmitter(LoggingMixin):
for dll in context['DELAYLOAD_DLLS']]) for dll in context['DELAYLOAD_DLLS']])
context['OS_LIBS'].append('delayimp') context['OS_LIBS'].append('delayimp')
for v in ['CMFLAGS', 'CMMFLAGS', 'ASFLAGS']: for v in ['CMFLAGS', 'CMMFLAGS']:
if v in context and context[v]: if v in context and context[v]:
passthru.variables['MOZBUILD_' + v] = context[v] passthru.variables['MOZBUILD_' + v] = context[v]
@ -1175,13 +1179,18 @@ class TreeMetadataEmitter(LoggingMixin):
for name, jar in context.get('JAVA_JAR_TARGETS', {}).items(): for name, jar in context.get('JAVA_JAR_TARGETS', {}).items():
yield ContextWrapped(context, jar) yield ContextWrapped(context, jar)
computed_as_flags.resolve_flags('MOZBUILD',
context.get('ASFLAGS'))
if context.get('USE_YASM') is True: if context.get('USE_YASM') is True:
yasm = context.config.substs.get('YASM') yasm = context.config.substs.get('YASM')
if not yasm: if not yasm:
raise SandboxValidationError('yasm is not available', context) raise SandboxValidationError('yasm is not available', context)
passthru.variables['AS'] = yasm passthru.variables['AS'] = yasm
passthru.variables['ASFLAGS'] = context.config.substs.get('YASM_ASFLAGS')
passthru.variables['AS_DASH_C_FLAG'] = '' passthru.variables['AS_DASH_C_FLAG'] = ''
computed_as_flags.resolve_flags('OS',
context.config.substs.get('YASM_ASFLAGS', []))
for (symbol, cls) in [ for (symbol, cls) in [
('ANDROID_RES_DIRS', AndroidResDirs), ('ANDROID_RES_DIRS', AndroidResDirs),
@ -1210,6 +1219,9 @@ class TreeMetadataEmitter(LoggingMixin):
elif context.objdir in self._rust_compile_dirs: elif context.objdir in self._rust_compile_dirs:
yield computed_link_flags yield computed_link_flags
if context.objdir in self._asm_compile_dirs:
yield computed_as_flags
if context.objdir in self._host_compile_dirs: if context.objdir in self._host_compile_dirs:
yield computed_host_flags yield computed_host_flags

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

@ -0,0 +1,16 @@
# 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
Library('dummy')
SOURCES += [
'test1.c',
'test1.S'
]
ASFLAGS += ['-no-integrated-as']

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

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

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

@ -2,4 +2,12 @@
# Any copyright is dedicated to the Public Domain. # Any copyright is dedicated to the Public Domain.
# http://creativecommons.org/publicdomain/zero/1.0/ # http://creativecommons.org/publicdomain/zero/1.0/
@template
def Library(name):
LIBRARY_NAME = name
Library('dummy')
USE_YASM = True USE_YASM = True
SOURCES += ['test1.S']

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

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

@ -209,6 +209,15 @@ class TestEmitterBasic(unittest.TestCase):
self.assertEqual(flags.flags['MOZBUILD_CFLAGS'], ['-Wall', '-funroll-loops']) self.assertEqual(flags.flags['MOZBUILD_CFLAGS'], ['-Wall', '-funroll-loops'])
self.assertEqual(flags.flags['MOZBUILD_CXXFLAGS'], ['-funroll-loops', '-Wall']) self.assertEqual(flags.flags['MOZBUILD_CXXFLAGS'], ['-funroll-loops', '-Wall'])
def test_asflags(self):
reader = self.reader('asflags', extra_substs={
'ASFLAGS': ['-safeseh'],
})
as_sources, sources, ldflags, asflags, lib, flags = self.read_topsrcdir(reader)
self.assertIsInstance(asflags, ComputedFlags)
self.assertEqual(asflags.flags['OS'], reader.config.substs['ASFLAGS'])
self.assertEqual(asflags.flags['MOZBUILD'], ['-no-integrated-as'])
def test_debug_flags(self): def test_debug_flags(self):
reader = self.reader('compile-flags', extra_substs={ reader = self.reader('compile-flags', extra_substs={
'MOZ_DEBUG_FLAGS': '-g', 'MOZ_DEBUG_FLAGS': '-g',
@ -425,15 +434,20 @@ class TestEmitterBasic(unittest.TestCase):
YASM='yasm', YASM='yasm',
YASM_ASFLAGS='-foo', YASM_ASFLAGS='-foo',
)) ))
objs = self.read_topsrcdir(reader)
self.assertEqual(len(objs), 1) sources, passthru, ldflags, asflags, lib, flags = self.read_topsrcdir(reader)
self.assertIsInstance(objs[0], VariablePassthru)
self.assertIsInstance(passthru, VariablePassthru)
self.assertIsInstance(ldflags, ComputedFlags)
self.assertIsInstance(asflags, ComputedFlags)
self.assertIsInstance(flags, ComputedFlags)
self.assertEqual(asflags.flags['OS'], reader.config.substs['YASM_ASFLAGS'])
maxDiff = self.maxDiff maxDiff = self.maxDiff
self.maxDiff = None self.maxDiff = None
self.assertEqual(objs[0].variables, self.assertEqual(passthru.variables,
{'AS': 'yasm', {'AS': 'yasm',
'ASFLAGS': '-foo',
'AS_DASH_C_FLAG': ''}) 'AS_DASH_C_FLAG': ''})
self.maxDiff = maxDiff self.maxDiff = maxDiff
@ -1016,6 +1030,8 @@ class TestEmitterBasic(unittest.TestCase):
# The second to last object is a Linkable. # The second to last object is a Linkable.
linkable = objs.pop() linkable = objs.pop()
self.assertTrue(linkable.cxx_link) self.assertTrue(linkable.cxx_link)
as_flags = objs.pop()
self.assertIsInstance(as_flags, ComputedFlags)
ld_flags = objs.pop() ld_flags = objs.pop()
self.assertIsInstance(ld_flags, ComputedFlags) self.assertIsInstance(ld_flags, ComputedFlags)
self.assertEqual(len(objs), 6) self.assertEqual(len(objs), 6)
@ -1074,6 +1090,8 @@ class TestEmitterBasic(unittest.TestCase):
# The second to last object is a Linkable. # The second to last object is a Linkable.
linkable = objs.pop() linkable = objs.pop()
self.assertTrue(linkable.cxx_link) self.assertTrue(linkable.cxx_link)
flags = objs.pop()
self.assertIsInstance(flags, ComputedFlags)
self.assertEqual(len(objs), 7) self.assertEqual(len(objs), 7)
generated_sources = [o for o in objs if isinstance(o, GeneratedSources)] generated_sources = [o for o in objs if isinstance(o, GeneratedSources)]