diff --git a/build/build-clang/build-clang.py b/build/build-clang/build-clang.py index 8b82918c3f3a..117264fa2d41 100755 --- a/build/build-clang/build-clang.py +++ b/build/build-clang/build-clang.py @@ -105,7 +105,11 @@ def import_clang_tidy(source_dir, build_clang_tidy_alpha): 'clang-tools-extra/clang-tidy') sys.path.append(clang_plugin_path) 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): diff --git a/build/clang-plugin/import_mozilla_checks.py b/build/clang-plugin/import_mozilla_checks.py index ddf3a175c0aa..b4a4e002c0a9 100755 --- a/build/clang-plugin/import_mozilla_checks.py +++ b/build/clang-plugin/import_mozilla_checks.py @@ -4,7 +4,6 @@ # file, You can obtain one at http://mozilla.org/MPL/2.0/. import os -import sys import glob import shutil import errno @@ -34,13 +33,17 @@ def copy_dir_contents(src, dest): 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/external/*.cpp" % module_path)] - if import_alpha: - alpha_names = [' ' + os.path.join("alpha", os.path.basename(f)) - for f in glob.glob("%s/alpha/*.cpp" % module_path)] - names += alpha_names + + if import_options["external"]: + names += [' ' + os.path.join("external", os.path.basename(f)) + for f in glob.glob("%s/external/*.cpp" % (module_path))] + + 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: 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})) -def do_import(mozilla_path, clang_tidy_path, import_alpha): +def do_import(mozilla_path, clang_tidy_path, import_options): module = 'mozilla' module_path = os.path.join(clang_tidy_path, module) try: @@ -110,7 +113,7 @@ def do_import(mozilla_path, clang_tidy_path, import_alpha): copy_dir_contents(mozilla_path, module_path) write_third_party_paths(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')) with open(os.path.join(module_path, '..', 'CMakeLists.txt'), 'a') as f: f.write('add_subdirectory(%s)\n' % module) @@ -126,29 +129,36 @@ static int LLVM_ATTRIBUTE_UNUSED MozillaModuleAnchorDestination = def main(): - if len(sys.argv) < 3 or len(sys.argv) > 4: - print("""\ -Usage: import_mozilla_checks.py [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. -""") + import argparse - return + parser = argparse.ArgumentParser( + usage="import_mozilla_checks.py [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(mozilla_path): + if not os.path.isdir(args.mozilla_path): print("Invalid path to mozilla clang plugin") - clang_tidy_path = sys.argv[2] - if not os.path.isdir(mozilla_path): + if not os.path.isdir(args.clang_tidy_path): 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': - import_alpha = True - - do_import(mozilla_path, clang_tidy_path, import_alpha) + do_import(args.mozilla_path, args.clang_tidy_path, import_options) if __name__ == '__main__':