Skip to content

tools: update gyp-next to 0.20.2 #58788

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

Merged
merged 1 commit into from
Jun 26, 2025
Merged
Show file tree
Hide file tree
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
15 changes: 15 additions & 0 deletions tools/gyp/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
# Changelog

## [0.20.2](https://github.com/nodejs/gyp-next/compare/v0.20.1...v0.20.2) (2025-06-22)


### Bug Fixes

* Python lint import-outside-top-level ruff rule PLC0415 ([#298](https://github.com/nodejs/gyp-next/issues/298)) ([34f4df6](https://github.com/nodejs/gyp-next/commit/34f4df614936ee6a056e47406ebbe7e3c1cb6540))

## [0.20.1](https://github.com/nodejs/gyp-next/compare/v0.20.0...v0.20.1) (2025-06-06)


### Bug Fixes

* Ensure Consistent Order of build_files in WriteAutoRegenerationRule ([#293](https://github.com/nodejs/gyp-next/issues/293)) ([59b5903](https://github.com/nodejs/gyp-next/commit/59b59035f4ae63419343ffdafe0f0ff511ada17d))
* ignore failure of `GetCompilerPredefines` ([#295](https://github.com/nodejs/gyp-next/issues/295)) ([0eaea29](https://github.com/nodejs/gyp-next/commit/0eaea297f0fbb0869597aa162f66f78eb2468fad))

## [0.20.0](https://github.com/nodejs/gyp-next/compare/v0.19.1...v0.20.0) (2025-03-27)


Expand Down
3 changes: 1 addition & 2 deletions tools/gyp/pylib/gyp/MSVSSettings.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,8 +396,7 @@ def _ValidateExclusionSetting(setting, settings, error_msg, stderr=sys.stderr):
# This may be unrecognized because it's an exclusion list. If the
# setting name has the _excluded suffix, then check the root name.
unrecognized = True
m = re.match(_EXCLUDED_SUFFIX_RE, setting)
if m:
if m := re.match(_EXCLUDED_SUFFIX_RE, setting):
root_setting = m.group(1)
unrecognized = root_setting not in settings

Expand Down
5 changes: 2 additions & 3 deletions tools/gyp/pylib/gyp/MSVSVersion.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ def _RegistryGetValueUsingWinReg(key, value):
contents of the registry key's value, or None on failure. Throws
ImportError if winreg is unavailable.
"""
from winreg import HKEY_LOCAL_MACHINE, OpenKey, QueryValueEx
from winreg import HKEY_LOCAL_MACHINE, OpenKey, QueryValueEx # noqa: PLC0415
try:
root, subkey = key.split("\\", 1)
assert root == "HKLM" # Only need HKLM for now.
Expand Down Expand Up @@ -552,8 +552,7 @@ def SelectVisualStudioVersion(version="auto", allow_fallback=True):
"2019": ("16.0",),
"2022": ("17.0",),
}
override_path = os.environ.get("GYP_MSVS_OVERRIDE_PATH")
if override_path:
if override_path := os.environ.get("GYP_MSVS_OVERRIDE_PATH"):
msvs_version = os.environ.get("GYP_MSVS_VERSION")
if not msvs_version:
raise ValueError(
Expand Down
2 changes: 1 addition & 1 deletion tools/gyp/pylib/gyp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ def gyp_main(args):

options, build_files_arg = parser.parse_args(args)
if options.version:
import pkg_resources
import pkg_resources # noqa: PLC0415
print(f"v{pkg_resources.get_distribution('gyp-next').version}")
return 0
build_files = build_files_arg
Expand Down
36 changes: 27 additions & 9 deletions tools/gyp/pylib/gyp/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,8 +421,9 @@ def EnsureDirExists(path):
except OSError:
pass

def GetCrossCompilerPredefines(): # -> dict
def GetCompilerPredefines(): # -> dict
cmd = []
defines = {}

# shlex.split() will eat '\' in posix mode, but
# setting posix=False will preserve extra '"' cause CreateProcess fail on Windows
Expand All @@ -439,7 +440,7 @@ def replace_sep(s):
if CXXFLAGS := os.environ.get("CXXFLAGS"):
cmd += shlex.split(replace_sep(CXXFLAGS))
else:
return {}
return defines

if sys.platform == "win32":
fd, input = tempfile.mkstemp(suffix=".c")
Expand All @@ -450,17 +451,33 @@ def replace_sep(s):
real_cmd, shell=True,
capture_output=True, check=True
).stdout
except subprocess.CalledProcessError as e:
print(
"Warning: failed to get compiler predefines\n"
"cmd: %s\n"
"status: %d" % (e.cmd, e.returncode),
file=sys.stderr
)
return defines
finally:
os.unlink(input)
else:
input = "/dev/null"
real_cmd = [*cmd, "-dM", "-E", "-x", "c", input]
stdout = subprocess.run(
real_cmd, shell=False,
capture_output=True, check=True
).stdout
try:
stdout = subprocess.run(
real_cmd, shell=False,
capture_output=True, check=True
).stdout
except subprocess.CalledProcessError as e:
print(
"Warning: failed to get compiler predefines\n"
"cmd: %s\n"
"status: %d" % (e.cmd, e.returncode),
file=sys.stderr
)
return defines

defines = {}
lines = stdout.decode("utf-8").replace("\r\n", "\n").split("\n")
for line in lines:
if (line or "").startswith("#define "):
Expand Down Expand Up @@ -499,7 +516,7 @@ def GetFlavor(params):
if "flavor" in params:
return params["flavor"]

defines = GetCrossCompilerPredefines()
defines = GetCompilerPredefines()
if "__EMSCRIPTEN__" in defines:
return "emscripten"
if "__wasm__" in defines:
Expand Down Expand Up @@ -566,7 +583,8 @@ def uniquer(seq, idfun=lambda x: x):


# Based on http://code.activestate.com/recipes/576694/.
class OrderedSet(MutableSet):
class OrderedSet(MutableSet): # noqa: PLW1641
# TODO (cclauss): Fix eq-without-hash ruff rule PLW1641
def __init__(self, iterable=None):
self.end = end = []
end += [None, end, end] # sentinel node for doubly linked list
Expand Down
32 changes: 24 additions & 8 deletions tools/gyp/pylib/gyp/common_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"""Unit tests for the common.py file."""

import os
import subprocess
import sys
import unittest
from unittest.mock import MagicMock, patch
Expand Down Expand Up @@ -85,22 +86,34 @@ def decode(self, encoding):
@patch("os.close")
@patch("os.unlink")
@patch("tempfile.mkstemp")
def test_GetCrossCompilerPredefines(self, mock_mkstemp, mock_unlink, mock_close):
def test_GetCompilerPredefines(self, mock_mkstemp, mock_unlink, mock_close):
mock_close.return_value = None
mock_unlink.return_value = None
mock_mkstemp.return_value = (0, "temp.c")

def mock_run(env, defines_stdout, expected_cmd):
def mock_run(env, defines_stdout, expected_cmd, throws=False):
with patch("subprocess.run") as mock_run:
mock_process = MagicMock()
mock_process.returncode = 0
mock_process.stdout = TestGetFlavor.MockCommunicate(defines_stdout)
mock_run.return_value = mock_process
expected_input = "temp.c" if sys.platform == "win32" else "/dev/null"
if throws:
mock_run.side_effect = subprocess.CalledProcessError(
returncode=1,
cmd=[
*expected_cmd,
"-dM", "-E", "-x", "c", expected_input
]
)
else:
mock_process = MagicMock()
mock_process.returncode = 0
mock_process.stdout = TestGetFlavor.MockCommunicate(defines_stdout)
mock_run.return_value = mock_process
with patch.dict(os.environ, env):
defines = gyp.common.GetCrossCompilerPredefines()
try:
defines = gyp.common.GetCompilerPredefines()
except Exception as e:
self.fail(f"GetCompilerPredefines raised an exception: {e}")
flavor = gyp.common.GetFlavor({})
if env.get("CC_target"):
if env.get("CC_target") or env.get("CC"):
mock_run.assert_called_with(
[
*expected_cmd,
Expand All @@ -110,6 +123,9 @@ def mock_run(env, defines_stdout, expected_cmd):
capture_output=True, check=True)
return [defines, flavor]

[defines0, _] = mock_run({ "CC": "cl.exe" }, "", ["cl.exe"], True)
assert defines0 == {}

[defines1, _] = mock_run({}, "", [])
assert defines1 == {}

Expand Down
3 changes: 1 addition & 2 deletions tools/gyp/pylib/gyp/generator/android.py
Original file line number Diff line number Diff line change
Expand Up @@ -900,8 +900,7 @@ def WriteTarget(
if self.type != "none":
self.WriteTargetFlags(spec, configs, link_deps)

settings = spec.get("aosp_build_settings", {})
if settings:
if settings := spec.get("aosp_build_settings", {}):
self.WriteLn("### Set directly by aosp_build_settings.")
for k, v in settings.items():
if isinstance(v, list):
Expand Down
6 changes: 2 additions & 4 deletions tools/gyp/pylib/gyp/generator/cmake.py
Original file line number Diff line number Diff line change
Expand Up @@ -810,8 +810,7 @@ def WriteTarget(
# link directories to targets defined after it is called.
# As a result, link_directories must come before the target definition.
# CMake unfortunately has no means of removing entries from LINK_DIRECTORIES.
library_dirs = config.get("library_dirs")
if library_dirs is not None:
if (library_dirs := config.get("library_dirs")) is not None:
output.write("link_directories(")
for library_dir in library_dirs:
output.write(" ")
Expand Down Expand Up @@ -1295,8 +1294,7 @@ def CallGenerateOutputForConfig(arglist):


def GenerateOutput(target_list, target_dicts, data, params):
user_config = params.get("generator_flags", {}).get("config", None)
if user_config:
if user_config := params.get("generator_flags", {}).get("config", None):
GenerateOutputForConfig(target_list, target_dicts, data, params, user_config)
else:
config_names = target_dicts[target_list[0]]["configurations"]
Expand Down
3 changes: 1 addition & 2 deletions tools/gyp/pylib/gyp/generator/eclipse.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,8 +451,7 @@ def GenerateOutput(target_list, target_dicts, data, params):
if params["options"].generator_output:
raise NotImplementedError("--generator_output not implemented for eclipse")

user_config = params.get("generator_flags", {}).get("config", None)
if user_config:
if user_config := params.get("generator_flags", {}).get("config", None):
GenerateOutputForConfig(target_list, target_dicts, data, params, user_config)
else:
config_names = target_dicts[target_list[0]]["configurations"]
Expand Down
10 changes: 4 additions & 6 deletions tools/gyp/pylib/gyp/generator/make.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def CalculateVariables(default_variables, params):

# Copy additional generator configuration data from Xcode, which is shared
# by the Mac Make generator.
import gyp.generator.xcode as xcode_generator
import gyp.generator.xcode as xcode_generator # noqa: PLC0415

global generator_additional_non_configuration_keys
generator_additional_non_configuration_keys = getattr(
Expand Down Expand Up @@ -1465,8 +1465,7 @@ def WriteSources(
order_only=True,
)

pchdeps = precompiled_header.GetObjDependencies(compilable, objs)
if pchdeps:
if pchdeps := precompiled_header.GetObjDependencies(compilable, objs):
self.WriteLn("# Dependencies from obj files to their precompiled headers")
for source, obj, gch in pchdeps:
self.WriteLn(f"{obj}: {gch}")
Expand Down Expand Up @@ -1600,8 +1599,7 @@ def ComputeOutputBasename(self, spec):

target_prefix = spec.get("product_prefix", target_prefix)
target = spec.get("product_name", target)
product_ext = spec.get("product_extension")
if product_ext:
if product_ext := spec.get("product_extension"):
target_ext = "." + product_ext

return target_prefix + target + target_ext
Expand Down Expand Up @@ -2383,7 +2381,7 @@ def WriteAutoRegenerationRule(params, root_makefile, makefile_name, build_files)
% {
"makefile_name": makefile_name,
"deps": replace_sep(
" ".join(SourceifyAndQuoteSpaces(bf) for bf in build_files)
" ".join(sorted(SourceifyAndQuoteSpaces(bf) for bf in build_files))
),
"cmd": replace_sep(gyp.common.EncodePOSIXShellList(
[gyp_binary, "-fmake"] + gyp.RegenerateFlags(options) + build_files_args
Expand Down
12 changes: 4 additions & 8 deletions tools/gyp/pylib/gyp/generator/msvs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1364,8 +1364,7 @@ def _GetOutputTargetExt(spec):
Returns:
A string with the extension, or None
"""
target_extension = spec.get("product_extension")
if target_extension:
if target_extension := spec.get("product_extension"):
return "." + target_extension
return None

Expand Down Expand Up @@ -3166,8 +3165,7 @@ def _GetMSBuildAttributes(spec, config, build_file):
"windows_driver": "Link",
"static_library": "Lib",
}
msbuild_tool = msbuild_tool_map.get(spec["type"])
if msbuild_tool:
if msbuild_tool := msbuild_tool_map.get(spec["type"]):
msbuild_settings = config["finalized_msbuild_settings"]
out_file = msbuild_settings[msbuild_tool].get("OutputFile")
if out_file:
Expand All @@ -3184,8 +3182,7 @@ def _GetMSBuildConfigurationGlobalProperties(spec, configurations, build_file):
# there are actions.
# TODO(jeanluc) Handle the equivalent of setting 'CYGWIN=nontsec'.
new_paths = []
cygwin_dirs = spec.get("msvs_cygwin_dirs", ["."])[0]
if cygwin_dirs:
if cygwin_dirs := spec.get("msvs_cygwin_dirs", ["."])[0]:
cyg_path = "$(MSBuildProjectDirectory)\\%s\\bin\\" % _FixPath(cygwin_dirs)
new_paths.append(cyg_path)
# TODO(jeanluc) Change the convention to have both a cygwin_dir and a
Expand Down Expand Up @@ -3370,7 +3367,6 @@ def _FinalizeMSBuildSettings(spec, configuration):
prebuild = configuration.get("msvs_prebuild")
postbuild = configuration.get("msvs_postbuild")
def_file = _GetModuleDefinition(spec)
precompiled_header = configuration.get("msvs_precompiled_header")

# Add the information to the appropriate tool
# TODO(jeanluc) We could optimize and generate these settings only if
Expand Down Expand Up @@ -3408,7 +3404,7 @@ def _FinalizeMSBuildSettings(spec, configuration):
msbuild_settings, "ClCompile", "DisableSpecificWarnings", disabled_warnings
)
# Turn on precompiled headers if appropriate.
if precompiled_header:
if precompiled_header := configuration.get("msvs_precompiled_header"):
# While MSVC works with just file name eg. "v8_pch.h", ClangCL requires
# the full path eg. "tools/msvs/pch/v8_pch.h" to find the file.
# P.S. Only ClangCL defines msbuild_toolset, for MSVC it is None.
Expand Down
Loading
Loading