2018-06-09 18:32:04 -04:00
|
|
|
#!/usr/bin/env python
|
|
|
|
"""
|
2018-06-13 08:58:06 -04:00
|
|
|
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.
|
2018-06-09 18:32:04 -04:00
|
|
|
"""
|
|
|
|
import subprocess
|
|
|
|
import sys
|
|
|
|
import os
|
|
|
|
|
2018-06-12 16:05:49 -04:00
|
|
|
def symlink(target, name, target_is_dir=False):
|
|
|
|
if os.name == "nt":
|
|
|
|
from ctypes import windll, WinError
|
|
|
|
CreateSymbolicLinkW = windll.kernel32.CreateSymbolicLinkW
|
|
|
|
flags = 0x02 # SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE
|
|
|
|
if (target_is_dir):
|
|
|
|
flags |= 0x01 # SYMBOLIC_LINK_FLAG_DIRECTORY
|
|
|
|
if not CreateSymbolicLinkW(name.encode('utf-16le'),
|
|
|
|
target.encode('utf-16le'),
|
|
|
|
flags):
|
|
|
|
raise WinError()
|
|
|
|
else:
|
|
|
|
os.symlink(target, name)
|
2018-06-11 21:54:55 -04:00
|
|
|
|
2018-06-09 18:32:04 -04:00
|
|
|
js_path = os.path.dirname(os.path.realpath(__file__))
|
2018-06-11 21:54:55 -04:00
|
|
|
node_modules_path = os.path.join(js_path, "node_modules")
|
|
|
|
|
|
|
|
if not os.path.exists("node_modules"):
|
2018-06-12 16:05:49 -04:00
|
|
|
symlink(node_modules_path, "node_modules", True)
|
2018-06-11 21:54:55 -04:00
|
|
|
|
2018-06-09 18:32:04 -04:00
|
|
|
args = ["node"] + sys.argv[1:]
|
|
|
|
sys.exit(subprocess.call(args))
|