Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(gyp): update gyp to v0.15.0 #2825

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion gyp/.flake8
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
[flake8]
max-complexity = 101
max-line-length = 88
extend-ignore = E203 # whitespace before ':' to agree with psf/black
extend-ignore =
# whitespace before ':' to agree with psf/black
E203
8 changes: 5 additions & 3 deletions gyp/.github/workflows/Python_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
max-parallel: 8
max-parallel: 6
matrix:
os: [macos-latest, ubuntu-latest] # , windows-latest]
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11-dev"]
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12-dev"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12-dev"]
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
Expand All @@ -30,7 +30,9 @@ jobs:
- run: ./gyp -V && ./gyp --version && gyp -V && gyp --version
- name: Lint with flake8
run: flake8 . --ignore=E203,W503 --max-complexity=101 --max-line-length=88 --show-source --statistics
- name: Test with pytest
- name: Lint with ruff # See pyproject.toml for settings
run: ruff .
- name: Test with pytest # See pyproject.toml for settings
run: pytest
# - name: Run doctests with pytest
# run: pytest --doctest-modules
20 changes: 20 additions & 0 deletions gyp/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
# Changelog

## [0.15.0](https://github.com/nodejs/gyp-next/compare/v0.14.1...v0.15.0) (2023-03-30)


### Features

