Bug 1386876 - Move visibility flag handling to computed compile flags with templates. r=glandium

MozReview-Commit-ID: 9hwiCQv8WKU

--HG--
extra : rebase_source : cc7593fd06949a432dd056194ff19c1ac0daf4e4
This commit is contained in:
Chris Manchester 2017-09-11 11:36:31 -07:00
parent c0a229d4c3
commit 26d4e4810c
11 changed files with 40 additions and 24 deletions

View File

@ -150,6 +150,10 @@ def HostRustLibrary(name, features=None):
def DisableStlWrapping():
COMPILE_FLAGS['STL'] = []
@template
def NoVisibilityFlags():
COMPILE_FLAGS['VISIBILITY'] = []
include('gecko_templates.mozbuild')
include('test_templates.mozbuild')

View File

@ -328,8 +328,8 @@ CXXFLAGS += $(WARNINGS_AS_ERRORS)
CFLAGS += $(WARNINGS_AS_ERRORS)
endif # ALLOW_COMPILER_WARNINGS
COMPILE_CFLAGS = $(VISIBILITY_FLAGS) $(DEFINES) $(INCLUDES) $(OS_INCLUDES) $(DSO_CFLAGS) $(DSO_PIC_CFLAGS) $(RTL_FLAGS) $(OS_COMPILE_CFLAGS) $(_DEPEND_CFLAGS) $(CFLAGS) $(MOZBUILD_CFLAGS) $(MK_COMPILE_DEFINES)
COMPILE_CXXFLAGS = $(COMPUTED_CXXFLAGS) $(VISIBILITY_FLAGS) $(DEFINES) $(INCLUDES) $(OS_INCLUDES) $(DSO_CFLAGS) $(DSO_PIC_CFLAGS) $(RTL_FLAGS) $(OS_COMPILE_CXXFLAGS) $(_DEPEND_CFLAGS) $(CXXFLAGS) $(MOZBUILD_CXXFLAGS) $(MK_COMPILE_DEFINES)
COMPILE_CFLAGS = $(COMPUTED_CFLAGS) $(DEFINES) $(INCLUDES) $(OS_INCLUDES) $(DSO_CFLAGS) $(DSO_PIC_CFLAGS) $(RTL_FLAGS) $(OS_COMPILE_CFLAGS) $(_DEPEND_CFLAGS) $(CFLAGS) $(MOZBUILD_CFLAGS) $(MK_COMPILE_DEFINES)
COMPILE_CXXFLAGS = $(COMPUTED_CXXFLAGS) $(DEFINES) $(INCLUDES) $(OS_INCLUDES) $(DSO_CFLAGS) $(DSO_PIC_CFLAGS) $(RTL_FLAGS) $(OS_COMPILE_CXXFLAGS) $(_DEPEND_CFLAGS) $(CXXFLAGS) $(MOZBUILD_CXXFLAGS) $(MK_COMPILE_DEFINES)
COMPILE_CMFLAGS = $(OS_COMPILE_CMFLAGS) $(MOZBUILD_CMFLAGS)
COMPILE_CMMFLAGS = $(OS_COMPILE_CMMFLAGS) $(MOZBUILD_CMMFLAGS)
ASFLAGS += $(MOZBUILD_ASFLAGS)

View File

