|
4 | 4 | # Use of this source code is governed by a BSD-style license that can be |
5 | 5 | # found in the LICENSE file. |
6 | 6 |
|
7 | | - |
| 7 | +from __future__ import annotations |
8 | 8 | import copy |
9 | 9 | import gyp.input |
10 | 10 | import argparse |
|
24 | 24 | DEBUG_VARIABLES = "variables" |
25 | 25 | DEBUG_INCLUDES = "includes" |
26 | 26 |
|
| 27 | +def EscapeForCString(string: bytes | str) -> str: |
| 28 | + if isinstance(string, str): |
| 29 | + string = string.encode(encoding='utf8') |
| 30 | + |
| 31 | + backslash_or_double_quote = {ord('\\'), ord('"')} |
| 32 | + result = '' |
| 33 | + for char in string: |
| 34 | + if char in backslash_or_double_quote or not 32 <= char < 127: |
| 35 | + result += '\\%03o' % char |
| 36 | + else: |
| 37 | + result += chr(char) |
| 38 | + return result |
27 | 39 |
|
28 | 40 | def DebugOutput(mode, message, *args): |
29 | 41 | if "all" in gyp.debug or mode in gyp.debug: |
@@ -106,18 +118,19 @@ def Load( |
106 | 118 |
|
107 | 119 | output_dir = params["options"].generator_output or params["options"].toplevel_dir |
108 | 120 | if default_variables["GENERATOR"] == "ninja": |
109 | | - default_variables.setdefault( |
110 | | - "PRODUCT_DIR_ABS", |
111 | | - os.path.join( |
112 | | - output_dir, "out", default_variables.get("build_type", "default") |
113 | | - ), |
| 121 | + product_dir_abs = os.path.join( |
| 122 | + output_dir, "out", default_variables.get("build_type", "default") |
114 | 123 | ) |
115 | 124 | else: |
116 | | - default_variables.setdefault( |
117 | | - "PRODUCT_DIR_ABS", |
118 | | - os.path.join(output_dir, default_variables["CONFIGURATION_NAME"]), |
| 125 | + product_dir_abs = os.path.join( |
| 126 | + output_dir, default_variables["CONFIGURATION_NAME"] |
119 | 127 | ) |
120 | 128 |
|
| 129 | + default_variables.setdefault("PRODUCT_DIR_ABS", product_dir_abs) |
| 130 | + default_variables.setdefault( |
| 131 | + "PRODUCT_DIR_ABS_CSTR", EscapeForCString(product_dir_abs) |
| 132 | + ) |
| 133 | + |
121 | 134 | # Give the generator the opportunity to set additional variables based on |
122 | 135 | # the params it will receive in the output phase. |
123 | 136 | if getattr(generator, "CalculateVariables", None): |
@@ -253,7 +266,7 @@ def Noop(value): |
253 | 266 | for name, metadata in options._regeneration_metadata.items(): |
254 | 267 | opt = metadata["opt"] |
255 | 268 | value = getattr(options, name) |
256 | | - value_predicate = metadata["type"] == "path" and FixPath or Noop |
| 269 | + value_predicate = (metadata["type"] == "path" and FixPath) or Noop |
257 | 270 | action = metadata["action"] |
258 | 271 | env_name = metadata["env_name"] |
259 | 272 | if action == "append": |
|
0 commit comments