* **msvs:** add SpectreMitigation attribute ([#190](https://github.com/nodejs/gyp-next/issues/190)) ([853e464](https://github.com/nodejs/gyp-next/commit/853e4643b6737224a5aa0720a4108461a0230991))

## [0.14.1](https://github.com/nodejs/gyp-next/compare/v0.14.0...v0.14.1) (2023-02-19)


### Bug Fixes

* flake8 extended-ignore ([#186](https://github.com/nodejs/gyp-next/issues/186)) ([c38493c](https://github.com/nodejs/gyp-next/commit/c38493c2556aa63b6dc40ab585c18aef5ca270d3))
* No build_type in default_variables ([#183](https://github.com/nodejs/gyp-next/issues/183)) ([ac262fe](https://github.com/nodejs/gyp-next/commit/ac262fe82453c4e8dc47529338d157eb0b5ec0fb))


### Documentation

* README.md: Add pipx installation and run instructions ([#165](https://github.com/nodejs/gyp-next/issues/165)) ([4d28b15](https://github.com/nodejs/gyp-next/commit/4d28b155568dc35f11c7f86124d1dd42ba428bed))

## [0.14.0](https://github.com/nodejs/gyp-next/compare/v0.13.0...v0.14.0) (2022-10-08)


Expand Down
23 changes: 23 additions & 0 deletions gyp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,26 @@ Documents are available at [gyp.gsrc.io](https://gyp.gsrc.io), or you can check

__gyp-next__ is [released](https://github.com/nodejs/gyp-next/releases) to the [__Python Packaging Index__](https://pypi.org/project/gyp-next) (PyPI) and can be installed with the command:
* `python3 -m pip install gyp-next`

When used as a command line utility, __gyp-next__ can also be installed with [pipx](https://pypa.github.io/pipx):
* `pipx install gyp-next`
```
Installing to a new venv 'gyp-next'
installed package gyp-next 0.13.0, installed using Python 3.10.6
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
installed package gyp-next 0.13.0, installed using Python 3.10.6
installed package gyp-next 0.13.0, installed using Python 3.12.0

These apps are now globally available
- gyp
done! ✨ 🌟 ✨
```

Or to run __gyp-next__ directly without installing it:
* `pipx run gyp-next --help`
```
NOTE: running app 'gyp' from 'gyp-next'
usage: usage: gyp [options ...] [build_file ...]

options:
-h, --help show this help message and exit
--build CONFIGS configuration for build after project generation
--check check format of gyp files
[ ... ]
```
24 changes: 11 additions & 13 deletions gyp/pylib/gyp/MSVSNew.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,19 +285,17 @@ def Write(self, writer=gyp.common.WriteOnDiff):
"\tEndProjectSection\r\n"
)

if isinstance(e, MSVSFolder):
if e.items:
f.write("\tProjectSection(SolutionItems) = preProject\r\n")
for i in e.items:
f.write(f"\t\t{i} = {i}\r\n")
f.write("\tEndProjectSection\r\n")

if isinstance(e, MSVSProject):
if e.dependencies:
f.write("\tProjectSection(ProjectDependencies) = postProject\r\n")
for d in e.dependencies:
f.write(f"\t\t{d.get_guid()} = {d.get_guid()}\r\n")
f.write("\tEndProjectSection\r\n")
if isinstance(e, MSVSFolder) and e.items:
f.write("\tProjectSection(SolutionItems) = preProject\r\n")
for i in e.items:
f.write(f"\t\t{i} = {i}\r\n")
f.write("\tEndProjectSection\r\n")

if isinstance(e, MSVSProject) and e.dependencies:
f.write("\tProjectSection(ProjectDependencies) = postProject\r\n")
for d in e.dependencies:
f.write(f"\t\t{d.get_guid()} = {d.get_guid()}\r\n")
f.write("\tEndProjectSection\r\n")

f.write("EndProject\r\n")

Expand Down
6 changes: 4 additions & 2 deletions gyp/pylib/gyp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ def Load(
if default_variables["GENERATOR"] == "ninja":
default_variables.setdefault(
"PRODUCT_DIR_ABS",
os.path.join(output_dir, "out", default_variables["build_type"]),
os.path.join(
output_dir, "out", default_variables.get("build_type", "default")
),
)
else:
default_variables.setdefault(
Expand Down Expand Up @@ -622,7 +624,7 @@ def gyp_main(args):
if options.generator_flags:
gen_flags += options.generator_flags
generator_flags = NameValueListToDict(gen_flags)
if DEBUG_GENERAL in gyp.debug.keys():
if DEBUG_GENERAL in gyp.debug:
DebugOutput(DEBUG_GENERAL, "generator_flags: %s", generator_flags)

# Generate all requested formats (use a set in case we got one format request
Expand Down
21 changes: 7 additions & 14 deletions gyp/pylib/gyp/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,20 +144,16 @@ def RelativePath(path, relative_to, follow_path_symlink=True):
# symlink, this option has no effect.

# Convert to normalized (and therefore absolute paths).
if follow_path_symlink:
path = os.path.realpath(path)
else:
path = os.path.abspath(path)
path = os.path.realpath(path) if follow_path_symlink else os.path.abspath(path)
relative_to = os.path.realpath(relative_to)

# On Windows, we can't create a relative path to a different drive, so just
# use the absolute path.
if sys.platform == "win32":
if (
os.path.splitdrive(path)[0].lower()
!= os.path.splitdrive(relative_to)[0].lower()
):
return path
if sys.platform == "win32" and (
os.path.splitdrive(path)[0].lower()
!= os.path.splitdrive(relative_to)[0].lower()
):
return path

# Split the paths into components.
path_split = path.split(os.path.sep)
Expand Down Expand Up @@ -277,10 +273,7 @@ def EncodePOSIXShellArgument(argument):
if not isinstance(argument, str):
argument = str(argument)

if _quote.search(argument):
quote = '"'
else:
quote = ""
quote = '"' if _quote.search(argument) else ""

encoded = quote + re.sub(_escape, r"\\\1", argument) + quote

Expand Down
2 changes: 2 additions & 0 deletions gyp/pylib/gyp/easy_xml_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ def test_EasyXml_complex(self):
'\'Debug|Win32\'" Label="Configuration">'
"<ConfigurationType>Application</ConfigurationType>"
"<CharacterSet>Unicode</CharacterSet>"
"<SpectreMitigation>SpectreLoadCF</SpectreMitigation>"
"</PropertyGroup>"
"</Project>"
)
Expand All @@ -99,6 +100,7 @@ def test_EasyXml_complex(self):
},
["ConfigurationType", "Application"],
["CharacterSet", "Unicode"],
["SpectreMitigation", "SpectreLoadCF"]
],
]
)
Expand Down
2 changes: 1 addition & 1 deletion gyp/pylib/gyp/generator/analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ def _GetUnqualifiedToTargetMapping(all_targets, to_find):
if not to_find:
return {}, []
to_find = set(to_find)
for target_name in all_targets.keys():
for target_name in all_targets:
extracted = gyp.common.ParseQualifiedTarget(target_name)
if len(extracted) > 1 and extracted[1] in to_find:
to_find.remove(extracted[1])
Expand Down
5 changes: 1 addition & 4 deletions gyp/pylib/gyp/generator/cmake.py
Original file line number Diff line number Diff line change
Expand Up @@ -929,10 +929,7 @@ def WriteTarget(
product_prefix = spec.get("product_prefix", default_product_prefix)
product_name = spec.get("product_name", default_product_name)
product_ext = spec.get("product_extension")
if product_ext:
product_ext = "." + product_ext
else:
product_ext = default_product_ext
product_ext = "." + product_ext if product_ext else default_product_ext

SetTargetProperty(output, cmake_target_name, "PREFIX", product_prefix)
SetTargetProperty(
Expand Down
2 changes: 1 addition & 1 deletion gyp/pylib/gyp/generator/compile_commands_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@


def IsMac(params):
return "mac" == gyp.common.GetFlavor(params)
return gyp.common.GetFlavor(params) == "mac"


def CalculateVariables(default_variables, params):
Expand Down
5 changes: 1 addition & 4 deletions gyp/pylib/gyp/generator/eclipse.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,10 +248,7 @@ def GetAllDefines(target_list, target_dicts, data, config_name, params, compiler
continue
cpp_line_parts = cpp_line.split(" ", 2)
key = cpp_line_parts[1]
if len(cpp_line_parts) >= 3:
val = cpp_line_parts[2]
else:
val = "1"
val = cpp_line_parts[2] if len(cpp_line_parts) >= 3 else "1"
all_defines[key] = val

return all_defines
Expand Down
7 changes: 2 additions & 5 deletions gyp/pylib/gyp/generator/make.py
Original file line number Diff line number Diff line change
Expand Up @@ -681,10 +681,7 @@ def WriteRootHeaderSuffixRules(writer):

def Compilable(filename):
"""Return true if the file is compilable (should be in OBJS)."""
for res in (filename.endswith(e) for e in COMPILABLE_EXTENSIONS):
if res:
return True
return False
return any(res for res in (filename.endswith(e) for e in COMPILABLE_EXTENSIONS))


def Linkable(filename):
Expand Down Expand Up @@ -778,7 +775,7 @@ def __init__(self, generator_flags, flavor):
self.suffix_rules_objdir2 = {}

# Generate suffix rules for all compilable extensions.
for ext in COMPILABLE_EXTENSIONS.keys():
for ext in COMPILABLE_EXTENSIONS:
# Suffix rules for source folder.
self.suffix_rules_srcdir.update(
{
Expand Down
56 changes: 24 additions & 32 deletions gyp/pylib/gyp/generator/msvs.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def _FixPath(path, separator="\\"):
fixpath_prefix
and path
and not os.path.isabs(path)
and not path[0] == "$"
and path[0] != "$"
and not _IsWindowsAbsPath(path)
):
path = os.path.join(fixpath_prefix, path)
Expand Down Expand Up @@ -283,7 +283,7 @@ def _ToolSetOrAppend(tools, tool_name, setting, value, only_if_unset=False):
if not tools.get(tool_name):
tools[tool_name] = dict()
tool = tools[tool_name]
if "CompileAsWinRT" == setting:
if setting == "CompileAsWinRT":
return
if tool.get(setting):
if only_if_unset:
Expand Down Expand Up @@ -412,10 +412,7 @@ def _BuildCommandLineForRuleRaw(
return input_dir_preamble + cmd
else:
# Convert cat --> type to mimic unix.
if cmd[0] == "cat":
command = ["type"]
else:
command = [cmd[0].replace("/", "\\")]
command = ["type"] if cmd[0] == "cat" else [cmd[0].replace("/", "\\")]
# Add call before command to ensure that commands can be tied together one
# after the other without aborting in Incredibuild, since IB makes a bat
# file out of the raw command string, and some commands (like python) are
Expand Down Expand Up @@ -1384,10 +1381,7 @@ def _GetDefines(config):
"""
defines = []
for d in config.get("defines", []):
if type(d) == list:
fd = "=".join([str(dpart) for dpart in d])
else:
fd = str(d)
fd = "=".join([str(dpart) for dpart in d]) if isinstance(d, list) else str(d)
defines.append(fd)
return defines

Expand Down Expand Up @@ -1598,10 +1592,7 @@ def _IdlFilesHandledNonNatively(spec, sources):
if rule["extension"] == "idl" and int(rule.get("msvs_external_rule", 0)):
using_idl = True
break
if using_idl:
excluded_idl = [i for i in sources if i.endswith(".idl")]
else:
excluded_idl = []
excluded_idl = [i for i in sources if i.endswith(".idl")] if using_idl else []
return excluded_idl


Expand Down Expand Up @@ -3015,16 +3006,19 @@ 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(
properties, condition, "TargetVersion", _ConfigTargetVersion(settings)
)
if character_set:
if "msvs_enable_winrt" not in spec:
_AddConditionalProperty(
properties, condition, "CharacterSet", character_set
)
if character_set and "msvs_enable_winrt" not in spec:
_AddConditionalProperty(
properties, condition, "CharacterSet", character_set
)
return _GetMSBuildPropertyGroup(spec, "Configuration", properties)


Expand Down Expand Up @@ -3104,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
Expand Down Expand Up @@ -3326,15 +3322,14 @@ def _GetMSBuildToolSettingsSections(spec, configurations):
for tool_name, tool_settings in sorted(msbuild_settings.items()):
# Skip the tool named '' which is a holder of global settings handled
# by _GetMSBuildConfigurationGlobalProperties.
if tool_name:
if tool_settings:
tool = [tool_name]
for name, value in sorted(tool_settings.items()):
formatted_value = _GetValueFormattedForMSBuild(
tool_name, name, value
)
tool.append([name, formatted_value])
group.append(tool)
if tool_name and tool_settings:
tool = [tool_name]
for name, value in sorted(tool_settings.items()):
formatted_value = _GetValueFormattedForMSBuild(
tool_name, name, value
)
tool.append([name, formatted_value])
group.append(tool)
groups.append(group)
return groups

Expand Down Expand Up @@ -3462,10 +3457,7 @@ def _GetValueFormattedForMSBuild(tool_name, name, value):
"Link": ["AdditionalOptions"],
"Lib": ["AdditionalOptions"],
}
if tool_name in exceptions and name in exceptions[tool_name]:
char = " "
else:
char = ";"
char = " " if name in exceptions.get(tool_name, []) else ";"
formatted_value = char.join(
[MSVSSettings.ConvertVCMacrosToMSBuild(i) for i in value]
)
Expand Down
5 changes: 1 addition & 4 deletions gyp/pylib/gyp/generator/ninja.py
Original file line number Diff line number Diff line change
Expand Up @@ -1815,10 +1815,7 @@ def ComputeOutputFileName(self, spec, type=None):
"executable": default_variables["EXECUTABLE_SUFFIX"],
}
extension = spec.get("product_extension")
if extension:
extension = "." + extension
else:
extension = DEFAULT_EXTENSION.get(type, "")
extension = "." + extension if extension else DEFAULT_EXTENSION.get(type, "")

if "product_name" in spec:
# If we were given an explicit name, use that.
Expand Down
Loading