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

build will fail if only python3 avaiable #38791

Closed
gengjiawen opened this issue May 24, 2021 · 3 comments
Closed

build will fail if only python3 avaiable #38791

gengjiawen opened this issue May 24, 2021 · 3 comments
Labels
gyp Issues and PRs related to the GYP tool and .gyp build files python PRs and issues that require attention from people who are familiar with Python.

Comments

@gengjiawen
Copy link
Member

Found this on testing gcc-11 docker image.

[251/3367] ACTION postmortem-metadata: gen-postmortem-metadata_7acc03b21ed727c9887fcf4669bc652e
FAILED: gen/debug-support.cc 
cd ../../tools/v8_gypfiles; python ../../deps/v8/tools/gen-postmortem-metadata.py ../../out/Release/gen/debug-support.cc ../../out/Release/gen/torque-generated/instance-types.h ../../deps/v8/src/objects/allocation-site.h ../../deps/v8/src/objects/allocation-site-inl.h ../../deps/v8/src/objects/cell.h ../../deps/v8/src/objects/cell-inl.h ../../deps/v8/src/objects/code.h ../../deps/v8/src/objects/code-inl.h ../../deps/v8/src/objects/data-handler.h ../../deps/v8/src/objects/data-handler-inl.h ../../deps/v8/src/objects/descriptor-array.h ../../deps/v8/src/objects/descriptor-array-inl.h ../../deps/v8/src/objects/feedback-cell.h ../../deps/v8/src/objects/feedback-cell-inl.h ../../deps/v8/src/objects/fixed-array.h ../../deps/v8/src/objects/fixed-array-inl.h ../../deps/v8/src/objects/heap-number.h ../../deps/v8/src/objects/heap-number-inl.h ../../deps/v8/src/objects/heap-object.h ../../deps/v8/src/objects/heap-object-inl.h ../../deps/v8/src/objects/instance-type.h ../../deps/v8/src/objects/js-array-buffer.h ../../deps/v8/src/objects/js-array-buffer-inl.h ../../deps/v8/src/objects/js-array.h ../../deps/v8/src/objects/js-array-inl.h ../../deps/v8/src/objects/js-function-inl.h ../../deps/v8/src/objects/js-function.cc ../../deps/v8/src/objects/js-function.h ../../deps/v8/src/objects/js-objects.cc ../../deps/v8/src/objects/js-objects.h ../../deps/v8/src/objects/js-objects-inl.h ../../deps/v8/src/objects/js-promise.h ../../deps/v8/src/objects/js-promise-inl.h ../../deps/v8/src/objects/js-regexp.cc ../../deps/v8/src/objects/js-regexp.h ../../deps/v8/src/objects/js-regexp-inl.h ../../deps/v8/src/objects/js-regexp-string-iterator.h ../../deps/v8/src/objects/js-regexp-string-iterator-inl.h ../../deps/v8/src/objects/map.cc ../../deps/v8/src/objects/map.h ../../deps/v8/src/objects/map-inl.h ../../deps/v8/src/objects/name.h ../../deps/v8/src/objects/name-inl.h ../../deps/v8/src/objects/objects.h ../../deps/v8/src/objects/objects-inl.h ../../deps/v8/src/objects/oddball.h ../../deps/v8/src/objects/oddball-inl.h ../../deps/v8/src/objects/primitive-heap-object.h ../../deps/v8/src/objects/primitive-heap-object-inl.h ../../deps/v8/src/objects/scope-info.h ../../deps/v8/src/objects/scope-info-inl.h ../../deps/v8/src/objects/script.h ../../deps/v8/src/objects/script-inl.h ../../deps/v8/src/objects/shared-function-info.cc ../../deps/v8/src/objects/shared-function-info.h ../../deps/v8/src/objects/shared-function-info-inl.h ../../deps/v8/src/objects/string.cc ../../deps/v8/src/objects/string-comparator.cc ../../deps/v8/src/objects/string-comparator.h ../../deps/v8/src/objects/string.h ../../deps/v8/src/objects/string-inl.h ../../deps/v8/src/objects/struct.h ../../deps/v8/src/objects/struct-inl.h
/bin/sh: 1: python: not found
@targos
Copy link
Member

