Skip to content

Commit

Permalink
Bug 1776104 - Verify that the paths exist before writing ThirdPartyPa…
Browse files Browse the repository at this point in the history
…ths.cpp. r=andi

Differential Revision: https://phabricator.services.mozilla.com/D150069
  • Loading branch information
rvandermeulen committed Jun 27, 2022
1 parent b8e30b3 commit ce4ab51
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 3 deletions.
32 changes: 31 additions & 1 deletion build/clang-plugin/ThirdPartyPaths.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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:
Expand All @@ -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(
Expand Down
8 changes: 7 additions & 1 deletion build/clang-plugin/import_mozilla_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
3 changes: 2 additions & 1 deletion build/clang-plugin/moz.build
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
)

Expand Down
1 change: 1 addition & 0 deletions tools/rewriting/Unvalidated.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$UNVALIDATED/function2

0 comments on commit ce4ab51

Please sign in to comment.