-
Notifications
You must be signed in to change notification settings - Fork 52
/
build.py
95 lines (66 loc) · 3.1 KB
/
build.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
# -*- coding: utf-8 -*-
# Copyright (C) 2016, Maximilian Köhl <[email protected]>
#
# This program is free software: you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License version 3 as published by
# the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
import argparse
import os
from jaspy import metadata
from jaspy.converter import convert
from jaspy.preprocessor import process
__path__ = os.path.dirname(__file__)
if __path__:
os.chdir(__path__)
with open(os.path.join(__path__, 'modules', '_builtins.py')) as builtins:
code = compile(builtins.read(), '<builtins>', 'exec')
source = convert(code)
builtins_source = 'jaspy.module(%r, %s);' % ('_builtins', source)
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('--debug', action='store_true', default=False)
parser.add_argument('--debug-instructions', action='store_true', default=False)
# TODO: disable DEBUG_EXCEPTIONS when production ready
parser.add_argument('--debug-exceptions', action='store_true', default=True)
parser.add_argument('--debug-threading', action='store_true', default=False)
parser.add_argument('--exclude-bigint', action='store_true', default=False)
parser.add_argument('--exclude-siphash', action='store_true', default=False)
parser.add_argument('--include-encoding', action='store_true', default=False)
parser.add_argument('--disable-debugger', action='store_true', default=False)
parser.add_argument('--disable-threading', action='store_true', default=False)
parser.add_argument('--threading-limit', type=int, default=5000)
parser.add_argument('--modules', nargs='*')
arguments = parser.parse_args()
libs = []
if not arguments.exclude_bigint:
libs.append('biginteger/BigInteger.js')
if not arguments.exclude_siphash:
libs.append('siphash/lib/siphash.js')
if arguments.include_encoding:
libs.append('text-encoding/lib/encoding.js')
namespace = {
'DEBUG': arguments.debug,
'DEBUG_INSTRUCTIONS': arguments.debug_instructions,
'DEBUG_EXCEPTIONS': arguments.debug_exceptions,
'DEBUG_THREADING': arguments.debug_threading,
'ENABLE_DEBUGGER': not arguments.disable_debugger,
'ENABLE_THREADING': not arguments.disable_threading,
'ENABLE_ASSERTIONS': True,
'THREADING_LIMIT': arguments.threading_limit,
'UNICODE_SUPPORT': True,
'modules': arguments.modules or [],
'metadata': metadata,
'libs': libs,
'_builtins': builtins_source
}
if not os.path.exists('build'):
os.mkdir('build')
with open('build/jaspy.js', 'w') as output:
output.write(process('src/__init__.js', namespace))