Skip to content

Commit

Permalink
feat: provide escaped version of PRODUCT_DIR_ABS
Browse files Browse the repository at this point in the history
Since Node.js uses this in a C string, we should provide a version that
escapes it as a C string.
  • Loading branch information
addaleax committed Dec 2, 2024
1 parent db89089 commit 73ea33a
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions pylib/gyp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,17 @@
DEBUG_VARIABLES = "variables"
DEBUG_INCLUDES = "includes"

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

result = ''
for char in string:
if not (32 <= char < 127) or char in (ord('\\'), ord('"')):
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,17 +117,14 @@ 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"])

Check failure on line 124 in pylib/gyp/__init__.py

View workflow job for this annotation

GitHub Actions / Python_tests (macos-13, 3.8)

Ruff (E501)

pylib/gyp/__init__.py:124:89: E501 Line too long (91 > 88)

Check failure on line 124 in pylib/gyp/__init__.py

View workflow job for this annotation

GitHub Actions / Python_tests (macos-13, 3.12)

Ruff (E501)

pylib/gyp/__init__.py:124:89: E501 Line too long (91 > 88)

Check failure on line 124 in pylib/gyp/__init__.py

View workflow job for this annotation

GitHub Actions / Python_tests (macos-13, 3.10)

Ruff (E501)

pylib/gyp/__init__.py:124:89: E501 Line too long (91 > 88)

Check failure on line 124 in pylib/gyp/__init__.py

View workflow job for this annotation

GitHub Actions / Python_tests (macos-13, 3.9)

Ruff (E501)

pylib/gyp/__init__.py:124:89: E501 Line too long (91 > 88)

Check failure on line 124 in pylib/gyp/__init__.py

View workflow job for this annotation

GitHub Actions / Python_tests (macos-13, 3.11)

Ruff (E501)

pylib/gyp/__init__.py:124:89: E501 Line too long (91 > 88)

Check failure on line 124 in pylib/gyp/__init__.py

View workflow job for this annotation

GitHub Actions / Python_tests (macos-14, 3.11)

Ruff (E501)

pylib/gyp/__init__.py:124:89: E501 Line too long (91 > 88)

Check failure on line 124 in pylib/gyp/__init__.py

View workflow job for this annotation

GitHub Actions / Python_tests (macos-13, 3.13)

Ruff (E501)

pylib/gyp/__init__.py:124:89: E501 Line too long (91 > 88)

Check failure on line 124 in pylib/gyp/__init__.py

View workflow job for this annotation

GitHub Actions / Python_tests (macos-14, 3.12)

Ruff (E501)

pylib/gyp/__init__.py:124:89: E501 Line too long (91 > 88)

Check failure on line 124 in pylib/gyp/__init__.py

View workflow job for this annotation

GitHub Actions / Python_tests (macos-14, 3.13)

Ruff (E501)

pylib/gyp/__init__.py:124:89: E501 Line too long (91 > 88)

Check failure on line 124 in pylib/gyp/__init__.py

View workflow job for this annotation

GitHub Actions / Python_tests (macos-14, 3.9)

Ruff (E501)

pylib/gyp/__init__.py:124:89: E501 Line too long (91 > 88)

Check failure on line 124 in pylib/gyp/__init__.py

View workflow job for this annotation

GitHub Actions / Python_tests (macos-14, 3.10)

Ruff (E501)

pylib/gyp/__init__.py:124:89: E501 Line too long (91 > 88)

Check failure on line 124 in pylib/gyp/__init__.py

View workflow job for this annotation

GitHub Actions / Python_tests (macos-14, 3.8)

Ruff (E501)

pylib/gyp/__init__.py:124:89: E501 Line too long (91 > 88)

Check failure on line 124 in pylib/gyp/__init__.py

View workflow job for this annotation

GitHub Actions / Python_tests (ubuntu-latest, 3.9)

Ruff (E501)

pylib/gyp/__init__.py:124:89: E501 Line too long (91 > 88)

Check failure on line 124 in pylib/gyp/__init__.py

View workflow job for this annotation

GitHub Actions / Python_tests (ubuntu-latest, 3.11)

Ruff (E501)

pylib/gyp/__init__.py:124:89: E501 Line too long (91 > 88)

Check failure on line 124 in pylib/gyp/__init__.py

View workflow job for this annotation

GitHub Actions / Python_tests (ubuntu-latest, 3.8)

Ruff (E501)

pylib/gyp/__init__.py:124:89: E501 Line too long (91 > 88)

Check failure on line 124 in pylib/gyp/__init__.py

View workflow job for this annotation

GitHub Actions / Python_tests (ubuntu-latest, 3.10)

Ruff (E501)

pylib/gyp/__init__.py:124:89: E501 Line too long (91 > 88)

Check failure on line 124 in pylib/gyp/__init__.py

View workflow job for this annotation

GitHub Actions / Python_tests (ubuntu-latest, 3.12)

Ruff (E501)

pylib/gyp/__init__.py:124:89: E501 Line too long (91 > 88)

Check failure on line 124 in pylib/gyp/__init__.py

