1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-27 17:49:08 -05:00
denoland-deno/js/run_node.py

41 lines
1.4 KiB
Python
Raw Normal View History

#!/usr/bin/env python
"""
gn can only run python scripts. This launches a subprocess Node process.
The working dir of this program is out/Debug/ (AKA root_build_dir)
Before running node, we symlink js/node_modules to out/Debug/node_modules.
"""
import subprocess
import sys
import os
2018-06-22 15:16:27 -04:00
2018-06-12 16:05:49 -04:00
def symlink(target, name, target_is_dir=False):
2018-06-22 15:16:27 -04:00
if os.name == "nt":
import ctypes
CreateSymbolicLinkW = ctypes.windll.kernel32.CreateSymbolicLinkW
CreateSymbolicLinkW.restype = ctypes.c_ubyte
CreateSymbolicLinkW.argtypes = (ctypes.c_wchar_p, ctypes.c_wchar_p,
ctypes.c_uint32)
flags = 0x02 # SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE
if (target_is_dir):
flags |= 0x01 # SYMBOLIC_LINK_FLAG_DIRECTORY
if not CreateSymbolicLinkW(name, target, flags):
raise ctypes.WinError()
else:
os.symlink(target, name)
2018-06-11 21:54:55 -04:00
root_path = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
third_party_path = os.path.join(root_path, "third_party")
target_abs = os.path.join(third_party_path, "node_modules")
2018-06-23 05:40:28 -04:00
target_rel = os.path.relpath(target_abs)
2018-06-11 21:54:55 -04:00
2018-06-23 05:40:28 -04:00
if not os.path.exists("node_modules"):
if os.path.lexists("node_modules"):
2018-06-22 15:16:27 -04:00
os.unlink("node_modules")
2018-06-23 05:40:28 -04:00
symlink(target_rel, "node_modules", True)
2018-06-11 21:54:55 -04:00
args = ["node"] + sys.argv[1:]
sys.exit(subprocess.call(args))