Bug 1403346 - Define flags loading the clang plugin in configure rather than the make backend. draft
authorChris Manchester <cmanchester@mozilla.com>
Wed, 25 Oct 2017 15:12:10 -0700
changeset 686526 0fc641d3785873bc22e674ad9df8959cbee1081a
parent 686525 920f16dc595f683229a29596e53be403d330178b
child 686527 376a9d10517017891644b4b8135696785580d1ea
push id86198
push userbmo:cmanchester@mozilla.com
push dateWed, 25 Oct 2017 22:13:37 +0000
bugs1403346
milestone58.0a1
Bug 1403346 - Define flags loading the clang plugin in configure rather than the make backend. MozReview-Commit-ID: EubsjJl1LBS
build/autoconf/clang-plugin.m4
build/moz.configure/old.configure
build/moz.configure/toolchain.configure
config/static-checking-config.mk
moz.configure
--- a/build/autoconf/clang-plugin.m4
+++ b/build/autoconf/clang-plugin.m4
@@ -1,18 +1,14 @@
 dnl This Source Code Form is subject to the terms of the Mozilla Public
 dnl License, v. 2.0. If a copy of the MPL was not distributed with this
 dnl file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 AC_DEFUN([MOZ_CONFIG_CLANG_PLUGIN], [
 
-MOZ_ARG_ENABLE_BOOL(clang-plugin,
-[  --enable-clang-plugin   Enable building with the mozilla clang plugin ],
-   ENABLE_CLANG_PLUGIN=1,
-   ENABLE_CLANG_PLUGIN= )
 if test -n "$ENABLE_CLANG_PLUGIN"; then
     if test -z "${CLANG_CC}${CLANG_CL}"; then
         AC_MSG_ERROR([Can't use clang plugin without clang.])
     fi
 
     AC_MSG_CHECKING([for llvm-config])
     if test -z "$LLVMCONFIG"; then
       if test -n "$CLANG_CL"; then
@@ -150,18 +146,21 @@ if test -n "$ENABLE_CLANG_PLUGIN"; then
             CXXFLAGS="$_SAVE_CXXFLAGS"
             export MACOSX_DEPLOYMENT_TARGET="$_SAVE_MACOSX_DEPLOYMENT_TARGET"
             AC_LANG_RESTORE
         ])
     if test "$ac_cv_has_accepts_ignoringParenImpCasts" = "yes"; then
       LLVM_CXXFLAGS="$LLVM_CXXFLAGS -DHAS_ACCEPTS_IGNORINGPARENIMPCASTS"
     fi
 
+    CLANG_PLUGIN_FLAGS="-Xclang -load -Xclang $CLANG_PLUGIN -Xclang -add-plugin -Xclang moz-check"
+
     AC_DEFINE(MOZ_CLANG_PLUGIN)
 fi
 
+AC_SUBST_LIST(CLANG_PLUGIN_FLAGS)
 AC_SUBST(LLVM_CXXFLAGS)
 AC_SUBST(LLVM_LDFLAGS)
 AC_SUBST(CLANG_LDFLAGS)
 
 AC_SUBST(ENABLE_CLANG_PLUGIN)
 
 ])
--- a/build/moz.configure/old.configure
+++ b/build/moz.configure/old.configure
@@ -168,17 +168,16 @@ def old_configure_options(*options):
 
 @old_configure_options(
     '--cache-file',
     '--datadir',
     '--enable-accessibility',
     '--enable-address-sanitizer',
     '--enable-alsa',
     '--enable-bundled-fonts',
-    '--enable-clang-plugin',
     '--enable-content-sandbox',
     '--enable-cookies',
     '--enable-cpp-rtti',
     '--enable-crashreporter',
     '--enable-dbus',
     '--enable-debug-js-modules',
     '--enable-directshow',
     '--enable-dtrace',
--- a/build/moz.configure/toolchain.configure
+++ b/build/moz.configure/toolchain.configure
@@ -1480,16 +1480,23 @@ def select_linker(linker, c_compiler, de
         else:
             die("Could not use lld as linker")
 
 
 set_config('LD_IS_BFD', depends(select_linker.KIND)
            (lambda x: x == 'bfd' or None))
 set_config('LINKER_LDFLAGS', select_linker.LINKER_FLAG)
 
+
+js_option('--enable-clang-plugin', env='ENABLE_CLANG_PLUGIN',
+          help="Enable building with the mozilla clang plugin")
+
+add_old_configure_assignment('ENABLE_CLANG_PLUGIN',
+                             depends_if('--enable-clang-plugin')(lambda _: True))
+
 # Code Coverage
 # ==============================================================
 
 js_option('--enable-coverage', env='MOZ_CODE_COVERAGE',
           help='Enable code coverage')
 
 
 @depends('--enable-coverage')
--- a/config/static-checking-config.mk
+++ b/config/static-checking-config.mk
@@ -9,12 +9,11 @@ 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
 
-CLANG_PLUGIN := $(topobjdir)/build/clang-plugin/$(DLL_PREFIX)clang-plugin$(DLL_SUFFIX)
-OS_CXXFLAGS += -Xclang -load -Xclang $(CLANG_PLUGIN) -Xclang -add-plugin -Xclang moz-check
-OS_CFLAGS += -Xclang -load -Xclang $(CLANG_PLUGIN) -Xclang -add-plugin -Xclang moz-check
+OS_CXXFLAGS += $(CLANG_PLUGIN_FLAGS)
+OS_CFLAGS += $(CLANG_PLUGIN_FLAGS)
 endif
--- a/moz.configure
+++ b/moz.configure
@@ -270,16 +270,32 @@ def build_gtest(pgo, build_project, targ
     if not enable_tests or not enabled:
         return None
     if (automation and build_project == 'browser' and
         not (pgo and target.os == 'WINNT')):
         return True
 
 set_config('LINK_GTEST_DURING_COMPILE', build_gtest)
 
+# clang-plugin location
+# ==============================================================
+@depends(library_name_info, check_build_environment, when='--enable-clang-plugin')
+def clang_plugin_path(library_name_info, build_env):
+    topobjdir = build_env.topobjdir
+    if topobjdir.endswith('/js/src'):
+        topobjdir = topobjdir[:-7]
+    return os.path.abspath(
+        os.path.join(topobjdir, 'build', 'clang-plugin',
+                     '%sclang-plugin%s' % (library_name_info.dll.prefix,
+                                           library_name_info.dll.suffix))
+    )
+
+add_old_configure_assignment('CLANG_PLUGIN', clang_plugin_path)
+
+
 # Awk detection
 # ==============================================================
 awk = check_prog('AWK', ('gawk', 'mawk', 'nawk', 'awk'))
 
 # Until the AWK variable is not necessary in old-configure
 @depends(awk)
 def awk_for_old_configure(value):
     return value