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

Add Python symlink to path (for non-Windows OSes only) #2362

Merged
merged 6 commits into from
Jun 10, 2022

Commits on May 28, 2022

  1. lib: create a Python symlink and add it to PATH

    Helps to ensure a version of Python validated by lib/find-python.js
    is used to run various Python scripts generated by gyp.
    
    Known to affect gyp-mac-tool, probably affects gyp-flock-tool as well.
    
    These Python scripts (such as `gyp-mac-tool`) are invoked directly,
    via the generated Makefile, so their shebang lines determine
    which Python binary is used to run them.
    The shebang lines of these scripts are all `#!/usr/bin/env python3`,
    so the first `python3` on the user's PATH will be used.
    
    By adding a symlink to the Python binary validated by find-python.js,
    and putting this symlink first on the PATH, we can ensure we use
    a compatible version of Python to run these scripts.
    
    (Only on Unix/Unix-like OSes. Symlinks are tricky on Windows,
    and Python isn't used at build-time anyhow on Windows,
    so this intervention isn't useful or necessary on Windows.
    
    A similar technique for Windows, no symlinks required,
    would be to make batch scripts which execute the target binary,
    much like what Node does for its bundled copy of npm on Windows.)
    DeeDeeG committed May 28, 2022
    Configuration menu
    Copy the full SHA
    4161552 View commit details
    Browse the repository at this point in the history
  2. test: update mocked graceful-fs for configure test

    Add missing functions "unlink()" and "symlink()" to mocked module.
    DeeDeeG committed May 28, 2022
    Configuration menu
    Copy the full SHA
    3ed3458 View commit details
    Browse the repository at this point in the history
  3. lib: log any errors when creating Python symlink

    Warn users about errors, but continue on in case the user does
    happen to have new enough Python on their PATH.
    
    (The symlinks are only meant to fix an issue in a corner case,
    where the user told `node-gyp` where new enough Python is,
    but it's not the first `python3` on their PATH.
    We should not introduce a new potential failure mode to all users
    when fixing this bug. So no hard errors during the symlink process.)
    DeeDeeG committed May 28, 2022
    Configuration menu
    Copy the full SHA
    b9367d3 View commit details
    Browse the repository at this point in the history
  4. lib: improve error formatting for Python symlink

    Logging the entire error object shows the stack twice,
    and all the other information is contained in the stack.
    
    It also messes with the order of what is logged.
    
    Rather than logging a bunch of redundant information in a messy way,
    we can log only the stack. Logging it in a separate log.warn()
    also gets rid of an extra space character at the beginning of the line.
    DeeDeeG committed May 28, 2022
    Configuration menu
    Copy the full SHA
    5889ba0 View commit details
    Browse the repository at this point in the history
  5. lib: restore err.errno to logs for symlink errors

    This info (err.errno) is the only piece of information
    in the error object that is not redundant to err.stack.
    DeeDeeG committed May 28, 2022
    Configuration menu
    Copy the full SHA
    0b54241 View commit details
    Browse the repository at this point in the history
  6. lib: use log.verbose, not log.warn

    These messages aren't important enough to be `log.warn`s.
    
    Log as verbose only; they will also appear in full error output.
    DeeDeeG committed May 28, 2022
    Configuration menu
    Copy the full SHA
    54328e1 View commit details
    Browse the repository at this point in the history