From 4948db665eeac4f8ad54e191f2f56b438be8100c Mon Sep 17 00:00:00 2001 From: Jiawen Geng Date: Fri, 20 Aug 2021 12:59:59 +0000 Subject: [PATCH] tools: update gyp-next to v0.9.5 --- tools/gyp/.github/workflows/node-gyp.yml | 4 ++- tools/gyp/CHANGELOG.md | 16 +++++++++ tools/gyp/pylib/gyp/easy_xml.py | 5 +-- tools/gyp/pylib/gyp/generator/ninja.py | 29 +++++++-------- tools/gyp/pylib/gyp/msvs_emulation.py | 45 ++++++++++++++++-------- tools/gyp/setup.py | 2 +- 6 files changed, 67 insertions(+), 34 deletions(-) diff --git a/tools/gyp/.github/workflows/node-gyp.yml b/tools/gyp/.github/workflows/node-gyp.yml index 59d23fdffc2150..bd7c85ffda9169 100644 --- a/tools/gyp/.github/workflows/node-gyp.yml +++ b/tools/gyp/.github/workflows/node-gyp.yml @@ -8,6 +8,8 @@ jobs: fail-fast: false matrix: os: [macos-latest, ubuntu-latest, windows-latest] + python: [3.6, 3.9] + runs-on: ${{ matrix.os }} steps: - name: Clone gyp-next @@ -24,7 +26,7 @@ jobs: node-version: 14.x - uses: actions/setup-python@v2 with: - python-version: 3.9 + python-version: ${{ matrix.python }} - name: Install dependencies run: | cd node-gyp diff --git a/tools/gyp/CHANGELOG.md b/tools/gyp/CHANGELOG.md index d84ee08238d37f..141da1f589a3ec 100644 --- a/tools/gyp/CHANGELOG.md +++ b/tools/gyp/CHANGELOG.md @@ -1,5 +1,21 @@ # Changelog +### [0.9.5](https://www.github.com/nodejs/gyp-next/compare/v0.9.4...v0.9.5) (2021-08-18) + + +### Bug Fixes + +* add python 3.6 to node-gyp integration test ([3462d4c](https://www.github.com/nodejs/gyp-next/commit/3462d4ce3c31cce747513dc7ca9760c81d57c60e)) +* revert for windows compatibility ([d078e7d](https://www.github.com/nodejs/gyp-next/commit/d078e7d7ae080ddae243188f6415f940376a7368)) +* support msvs_quote_cmd in ninja generator ([#117](https://www.github.com/nodejs/gyp-next/issues/117)) ([46486ac](https://www.github.com/nodejs/gyp-next/commit/46486ac6e9329529d51061e006a5b39631e46729)) + +### [0.9.4](https://www.github.com/nodejs/gyp-next/compare/v0.9.3...v0.9.4) (2021-08-09) + + +### Bug Fixes + +* .S is an extension for asm file on Windows ([#115](https://www.github.com/nodejs/gyp-next/issues/115)) ([d2fad44](https://www.github.com/nodejs/gyp-next/commit/d2fad44ef3a79ca8900f1307060153ded57053fc)) + ### [0.9.3](https://www.github.com/nodejs/gyp-next/compare/v0.9.2...v0.9.3) (2021-07-07) diff --git a/tools/gyp/pylib/gyp/easy_xml.py b/tools/gyp/pylib/gyp/easy_xml.py index 0c99e29ecf8ce0..bda1a47468ae2b 100644 --- a/tools/gyp/pylib/gyp/easy_xml.py +++ b/tools/gyp/pylib/gyp/easy_xml.py @@ -123,10 +123,7 @@ def WriteXmlIfChanged(content, path, encoding="utf-8", pretty=False, default_encoding = locale.getdefaultlocale()[1] if default_encoding and default_encoding.upper() != encoding.upper(): - if win32 and sys.version_info < (3, 7): - xml_string = xml_string.decode("cp1251").encode(encoding) - else: - xml_string = xml_string.encode(encoding) + xml_string = xml_string.encode(encoding) # Get the old content try: diff --git a/tools/gyp/pylib/gyp/generator/ninja.py b/tools/gyp/pylib/gyp/generator/ninja.py index b66e674a7b3871..d173bf22990116 100644 --- a/tools/gyp/pylib/gyp/generator/ninja.py +++ b/tools/gyp/pylib/gyp/generator/ninja.py @@ -654,10 +654,10 @@ def WriteActions( description = self.GenerateDescription( "ACTION", action.get("message", None), name ) - is_cygwin = ( - self.msvs_settings.IsRuleRunUnderCygwin(action) + win_shell_flags = ( + self.msvs_settings.GetRuleShellFlags(action) if self.flavor == "win" - else False + else None ) args = action["action"] depfile = action.get("depfile", None) @@ -665,7 +665,7 @@ def WriteActions( depfile = self.ExpandSpecial(depfile, self.base_to_build) pool = "console" if int(action.get("ninja_use_console", 0)) else None rule_name, _ = self.WriteNewNinjaRule( - name, args, description, is_cygwin, env, pool, depfile=depfile + name, args, description, win_shell_flags, env, pool, depfile=depfile ) inputs = [self.GypPathToNinja(i, env) for i in action["inputs"]] @@ -707,14 +707,14 @@ def WriteRules( rule.get("message", None), ("%s " + generator_default_variables["RULE_INPUT_PATH"]) % name, ) - is_cygwin = ( - self.msvs_settings.IsRuleRunUnderCygwin(rule) + win_shell_flags = ( + self.msvs_settings.GetRuleShellFlags(rule) if self.flavor == "win" - else False + else None ) pool = "console" if int(rule.get("ninja_use_console", 0)) else None rule_name, args = self.WriteNewNinjaRule( - name, args, description, is_cygwin, env, pool + name, args, description, win_shell_flags, env, pool ) # TODO: if the command references the outputs directly, we should @@ -733,7 +733,7 @@ def WriteRules( def cygwin_munge(path): # pylint: disable=cell-var-from-loop - if is_cygwin: + if win_shell_flags and win_shell_flags.cygwin: return path.replace("\\", "/") return path @@ -1221,7 +1221,7 @@ def WriteSourcesForArch( command = "cc_s" elif ( self.flavor == "win" - and ext == "asm" + and ext in ("asm", "S") and not self.msvs_settings.HasExplicitAsmRules(spec) ): command = "asm" @@ -1899,7 +1899,7 @@ def WriteVariableList(self, ninja_file, var, values): ninja_file.variable(var, " ".join(values)) def WriteNewNinjaRule( - self, name, args, description, is_cygwin, env, pool, depfile=None + self, name, args, description, win_shell_flags, env, pool, depfile=None ): """Write out a new ninja "rule" statement for a given command. @@ -1946,13 +1946,14 @@ def WriteNewNinjaRule( if self.flavor == "win": rspfile = rule_name + ".$unique_name.rsp" # The cygwin case handles this inside the bash sub-shell. - run_in = "" if is_cygwin else " " + self.build_to_base - if is_cygwin: + run_in = "" if win_shell_flags.cygwin else " " + self.build_to_base + if win_shell_flags.cygwin: rspfile_content = self.msvs_settings.BuildCygwinBashCommandLine( args, self.build_to_base ) else: - rspfile_content = gyp.msvs_emulation.EncodeRspFileList(args) + rspfile_content = gyp.msvs_emulation.EncodeRspFileList( + args, win_shell_flags.quote) command = ( "%s gyp-win-tool action-wrapper $arch " % sys.executable + rspfile diff --git a/tools/gyp/pylib/gyp/msvs_emulation.py b/tools/gyp/pylib/gyp/msvs_emulation.py index 6fcabd049d843c..2d289dcb47f467 100644 --- a/tools/gyp/pylib/gyp/msvs_emulation.py +++ b/tools/gyp/pylib/gyp/msvs_emulation.py @@ -7,6 +7,7 @@ build systems, primarily ninja. """ +import collections import os import re import subprocess @@ -19,7 +20,7 @@ windows_quoter_regex = re.compile(r'(\\*)"') -def QuoteForRspFile(arg): +def QuoteForRspFile(arg, quote_cmd=True): """Quote a command line argument so that it appears as one argument when processed via cmd.exe and parsed by CommandLineToArgvW (as is typical for Windows programs).""" @@ -36,7 +37,8 @@ def QuoteForRspFile(arg): # For a literal quote, CommandLineToArgvW requires 2n+1 backslashes # preceding it, and results in n backslashes + the quote. So we substitute # in 2* what we match, +1 more, plus the quote. - arg = windows_quoter_regex.sub(lambda mo: 2 * mo.group(1) + '\\"', arg) + if quote_cmd: + arg = windows_quoter_regex.sub(lambda mo: 2 * mo.group(1) + '\\"', arg) # %'s also need to be doubled otherwise they're interpreted as batch # positional arguments. Also make sure to escape the % so that they're @@ -48,12 +50,17 @@ def QuoteForRspFile(arg): # These commands are used in rsp files, so no escaping for the shell (via ^) # is necessary. - # Finally, wrap the whole thing in quotes so that the above quote rule - # applies and whitespace isn't a word break. - return '"' + arg + '"' + # As a workaround for programs that don't use CommandLineToArgvW, gyp + # supports msvs_quote_cmd=0, which simply disables all quoting. + if quote_cmd: + # Finally, wrap the whole thing in quotes so that the above quote rule + # applies and whitespace isn't a word break. + return f'"{arg}"' + return arg -def EncodeRspFileList(args): + +def EncodeRspFileList(args, quote_cmd): """Process a list of arguments using QuoteCmdExeArgument.""" # Note that the first argument is assumed to be the command. Don't add # quotes around it because then built-ins like 'echo', etc. won't work. @@ -67,7 +74,8 @@ def EncodeRspFileList(args): program = call + " " + os.path.normpath(program) else: program = os.path.normpath(args[0]) - return program + " " + " ".join(QuoteForRspFile(arg) for arg in args[1:]) + return (program + " " + + " ".join(QuoteForRspFile(arg, quote_cmd) for arg in args[1:])) def _GenericRetrieve(root, default, path): @@ -933,13 +941,22 @@ def BuildCygwinBashCommandLine(self, args, path_to_base): ) return cmd - def IsRuleRunUnderCygwin(self, rule): - """Determine if an action should be run under cygwin. If the variable is - unset, or set to 1 we use cygwin.""" - return ( - int(rule.get("msvs_cygwin_shell", self.spec.get("msvs_cygwin_shell", 1))) - != 0 - ) + RuleShellFlags = collections.namedtuple("RuleShellFlags", ["cygwin", "quote"]) + + def GetRuleShellFlags(self, rule): + """Return RuleShellFlags about how the given rule should be run. This + includes whether it should run under cygwin (msvs_cygwin_shell), and + whether the commands should be quoted (msvs_quote_cmd).""" + # If the variable is unset, or set to 1 we use cygwin + cygwin = int(rule.get("msvs_cygwin_shell", + self.spec.get("msvs_cygwin_shell", 1))) != 0 + # Default to quoting. There's only a few special instances where the + # target command uses non-standard command line parsing and handle quotes + # and quote escaping differently. + quote_cmd = int(rule.get("msvs_quote_cmd", 1)) + assert quote_cmd != 0 or cygwin != 1, \ + "msvs_quote_cmd=0 only applicable for msvs_cygwin_shell=0" + return MsvsSettings.RuleShellFlags(cygwin, quote_cmd) def _HasExplicitRuleForExtension(self, spec, extension): """Determine if there's an explicit rule for a particular extension.""" diff --git a/tools/gyp/setup.py b/tools/gyp/setup.py index 1ff298a12326b0..51c6b057378858 100644 --- a/tools/gyp/setup.py +++ b/tools/gyp/setup.py @@ -15,7 +15,7 @@ setup( name="gyp-next", - version="0.9.3", + version="0.9.5", description="A fork of the GYP build system for use in the Node.js projects", long_description=long_description, long_description_content_type="text/markdown",