Bug 1776104 - Verify that the paths exist before writing ThirdPartyPaths.cpp. r=andi

Differential Revision: https://phabricator.services.mozilla.com/D150069
This commit is contained in:
Ryan VanderMeulen 2022-06-27 13:05:46 +00:00
parent b8e30b3751
commit ce4ab516bb
4 changed files with 41 additions and 3 deletions

View File

@ -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(

View File

@ -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):

View File

@ -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",
],
)

View File

@ -0,0 +1 @@
$UNVALIDATED/function2