Skip to content

Version number comparisons in Python and GYP files are not safe #29927

Closed
@targos

Description

@targos

Noted by @richardlau in #29897

Problem

In various places in GYP files and Python scripts, we use string or number comparisons to check if the version of compiling tools satisfies some minimum value. These are not safe and could give wrong results:

  • "10.1" >= "2.4" returns False
  • 2.24 > 2.3 returns False

Some examples in our code base

node/configure.py

Lines 1233 to 1237 in 81bc7b3

openssl110_asm_supported = \
('gas_version' in variables and float(variables['gas_version']) >= 2.23) or \
('xcode_version' in variables and float(variables['xcode_version']) >= 5.0) or \
('llvm_version' in variables and float(variables['llvm_version']) >= 3.3) or \
('nasm_version' in variables and float(variables['nasm_version']) >= 2.10)

'llvm_version>="3.3" or xcode_version>="5.0" or gas_version>="2.23"', {

}, 'gas_version >= "2.26" or nasm_version >= "2.11.8"', {

Solution?

I haven't found a solution yet, because we need something that works in GYP conditions, meaning simple Python expressions that cannot import external libraries (correct me if I'm wrong).

We could use the builtin from distutils.version import StrictVersion and StrictVersion("2.24") >= StrictVersion("2.3") but I don't know if it's possible to make StrictVersion available to GYP conditionals.

/cc @nodejs/gyp @nodejs/python

Metadata

Metadata

Assignees

No one assigned

    Labels

    gypIssues and PRs related to the GYP tool and .gyp build filespythonPRs and issues that require attention from people who are familiar with Python.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions