Skip to content

Commit ccf6ee1

Browse files
legendecasgithub-actions[bot]
authored andcommitted
tools: update gyp-next to 0.20.2
1 parent af66574 commit ccf6ee1

23 files changed

+112
-101
lines changed

tools/gyp/CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
# Changelog
22

3+
## [0.20.2](https://github.com/nodejs/gyp-next/compare/v0.20.1...v0.20.2) (2025-06-22)
4+
5+
6+
### Bug Fixes
7+
8+
* 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))
9+
10+
## [0.20.1](https://github.com/nodejs/gyp-next/compare/v0.20.0...v0.20.1) (2025-06-06)
11+
12+
13+
### Bug Fixes
14+
15+
* 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))
16+
* ignore failure of `GetCompilerPredefines` ([#295](https://github.com/nodejs/gyp-next/issues/295)) ([0eaea29](https://github.com/nodejs/gyp-next/commit/0eaea297f0fbb0869597aa162f66f78eb2468fad))
17+
318
## [0.20.0](https://github.com/nodejs/gyp-next/compare/v0.19.1...v0.20.0) (2025-03-27)
419

520

tools/gyp/pylib/gyp/MSVSSettings.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,8 +396,7 @@ def _ValidateExclusionSetting(setting, settings, error_msg, stderr=sys.stderr):
396396
# This may be unrecognized because it's an exclusion list. If the
397397
# setting name has the _excluded suffix, then check the root name.
398398
unrecognized = True
399-
m = re.match(_EXCLUDED_SUFFIX_RE, setting)
400-
if m:
399+
if m := re.match(_EXCLUDED_SUFFIX_RE, setting):
401400
root_setting = m.group(1)
402401
unrecognized = root_setting not in settings
403402

tools/gyp/pylib/gyp/MSVSVersion.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ def _RegistryGetValueUsingWinReg(key, value):
219219
contents of the registry key's value, or None on failure. Throws
220220
ImportError if winreg is unavailable.
221221
"""
222-
from winreg import HKEY_LOCAL_MACHINE, OpenKey, QueryValueEx
222+
from winreg import HKEY_LOCAL_MACHINE, OpenKey, QueryValueEx # noqa: PLC0415
223223
try:
224224
root, subkey = key.split("\\", 1)
225225
assert root == "HKLM" # Only need HKLM for now.
@@ -552,8 +552,7 @@ def SelectVisualStudioVersion(version="auto", allow_fallback=True):
552552
"2019": ("16.0",),
553553
"2022": ("17.0",),
554554
}
555-
override_path = os.environ.get("GYP_MSVS_OVERRIDE_PATH")
556-
if override_path:
555+
if override_path := os.environ.get("GYP_MSVS_OVERRIDE_PATH"):
557556
msvs_version = os.environ.get("GYP_MSVS_VERSION")
558557
if not msvs_version:
559558
raise ValueError(

tools/gyp/pylib/gyp/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ def gyp_main(args):
489489

490490
options, build_files_arg = parser.parse_args(args)
491491
if options.version:
492-
import pkg_resources
492+
import pkg_resources # noqa: PLC0415
493493
print(f"v{pkg_resources.get_distribution('gyp-next').version}")
494494
return 0
495495
build_files = build_files_arg

tools/gyp/pylib/gyp/common.py

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -421,8 +421,9 @@ def EnsureDirExists(path):
421421
except OSError:
422422
pass
423423

424-
def GetCrossCompilerPredefines(): # -> dict
424+
def GetCompilerPredefines(): # -> dict
425425
cmd = []
426+
defines = {}
426427

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

444445
if sys.platform == "win32":
445446
fd, input = tempfile.mkstemp(suffix=".c")
@@ -450,17 +451,33 @@ def replace_sep(s):
450451
real_cmd, shell=True,
451452
capture_output=True, check=True
452453
).stdout
454+
except subprocess.CalledProcessError as e:
455+
print(
456+
"Warning: failed to get compiler predefines\n"
457+
"cmd: %s\n"
458+
"status: %d" % (e.cmd, e.returncode),
459+
file=sys.stderr
460+
)
461+
return defines
453462
finally:
454463
os.unlink(input)
455464
else:
456465
input = "/dev/null"
457466
real_cmd = [*cmd, "-dM", "-E", "-x", "c", input]
458-
stdout = subprocess.run(
459-
real_cmd, shell=False,
460-
capture_output=True, check=True
461-
).stdout
467+
try:
468+
stdout = subprocess.run(
469+
real_cmd, shell=False,
470+
capture_output=True, check=True
471+
).stdout
472+
except subprocess.CalledProcessError as e:
473+
print(
474+
"Warning: failed to get compiler predefines\n"
475+
"cmd: %s\n"
476+
"status: %d" % (e.cmd, e.returncode),
477+
file=sys.stderr
478+
)
479+
return defines
462480

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

502-
defines = GetCrossCompilerPredefines()
519+
defines = GetCompilerPredefines()
503520
if "__EMSCRIPTEN__" in defines:
504521
return "emscripten"
505522
if "__wasm__" in defines:
@@ -566,7 +583,8 @@ def uniquer(seq, idfun=lambda x: x):
566583

567584

568585
# Based on http://code.activestate.com/recipes/576694/.
569-
class OrderedSet(MutableSet):
586+
class OrderedSet(MutableSet): # noqa: PLW1641
587+
# TODO (cclauss): Fix eq-without-hash ruff rule PLW1641
570588
def __init__(self, iterable=None):
571589
self.end = end = []
572590
end += [None, end, end] # sentinel node for doubly linked list

tools/gyp/pylib/gyp/common_test.py

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"""Unit tests for the common.py file."""
88

99
import os
10+
import subprocess
1011
import sys
1112
import unittest
1213
from unittest.mock import MagicMock, patch
@@ -85,22 +86,34 @@ def decode(self, encoding):
8586
@patch("os.close")
8687
@patch("os.unlink")
8788
@patch("tempfile.mkstemp")
88-
def test_GetCrossCompilerPredefines(self, mock_mkstemp, mock_unlink, mock_close):
89+
def test_GetCompilerPredefines(self, mock_mkstemp, mock_unlink, mock_close):
8990
mock_close.return_value = None
9091
mock_unlink.return_value = None
9192
mock_mkstemp.return_value = (0, "temp.c")
9293

93-
def mock_run(env, defines_stdout, expected_cmd):
94+
def mock_run(env, defines_stdout, expected_cmd, throws=False):
9495
with patch("subprocess.run") as mock_run:
95-
mock_process = MagicMock()
96-
mock_process.returncode = 0
97-
mock_process.stdout = TestGetFlavor.MockCommunicate(defines_stdout)
98-
mock_run.return_value = mock_process
9996
expected_input = "temp.c" if sys.platform == "win32" else "/dev/null"
97+
if throws:
98+
mock_run.side_effect = subprocess.CalledProcessError(
99+
returncode=1,
100+
cmd=[
101+
*expected_cmd,
102+
"-dM", "-E", "-x", "c", expected_input
103+
]
104+
)
105+
else:
106+
mock_process = MagicMock()
107+
mock_process.returncode = 0
108+
mock_process.stdout = TestGetFlavor.MockCommunicate(defines_stdout)
109+
mock_run.return_value = mock_process
100110
with patch.dict(os.environ, env):
101-
defines = gyp.common.GetCrossCompilerPredefines()
111+
try:
112+
defines = gyp.common.GetCompilerPredefines()
113+
except Exception as e:
114+
self.fail(f"GetCompilerPredefines raised an exception: {e}")
102115
flavor = gyp.common.GetFlavor({})
103-
if env.get("CC_target"):
116+
if env.get("CC_target") or env.get("CC"):
104117
mock_run.assert_called_with(
105118
[
106119
*expected_cmd,
@@ -110,6 +123,9 @@ def mock_run(env, defines_stdout, expected_cmd):
110123
capture_output=True, check=True)
111124
return [defines, flavor]
112125

126+
[defines0, _] = mock_run({ "CC": "cl.exe" }, "", ["cl.exe"], True)
127+
assert defines0 == {}
128+
113129
[defines1, _] = mock_run({}, "", [])
114130
assert defines1 == {}
115131

tools/gyp/pylib/gyp/generator/android.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -900,8 +900,7 @@ def WriteTarget(
900900
if self.type != "none":
901901
self.WriteTargetFlags(spec, configs, link_deps)
902902

903-
settings = spec.get("aosp_build_settings", {})
904-
if settings:
903+
if settings := spec.get("aosp_build_settings", {}):
905904
self.WriteLn("### Set directly by aosp_build_settings.")
906905
for k, v in settings.items():
907906
if isinstance(v, list):

tools/gyp/pylib/gyp/generator/cmake.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -810,8 +810,7 @@ def WriteTarget(
810810
# link directories to targets defined after it is called.
811811
# As a result, link_directories must come before the target definition.
812812
# CMake unfortunately has no means of removing entries from LINK_DIRECTORIES.
813-
library_dirs = config.get("library_dirs")
814-
if library_dirs is not None:
813+
if (library_dirs := config.get("library_dirs")) is not None:
815814
output.write("link_directories(")
816815
for library_dir in library_dirs:
817816
output.write(" ")
@@ -1295,8 +1294,7 @@ def CallGenerateOutputForConfig(arglist):
12951294

12961295

12971296
def GenerateOutput(target_list, target_dicts, data, params):
1298-
user_config = params.get("generator_flags", {}).get("config", None)
1299-
if user_config:
1297+
if user_config := params.get("generator_flags", {}).get("config", None):
13001298
GenerateOutputForConfig(target_list, target_dicts, data, params, user_config)
13011299
else:
13021300
config_names = target_dicts[target_list[0]]["configurations"]

tools/gyp/pylib/gyp/generator/eclipse.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -451,8 +451,7 @@ def GenerateOutput(target_list, target_dicts, data, params):
451451
if params["options"].generator_output:
452452
raise NotImplementedError("--generator_output not implemented for eclipse")
453453

454-
user_config = params.get("generator_flags", {}).get("config", None)
455-
if user_config:
454+
if user_config := params.get("generator_flags", {}).get("config", None):
456455
GenerateOutputForConfig(target_list, target_dicts, data, params, user_config)
457456
else:
458457
config_names = target_dicts[target_list[0]]["configurations"]

tools/gyp/pylib/gyp/generator/make.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def CalculateVariables(default_variables, params):
7878

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

8383
global generator_additional_non_configuration_keys
8484
generator_additional_non_configuration_keys = getattr(
@@ -1465,8 +1465,7 @@ def WriteSources(
14651465
order_only=True,
14661466
)
14671467

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

16011600
target_prefix = spec.get("product_prefix", target_prefix)
16021601
target = spec.get("product_name", target)
1603-
product_ext = spec.get("product_extension")
1604-
if product_ext:
1602+
if product_ext := spec.get("product_extension"):
16051603
target_ext = "." + product_ext
16061604

16071605
return target_prefix + target + target_ext
@@ -2383,7 +2381,7 @@ def WriteAutoRegenerationRule(params, root_makefile, makefile_name, build_files)
23832381
% {
23842382
"makefile_name": makefile_name,
23852383
"deps": replace_sep(
2386-
" ".join(SourceifyAndQuoteSpaces(bf) for bf in build_files)
2384+
" ".join(sorted(SourceifyAndQuoteSpaces(bf) for bf in build_files))
23872385
),
23882386
"cmd": replace_sep(gyp.common.EncodePOSIXShellList(
23892387
[gyp_binary, "-fmake"] + gyp.RegenerateFlags(options) + build_files_args

tools/gyp/pylib/gyp/generator/msvs.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1364,8 +1364,7 @@ def _GetOutputTargetExt(spec):
13641364
Returns:
13651365
A string with the extension, or None
13661366
"""
1367-
target_extension = spec.get("product_extension")
1368-
if target_extension:
1367+
if target_extension := spec.get("product_extension"):
13691368
return "." + target_extension
13701369
return None
13711370

@@ -3166,8 +3165,7 @@ def _GetMSBuildAttributes(spec, config, build_file):
31663165
"windows_driver": "Link",
31673166
"static_library": "Lib",
31683167
}
3169-
msbuild_tool = msbuild_tool_map.get(spec["type"])
3170-
if msbuild_tool:
3168+
if msbuild_tool := msbuild_tool_map.get(spec["type"]):
31713169
msbuild_settings = config["finalized_msbuild_settings"]
31723170
out_file = msbuild_settings[msbuild_tool].get("OutputFile")
31733171
if out_file:
@@ -3184,8 +3182,7 @@ def _GetMSBuildConfigurationGlobalProperties(spec, configurations, build_file):
31843182
# there are actions.
31853183
# TODO(jeanluc) Handle the equivalent of setting 'CYGWIN=nontsec'.
31863184
new_paths = []
3187-
cygwin_dirs = spec.get("msvs_cygwin_dirs", ["."])[0]
3188-
if cygwin_dirs:
3185+
if cygwin_dirs := spec.get("msvs_cygwin_dirs", ["."])[0]:
31893186
cyg_path = "$(MSBuildProjectDirectory)\\%s\\bin\\" % _FixPath(cygwin_dirs)
31903187
new_paths.append(cyg_path)
31913188
# TODO(jeanluc) Change the convention to have both a cygwin_dir and a
@@ -3370,7 +3367,6 @@ def _FinalizeMSBuildSettings(spec, configuration):
33703367
prebuild = configuration.get("msvs_prebuild")
33713368
postbuild = configuration.get("msvs_postbuild")
33723369
def_file = _GetModuleDefinition(spec)
3373-
precompiled_header = configuration.get("msvs_precompiled_header")
33743370

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

0 commit comments

Comments
 (0)