From e98bb16e941613b920a7f863c4ebe4986ceda3cc Mon Sep 17 00:00:00 2001 From: DeeDeeG Date: Sat, 29 Aug 2020 18:58:52 -0400 Subject: [PATCH 1/6] doc: drop the --production flag for installing windows-build-tools This isn't needed, and was probably copy-pasted from windows-build-tools' README.md, which has since been changed to drop the `--production` flag from the install instructions. Reviewed-By: Richard Lau Reviewed-By: Christian Clauss Reviewed-By: Rod Vagg --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index fd7e6a117c..cea8015810 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ Install the current version of Python from the [Microsoft Store package](https:/ #### Option 1 -Install all the required tools and configurations using Microsoft's [windows-build-tools](https://github.com/felixrieseberg/windows-build-tools) using `npm install --global --production windows-build-tools` from an elevated PowerShell or CMD.exe (run as Administrator). +Install all the required tools and configurations using Microsoft's [windows-build-tools](https://github.com/felixrieseberg/windows-build-tools) using `npm install --global windows-build-tools` from an elevated PowerShell or CMD.exe (run as Administrator). #### Option 2 From d1176d7c49818d77759d0c0a2fb40b9f297d59b3 Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Wed, 13 May 2020 13:19:16 -0700 Subject: [PATCH 2/6] ci: switch to GitHub Actions Co-authored-by: Christian Clauss Co-authored-by: Matias Lopez PR-URL: https://github.com/nodejs/node-gyp/pull/2210 Closes: #2127 Closes: #2209 --- .github/workflows/Python_tests.yml | 40 ------------- .github/workflows/tests.yml | 51 ++++++++++++++++ .travis.yml | 93 ------------------------------ test/test-options.js | 16 +++-- 4 files changed, 62 insertions(+), 138 deletions(-) delete mode 100644 .github/workflows/Python_tests.yml create mode 100644 .github/workflows/tests.yml delete mode 100644 .travis.yml diff --git a/.github/workflows/Python_tests.yml b/.github/workflows/Python_tests.yml deleted file mode 100644 index 067294515d..0000000000 --- a/.github/workflows/Python_tests.yml +++ /dev/null @@ -1,40 +0,0 @@ -# TODO: Line 15, enable python-version: 3.5 -# TODO: Line 36, enable pytest --doctest-modules - -name: Python_tests -on: [push, pull_request] -jobs: - Python_tests: - runs-on: ${{ matrix.os }} - strategy: - fail-fast: false - max-parallel: 15 - matrix: - os: [macos-latest, ubuntu-latest, windows-latest] - python-version: [2.7, 3.6, 3.7, 3.8] # 3.5, - steps: - - uses: actions/checkout@v2 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v1 - with: - python-version: ${{ matrix.python-version }} - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install flake8 pytest # -r requirements.txt - - name: Lint with flake8 - if: matrix.os == 'ubuntu-latest' - run: | - # stop the build if there are Python syntax errors or undefined names - flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics - # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide - flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics - - name: Test with pytest (Linux and macOS) - if: matrix.os != 'windows-latest' - run: pytest - - name: Test with pytest (Windows) - if: matrix.os == 'windows-latest' - shell: bash - run: GYP_MSVS_VERSION=2015 GYP_MSVS_OVERRIDE_PATH="C:\\Dummy" pytest - # - name: Run doctests with pytest - # run: pytest --doctest-modules diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000000..729a8f05e9 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,51 @@ +# TODO: Line 47, enable pytest --doctest-modules + +name: Tests +on: [push, pull_request] +jobs: + Tests: + strategy: + fail-fast: false + max-parallel: 15 + matrix: + node: [10.x, 12.x, 14.x] + python: [3.6, 3.7, 3.8] + os: [macos-latest, ubuntu-latest, windows-latest] + runs-on: ${{ matrix.os }} + steps: + - name: Checkout Repository + uses: actions/checkout@v2 + - name: Use Node.js ${{ matrix.node }} + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node }} + - name: Use Python ${{ matrix.python }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python }} + env: + PYTHON_VERSION: ${{ matrix.python }} + - name: Install Dependencies + run: | + npm install --no-progress + pip install flake8 pytest + - name: Set Windows environment + if: matrix.os == 'windows-latest' + run: + echo '::set-env name=GYP_MSVS_VERSION::2015' + echo '::set-env name=GYP_MSVS_OVERRIDE_PATH::C:\\Dummy' + - name: Lint Python + if: matrix.os == 'ubuntu-latest' + run: | + # stop the build if there are Python syntax errors or undefined names + flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics + # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide + flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics + - name: Run Python tests + run: | + python -m pytest + # - name: Run doctests with pytest + # run: python -m pytest --doctest-modules + - name: Run Node tests + run: | + npm test diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index ae691bed48..0000000000 --- a/.travis.yml +++ /dev/null @@ -1,93 +0,0 @@ -dist: xenial -language: python -cache: pip -addons: - homebrew: - update: true - packages: - - npm - - pyenv -jobs: - include: - - name: "Python 2.7 on Linux" - env: NODE_GYP_FORCE_PYTHON=python2 - python: 2.7 - - - name: "Node.js 10 & Python 3.8 on Linux" - python: 3.8 - env: NODE_GYP_FORCE_PYTHON=python3 - before_install: nvm install 10 - - - name: "Node.js 12 & Python 3.5 on Linux" - python: 3.5 - env: NODE_GYP_FORCE_PYTHON=python3 - before_install: nvm install 12 - - name: "Node.js 12 & Python 3.6 on Linux" - python: 3.6 - env: NODE_GYP_FORCE_PYTHON=python3 - before_install: nvm install 12 - - name: "Node.js 12 & Python 3.7 on Linux" - python: 3.7 - env: NODE_GYP_FORCE_PYTHON=python3 - before_install: nvm install 12 - - name: "Node.js 12 & Python 3.8 on Linux" - python: 3.8 - env: NODE_GYP_FORCE_PYTHON=python3 - before_install: nvm install 12 - - - name: "Python 2.7 on macOS" - os: osx - osx_image: xcode11.2 - language: shell # 'language: python' is not yet supported on macOS - env: NODE_GYP_FORCE_PYTHON=python2 PATH=$HOME/.pyenv/shims:$PATH PYENV_VERSION=2.7.17 - before_install: pyenv install $PYENV_VERSION - - name: "Python 3.8 on macOS" - os: osx - osx_image: xcode11.2 - language: shell # 'language: python' is not yet supported on macOS - env: NODE_GYP_FORCE_PYTHON=python3 PATH=$HOME/.pyenv/shims:$PATH PYENV_VERSION=3.8.0 - before_install: pyenv install $PYENV_VERSION - - - name: "Node.js 12 & Python 2.7 on Windows" - os: windows - language: node_js - node_js: 12 # node - env: >- - PATH=/c/Python27:/c/Python27/Scripts:$PATH - NODE_GYP_FORCE_PYTHON=/c/Python27/python.exe - before_install: choco install python2 - - - name: "Node.js 12 & Python 3.7 on Windows" - os: windows - language: node_js - node_js: 12 # node - env: >- - PATH=/c/Python37:/c/Python37/Scripts:$PATH - NODE_GYP_FORCE_PYTHON=/c/Python37/python.exe - before_install: choco install python --version=3.7.4 - - name: "Node.js 12 & Python 3.8 on Windows" - os: windows - language: node_js - node_js: 12 # node - env: >- - PATH=/c/Python38:/c/Python38/Scripts:$PATH - NODE_GYP_FORCE_PYTHON=/c/Python38/python.exe - before_install: choco install python - -install: - - python -m pip install --upgrade flake8 pytest==4.6.6 # pytest 5 no longer supports legacy Python -before_script: - - python -m flake8 --version - # stop the build if there are Python syntax errors or undefined names - - python -m flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics - # exit-zero treats all errors as warnings. Two space indentation is OK. The GitHub editor is 127 chars wide - - python -m flake8 . --count --exit-zero --ignore=E111,E114,W503 --max-complexity=10 --max-line-length=127 --statistics - - npm install - - npm list -script: - - node -e 'require("npmlog").level="verbose"; require("./lib/find-python")(null,()=>{})' - - npm test - - GYP_MSVS_VERSION=2015 GYP_MSVS_OVERRIDE_PATH="C:\\Dummy" python -m pytest -notifications: - on_success: change - on_failure: change # `always` will be the setting once code changes slow down diff --git a/test/test-options.js b/test/test-options.js index 252baa2035..b2ac62c874 100644 --- a/test/test-options.js +++ b/test/test-options.js @@ -3,13 +3,19 @@ const test = require('tap').test const gyp = require('../lib/node-gyp') -test('options in environment', function (t) { +test('options in environment', (t) => { t.plan(1) // `npm test` dumps a ton of npm_config_* variables in the environment. Object.keys(process.env) - .filter(function (key) { return /^npm_config_/.test(key) }) - .forEach(function (key) { delete process.env[key] }) + .filter((key) => /^npm_config_/.test(key)) + .forEach((key) => { delete process.env[key] }) + + // in some platforms, certain keys are stubborn and cannot be removed + const keys = Object.keys(process.env) + .filter((key) => /^npm_config_/.test(key)) + .map((key) => key.substring('npm_config_'.length)) + .concat('argv', 'x') // Zero-length keys should get filtered out. process.env.npm_config_ = '42' @@ -18,8 +24,8 @@ test('options in environment', function (t) { // Except loglevel. process.env.npm_config_loglevel = 'debug' - var g = gyp() + const g = gyp() g.parseArgv(['rebuild']) // Also sets opts.argv. - t.deepEqual(Object.keys(g.opts).sort(), ['argv', 'x']) + t.deepEqual(Object.keys(g.opts).sort(), keys.sort()) }) From 9bf112b44c98be39bf8770a1341fa4ddf23556d4 Mon Sep 17 00:00:00 2001 From: Rod Vagg Date: Wed, 9 Sep 2020 13:48:09 +1000 Subject: [PATCH 3/6] doc: replace status badges with new Actions badge PR-URL: https://github.com/nodejs/node-gyp/pull/2218 Reviewed-By: Christian Clauss Reviewed-By: Matias Lopez Reviewed-By: Richard Lau --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index cea8015810..e06b01a739 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,6 @@ # `node-gyp` - Node.js native addon build tool -[![Travis CI](https://travis-ci.com/nodejs/node-gyp.svg?branch=master)](https://travis-ci.com/nodejs/node-gyp) -[![Build Status](https://github.com/nodejs/node-gyp/workflows/Python_tests/badge.svg)](https://github.com/nodejs/node-gyp/actions?workflow=Python_tests) +[![Build Status](https://github.com/nodejs/node-gyp/workflows/Tests/badge.svg?branch=master)](https://github.com/nodejs/node-gyp/actions?query=workflow%3ATests+branch%3Amaster) `node-gyp` is a cross-platform command-line tool written in Node.js for compiling native addon modules for Node.js. It contains a vendored copy of the From 574677d068b0059e7b1efe25aa5415d1c42cf66b Mon Sep 17 00:00:00 2001 From: mcdmaster Date: Sat, 14 Nov 2020 06:36:23 +0900 Subject: [PATCH 4/6] lib: find extensive Win10SDK installation --- lib/Find-VisualStudio.cs | 64 ++++++++++++++++++++++++++++++++++------ 1 file changed, 55 insertions(+), 9 deletions(-) diff --git a/lib/Find-VisualStudio.cs b/lib/Find-VisualStudio.cs index d2e45a7627..8749de128b 100644 --- a/lib/Find-VisualStudio.cs +++ b/lib/Find-VisualStudio.cs @@ -3,13 +3,12 @@ // See accompanying file LICENSE at https://github.com/node4good/windows-autoconf // Usage: -// powershell -ExecutionPolicy Unrestricted -Command "Add-Type -Path Find-VisualStudio.cs; [VisualStudioConfiguration.Main]::PrintJson()" -// This script needs to be compatible with PowerShell v2 to run on Windows 2008R2 and Windows 7. - +// powershell -ExecutionPolicy Unrestricted -Version "2.0" -Command "&{Add-Type -Path Find-VS2017.cs; [VisualStudioConfiguration.Main]::Query()}" using System; using System.Text; using System.Runtime.InteropServices; using System.Collections.Generic; +using System.Text.RegularExpressions; namespace VisualStudioConfiguration { @@ -196,12 +195,13 @@ public static void PrintJson() int pceltFetched; ISetupInstance2[] rgelt = new ISetupInstance2[1]; List instances = new List(); + while (true) { e.Next(1, rgelt, out pceltFetched); if (pceltFetched <= 0) { - Console.WriteLine(String.Format("[{0}]", string.Join(",", instances.ToArray()))); + Console.Write(String.Format("[{0}]", string.Join(",", instances.ToArray()))); return; } @@ -216,6 +216,25 @@ public static void PrintJson() } } + private static string CheckInstance(ISetupPackageReference package) + { + // Visual Studio Community 2017 component directory: + // https://www.visualstudio.com/en-us/productinfo/vs2017-install-product-Community.workloads + String Win10SDKVer = null; + + const string Win10SDKPrefix = "Microsoft.VisualStudio.Component.Windows10SDK."; + String id = package.GetId(); + if (id.StartsWith(Win10SDKPrefix)) + { + String[] parts = id.Substring(Win10SDKPrefix.Length).Split('.'); + String foundSdkVer = parts[4]; + Win10SDKVer = String.Compare(Win10SDKVer, foundSdkVer) > 0 ? Win10SDKVer : foundSdkVer; + return String.Format("{0}.{1}", id, Win10SDKVer); + } + // "Microsoft.VisualStudio.Component.Windows81SDK" as well + return id; + } + private static string JsonString(string s) { return "\"" + s.Replace("\\", "\\\\").Replace("\"", "\\\"") + "\""; @@ -225,7 +244,6 @@ private static string InstanceJson(ISetupInstance2 setupInstance2) { // Visual Studio component directory: // https://docs.microsoft.com/en-us/visualstudio/install/workload-and-component-ids - StringBuilder json = new StringBuilder(); json.Append("{"); @@ -238,13 +256,41 @@ private static string InstanceJson(ISetupInstance2 setupInstance2) List packages = new List(); foreach (ISetupPackageReference package in setupInstance2.GetPackages()) { - string id = JsonString(package.GetId()); + string id = JsonString(CheckInstance(package)); packages.Add(id); } - json.Append(String.Format("\"packages\":[{0}]", string.Join(",", packages.ToArray()))); + json.Append(String.Format("\"packages\":[{0}", string.Join(",", packages.ToArray()))); + + String jsonResultString = json.ToString(); + if (!jsonResultString.Contains("Windows10SDK")) + { + System.Diagnostics.Process cmd = new System.Diagnostics.Process(); + cmd.StartInfo.FileName = "cmd.exe"; + cmd.StartInfo.RedirectStandardInput = true; + cmd.StartInfo.RedirectStandardOutput = true; + cmd.StartInfo.CreateNoWindow = true; + cmd.StartInfo.UseShellExecute = false; + cmd.Start(); + + cmd.StandardInput.WriteLine("@echo off"); + cmd.StandardInput.Flush(); + cmd.StandardInput.WriteLine( + String.Format("{0}\\VC\\Auxiliary\\Build\\vcvarsall.bat x64", path) + ); + cmd.StandardInput.Flush(); + cmd.StandardInput.WriteLine("@echo %UCRTVersion%"); + cmd.StandardInput.Flush(); + cmd.StandardInput.Close(); + cmd.WaitForExit(); + String SDKFullText = cmd.StandardOutput.ReadToEnd(); + int pos = SDKFullText.IndexOf("[Version "); + String SDKVersion = SDKFullText.Substring(pos + 14, 5); + json.Append(String.Format(",\"Microsoft.VisualStudio.Component.Windows10SDK.{0}\"", SDKVersion)); + cmd.Close(); + } + json.Append("]}"); - json.Append("}"); return json.ToString(); } } -} +} \ No newline at end of file From e1d0a4ac93fe40a567c13aaddd3ae1096c7d9343 Mon Sep 17 00:00:00 2001 From: mcdmaster Date: Sat, 14 Nov 2020 06:43:41 +0900 Subject: [PATCH 5/6] lib: find extensive Win10SDK installation --- lib/Find-VisualStudio.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Find-VisualStudio.cs b/lib/Find-VisualStudio.cs index 8749de128b..a73f282c83 100644 --- a/lib/Find-VisualStudio.cs +++ b/lib/Find-VisualStudio.cs @@ -3,8 +3,8 @@ // See accompanying file LICENSE at https://github.com/node4good/windows-autoconf // Usage: -// powershell -ExecutionPolicy Unrestricted -Version "2.0" -Command "&{Add-Type -Path Find-VS2017.cs; [VisualStudioConfiguration.Main]::Query()}" -using System; +// powershell -ExecutionPolicy Unrestricted -Command "Add-Type -Path Find-VisualStudio.cs; [VisualStudioConfiguration.Main]::PrintJson()" +// This script needs to be compatible with PowerShell v2 to run on Windows 2008R2 and Windows 7.using System; using System.Text; using System.Runtime.InteropServices; using System.Collections.Generic; From bb5c21cd08e408caeb339dd809b797b3dd467d64 Mon Sep 17 00:00:00 2001 From: mcdmaster Date: Sat, 14 Nov 2020 06:50:39 +0900 Subject: [PATCH 6/6] lib: find extensive Win10SDK installation --- lib/Find-VisualStudio.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/Find-VisualStudio.cs b/lib/Find-VisualStudio.cs index a73f282c83..f1070d3f55 100644 --- a/lib/Find-VisualStudio.cs +++ b/lib/Find-VisualStudio.cs @@ -4,7 +4,9 @@ // Usage: // powershell -ExecutionPolicy Unrestricted -Command "Add-Type -Path Find-VisualStudio.cs; [VisualStudioConfiguration.Main]::PrintJson()" -// This script needs to be compatible with PowerShell v2 to run on Windows 2008R2 and Windows 7.using System; +// This script needs to be compatible with PowerShell v2 to run on Windows 2008R2 and Windows 7. + +using System; using System.Text; using System.Runtime.InteropServices; using System.Collections.Generic;