tp: fix metrics and stdlib on Android builds
Bug: 264711057
Change-Id: Ib66087e4aaaf294038539015785f0ea599824e5a
diff --git a/tools/gen_stdlib_docs_json.py b/tools/gen_stdlib_docs_json.py
index e6953d0..c89b7a7 100755
--- a/tools/gen_stdlib_docs_json.py
+++ b/tools/gen_stdlib_docs_json.py
@@ -30,7 +30,6 @@
parser = argparse.ArgumentParser()
parser.add_argument('--json-out', required=True)
parser.add_argument('--input-list-file')
- parser.add_argument('--root-dir', required=True)
parser.add_argument('sql_files', nargs='*')
args = parser.parse_args()
@@ -46,11 +45,23 @@
else:
sql_files = args.sql_files
+ # Unfortunately we cannot pass this in as an arg as soong does not provide
+ # us a way to get the path to the Perfetto source directory. This fails on
+ # empty path but it's a price worth paying to have to use gross hacks in
+ # Soong.
+ root_dir = os.path.commonpath(sql_files)
+
# Extract the SQL output from each file.
sql_outputs: Dict[str, str] = {}
for file_name in sql_files:
with open(file_name, 'r') as f:
- relpath = os.path.relpath(file_name, args.root_dir)
+ relpath = os.path.relpath(file_name, root_dir)
+
+ # We've had bugs (e.g. b/264711057) when Soong's common path logic breaks
+ # and ends up with a bunch of ../ prefixing the path: disallow any ../
+ # as this should never be a valid in our C++ output.
+ assert '../' not in relpath
+
sql_outputs[relpath] = f.read()
modules = defaultdict(list)