From e28439607484596a3c95f19eec9292c3fec69170 Mon Sep 17 00:00:00 2001
From: Raymond Zhao <7199958+rzhao271@users.noreply.github.com>
Date: Mon, 29 Jan 2024 19:24:14 -0800
Subject: [PATCH] chore: use newest node-gyp for SDL pipeline (#199820)
* chore: use latest upstream node-gyp
* fix: use node-gyp.js file directly
* apply PR feedback
* chore: delete patch file
* Apply PR feedback
* Update cache salt
---
build/.cachesalt | 2 +-
build/azure-pipelines/sdl-scan.yml | 25 +++------
.../win32/product-build-win32.yml | 30 +++--------
.../gyp_spectre_mitigation_support.patch | 51 -------------------
4 files changed, 14 insertions(+), 94 deletions(-)
delete mode 100644 build/npm/gyp/patches/gyp_spectre_mitigation_support.patch
diff --git a/build/.cachesalt b/build/.cachesalt
index a8a329ac0b8..4f3f91b0edf 100644
--- a/build/.cachesalt
+++ b/build/.cachesalt
@@ -1 +1 @@
-2023-12-07T16:21:36.646Z
+2024-01-29T19:26:27.993Z
diff --git a/build/azure-pipelines/sdl-scan.yml b/build/azure-pipelines/sdl-scan.yml
index 91c8a2477af..927cd5e04ae 100644
--- a/build/azure-pipelines/sdl-scan.yml
+++ b/build/azure-pipelines/sdl-scan.yml
@@ -95,29 +95,16 @@ stages:
displayName: CodeQL Initialize
condition: eq(variables['Codeql.enabled'], 'True')
- - powershell: |
- mkdir -Force .build/node-gyp
- displayName: Create custom node-gyp directory
- condition: and(succeeded(), ne(variables.NODE_MODULES_RESTORED, 'true'))
-
- - powershell: |
- . ../../build/azure-pipelines/win32/exec.ps1
- $ErrorActionPreference = "Stop"
- # TODO: Should be replaced with upstream URL once https://github.com/nodejs/node-gyp/pull/2825
- # gets merged.
- exec { git clone https://github.com/rzhao271/node-gyp.git . } "Cloning rzhao271/node-gyp failed"
- exec { git checkout 102b347da0c92c29f9c67df22e864e70249cf086 } "Checking out 102b347 failed"
- exec { npm install } "Building rzhao271/node-gyp failed"
- exec { python3 -m pip install setuptools } "Installing setuptools failed"
- displayName: Install custom node-gyp
- workingDirectory: .build/node-gyp
- condition: and(succeeded(), ne(variables.NODE_MODULES_RESTORED, 'true'))
-
- powershell: |
. build/azure-pipelines/win32/exec.ps1
. build/azure-pipelines/win32/retry.ps1
$ErrorActionPreference = "Stop"
- $env:npm_config_node_gyp = "$(Join-Path $pwd.Path '.build/node-gyp/bin/node-gyp.js')"
+ # TODO: remove custom node-gyp when updating to Node v20,
+ # refs https://github.com/npm/cli/releases/tag/v10.2.3 which is available with Node >= 20.10.0
+ $nodeGypDir = "$(Agent.TempDirectory)/custom-packages"
+ mkdir "$nodeGypDir"
+ npm install node-gyp@10.0.1 -g --prefix "$nodeGypDir"
+ $env:npm_config_node_gyp = "${nodeGypDir}/node_modules/node-gyp/bin/node-gyp.js"
$env:npm_config_arch = "$(NPM_ARCH)"
retry { exec { yarn --frozen-lockfile --check-files } }
env:
diff --git a/build/azure-pipelines/win32/product-build-win32.yml b/build/azure-pipelines/win32/product-build-win32.yml
index 8727c5b5a2b..ed316e721bc 100644
--- a/build/azure-pipelines/win32/product-build-win32.yml
+++ b/build/azure-pipelines/win32/product-build-win32.yml
@@ -89,33 +89,17 @@ steps:
condition: and(succeeded(), ne(variables.NODE_MODULES_RESTORED, 'true'), ne(variables['NPM_REGISTRY'], 'none'))
displayName: Setup NPM Authentication
- - powershell: |
- mkdir -Force .build/node-gyp
- displayName: Create custom node-gyp directory
- condition: and(succeeded(), ne(variables.NODE_MODULES_RESTORED, 'true'))
-
- - powershell: |
- . ../../build/azure-pipelines/win32/exec.ps1
- $ErrorActionPreference = "Stop"
- # TODO: Should be replaced with upstream URL once https://github.com/nodejs/node-gyp/pull/2825
- # gets merged.
- exec { git config --global user.email "vscode@microsoft.com" } "git config user.email failed"
- exec { git config --global user.name "VSCode" } "git config user.name failed"
- exec { git clone https://github.com/nodejs/node-gyp.git . } "Cloning nodejs/node-gyp failed"
- exec { git checkout v9.4.0 } "Checking out v9.4.0 failed"
- exec { git am --3way --whitespace=fix ../../build/npm/gyp/patches/gyp_spectre_mitigation_support.patch } "Apply spectre patch failed"
- exec { npm install } "Building node-gyp failed"
- exec { python3 -m pip install setuptools } "Installing setuptools failed"
- displayName: Install custom node-gyp
- workingDirectory: .build/node-gyp
- condition: and(succeeded(), ne(variables.NODE_MODULES_RESTORED, 'true'))
-
- powershell: |
. build/azure-pipelines/win32/exec.ps1
. build/azure-pipelines/win32/retry.ps1
$ErrorActionPreference = "Stop"
- $env:npm_config_node_gyp="$(Join-Path $pwd.Path '.build/node-gyp/bin/node-gyp.js')"
- $env:npm_config_arch="$(VSCODE_ARCH)"
+ # TODO: remove custom node-gyp when updating to Node v20,
+ # refs https://github.com/npm/cli/releases/tag/v10.2.3 which is available with Node >= 20.10.0
+ $nodeGypDir = "$(Agent.TempDirectory)/custom-packages"
+ mkdir "$nodeGypDir"
+ npm install node-gyp@10.0.1 -g --prefix "$nodeGypDir"
+ $env:npm_config_node_gyp = "${nodeGypDir}/node_modules/node-gyp/bin/node-gyp.js"
+ $env:npm_config_arch = "$(VSCODE_ARCH)"
$env:CHILD_CONCURRENCY="1"
retry { exec { yarn --frozen-lockfile --check-files } }
env:
diff --git a/build/npm/gyp/patches/gyp_spectre_mitigation_support.patch b/build/npm/gyp/patches/gyp_spectre_mitigation_support.patch
deleted file mode 100644
index e64f42e2b04..00000000000
--- a/build/npm/gyp/patches/gyp_spectre_mitigation_support.patch
+++ /dev/null
@@ -1,51 +0,0 @@
-From 853e4643b6737224a5aa0720a4108461a0230991 Mon Sep 17 00:00:00 2001
-From: Raymond Zhao <7199958+rzhao271@users.noreply.github.com>
-Date: Thu, 30 Mar 2023 05:23:36 -0700
-Subject: [PATCH] feat(msvs): add SpectreMitigation attribute (#190)
-
-Backports https://github.com/nodejs/gyp-next/commit/853e4643b6737224a5aa0720a4108461a0230991
-
-diff --git a/gyp/pylib/gyp/easy_xml_test.py b/gyp/pylib/gyp/easy_xml_test.py
-index 342f693..c5808b8 100755
---- a/gyp/pylib/gyp/easy_xml_test.py
-+++ b/gyp/pylib/gyp/easy_xml_test.py
-@@ -76,6 +76,7 @@ def test_EasyXml_complex(self):
- '\'Debug|Win32\'" Label="Configuration">'
- "Application"
- "Unicode"
-+ "SpectreLoadCF"
- ""
- ""
- )
-@@ -99,6 +100,7 @@ def test_EasyXml_complex(self):
- },
- ["ConfigurationType", "Application"],
- ["CharacterSet", "Unicode"],
-+ ["SpectreMitigation", "SpectreLoadCF"]
- ],
- ]
- )
-diff --git a/gyp/pylib/gyp/generator/msvs.py b/gyp/pylib/gyp/generator/msvs.py
-index 72269bd..85c354f 100644
---- a/gyp/pylib/gyp/generator/msvs.py
-+++ b/gyp/pylib/gyp/generator/msvs.py
-@@ -3006,6 +3006,10 @@ def _GetMSBuildConfigurationDetails(spec, build_file):
- character_set = msbuild_attributes.get("CharacterSet")
- config_type = msbuild_attributes.get("ConfigurationType")
- _AddConditionalProperty(properties, condition, "ConfigurationType", config_type)
-+ spectre_mitigation = msbuild_attributes.get('SpectreMitigation')
-+ if spectre_mitigation:
-+ _AddConditionalProperty(properties, condition, "SpectreMitigation",
-+ spectre_mitigation)
- if config_type == "Driver":
- _AddConditionalProperty(properties, condition, "DriverType", "WDM")
- _AddConditionalProperty(
-@@ -3094,6 +3098,8 @@ def _ConvertMSVSBuildAttributes(spec, config, build_file):
- msbuild_attributes[a] = _ConvertMSVSCharacterSet(msvs_attributes[a])
- elif a == "ConfigurationType":
- msbuild_attributes[a] = _ConvertMSVSConfigurationType(msvs_attributes[a])
-+ elif a == "SpectreMitigation":
-+ msbuild_attributes[a] = msvs_attributes[a]
- else:
- print("Warning: Do not know how to convert MSVS attribute " + a)
- return msbuild_attributes