| 2740 | o['variables']['node_section_ordering_info'] = "" |
| 2741 | |
| 2742 | def make_bin_override(): |
| 2743 | if sys.platform == 'win32': |
| 2744 | raise Exception('make_bin_override should not be called on win32.') |
| 2745 | # If the system python is not the python we are running (which should be |
| 2746 | # python 3.10+), then create a directory with a symlink called `python` to our |
| 2747 | # sys.executable. This directory will be prefixed to the PATH, so that |
| 2748 | # other tools that shell out to `python` will use the appropriate python |
| 2749 | |
| 2750 | which_python = shutil.which('python') |
| 2751 | if (which_python and |
| 2752 | os.path.realpath(which_python) == os.path.realpath(sys.executable)): |
| 2753 | return |
| 2754 | |
| 2755 | bin_override = Path('out', 'tools', 'bin').resolve() |
| 2756 | try: |
| 2757 | bin_override.mkdir(parents=True) |
| 2758 | except OSError as e: |
| 2759 | if e.errno != errno.EEXIST: |
| 2760 | raise e |
| 2761 | |
| 2762 | python_link = bin_override / 'python' |
| 2763 | try: |
| 2764 | python_link.unlink() |
| 2765 | except OSError as e: |
| 2766 | if e.errno != errno.ENOENT: |
| 2767 | raise e |
| 2768 | os.symlink(sys.executable, python_link) |
| 2769 | |
| 2770 | # We need to set the environment right now so that when gyp (in run_gyp) |
| 2771 | # shells out, it finds the right python (specifically at |
| 2772 | # https://github.com/nodejs/node/blob/d82e107/deps/v8/gypfiles/toolchain.gypi#L43) |
| 2773 | os.environ['PATH'] = str(bin_override) + ':' + os.environ['PATH'] |
| 2774 | |
| 2775 | return bin_override |
| 2776 | |
| 2777 | output = { |
| 2778 | 'variables': {}, |