targos commented May 24, 2021

It's because actions that run Python in our gypfiles directly reference the python executable:

'python',

Maybe we should do something in GYP to expose sys.executable as a variable?

@targos targos added gyp Issues and PRs related to the GYP tool and .gyp build files python PRs and issues that require attention from people who are familiar with Python. labels May 24, 2021
@richardlau
Copy link
Member

I believe this is only an issue for building with Ninja. With make our configure scripts write out the path to Python as the PYTHON make variable via config.mk but also create a symbolic python link to sys.executable if it's not the same binary as python on the PATH and append the directory containing the link to PATH:

node/configure.py

Lines 1952 to 1954 in e9e851f

# Not needed for trivial case. Useless when it's a win32 path.
if sys.executable != 'python' and ':\\' not in sys.executable:
config['PYTHON'] = sys.executable

node/configure.py

Lines 1971 to 1976 in e9e851f

# On Windows there's no reason to search for a different python binary.
bin_override = None if sys.platform == 'win32' else make_bin_override()
if bin_override:
config_str = 'export PATH:=' + bin_override + ':$(PATH)\n' + config_str
write('config.mk', do_not_edit + config_str)

node/configure.py

Lines 1837 to 1868 in e9e851f

def make_bin_override():
if sys.platform == 'win32':
raise Exception('make_bin_override should not be called on win32.')
# If the system python is not the python we are running (which should be
# python 3), then create a directory with a symlink called `python` to our
# sys.executable. This directory will be prefixed to the PATH, so that
# other tools that shell out to `python` will use the appropriate python
which_python = which('python')
if (which_python and
os.path.realpath(which_python) == os.path.realpath(sys.executable)):
return
bin_override = os.path.abspath('out/tools/bin')
try:
os.makedirs(bin_override)
except OSError as e:
if e.errno != errno.EEXIST: raise e
python_link = os.path.join(bin_override, 'python')
try:
os.unlink(python_link)
except OSError as e:
if e.errno != errno.ENOENT: raise e
os.symlink(sys.executable, python_link)
# We need to set the environment right now so that when gyp (in run_gyp)
# shells out, it finds the right python (specifically at
# https://github.com/nodejs/node/blob/d82e107/deps/v8/gypfiles/toolchain.gypi#L43)
os.environ['PATH'] = bin_override + ':' + os.environ['PATH']
return bin_override

(FWIW this is also the reason the V8 CI builds fail when Node.js' configure is run with Python 3 as the override means #!/usr/bin/env python ends up pointing to the Python 3 binary configure was run with instead of the default python.)

@skys215
Copy link

skys215 commented Mar 16, 2022

Am I the only one face the same problem after upgrading macos to 12.3?

npm ERR! gyp info using node-gyp@3.5.0
npm ERR! gyp info using node@17.7.1 | darwin | x64
npm ERR! gyp verb command rebuild []
npm ERR! gyp verb command clean []
npm ERR! gyp verb clean removing "build" directory
npm ERR! gyp verb command configure []
npm ERR! gyp verb check python checking for Python executable "/usr/bin/python" in the PATH
npm ERR! gyp verb `which` failed Error: not found: /usr/bin/python
npm ERR! gyp ERR! configure error
npm ERR! gyp ERR! stack Error: Can't find Python executable "/usr/bin/python", you can set the PYTHON env variable.
~> echo $PYTHON
/usr/local/bin/python3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gyp Issues and PRs related to the GYP tool and .gyp build files python PRs and issues that require attention from people who are familiar with Python.
Projects
None yet
Development

No branches or pull requests

4 participants