зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1648798 - Add option for importing external checks into clang-tidy; r=tjr,andi
Differential Revision: https://phabricator.services.mozilla.com/D81699
This commit is contained in:
Родитель
0d02beff03
Коммит
d3be11d148
|
@ -105,7 +105,11 @@ def import_clang_tidy(source_dir, build_clang_tidy_alpha):
|
||||||
'clang-tools-extra/clang-tidy')
|
'clang-tools-extra/clang-tidy')
|
||||||
sys.path.append(clang_plugin_path)
|
sys.path.append(clang_plugin_path)
|
||||||
from import_mozilla_checks import do_import
|
from import_mozilla_checks import do_import
|
||||||
do_import(clang_plugin_path, clang_tidy_path, build_clang_tidy_alpha)
|
import_options = {
|
||||||
|
"alpha": build_clang_tidy_alpha,
|
||||||
|
"external": False
|
||||||
|
}
|
||||||
|
do_import(clang_plugin_path, clang_tidy_path, import_options)
|
||||||
|
|
||||||
|
|
||||||
def build_package(package_build_dir, cmake_args):
|
def build_package(package_build_dir, cmake_args):
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
|
||||||
import glob
|
import glob
|
||||||
import shutil
|
import shutil
|
||||||
import errno
|
import errno
|
||||||
|
@ -34,13 +33,17 @@ def copy_dir_contents(src, dest):
|
||||||
raise Exception('Directory not copied. Error: %s' % e)
|
raise Exception('Directory not copied. Error: %s' % e)
|
||||||
|
|
||||||
|
|
||||||
def write_cmake(module_path, import_alpha):
|
def write_cmake(module_path, import_options):
|
||||||
names = [' ' + os.path.basename(f) for f in glob.glob("%s/*.cpp" % module_path)]
|
names = [' ' + os.path.basename(f) for f in glob.glob("%s/*.cpp" % module_path)]
|
||||||
names += [' ' + os.path.basename(f) for f in glob.glob("%s/external/*.cpp" % module_path)]
|
|
||||||
if import_alpha:
|
if import_options["external"]:
|
||||||
alpha_names = [' ' + os.path.join("alpha", os.path.basename(f))
|
names += [' ' + os.path.join("external", os.path.basename(f))
|
||||||
for f in glob.glob("%s/alpha/*.cpp" % module_path)]
|
for f in glob.glob("%s/external/*.cpp" % (module_path))]
|
||||||
names += alpha_names
|
|
||||||
|
if import_options["alpha"]:
|
||||||
|
names += [' ' + os.path.join("alpha", os.path.basename(f))
|
||||||
|
for f in glob.glob("%s/alpha/*.cpp" % (module_path))]
|
||||||
|
|
||||||
with open(os.path.join(module_path, 'CMakeLists.txt'), 'w') as f:
|
with open(os.path.join(module_path, 'CMakeLists.txt'), 'w') as f:
|
||||||
f.write("""set(LLVM_LINK_COMPONENTS support)
|
f.write("""set(LLVM_LINK_COMPONENTS support)
|
||||||
|
|
||||||
|
@ -98,7 +101,7 @@ def generate_thread_allows(mozilla_path, module_path):
|
||||||
f.write(ThreadAllows.generate_allows({files, names}))
|
f.write(ThreadAllows.generate_allows({files, names}))
|
||||||
|
|
||||||
|
|
||||||
def do_import(mozilla_path, clang_tidy_path, import_alpha):
|
def do_import(mozilla_path, clang_tidy_path, import_options):
|
||||||
module = 'mozilla'
|
module = 'mozilla'
|
||||||
module_path = os.path.join(clang_tidy_path, module)
|
module_path = os.path.join(clang_tidy_path, module)
|
||||||
try:
|
try:
|
||||||
|
@ -110,7 +113,7 @@ def do_import(mozilla_path, clang_tidy_path, import_alpha):
|
||||||
copy_dir_contents(mozilla_path, module_path)
|
copy_dir_contents(mozilla_path, module_path)
|
||||||
write_third_party_paths(mozilla_path, module_path)
|
write_third_party_paths(mozilla_path, module_path)
|
||||||
generate_thread_allows(mozilla_path, module_path)
|
generate_thread_allows(mozilla_path, module_path)
|
||||||
write_cmake(module_path, import_alpha)
|
write_cmake(module_path, import_options)
|
||||||
add_moz_module(os.path.join(module_path, '..', 'CMakeLists.txt'))
|
add_moz_module(os.path.join(module_path, '..', 'CMakeLists.txt'))
|
||||||
with open(os.path.join(module_path, '..', 'CMakeLists.txt'), 'a') as f:
|
with open(os.path.join(module_path, '..', 'CMakeLists.txt'), 'a') as f:
|
||||||
f.write('add_subdirectory(%s)\n' % module)
|
f.write('add_subdirectory(%s)\n' % module)
|
||||||
|
@ -126,29 +129,36 @@ static int LLVM_ATTRIBUTE_UNUSED MozillaModuleAnchorDestination =
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
if len(sys.argv) < 3 or len(sys.argv) > 4:
|
import argparse
|
||||||
print("""\
|
|
||||||
Usage: import_mozilla_checks.py <mozilla-clang-plugin-path> <clang-tidy-path> [import_alpha]
|
|
||||||
Imports the Mozilla static analysis checks into a clang-tidy source tree.
|
|
||||||
If `import_alpha` is specified then in-tree alpha checkers will be also imported.
|
|
||||||
""")
|
|
||||||
|
|
||||||
return
|
parser = argparse.ArgumentParser(
|
||||||
|
usage="import_mozilla_checks.py <mozilla-clang-plugin-path> <clang-tidy-path> [option]",
|
||||||
|
description="Imports the Mozilla static analysis checks into a clang-tidy source tree."
|
||||||
|
)
|
||||||
|
parser.add_argument('mozilla_path',
|
||||||
|
help="Full path to mozilla-central/build/clang-plugin")
|
||||||
|
parser.add_argument('clang_tidy_path',
|
||||||
|
help="Full path to llvm-project/clang-tools-extra/clang-tidy")
|
||||||
|
parser.add_argument('--import-alpha',
|
||||||
|
help="Enable import of in-tree alpha checks",
|
||||||
|
action="store_true")
|
||||||
|
parser.add_argument('--import-external',
|
||||||
|
help="Enable import of in-tree external checks",
|
||||||
|
action="store_true")
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
mozilla_path = sys.argv[1]
|
if not os.path.isdir(args.mozilla_path):
|
||||||
if not os.path.isdir(mozilla_path):
|
|
||||||
print("Invalid path to mozilla clang plugin")
|
print("Invalid path to mozilla clang plugin")
|
||||||
|
|
||||||
clang_tidy_path = sys.argv[2]
|
if not os.path.isdir(args.clang_tidy_path):
|
||||||
if not os.path.isdir(mozilla_path):
|
|
||||||
print("Invalid path to clang-tidy source directory")
|
print("Invalid path to clang-tidy source directory")
|
||||||
|
|
||||||
import_alpha = False
|
import_options = {
|
||||||
|
"alpha": args.import_alpha,
|
||||||
|
"external": args.import_external
|
||||||
|
}
|
||||||
|
|
||||||
if len(sys.argv) == 4 and sys.argv[3] == 'import_alpha':
|
do_import(args.mozilla_path, args.clang_tidy_path, import_options)
|
||||||
import_alpha = True
|
|
||||||
|
|
||||||
do_import(mozilla_path, clang_tidy_path, import_alpha)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
Загрузка…
Ссылка в новой задаче