forked from cloudflare/stpyv8
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
208 lines (161 loc) · 6.27 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
#!/usr/bin/env python
import sys
import os
import subprocess
import shutil
import logging
try:
from setuptools import setup, Extension
except ImportError:
from distutils.core import setup, Extension
from distutils.command.build import build
from distutils.command.install import install
from settings import *
log = logging.getLogger()
def exec_cmd(cmdline, *args, **kwargs):
msg = kwargs.get('msg')
cwd = kwargs.get('cwd', '.')
output = kwargs.get('output')
if msg:
print(msg)
cmdline = ' '.join([cmdline] + list(args))
proc = subprocess.Popen(cmdline,
shell = kwargs.get('shell', True),
cwd = cwd,
env = kwargs.get('env'),
stdout = subprocess.PIPE if output else None,
stderr = subprocess.PIPE if output else None)
stdout, stderr = proc.communicate()
succeeded = proc.returncode == 0
if not succeeded:
log.error("%s failed: code = %d", msg or "Execute command", proc.returncode)
if output:
log.debug(stderr)
return succeeded, stdout, stderr if output else succeeded
def install_depot():
if not os.path.exists(DEPOT_HOME):
exec_cmd("git clone",
DEPOT_GIT_URL,
DEPOT_HOME,
cwd = os.path.dirname(DEPOT_HOME),
msg = "Cloning depot tools")
return
# depot_tools updates itself automatically when running gclient tool
if os.path.isfile(os.path.join(DEPOT_HOME, 'gclient')):
_, stdout, _ = exec_cmd(os.path.join(DEPOT_HOME, 'gclient'),
"--version",
cwd = DEPOT_HOME,
output = True,
msg = "Found depot tools")
def checkout_v8():
if not os.path.exists(V8_HOME):
exec_cmd(os.path.join(DEPOT_HOME, 'fetch'),
'v8',
cwd = os.path.dirname(V8_HOME),
msg = "Fetching Google V8 code")
exec_cmd('git fetch --tags',
cwd = V8_HOME,
msg = "Fetching the release tag information")
exec_cmd('git checkout',
V8_GIT_TAG,
cwd = V8_HOME,
msg = "Checkout Google V8 v{}".format(V8_GIT_TAG))
exec_cmd(os.path.join(DEPOT_HOME, 'gclient'),
'sync',
'-D',
cwd = os.path.dirname(V8_HOME),
msg = "Syncing Google V8 code")
# On Linux, install additional dependencies, per
# https://v8.dev/docs/build step 4
if sys.platform in ("linux", "linux2", ) and v8_deps_linux:
exec_cmd('./v8/build/install-build-deps.sh',
cwd = os.path.dirname(V8_HOME),
msg = "Installing additional linux dependencies")
def build_v8():
exec_cmd(os.path.join(DEPOT_HOME, 'gn'),
"gen out.gn/x64.release.sample --args='{}'".format(GN_ARGS),
cwd = V8_HOME,
msg = "Generate build scripts for V8 (v{})".format(V8_GIT_TAG))
exec_cmd(os.path.join(DEPOT_HOME, 'ninja'),
"-C out.gn/x64.release.sample v8_monolith",
cwd = V8_HOME,
msg = "Build V8 with ninja")
def clean_stpyv8():
build_folder = os.path.join(STPYV8_HOME, 'build')
if os.path.exists(os.path.join(build_folder)):
shutil.rmtree(build_folder)
def prepare_v8():
try:
install_depot()
checkout_v8()
build_v8()
clean_stpyv8()
except Exception as e:
log.error("Fail to checkout and build v8, %s", str(e))
class stpyv8_build(build):
def run(self):
V8_GIT_TAG = V8_GIT_TAG_STABLE
prepare_v8()
build.run(self)
class stpyv8_develop(build):
def run(self):
V8_GIT_TAG = V8_GIT_TAG_MASTER
prepare_v8()
build.run(self)
class stpyv8_install_v8(build):
def run(self):
V8_GIT_TAG = V8_GIT_TAG_MASTER
prepare_v8()
class stpyv8_build_no_v8(build):
def run(self):
clean_stpyv8()
build.run(self)
class stpyv8_install(install):
def run(self):
self.skip_build = True
if icu_data_folder:
os.makedirs(icu_data_folder, exist_ok = True)
shutil.copy(os.path.join(V8_HOME, "out.gn/x64.release.sample/icudtl.dat"),
icu_data_folder)
install.run(self)
stpyv8 = Extension(name = "_STPyV8",
sources = [os.path.join("src", source) for source in source_files],
define_macros = macros,
include_dirs = include_dirs,
library_dirs = library_dirs,
libraries = libraries,
extra_compile_args = extra_compile_args,
extra_link_args = extra_link_args,
)
setup(name = "stpyv8",
version = STPYV8_VERSION,
description = "Python Wrapper for Google V8 Engine",
platforms = "x86",
author = "Philip Syme, Angelo Dell'Aera",
url = "https://github.com/area1/stpyv8",
license = "Apache License 2.0",
py_modules = ["STPyV8"],
ext_modules = [stpyv8],
classifiers = [
"Development Status :: 4 - Beta",
"Environment :: Plugins",
"Intended Audience :: Developers",
"Intended Audience :: System Administrators",
"License :: OSI Approved :: Apache Software License",
"Natural Language :: English",
"Operating System :: POSIX",
"Programming Language :: C++",
"Programming Language :: Python",
"Topic :: Internet",
"Topic :: Internet :: WWW/HTTP",
"Topic :: Software Development",
"Topic :: Software Development :: Libraries :: Python Modules",
"Topic :: Utilities",
],
cmdclass = dict(
build = stpyv8_build,
develop = stpyv8_develop,
v8 = stpyv8_install_v8,
stpyv8 = stpyv8_build_no_v8,
install = stpyv8_install),
)