tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit a0b750c5fc0df2f7ab481542365d24cc42645465
parent 934a439e0e1655d0ee64b28ce6cdfea7db3dd35b
Author: serge-sans-paille <sguelton@mozilla.com>
Date:   Tue, 16 Dec 2025 13:47:13 +0000

Bug 2002798 - Shortpath for find_variables_from_ast r=ahochheiden

It's very common to ask for variables that are not present in many
moz.build files. In that case we can perform a fast quick check through
regular expression before parsing the actual files.

This speeds up taskgraph construction by 500ms.

Differential Revision: https://phabricator.services.mozilla.com/D274298

Diffstat:
Mpython/mozbuild/mozbuild/frontend/reader.py | 13++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/python/mozbuild/mozbuild/frontend/reader.py b/python/mozbuild/mozbuild/frontend/reader.py @@ -21,6 +21,7 @@ import functools import inspect import logging import os +import re import sys import textwrap import time @@ -996,10 +997,11 @@ class BuildReader: <variable name>, <key>, <value>)`. The `key` will only be defined if the variable is an object, otherwise it is `None`. """ - if isinstance(variables, str): variables = [variables] + variables_matcher = re.compile("|".join(variables)) + def assigned_variable(node): # This is not correct, but we don't care yet. if hasattr(node, "targets"): @@ -1080,12 +1082,17 @@ class BuildReader: mozbuild_paths = self.all_mozbuild_paths() for p in mozbuild_paths: - assignments[:] = [] full = os.path.join(self.config.topsrcdir, p) - with open(full, "rb") as fh: + with open(full) as fh: source = fh.read() + # No need to do the heavy parsing if there is no literal mention of + # the variables + if not re.search(variables_matcher, source): + continue + + assignments[:] = [] tree = ast.parse(source, full) Visitor().visit(tree)