Bug 1403346 - Implement clang-plugin cxxflags in moz.build.
MozReview-Commit-ID: 9zSryJcTRGl
--- a/build/clang-plugin/Makefile.in
+++ b/build/clang-plugin/Makefile.in
@@ -4,23 +4,19 @@
# LLVM_CXXFLAGS comes with its own optimization flags.
MOZ_OPTIMIZE =
include $(topsrcdir)/config/config.mk
# In the current moz.build world, we need to override essentially every
# variable to limit ourselves to what we need to build the clang plugin.
-ifeq ($(HOST_OS_ARCH),WINNT)
-OS_CXXFLAGS := $(LLVM_CXXFLAGS) -GR- -EHsc
-else
-OS_CXXFLAGS := $(LLVM_CXXFLAGS) -fno-rtti -fno-exceptions
+ifneq ($(HOST_OS_ARCH),WINNT)
DSO_LDOPTS := -shared
endif
-OS_COMPILE_CXXFLAGS :=
OS_LDFLAGS := $(LLVM_LDFLAGS) $(CLANG_LDFLAGS)
ifeq ($(HOST_OS_ARCH)_$(OS_ARCH),Linux_Darwin)
# Use the host compiler instead of the target compiler.
CXX := $(HOST_CXX)
# expandlibs doesn't know the distinction between host and target toolchains,
# and on cross linux/darwin builds, the options to give to the linker for file
# lists differ between both, so don't use file lists.
--- a/build/clang-plugin/moz.build
+++ b/build/clang-plugin/moz.build
@@ -54,8 +54,24 @@ NoVisibilityFlags()
# libc++ is required to build plugins against clang on OS X.
if CONFIG['HOST_OS_ARCH'] == 'Darwin':
CXXFLAGS += ['-stdlib=libc++']
LDFLAGS += ['-lc++']
DIRS += [
'tests',
]
+
+
+# In the current moz.build world, we need to override essentially every
+# variable to limit ourselves to what we need to build the clang plugin.
+if CONFIG['HOST_OS_ARCH'] == 'WINNT':
+ extra_cxxflags = ['-GR-', '-EHsc']
+else:
+ extra_cxxflags = ['-fno-rtti', '-fno-exceptions']
+
+if CONFIG['LLVM_CXXFLAGS']:
+ COMPILE_FLAGS['OS_CXXFLAGS'] = CONFIG['LLVM_CXXFLAGS'] + extra_cxxflags
+
+COMPILE_FLAGS['CLANG_PLUGIN'] = []
+COMPILE_FLAGS['OPTIMIZE'] = []
+COMPILE_FLAGS['DEBUG'] = []
+COMPILE_FLAGS['OS_COMPILE_CXXFLAGS'] = []
--- a/build/clang-plugin/tests/Makefile.in
+++ b/build/clang-plugin/tests/Makefile.in
@@ -1,17 +1,12 @@
# 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/.
-# Build without any warning flags, and with clang verify flag for a
-# syntax-only build (no codegen), without a limit on the number of errors.
-OS_CFLAGS := $(filter-out -W%,$(OS_CFLAGS)) -fsyntax-only -Xclang -verify -ferror-limit=0 -std=c11 -Wno-invalid-noreturn
-OS_CXXFLAGS := $(filter-out -W%,$(OS_CXXFLAGS)) -fsyntax-only -Xclang -verify -ferror-limit=0 -Wno-invalid-noreturn
-
include $(topsrcdir)/config/rules.mk
target:: $(OBJS)
# We don't actually build anything.
.PHONY: $(OBJS)
# Don't actually build a library, since we don't actually build objects.
--- a/build/clang-plugin/tests/moz.build
+++ b/build/clang-plugin/tests/moz.build
@@ -42,8 +42,20 @@ SOURCES += [
'TestRefCountedCopyConstructor.cpp',
'TestSprintfLiteral.cpp',
'TestStackClass.cpp',
'TestTrivialCtorDtor.cpp',
]
DisableStlWrapping()
NoVisibilityFlags()
+
+# Build without any warning flags, and with clang verify flag for a
+# syntax-only build (no codegen), without a limit on the number of errors.
+COMPILE_FLAGS['OS_CXXFLAGS'] = (
+ [f for f in COMPILE_FLAGS.get('OS_CXXFLAGS', []) if not f.startswith('-W')] +
+ ['-fsyntax-only', '-Xclang', '-verify', '-ferror-limit=0', '-Wno-invalid-noreturn']
+)
+COMPILE_FLAGS['OS_CFLAGS'] = (
+ [f for f in COMPILE_FLAGS.get('OS_CFLAGS', []) if not f.startswith('-W')] +
+ ['-fsyntax-only', '-Xclang', '-verify', '-ferror-limit=0', '-std=c11',
+ '-Wno-invalid-noreturn']
+)
--- a/config/static-checking-config.mk
+++ b/config/static-checking-config.mk
@@ -8,12 +8,9 @@
ifdef ENABLE_CLANG_PLUGIN
# Replace "clang-cl.exe" to "clang.exe --driver-mode=cl" to avoid loading the
# module clang.exe again when load the plugin dll, which links to the import
# library of clang.exe.
ifeq ($(OS_ARCH),WINNT)
CC := $(subst clang-cl.exe,clang.exe --driver-mode=cl,$(CC:.EXE=.exe))
CXX := $(subst clang-cl.exe,clang.exe --driver-mode=cl,$(CXX:.EXE=.exe))
endif
-
-OS_CXXFLAGS += $(CLANG_PLUGIN_FLAGS)
-OS_CFLAGS += $(CLANG_PLUGIN_FLAGS)
endif
--- a/python/mozbuild/mozbuild/frontend/context.py
+++ b/python/mozbuild/mozbuild/frontend/context.py
@@ -333,16 +333,18 @@ class CompileFlags(ContextDerivedValue,
('CXXFLAGS', 'CFLAGS', 'CXX_LDFLAGS', 'C_LDFLAGS')),
('OS_CFLAGS', context.config.substs.get('OS_CFLAGS'),
('CFLAGS', 'C_LDFLAGS')),
('OS_CXXFLAGS', context.config.substs.get('OS_CXXFLAGS'),
('CXXFLAGS', 'CXX_LDFLAGS')),
('DEBUG', (context.config.substs['MOZ_DEBUG_FLAGS'].split() if
'MOZ_DEBUG_FLAGS' in context.config.substs else []),
('CFLAGS', 'CXXFLAGS', 'CXX_LDFLAGS', 'C_LDFLAGS')),
+ ('CLANG_PLUGIN', context.config.substs.get('CLANG_PLUGIN_FLAGS'),
+ ('CFLAGS', 'CXXFLAGS', 'CXX_LDFLAGS', 'C_LDFLAGS')),
('OPTIMIZE', self._optimize_flags(),
('CFLAGS', 'CXXFLAGS', 'CXX_LDFLAGS', 'C_LDFLAGS')),
('FRAMEPTR', context.config.substs.get('MOZ_FRAMEPTR_FLAGS'),
('CFLAGS', 'CXXFLAGS', 'CXX_LDFLAGS', 'C_LDFLAGS')),
('WARNINGS_AS_ERRORS', self._warnings_as_errors(),
('CXXFLAGS', 'CFLAGS', 'CXX_LDFLAGS', 'C_LDFLAGS')),
)
self._known_keys = set(k for k, v, _ in self.flag_variables)
@@ -388,17 +390,17 @@ class CompileFlags(ContextDerivedValue,
def __setitem__(self, key, value):
if key not in self._known_keys:
raise ValueError('Invalid value. `%s` is not a compile flags '
'category.' % key)
if key in self and self[key] is None:
raise ValueError('`%s` may not be set in COMPILE_FLAGS from moz.build, this '
'value is resolved from the emitter.' % key)
- if not (isinstance(value, list) and all(isinstance(v, unicode) for v in value)):
+ if not (isinstance(value, list) and all(isinstance(v, basestring) for v in value)):
raise ValueError('A list of strings must be provided as a value for a '
'compile flags category.')
dict.__setitem__(self, key, value)
class FinalTargetValue(ContextDerivedValue, unicode):
def __new__(cls, context, value=""):
if not value: