|
| 1 | +# @node-versions: v24.10.0+ |
| 2 | +# @description: Fix inspector protocol code generator on Windows |
| 3 | +# |
| 4 | +# On Windows, the --config_value argument passing through gyp-win-tool and |
| 5 | +# ninja response files fails to properly set config.protocol.path, causing: |
| 6 | +# AttributeError: 'X' object has no attribute 'path' |
| 7 | +# |
| 8 | +# This patch modifies code_generator.py to accept the config file path and |
| 9 | +# compute the protocol path from it when --config_value fails to set it. |
| 10 | +# |
| 11 | +# Root cause: When ninja executes the action through gyp-win-tool action-wrapper |
| 12 | +# on Windows, arguments in response files (.rsp) don't preserve the |
| 13 | +# --config_value protocol.path=... argument correctly, so the path attribute |
| 14 | +# never gets added to the protocol config object by init_defaults(). |
| 15 | +# |
| 16 | +# Solution: |
| 17 | +# 1. Modify Protocol.__init__() to accept config_file parameter |
| 18 | +# 2. Compute protocol path from config file location when missing |
| 19 | +# 3. Add the path to config.protocol so main() can use it |
| 20 | +# |
| 21 | +# Original error: |
| 22 | +# AttributeError: 'X' object has no attribute 'path' |
| 23 | +# At: code_generator.py:365 in Protocol.__init__ |
| 24 | +# |
| 25 | +# References: |
| 26 | +# - Node.js v24 gyp build system Windows argument passing |
| 27 | +# - tools/v8_gypfiles/v8.gyp protocol_generated_sources action |
| 28 | + |
| 29 | +--- a/deps/v8/third_party/inspector_protocol/code_generator.py |
| 30 | ++++ b/deps/v8/third_party/inspector_protocol/code_generator.py |
| 31 | +@@ -359,12 +359,27 @@ def to_file_name(config, file_name): |
| 32 | + |
| 33 | + class Protocol(object): |
| 34 | +- def __init__(self, config): |
| 35 | ++ def __init__(self, config, config_file=None): |
| 36 | + self.config = config |
| 37 | + self.json_api = {"domains": []} |
| 38 | + self.imported_domains = [] |
| 39 | + self.exported_domains = [] |
| 40 | +- self.generate_domains = self.read_protocol_file(config.protocol.path) |
| 41 | ++ # Windows gyp-win-tool may fail to pass --config_value correctly. |
| 42 | ++ # Fall back to computing the path from the config file location. |
| 43 | ++ if hasattr(config.protocol, 'path'): |
| 44 | ++ protocol_path = config.protocol.path |
| 45 | ++ else: |
| 46 | ++ # Compute path from config file: deps/v8/src/inspector -> deps/v8/include |
| 47 | ++ if config_file: |
| 48 | ++ config_dir = os.path.dirname(config_file) |
| 49 | ++ protocol_path = os.path.normpath(os.path.join(config_dir, '../../include/js_protocol.pdl')) |
| 50 | ++ else: |
| 51 | ++ raise Exception("config.protocol.path not set and config_file not provided") |
| 52 | ++ # Add path to config so main() can use it later. |
| 53 | ++ protocol_obj = config.protocol._replace(path=protocol_path) |
| 54 | ++ config = config._replace(protocol=protocol_obj) |
| 55 | ++ self.config = config |
| 56 | ++ self.generate_domains = self.read_protocol_file(protocol_path) |
| 57 | + |
| 58 | + if config.protocol.options: |
| 59 | + self.generate_domains = [rule.domain for rule in config.protocol.options] |
| 60 | +@@ -605,7 +620,7 @@ def write_object_h(domain, output_dir, header_guard_prefix, config, templates, |
| 61 | + |
| 62 | + def main(): |
| 63 | + jinja_dir, config_file, config = read_config() |
| 64 | +- protocol = Protocol(config) |
| 65 | ++ protocol = Protocol(config, config_file) |
| 66 | + if not config.exported and len(protocol.exported_domains): |
| 67 | + sys.stderr.write(("Domains [%s] are exported, but config is missing export " |
| 68 | + "entry\n\n") % ", ".join(protocol.exported_domains)) |
0 commit comments