From ce4ab516bb778a94224389b2bb92cd54f462e17d Mon Sep 17 00:00:00 2001 From: Ryan VanderMeulen Date: Mon, 27 Jun 2022 13:05:46 +0000 Subject: [PATCH] Bug 1776104 - Verify that the paths exist before writing ThirdPartyPaths.cpp. r=andi Differential Revision: https://phabricator.services.mozilla.com/D150069 --- build/clang-plugin/ThirdPartyPaths.py | 32 ++++++++++++++++++++- build/clang-plugin/import_mozilla_checks.py | 8 +++++- build/clang-plugin/moz.build | 3 +- tools/rewriting/Unvalidated.txt | 1 + 4 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 tools/rewriting/Unvalidated.txt diff --git a/build/clang-plugin/ThirdPartyPaths.py b/build/clang-plugin/ThirdPartyPaths.py index caaa919d43f28..bd9d236974052 100644 --- a/build/clang-plugin/ThirdPartyPaths.py +++ b/build/clang-plugin/ThirdPartyPaths.py @@ -1,6 +1,17 @@ #!/usr/bin/env python3 +import glob import json +import sys + +# Import buildconfig if available, otherwise set has_buildconfig to False so +# we skip the check which relies on it. +try: + import buildconfig +except ImportError: + has_buildconfig = False +else: + has_buildconfig = True def generate(output, *input_paths): @@ -11,6 +22,7 @@ def generate(output, *input_paths): """ tpp_list = [] lines = set() + path_found = True for path in input_paths: with open(path) as f: @@ -20,7 +32,25 @@ def generate(output, *input_paths): line = line.strip() if line.endswith("/"): line = line[:-1] - tpp_list.append(line) + + if has_buildconfig: + # Ignore lines starting with $UNVALIDATED + # These should only be coming from Unvalidated.txt + if line.startswith("$UNVALIDATED"): + line = line[13:] + elif not glob.glob(buildconfig.topsrcdir + "/" + line): + path_found = False + + if path_found: + tpp_list.append(line) + else: + print( + "Third-party path " + + line + + " does not exist. Remove it from Generated.txt or " + + "ThirdPartyPaths.txt and try again." + ) + sys.exit(1) tpp_strings = ",\n ".join([json.dumps(tpp) for tpp in sorted(tpp_list)]) output.write( diff --git a/build/clang-plugin/import_mozilla_checks.py b/build/clang-plugin/import_mozilla_checks.py index 70585c88594b4..e6de6987b0248 100755 --- a/build/clang-plugin/import_mozilla_checks.py +++ b/build/clang-plugin/import_mozilla_checks.py @@ -95,8 +95,14 @@ def add_moz_module(cmake_path): def write_third_party_paths(mozilla_path, module_path): tpp_txt = os.path.join(mozilla_path, "../../tools/rewriting/ThirdPartyPaths.txt") generated_txt = os.path.join(mozilla_path, "../../tools/rewriting/Generated.txt") + # Unvalidated.txt is used for rare cases where we don't want to validate that a given + # path exists but still want it included in the ThirdPartyPaths check in the plugin. + # For example, headers exported to dist/include that live elsewhere. + unvalidated_txt = os.path.join( + mozilla_path, "../../tools/rewriting/Unvalidated.txt" + ) with open(os.path.join(module_path, "ThirdPartyPaths.cpp"), "w") as f: - ThirdPartyPaths.generate(f, tpp_txt, generated_txt) + ThirdPartyPaths.generate(f, tpp_txt, generated_txt, unvalidated_txt) def generate_thread_allows(mozilla_path, module_path): diff --git a/build/clang-plugin/moz.build b/build/clang-plugin/moz.build index 5fc8c1d0e391d..a7495d0e94374 100644 --- a/build/clang-plugin/moz.build +++ b/build/clang-plugin/moz.build @@ -70,8 +70,9 @@ GeneratedFile( script="ThirdPartyPaths.py", entry_point="generate", inputs=[ - "/tools/rewriting/ThirdPartyPaths.txt", "/tools/rewriting/Generated.txt", + "/tools/rewriting/ThirdPartyPaths.txt", + "/tools/rewriting/Unvalidated.txt", ], ) diff --git a/tools/rewriting/Unvalidated.txt b/tools/rewriting/Unvalidated.txt new file mode 100644 index 0000000000000..96f540d1f19a3 --- /dev/null +++ b/tools/rewriting/Unvalidated.txt @@ -0,0 +1 @@ +$UNVALIDATED/function2