Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: provide escaped version of PRODUCT_DIR_ABS #271

Merged
merged 3 commits into from
Dec 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 22 additions & 9 deletions pylib/gyp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.


from __future__ import annotations
import copy
import gyp.input
import argparse
Expand All @@ -24,6 +24,18 @@
DEBUG_VARIABLES = "variables"
DEBUG_INCLUDES = "includes"

def EscapeForCString(string: bytes | str) -> str:
if isinstance(string, str):
string = string.encode(encoding='utf8')

backslash_or_double_quote = {ord('\\'), ord('"')}
result = []
for char in string:
if char in backslash_or_double_quote or not 32 <= char < 127:
result += '\\%03o' % char
else:
result += chr(char)
return result

def DebugOutput(mode, message, *args):
if "all" in gyp.debug or mode in gyp.debug:
Expand Down Expand Up @@ -106,18 +118,19 @@ def Load(

output_dir = params["options"].generator_output or params["options"].toplevel_dir
if default_variables["GENERATOR"] == "ninja":
default_variables.setdefault(
"PRODUCT_DIR_ABS",
os.path.join(
output_dir, "out", default_variables.get("build_type", "default")
),
product_dir_abs = os.path.join(
output_dir, "out", default_variables.get("build_type", "default")
)
else:
default_variables.setdefault(
"PRODUCT_DIR_ABS",
os.path.join(output_dir, default_variables["CONFIGURATION_NAME"]),
product_dir_abs = os.path.join(
output_dir, default_variables["CONFIGURATION_NAME"]
)

default_variables.setdefault("PRODUCT_DIR_ABS", product_dir_abs)
default_variables.setdefault(
"PRODUCT_DIR_ABS_CSTR", EscapeForCString(product_dir_abs)
)

# Give the generator the opportunity to set additional variables based on
# the params it will receive in the output phase.
if getattr(generator, "CalculateVariables", None):
Expand Down
Loading