@ -71,7 +71,7 @@ class CompileDBBackend(CommonBackend):
if isinstance(obj, DirectoryTraversal):
self._envs[obj.objdir] = obj.config
for var in ('VISIBILITY_FLAGS', 'WARNINGS_AS_ERRORS'):
for var in ('WARNINGS_AS_ERRORS',):
value = obj.config.substs.get(var)
if value:
self._local_flags[obj.objdir][var] = value
@ -103,7 +103,7 @@ class CompileDBBackend(CommonBackend):
self._gyp_dirs.add(obj.objdir)
for var in ('MOZBUILD_CFLAGS', 'MOZBUILD_CXXFLAGS',
'MOZBUILD_CMFLAGS', 'MOZBUILD_CMMFLAGS',
'RTL_FLAGS', 'VISIBILITY_FLAGS'):
'RTL_FLAGS'):
if var in obj.variables:
self._local_flags[obj.objdir][var] = obj.variables[var]
if (obj.variables.get('ALLOW_COMPILER_WARNINGS') and
@ -236,11 +236,9 @@ class CompileDBBackend(CommonBackend):
value = value.split()
db.extend(value)
if canonical_suffix in ('.mm', '.cpp'):
db.append('$(COMPUTED_CXXFLAGS)')
db.append('$(COMPUTED_%s)' % self.CFLAGS[canonical_suffix])
db.extend((
'$(VISIBILITY_FLAGS)',
'$(DEFINES)',
'-I%s' % mozpath.join(cenv.topsrcdir, reldir),
'-I%s' % objdir,

View File

@ -301,6 +301,8 @@ class CompileFlags(ContextDerivedValue, dict):
def __init__(self, context):
self.flag_variables = (
('STL', context.config.substs.get('STL_FLAGS'), ('CXXFLAGS',)),
('VISIBILITY', context.config.substs.get('VISIBILITY_FLAGS'),
('CXXFLAGS', 'CFLAGS')),
)
self._known_keys = set(k for k, v, _ in self.flag_variables)

View File

@ -935,10 +935,6 @@ class TreeMetadataEmitter(LoggingMixin):
if v in context and context[v]:
passthru.variables['MOZBUILD_' + v] = context[v]
# NO_VISIBILITY_FLAGS is slightly different
if context['NO_VISIBILITY_FLAGS']:
passthru.variables['VISIBILITY_FLAGS'] = ''
if isinstance(context, TemplateContext) and context.template == 'Gyp':
passthru.variables['IS_GYP_DIR'] = True

View File

@ -2,8 +2,6 @@
# Any copyright is dedicated to the Public Domain.
# http://creativecommons.org/publicdomain/zero/1.0/
NO_VISIBILITY_FLAGS = True
DELAYLOAD_DLLS = ['foo.dll', 'bar.dll']
RCFILE = 'foo.rc'

View File

@ -319,9 +319,6 @@ class TestRecursiveMakeBackend(BackendTester):
'ALLOW_COMPILER_WARNINGS': [
'ALLOW_COMPILER_WARNINGS := 1',
],
'VISIBILITY_FLAGS': [
'VISIBILITY_FLAGS :=',
],
'RCFILE': [
'RCFILE := foo.rc',
],

View File

@ -4,8 +4,6 @@
DIST_INSTALL = False
NO_VISIBILITY_FLAGS = True
DELAYLOAD_DLLS = ['foo.dll', 'bar.dll']
RCFILE = 'foo.rc'

View File

@ -0,0 +1,17 @@
# 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')
@template
def NoVisibilityFlags():
COMPILE_FLAGS['VISIBILITY'] = []
UNIFIED_SOURCES += ['test1.c']
NoVisibilityFlags()

View File

@ -77,6 +77,9 @@ class TestEmitterBasic(unittest.TestCase):
BIN_SUFFIX='.prog',
OS_TARGET='WINNT',
COMPILE_ENVIRONMENT='1',
STL_FLAGS=['-I/path/to/topobjdir/dist/stl_wrappers'],
VISIBILITY_FLAGS=['-include',
'$(topsrcdir)/config/gcc_hidden.h'],
)
if extra_substs:
substs.update(extra_substs)
@ -182,7 +185,6 @@ class TestEmitterBasic(unittest.TestCase):
wanted = {
'ALLOW_COMPILER_WARNINGS': True,
'NO_DIST_INSTALL': True,
'VISIBILITY_FLAGS': '',
'RCFILE': 'foo.rc',
'RESFILE': 'bar.res',
'RCINCLUDE': 'bar.rc',
@ -204,11 +206,11 @@ class TestEmitterBasic(unittest.TestCase):
self.maxDiff = maxDiff
def test_compile_flags(self):
reader = self.reader('compile-flags',
extra_substs={'STL_FLAGS': ['-I/path/to/objdir/dist/stl_wrappers']})
reader = self.reader('compile-flags')
sources, flags, lib = self.read_topsrcdir(reader)
self.assertIsInstance(flags, ComputedFlags)
self.assertEqual(flags.flags['STL'], reader.config.substs['STL_FLAGS'])
self.assertEqual(flags.flags['VISIBILITY'], reader.config.substs['VISIBILITY_FLAGS'])
def test_compile_flags_validation(self):
reader = self.reader('compile-flags-field-validation')
@ -221,14 +223,18 @@ class TestEmitterBasic(unittest.TestCase):
'A list of strings must be provided'):
self.read_topsrcdir(reader)
def test_disable_stl_wrapping(self):
reader = self.reader('disable-stl-wrapping',
extra_substs={'STL_FLAGS': ['-I/path/to/objdir/dist/stl_wrappers']})
reader = self.reader('disable-stl-wrapping')
sources, flags, lib = self.read_topsrcdir(reader)
self.assertIsInstance(flags, ComputedFlags)
self.assertEqual(flags.flags['STL'], [])
def test_visibility_flags(self):
reader = self.reader('visibility-flags')
sources, flags, lib = self.read_topsrcdir(reader)
self.assertIsInstance(flags, ComputedFlags)
self.assertEqual(flags.flags['VISIBILITY'], [])
def test_use_yasm(self):
# When yasm is not available, this should raise.
reader = self.reader('use-yasm')