| 1 |
# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*- |
| 2 |
# vim: set filetype=python: |
| 3 |
# This Source Code Form is subject to the terms of the Mozilla Public |
| 4 |
# License, v. 2.0. If a copy of the MPL was not distributed with this |
| 5 |
# file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 6 |
|
| 7 |
HostSharedLibrary("clang-plugin") |
| 8 |
|
| 9 |
HOST_SOURCES += ["!ThirdPartyPaths.cpp"] |
| 10 |
|
| 11 |
HOST_SOURCES += [ |
| 12 |
"ArithmeticArgChecker.cpp", |
| 13 |
"AssertAssignmentChecker.cpp", |
| 14 |
"CanRunScriptChecker.cpp", |
| 15 |
"CustomAttributes.cpp", |
| 16 |
"CustomTypeAnnotation.cpp", |
| 17 |
"DanglingOnTemporaryChecker.cpp", |
| 18 |
"DiagnosticsMatcher.cpp", |
| 19 |
"ExplicitImplicitChecker.cpp", |
| 20 |
"ExplicitOperatorBoolChecker.cpp", |
| 21 |
"GlobalVariableInitializationChecker.cpp", |
| 22 |
"JSHandleRootedTypedefChecker.cpp", |
| 23 |
"KnownLiveChecker.cpp", |
| 24 |
"KungFuDeathGripChecker.cpp", |
| 25 |
"MozCheckAction.cpp", |
| 26 |
"MustOverrideChecker.cpp", |
| 27 |
"MustReturnFromCallerChecker.cpp", |
| 28 |
"NaNExprChecker.cpp", |
| 29 |
"NeedsNoVTableTypeChecker.cpp", |
| 30 |
"NoAddRefReleaseOnReturnChecker.cpp", |
| 31 |
"NoAutoTypeChecker.cpp", |
| 32 |
"NoDuplicateRefCntMemberChecker.cpp", |
| 33 |
"NoExplicitMoveConstructorChecker.cpp", |
| 34 |
"NoNewThreadsChecker.cpp", |
| 35 |
"NonMemMovableMemberChecker.cpp", |
| 36 |
"NonMemMovableTemplateArgChecker.cpp", |
| 37 |
"NonParamInsideFunctionDeclChecker.cpp", |
| 38 |
"NonTrivialTypeInFfiChecker.cpp", |
| 39 |
"NoPrincipalGetURI.cpp", |
| 40 |
"NoUsingNamespaceMozillaJavaChecker.cpp", |
| 41 |
"OverrideBaseCallChecker.cpp", |
| 42 |
"OverrideBaseCallUsageChecker.cpp", |
| 43 |
"ParamTraitsEnumChecker.cpp", |
| 44 |
"RefCountedCopyConstructorChecker.cpp", |
| 45 |
"RefCountedInsideLambdaChecker.cpp", |
| 46 |
"RefCountedThisInsideConstructorChecker.cpp", |
| 47 |
"ScopeChecker.cpp", |
| 48 |
"SprintfLiteralChecker.cpp", |
| 49 |
"TrivialCtorDtorChecker.cpp", |
| 50 |
"TrivialDtorChecker.cpp", |
| 51 |
"VariableUsageHelpers.cpp", |
| 52 |
] |
| 53 |
|
| 54 |
# Ideally, we wouldn't have compile-time choices wrt checks. bug 1617153. |
| 55 |
if CONFIG["OS_ARCH"] == "WINNT": |
| 56 |
HOST_DEFINES["TARGET_IS_WINDOWS"] = True |
| 57 |
HOST_SOURCES += [ |
| 58 |
"FopenUsageChecker.cpp", |
| 59 |
"LoadLibraryUsageChecker.cpp", |
| 60 |
] |
| 61 |
|
| 62 |
if CONFIG["ENABLE_MOZSEARCH_PLUGIN"]: |
| 63 |
HOST_SOURCES += [ |
| 64 |
"mozsearch-plugin/BindingOperations.cpp", |
| 65 |
"mozsearch-plugin/FileOperations.cpp", |
| 66 |
"mozsearch-plugin/from-clangd/HeuristicResolver.cpp", |
| 67 |
"mozsearch-plugin/MozsearchIndexer.cpp", |
| 68 |
"mozsearch-plugin/StringOperations.cpp", |
| 69 |
] |
| 70 |
|
| 71 |
GeneratedFile( |
| 72 |
"ThirdPartyPaths.cpp", |
| 73 |
script="ThirdPartyPaths.py", |
| 74 |
entry_point="generate", |
| 75 |
inputs=[ |
| 76 |
"/tools/rewriting/ThirdPartyPaths.txt", |
| 77 |
"/tools/rewriting/Generated.txt", |
| 78 |
], |
| 79 |
) |
| 80 |
|
| 81 |
GeneratedFile( |
| 82 |
"ThreadAllows.h", |
| 83 |
script="ThreadAllows.py", |
| 84 |
entry_point="generate_file", |
| 85 |
inputs=[ |
| 86 |
"/build/clang-plugin/ThreadAllows.txt", |
| 87 |
"/build/clang-plugin/ThreadFileAllows.txt", |
| 88 |
], |
| 89 |
) |
| 90 |
|
| 91 |
HOST_COMPILE_FLAGS["STL"] = [] |
| 92 |
HOST_COMPILE_FLAGS["VISIBILITY"] = [] |
| 93 |
|
| 94 |
# libc++ is required to build plugins against clang on OS X. |
| 95 |
if CONFIG["HOST_OS_ARCH"] == "Darwin": |
| 96 |
HOST_CXXFLAGS += ["-stdlib=libc++"] |
| 97 |
|
| 98 |
# As of clang 8, llvm-config doesn't output the flags used to build clang |
| 99 |
# itself, so we don't end up with -fPIC as a side effect. llvm.org/PR8220 |
| 100 |
if CONFIG["HOST_OS_ARCH"] != "WINNT": |
| 101 |
HOST_CXXFLAGS += ["-fPIC"] |
| 102 |
|
| 103 |
DIRS += [ |
| 104 |
"tests", |
| 105 |
] |
| 106 |
|
| 107 |
include("external/sources.mozbuild") |
| 108 |
|
| 109 |
if CONFIG["ENABLE_CLANG_PLUGIN_ALPHA"]: |
| 110 |
HOST_DEFINES["MOZ_CLANG_PLUGIN_ALPHA"] = "1" |
| 111 |
include("alpha/sources.mozbuild") |
| 112 |
|
| 113 |
# In the current moz.build world, we need to override essentially every |
| 114 |
# variable to limit ourselves to what we need to build the clang plugin. |
| 115 |
if CONFIG["HOST_OS_ARCH"] == "WINNT": |
| 116 |
extra_cxxflags = ["-GR-", "-EHsc"] |
| 117 |
# Clang 14 headers enforce a requirement upon Visual Studio 2019 headers, |
| 118 |
# for support of newer C++ versions, which is necessary for clang itself, |
| 119 |
# but as of writing, it's not necessary for the plugin code, so enable |
| 120 |
# the escape hatch, at least until we generally upgrade to VS 2019. |
| 121 |
HOST_DEFINES["LLVM_FORCE_USE_OLD_TOOLCHAIN"] = True |
| 122 |
else: |
| 123 |
extra_cxxflags = ["-fno-rtti", "-fno-exceptions"] |
| 124 |
|
| 125 |
if CONFIG["LLVM_CXXFLAGS"]: |
| 126 |
HOST_COMPILE_FLAGS["HOST_CXXFLAGS"] = CONFIG["LLVM_CXXFLAGS"] + extra_cxxflags |
| 127 |
|
| 128 |
# Avoid -DDEBUG=1 on the command line, which conflicts with a #define |
| 129 |
# DEBUG(...) in llvm headers. |
| 130 |
DEFINES["DEBUG"] = False |
| 131 |
|
| 132 |
HOST_OS_LIBS += ["clangASTMatchers"] |
| 133 |
if CONFIG["HOST_OS_ARCH"] == "WINNT": |
| 134 |
HOST_OS_LIBS += ["clang"] |