nodejs: fix hardcoded values in GYP script

This commit is contained in:
Antoine du Hamel
2025-08-18 15:29:51 +02:00
parent f86a07aba8
commit 1e7ed3e27d
6 changed files with 65 additions and 92 deletions
@@ -1,76 +0,0 @@
Avoids needing xcrun or xcodebuild in PATH for native package builds
--- a/tools/gyp/pylib/gyp/xcode_emulation.py
+++ b/tools/gyp/pylib/gyp/xcode_emulation.py
@@ -522,7 +522,13 @@ class XcodeSettings:
# Since the CLT has no SDK paths anyway, returning None is the
# most sensible route and should still do the right thing.
try:
- return GetStdoutQuiet(["xcrun", "--sdk", sdk, infoitem])
+ #return GetStdoutQuiet(["xcrun", "--sdk", sdk, infoitem])
+ return {
+ "--show-sdk-platform-path": "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform",
+ "--show-sdk-path": "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk",
+ "--show-sdk-build-version": "19A547",
+ "--show-sdk-version": "10.15"
+ }[infoitem]
except GypError:
pass
@@ -1499,7 +1505,8 @@ def XcodeVersion():
version = ""
build = ""
try:
- version_list = GetStdoutQuiet(["xcodebuild", "-version"]).splitlines()
+ #version_list = GetStdoutQuiet(["xcodebuild", "-version"]).splitlines()
+ version_list = []
# In some circumstances xcodebuild exits 0 but doesn't return
# the right results; for example, a user on 10.7 or 10.8 with
# a bogus path set via xcode-select
@@ -1510,7 +1517,8 @@ def XcodeVersion():
version = version_list[0].split()[-1] # Last word on first line
build = version_list[-1].split()[-1] # Last word on last line
except GypError: # Xcode not installed so look for XCode Command Line Tools
- version = CLTVersion() # macOS Catalina returns 11.0.0.0.1.1567737322
+ #version = CLTVersion() # macOS Catalina returns 11.0.0.0.1.1567737322
+ version = "11.0.0.0.1.1567737322"
if not version:
raise GypError("No Xcode or CLT version detected!")
# Be careful to convert "4.2.3" to "0423" and "11.0.0" to "1100":
--- a/deps/npm/node_modules/node-gyp/gyp/pylib/gyp/xcode_emulation.py
+++ b/deps/npm/node_modules/node-gyp/gyp/pylib/gyp/xcode_emulation.py
@@ -522,7 +522,13 @@ class XcodeSettings:
# Since the CLT has no SDK paths anyway, returning None is the
# most sensible route and should still do the right thing.
try:
- return GetStdoutQuiet(["xcrun", "--sdk", sdk, infoitem])
+ #return GetStdoutQuiet(["xcrun", "--sdk", sdk, infoitem])
+ return {
+ "--show-sdk-platform-path": "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform",
+ "--show-sdk-path": "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk",
+ "--show-sdk-build-version": "19A547",
+ "--show-sdk-version": "10.15"
+ }[infoitem]
except GypError:
pass
@@ -1499,7 +1505,8 @@ def XcodeVersion():
version = ""
build = ""
try:
- version_list = GetStdoutQuiet(["xcodebuild", "-version"]).splitlines()
+ #version_list = GetStdoutQuiet(["xcodebuild", "-version"]).splitlines()
+ version_list = []
# In some circumstances xcodebuild exits 0 but doesn't return
# the right results; for example, a user on 10.7 or 10.8 with
# a bogus path set via xcode-select
@@ -1510,7 +1517,8 @@ def XcodeVersion():
version = version_list[0].split()[-1] # Last word on first line
build = version_list[-1].split()[-1] # Last word on last line
except GypError: # Xcode not installed so look for XCode Command Line Tools
- version = CLTVersion() # macOS Catalina returns 11.0.0.0.1.1567737322
+ #version = CLTVersion() # macOS Catalina returns 11.0.0.0.1.1567737322
+ version = "11.0.0.0.1.1567737322"
if not version:
raise GypError("No Xcode or CLT version detected!")
# Be careful to convert "4.2.3" to "0423" and "11.0.0" to "1100":
@@ -0,0 +1,25 @@
Sandboxed builds need a fallback value for the version of the Command Line Tools
being used.
--- a/tools/gyp/pylib/gyp/xcode_emulation.py
+++ b/tools/gyp/pylib/gyp/xcode_emulation.py
@@ -1552,7 +1552,7 @@ def CLTVersion():
output = GetStdout(["/usr/sbin/softwareupdate", "--history"])
return re.search(regex, output).groupdict()["version"]
except (GypError, OSError):
- return None
+ return "11.0.0.0.1.1567737322"
def GetStdoutQuiet(cmdlist):
--- a/deps/npm/node_modules/node-gyp/gyp/pylib/gyp/xcode_emulation.py
+++ b/deps/npm/node_modules/node-gyp/gyp/pylib/gyp/xcode_emulation.py
@@ -1552,7 +1552,7 @@ def CLTVersion():
output = GetStdout(["/usr/sbin/softwareupdate", "--history"])
return re.search(regex, output).groupdict()["version"]
except (GypError, OSError):
- return None
+ return "11.0.0.0.1.1567737322"
def GetStdoutQuiet(cmdlist):
+3 -5
View File
@@ -5,15 +5,13 @@
patch_tools ? true,
}:
let
url = "https://github.com/nodejs/gyp-next/commit/706d04aba5bd18f311dc56f84720e99f64c73466.patch?full_index=1";
url = "https://github.com/nodejs/gyp-next/commit/8224deef984add7e7afe846cfb82c9d3fa6da1fb.patch?full_index=1";
in
lib.optionals patch_tools ([
# Fixes builds with Nix sandbox on Darwin for gyp.
# See https://github.com/NixOS/nixpkgs/issues/261820
# and https://github.com/nodejs/gyp-next/pull/216
(fetchpatch2 {
inherit url;
hash = "sha256-iV9qvj0meZkgRzFNur2v1jtLZahbqvSJ237NoM8pPZc=";
hash = "sha256-kvCMpedjrY64BlaC1R0NVjk/vIVivYAGVgWwMEGeP6k=";
stripLen = 1;
extraPrefix = "tools/gyp/";
})
@@ -21,7 +19,7 @@ lib.optionals patch_tools ([
++ lib.optionals patch_npm ([
(fetchpatch2 {
inherit url;
hash = "sha256-1iyeeAprmWpmLafvOOXW45iZ4jWFSloWJxQ0reAKBOo=";
hash = "sha256-cXTwmCRHrNhuY1+3cD/EvU0CJ+1Nk4TRh6c3twvfaW8=";
stripLen = 1;
extraPrefix = "deps/npm/node_modules/node-gyp/gyp/";
})
+17 -1
View File
@@ -13,7 +13,24 @@ let
};
gypPatches = callPackage ./gyp-patches.nix { } ++ [
# Fixes builds with Nix sandbox on Darwin for gyp.
# See https://github.com/NixOS/nixpkgs/issues/261820
# and https://github.com/nodejs/gyp-next/pull/216
(fetchpatch2 {
url = "https://github.com/nodejs/gyp-next/commit/706d04aba5bd18f311dc56f84720e99f64c73466.patch?full_index=1";
hash = "sha256-iV9qvj0meZkgRzFNur2v1jtLZahbqvSJ237NoM8pPZc=";
stripLen = 1;
extraPrefix = "tools/gyp/";
})
(fetchpatch2 {
url = "https://github.com/nodejs/gyp-next/commit/706d04aba5bd18f311dc56f84720e99f64c73466.patch?full_index=1";
hash = "sha256-1iyeeAprmWpmLafvOOXW45iZ4jWFSloWJxQ0reAKBOo=";
stripLen = 1;
extraPrefix = "deps/npm/node_modules/node-gyp/gyp/";
})
./gyp-patches-pre-v22-import-sys.patch
./gyp-patches-set-fallback-value-for-CLT.patch
];
in
buildNodejs {
@@ -24,7 +41,6 @@ buildNodejs {
./configure-emulator.patch
./configure-armv6-vfpv2.patch
./disable-darwin-v8-system-instrumentation-node19.patch
./bypass-darwin-xcrun-node16.patch
./node-npm-build-npm-package-logic.patch
./use-correct-env-in-tests.patch
+10 -1
View File
@@ -14,6 +14,15 @@ let
inherit openssl;
python = python3;
};
gypPatches =
if stdenv.buildPlatform.isDarwin then
callPackage ./gyp-patches.nix { }
++ [
./gyp-patches-set-fallback-value-for-CLT.patch
]
else
[ ];
in
buildNodejs {
inherit enableNpm;
@@ -44,10 +53,10 @@ buildNodejs {
hash = "sha256-hSTLljmVzYmc3WAVeRq9EPYluXGXFeWVXkykufGQPVw=";
})
]
++ gypPatches
++ [
./configure-armv6-vfpv2.patch
./disable-darwin-v8-system-instrumentation-node19.patch
./bypass-darwin-xcrun-node16.patch
./node-npm-build-npm-package-logic.patch
./use-correct-env-in-tests.patch
./bin-sh-node-run-v22.patch
+10 -9
View File
@@ -14,6 +14,15 @@ let
inherit openssl;
python = python3;
};
gypPatches =
if stdenv.buildPlatform.isDarwin then
callPackage ./gyp-patches.nix { patch_tools = false; }
++ [
./gyp-patches-set-fallback-value-for-CLT.patch
]
else
[ ];
in
buildNodejs {
inherit enableNpm;
@@ -50,16 +59,8 @@ buildNodejs {
./node-npm-build-npm-package-logic.patch
./use-correct-env-in-tests.patch
./bin-sh-node-run-v22.patch
# TODO: newer GYP versions have been patched to be more compatible with Nix sandbox. We need
# to adapt our patch to this newer version, see https://github.com/NixOS/nixpkgs/pull/434742.
(fetchpatch2 {
url = "https://github.com/nodejs/node/commit/886e4b3b534a9f3ad2facbc99097419e06615900.patch?full_index=1";
hash = "sha256-HFTabl92NPkBwXD0mUGDN+Gzabyi+Ph0kL0FEHHknbk=";
revert = true;
})
./bypass-darwin-xcrun-node16.patch
]
++ gypPatches
++ lib.optionals (!stdenv.buildPlatform.isDarwin) [
# test-icu-env is failing without the reverts
(fetchpatch2 {