View workflow job for this annotation

GitHub Actions / Python_tests (ubuntu-latest, 3.13)

Ruff (E501)

pylib/gyp/__init__.py:124:89: E501 Line too long (91 > 88)

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

Check failure on line 127 in pylib/gyp/__init__.py

View workflow job for this annotation

GitHub Actions / Python_tests (macos-13, 3.8)

Ruff (E501)

pylib/gyp/__init__.py:127:89: E501 Line too long (91 > 88)

Check failure on line 127 in pylib/gyp/__init__.py

View workflow job for this annotation

GitHub Actions / Python_tests (macos-13, 3.12)

Ruff (E501)

pylib/gyp/__init__.py:127:89: E501 Line too long (91 > 88)

Check failure on line 127 in pylib/gyp/__init__.py

View workflow job for this annotation

GitHub Actions / Python_tests (macos-13, 3.10)

Ruff (E501)

pylib/gyp/__init__.py:127:89: E501 Line too long (91 > 88)

Check failure on line 127 in pylib/gyp/__init__.py

View workflow job for this annotation

GitHub Actions / Python_tests (macos-13, 3.9)

Ruff (E501)

pylib/gyp/__init__.py:127:89: E501 Line too long (91 > 88)

Check failure on line 127 in pylib/gyp/__init__.py

View workflow job for this annotation

GitHub Actions / Python_tests (macos-13, 3.11)

Ruff (E501)

pylib/gyp/__init__.py:127:89: E501 Line too long (91 > 88)

Check failure on line 127 in pylib/gyp/__init__.py

View workflow job for this annotation

GitHub Actions / Python_tests (macos-14, 3.11)

Ruff (E501)

pylib/gyp/__init__.py:127:89: E501 Line too long (91 > 88)

Check failure on line 127 in pylib/gyp/__init__.py

View workflow job for this annotation

GitHub Actions / Python_tests (macos-13, 3.13)

Ruff (E501)

pylib/gyp/__init__.py:127:89: E501 Line too long (91 > 88)

Check failure on line 127 in pylib/gyp/__init__.py

View workflow job for this annotation

GitHub Actions / Python_tests (macos-14, 3.12)

Ruff (E501)

pylib/gyp/__init__.py:127:89: E501 Line too long (91 > 88)

Check failure on line 127 in pylib/gyp/__init__.py

View workflow job for this annotation

GitHub Actions / Python_tests (macos-14, 3.13)

Ruff (E501)

pylib/gyp/__init__.py:127:89: E501 Line too long (91 > 88)

Check failure on line 127 in pylib/gyp/__init__.py

View workflow job for this annotation

GitHub Actions / Python_tests (macos-14, 3.9)

Ruff (E501)

pylib/gyp/__init__.py:127:89: E501 Line too long (91 > 88)

Check failure on line 127 in pylib/gyp/__init__.py

View workflow job for this annotation

GitHub Actions / Python_tests (macos-14, 3.10)

Ruff (E501)

pylib/gyp/__init__.py:127:89: E501 Line too long (91 > 88)

Check failure on line 127 in pylib/gyp/__init__.py

View workflow job for this annotation

GitHub Actions / Python_tests (macos-14, 3.8)

Ruff (E501)

pylib/gyp/__init__.py:127:89: E501 Line too long (91 > 88)

Check failure on line 127 in pylib/gyp/__init__.py

View workflow job for this annotation

GitHub Actions / Python_tests (ubuntu-latest, 3.9)

Ruff (E501)

pylib/gyp/__init__.py:127:89: E501 Line too long (91 > 88)

Check failure on line 127 in pylib/gyp/__init__.py

View workflow job for this annotation

GitHub Actions / Python_tests (ubuntu-latest, 3.11)

Ruff (E501)

pylib/gyp/__init__.py:127:89: E501 Line too long (91 > 88)

Check failure on line 127 in pylib/gyp/__init__.py

View workflow job for this annotation

GitHub Actions / Python_tests (ubuntu-latest, 3.8)

Ruff (E501)

pylib/gyp/__init__.py:127:89: E501 Line too long (91 > 88)

Check failure on line 127 in pylib/gyp/__init__.py

View workflow job for this annotation

GitHub Actions / Python_tests (ubuntu-latest, 3.10)

Ruff (E501)

pylib/gyp/__init__.py:127:89: E501 Line too long (91 > 88)

Check failure on line 127 in pylib/gyp/__init__.py

View workflow job for this annotation

GitHub Actions / Python_tests (ubuntu-latest, 3.12)

Ruff (E501)

pylib/gyp/__init__.py:127:89: E501 Line too long (91 > 88)

Check failure on line 127 in pylib/gyp/__init__.py

View workflow job for this annotation

GitHub Actions / Python_tests (ubuntu-latest, 3.13)

Ruff (E501)

pylib/gyp/__init__.py:127:89: E501 Line too long (91 > 88)

# Give the generator the opportunity to set additional variables based on
# the params it will receive in the output phase.
Expand Down

0 comments on commit 73ea33a

Please sign in to comment.